test_wiki_slices.py

tests/test_wiki_slices.py

A test is a slice of a master flow (round 5, R5-4a).

test_a_slice_is_drawn_as_a_window_of_the_master_flow

None test_wiki_slices.test_a_slice_is_drawn_as_a_window_of_the_master_flow()

Window of the master flow with the slice lit.

tests/test_wiki_slices.py:106

Checks

  • assert {v: k for k, v in groups.items()} == {"1": "ex entry", "2": "ex"}
  • assert ">2<" in html and ">3<" in html # master numbering kept
  • assert "test enters" in html
  • assert "1 earlier step" in html and "2 later steps" in html
  • assert 'data-step="0"' in wide and 'class="st dim" data-step="3"' in wide

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-041measuredtest_a_slice_is_drawn_as_a_window_of_the_master_flow → lines_per_test
Source · 22 lines
def test_a_slice_is_drawn_as_a_window_of_the_master_flow() -> None:
    """THE PORTION OF THE DIAGRAM: the window runs from `pad` steps before the first exercised step
    to `pad` after the last, numbered as in the master flow; exercised steps are lit (`ex`), the
    rest dimmed (`dim`); the test's entry is marked; the steps outside the window are counted.

    @brief Window of the master flow with the slice lit.
    """
    import re

    from clew.wiki.slices import slice_svg

    cut = slice_of(_FLOW, lines_per_test(_CONTEXTS)["test_load"])
    html = slice_svg(_FLOW, cut, pad=0)
    groups = dict(re.findall(r'<g class="st ([a-z ]+)" data-step="(\d+)"', html))
    assert {v: k for k, v in groups.items()} == {"1": "ex entry", "2": "ex"}
    assert ">2<" in html and ">3<" in html  # master numbering kept
    assert "test enters" in html
    assert "1 earlier step" in html and "2 later steps" in html
    wide = slice_svg(_FLOW, cut, pad=1)
    assert 'data-step="0"' in wide and 'class="st dim" data-step="3"' in wide

Activity · 11 steps
lines 113–113import relines 115–115from clew.wiki.slices import slice_svglines 117–117cut = slice_of(_FLOW, lines_per_test(_CONTEXTS)["test_load"])lines 118–118html = slice_svg(_FLOW, cut, pad=0)lines 119–119groups = dict(re.findall(r'<g class="st ([a-z ]+)" data-step="(\d+)"', html))lines 120–120assert {v: k for k, v in groups.items()} == {"1": "ex entry", "2": "ex"}lines 121–121assert ">2<" in html and ">3<" in htmllines 122–122assert "test enters" in htmllines 123–123assert "1 earlier step" in html and "2 later steps" in htmllines 124–124wide = slice_svg(_FLOW, cut, pad=1)lines 125–125assert 'data-step="0"' in wide and 'class="st dim" data-step="3"' in wide

test_a_step_is_exercised_when_its_call_site_ran_in_the_test

None test_wiki_slices.test_a_step_is_exercised_when_its_call_site_ran_in_the_test()

Exercised = call-site line ran in this test.

tests/test_wiki_slices.py:78

Checks

  • assert cut.exercised == (0, 1, 3, 4)
  • assert cut.entered == ("main",)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-041measuredtest_a_step_is_exercised_when_its_call_site_ran_in_the_test → lines_per_test
Source · 11 lines
def test_a_step_is_exercised_when_its_call_site_ran_in_the_test() -> None:
    """test_main ran lines 10, 11, 20, 30 but not 21: check() was never called from load in that
    test, so step 2 (load → check) is not part of what test_main validates.

    @brief Exercised = call-site line ran in this test.
    """
    cut = slice_of(_FLOW, lines_per_test(_CONTEXTS)["test_main"])
    assert cut.exercised == (0, 1, 3, 4)
    assert cut.entered == ("main",)

Activity · 3 steps
lines 84–84cut = slice_of(_FLOW, lines_per_test(_CONTEXTS)["test_main"])lines 85–85assert cut.exercised == (0, 1, 3, 4)lines 86–86assert cut.entered == ("main",)

test_a_test_that_calls_into_the_middle_enters_there

None test_wiki_slices.test_a_test_that_calls_into_the_middle_enters_there()

Mid-flow entry is where the test called in.

tests/test_wiki_slices.py:89

Checks

  • assert cut.exercised == (1, 2)
  • assert cut.entered == ("load",)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-041measuredtest_a_test_that_calls_into_the_middle_enters_there → lines_per_test
