test_wiki_activity.py

tests/test_wiki_activity.py

A function's activity diagram, from its parsed body (round 5, P5.5; owner Q/A 2026-11-20).

test_an_elif_is_a_condition_at_the_same_depth

None test_wiki_activity.test_an_elif_is_a_condition_at_the_same_depth()

`elif` is not `else` + nested `if`; a final `else` keeps its own line.

tests/test_wiki_activity.py:77

Show on the map →

Called by none

Calls steps_of

Checks

  • assert [(s.kind, s.text, s.first, s.depth) for s in steps] == [

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-045measuredtest_an_elif_is_a_condition_at_the_same_depth → steps_of
Source · 16 lines
def test_an_elif_is_a_condition_at_the_same_depth() -> None:
    """@brief `elif` is not `else` + nested `if`; a final `else` keeps its own line."""
    src = (
        "def f(x):\n    if x > 1:\n        a()\n    elif x:\n        b()\n    else:\n        c()\n"
    )
    steps = steps_of(src.splitlines(), "m.py", 1)
    assert [(s.kind, s.text, s.first, s.depth) for s in steps] == [
        (COND, "if x > 1", 2, 0),
        (STMT, "a()", 3, 1),
        (COND, "elif x", 4, 0),
        (STMT, "b()", 5, 1),
        (ELSE, "else", 6, 0),
        (STMT, "c()", 7, 1),
    ]

Activity · 3 steps
lines 79–81src = ( "def f(x):\n if x > 1:\n a()\n elif x:\n b()\n else:\n c()\n" )lines 82–82steps = steps_of(src.splitlines(), "m.py", 1)lines 83–90assert [(s.kind, s.text, s.first, s.depth) for s in steps] == [ (COND, "if x > 1", 2, 0), (STMT, "a()", 3, 1), (COND, "elif x", 4, 0), (STMT, "b()", 5, 1), (ELSE, "else", 6, 0), (STMT, "c()", 7, 1), ]

test_an_unknown_language_has_no_diagram

None test_wiki_activity.test_an_unknown_language_has_no_diagram()

No parser: no steps, no SVG.

tests/test_wiki_activity.py:72

Checks

  • assert steps_of(["fn x() {}"], "src/m.rs", 1) == [] and activity_svg([], "x") == ""

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-045measuredtest_an_unknown_language_has_no_diagram → steps_of
Source · 5 lines
def test_an_unknown_language_has_no_diagram() -> None:
    """@brief No parser: no steps, no SVG."""
    assert steps_of(["fn x() {}"], "src/m.rs", 1) == [] and activity_svg([], "x") == ""

Activity · 1 steps
lines 74–74assert steps_of(["fn x() {}"], "src/m.rs", 1) == [] and activity_svg([], "x") == ""

test_cpp_steps_follow_the_same_shape

None test_wiki_activity.test_cpp_steps_follow_the_same_shape()

tree-sitter: the same seven steps for the C++ twin.

tests/test_wiki_activity.py:57

Show on the map →

Called by none

Calls steps_of

Checks

  • assert [(s.kind, s.depth) for s in steps] == _EXPECTED
  • assert steps[2].text == "if (i % 2)" and steps[-1].text == "return out;"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-045measuredtest_cpp_steps_follow_the_same_shape → steps_of
Source · 7 lines
def test_cpp_steps_follow_the_same_shape() -> None:
    """@brief tree-sitter: the same seven steps for the C++ twin."""
    steps = steps_of(_CPP.splitlines(), "src/m.cpp", first_line=1)
    assert [(s.kind, s.depth) for s in steps] == _EXPECTED
    assert steps[2].text == "if (i % 2)" and steps[-1].text == "return out;"

Activity · 3 steps
lines 59–59steps = steps_of(_CPP.splitlines(), "src/m.cpp", first_line=1)lines 60–60assert [(s.kind, s.depth) for s in steps] == _EXPECTEDlines 61–61assert steps[2].text == "if (i % 2)" and steps[-1].text == "return out;"

test_line_ranges_are_compact_and_ordered

None test_wiki_activity.test_line_ranges_are_compact_and_ordered()

`{20, 12, 13, 14, 15}` → `12-15,20`: what a box's link carries.

tests/test_wiki_activity.py:93

Show on the map →

Called by none

Calls _ranges

Checks

  • assert _ranges({20, 12, 13, 14, 15}) == "12-15,20" and _ranges(set()) == ""

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-045catalog
Source · 7 lines
def test_line_ranges_are_compact_and_ordered() -> None:
    """@brief `{20, 12, 13, 14, 15}` → `12-15,20`: what a box's link carries."""
    from clew.wiki.testpages import _ranges

    assert _ranges({20, 12, 13, 14, 15}) == "12-15,20" and _ranges(set()) == ""

Activity · 2 steps
lines 95–95from clew.wiki.testpages import _rangeslines 97–97assert _ranges({20, 12, 13, 14, 15}) == "12-15,20" and _ranges(set()) == ""

test_python_steps_follow_the_control_flow_with_absolute_lines

None test_wiki_activity.test_python_steps_follow_the_control_flow_with_absolute_lines()

`ast`: the docstring is not a step; lines are the file's (the body starts at 20).

tests/test_wiki_activity.py:49

Show on the map →

Called by none

Calls steps_of

Checks

  • assert [(s.kind, s.depth) for s in steps] == _EXPECTED
  • assert [s.first for s in steps] == [22, 23, 24, 25, 26, 27, 28]
  • assert steps[1].text == "for item in items" and steps[-1].text == "return out"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-045measuredtest_python_steps_follow_the_control_flow_with_absolute_lines → steps_of
Source · 8 lines
def test_python_steps_follow_the_control_flow_with_absolute_lines() -> None:
    """@brief `ast`: the docstring is not a step; lines are the file's (the body starts at 20)."""
    steps = steps_of(_PY.splitlines(), "src/m.py", first_line=20)
    assert [(s.kind, s.depth) for s in steps] == _EXPECTED
    assert [s.first for s in steps] == [22, 23, 24, 25, 26, 27, 28]
    assert steps[1].text == "for item in items" and steps[-1].text == "return out"

Activity · 4 steps
lines 51–51steps = steps_of(_PY.splitlines(), "src/m.py", first_line=20)lines 52–52assert [(s.kind, s.depth) for s in steps] == _EXPECTEDlines 53–53assert [s.first for s in steps] == [22, 23, 24, 25, 26, 27, 28]lines 54–54assert steps[1].text == "for item in items" and steps[-1].text == "return out"

test_the_page_script_lights_the_linked_lines

None test_wiki_activity.test_the_page_script_lights_the_linked_lines()

clew.js reads `lit` and marks the activity steps it covers.

tests/test_wiki_activity.py:120

Show on the map →

Called by none

Calls none

Checks

  • assert "lit" in js and ".activity" in js

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-045catalog
Source · 6 lines
def test_the_page_script_lights_the_linked_lines() -> None:
    """@brief clew.js reads `lit` and marks the activity steps it covers."""
    from clew.wiki.theme import THEMES

    js = (THEMES / "clew" / "static" / "clew.js").read_text()
    assert "lit" in js and ".activity" in js

1 more lines, not shown

Activity · 3 steps
lines 122–122from clew.wiki.theme import THEMESlines 124–124js = (THEMES / "clew" / "static" / "clew.js").read_text()lines 125–125assert "lit" in js and ".activity" in js

test_the_svg_carries_each_steps_lines_for_lighting

None test_wiki_activity.test_the_svg_carries_each_steps_lines_for_lighting()

`data-l` per step, a loop back edge, an accessible label, no script.

tests/test_wiki_activity.py:64

Checks

  • assert svg.count('class="step ') == 7 and 'data-l="25-25"' in svg
  • assert 'class="loop-back"' in svg and 'aria-label="activity of load: 7 steps"' in svg
  • assert "<script" not in svg

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-045measuredtest_the_svg_carries_each_steps_lines_for_lighting → steps_of
Source · 8 lines
def test_the_svg_carries_each_steps_lines_for_lighting() -> None:
    """@brief `data-l` per step, a loop back edge, an accessible label, no script."""
    svg = activity_svg(steps_of(_PY.splitlines(), "src/m.py", 20), "load")
    assert svg.count('class="step ') == 7 and 'data-l="25-25"' in svg
    assert 'class="loop-back"' in svg and 'aria-label="activity of load: 7 steps"' in svg
    assert "<script" not in svg

Activity · 4 steps
lines 66–66svg = activity_svg(steps_of(_PY.splitlines(), "src/m.py", 20), "load")lines 67–67assert svg.count('class="step ') == 7 and 'data-l="25-25"' in svglines 68–68assert 'class="loop-back"' in svg and 'aria-label="activity of load: 7 steps"' in svglines 69–69assert "<script" not in svg