From 24683c895414c336ab558b0d1de3a4b716fd3a6d Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Sun, 4 Aug 2019 16:11:14 +0200 Subject: [PATCH] Add test for handler signature --- .../tracetools_analysis/test_processor.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tracetools_analysis/test/tracetools_analysis/test_processor.py b/tracetools_analysis/test/tracetools_analysis/test_processor.py index 1b25d62..e0614d9 100644 --- a/tracetools_analysis/test/tracetools_analysis/test_processor.py +++ b/tracetools_analysis/test/tracetools_analysis/test_processor.py @@ -51,6 +51,19 @@ class StubHandler2(EventHandler): 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): def __init__(self, *args) -> None: @@ -58,6 +71,17 @@ class TestProcessor(unittest.TestCase): *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: handler1 = StubHandler1() handler2 = StubHandler2()