forked from p15670423/monkey
UT: Use AbstractAgentEvent in place of AbstractEvent
This commit is contained in:
parent
ce43a46a9c
commit
f577e48d72
|
@ -7,14 +7,14 @@ import pytest
|
||||||
from pubsub.core import Publisher
|
from pubsub.core import Publisher
|
||||||
|
|
||||||
from common.event_queue import EventSubscriber, IEventQueue, PyPubSubEventQueue
|
from common.event_queue import EventSubscriber, IEventQueue, PyPubSubEventQueue
|
||||||
from common.events import AbstractEvent
|
from common.events import AbstractAgentEvent
|
||||||
|
|
||||||
EVENT_TAG_1 = "event tag 1"
|
EVENT_TAG_1 = "event tag 1"
|
||||||
EVENT_TAG_2 = "event tag 2"
|
EVENT_TAG_2 = "event tag 2"
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class TestEvent1(AbstractEvent):
|
class TestEvent1(AbstractAgentEvent):
|
||||||
__test__ = False
|
__test__ = False
|
||||||
source: UUID = UUID("f811ad00-5a68-4437-bd51-7b5cc1768ad5")
|
source: UUID = UUID("f811ad00-5a68-4437-bd51-7b5cc1768ad5")
|
||||||
target: Union[UUID, IPv4Address, None] = None
|
target: Union[UUID, IPv4Address, None] = None
|
||||||
|
@ -23,7 +23,7 @@ class TestEvent1(AbstractEvent):
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class TestEvent2(AbstractEvent):
|
class TestEvent2(AbstractAgentEvent):
|
||||||
__test__ = False
|
__test__ = False
|
||||||
source: UUID = UUID("e810ad01-6b67-9446-fc58-9b8d717653f7")
|
source: UUID = UUID("e810ad01-6b67-9446-fc58-9b8d717653f7")
|
||||||
target: Union[UUID, IPv4Address, None] = None
|
target: Union[UUID, IPv4Address, None] = None
|
||||||
|
@ -37,8 +37,8 @@ def event_queue() -> IEventQueue:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def event_queue_subscriber() -> Callable[[AbstractEvent], None]:
|
def event_queue_subscriber() -> Callable[[AbstractAgentEvent], None]:
|
||||||
def fn(event: AbstractEvent):
|
def fn(event: AbstractAgentEvent):
|
||||||
fn.call_count += 1
|
fn.call_count += 1
|
||||||
fn.call_types.add(event.__class__)
|
fn.call_types.add(event.__class__)
|
||||||
fn.call_tags |= event.tags
|
fn.call_tags |= event.tags
|
||||||
|
@ -117,7 +117,7 @@ def test_keep_subscriber_in_scope(event_queue: IEventQueue):
|
||||||
class MyCallable:
|
class MyCallable:
|
||||||
called = False
|
called = False
|
||||||
|
|
||||||
def __call__(self, event: AbstractEvent):
|
def __call__(self, event: AbstractAgentEvent):
|
||||||
MyCallable.called = True
|
MyCallable.called = True
|
||||||
|
|
||||||
def subscribe():
|
def subscribe():
|
||||||
|
|
|
@ -4,21 +4,21 @@ from unittest.mock import MagicMock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from common.event_serializers import EventSerializerRegistry, IEventSerializer
|
from common.event_serializers import EventSerializerRegistry, IEventSerializer
|
||||||
from common.events import AbstractEvent
|
from common.events import AbstractAgentEvent
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class SomeEvent(AbstractEvent):
|
class SomeEvent(AbstractAgentEvent):
|
||||||
some_param: int = field(default=435)
|
some_param: int = field(default=435)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class OtherEvent(AbstractEvent):
|
class OtherEvent(AbstractAgentEvent):
|
||||||
other_param: float = field(default=123.456)
|
other_param: float = field(default=123.456)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class NoneEvent(AbstractEvent):
|
class NoneEvent(AbstractAgentEvent):
|
||||||
none_param: float = field(default=1.0)
|
none_param: float = field(default=1.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue