test_stage_timings.py

tests/test_stage_timings.py

Where a build's time goes, persisted beside what the build cost in total.

test_a_malformed_breakdown_decodes_without_raising

None test_stage_timings.test_a_malformed_breakdown_decodes_without_raising()

A malformed stored breakdown decodes to what it can, and does not raise.

tests/test_stage_timings.py:115

Checks

  • assert parse_stages("good=12 broken nonnumeric=xy also_good=3") == (("good", 12), ("also_good", 3), )
  • assert parse_stages("") == ()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-004measuredtest_a_malformed_breakdown_decodes_without_raising → parse_stages
Source · 19 lines
def test_a_malformed_breakdown_decodes_without_raising() -> None:
    """This value is read in a reporting path. A breakdown that cannot be shown must
    not take a `status` call down with it, so a bad segment is dropped rather than
    raised on.

    @brief Decoding is fail-soft.
    @version 1
    """
    assert parse_stages("good=12 broken nonnumeric=xy also_good=3") == (
        ("good", 12),
        ("also_good", 3),
    )
    assert parse_stages("") == ()


@pytest.mark.skipif(
    shutil.which("doxygen") is None,
    reason="the breakdown is asserted against a real build",
)

test_a_real_build_records_a_breakdown_covering_every_stage

None test_stage_timings.test_a_real_build_records_a_breakdown_covering_every_stage(Path tmp_path)

A real build records every stage of the pipeline, in execution order.

tests/test_stage_timings.py:136

Show on the map →

Called by none

Calls _refresh_meta, all, parse_stages

Checks

  • assert not missing, (f"stages ran but were never marked, so their cost is misattributed: {missing}" )
  • assert names.index("doxygen") < names.index("reachability")
  • assert all(elapsed >= 0 for _, elapsed in stages)
  • assert "enrich" not in names, "a stage that did not run must not be reported"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-004measured
REQ-DDB-CONFIG-005measured
REQ-DDB-CONFIG-006measured
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-001measured
REQ-DDB-MCP-004measuredtest_a_real_build_records_a_breakdown_covering_every_stage → parse_stages
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
REQ-DDB-WIKI-054inferredtest_a_real_build_records_a_breakdown_covering_every_stage → all
Source · 41 lines
def test_a_real_build_records_a_breakdown_covering_every_stage(tmp_path: Path) -> None:
    """Pinned against a REAL build rather than a stubbed one, because the thing that
    can break is a `timer.mark` deleted from `_build_stages` — and a stub of
    `_build_stages` is exactly the thing that would not notice.

    Ordering is asserted at the two ends rather than as a full sequence: `doxygen`
    must precede `reachability` because the graph cannot be traversed before it is
    parsed, and pinning all thirty-four positions would fail on any reordering the
    pipeline is free to make.

    @brief Every pipeline stage appears in the stored breakdown.
    @version 1
    """
    root = tmp_path / "repo"
    root.mkdir()
    (root / "unit.c").write_text("/** @brief A unit. */\nvoid unit(void) {}\n", encoding="utf-8")
    doxyfile = root / "Doxyfile"
    doxyfile.write_text(
        f"INPUT = {root}\nOUTPUT_DIRECTORY = {root}/out\nRECURSIVE = YES\nGENERATE_SQLITE3 = YES\n",
        encoding="utf-8",
    )
    out = tmp_path / "clew.db"
    build_index(output=out, repo_root=root, doxyfile=doxyfile)

    refresh = _refresh_meta(out)
    stages = parse_stages(refresh[STAGES_KEY])
    names = [name for name, _ in stages]

    missing = REQUIRED_STAGES - set(names)
    assert not missing, (
        f"stages ran but were never marked, so their cost is misattributed: {missing}"
    )
    assert names.index("doxygen") < names.index("reachability")
    assert all(elapsed >= 0 for _, elapsed in stages)
    assert "enrich" not in names, "a stage that did not run must not be reported"


@pytest.mark.skipif(
    shutil.which("doxygen") is None,
    reason="the breakdown is asserted against a real build",
)

test_an_unmarked_timer_records_nothing

None test_stage_timings.test_an_unmarked_timer_records_nothing()

A timer with no marks stamps no key at all.

tests/test_stage_timings.py:79

Show on the map →

Called by none

Calls none

Checks

  • assert StageTimer().as_meta() == {}
  • assert StageTimer().stages() == ()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-004measured
Source · 12 lines
def test_an_unmarked_timer_records_nothing() -> None:
    """`write_build_signature` drops falsy values, so an empty string would vanish
    anyway — but it would vanish silently, and a reader inspecting the timer directly
    would see a measurement that was never taken.

    @brief No marks means no section fragment.
    @version 1
    """
    assert StageTimer().as_meta() == {}
    assert StageTimer().stages() == ()

Activity · 2 steps
lines 87–87assert StageTimer().as_meta() == {}lines 88–88assert StageTimer().stages() == ()

