From 79a6c1db8fd07981a65487e589a32bca486bffef Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 16 Apr 2023 00:57:35 +0200 Subject: [PATCH] Improved imports --- src/cpl_reactive_extensions/__init__.py | 8 ++++++- src/cpl_reactive_extensions/abc/__init__.py | 5 ++++ .../reactive_test_case.py | 24 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/cpl_reactive_extensions/__init__.py b/src/cpl_reactive_extensions/__init__.py index 2b4c06ff..ee1370bd 100644 --- a/src/cpl_reactive_extensions/__init__.py +++ b/src/cpl_reactive_extensions/__init__.py @@ -19,8 +19,14 @@ __version__ = "2023.4.dev170" from collections import namedtuple - # imports +from .behavior_subject import BehaviorSubject +from .interval import Interval +from .observable import Observable +from .subject import Subject +from .subscriber import Subscriber +from .subscription import Subscription +from .type import ObserverOrCallable VersionInfo = namedtuple("VersionInfo", "major minor micro") version_info = VersionInfo(major="2023", minor="4", micro="dev170") diff --git a/src/cpl_reactive_extensions/abc/__init__.py b/src/cpl_reactive_extensions/abc/__init__.py index 41ecc2b3..7cedfcf7 100644 --- a/src/cpl_reactive_extensions/abc/__init__.py +++ b/src/cpl_reactive_extensions/abc/__init__.py @@ -21,6 +21,11 @@ from collections import namedtuple # imports +from .observer import Observer +from .operator import Operator +from .subscribable import Subscribable +from .unsubscribable import Unsubscribable + VersionInfo = namedtuple("VersionInfo", "major minor micro") version_info = VersionInfo(major="2023", minor="4", micro="dev170") diff --git a/unittests/unittests_reactive_extenstions/reactive_test_case.py b/unittests/unittests_reactive_extenstions/reactive_test_case.py index a374f0d5..a0cff291 100644 --- a/unittests/unittests_reactive_extenstions/reactive_test_case.py +++ b/unittests/unittests_reactive_extenstions/reactive_test_case.py @@ -148,3 +148,27 @@ class ReactiveTestCase(unittest.TestCase): sub.unsubscribe() end = datetime.now() self.assertEqual(round((end - start).total_seconds()), wait) + + def test_interval_custom(self): + wait = 10 + i = 0 + n = 0 + + def callback(x: Observer): + nonlocal n + x.next(n) + n += 1 + + def test_sub(x): + nonlocal i + self.assertEqual(x, i) + i += 1 + + observable = Interval(1.0, callback) + sub = observable.subscribe(test_sub) + start = datetime.now() + + time.sleep(wait) + sub.unsubscribe() + end = datetime.now() + self.assertEqual(round((end - start).total_seconds()), wait)