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

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measuredtest_a_stated_configuration_survives_export_declare_rebuild → stated_declaration
REQ-DDB-CONFIG-004measured
REQ-DDB-CONFIG-005measured
REQ-DDB-CONFIG-006measuredtest_a_stated_configuration_survives_export_declare_rebuild → _options_meta
REQ-DDB-CONFIG-007measured
REQ-DDB-CONFIG-009measured
REQ-DDB-INDEX-001measured
REQ-DDB-INDEX-002measured
REQ-DDB-INDEX-003measured
REQ-DDB-INDEX-004measured
REQ-DDB-INDEX-005measured
REQ-DDB-INDEX-006measured
REQ-DDB-INDEX-007measured
REQ-DDB-INDEX-008measured
REQ-DDB-INDEX-009measured
REQ-DDB-INDEX-010measured
REQ-DDB-INDEX-011measured
REQ-DDB-MCP-001measuredtest_a_stated_configuration_survives_export_declare_rebuild → stated_declaration → meta_section
REQ-DDB-MCP-004measured
REQ-DDB-PIPE-001measured
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-004measured
REQ-DDB-PIPE-005measured
REQ-DDB-PIPE-006measured
REQ-DDB-PIPE-007measured
REQ-DDB-PIPE-008measured
REQ-DDB-PIPE-009measured
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measured
REQ-DDB-PIPE-012measured
REQ-DDB-PIPE-013measured
REQ-DDB-PIPE-014measured
REQ-DDB-PIPE-015measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measured
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-003measured
REQ-DDB-SCHEMA-004measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-006measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-009measured
REQ-DDB-SCHEMA-011measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measured
REQ-DDB-SCHEMA-014measured
REQ-DDB-SCHEMA-015measured
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
lines 132–132from clew.declaration import SECTION_SHARED_KEYlines 134–134root = tmp_path / "target"lines 135–135doxyfile = _target(root)lines 136–136first = tmp_path / "first.db"lines 137–142build_index( output=first, repo_root=root, doxyfile=doxyfile, options={"predefined": [GATED_MACRO], SECTION_SHARED_KEY: MANIFEST}, )lines 143–143stated_first = stated_options(_options_meta(first))lines 144–146assert "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}" )lines 148–148exported = stated_declaration(first)lines 149–151assert exported.get("predefined") == [GATED_MACRO], ( f"the list shape must survive as a list, not a scalar: {exported}" )lines 152–154assert exported.get(SECTION_SHARED_KEY) == MANIFEST, ( f"the document shape must survive intact: {exported}" )lines 156–156declaration = tmp_path / "exported.yaml"lines 157–157declaration.write_text(render(exported, first), encoding="utf-8")lines 160–160second = tmp_path / "second.db"lines 161–161build_index(output=second, repo_root=root, doxyfile=doxyfile, declare=str(declaration))lines 163–163stated_second = stated_options(_options_meta(second))lines 164–166assert set(stated_second) == set(stated_first), ( f"the round trip lost or gained a statement: {stated_second} vs {stated_first}" )lines 167–170assert stated_declaration(second) == exported, ( "and the re-exported declaration must equal the first, or the format is not stable under " "its own round trip" )

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

Show on the map →

Called by none

Calls _target, stated_declaration

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

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measuredtest_an_index_with_no_statement_exports_a_document_that_states_nothing → stated_declaration
REQ-DDB-CONFIG-004measured
REQ-DDB-CONFIG-005measured
REQ-DDB-CONFIG-006measuredtest_an_index_with_no_statement_exports_a_document_that_states_nothing → stated_declaration → recorded_explicit
REQ-DDB-CONFIG-007measured
REQ-DDB-CONFIG-009measured
REQ-DDB-INDEX-001measured
REQ-DDB-INDEX-002measured
REQ-DDB-INDEX-003measured
REQ-DDB-INDEX-004measured
REQ-DDB-INDEX-005measured
REQ-DDB-INDEX-006measured
REQ-DDB-INDEX-007measured
REQ-DDB-INDEX-008measured
REQ-DDB-INDEX-009measured
REQ-DDB-INDEX-010measured
REQ-DDB-INDEX-011measured
REQ-DDB-MCP-001measuredtest_an_index_with_no_statement_exports_a_document_that_states_nothing → stated_declaration → meta_section
REQ-DDB-MCP-004measured
REQ-DDB-PIPE-001measured
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-004measured
REQ-DDB-PIPE-005measured
REQ-DDB-PIPE-006measured
REQ-DDB-PIPE-007measured
REQ-DDB-PIPE-008measured
REQ-DDB-PIPE-009measured
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measured
REQ-DDB-PIPE-012measured
REQ-DDB-PIPE-013measured
REQ-DDB-PIPE-014measured
REQ-DDB-PIPE-015measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measured
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-003measured
REQ-DDB-SCHEMA-004measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-006measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-009measured
REQ-DDB-SCHEMA-011measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measured
REQ-DDB-SCHEMA-014measured
REQ-DDB-SCHEMA-015measured
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"
    )

Activity · 7 steps
lines 102–102root = tmp_path / "bare"lines 103–103doxyfile = _target(root)lines 104–104db = tmp_path / "bare.db"lines 105–105build_index(output=db, repo_root=root, doxyfile=doxyfile)lines 107–110assert stated_declaration(db) == {}, ( "an index that recorded no statement must export none — anything here is a default being " "passed off as a declaration" )lines 111–111text = render({}, db)lines 112–114assert "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" )