test_pydocs.py¶
tests/test_pydocs.py
PEP 257 docstrings fill what doxygen left bare, and nothing else.
test_ast_rows_are_left_alone
test_pydocs.test_ast_rows_are_left_alone(tmp_path)
An 'ast' row says it has no documentation; filling one in would make that false.
Checks
assert _enrich_one(conn, "function", 1, 3, "f", "Sum.", "", True, [1]) == 0assert _enrich_one(conn, "function", 1, 9, "g", "Sum.", "", True, [2]) == 1assert Path(db).exists()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-013 | catalog | |
| REQ-DDB-QUERY-003 | measured | test_ast_rows_are_left_alone → _enrich_one → strip_xml |
Source · 17 lines
def test_ast_rows_are_left_alone(tmp_path):
"""An 'ast' row says it has no documentation; filling one in would make that false."""
from clew.pydocs import _enrich_one
db = tmp_path / "x.db"
conn = sqlite3.connect(db)
conn.execute(
"CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, name TEXT, file_id INT, "
"bodyfile_id INT, line INT, briefdescription TEXT, detaileddescription TEXT, dg_source TEXT)"
)
conn.execute("INSERT INTO memberdef VALUES (1, 'f', 1, 1, 3, '', '', 'ast')")
conn.execute("INSERT INTO memberdef VALUES (2, 'g', 1, 1, 9, '', '', 'doxygen')")
assert _enrich_one(conn, "function", 1, 3, "f", "Sum.", "", True, [1]) == 0
assert _enrich_one(conn, "function", 1, 9, "g", "Sum.", "", True, [2]) == 1
assert Path(db).exists()
Activity · 9 steps
test_build_fills_only_what_doxygen_left_bare
test_pydocs.test_build_fills_only_what_doxygen_left_bare(tmp_path)
Checks
assert rows["doxy"] == ("Doxygen-documented.", "4", "doxygen"), "a ## block is never replaced"assert rows["pep"] == ("Return the answer.", "2", "doxygen")assert rows["method"][0] == "Do the thing."assert rows["bare"][0] == "", "no docstring, nothing invented"assert strip_xml(classes["mod::Thing"]) == "A documented class."assert req == 1, ("the @req stays in doxygen's verbatim detail, where the requirements pass reads it" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → report_stats |
| REQ-DDB-CLI-002 | inferred | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → _doxygen_or_partial → _doxygen_stage → _run_doxygen_from_args → run_doxygen → doxygen_supports_sqlite3 |
| REQ-DDB-CONFIG-001 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _apply_declared_document → stated_document_meta |
| REQ-DDB-CONFIG-003 | inferred | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_requirements_yaml → _is_flat_req_list |
| REQ-DDB-CONFIG-004 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → resolve_preprocessor |
| REQ-DDB-CONFIG-005 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_kconfig |
| REQ-DDB-CONFIG-006 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _recorded_entry_patterns → recorded_explicit |
| REQ-DDB-CONFIG-007 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → write_build_signature |
| REQ-DDB-CONFIG-009 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _apply_toolchain_exclusions → load_toolchain_config |
| REQ-DDB-GUARD-012 | inferred | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → load_guard_config → read_guard_config → read_requirements_section |
| REQ-DDB-GUARD-019 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_python_docstrings → summarize → parse_doxygen_tags |
| REQ-DDB-GUARD-024 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_python_docstrings → summarize → apply_autobrief |
| REQ-DDB-INDEX-001 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _verify_extra_input_is_read → effective_file_patterns |
| REQ-DDB-INDEX-002 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → build_lock |
| REQ-DDB-INDEX-003 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → report_index_coverage |
| REQ-DDB-INDEX-004 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → recover_ast_symbols |
| REQ-DDB-INDEX-005 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → stamp_external_provenance |
| REQ-DDB-INDEX-006 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → record_code_text → code_text_rows |
| REQ-DDB-INDEX-007 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → record_owners |
| REQ-DDB-INDEX-008 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_file_licenses |
| REQ-DDB-INDEX-009 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_kerneldoc |
| REQ-DDB-INDEX-010 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_ast_includes |
| REQ-DDB-INDEX-011 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_property_keys |
| REQ-DDB-MCP-001 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _operator_excludes → meta_section |
| REQ-DDB-MCP-004 | measured | |
| REQ-DDB-PIPE-001 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_database |
| REQ-DDB-PIPE-003 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → build_call_edges |
| REQ-DDB-PIPE-004 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → python_entry_seeds |
| REQ-DDB-PIPE-005 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → write_build_signature |
| REQ-DDB-PIPE-006 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → run_rustdoc → _require_nightly_rustdoc → clean_subprocess_env |
| REQ-DDB-PIPE-007 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_kconfig_gates |
| REQ-DDB-PIPE-008 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_file_docs |
| REQ-DDB-PIPE-009 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → prune_dominated_fuzzy_call_edges |
| REQ-DDB-PIPE-010 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_shared_key_edges_inferred → _build_inferred_edges |
| REQ-DDB-PIPE-011 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_ast_includes → run_harvest → _harvest_one_file → _parseable_file |
| REQ-DDB-PIPE-012 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → build_harvest_plan → js_symbol_harvester |
| REQ-DDB-PIPE-013 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_python_docstrings |
| REQ-DDB-PIPE-014 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_kerneldoc → within_repo |
| REQ-DDB-PIPE-015 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_config_defaults |
| REQ-DDB-QUERY-003 | measured | test_build_fills_only_what_doxygen_left_bare → strip_xml |
| REQ-DDB-QUERY-011 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → extract_threads → _ensure_threads_tables |
| REQ-DDB-SCHEMA-001 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → extract_threads |
| REQ-DDB-SCHEMA-002 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_shared_key_edges_inferred → _writer_dispatch_map |
| REQ-DDB-SCHEMA-003 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_callback_registration_edges → _ensure_external_boundaries_table |
| REQ-DDB-SCHEMA-004 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → load_dispatch_manifest |
| REQ-DDB-SCHEMA-005 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → resolve_key_alias_prefixes |
| REQ-DDB-SCHEMA-006 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_requirements_yaml |
| REQ-DDB-SCHEMA-007 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_callback_registration_edges → _ensure_external_boundaries_table |
| REQ-DDB-SCHEMA-009 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_event_edges |
| REQ-DDB-SCHEMA-011 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → extract_context_conflicts |
| REQ-DDB-SCHEMA-012 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → load_dispatch_manifest → declaration_origin |
| REQ-DDB-SCHEMA-013 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_data_model_keys |
| REQ-DDB-SCHEMA-014 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_file_docs → ensure_file_docs_table |
| REQ-DDB-SCHEMA-015 | measured | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_requirements_yaml |
| REQ-DDB-WIKI-054 | inferred | test_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → recover_ast_symbols → _recover_into → all |
Source · 30 lines
def test_build_fills_only_what_doxygen_left_bare(tmp_path):
repo = tmp_path / "repo"
(repo / "pkg").mkdir(parents=True)
(repo / "pkg" / "mod.py").write_text(SRC, encoding="utf-8")
out = tmp_path / "clew.db"
_run_pipeline(_build_argparser().parse_args(["--output", str(out), "--repo-root", str(repo)]))
conn = sqlite3.connect(out)
rows = {
name: (strip_xml(brief), extract_version(detail), source)
for name, brief, detail, source in conn.execute(
"SELECT name, briefdescription, detaileddescription, dg_source FROM memberdef "
"WHERE kind='function'"
)
}
assert rows["doxy"] == ("Doxygen-documented.", "4", "doxygen"), "a ## block is never replaced"
assert rows["pep"] == ("Return the answer.", "2", "doxygen")
assert rows["method"][0] == "Do the thing."
assert rows["bare"][0] == "", "no docstring, nothing invented"
classes = dict(
conn.execute("SELECT name, briefdescription FROM compounddef WHERE kind='class'")
)
assert strip_xml(classes["mod::Thing"]) == "A documented class."
req = conn.execute(
"SELECT COUNT(*) FROM memberdef WHERE name='pep' AND detaileddescription LIKE '%REQ-X-001%'"
).fetchone()[0]
assert req == 1, (
"the @req stays in doxygen's verbatim detail, where the requirements pass reads it"
)
Activity · 15 steps
test_harvest_docstrings_lines_are_the_def_lines
test_pydocs.test_harvest_docstrings_lines_are_the_def_lines()
Checks
assert found == {assert found[("function", "pep")] == line_of("@decorated") + 1
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-013 | measured | test_harvest_docstrings_lines_are_the_def_lines → harvest_docstrings |
Source · 17 lines
def test_harvest_docstrings_lines_are_the_def_lines():
tree = lps.parse_tree("python", SRC.encode())
found = {(kind, name): line for kind, line, name, _ in harvest_docstrings(tree)}
lines = SRC.splitlines()
def line_of(prefix: str) -> int:
return next(i for i, text in enumerate(lines, 1) if text.lstrip().startswith(prefix))
assert found == {
("function", "doxy"): line_of("def doxy"),
("function", "pep"): line_of("def pep"),
("class", "Thing"): line_of("class Thing"),
("function", "method"): line_of("def method"),
}, "the def line, not the decorator's: that is the line doxygen records"
assert found[("function", "pep")] == line_of("@decorated") + 1
Activity · 6 steps
test_rows_are_located_on_the_lookups_own_file_key
test_pydocs.test_rows_are_located_on_the_lookups_own_file_key()
A member is keyed by its body file, else its declaring file; a class by its file.
Checks
assert located == {
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-013 | catalog |
Source · 22 lines
def test_rows_are_located_on_the_lookups_own_file_key():
"""A member is keyed by its body file, else its declaring file; a class by its file.
`_enrich_one` only searches the rowids filed under its key, so a key that differs
from its WHERE clause would silently drop rows the full scan used to find.
"""
from clew.pydocs import _locate_rows
conn = sqlite3.connect(":memory:")
conn.execute("CREATE TABLE memberdef (name TEXT, file_id INT, bodyfile_id INT, line INT)")
conn.execute("CREATE TABLE compounddef (name TEXT, file_id INT, line INT)")
conn.execute("INSERT INTO memberdef VALUES ('decl_only', 1, 0, 3)")
conn.execute("INSERT INTO memberdef VALUES ('decl_only_null', 1, NULL, 4)")
conn.execute("INSERT INTO memberdef VALUES ('defined', 1, 2, 5)")
conn.execute("INSERT INTO compounddef VALUES ('mod::C', 2, 7)")
located = _locate_rows(conn)
assert located == {
("memberdef", 1, 3): [1],
("memberdef", 1, 4): [2],
("memberdef", 2, 5): [3],
("compounddef", 2, 7): [1],
}1 more lines, not shown
Activity · 10 steps
test_summarize_takes_the_pep257_summary_and_version
test_pydocs.test_summarize_takes_the_pep257_summary_and_version()
Checks
assert summarize("Return the answer.\n\nLonger detail.\n\n@version 2\n") == ("Return the answer.", "2", )assert summarize("Multi-line\nsummary.\n\nBody.") == ("Multi-line summary.", "")assert summarize("Prose.\n@brief Stated.") == ("Stated.", ""), "an explicit brief wins"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-019 | measured | test_summarize_takes_the_pep257_summary_and_version → summarize → parse_doxygen_tags |
| REQ-DDB-GUARD-024 | measured | test_summarize_takes_the_pep257_summary_and_version → summarize → apply_autobrief |
| REQ-DDB-PIPE-013 | measured | test_summarize_takes_the_pep257_summary_and_version → summarize |
Source · 10 lines
def test_summarize_takes_the_pep257_summary_and_version():
assert summarize("Return the answer.\n\nLonger detail.\n\n@version 2\n") == (
"Return the answer.",
"2",
)
assert summarize("Multi-line\nsummary.\n\nBody.") == ("Multi-line summary.", "")
assert summarize("Prose.\n@brief Stated.") == ("Stated.", ""), "an explicit brief wins"
@pytest.mark.skipif(shutil.which("doxygen") is None, reason="enriches real doxygen rows")