Source · 11 lines
def test_a_test_that_calls_into_the_middle_enters_there() -> None:
    """test_load called load() itself: its calls ran (20, 21) but the step main → load did not,
    so the test enters the flow at load, and main's own steps are outside its slice.

    @brief Mid-flow entry is where the test called in.
    """
    cut = slice_of(_FLOW, lines_per_test(_CONTEXTS)["test_load"])
    assert cut.exercised == (1, 2)
    assert cut.entered == ("load",)

Activity · 3 steps
lines 95–95cut = slice_of(_FLOW, lines_per_test(_CONTEXTS)["test_load"])lines 96–96assert cut.exercised == (1, 2)lines 97–97assert cut.entered == ("load",)

test_a_test_that_ran_none_of_the_flow_has_an_empty_slice

None test_wiki_slices.test_a_test_that_ran_none_of_the_flow_has_an_empty_slice()

Nothing ran → nothing exercised, nowhere entered (and never an error).

tests/test_wiki_slices.py:100

Show on the map →

Called by none

Calls slice_of

Checks

  • assert cut.exercised == () and cut.entered == ()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-041measuredtest_a_test_that_ran_none_of_the_flow_has_an_empty_slice → slice_of
Source · 6 lines
def test_a_test_that_ran_none_of_the_flow_has_an_empty_slice() -> None:
    """@brief Nothing ran → nothing exercised, nowhere entered (and never an error)."""
    cut = slice_of(_FLOW, {"src/other.py": {1}})
    assert cut.exercised == () and cut.entered == ()

Activity · 2 steps
lines 102–102cut = slice_of(_FLOW, {"src/other.py": {1}})lines 103–103assert cut.exercised == () and cut.entered == ()

test_every_test_s_slice_of_a_flow_comes_from_one_pass_over_its_steps

None test_wiki_slices.test_every_test_s_slice_of_a_flow_comes_from_one_pass_over_its_steps()

All slices of a flow, equal to the per-test ones.

tests/test_wiki_slices.py:128

Checks

  • assert set(every) == {"test_main", "test_load"}
  • assert all(every[t] == slice_of(_FLOW, per_test[t]) for t in every)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-041measuredtest_every_test_s_slice_of_a_flow_comes_from_one_pass_over_its_steps → lines_per_test
REQ-DDB-WIKI-054inferredtest_every_test_s_slice_of_a_flow_comes_from_one_pass_over_its_steps → all
Source · 13 lines
def test_every_test_s_slice_of_a_flow_comes_from_one_pass_over_its_steps() -> None:
    """A FLOW PAGE NEEDS ALL ITS TESTS' SLICES at once (clew: ~2,900 tests); `slices_of` reads them
    from the steps' call sites in one pass, and agrees with `slice_of` test by test. A test that
    touched none of the flow is absent, not an empty slice.

    @brief All slices of a flow, equal to the per-test ones.
    """
    from clew.wiki.slices import slices_of

    every = slices_of(_FLOW, _CONTEXTS)
    per_test = lines_per_test(_CONTEXTS)
    assert set(every) == {"test_main", "test_load"}
    assert all(every[t] == slice_of(_FLOW, per_test[t]) for t in every)

1 more lines, not shown

Activity · 5 steps
lines 135–135from clew.wiki.slices import slices_oflines 137–137every = slices_of(_FLOW, _CONTEXTS)lines 138–138per_test = lines_per_test(_CONTEXTS)lines 139–139assert set(every) == {"test_main", "test_load"}lines 140–140assert all(every[t] == slice_of(_FLOW, per_test[t]) for t in every)

test_lines_are_grouped_per_test

None test_wiki_slices.test_lines_are_grouped_per_test()

{file: {line: tests}} turns into {test: {file: lines}}.

tests/test_wiki_slices.py:71

Checks

  • assert lines["test_load"] == {"src/app.py": {20, 21}}
  • assert lines["test_main"]["src/app.py"] == {10, 11, 20, 30}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-WIKI-041measuredtest_lines_are_grouped_per_test → lines_per_test
Source · 7 lines
def test_lines_are_grouped_per_test() -> None:
    """@brief {file: {line: tests}} turns into {test: {file: lines}}."""
    lines = lines_per_test(_CONTEXTS)
    assert lines["test_load"] == {"src/app.py": {20, 21}}
    assert lines["test_main"]["src/app.py"] == {10, 11, 20, 30}

Activity · 3 steps
lines 73–73lines = lines_per_test(_CONTEXTS)lines 74–74assert lines["test_load"] == {"src/app.py": {20, 21}}lines 75–75assert lines["test_main"]["src/app.py"] == {10, 11, 20, 30}