test_python_class_fields.py¶
tests/test_python_class_fields.py
gh#17 — the Python class attributes doxygen never emits.
test_a_dropped_field_is_inserted_and_linked_to_its_class
None test_python_class_fields.test_a_dropped_field_is_inserted_and_linked_to_its_class()
A `memberdef` row alone is not the answer here, which is what separates this from every other recovery in the module. The existing kinds are file-scope, so a row IS the result; a class attribute is reachable only through `member(scope_rowid, memberdef_rowid)`, and a row without that link is present in the table and absent from every class view — the same defect one layer in.
tests/test_python_class_fields.py:202
Checks
assert _recover_class_fields_into(conn, harvested) == 1assert _members(conn, "a::Config") == [("name", "str", "ast")]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_a_dropped_field_is_inserted_and_linked_to_its_class → _recover_class_fields_into |
| REQ-DDB-WIKI-054 | inferred | test_a_dropped_field_is_inserted_and_linked_to_its_class → _recover_class_fields_into → all |
Source · 12 lines
def test_a_dropped_field_is_inserted_and_linked_to_its_class() -> None:
"""A `memberdef` row alone is not the answer here, which is what separates this from
every other recovery in the module. The existing kinds are file-scope, so a row IS the
result; a class attribute is reachable only through `member(scope_rowid,
memberdef_rowid)`, and a row without that link is present in the table and absent from
every class view — the same defect one layer in."""
conn = _index()
harvested = [(1, {"class_fields": [["name", "Config", "str", 7]]})]
assert _recover_class_fields_into(conn, harvested) == 1
assert _members(conn, "a::Config") == [("name", "str", "ast")]
Activity · 4 steps
test_a_field_doxygen_already_emitted_is_not_duplicated
None test_python_class_fields.test_a_field_doxygen_already_emitted_is_not_duplicated()
The harvest deliberately collects EVERY annotated field, including the ones doxygen emitted, because which are present is a fact about the database rather than the source. The dedup therefore has to happen here, against the existing links — and if it does not, a class ends up with two rows for one attribute, which is gh#19's defect reintroduced through the back door.
tests/test_python_class_fields.py:214
Checks
assert _recover_class_fields_into(conn, harvested) == 1, "only the missing one is inserted"assert _members(conn, "a::Config") == [("brief", "str", "doxygen"), ("name", "str", "ast")]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_a_field_doxygen_already_emitted_is_not_duplicated → _recover_class_fields_into |
| REQ-DDB-WIKI-054 | inferred | test_a_field_doxygen_already_emitted_is_not_duplicated → _recover_class_fields_into → all |
Source · 20 lines
def test_a_field_doxygen_already_emitted_is_not_duplicated() -> None:
"""The harvest deliberately collects EVERY annotated field, including the ones doxygen
emitted, because which are present is a fact about the database rather than the source.
The dedup therefore has to happen here, against the existing links — and if it does not,
a class ends up with two rows for one attribute, which is gh#19's defect reintroduced
through the back door."""
conn = _index()
conn.execute(
"INSERT INTO memberdef (rowid, name, type, kind, file_id, line) "
"VALUES (99, 'brief', 'str', 'variable', 1, 9)"
)
conn.execute("INSERT INTO member (scope_rowid, memberdef_rowid, prot, virt) VALUES (10,99,0,0)")
harvested = [
(1, {"class_fields": [["brief", "Config", "str", 9], ["name", "Config", "str", 7]]})
]
assert _recover_class_fields_into(conn, harvested) == 1, "only the missing one is inserted"
assert _members(conn, "a::Config") == [("brief", "str", "doxygen"), ("name", "str", "ast")]
Activity · 6 steps
test_a_field_whose_class_is_not_indexed_is_skipped
None test_python_class_fields.test_a_field_whose_class_is_not_indexed_is_skipped()
FAILS CLOSED. A class the index does not hold — excluded by scope, or in a file doxygen did not parse — gives nothing to attach to, and inventing a compound would put a class in the index that no other layer knows about. The attribute is dropped, which is the state before this stage existed.
tests/test_python_class_fields.py:249
Checks
assert _recover_class_fields_into(conn, harvested) == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_a_field_whose_class_is_not_indexed_is_skipped → _recover_class_fields_into |
| REQ-DDB-WIKI-054 | inferred | test_a_field_whose_class_is_not_indexed_is_skipped → _recover_class_fields_into → all |
Source · 10 lines
def test_a_field_whose_class_is_not_indexed_is_skipped() -> None:
"""FAILS CLOSED. A class the index does not hold — excluded by scope, or in a file
doxygen did not parse — gives nothing to attach to, and inventing a compound would put a
class in the index that no other layer knows about. The attribute is dropped, which is
the state before this stage existed."""
conn = _index()
harvested = [(1, {"class_fields": [["field", "NotIndexed", "str", 3]]})]
assert _recover_class_fields_into(conn, harvested) == 0
Activity · 3 steps
test_each_field_carries_its_declaration_line
None test_python_class_fields.test_each_field_carries_its_declaration_line(tmp_path)
Each field carries the line it is declared on.
tests/test_python_class_fields.py:144
Checks
assert name in source_lines[line - 1], f"{name} reported at line {line}"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_each_field_carries_its_declaration_line → harvest_python_class_fields |
| REQ-DDB-PIPE-011 | measured |
Source · 11 lines
def test_each_field_carries_its_declaration_line(tmp_path) -> None:
"""The line is what makes a recovered row navigable, and what
`_one_row_per_declaration` keys on when the same name appears twice. A row without
it would be reported at line 0 and collapse against its own siblings."""
tree, src = _parse(tmp_path)
lines = {f.name: f.line for f in harvest_python_class_fields(tree, src)}
source_lines = _SOURCE.splitlines()
for name, line in lines.items():
assert name in source_lines[line - 1], f"{name} reported at line {line}"
Activity · 5 steps
test_every_annotated_class_attribute_is_harvested
None test_python_class_fields.test_every_annotated_class_attribute_is_harvested(tmp_path)
Every annotated class attribute is harvested, whatever doxygen did with it.
tests/test_python_class_fields.py:91
Checks
assert {k[1] for k in got} == {assert got[("Shapes", "bare_union")].type_text == "int | None"assert got[("Shapes", "with_default")].type_text == "str"assert got[("Plain", "class_level_bare")].class_name == "Plain"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_every_annotated_class_attribute_is_harvested → harvest_python_class_fields |
| REQ-DDB-PIPE-011 | measured |
Source · 22 lines
def test_every_annotated_class_attribute_is_harvested(tmp_path) -> None:
"""Harvests ALL of them, not only the ones doxygen dropped. Which rows are already
present is a question about the DATABASE, and answering it here would put the dedup
rule in the parser where it cannot see the index — the same split
`harvest_variable_declarations` already keeps from `_recoverable_variables`.
"""
tree, src = _parse(tmp_path)
got = {(f.class_name, f.name): f for f in harvest_python_class_fields(tree, src)}
assert {k[1] for k in got} == {
"bare_str",
"bare_int",
"bare_union",
"with_default",
"class_level_bare",
"class_level_assigned",
}, sorted(k[1] for k in got)
assert got[("Shapes", "bare_union")].type_text == "int | None"
assert got[("Shapes", "with_default")].type_text == "str"
assert got[("Plain", "class_level_bare")].class_name == "Plain"
Activity · 6 steps
test_non_fields_are_not_harvested
None test_python_class_fields.test_non_fields_are_not_harvested(tmp_path)
A local, a module global and a bare assignment are not class fields.
tests/test_python_class_fields.py:118
Checks
assert "local_annotated" not in names, "a method-local annotation is not a class field"assert "module_local" not in names, "a function-local annotation is not a class field"assert "CONST" not in names, "an unannotated assignment is doxygen's to emit, not ours"assert "method" not in names, "a method is a function, recovered by the function walk"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_non_fields_are_not_harvested → harvest_python_class_fields |
| REQ-DDB-PIPE-011 | measured |
Source · 21 lines
def test_non_fields_are_not_harvested(tmp_path) -> None:
"""THE THREE WAYS TO OVER-COLLECT, each of which would put a row in `memberdef` under
a class that does not declare it:
* `local_annotated` is inside a METHOD — annotated, indented under the class, and
not a field. A walk that descends into function bodies collects it.
* `module_local` is inside a free function at module scope.
* `CONST = 3` is an assignment with NO annotation. It is a real class attribute,
but doxygen already emits it (a value always saves it), so recovering it would
duplicate a row the index holds — which is what `provenance` exists to keep
distinguishable and what the dedup must prevent anyway.
"""
tree, src = _parse(tmp_path)
names = {f.name for f in harvest_python_class_fields(tree, src)}
assert "local_annotated" not in names, "a method-local annotation is not a class field"
assert "module_local" not in names, "a function-local annotation is not a class field"
assert "CONST" not in names, "an unannotated assignment is doxygen's to emit, not ours"
assert "method" not in names, "a method is a function, recovered by the function walk"
Activity · 6 steps
test_running_the_recovery_twice_inserts_nothing_the_second_time
None test_python_class_fields.test_running_the_recovery_twice_inserts_nothing_the_second_time()
A refresh folds the whole cached payload set, so this stage sees every field on every build. Without the dedup reading back what it just wrote, each refresh would add another row per attribute and a class's member list would grow with the repository's build history.
tests/test_python_class_fields.py:259
Checks
assert _recover_class_fields_into(conn, harvested) == 1assert _recover_class_fields_into(conn, harvested) == 0assert len(_members(conn, "a::Config")) == 1
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_running_the_recovery_twice_inserts_nothing_the_second_time → _recover_class_fields_into |
| REQ-DDB-WIKI-054 | inferred | test_running_the_recovery_twice_inserts_nothing_the_second_time → _recover_class_fields_into → all |
Source · 10 lines
def test_running_the_recovery_twice_inserts_nothing_the_second_time() -> None:
"""A refresh folds the whole cached payload set, so this stage sees every field on every
build. Without the dedup reading back what it just wrote, each refresh would add another
row per attribute and a class's member list would grow with the repository's build
history."""
conn = _index()
harvested = [(1, {"class_fields": [["name", "Config", "str", 7]]})]
assert _recover_class_fields_into(conn, harvested) == 1
assert _recover_class_fields_into(conn, harvested) == 0
assert len(_members(conn, "a::Config")) == 11 more lines, not shown
Activity · 5 steps
test_the_same_class_name_in_two_files_is_attached_to_the_right_one
None test_python_class_fields.test_the_same_class_name_in_two_files_is_attached_to_the_right_one()
MATCHED BY (file, name tail), not by name. Two modules may each declare a `Config`, and a bare-name match would file one module's attributes under the other's class — silently, and in a way that reads as a real member list. The file the attribute was parsed from settles it, and one file cannot declare a class name twice.
tests/test_python_class_fields.py:234
Checks
assert _recover_class_fields_into(conn, harvested) == 2assert [m[0] for m in _members(conn, "a::Config")] == ["from_a"]assert [m[0] for m in _members(conn, "b::Config")] == ["from_b"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-004 | measured | test_the_same_class_name_in_two_files_is_attached_to_the_right_one → _recover_class_fields_into |
| REQ-DDB-WIKI-054 | inferred | test_the_same_class_name_in_two_files_is_attached_to_the_right_one → _recover_class_fields_into → all |
Source · 15 lines
def test_the_same_class_name_in_two_files_is_attached_to_the_right_one() -> None:
"""MATCHED BY (file, name tail), not by name. Two modules may each declare a `Config`,
and a bare-name match would file one module's attributes under the other's class —
silently, and in a way that reads as a real member list. The file the attribute was
parsed from settles it, and one file cannot declare a class name twice."""
conn = _index()
harvested = [
(1, {"class_fields": [["from_a", "Config", "str", 7]]}),
(2, {"class_fields": [["from_b", "Config", "int", 3]]}),
]
assert _recover_class_fields_into(conn, harvested) == 2
assert [m[0] for m in _members(conn, "a::Config")] == ["from_a"]
assert [m[0] for m in _members(conn, "b::Config")] == ["from_b"]