Add test for handler signature

This commit is contained in:
Christophe Bedard 2019-08-04 16:11:14 +02:00
parent 831ae22872
commit 24683c8954

View file

@ -51,6 +51,19 @@ class StubHandler2(EventHandler):
self.handler_called = True self.handler_called = True
class WrongHandler(EventHandler):
def __init__(self) -> None:
handler_map = {
'myeventname': self._handler_wrong,
}
super().__init__(handler_map=handler_map)
def _handler_wrong(
self,
) -> None:
pass
class TestProcessor(unittest.TestCase): class TestProcessor(unittest.TestCase):
def __init__(self, *args) -> None: def __init__(self, *args) -> None:
@ -58,6 +71,17 @@ class TestProcessor(unittest.TestCase):
*args, *args,
) )
def test_handler_wrong_signature(self) -> None:
handler = WrongHandler()
mock_event = {
'_name': 'myeventname',
'_timestamp': 0,
'cpu_id': 0,
}
processor = Processor(handler)
with self.assertRaises(TypeError):
processor.process([mock_event])
def test_handler_method_with_merge(self) -> None: def test_handler_method_with_merge(self) -> None:
handler1 = StubHandler1() handler1 = StubHandler1()
handler2 = StubHandler2() handler2 = StubHandler2()