test_marks_record_in_order_and_round_trip_through_the_stored_form

None test_stage_timings.test_marks_record_in_order_and_round_trip_through_the_stored_form()

Marks partition the timed span, in order, and survive a round trip.

tests/test_stage_timings.py:93

Checks

  • assert names == ["first", "second", "third"], "order is the reading order"
  • assert parse_stages(rendered) == timer.stages()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-004measuredtest_marks_record_in_order_and_round_trip_through_the_stored_form → parse_stages
Source · 20 lines
def test_marks_record_in_order_and_round_trip_through_the_stored_form() -> None:
    """The round trip is the load-bearing half: the value is stored as text in a TEXT
    column and read back by `status`, so a writer and a reader that disagreed about
    the separator would produce a breakdown that silently decodes to nothing.

    @brief Encode and decode a breakdown without loss.
    @version 1
    """
    timer = StageTimer()
    timer.mark("first")
    timer.mark("second")
    timer.mark("third")

    names = [name for name, _ in timer.stages()]
    assert names == ["first", "second", "third"], "order is the reading order"

    rendered = timer.as_meta()[STAGES_KEY]
    assert parse_stages(rendered) == timer.stages()

Activity · 8 steps
lines 101–101timer = StageTimer()lines 102–102timer.mark("first")lines 103–103timer.mark("second")lines 104–104timer.mark("third")lines 106–106names = [name for name, _ in timer.stages()]lines 107–107assert names == ["first", "second", "third"], "order is the reading order"lines 109–109rendered = timer.as_meta()[STAGES_KEY]lines 110–110assert parse_stages(rendered) == timer.stages()

test_the_breakdown_sums_to_within_the_reported_duration

None test_stage_timings.test_the_breakdown_sums_to_within_the_reported_duration(Path tmp_path)

The breakdown accounts for the whole measured duration.

tests/test_stage_timings.py:179

Show on the map →

Called by none

Calls _refresh_meta, parse_stages

Checks

  • assert summed <= total, "segments cannot exceed the span they partition"
  • assert summed >= total // 2, (f"the breakdown accounts for only {summed}ms of a {total}ms build — " "a stage boundary is being missed" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-004measured
REQ-DDB-CONFIG-005measured
REQ-DDB-CONFIG-006measured
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-001measured
REQ-DDB-MCP-004measuredtest_the_breakdown_sums_to_within_the_reported_duration → parse_stages
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 · 30 lines
def test_the_breakdown_sums_to_within_the_reported_duration(tmp_path: Path) -> None:
    """The segments partition the timed span, so their sum cannot exceed the total —
    and if it does, marks are being taken on more than one clock. The lower bound is
    the useful half: it says the breakdown covers the build rather than some inner
    fraction of it, which is what makes "where did the time go" answerable at all.

    @brief Segments cover the duration they are reported beside.
    @version 1
    """
    root = tmp_path / "repo"
    root.mkdir()
    (root / "unit.c").write_text("/** @brief A unit. */\nvoid unit(void) {}\n", encoding="utf-8")
    doxyfile = root / "Doxyfile"
    doxyfile.write_text(
        f"INPUT = {root}\nOUTPUT_DIRECTORY = {root}/out\nGENERATE_SQLITE3 = YES\n",
        encoding="utf-8",
    )
    out = tmp_path / "clew.db"
    build_index(output=out, repo_root=root, doxyfile=doxyfile)

    refresh = _refresh_meta(out)
    total = int(refresh["duration_ms"])
    summed = sum(elapsed for _, elapsed in parse_stages(refresh[STAGES_KEY]))
    assert summed <= total, "segments cannot exceed the span they partition"
    assert summed >= total // 2, (
        f"the breakdown accounts for only {summed}ms of a {total}ms build — "
        "a stage boundary is being missed"
    )

Activity · 12 steps
lines 188–188root = tmp_path / "repo"lines 189–189root.mkdir()lines 190–190(root / "unit.c").write_text("/** @brief A unit. */\nvoid unit(void) {}\n", encoding="utf-8")lines 191–191doxyfile = root / "Doxyfile"lines 192–195doxyfile.write_text( f"INPUT = {root}\nOUTPUT_DIRECTORY = {root}/out\nGENERATE_SQLITE3 = YES\n", encoding="utf-8", )lines 196–196out = tmp_path / "clew.db"lines 197–197build_index(output=out, repo_root=root, doxyfile=doxyfile)lines 199–199refresh = _refresh_meta(out)lines 200–200total = int(refresh["duration_ms"])lines 201–201summed = sum(elapsed for _, elapsed in parse_stages(refresh[STAGES_KEY]))lines 202–202assert summed <= total, "segments cannot exceed the span they partition"lines 203–206assert summed >= total // 2, ( f"the breakdown accounts for only {summed}ms of a {total}ms build — " "a stage boundary is being missed" )