PublishedList

class safir.metrics.PublishedList(iterable=(), /)

Bases: list[P]

A list of event payload models with assertion helpers.

All assertion helpers take lists of dicts as expected items and use the model_dump(mode="json") serialization of the models for comparison.

Methods Summary

assert_published(expected, *[, any_order])

Assert that all of the expected payloads were published.

assert_published_all(expected, *[, any_order])

Assert that all of the expected payloads, and only the expected payloads, were published.

Methods Documentation

assert_published(expected, *, any_order=False)

Assert that all of the expected payloads were published.

Parameters:
  • expected (list[dict[str, Any]]) – A list of expected event payload dicts, to be compared with the model_dump(format="json") serialization of the actual published payloads.

  • any_order (bool, default: False) – If true, then the expected payload list must be an ordered subset of the actual published payloads. This is like the any_order parameter in unittest.mock.Mock methods.

Raises:
Return type:

None

assert_published_all(expected, *, any_order=False)

Assert that all of the expected payloads, and only the expected payloads, were published.

Parameters:
  • expected (list[dict[str, Any]]) – A list of expected event payload dicts, to be compared with the model_dump(format="json") serialization of the actual published payloads.

  • any_order (bool, default: False) – If true, then the expected payloads must be in the same order as the actual published payloads. This is like the any_order parameter in unittest.mock.Mock methods.

Raises:
Return type:

None