Files
clean-architecture-backend-…/scripts/tests/test_check_docs.py
T
DongHyeonka 9c4ca9f391 ci(docs): 숫자 검사가 굵은 글씨·표 칸의 Spring Boot 버전 복사도 잡는다
숫자 검사(number)는 「Spring Boot 4.0.8」처럼 이름 바로 뒤에 붙은 버전만
본다. 이름과 떨어진 복사는 지나간다. 기준 커밋 03a313ed의 살아 있는
문서에 그런 복사가 넷 있었다.
- docs/web/repository-adaptation.md:65 「baseline is **4.0.8**」
  (의존성 세션이 손으로 찾아 고친 줄. 그 브랜치는 **4.0.9**로 바꾼다)
- docs/compatibility/grpc-support-matrix.md:29 「| Spring Boot | 4.0.8 …」
- docs/mongodb/support-matrix.md:12 「| Spring Boot | 4.0.0 |」
- docs/jpa/repository-adaptation.md:100 「Boot 4.0.0 resolves …」
번역 묶음이 넷 모두 정본을 가리키게 고쳤지만, 검사가 막지 않으면
다시 생긴다.

규칙 셋을 더했다(Spring Boot 버전에만).
1. 이름 규칙이 「Spring」 없는 「Boot x.y.z」도 잡는다.
2. 표 행에 칸 전체가 「Spring Boot」(굵은 글씨·코드·링크를 벗긴 뒤,
   뒤에 BOM·버전이 붙어도 됨)인 칸이 있으면 그 행의 세 자리 버전.
3. 정본(src/gradle/libs.versions.toml의 springBoot)과 같은 버전 문자열은
   어디에 쓰든(굵은 글씨, 표 칸, 인라인 코드). 앞이 낱말·점·§이거나
   뒤가 낱말·「.숫자」이면 다른 수의 일부로 보고 넘긴다(RFC §4.0.8,
   14.0.8, 4.0.80, 4.0.8.1).
이름 옆 복사는 한 번만 센다(2·3이 그 안의 버전을 다시 세지 않는다).
결정 기록·제거 표·upgrade/를 빼는 범위는 그대로다(checked_for_drift).

버린 대안: 굵은 글씨 안의 모든 세 자리 버전을 잡기. 살아 있는 문서를
훑으면 Spring Boot 아닌 것이 둘 걸린다. docs/jpa/support-matrix.md의
Hibernate **7.1.8.Final**은 JpaDocumentationContractTest가 release
registry의 값과 같은지 단언하는 렌더링이라 지울 수 없다. 그것을 잡으면
굵은 글씨만 빼서 검사를 피하게 된다. 규칙 3은 정본 값을 직접 보므로,
지금 버전의 복사는 모양과 상관없이 생길 수 없고, 버전을 올리는 변경
때 옛 값의 복사가 남아 있을 수 없다.

한계: 정본 값과 다르고 이름과도 떨어진 버전(「4.0.0 / 5.0.0」 같은
문장)은 잡지 않는다. Spring Boot 밖의 버전 복사는 이 검사의 범위가
아니다(docs/README.md 「문서 검사」 number 행).

시험: 03a313ed 트리와 의존성 브랜치(cb67b879) 트리에 옛·새 검사를
돌렸다. 새 검사가 위 네 줄(의존성 브랜치는 **4.0.9**)을 더 잡고,
옛 검사가 잡던 28건은 모두 그대로 잡는다. 합친 트리는 걸림 0이라
예외를 더하거나 고칠 문서가 없다.

자기 시험 8개를 더했다(76 OK). 조건을 하나씩 끈 변이 시험 7개가 모두
rc=1이다: 옛 이름 정규식, 표 칸 규칙 끔, 정본 값 규칙 끔, 중복 세기
제거 끔, 정본 값 앞 § 허용, 정본 값 뒤 경계 끔, 칸 이름 앞부분만 맞춤.

검증(노트북): check-docs.py OK, 자기 시험 76 OK, check-work-docs.py OK.
2026-11-07 18:19:42 +09:00

