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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-004 | measured | test_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
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
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
Checks
assert StageTimer().as_meta() == {}assert StageTimer().stages() == ()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-004 | measured |
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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-MCP-004 | measured | test_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
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
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
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"
)