test_script_front_end.py

tests/test_script_front_end.py

Shell, CMake, YAML and JSON reach the index — and each gets what its file type is.

test_a_file_merely_ending_in_the_cmake_name_is_not_cmake

None test_script_front_end.test_a_file_merely_ending_in_the_cmake_name_is_not_cmake()

The CMake name matches as a component, not as a suffix.

tests/test_script_front_end.py:213

Checks

  • assert claims("CMakeLists.txt")
  • assert claims("src/CMakeLists.txt")
  • assert not claims("oldcmakelists.txt")
  • assert not claims("src/vendor-CMakeLists.txt")
  • assert _ts_language_for("src/CMakeLists.txt") is not None
  • assert _ts_language_for("oldcmakelists.txt") is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measuredtest_a_file_merely_ending_in_the_cmake_name_is_not_cmake → has_language
Source · 16 lines
def test_a_file_merely_ending_in_the_cmake_name_is_not_cmake() -> None:
    """THE SUFFIX TRAP. Both the router and `claims` match `CMakeLists.txt` by name, and the
    cheap way to express that in a suffix table — `endswith("cmakelists.txt")` — also
    matches `oldcmakelists.txt` and `vendor-cmakelists.txt`. The name is a whole path
    component, so that is what is tested.

    @brief The CMake name matches as a component, not as a suffix. @version 1
    """
    assert claims("CMakeLists.txt")
    assert claims("src/CMakeLists.txt")
    assert not claims("oldcmakelists.txt")
    assert not claims("src/vendor-CMakeLists.txt")

    if substrate.has_language("cmake"):
        assert _ts_language_for("src/CMakeLists.txt") is not None
        assert _ts_language_for("oldcmakelists.txt") is None

1 more lines, not shown

Activity · 7 steps
lines 221–221assert claims("CMakeLists.txt")lines 222–222assert claims("src/CMakeLists.txt")lines 223–223assert not claims("oldcmakelists.txt")lines 224–224assert not claims("src/vendor-CMakeLists.txt")lines 226–226◇ if substrate.has_language("cmake")lines 227–227assert _ts_language_for("src/CMakeLists.txt") is not Nonelines 228–228assert _ts_language_for("oldcmakelists.txt") is None

test_a_missing_grammar_routes_to_nothing_instead_of_raising

None test_script_front_end.test_a_missing_grammar_routes_to_nothing_instead_of_raising(pytest.MonkeyPatch monkeypatch)

An absent optional grammar resolves to None.

tests/test_script_front_end.py:128

Checks

  • assert _ts_language_for("scripts/deploy.sh") is None
  • assert _ts_language_for("CMakeLists.txt") is None
  • assert _ts_language_for("src/main.c") is not None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012inferredtest_a_missing_grammar_routes_to_nothing_instead_of_raising → _ts_language_for → _grammar_available → has_language
Source · 16 lines
def test_a_missing_grammar_routes_to_nothing_instead_of_raising(
    monkeypatch: pytest.MonkeyPatch,
) -> None:
    """THE DEGRADE, pinned. `parse_tree` raises ValueError for an unknown key, so the
    router must refuse the route rather than hand the build a grammar it cannot use.

    @brief An absent optional grammar resolves to None. @version 1
    """
    monkeypatch.setattr(substrate, "has_language", lambda key: key not in {"bash", "cmake"})
    assert _ts_language_for("scripts/deploy.sh") is None
    assert _ts_language_for("CMakeLists.txt") is None
    ## The always-present grammars are NOT gated: a wheel without them is a broken
    ## install, and failing loudly is correct there.
    assert _ts_language_for("src/main.c") is not None

Activity · 4 steps
lines 136–136monkeypatch.setattr(substrate, "has_language", lambda key: key not in {"bash", "cmake"})lines 137–137assert _ts_language_for("scripts/deploy.sh") is Nonelines 138–138assert _ts_language_for("CMakeLists.txt") is Nonelines 141–141assert _ts_language_for("src/main.c") is not None

test_a_shell_script_routes_to_the_bash_grammar

None test_script_front_end.test_a_shell_script_routes_to_the_bash_grammar()

`.sh` resolves a grammar.

tests/test_script_front_end.py:104

Checks

  • assert grammar is not None
  • assert grammar.key == "bash"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measuredtest_a_shell_script_routes_to_the_bash_grammar → has_language
