[WIP] Fixed imports

This commit is contained in:
Sven Heidemann 2023-04-16 22:01:15 +02:00
parent a155bbc468
commit 60a349f918
4 changed files with 44 additions and 35 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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

View File

@ -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)