test_export_roundtrip.py¶
tests/integration/test_export_roundtrip.py
A statement survives EXPORT -> DECLARE -> REBUILD, measured on the second index's records.
test_a_stated_configuration_survives_export_declare_rebuild
None test_export_roundtrip.test_a_stated_configuration_survives_export_declare_rebuild(Path tmp_path)
The exported document reproduces the statements.
tests/integration/test_export_roundtrip.py:117
Checks
assert "predefined" in stated_first and SECTION_SHARED_KEY in stated_first, (f"the fixture must record BOTH shapes or the round trip proves half of it: {stated_first}" )assert exported.get("predefined") == [GATED_MACRO], (f"the list shape must survive as a list, not a scalar: {exported}" )assert exported.get(SECTION_SHARED_KEY) == MANIFEST, (f"the document shape must survive intact: {exported}" )assert set(stated_second) == set(stated_first), (f"the round trip lost or gained a statement: {stated_second} vs {stated_first}" )assert stated_declaration(second) == exported, ("and the re-exported declaration must equal the first, or the format is not stable under " "its own round trip" )
Result: passed
Verifies
Source · 54 lines
def test_a_stated_configuration_survives_export_declare_rebuild(tmp_path: Path) -> None:
"""THREE BUILDS, TWO SHAPES, ASSERTED ON THE THIRD BUILD'S RECORDS.
1. state a `predefined` LIST and a `shared_key_patterns` DOCUMENT -> both recorded
2. export -> a YAML file
3. a FRESH index built with `--declare` that file -> the same statements recorded
Build 3 uses a DIFFERENT output path deliberately. The replay mechanism (gh#366) reads the
record out of the database being replaced, so building over the same file would let the REPLAY
supply the statements and the export could be empty while this test passed. A fresh path has no
record to replay from, so the only possible source is the exported document.
@brief The exported document reproduces the statements.
@version 1
"""
from clew.declaration import SECTION_SHARED_KEY
root = tmp_path / "target"
doxyfile = _target(root)
first = tmp_path / "first.db"
build_index(
output=first,
repo_root=root,
doxyfile=doxyfile,
options={"predefined": [GATED_MACRO], SECTION_SHARED_KEY: MANIFEST},
)
stated_first = stated_options(_options_meta(first))
assert "predefined" in stated_first and SECTION_SHARED_KEY in stated_first, (
f"the fixture must record BOTH shapes or the round trip proves half of it: {stated_first}"
)
exported = stated_declaration(first)
assert exported.get("predefined") == [GATED_MACRO], (
f"the list shape must survive as a list, not a scalar: {exported}"
)
assert exported.get(SECTION_SHARED_KEY) == MANIFEST, (
f"the document shape must survive intact: {exported}"
)
declaration = tmp_path / "exported.yaml"
declaration.write_text(render(exported, first), encoding="utf-8")
## A FRESH OUTPUT PATH: no record to replay, so the document is the only possible source.
second = tmp_path / "second.db"
build_index(output=second, repo_root=root, doxyfile=doxyfile, declare=str(declaration))
stated_second = stated_options(_options_meta(second))
assert set(stated_second) == set(stated_first), (
f"the round trip lost or gained a statement: {stated_second} vs {stated_first}"
)
assert stated_declaration(second) == exported, (
"and the re-exported declaration must equal the first, or the format is not stable under "
"its own round trip"
)1 more lines, not shown
Activity · 17 steps
test_an_index_with_no_statement_exports_a_document_that_states_nothing
None test_export_roundtrip.test_an_index_with_no_statement_exports_a_document_that_states_nothing(Path tmp_path)
Nothing stated exports nothing.
tests/integration/test_export_roundtrip.py:92
Checks
assert stated_declaration(db) == {}, ("an index that recorded no statement must export none — anything here is a default being " "passed off as a declaration" )assert "recorded NO tier-1 statements" in text, ("and it must SAY so: a zero-byte file reads as a failed command rather than a result" )
Result: passed
Verifies
Source · 25 lines
def test_an_index_with_no_statement_exports_a_document_that_states_nothing(tmp_path: Path) -> None:
"""THE FLOOR, and it is a real risk rather than a formality. The obvious implementation of an
export walks the EFFECTIVE configuration — tier 1 over tier 2 over the built-in floor — which
would write a file asserting the team declared every default. Committing that freezes the
defaults into the repo, so a later improvement to one is shadowed by a value nobody remembers
writing, and a tier-5 default becomes indistinguishable from a deliberate decision.
@brief Nothing stated exports nothing.
@version 1
"""
root = tmp_path / "bare"
doxyfile = _target(root)
db = tmp_path / "bare.db"
build_index(output=db, repo_root=root, doxyfile=doxyfile)
assert stated_declaration(db) == {}, (
"an index that recorded no statement must export none — anything here is a default being "
"passed off as a declaration"
)
text = render({}, db)
assert "recorded NO tier-1 statements" in text, (
"and it must SAY so: a zero-byte file reads as a failed command rather than a result"
)