Build 060.20.1: implement Trade Runtime Layer
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
# app/tests/unit/market_data/acquisition/runtime/trade/test_trade_runtime_registry.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from src.market_data.acquisition.runtime.trade.trade_runtime_exceptions import (
|
||||
InvalidRuntimeComponentError,
|
||||
RuntimeAlreadyRegisteredError,
|
||||
RuntimeNotRegisteredError,
|
||||
)
|
||||
from src.market_data.acquisition.runtime.trade.trade_runtime_registry import (
|
||||
TradeRuntimeRegistry,
|
||||
)
|
||||
|
||||
|
||||
class DummyComponent:
|
||||
"""Тестовый Runtime-компонент."""
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def component() -> DummyComponent:
|
||||
"""Создаёт тестовый Runtime-компонент."""
|
||||
return DummyComponent()
|
||||
|
||||
|
||||
def test_registry_is_empty_after_creation() -> None:
|
||||
registry = TradeRuntimeRegistry()
|
||||
|
||||
assert registry.is_registered("component") is False
|
||||
|
||||
|
||||
def test_is_registered_returns_false_for_unknown_key() -> None:
|
||||
registry = TradeRuntimeRegistry()
|
||||
|
||||
assert registry.is_registered("unknown") is False
|
||||
|
||||
|
||||
def test_register_component(component: DummyComponent) -> None:
|
||||
registry = TradeRuntimeRegistry()
|
||||
|
||||
registry.register("component", component)
|
||||
|
||||
assert registry.is_registered("component") is True
|
||||
|
||||
|
||||
def test_get_returns_registered_component(
|
||||
component: DummyComponent,
|
||||
) -> None:
|
||||
registry = TradeRuntimeRegistry()
|
||||
|
||||
registry.register("component", component)
|
||||
|
||||
assert registry.get("component") is component
|
||||
|
||||
|
||||
def test_is_registered_returns_true_after_registration(
|
||||
component: DummyComponent,
|
||||
) -> None:
|
||||
registry = TradeRuntimeRegistry()
|
||||
|
||||
registry.register("component", component)
|
||||
|
||||
assert registry.is_registered("component") is True
|
||||
|
||||
|
||||
def test_register_none_raises_invalid_runtime_component_error() -> None:
|
||||
registry = TradeRuntimeRegistry()
|
||||
|
||||
with pytest.raises(InvalidRuntimeComponentError):
|
||||
registry.register("component", None)
|
||||
|
||||
|
||||
def test_register_duplicate_key_raises_runtime_already_registered_error(
|
||||
component: DummyComponent,
|
||||
) -> None:
|
||||
registry = TradeRuntimeRegistry()
|
||||
|
||||
registry.register("component", component)
|
||||
|
||||
with pytest.raises(RuntimeAlreadyRegisteredError):
|
||||
registry.register("component", DummyComponent())
|
||||
|
||||
|
||||
def test_unregister_component(
|
||||
component: DummyComponent,
|
||||
) -> None:
|
||||
registry = TradeRuntimeRegistry()
|
||||
|
||||
registry.register("component", component)
|
||||
registry.unregister("component")
|
||||
|
||||
assert registry.is_registered("component") is False
|
||||
|
||||
with pytest.raises(RuntimeNotRegisteredError):
|
||||
registry.get("component")
|
||||
|
||||
|
||||
def test_unregister_unknown_component_raises_runtime_not_registered_error() -> None:
|
||||
registry = TradeRuntimeRegistry()
|
||||
|
||||
with pytest.raises(RuntimeNotRegisteredError):
|
||||
registry.unregister("unknown")
|
||||
|
||||
|
||||
def test_clear_removes_all_components() -> None:
|
||||
registry = TradeRuntimeRegistry()
|
||||
|
||||
registry.register("component_1", DummyComponent())
|
||||
registry.register("component_2", DummyComponent())
|
||||
registry.register("component_3", DummyComponent())
|
||||
|
||||
registry.clear()
|
||||
|
||||
assert registry.is_registered("component_1") is False
|
||||
assert registry.is_registered("component_2") is False
|
||||
assert registry.is_registered("component_3") is False
|
||||
|
||||
with pytest.raises(RuntimeNotRegisteredError):
|
||||
registry.get("component_1")
|
||||
|
||||
with pytest.raises(RuntimeNotRegisteredError):
|
||||
registry.get("component_2")
|
||||
|
||||
with pytest.raises(RuntimeNotRegisteredError):
|
||||
registry.get("component_3")
|
||||
Reference in New Issue
Block a user