test_macro_refs_caller_file.py

tests/test_macro_refs_caller_file.py

A recovered macro reference is credited to the function in the file it was read from.

test_a_body_with_only_a_prototype_elsewhere_resolves_by_its_unique_name

None test_macro_refs_caller_file.test_a_body_with_only_a_prototype_elsewhere_resolves_by_its_unique_name(Path db, Path tmp_path, pytest.MonkeyPatch monkeypatch)

Unique names fall back; shared names do not.

tests/test_macro_refs_caller_file.py:64

Checks

  • assert got == [(40, 1)]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_a_body_with_only_a_prototype_elsewhere_resolves_by_its_unique_name → import_ast_macro_refs
REQ-DDB-PIPE-011inferredtest_a_body_with_only_a_prototype_elsewhere_resolves_by_its_unique_name → import_ast_macro_refs → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_a_body_with_only_a_prototype_elsewhere_resolves_by_its_unique_name → import_ast_macro_refs → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
Source · 22 lines
def test_a_body_with_only_a_prototype_elsewhere_resolves_by_its_unique_name(
    db: Path, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
    """A function whose definition row is missing (the parser dropped it, or only a header
    prototype carries the name) keeps its edge when no other function shares the name; `help`,
    which is shared, does not fall back.

    @brief Unique names fall back; shared names do not. @version 1
    """
    conn = sqlite3.connect(db)
    conn.execute("INSERT INTO memberdef VALUES (40, 'step', 'function', 5, NULL)")
    conn.commit()
    conn.close()
    payloads = [(6, [("step", "LOG", 9), ("help", "LOG", 12)])]
    monkeypatch.setattr(macro_refs, "run_harvest", lambda *a, **k: payloads)

    macro_refs.import_ast_macro_refs(db, tmp_path)

    conn = sqlite3.connect(db)
    got = sorted(conn.execute("SELECT src_rowid, dst_rowid FROM xrefs"))
    conn.close()
    assert got == [(40, 1)]

1 more lines, not shown

Activity · 11 steps
lines 73–73conn = sqlite3.connect(db)lines 74–74conn.execute("INSERT INTO memberdef VALUES (40, 'step', 'function', 5, NULL)")lines 75–75conn.commit()lines 76–76conn.close()lines 77–77payloads = [(6, [("step", "LOG", 9), ("help", "LOG", 12)])]lines 78–78monkeypatch.setattr(macro_refs, "run_harvest", lambda *a, **k: payloads)lines 80–80macro_refs.import_ast_macro_refs(db, tmp_path)lines 82–82conn = sqlite3.connect(db)lines 83–83got = sorted(conn.execute("SELECT src_rowid, dst_rowid FROM xrefs"))lines 84–84conn.close()lines 85–85assert got == [(40, 1)]

test_each_copy_of_a_function_keeps_its_own_macro_reference

None test_macro_refs_caller_file.test_each_copy_of_a_function_keeps_its_own_macro_reference(Path db, Path tmp_path, pytest.MonkeyPatch monkeypatch)

Both C copies get the edge and the shell function gets none.

tests/test_macro_refs_caller_file.py:46

Checks

  • assert got == [(10, 1, "ast"), (20, 1, "ast")]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-003measuredtest_each_copy_of_a_function_keeps_its_own_macro_reference → import_ast_macro_refs
REQ-DDB-PIPE-011inferredtest_each_copy_of_a_function_keeps_its_own_macro_reference → import_ast_macro_refs → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_each_copy_of_a_function_keeps_its_own_macro_reference → import_ast_macro_refs → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
Source · 18 lines
def test_each_copy_of_a_function_keeps_its_own_macro_reference(
    db: Path, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
    """Files 1 and 2 use the macro inside `help`; file 3 (the shell script, last row) does not.

    @brief Both C copies get the edge and the shell function gets none. @version 1
    """
    payloads = [(1, [("help", "LOG", 4)]), (2, [("help", "LOG", 4)]), (3, [])]
    monkeypatch.setattr(macro_refs, "run_harvest", lambda *a, **k: payloads)

    macro_refs.import_ast_macro_refs(db, tmp_path)

    conn = sqlite3.connect(db)
    got = sorted(conn.execute("SELECT src_rowid, dst_rowid, context FROM xrefs"))
    conn.close()
    assert got == [(10, 1, "ast"), (20, 1, "ast")]

Activity · 7 steps
lines 53–53payloads = [(1, [("help", "LOG", 4)]), (2, [("help", "LOG", 4)]), (3, [])]lines 54–54monkeypatch.setattr(macro_refs, "run_harvest", lambda *a, **k: payloads)lines 56–56macro_refs.import_ast_macro_refs(db, tmp_path)lines 58–58conn = sqlite3.connect(db)lines 59–59got = sorted(conn.execute("SELECT src_rowid, dst_rowid, context FROM xrefs"))lines 60–60conn.close()lines 61–61assert got == [(10, 1, "ast"), (20, 1, "ast")]