From 0a9384e67045a28f847677de9f58d5dacae996fe Mon Sep 17 00:00:00 2001 From: Davide Casale Date: Tue, 7 Feb 2023 17:45:03 +0100 Subject: [PATCH] Add new bfxapi/tests/test_notification unit test. --- bfxapi/labeler.py | 2 +- bfxapi/tests/__init__.py | 2 ++ bfxapi/tests/test_notification.py | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 bfxapi/tests/test_notification.py diff --git a/bfxapi/labeler.py b/bfxapi/labeler.py index 1c2655d..79f5ed4 100644 --- a/bfxapi/labeler.py +++ b/bfxapi/labeler.py @@ -19,7 +19,7 @@ class _Serializer(Generic[T]): labels = list(filter(lambda label: label not in (skip or list()), self.__labels)) if len(labels) > len(args): - raise LabelerSerializerException(" and <*args> arguments should contain the same amount of elements.") + raise LabelerSerializerException(f"{self.name} -> and <*args> arguments should contain the same amount of elements.") for index, label in enumerate(labels): if label not in self.__IGNORE: diff --git a/bfxapi/tests/__init__.py b/bfxapi/tests/__init__.py index 25965b4..a63ea0d 100644 --- a/bfxapi/tests/__init__.py +++ b/bfxapi/tests/__init__.py @@ -2,6 +2,7 @@ import unittest from .test_rest_serializers_and_types import TestRestSerializersAndTypes from .test_websocket_serializers_and_types import TestWebsocketSerializersAndTypes from .test_labeler import TestLabeler +from .test_notification import TestNotification NAME = "tests" @@ -10,6 +11,7 @@ def suite(): unittest.makeSuite(TestRestSerializersAndTypes), unittest.makeSuite(TestWebsocketSerializersAndTypes), unittest.makeSuite(TestLabeler), + unittest.makeSuite(TestNotification), ]) if __name__ == "__main__": diff --git a/bfxapi/tests/test_notification.py b/bfxapi/tests/test_notification.py new file mode 100644 index 0000000..f71df60 --- /dev/null +++ b/bfxapi/tests/test_notification.py @@ -0,0 +1,25 @@ +import unittest + +from dataclasses import dataclass +from ..labeler import generate_labeler_serializer +from ..notification import _Type, _Notification, Notification + +class TestNotification(unittest.TestCase): + def test_notification(self): + @dataclass + class Test(_Type): + A: int + B: float + C: str + + test = generate_labeler_serializer("Test", Test, + [ "A", "_PLACEHOLDER", "B", "_PLACEHOLDER", "C" ]) + + notification = _Notification[Test](test) + + self.assertEqual(notification.parse(*[1675787861506, "test", None, None, [ 5, None, 65.0, None, "X" ], 0, "SUCCESS", "This is just a test notification."]), + Notification[Test](1675787861506, "test", None, Test(5, 65.0, "X"), 0, "SUCCESS", "This is just a test notification."), + msg="_Notification should produce the right notification.") + +if __name__ == "__main__": + unittest.main() \ No newline at end of file