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.

tests/test_pydocs.py:115

Show on the map →

Called by none

Calls _enrich_one

Checks

  • 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()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-013catalog
REQ-DDB-QUERY-003measuredtest_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
lines 117–117from clew.pydocs import _enrich_onelines 119–119db = tmp_path / "x.db"lines 120–120conn = sqlite3.connect(db)lines 121–124conn.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)" )lines 125–125conn.execute("INSERT INTO memberdef VALUES (1, 'f', 1, 1, 3, '', '', 'ast')")lines 126–126conn.execute("INSERT INTO memberdef VALUES (2, 'g', 1, 1, 9, '', '', 'doxygen')")lines 127–127assert _enrich_one(conn, "function", 1, 3, "f", "Sum.", "", True, [1]) == 0lines 128–128assert _enrich_one(conn, "function", 1, 9, "g", "Sum.", "", True, [2]) == 1lines 129–129assert Path(db).exists()

test_build_fills_only_what_doxygen_left_bare

test_pydocs.test_build_fills_only_what_doxygen_left_bare(tmp_path)

tests/test_pydocs.py:85

Show on the map →

Called by none

Calls _build_argparser, _run_pipeline, extract_version, strip_xml

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

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → report_stats
REQ-DDB-CLI-002inferredtest_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-001measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _apply_declared_document → stated_document_meta
REQ-DDB-CONFIG-003inferredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_requirements_yaml → _is_flat_req_list
REQ-DDB-CONFIG-004measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → resolve_preprocessor
REQ-DDB-CONFIG-005measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_kconfig
REQ-DDB-CONFIG-006measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _recorded_entry_patterns → recorded_explicit
REQ-DDB-CONFIG-007measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → write_build_signature
REQ-DDB-CONFIG-009measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _apply_toolchain_exclusions → load_toolchain_config
REQ-DDB-GUARD-012inferredtest_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-019measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_python_docstrings → summarize → parse_doxygen_tags
REQ-DDB-GUARD-024measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_python_docstrings → summarize → apply_autobrief
REQ-DDB-INDEX-001measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _verify_extra_input_is_read → effective_file_patterns
REQ-DDB-INDEX-002measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → build_lock
REQ-DDB-INDEX-003measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → report_index_coverage
REQ-DDB-INDEX-004measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → recover_ast_symbols
REQ-DDB-INDEX-005measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → stamp_external_provenance
REQ-DDB-INDEX-006measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → record_code_text → code_text_rows
REQ-DDB-INDEX-007measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → record_owners
REQ-DDB-INDEX-008measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_file_licenses
REQ-DDB-INDEX-009measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_kerneldoc
REQ-DDB-INDEX-010measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_ast_includes
REQ-DDB-INDEX-011measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_property_keys
REQ-DDB-MCP-001measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _operator_excludes → meta_section
REQ-DDB-MCP-004measured
REQ-DDB-PIPE-001measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_database
REQ-DDB-PIPE-003measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → build_call_edges
REQ-DDB-PIPE-004measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → python_entry_seeds
REQ-DDB-PIPE-005measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → write_build_signature
REQ-DDB-PIPE-006measuredtest_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-007measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_kconfig_gates
REQ-DDB-PIPE-008measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_file_docs
REQ-DDB-PIPE-009measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → prune_dominated_fuzzy_call_edges
REQ-DDB-PIPE-010measuredtest_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-011measuredtest_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-012measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → build_harvest_plan → js_symbol_harvester
REQ-DDB-PIPE-013measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → enrich_python_docstrings
REQ-DDB-PIPE-014measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_kerneldoc → within_repo
REQ-DDB-PIPE-015measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_config_defaults
REQ-DDB-QUERY-003measuredtest_build_fills_only_what_doxygen_left_bare → strip_xml
REQ-DDB-QUERY-011measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-001measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → extract_threads
REQ-DDB-SCHEMA-002measuredtest_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-003measuredtest_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-004measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → load_dispatch_manifest
REQ-DDB-SCHEMA-005measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → resolve_key_alias_prefixes
REQ-DDB-SCHEMA-006measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_requirements_yaml
REQ-DDB-SCHEMA-007measuredtest_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-009measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_event_edges
REQ-DDB-SCHEMA-011measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → extract_context_conflicts
REQ-DDB-SCHEMA-012measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → load_dispatch_manifest → declaration_origin
REQ-DDB-SCHEMA-013measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → import_data_model_keys
REQ-DDB-SCHEMA-014measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_file_docs → ensure_file_docs_table
REQ-DDB-SCHEMA-015measuredtest_build_fills_only_what_doxygen_left_bare → _run_pipeline → _run_pipeline_inner → _build_stages → ingest_requirements_yaml
REQ-DDB-WIKI-054inferredtest_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
lines 86–86repo = tmp_path / "repo"lines 87–87(repo / "pkg").mkdir(parents=True)lines 88–88(repo / "pkg" / "mod.py").write_text(SRC, encoding="utf-8")lines 89–89out = tmp_path / "clew.db"lines 90–90_run_pipeline(_build_argparser().parse_args(["--output", str(out), "--repo-root", str(repo)]))lines 91–91conn = sqlite3.connect(out)lines 92–98rows = { 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'" ) }lines 99–99assert rows["doxy"] == ("Doxygen-documented.", "4", "doxygen"), "a ## block is never replaced"lines 100–100assert rows["pep"] == ("Return the answer.", "2", "doxygen")lines 101–101assert rows["method"][0] == "Do the thing."lines 102–102assert rows["bare"][0] == "", "no docstring, nothing invented"lines 103–105classes = dict( conn.execute("SELECT name, briefdescription FROM compounddef WHERE kind='class'") )lines 106–106assert strip_xml(classes["mod::Thing"]) == "A documented class."lines 107–109req = conn.execute( "SELECT COUNT(*) FROM memberdef WHERE name='pep' AND detaileddescription LIKE '%REQ-X-001%'" ).fetchone()[0]lines 110–112assert req == 1, ( "the @req stays in doxygen's verbatim detail, where the requirements pass reads it" )

test_harvest_docstrings_lines_are_the_def_lines

test_pydocs.test_harvest_docstrings_lines_are_the_def_lines()

tests/test_pydocs.py:58

Checks

  • assert found == {
  • assert found[("function", "pep")] == line_of("@decorated") + 1

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-013measuredtest_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
lines 59–59tree = lps.parse_tree("python", SRC.encode())lines 60–60found = {(kind, name): line for kind, line, name, _ in harvest_docstrings(tree)}lines 61–61lines = SRC.splitlines()lines 63–64def line_of(prefix: str) -> int: return next(i for i, text in enumerate(lines, 1) if text.lstrip().startswith(prefix))lines 66–71assert 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"lines 72–72assert found[("function", "pep")] == line_of("@decorated") + 1

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.

tests/test_pydocs.py:132

Show on the map →

Called by none

Calls _locate_rows

Checks

  • assert located == {

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-013catalog
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
lines 138–138from clew.pydocs import _locate_rowslines 140–140conn = sqlite3.connect(":memory:")lines 141–141conn.execute("CREATE TABLE memberdef (name TEXT, file_id INT, bodyfile_id INT, line INT)")lines 142–142conn.execute("CREATE TABLE compounddef (name TEXT, file_id INT, line INT)")lines 143–143conn.execute("INSERT INTO memberdef VALUES ('decl_only', 1, 0, 3)")lines 144–144conn.execute("INSERT INTO memberdef VALUES ('decl_only_null', 1, NULL, 4)")lines 145–145conn.execute("INSERT INTO memberdef VALUES ('defined', 1, 2, 5)")lines 146–146conn.execute("INSERT INTO compounddef VALUES ('mod::C', 2, 7)")lines 147–147located = _locate_rows(conn)lines 148–153assert located == { ("memberdef", 1, 3): [1], ("memberdef", 1, 4): [2], ("memberdef", 2, 5): [3], ("compounddef", 2, 7): [1], }

test_summarize_takes_the_pep257_summary_and_version

test_pydocs.test_summarize_takes_the_pep257_summary_and_version()

tests/test_pydocs.py:75

Show on the map →

Called by none

Calls summarize

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

requirementlinkedpath to the implementer
REQ-DDB-GUARD-019measuredtest_summarize_takes_the_pep257_summary_and_version → summarize → parse_doxygen_tags
REQ-DDB-GUARD-024measuredtest_summarize_takes_the_pep257_summary_and_version → summarize → apply_autobrief
REQ-DDB-PIPE-013measuredtest_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")