Skip to content

castlecraft_engineer.testing.command_bus

castlecraft_engineer.testing.command_bus

DummyCommandHandlerOnly(DummyCommandOnly)

Provides a dummy CommandHandler class.

Source code in src/castlecraft_engineer/testing/command_bus.py
@pytest.fixture(scope="class")
def DummyCommandHandlerOnly(
    DummyCommandOnly: Type[_DummyCommand],
) -> Type[_DummyCommandHandler]:
    """Provides a dummy CommandHandler class."""
    return _DummyCommandHandler

DummyCommandHandlerWithDependencyOnly(DummyCommandWithDependencyOnly, DummyDependencyOnly)

Provides a dummy CommandHandler class with a dependency.

Source code in src/castlecraft_engineer/testing/command_bus.py
@pytest.fixture(scope="class")
def DummyCommandHandlerWithDependencyOnly(
    DummyCommandWithDependencyOnly: Type[_DummyCommandWithDependency],
    DummyDependencyOnly: Type[_DummyDependency],
) -> Type[_DummyCommandHandlerWithDependency]:
    """Provides a dummy CommandHandler class with a dependency."""
    return _DummyCommandHandlerWithDependency

DummyCommandOnly()

Provides a dummy Command class.

Source code in src/castlecraft_engineer/testing/command_bus.py
@pytest.fixture(scope="class")
def DummyCommandOnly() -> Type[_DummyCommand]:
    """Provides a dummy Command class."""
    return _DummyCommand

DummyCommandWithDependencyOnly()

Provides a dummy Command class requiring a handler with dependency.

Source code in src/castlecraft_engineer/testing/command_bus.py
@pytest.fixture(scope="class")
def DummyCommandWithDependencyOnly() -> Type[_DummyCommandWithDependency]:
    """Provides a dummy Command class requiring a handler with dependency."""
    return _DummyCommandWithDependency

DummyDependencyOnly()

Provides a dummy dependency class.

Source code in src/castlecraft_engineer/testing/command_bus.py
@pytest.fixture(scope="class")
def DummyDependencyOnly() -> Type[_DummyDependency]:
    """Provides a dummy dependency class."""
    return _DummyDependency

clean_container_for_bus_tests()

Provides a fresh, isolated punq container for each test by patching the global 'container' used by the CommandBus. Ensures test isolation for DI registrations.

Source code in src/castlecraft_engineer/testing/command_bus.py
@pytest.fixture(autouse=True)
def clean_container_for_bus_tests() -> Iterator[punq.Container]:
    """
    Provides a fresh, isolated punq container for each test
    by patching the global 'container' used by the CommandBus.
    Ensures test isolation for DI registrations.
    """
    isolated_container = punq.Container()

    yield isolated_container

command_bus_instance(clean_container_for_bus_tests)

Provides a clean CommandBus instance for testing.

Source code in src/castlecraft_engineer/testing/command_bus.py
@pytest.fixture
def command_bus_instance(clean_container_for_bus_tests) -> CommandBus:
    """Provides a clean CommandBus instance for testing."""

    return CommandBus(
        container=clean_container_for_bus_tests,
    )