Source · 9 lines
def test_a_shell_script_routes_to_the_bash_grammar() -> None:
    """@brief `.sh` resolves a grammar. @version 1"""
    if not substrate.has_language("bash"):
        pytest.skip("substrate has no bash grammar; clew requires lang-parsing-substrate>=0.12.0")
    grammar = _ts_language_for("scripts/deploy.sh")
    assert grammar is not None
    assert grammar.key == "bash"

Activity · 5 steps
lines 106–106◇ if not substrate.has_language("bash")lines 107–107pytest.skip("substrate has no bash grammar; clew requires lang-parsing-substrate>=0.12.0")lines 108–108grammar = _ts_language_for("scripts/deploy.sh")lines 109–109assert grammar is not Nonelines 110–110assert grammar.key == "bash"

test_shell_and_cmake_definitions_become_rows

None test_script_front_end.test_shell_and_cmake_definitions_become_rows(tuple[Path, Path] repo)

A shell function and a CMake function and macro are written as rows.

tests/test_script_front_end.py:173

Checks

  • assert members == {

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-019measured
REQ-DDB-GUARD-024measured
REQ-DDB-INDEX-004measuredtest_shell_and_cmake_definitions_become_rows → emit_definitions → ensure_symbol_provenance
REQ-DDB-PIPE-003measuredtest_shell_and_cmake_definitions_become_rows → emit_definitions → run_harvest
REQ-DDB-PIPE-011measuredtest_shell_and_cmake_definitions_become_rows → emit_definitions → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012measuredtest_shell_and_cmake_definitions_become_rows → missing_languages
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-014measuredtest_shell_and_cmake_definitions_become_rows → emit_definitions → ensure_generated_files_table
Source · 21 lines
def test_shell_and_cmake_definitions_become_rows(repo: tuple[Path, Path]) -> None:
    """The end-to-end path: registration, the shared harvest's dispatch, and the writer.

    @brief A shell function and a CMake function and macro are written as rows. @version 1
    """
    db, root = repo
    missing = substrate.missing_languages(("bash", "cmake"))
    if missing:
        pytest.skip(f"substrate lacks {missing}; clew requires lang-parsing-substrate>=0.12.0")

    register_paths(db, ["scripts/deploy.sh", "CMakeLists.txt", "config.yaml"])
    emit_definitions(db, root, None)

    members = _members(db)
    assert members == {
        "deploy": "function",
        "add_firmware": "function",
        "strict_warnings": "macro definition",
    }

Activity · 8 steps
lines 178–178db, root = repolines 179–179missing = substrate.missing_languages(("bash", "cmake"))lines 180–180◇ if missinglines 181–181pytest.skip(f"substrate lacks {missing}; clew requires lang-parsing-substrate>=0.12.0")lines 183–183register_paths(db, ["scripts/deploy.sh", "CMakeLists.txt", "config.yaml"])lines 184–184emit_definitions(db, root, None)lines 186–186members = _members(db)lines 187–191assert members == { "deploy": "function", "add_firmware": "function", "strict_warnings": "macro definition", }

test_the_cmake_file_name_routes_even_though_its_extension_is_txt

None test_script_front_end.test_the_cmake_file_name_routes_even_though_its_extension_is_txt()

The CMake file name routes; a plain `.txt` does not.

tests/test_script_front_end.py:113

Checks

  • assert named is not None and named.key == "cmake"
  • assert _ts_language_for("src/CMakeLists.txt") is not None
  • assert _ts_language_for("notes.txt") is None
  • assert _ts_language_for("requirements.txt") is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measuredtest_the_cmake_file_name_routes_even_though_its_extension_is_txt → has_language
Source · 15 lines
def test_the_cmake_file_name_routes_even_though_its_extension_is_txt() -> None:
    """`CMakeLists.txt` is named, not suffixed — and `.txt` must NOT route to CMake, or
    every README.txt in the tree would be parsed as a build script.

    @brief The CMake file name routes; a plain `.txt` does not. @version 1
    """
    if not substrate.has_language("cmake"):
        pytest.skip("substrate has no cmake grammar; clew requires lang-parsing-substrate>=0.12.0")
    named = _ts_language_for("CMakeLists.txt")
    assert named is not None and named.key == "cmake"
    assert _ts_language_for("src/CMakeLists.txt") is not None
    assert _ts_language_for("notes.txt") is None
    assert _ts_language_for("requirements.txt") is None

Activity · 7 steps
lines 119–119◇ if not substrate.has_language("cmake")lines 120–120pytest.skip("substrate has no cmake grammar; clew requires lang-parsing-substrate>=0.12.0")lines 121–121named = _ts_language_for("CMakeLists.txt")lines 122–122assert named is not None and named.key == "cmake"lines 123–123assert _ts_language_for("src/CMakeLists.txt") is not Nonelines 124–124assert _ts_language_for("notes.txt") is Nonelines 125–125assert _ts_language_for("requirements.txt") is None

test_the_data_files_are_in_the_file_set_with_no_symbols

None test_script_front_end.test_the_data_files_are_in_the_file_set_with_no_symbols(tuple[Path, Path] repo)

YAML and JSON are registered and carry no memberdef rows.

tests/test_script_front_end.py:161

Show on the map →

Called by none

Calls _members, _paths, emit_definitions, register_paths

Checks

  • assert _paths(db) == {"config.yaml", "data.json"}
  • assert _members(db) == {}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-004measuredtest_the_data_files_are_in_the_file_set_with_no_symbols → emit_definitions → ensure_symbol_provenance
REQ-DDB-PIPE-003measuredtest_the_data_files_are_in_the_file_set_with_no_symbols → emit_definitions → run_harvest
REQ-DDB-PIPE-011inferredtest_the_data_files_are_in_the_file_set_with_no_symbols → emit_definitions → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012measuredtest_the_data_files_are_in_the_file_set_with_no_symbols → emit_definitions
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-014measuredtest_the_data_files_are_in_the_file_set_with_no_symbols → emit_definitions → ensure_generated_files_table
Source · 12 lines
def test_the_data_files_are_in_the_file_set_with_no_symbols(repo: tuple[Path, Path]) -> None:
    """@brief YAML and JSON are registered and carry no memberdef rows. @version 1"""
    db, root = repo
    scanned = ["config.yaml", "data.json", "src/main.c"]

    register_paths(db, scanned)

    assert _paths(db) == {"config.yaml", "data.json"}
    emit_definitions(db, root, None)
    assert _members(db) == {}

Activity · 6 steps
lines 163–163db, root = repolines 164–164scanned = ["config.yaml", "data.json", "src/main.c"]lines 166–166register_paths(db, scanned)lines 168–168assert _paths(db) == {"config.yaml", "data.json"}lines 169–169emit_definitions(db, root, None)lines 170–170assert _members(db) == {}

test_the_shell_doc_block_reaches_the_row

None test_script_front_end.test_the_shell_doc_block_reaches_the_row(tuple[Path, Path] repo)

The `#` block above a shell function becomes its brief.

tests/test_script_front_end.py:194

Checks

  • assert "Deploy the built artefact." in brief

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-019measured
REQ-DDB-GUARD-024measured
REQ-DDB-INDEX-004measuredtest_the_shell_doc_block_reaches_the_row → emit_definitions → ensure_symbol_provenance
REQ-DDB-PIPE-003measuredtest_the_shell_doc_block_reaches_the_row → emit_definitions → run_harvest
REQ-DDB-PIPE-011measuredtest_the_shell_doc_block_reaches_the_row → emit_definitions → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012measuredtest_the_shell_doc_block_reaches_the_row → has_language
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-014measuredtest_the_shell_doc_block_reaches_the_row → emit_definitions → ensure_generated_files_table
Source · 19 lines
def test_the_shell_doc_block_reaches_the_row(repo: tuple[Path, Path]) -> None:
    """@brief The `#` block above a shell function becomes its brief. @version 1"""
    db, root = repo
    if not substrate.has_language("bash"):
        pytest.skip("substrate has no bash grammar; clew requires lang-parsing-substrate>=0.12.0")

    register_paths(db, ["scripts/deploy.sh"])
    emit_definitions(db, root, None)

    conn = sqlite3.connect(str(db))
    try:
        brief = conn.execute(
            "SELECT briefdescription FROM memberdef WHERE name = 'deploy'"
        ).fetchone()[0]
    finally:
        conn.close()
    assert "Deploy the built artefact." in brief

Activity · 9 steps
lines 196–196db, root = repolines 197–197◇ if not substrate.has_language("bash")lines 198–198pytest.skip("substrate has no bash grammar; clew requires lang-parsing-substrate>=0.12.0")lines 200–200register_paths(db, ["scripts/deploy.sh"])lines 201–201emit_definitions(db, root, None)lines 203–203conn = sqlite3.connect(str(db))lines 204–204trylines 205–207brief = conn.execute( "SELECT briefdescription FROM memberdef WHERE name = 'deploy'" ).fetchone()[0]lines 210–210assert "Deploy the built artefact." in brief