Checks: check, matchers, refused

A named check or a table of checks; an expected API refusal with its code.

since 0.1.0-rc.1since 0.3.0

Methods

EntrySignatureAvailable sinceAPI 3
checkcheck(name, actual, expected=True); check(rows) -> int0.1.0-rc.1¹no calls in expressions
within, near, one_of, matcheswithin(low, high), near(value, tolerance), one_of(*options), matches(pattern)0.3.0unchanged
refusedwith refused(code, *, name=None, **details) as refusal0.3.0unchanged

¹ Base form; the 0.3.0 extensions are described in the card.

API 3 changes (0.5.0)

Unchanged, no await.

Recommended

Expectations by CMSIS names and matchers; a refusal through refused with code and effect.

from stm32_gdbtest import within, near, one_of

t.check("VDDA, mV", t.read("board_adc_reading.vdda_mv"), within(2800, 3600))
t.check("stand backend", t.profile.stand["backend"], one_of("openocd", "jlink"))
t.check([
    ("PA5 output", "GPIOA->MODER & GPIO_MODER_MODER5", "GPIO_MODER_MODER5_0"),
    ("timer running", "TIM3->CR1 & TIM_CR1_CEN"),
])
with t.refused("unsupported_argument", effect="none"):
    t.call("app_step", object())

Avoid

assert and a bare try/except give no name in the report and hide the refusal code. Magic numbers instead of CMSIS names escape the contract.

assert t.read("app_state.ticks") == 1                     # no named check
try:
    t.call("app_step", object())
except Exception:
    pass                                                    # hides the code and the effect
t.check("mode", t.read("GPIOA->MODER") & 0xC00, 0x400)    # magic numbers

The fragments show refused or discouraged patterns, not a working recipe.

Fragments for a scenario body; firmware symbols are illustrative.

← RegistersAll groupsInjection →