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
Checks
assert len(out) == 1 and "KAFKA" in out[0].message
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-026 | measured | test_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].messageActivity · 2 steps
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
Checks
assert [v.message.split("'")[1] for v in out] == ["send_status"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-026 | measured | test_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
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
Checks
assert len(out) == 1 and "on_message" in out[0].message and out[0].check == "bus"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-026 | measured | test_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
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
Checks
assert check_bus_tags([tagged, exempt], "a.py", _BUS, _lines("pass")) == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-026 | measured | test_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
test_bus_tags_are_known_tags_when_configured
test_bus_tags_are_known_tags_when_configured()
tests/guard/test_guard_bus.py:86
Checks
assert check_unknown_tags(_fn("on_x", emits=["MQTT x"]), "a.py", _BUS) == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-001 | measured | test_bus_tags_are_known_tags_when_configured → check_unknown_tags |
| REQ-DDB-GUARD-026 | catalog |
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
test_no_bus_section_means_no_rule
test_no_bus_section_means_no_rule()
tests/guard/test_guard_bus.py:81
Checks
assert check_bus_tags([_fn("on_message")], "a.py", {"validate": {}}, _lines("pass")) == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-026 | measured | test_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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-012 | measured | test_the_bus_section_is_part_of_the_validated_schema → validate_config_schema |
| REQ-DDB-GUARD-026 | catalog |
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)