MockEventManager

class safir.metrics.MockEventManager(application, topic_prefix, logger=None)

Bases: EventManager

An event manager that creates mock publishers that record all publishes.

This is used as the implementation of EventManager when event publication is disabled and mocking is enabled. Like a NoopEventManager, the event type registrations are still verified to catch errors, but any calls to MockEventPublisher are recorded for later assertion.

This is for use only in unit testing. Don’t use it in any deployed environment because memory usage will grow unbounded.

Parameters:
  • application (str) – Name of the application that is generating events.

  • topic_prefix (str) – Kafka topic prefix for the metrics events topic for this application.

  • logger (BoundLogger | None, default: None) – Logger to use for internal logging.

Methods Summary

build_publisher_for_model(model)

Build a no-op recording publisher for a specific enriched model.

Methods Documentation

async build_publisher_for_model(model)

Build a no-op recording publisher for a specific enriched model.

Parameters:

model (type[TypeVar(P, bound= EventPayload)]) – Enriched and configured model representing the event that will be published.

Returns:

An appropriate event publisher implementation instance.

Return type:

EventPublisher