436 lines
22 KiB
Python

"""scripts/check-docs.py의 시험. 고장 낸 입력에서 실패하고, 맞는 입력에서 통과하는지 본다.
python3 -m unittest discover -s scripts/tests
"""
from __future__ import annotations
import importlib.util
import json
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
SCRIPTS = Path(__file__).resolve().parent.parent
_spec = importlib.util.spec_from_file_location("check_docs", SCRIPTS / "check-docs.py")
check_docs = importlib.util.module_from_spec(_spec)
sys.modules["check_docs"] = check_docs
_spec.loader.exec_module(check_docs)
KOREAN = "이 문서는 한국어로 쓴 살아 있는 문서다. 코드와 같은 변경에서 고친다.\n"
ENGLISH = "This document is written in English and explains how the module works in detail.\n"
def head(kind: str = "설계서", status: str = "구현됨", written: str = "2026-08-11",
summary: str = "한국어로 쓴 요약 한 문장이다.", canonical: str = "`docs/live.md`",
extra: str = "", label: str | None = None) -> str:
if label is None:
label = check_docs.DECISION_LABEL if kind == "결정 기록" else check_docs.RECORD_LABEL.format(kind=kind)
lines = [check_docs.HEAD_START, label, "", f"- 상태: {status}", f"- 작성일: {written}",
f"- 요약: {summary}", f"- 현재 정본: {canonical}"]
if extra:
lines.append(extra)
lines += [check_docs.HEAD_END, ""]
return "\n".join(lines) + "\n"
class Repository:
"""A throwaway git working tree with a registry, so the checker sees what git sees."""
def __init__(self) -> None:
self._directory = tempfile.TemporaryDirectory()
self.root = Path(self._directory.name)
subprocess.run(["git", "init", "-q", str(self.root)], check=True)
self.write("docs/live.md", KOREAN)
self.write(check_docs.REGISTRY_FILE, json.dumps({"modules": [
{"id": "app", "gradle_path": ":app", "source_path": "src/app"},
{"id": "adapter-web", "gradle_path": ":adapter:inbound:web", "source_path": "src/adapter/inbound/web"},
]}))
def write(self, path: str, text: str) -> None:
target = self.root / path
target.parent.mkdir(parents=True, exist_ok=True)
target.write_text(text, encoding="utf-8")
def run(self, only: tuple[str, ...] = check_docs.CHECKS, exceptions: str = "",
frozen: frozenset[str] | None = None) -> list[str]:
if frozen is None:
frozen = frozenset(check_docs.fingerprint(line) for line in check_docs.read_exceptions(exceptions))
errors, _ = check_docs.run(self.root, only, exceptions=exceptions, frozen=frozen)
return errors
def close(self) -> None:
self._directory.cleanup()
class RepositoryTestCase(unittest.TestCase):
def setUp(self) -> None:
self.repo = Repository()
self.addCleanup(self.repo.close)
def assertFailsWith(self, errors: list[str], fragment: str) -> None:
self.assertTrue(any(fragment in error for error in errors), f"no error with {fragment!r}: {errors}")
class LanguageTest(RepositoryTestCase):
def test_an_english_living_document_fails(self) -> None:
self.repo.write("docs/guide.md", "# Guide\n\n" + ENGLISH * 3)
self.assertFailsWith(self.repo.run(("language",)), "docs/guide.md: 영어 문서다")
def test_a_korean_living_document_passes(self) -> None:
self.repo.write("src/app/README.md", "# 앱\n\n" + KOREAN * 3)
self.assertEqual(self.repo.run(("language",)), [])
def test_code_commands_and_paths_do_not_make_a_korean_document_english(self) -> None:
code = "```bash\n" + "./gradlew :app:test --console=plain and many more english words here\n" * 20 + "```\n"
self.repo.write("docs/guide.md", "# 안내\n\n" + KOREAN + code + "`src/app/Foo.java`를 본다.\n")
self.assertEqual(self.repo.run(("language",)), [])
def test_a_record_body_keeps_its_original_language(self) -> None:
self.repo.write("docs/design/2026-08-11-x-design.md", head() + "# Design\n\n" + ENGLISH * 3)
self.assertEqual(self.repo.run(("language",)), [])
def test_an_english_decision_record_body_fails(self) -> None:
self.repo.write("docs/adr/ADR-X-001.md", head(kind="결정 기록", status="채택") + "# ADR\n\n" + ENGLISH * 3)
self.assertFailsWith(self.repo.run(("language",)), "docs/adr/ADR-X-001.md: 영어 문서다")
class ExceptionListTest(RepositoryTestCase):
LINE = "language\tdocs/guide.md"
def test_a_frozen_exception_excuses_its_document(self) -> None:
self.repo.write("docs/guide.md", ENGLISH * 3)
self.assertEqual(self.repo.run(("language",), exceptions=self.LINE + "\n"), [])
def test_adding_a_line_to_the_exception_list_fails(self) -> None:
self.repo.write("docs/guide.md", ENGLISH * 3)
errors = self.repo.run(("language",), exceptions=self.LINE + "\n", frozen=frozenset())
self.assertFailsWith(errors, "기준선에 없는 예외다")
def test_a_frozen_fingerprint_whose_line_was_removed_fails(self) -> None:
# The line was deleted from the list but its fingerprint stayed: the same line could come back.
orphan = frozenset({check_docs.fingerprint(self.LINE)})
for only in (("language",), ("head",)):
errors = self.repo.run(only, exceptions="", frozen=orphan)
self.assertFailsWith(errors, "예외 목록에 그 줄이 없는 지문이다")
def test_a_removed_line_added_back_fails_once_its_fingerprint_is_gone(self) -> None:
self.repo.write("docs/guide.md", ENGLISH * 3)
remaining = "language\tdocs/other.md"
self.repo.write("docs/other.md", ENGLISH * 3)
exceptions = remaining + "\n" + self.LINE + "\n"
errors = self.repo.run(("language",), exceptions=exceptions,
frozen=frozenset({check_docs.fingerprint(remaining)}))
self.assertFailsWith(errors, "기준선에 없는 예외다")
self.assertFalse(any("예외 목록에 그 줄이 없는 지문이다" in error for error in errors), errors)
def test_an_exception_that_no_longer_fails_must_be_removed(self) -> None:
self.repo.write("docs/guide.md", KOREAN * 3)
self.assertFailsWith(self.repo.run(("language",), exceptions=self.LINE + "\n"), "더는 걸리지 않는다")
def test_an_exception_for_one_check_does_not_excuse_another(self) -> None:
self.repo.write("docs/guide.md", "`docs/gone.md`를 본다. " + KOREAN)
errors = self.repo.run(("reference",), exceptions="number\tdocs/guide.md\tdocs/gone.md\n")
self.assertFailsWith(errors, "없는 경로다: docs/gone.md")
def test_every_line_of_the_real_exception_list_is_in_the_frozen_baseline(self) -> None:
text = (SCRIPTS.parent / check_docs.EXCEPTIONS_FILE).read_text(encoding="utf-8")
outside = [line for line in check_docs.read_exceptions(text)
if check_docs.fingerprint(line) not in check_docs.FROZEN]
self.assertEqual(outside, [])
def test_every_frozen_fingerprint_has_its_line_in_the_real_exception_list(self) -> None:
text = (SCRIPTS.parent / check_docs.EXCEPTIONS_FILE).read_text(encoding="utf-8")
listed = {check_docs.fingerprint(line) for line in check_docs.read_exceptions(text)}
self.assertEqual(sorted(check_docs.FROZEN - listed), [])
def test_a_new_line_in_the_real_exception_list_is_not_in_the_frozen_baseline(self) -> None:
self.assertNotIn(check_docs.fingerprint("language\tdocs/brand-new-english.md"), check_docs.FROZEN)
class HeadBlockTest(RepositoryTestCase):
PATH = "docs/design/2026-08-11-x-design.md"
def errors_for(self, text: str) -> list[str]:
self.repo.write(self.PATH, text + "# Original\n\nbody\n")
return self.repo.run(("head",))
def test_a_complete_head_block_passes(self) -> None:
self.assertEqual(self.errors_for(head()), [])
def test_canonical_none_with_a_reason_passes(self) -> None:
self.assertEqual(self.errors_for(head(canonical="없음 — 지운 기능이다")), [])
def test_a_record_without_a_head_block_fails(self) -> None:
self.assertFailsWith(self.errors_for(""), "맨 위에 머리 블록이 없다")
def test_a_status_outside_the_vocabulary_fails(self) -> None:
self.assertFailsWith(self.errors_for(head(status="Accepted")), "설계서의 상태는")
def test_a_plan_status_on_a_decision_record_fails(self) -> None:
self.repo.write("docs/adr/ADR-X-001.md", head(kind="결정 기록", status="끝남") + "# ADR\n")
self.assertFailsWith(self.repo.run(("head",)), "결정 기록의 상태는")
def test_a_malformed_date_fails(self) -> None:
self.assertFailsWith(self.errors_for(head(written="2026-13-01")), "작성일은 YYYY-MM-DD다")
def test_an_english_summary_fails(self) -> None:
self.assertFailsWith(self.errors_for(head(summary="A design for the module boundary.")), "요약은 한국어")
def test_a_canonical_path_that_does_not_exist_fails(self) -> None:
self.assertFailsWith(self.errors_for(head(canonical="`docs/missing.md`")), "현재 정본 경로가 없다")
def test_a_canonical_value_without_a_path_fails(self) -> None:
self.assertFailsWith(self.errors_for(head(canonical="jpa 문서")), "현재 정본은")
def test_superseded_without_its_replacement_fails(self) -> None:
self.assertFailsWith(self.errors_for(head(status="대체됨")), "「대체됨」 칸에 대체한 문서")
def test_superseded_with_its_replacement_passes(self) -> None:
self.assertEqual(self.errors_for(head(status="대체됨", extra="- 대체됨: `docs/live.md`")), [])
def test_a_wrong_kind_label_fails(self) -> None:
self.assertFailsWith(self.errors_for(head(label="> **기록 · 계획서** 다른 종류다.")), "머리 블록 둘째 줄은")
def test_an_unknown_field_fails(self) -> None:
self.assertFailsWith(self.errors_for(head(extra="- 담당: 누군가")), "머리 블록에 없는 칸이다")
def test_the_kind_follows_the_folder(self) -> None:
self.repo.write("docs/history/plans/evidence/x.md", head(kind="증거", status="보관") + "# Evidence\n")
self.assertEqual(self.repo.run(("head",)), [])
class ReferenceTest(RepositoryTestCase):
def errors_for(self, text: str, path: str = "docs/guide.md") -> list[str]:
self.repo.write(path, KOREAN + text)
return self.repo.run(("reference",))
def test_a_missing_repository_path_fails(self) -> None:
self.assertFailsWith(self.errors_for("`docs/gone.md`를 읽는다.\n"), "없는 경로다: docs/gone.md")
def test_an_existing_path_with_a_line_number_passes(self) -> None:
self.assertEqual(self.errors_for("`docs/live.md:12`를 읽는다.\n"), [])
def test_a_missing_path_under_the_root_compose_folder_fails(self) -> None:
self.assertFailsWith(self.errors_for("`compose/gone/README.md`를 읽는다.\n"), "없는 경로다: compose/gone/README.md")
def test_a_path_inside_a_command_is_checked(self) -> None:
self.assertFailsWith(self.errors_for("`python3 scripts/gone.py --all`을 돌린다.\n"), "scripts/gone.py")
def test_fenced_code_is_skipped(self) -> None:
self.assertEqual(self.errors_for("```text\n`docs/gone.md`\n```\n"), [])
def test_a_history_quote_is_skipped(self) -> None:
self.assertEqual(self.errors_for("> 이력: `docs/gone.md`는 2026-09-25에 지웠다.\n> `src/gone/` 도.\n"), [])
def test_a_placeholder_path_is_skipped(self) -> None:
self.assertEqual(self.errors_for("`docs/reviews/<폴더>`와 `src/**/CLAUDE.md`를 본다.\n"), [])
def test_a_leaf_relative_source_path_resolves_through_some_leaf(self) -> None:
self.repo.write("src/app/src/test/resources/contracts/x.sha256", "x")
self.assertEqual(self.errors_for("각 leaf의 `src/test/resources/contracts/x.sha256`을 본다.\n"), [])
def test_a_source_set_name_every_leaf_has_is_skipped(self) -> None:
self.assertEqual(self.errors_for("테스트는 각 leaf의 `src/test`와 `src/main/java/` 옆에 둔다.\n"), [])
def test_a_gradle_path_outside_the_registry_fails(self) -> None:
self.assertFailsWith(self.errors_for("`./gradlew :sample:check`를 돌린다.\n"), "registry에 없는 Gradle 경로다: :sample:check")
def test_a_task_of_a_registered_project_passes(self) -> None:
self.assertEqual(self.errors_for("`./gradlew :adapter:inbound:web:test`와 `:app:check`를 돌린다.\n"), [])
def test_the_removal_table_is_not_checked(self) -> None:
self.assertEqual(self.errors_for("`src/gone/Old.java`를 지웠다.\n", path="docs/capability-status.md"), [])
def test_a_record_is_not_checked(self) -> None:
self.repo.write("docs/design/2026-08-11-x-design.md", head() + "`docs/gone.md`\n")
self.assertEqual(self.repo.run(("reference",)), [])
class NumberTest(RepositoryTestCase):
def errors_for(self, text: str) -> list[str]:
self.repo.write("src/app/CLAUDE.md", KOREAN + text)
return self.repo.run(("number",))
def test_a_copied_spring_boot_version_fails(self) -> None:
self.assertFailsWith(self.errors_for("Runtime baseline: Spring Boot 4.0.8.\n"), "'Spring Boot 4.0.8'")
def test_a_major_version_passes(self) -> None:
self.assertEqual(self.errors_for("Spring Boot 4 위에서 돈다.\n"), [])
def test_a_copied_leaf_count_fails(self) -> None:
self.assertFailsWith(self.errors_for("registry는 leaf 65개를 가진다.\n"), "leaf 개수")
self.assertFailsWith(self.errors_for("declares exactly 19 leaf identities.\n"), "leaf 개수")
def test_a_word_count_of_leaves_passes(self) -> None:
self.assertEqual(self.errors_for("leaf 하나를 고른다.\n"), [])
def with_catalog(self, version: str = "4.0.8") -> None:
self.repo.write(check_docs.CATALOG_FILE, f'[versions]\nspringBoot = "{version}"\nother = "1.2.3"\n')
def test_boot_without_spring_fails(self) -> None:
self.assertFailsWith(self.errors_for("BOM은 Boot 4.0.0이 푼다.\n"), "'Boot 4.0.0'")
def test_a_bold_copy_of_the_catalog_version_fails(self) -> None:
self.with_catalog()
self.assertFailsWith(self.errors_for("이 저장소의 기준은 **4.0.8**이다.\n"), "'4.0.8'")
def test_the_catalog_version_in_code_fails(self) -> None:
self.with_catalog()
self.assertFailsWith(self.errors_for("`org.springframework.boot:spring-boot:4.0.8`을 쓴다.\n"), "'4.0.8'")
def test_a_version_in_a_spring_boot_table_row_fails(self) -> None:
self.with_catalog()
errors = self.errors_for("| 의존성 | 버전 |\n| --- | --- |\n| **Spring Boot** | 4.0.0 (BOM이 관리) |\n")
self.assertFailsWith(errors, "'4.0.0'")
def test_a_copy_next_to_the_name_is_reported_once(self) -> None:
self.with_catalog()
errors = self.errors_for("| Spring Boot | Spring Boot 4.0.8 |\n")
self.assertEqual(len(errors), 1, errors)
self.assertFailsWith(errors, "'Spring Boot 4.0.8'")
def test_another_library_in_a_table_row_passes(self) -> None:
self.with_catalog()
self.assertEqual(self.errors_for("| Hibernate | **7.1.8.Final** |\n| Spring Boot | 카탈로그 |\n"), [])
def test_numbers_that_only_contain_the_catalog_version_pass(self) -> None:
self.with_catalog()
self.assertEqual(self.errors_for("RFC 9113 §4.0.8, 버전 14.0.8, 4.0.80, 4.0.8.1, 다른 값 1.2.3.\n"), [])
def test_a_spring_boot_cell_name_must_be_the_whole_cell(self) -> None:
self.with_catalog()
self.assertEqual(self.errors_for("| Spring Boot BOM이 푸는 Hibernate | 7.1.8.Final |\n"), [])
class ScopeTest(RepositoryTestCase):
def test_markdown_under_a_source_set_resources_folder_is_not_a_document(self) -> None:
self.repo.write("src/app/src/test/resources/fixtures/broken-readme.md", "# Broken\n\n" + ENGLISH * 3)
self.assertEqual(self.repo.run(("language",)), [])
def test_markdown_beside_a_source_set_is_still_a_document(self) -> None:
self.repo.write("src/app/src/test/README.md", "# Tests\n\n" + ENGLISH * 3)
self.assertFailsWith(self.repo.run(("language",)), "src/app/src/test/README.md: 영어 문서다")
def table(*rows: str) -> str:
return "| 폴더 | 무엇 |\n| --- | --- |\n" + "".join(f"| {row} | 설명 |\n" for row in rows)
class MapTest(RepositoryTestCase):
def errors_for(self, text: str) -> list[str]:
self.repo.write(check_docs.MAP_FILE, "# docs\n\n" + KOREAN + text)
return self.repo.run(("map",))
def test_a_map_that_names_every_folder_passes(self) -> None:
self.repo.write("docs/jpa/guide.md", KOREAN)
self.repo.write("docs/history/plans/2026-08-11-x-plan.md", KOREAN)
checks = "| 검사 | 보는 것 |\n| --- | --- |\n| `language` | 언어 |\n"
self.assertEqual(self.errors_for(table("`jpa/`", "`history/plans/`") + "\n" + checks), [])
def test_a_folder_missing_from_the_map_fails(self) -> None:
self.repo.write("docs/redis/operations.md", KOREAN)
self.assertFailsWith(self.errors_for(table()), "지도에 없는 문서 폴더다: docs/redis/")
def test_a_folder_without_markdown_must_be_mapped_too(self) -> None:
self.repo.write("docs/security/public-paths-snapshot.txt", "/api/healthcheck\n")
self.assertFailsWith(self.errors_for(table()), "지도에 없는 문서 폴더다: docs/security/")
def test_a_folder_that_only_holds_folders_is_covered_by_its_subfolders(self) -> None:
self.repo.write("docs/history/plans/2026-08-11-x-plan.md", KOREAN)
self.repo.write("docs/history/study/x.md", KOREAN)
errors = self.errors_for(table("`history/`", "`history/plans/`"))
self.assertFailsWith(errors, "지도에 없는 문서 폴더다: docs/history/study/")
self.assertFalse(any("docs/history/plans/" in error for error in errors), errors)
def test_folders_below_the_mapped_level_need_no_row(self) -> None:
self.repo.write("docs/history/packages/jpa/README.md", KOREAN)
self.repo.write("docs/mongodb/advanced/sharding.md", KOREAN)
self.repo.write("docs/mongodb/guide.md", KOREAN)
self.assertEqual(self.errors_for(table("`history/packages/`", "`mongodb/`")), [])
def test_a_mapped_folder_that_does_not_exist_fails(self) -> None:
self.assertFailsWith(self.errors_for(table("`gone/`")), "지도의 폴더가 없다: docs/gone/")
def test_a_folder_named_outside_the_first_cell_does_not_count(self) -> None:
self.repo.write("docs/redis/operations.md", KOREAN)
self.assertFailsWith(self.errors_for(table("운영") + "| 캐시 | `redis/` |\n"),
"지도에 없는 문서 폴더다: docs/redis/")
def test_a_folder_inside_a_code_block_does_not_count(self) -> None:
self.repo.write("docs/redis/operations.md", KOREAN)
self.assertFailsWith(self.errors_for("```text\n" + table("`redis/`") + "```\n"),
"지도에 없는 문서 폴더다: docs/redis/")
def test_a_folder_may_be_written_from_the_repository_root(self) -> None:
self.repo.write("docs/redis/operations.md", KOREAN)
self.assertEqual(self.errors_for(table("`docs/redis/`")), [])
def test_a_placeholder_folder_is_not_an_entry(self) -> None:
self.assertEqual(self.errors_for(table("`history/packages/<어댑터>/`")), [])
def test_a_repository_without_the_map_fails(self) -> None:
self.assertFailsWith(self.repo.run(("map",)), "문서 지도가 없다")
def readme(sections: tuple[str, ...] = check_docs.README_SECTIONS, title: str = "# 템플릿",
intro: str = "이 저장소가 무엇이고 누가 쓰는지 쓴 한 문단이다.") -> str:
parts = [title, "", intro, ""] if intro else [title, ""]
for section in sections:
parts += [section if section.startswith("#") else f"## {section}", "", KOREAN]
return "\n".join(parts)
class ReadmeTest(RepositoryTestCase):
def errors_for(self, text: str) -> list[str]:
self.repo.write(check_docs.README_FILE, text)
return self.repo.run(("readme",))
def test_every_section_in_order_passes(self) -> None:
self.assertEqual(self.errors_for(readme()), [])
def test_other_sections_between_the_required_ones_pass(self) -> None:
sections = check_docs.README_SECTIONS[:2] + ("부록",) + check_docs.README_SECTIONS[2:]
self.assertEqual(self.errors_for(readme(sections)), [])
def test_each_missing_section_fails(self) -> None:
for missing in check_docs.README_SECTIONS:
with self.subTest(missing=missing):
sections = tuple(section for section in check_docs.README_SECTIONS if section != missing)
self.assertFailsWith(self.errors_for(readme(sections)), f"「## {missing}」 절이 없다")
def test_sections_out_of_order_fail(self) -> None:
sections = ("시작하기", "프로젝트 구조") + check_docs.README_SECTIONS[2:]
self.assertFailsWith(self.errors_for(readme(sections)), "「## 시작하기」 절은 「## 프로젝트 구조」 절 뒤에 온다")
def test_a_readme_that_does_not_start_with_a_title_fails(self) -> None:
self.assertFailsWith(self.errors_for(readme(title="템플릿 소개")), "첫 줄은 `# 제목`이다")
self.assertFailsWith(self.errors_for("소개 한 줄\n\n" + readme()), "첫 줄은 `# 제목`이다")
def test_a_readme_without_an_introduction_fails(self) -> None:
self.assertFailsWith(self.errors_for(readme(intro="")), "한 문단을 둔다")
def test_a_section_heading_at_another_level_does_not_count(self) -> None:
sections = tuple("### 문서 지도" if section == "문서 지도" else section
for section in check_docs.README_SECTIONS)
self.assertFailsWith(self.errors_for(readme(sections)), "「## 문서 지도」 절이 없다")
def test_a_section_heading_inside_a_code_block_does_not_count(self) -> None:
sections = tuple(section for section in check_docs.README_SECTIONS if section != "검증")
text = readme(sections) + "\n```markdown\n## 검증\n```\n"
self.assertFailsWith(self.errors_for(text), "「## 검증」 절이 없다")
def test_a_repository_without_a_readme_fails(self) -> None:
self.assertFailsWith(self.repo.run(("readme",)), "루트 README가 없다")
class CommandLineTest(unittest.TestCase):
def test_an_unknown_check_is_a_usage_error(self) -> None:
self.assertEqual(check_docs.main(["--only", "spelling"]), 2)
if __name__ == "__main__":
unittest.main()