test_doxygen_exclude_walk.py

tests/test_doxygen_exclude_walk.py

An excluded directory is pruned from doxygen's walk, not read and then discarded.

test_an_absolute_directory_exclude_becomes_an_anchored_pattern

None test_doxygen_exclude_walk.test_an_absolute_directory_exclude_becomes_an_anchored_pattern(Path tmp_path)

Directory excludes are rewritten; files, relative and glob-shaped paths are not.

tests/test_doxygen_exclude_walk.py:53

Checks

  • assert f"EXCLUDE_PATTERNS += {vendored}/*" in content
  • assert f"EXCLUDE += {vendored}\n" not in content, "the EXCLUDE entry alone costs the read"
  • assert f"EXCLUDE += {scratch}" in content
  • assert "EXCLUDE += relative/dir" in content
  • assert f"EXCLUDE += {globby}" in content
  • assert content.index("\nEXCLUDE_PATTERNS =\n") < content.index(f"EXCLUDE_PATTERNS += {vendored}/*" ), "the pattern must follow the clear, or the clear erases it"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-001measuredtest_an_absolute_directory_exclude_becomes_an_anchored_pattern → synthesize_doxyfile
REQ-DDB-PIPE-003measuredtest_an_absolute_directory_exclude_becomes_an_anchored_pattern → _build_doxyfile_content → extra_input_clears_exclude
Source · 34 lines
def test_an_absolute_directory_exclude_becomes_an_anchored_pattern(tmp_path: Path) -> None:
    """THE SHAPE. A directory goes to `EXCLUDE_PATTERNS` as `<absolute dir>/*` — anchored at
    its own absolute path, so it cannot match a same-named directory elsewhere the way
    `*/vendored/*` would — and is NOT also left in `EXCLUDE`, because that entry alone is what
    costs the read. A file, a relative path, and a path whose name contains wildcard characters
    stay in `EXCLUDE`: a pattern matches doxygen's absolute path, and a `[` in a directory name
    would be read as a character class.

    @brief Directory excludes are rewritten; files, relative and glob-shaped paths are not.
    @version 1
    """
    root, vendored, scratch = _tree(tmp_path / "repo")
    globby = root / "deps" / "odd[1]"
    globby.mkdir()
    doxyfile = synthesize_doxyfile(root, tmp_path / "synth")

    content = _build_doxyfile_content(
        doxyfile,
        [str(root)],
        [str(vendored), str(scratch), "relative/dir", str(globby)],
        replace_input=True,
    )

    assert f"EXCLUDE_PATTERNS += {vendored}/*" in content
    assert f"EXCLUDE += {vendored}\n" not in content, "the EXCLUDE entry alone costs the read"
    assert f"EXCLUDE += {scratch}" in content
    assert "EXCLUDE += relative/dir" in content
    assert f"EXCLUDE += {globby}" in content
    assert content.index("\nEXCLUDE_PATTERNS =\n") < content.index(
        f"EXCLUDE_PATTERNS += {vendored}/*"
    ), "the pattern must follow the clear, or the clear erases it"


@pytest.mark.skipif(shutil.which("doxygen") is None, reason="asserted against real doxygen")

test_the_pattern_excludes_exactly_what_the_directory_exclude_did

None test_doxygen_exclude_walk.test_the_pattern_excludes_exactly_what_the_directory_exclude_did(Path tmp_path)

Doxygen indexes the same files with the rewritten excludes.

tests/test_doxygen_exclude_walk.py:87

Checks

  • assert any(n.endswith("src/kept.c") for n in names), names
  • assert not any("deps/vendored" in n for n in names), names
  • assert not any(n.endswith("scratch.c") for n in names), names

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-001measuredtest_the_pattern_excludes_exactly_what_the_directory_exclude_did → synthesize_doxyfile
REQ-DDB-PIPE-003measuredtest_the_pattern_excludes_exactly_what_the_directory_exclude_did → _build_doxyfile_content → extra_input_clears_exclude
Source · 24 lines
def test_the_pattern_excludes_exactly_what_the_directory_exclude_did(tmp_path: Path) -> None:
    """THE EQUIVALENCE, AGAINST DOXYGEN ITSELF. The rewrite is only a speedup if doxygen indexes
    the same files. So the kept file is indexed, and nothing under the excluded directory is,
    nested subdirectory included. The excluded single file is also absent.

    @brief Doxygen indexes the same files with the rewritten excludes.
    @version 1
    """
    root, vendored, scratch = _tree(tmp_path / "repo")
    doxyfile = synthesize_doxyfile(root, tmp_path / "synth")
    out = tmp_path / "out"
    content = _build_doxyfile_content(
        doxyfile, [str(root)], [str(vendored), str(scratch)], replace_input=True, output_dir=out
    )

    subprocess.run(
        ["doxygen", "-"], input=content, text=True, capture_output=True, cwd=root, check=True
    )

    db = next(out.rglob("doxygen_sqlite3.db"))
    names = {r[0] for r in sqlite3.connect(db).execute("SELECT name FROM path WHERE type=1")}
    assert any(n.endswith("src/kept.c") for n in names), names
    assert not any("deps/vendored" in n for n in names), names
    assert not any(n.endswith("scratch.c") for n in names), names

1 more lines, not shown

Activity · 10 steps
lines 95–95root, vendored, scratch = _tree(tmp_path / "repo")lines 96–96doxyfile = synthesize_doxyfile(root, tmp_path / "synth")lines 97–97out = tmp_path / "out"lines 98–100content = _build_doxyfile_content( doxyfile, [str(root)], [str(vendored), str(scratch)], replace_input=True, output_dir=out )lines 102–104subprocess.run( ["doxygen", "-"], input=content, text=True, capture_output=True, cwd=root, check=True )lines 106–106db = next(out.rglob("doxygen_sqlite3.db"))lines 107–107names = {r[0] for r in sqlite3.connect(db).execute("SELECT name FROM path WHERE type=1")}lines 108–108assert any(n.endswith("src/kept.c") for n in names), nameslines 109–109assert not any("deps/vendored" in n for n in names), nameslines 110–110assert not any(n.endswith("scratch.c") for n in names), names