test_guard_exemption_reason.py

tests/guard/test_guard_exemption_reason.py

An exemption can be required to say why (PG3b; 2.0.0, owner Q/A 2026-11-19).

test_a_bare_exemption_is_refused_when_reasons_are_required

None test_guard_exemption_reason.test_a_bare_exemption_is_refused_when_reasons_are_required(str tag)

No reason, switch on: one violation naming the tag.

tests/guard/test_guard_exemption_reason.py:38

Checks

  • assert f"@{tag}" in v.message and "reason" in v.message

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-001measuredtest_a_bare_exemption_is_refused_when_reasons_are_required → check_exemption_reasons
Source · 6 lines
def test_a_bare_exemption_is_refused_when_reasons_are_required(tag: str) -> None:
    """@brief No reason, switch on: one violation naming the tag."""
    (v,) = check_exemption_reasons(_func(tag, ""), "a.c", _REQUIRED)
    assert f"@{tag}" in v.message and "reason" in v.message

Activity · 2 steps
lines 40–40(v,) = check_exemption_reasons(_func(tag, ""), "a.c", _REQUIRED)lines 41–41assert f"@{tag}" in v.message and "reason" in v.message

test_a_reasoned_exemption_passes

None test_guard_exemption_reason.test_a_reasoned_exemption_passes()

A one-line reason satisfies it.

tests/guard/test_guard_exemption_reason.py:44

Checks

  • assert (check_exemption_reasons(_func("utility", "parses the header for the loader"), "a.c", _REQUIRED ) == [] )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-001measuredtest_a_reasoned_exemption_passes → check_exemption_reasons
Source · 10 lines
def test_a_reasoned_exemption_passes() -> None:
    """@brief A one-line reason satisfies it."""
    assert (
        check_exemption_reasons(
            _func("utility", "parses the header for the loader"), "a.c", _REQUIRED
        )
        == []
    )

Activity · 1 steps
lines 46–51assert ( check_exemption_reasons( _func("utility", "parses the header for the loader"), "a.c", _REQUIRED ) == [] )

test_an_unknown_setting_is_refused

None test_guard_exemption_reason.test_an_unknown_setting_is_refused()

`required` or `optional`; anything else named.

tests/guard/test_guard_exemption_reason.py:59

Checks

  • assert any("exemption_reason" in e for e in errors), errors

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measuredtest_an_unknown_setting_is_refused → validate_config_schema
Source · 4 lines
def test_an_unknown_setting_is_refused() -> None:
    """@brief `required` or `optional`; anything else named."""
    errors = validate_config_schema({"validate": {"exemption_reason": "mandatory"}})
    assert any("exemption_reason" in e for e in errors), errors

1 more lines, not shown

Activity · 2 steps
lines 61–61errors = validate_config_schema({"validate": {"exemption_reason": "mandatory"}})lines 62–62assert any("exemption_reason" in e for e in errors), errors

test_reasons_are_optional_by_default

None test_guard_exemption_reason.test_reasons_are_optional_by_default()

Default: a bare exemption is fine.

tests/guard/test_guard_exemption_reason.py:54

Checks

  • assert check_exemption_reasons(_func("utility", ""), "a.c", CONFIG_DEFAULTS) == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-001measuredtest_reasons_are_optional_by_default → check_exemption_reasons
Source · 5 lines
def test_reasons_are_optional_by_default() -> None:
    """@brief Default: a bare exemption is fine."""
    assert check_exemption_reasons(_func("utility", ""), "a.c", CONFIG_DEFAULTS) == []

Activity · 1 steps
lines 56–56assert check_exemption_reasons(_func("utility", ""), "a.c", CONFIG_DEFAULTS) == []