本文整理汇总了Python中rx.testing.TestScheduler.schedule_absolute方法的典型用法代码示例。如果您正苦于以下问题:Python TestScheduler.schedule_absolute方法的具体用法?Python TestScheduler.schedule_absolute怎么用?Python TestScheduler.schedule_absolute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.testing.TestScheduler
的用法示例。
在下文中一共展示了TestScheduler.schedule_absolute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multicast_hot_4
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import schedule_absolute [as 别名]
def test_multicast_hot_4(self):
c = [None]
d1 = [None]
d2 = [None]
ex = 'ex'
scheduler = TestScheduler()
xs = scheduler.create_hot_observable(on_next(40, 0), on_next(90, 1), on_next(150, 2), on_next(210, 3), on_next(240, 4), on_next(270, 5), on_next(330, 6), on_next(340, 7), on_error(390, ex))
s = Subject()
o = scheduler.create_observer()
def action0(scheduler, state):
c[0] = xs.multicast(s)
scheduler.schedule_absolute(50, action0)
def action1(scheduler, state):
d2[0] = c[0].connect()
scheduler.schedule_absolute(100, action1)
def action2(scheduler, state):
d1[0] = c[0].subscribe(o)
scheduler.schedule_absolute(200, action2)
def action3(scheduler, state):
d2[0].dispose()
scheduler.schedule_absolute(300, action3)
def action4(scheduler, state):
d2[0] = c[0].connect()
scheduler.schedule_absolute(335, action4)
scheduler.start()
o.messages.assert_equal(on_next(210, 3), on_next(240, 4), on_next(270, 5), on_next(340, 7), on_error(390, ex))
xs.subscriptions.assert_equal(subscribe(100, 300), subscribe(335, 390))
示例2: test_retry_observable_retry_count_throws
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import schedule_absolute [as 别名]
def test_retry_observable_retry_count_throws(self):
scheduler1 = TestScheduler()
xs = rx.return_value(1).pipe(ops.retry(3))
xs.subscribe(lambda x: _raise('ex'), scheduler=scheduler1)
self.assertRaises(RxException, scheduler1.start)
scheduler2 = TestScheduler()
ys = rx.throw('ex').pipe(ops.retry(100))
d = ys.subscribe(on_error=lambda ex: _raise('ex'), scheduler=scheduler2)
def dispose(_, __):
d.dispose()
scheduler2.schedule_absolute(0, dispose)
scheduler2.start()
scheduler3 = TestScheduler()
zs = rx.return_value(1).pipe(ops.retry(100))
zs.subscribe(on_completed=lambda: _raise('ex'), scheduler=scheduler3)
with pytest.raises(RxException):
scheduler3.start()
xss = rx.create(lambda o: _raise('ex')).pipe(ops.retry(100))
with pytest.raises(Exception):
xss.subscribe()
示例3: test_paused_with_state_change_in_subscriber
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import schedule_absolute [as 别名]
def test_paused_with_state_change_in_subscriber(self):
scheduler = TestScheduler()
results = scheduler.create_observer()
xs = scheduler.create_hot_observable(
on_next(150, 1), on_next(210, 2), on_next(250, 3), on_next(270, 4), on_next(330, 5), on_completed(500)
)
controller = Subject()
pausable_buffered = xs.pausable_buffered(controller)
def action1(scheduler, state):
def on_next(value):
results.on_next(value)
controller.on_next(False)
def action2(scheduler, state):
controller.on_next(True)
scheduler.schedule_relative(100, action2)
subscription = pausable_buffered.subscribe(on_next, results.on_error, results.on_completed)
controller.on_next(True)
scheduler.schedule_absolute(200, action1)
scheduler.start()
results.messages.assert_equal(
on_next(210, 2), on_next(310, 3), on_next(310, 4), on_next(410, 5), on_completed(500)
)
示例4: test_paused_with_immediate_unpause
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import schedule_absolute [as 别名]
def test_paused_with_immediate_unpause(self):
subscription = [None]
scheduler = TestScheduler()
results = scheduler.create_observer()
xs = scheduler.create_hot_observable(
on_next(150, 1),
on_next(210, 2),
on_completed(500)
)
controller = Observable.just(True)
pausable_buffered = xs.pausable_buffered(controller)
def action1(scheduler, state):
subscription[0] = pausable_buffered.subscribe(results)
scheduler.schedule_absolute(200, action1)
scheduler.start()
results.messages.assert_equal(
on_next(210, 2),
on_completed(500)
)
示例5: test_map_disposeinsidemapper
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import schedule_absolute [as 别名]
def test_map_disposeinsidemapper(self):
scheduler = TestScheduler()
xs = scheduler.create_hot_observable(on_next(100, 1), on_next(200, 2), on_next(500, 3), on_next(600, 4))
results = scheduler.create_observer()
d = SerialDisposable()
invoked = [0]
def projection(x, *args, **kw):
invoked[0] += 1
if scheduler.clock > 400:
d.dispose()
return x
d.disposable = xs.pipe(
map(projection)
).subscribe(results, scheduler)
def action(scheduler, state):
return d.dispose()
scheduler.schedule_absolute(ReactiveTest.disposed, action)
scheduler.start()
assert results.messages == [on_next(100, 1), on_next(200, 2)]
assert xs.subscriptions == [ReactiveTest.subscribe(0, 500)]
assert invoked[0] == 3
示例6: test_multicast_hot_3
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import schedule_absolute [as 别名]
def test_multicast_hot_3(self):
c = [None]
d1 = [None]
d2 = [None]
scheduler = TestScheduler()
xs = scheduler.create_hot_observable(on_next(40, 0), on_next(90, 1), on_next(150, 2), on_next(210, 3), on_next(240, 4), on_next(270, 5), on_next(330, 6), on_next(340, 7), on_completed(390))
s = Subject()
o = scheduler.create_observer()
def action0(scheduler, state):
c[0] = xs.pipe(ops.multicast(s))
scheduler.schedule_absolute(50, action0)
def action1(scheduler, state):
d2[0] = c[0].connect(scheduler)
scheduler.schedule_absolute(100, action1)
def action2(scheduler, state):
d1[0] = c[0].subscribe(o)
scheduler.schedule_absolute(200, action2)
def action3(scheduler, state):
d2[0].dispose()
scheduler.schedule_absolute(300, action3)
def action4(scheduler, state):
d2[0] = c[0].connect(scheduler)
scheduler.schedule_absolute(335, action4)
scheduler.start()
assert o.messages == [on_next(210, 3), on_next(240, 4), on_next(270, 5), on_next(340, 7), on_completed(390)]
assert xs.subscriptions == [subscribe(100, 300), subscribe(335, 390)]
示例7: test_group_by_with_merge
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import schedule_absolute [as 别名]
def test_group_by_with_merge(self):
scheduler = TestScheduler()
xs = [None]
results = [None]
def action1(scheduler, state):
xs[0] = Observable.from_(["alpha", "apple", "beta", "bat", "gamma"]) \
.group_by(lambda s: s[0]) \
.map(lambda group: group.to_list()) \
.merge_all()
scheduler.schedule_absolute(created, action1)
def action2(scheduler, state):
results[0] = scheduler.create_observer()
xs[0].subscribe(results[0])
scheduler.schedule_absolute(subscribed, action2)
scheduler.start()
results[0].messages.assert_equal(
on_next(200, ["alpha", "apple"]),
on_next(200, ["beta", "bat"]),
on_next(200, ["gamma"]),
on_completed(200))
示例8: test_group_by_with_merge
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import schedule_absolute [as 别名]
def test_group_by_with_merge(self):
scheduler = TestScheduler()
xs = [None]
results = [None]
def action1(scheduler, state):
xs[0] = rx.from_iterable(["alpha", "apple", "beta", "bat", "gamma"]) \
.pipe(ops.group_by(lambda s: s[0]),
ops.map(lambda xs: xs.pipe(ops.to_iterable(), ops.map(list))),
ops.merge_all(),
)
scheduler.schedule_absolute(created, action1)
def action2(scheduler, state):
results[0] = scheduler.create_observer()
xs[0].subscribe(results[0], scheduler)
scheduler.schedule_absolute(subscribed, action2)
scheduler.start()
assert results[0].messages == [
on_next(200, ["alpha", "apple"]),
on_next(200, ["beta", "bat"]),
on_next(200, ["gamma"]),
on_completed(200)]
示例9: test_repeat_observable_repeat_count_throws
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import schedule_absolute [as 别名]
def test_repeat_observable_repeat_count_throws(self):
scheduler1 = TestScheduler()
xs = Observable.return_value(1, scheduler1).repeat(3)
xs.subscribe(lambda x: _raise('ex'))
with self.assertRaises(RxException):
scheduler1.start()
scheduler2 = TestScheduler()
ys = Observable.throw_exception('ex1', scheduler2).repeat(3)
ys.subscribe(on_error=lambda ex: _raise('ex2'))
with self.assertRaises(RxException):
scheduler2.start()
scheduler3 = TestScheduler()
zs = Observable.return_value(1, scheduler3).repeat(100)
d = zs.subscribe(on_completed=lambda: _raise('ex3'))
scheduler3.schedule_absolute(10, lambda sc, st: d.dispose())
scheduler3.start()
xss = Observable.create(lambda o: _raise('ex4')).repeat(3)
with self.assertRaises(RxException):
xss.subscribe()
示例10: test_repeat_observable_repeat_count_throws
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import schedule_absolute [as 别名]
def test_repeat_observable_repeat_count_throws():
scheduler1 = TestScheduler()
xs = Observable.return_value(1, scheduler1).repeat(3)
xs.subscribe(lambda x: _raise('ex'))
try:
return scheduler1.start()
except RxException:
pass
scheduler2 = TestScheduler()
ys = Observable.throwException('ex1', scheduler2).repeat(3)
ys.subscribe(lambda ex: _raise('ex2'))
try:
return scheduler2.start()
except RxException:
pass
scheduler3 = TestScheduler()
zs = Observable.return_value(1, scheduler3).repeat(100)
d = zs.subscribe(on_complete=lambda: _raise('ex3'))
scheduler3.schedule_absolute(10, lambda: d.dispose())
scheduler3.start()
xss = Observable.create(lambda o: _raise('ex4')).repeat(3)
try:
return xss.subscribe()
except RxException:
pass
示例11: test_retry_observable_throws
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import schedule_absolute [as 别名]
def test_retry_observable_throws(self):
scheduler1 = TestScheduler()
xs = Observable.return_value(1, scheduler1).retry()
xs.subscribe(lambda x: _raise('ex'))
try:
return scheduler1.start()
except RxException:
pass
scheduler2 = TestScheduler()
ys = Observable.throw_exception('ex', scheduler2).retry()
d = ys.subscribe(on_error=lambda ex: _raise('ex'))
scheduler2.schedule_absolute(210, lambda: d.dispose())
scheduler2.start()
scheduler3 = TestScheduler()
zs = Observable.return_value(1, scheduler3).retry()
zs.subscribe(on_completed=lambda: _raise('ex'))
try:
return scheduler3.start()
except RxException:
pass
xss = Observable.create(lambda o: _raise('ex')).retry()
try:
return xss.subscribe()
except RxException:
pass
示例12: test_select_with_index_dispose_inside_selector
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import schedule_absolute [as 别名]
def test_select_with_index_dispose_inside_selector():
scheduler = TestScheduler()
xs = scheduler.create_hot_observable(on_next(100, 4), on_next(200, 3), on_next(500, 2), on_next(600, 1))
invoked = 0
results = scheduler.create_observer()
d = SerialDisposable()
def projection(x, index):
nonlocal invoked
invoked += 1
if scheduler.clock > 400:
d.dispose()
return x + index * 10
d.disposable = xs.select(projection).subscribe(results)
def action(scheduler, state):
return d.dispose()
scheduler.schedule_absolute(disposed, action)
scheduler.start()
results.messages.assert_equal(on_next(100, 4), on_next(200, 13))
xs.subscriptions.assert_equal(subscribe(0, 500))
assert invoked == 3
示例13: test_select_disposeinsideselector
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import schedule_absolute [as 别名]
def test_select_disposeinsideselector(self):
scheduler = TestScheduler()
xs = scheduler.create_hot_observable(on_next(100, 1), on_next(200, 2), on_next(500, 3), on_next(600, 4))
results = scheduler.create_observer()
d = SerialDisposable()
invoked = [0]
def projection(x, *args, **kw):
invoked[0] += 1
if scheduler.clock > 400:
#print("*** Dispose ****")
d.dispose()
return x
d.disposable = xs.select(projection).subscribe(results)
def action(scheduler, state):
return d.dispose()
scheduler.schedule_absolute(ReactiveTest.disposed, action)
scheduler.start()
results.messages.assert_equal(on_next(100, 1), on_next(200, 2))
xs.subscriptions.assert_equal(ReactiveTest.subscribe(0, 500))
assert invoked[0] == 3
示例14: test_if_default_other
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import schedule_absolute [as 别名]
def test_if_default_other(self):
b = [True]
scheduler = TestScheduler()
xs = scheduler.create_hot_observable(on_next(110, 1), on_next(220, 2), on_next(330, 3), on_error(440, 'ex'))
def action(scheduler, state):
b[0] = False
scheduler.schedule_absolute(150, action)
def create():
def condition():
return b[0]
return Observable.if_then(condition, xs)
results = scheduler.start(create)
results.messages.assert_equal(on_completed(200))
xs.subscriptions.assert_equal()
示例15: test_if_default_completed
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import schedule_absolute [as 别名]
def test_if_default_completed(self):
b = [False]
scheduler = TestScheduler()
xs = scheduler.create_hot_observable(on_next(110, 1), on_next(220, 2), on_next(330, 3), on_completed(440))
def action(scheduler, state):
b[0] = True
scheduler.schedule_absolute(150, action)
def create():
def condition():
return b[0]
return rx.if_then(condition, xs)
results = scheduler.start(create)
assert results.messages == [on_next(220, 2), on_next(330, 3), on_completed(440)]
assert xs.subscriptions == [subscribe(200, 440)]