Skip to content

featherweight.testing

testing

Helpers for testing code that uses featherweight, and for checking an implementation of one of its abstract classes.

MemoryResultStore

MemoryResultStore()

Bases: ResultStore

A ResultStore in a dict: nothing survives the process. For tests, and the smallest example of the class.

MemoryQueue

MemoryQueue(lease: float = 60.0)

Bases: JobQueue

A JobQueue in memory: nothing survives the process. For tests, and the smallest example of the class. A received message is leased for lease seconds (pass a very short one in a test): if it is not acked, nacked or extended in time, it is delivered again with a higher delivery_count. There is no limit on redeliveries.

RecordingObserver

RecordingObserver()

Bases: Observer

An Observer that keeps what it hears, as (hook, record) pairs in events, for tests. It asks for no content: use RecordingContentObserver for one that does.

check_result_store async

check_result_store(
    make_store: Callable[
        [], ResultStore | Awaitable[ResultStore]
    ],
) -> None

Run the ResultStore contract against a store. make_store returns a fresh, empty store (it may be async). Raises AssertionError that says which rule a store breaks.

async def test_my_store():
    await check_result_store(lambda: MyStore(...))

check_database async

check_database(make_db: Callable[[], Database]) -> None

Run the Database contract against an implementation. make_db returns a fresh, empty, unopened database; the kit opens and closes it. Raises AssertionError that says which rule an implementation breaks.

async def test_my_database():
    await check_database(lambda: MyDatabase(...))

check_queue async

check_queue(
    make_queue: Callable[
        [float], JobQueue | Awaitable[JobQueue]
    ],
) -> None

Run the JobQueue contract against a queue. make_queue(lease) returns a fresh, empty queue whose lease is lease seconds (it may be async): the kit uses a short one to see a message come back, and needs a queue that delivers a message at least three times. Raises AssertionError that says which rule a queue breaks.

async def test_my_queue():
    await check_queue(lambda lease: MyQueue(visibility_timeout=lease))

check_observer async

check_observer(
    make_observer: Callable[
        [], Observer | Awaitable[Observer]
    ],
) -> None

Run the Observer contract against an observer: every hook accepts its record and fails nothing, a scope can be entered, finished and left, submitted returns nothing or a mapping of strings, and no hook changes the record it was given. Raises AssertionError that says which rule an observer breaks.

async def test_my_observer():
    await check_observer(lambda: MyObserver(...))