test_guard_bus.py

tests/guard/test_guard_bus.py

The bus-tag rule (1.4.0 W10, #67's fifth consumer).

test_a_bus_outside_the_vocabulary_is_refused

test_a_bus_outside_the_vocabulary_is_refused()

tests/guard/test_guard_bus.py:75

Show on the map →

Called by none

Calls _fn, check_bus_tags

Checks

  • assert len(out) == 1 and "KAFKA" in out[0].message

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-026measuredtest_a_bus_outside_the_vocabulary_is_refused → check_bus_tags
Source · 4 lines
def test_a_bus_outside_the_vocabulary_is_refused() -> None:
    """@brief `@emits KAFKA x` names a bus the vocabulary does not hold."""
    out = check_bus_tags([_fn("on_x", emits=["KAFKA x"])], "a.py", _BUS, _lines("pass"))
    assert len(out) == 1 and "KAFKA" in out[0].message
Activity · 2 steps
lines 77–77out = check_bus_tags([_fn("on_x", emits=["KAFKA x"])], "a.py", _BUS, _lines("pass"))lines 78–78assert len(out) == 1 and "KAFKA" in out[0].message

test_a_caller_of_a_sender_must_name_the_bus

test_a_caller_of_a_sender_must_name_the_bus()

tests/guard/test_guard_bus.py:63

Show on the map →

Called by none

Calls _fn, check_bus_tags

Checks

  • assert [v.message.split("'")[1] for v in out] == ["send_status"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-026measuredtest_a_caller_of_a_sender_must_name_the_bus → check_bus_tags
Source · 10 lines
def test_a_caller_of_a_sender_must_name_the_bus() -> None:
    """THE CROSSING IS THE CALLER THAT CHOOSES THE TOPIC (#67, Python consumer), not only a named
    handler.

    @brief A body that calls a configured sender is in scope; the sender itself is not.
    """
    caller = _fn("send_status")
    sender = _fn("publish")
    out = check_bus_tags([caller, sender], "a.py", _BUS, _lines("publish(topic, data)"))
    assert [v.message.split("'")[1] for v in out] == ["send_status"]
Activity · 4 steps
lines 69–69caller = _fn("send_status")lines 70–70sender = _fn("publish")lines 71–71out = check_bus_tags([caller, sender], "a.py", _BUS, _lines("publish(topic, data)"))lines 72–72assert [v.message.split("'")[1] for v in out] == ["send_status"]

test_a_handler_without_a_bus_tag_is_a_violation

test_a_handler_without_a_bus_tag_is_a_violation()

tests/guard/test_guard_bus.py:47

Show on the map →

Called by none

Calls _fn, check_bus_tags

Checks

  • assert len(out) == 1 and "on_message" in out[0].message and out[0].check == "bus"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-026measuredtest_a_handler_without_a_bus_tag_is_a_violation → check_bus_tags
Source · 4 lines
def test_a_handler_without_a_bus_tag_is_a_violation() -> None:
    """@brief A name matching a handler glob must carry a bus tag."""
    out = check_bus_tags([_fn("on_message")], "a.py", _BUS, _lines("pass"))
    assert len(out) == 1 and "on_message" in out[0].message and out[0].check == "bus"
Activity · 2 steps
lines 49–49out = check_bus_tags([_fn("on_message")], "a.py", _BUS, _lines("pass"))lines 50–50assert len(out) == 1 and "on_message" in out[0].message and out[0].check == "bus"

test_a_tagged_handler_passes_and_exemptions_are_honoured

test_a_tagged_handler_passes_and_exemptions_are_honoured()

tests/guard/test_guard_bus.py:53

Show on the map →

Called by none

Calls _fn, check_bus_tags

Checks

  • assert check_bus_tags([tagged, exempt], "a.py", _BUS, _lines("pass")) == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-026measuredtest_a_tagged_handler_passes_and_exemptions_are_honoured → check_bus_tags
Source · 8 lines
def test_a_tagged_handler_passes_and_exemptions_are_honoured() -> None:
    """THE EXISTING EXEMPTION MODEL, reused: a blanket rule would push repos to exempt everything.

    @brief A bus tag or an exemption tag satisfies the rule.
    """
    tagged = _fn("on_message", handles=["MQTT cmd/req"])
    exempt = _fn("on_click", callback=[""])
    assert check_bus_tags([tagged, exempt], "a.py", _BUS, _lines("pass")) == []
Activity · 3 steps
lines 58–58tagged = _fn("on_message", handles=["MQTT cmd/req"])lines 59–59exempt = _fn("on_click", callback=[""])lines 60–60assert check_bus_tags([tagged, exempt], "a.py", _BUS, _lines("pass")) == []

test_bus_tags_are_known_tags_when_configured

test_bus_tags_are_known_tags_when_configured()

tests/guard/test_guard_bus.py:86

Show on the map →

Called by none

Calls _fn, check_unknown_tags

Checks

  • assert check_unknown_tags(_fn("on_x", emits=["MQTT x"]), "a.py", _BUS) == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-001measuredtest_bus_tags_are_known_tags_when_configured → check_unknown_tags
REQ-DDB-GUARD-026catalog
Source · 3 lines
def test_bus_tags_are_known_tags_when_configured() -> None:
    """@brief A configured bus tag is not reported as unknown."""
    assert check_unknown_tags(_fn("on_x", emits=["MQTT x"]), "a.py", _BUS) == []
Activity · 1 steps
lines 88–88assert check_unknown_tags(_fn("on_x", emits=["MQTT x"]), "a.py", _BUS) == []

test_no_bus_section_means_no_rule

test_no_bus_section_means_no_rule()

tests/guard/test_guard_bus.py:81

Show on the map →

Called by none

Calls _fn, check_bus_tags

Checks

  • assert check_bus_tags([_fn("on_message")], "a.py", {"validate": {}}, _lines("pass")) == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-026measuredtest_no_bus_section_means_no_rule → check_bus_tags
Source · 3 lines
def test_no_bus_section_means_no_rule() -> None:
    """@brief Unconfigured, the rule checks nothing."""
    assert check_bus_tags([_fn("on_message")], "a.py", {"validate": {}}, _lines("pass")) == []
Activity · 1 steps
lines 83–83assert check_bus_tags([_fn("on_message")], "a.py", {"validate": {}}, _lines("pass")) == []

test_the_bus_section_is_part_of_the_validated_schema

test_the_bus_section_is_part_of_the_validated_schema()

tests/guard/test_guard_bus.py:91

Checks

  • assert validate_config_schema(_BUS) == []
  • assert validate_config_schema(bad)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measuredtest_the_bus_section_is_part_of_the_validated_schema → validate_config_schema
REQ-DDB-GUARD-026catalog
Source · 5 lines
def test_the_bus_section_is_part_of_the_validated_schema() -> None:
    """@brief `validate.bus` is accepted; an unknown key inside it is not."""
    assert validate_config_schema(_BUS) == []
    bad = {"validate": {"bus": {"vocabulary": ["MQTT"], "colour": "blue"}}}
    assert validate_config_schema(bad)
Activity · 3 steps
lines 93–93assert validate_config_schema(_BUS) == []lines 94–94bad = {"validate": {"bus": {"vocabulary": ["MQTT"], "colour": "blue"}}}lines 95–95assert validate_config_schema(bad)