From 60a349f918fd46c5b1e556d971c85f604f9c5d49 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 16 Apr 2023 22:01:15 +0200 Subject: [PATCH] [WIP] Fixed imports --- .../internal/async_action.py | 14 +++++-- .../observable_operator_test_case.py | 38 ++++++++++--------- .../reactive_test_case.py | 7 +++- .../scheduler_test_case.py | 20 +++++----- 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/cpl_reactive_extensions/internal/async_action.py b/src/cpl_reactive_extensions/internal/async_action.py index 4b5b18a0..30e89080 100644 --- a/src/cpl_reactive_extensions/internal/async_action.py +++ b/src/cpl_reactive_extensions/internal/async_action.py @@ -84,14 +84,20 @@ class AsyncAction(Action): if self.closed: return - self._scheduler.actions.remove(self) - - if self._timer is not None: - self._timer = self.recycle_async_timer(self._scheduler, self.timer, None) + timer = self.timer + scheduler = self._scheduler + actions = self._scheduler.actions self._work = None self.state = None self._scheduler = None self._pending = False self.delay = None + + if self in actions: + actions.remove(self) + + if self.timer is not None: + self.timer = self.recycle_async_timer(scheduler, timer, None) + Action.unsubscribe(self) diff --git a/unittests/unittests_reactive_extenstions/observable_operator_test_case.py b/unittests/unittests_reactive_extenstions/observable_operator_test_case.py index c00dd850..95779456 100644 --- a/unittests/unittests_reactive_extenstions/observable_operator_test_case.py +++ b/unittests/unittests_reactive_extenstions/observable_operator_test_case.py @@ -33,9 +33,10 @@ class ObservableOperatorTestCase(unittest.TestCase): count += 1 observable = Interval(0.1) - observable.pipe(take(2)).subscribe(sub) + sub = observable.pipe(take(2)).subscribe(sub) time.sleep(0.5) self.assertEqual(count, 2) + sub.unsubscribe() def test_take_five(self): count = 0 @@ -46,9 +47,10 @@ class ObservableOperatorTestCase(unittest.TestCase): count += 1 observable = Interval(0.1) - observable.pipe(take(5)).subscribe(sub) + sub = observable.pipe(take(5)).subscribe(sub) time.sleep(1) self.assertEqual(count, 5) + sub.unsubscribe() def test_take_until(self): count = 0 @@ -68,19 +70,19 @@ class ObservableOperatorTestCase(unittest.TestCase): unsubscriber.complete() self.assertEqual(count, timer * 10 - 1) - def test_debounce_time(self): - def call(x): - x.next(1) - x.next(2) - x.next(3) - x.next(4) - x.next(5) - x.next(6) - x.complete() - - observable = Observable(call) - - sub = observable.pipe(debounce_time(600)).subscribe(lambda x: Console.write_line("Hey", x)) - - time.sleep(2) - sub.unsubscribe() + # def test_debounce_time(self): + # def call(x): + # x.next(1) + # x.next(2) + # x.next(3) + # x.next(4) + # x.next(5) + # x.next(6) + # x.complete() + # + # observable = Observable(call) + # + # sub = observable.pipe(debounce_time(600)).subscribe(lambda x: Console.write_line("Hey", x)) + # + # time.sleep(2) + # sub.unsubscribe() diff --git a/unittests/unittests_reactive_extenstions/reactive_test_case.py b/unittests/unittests_reactive_extenstions/reactive_test_case.py index 28619411..10b35bfb 100644 --- a/unittests/unittests_reactive_extenstions/reactive_test_case.py +++ b/unittests/unittests_reactive_extenstions/reactive_test_case.py @@ -92,11 +92,12 @@ class ReactiveTestCase(unittest.TestCase): expected_x += 1 observable = Observable.from_list([1, 2, 3, 4]) - observable.subscribe( + sub = observable.subscribe( _next, self._on_error, ) self.assertFalse(self._error) + sub.unsubscribe() def test_subject(self): expected_x = 1 @@ -115,9 +116,10 @@ class ReactiveTestCase(unittest.TestCase): subject.subscribe(lambda x: _next(True, x), self._on_error) observable = Observable.from_list([1, 2, 3]) - observable.subscribe(subject, self._on_error) + sub = observable.subscribe(subject, self._on_error) self.assertFalse(self._error) + sub.unsubscribe() def test_behavior_subject(self): subject = BehaviorSubject(int, 0) @@ -129,6 +131,7 @@ class ReactiveTestCase(unittest.TestCase): subject.subscribe(lambda x: Console.write_line("b", x)) subject.next(3) + subject.unsubscribe() def test_interval_default(self): wait = 10 diff --git a/unittests/unittests_reactive_extenstions/scheduler_test_case.py b/unittests/unittests_reactive_extenstions/scheduler_test_case.py index bfa3b126..18c1523b 100644 --- a/unittests/unittests_reactive_extenstions/scheduler_test_case.py +++ b/unittests/unittests_reactive_extenstions/scheduler_test_case.py @@ -3,7 +3,6 @@ import unittest from datetime import datetime from cpl_core.console import Console -from cpl_reactive_extensions.scheduler.async_scheduler import async_scheduler from cpl_reactive_extensions.timer import Timer @@ -25,13 +24,12 @@ class SchedulerTestCase(unittest.TestCase): timer.clear() def test_schedule(self): - pass - # count = 0 - # - # def task(): - # nonlocal count - # Console.write_line(datetime.now(), "Hello world") - # count += 1 - # - # # async_scheduler.schedule(task, 100) - # time.sleep(2) + count = 0 + + def task(): + nonlocal count + Console.write_line(datetime.now(), "Hello world") + count += 1 + + # async_scheduler.schedule(task, 100) + time.sleep(2)