本文整理汇总了Python中rx.testing.TestScheduler.create_cold_observable方法的典型用法代码示例。如果您正苦于以下问题:Python TestScheduler.create_cold_observable方法的具体用法?Python TestScheduler.create_cold_observable怎么用?Python TestScheduler.create_cold_observable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.testing.TestScheduler
的用法示例。
在下文中一共展示了TestScheduler.create_cold_observable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_select_many_then_error_complete
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_cold_observable [as 别名]
def test_select_many_then_error_complete():
ex = "ex"
scheduler = TestScheduler()
xs = scheduler.create_cold_observable(
on_next(100, 4), on_next(200, 2), on_next(300, 3), on_next(400, 1), on_error(500, ex)
)
ys = scheduler.create_cold_observable(
on_next(50, "foo"), on_next(100, "bar"), on_next(150, "baz"), on_next(200, "qux"), on_completed(250)
)
results = scheduler.start(lambda: xs.select_many(ys))
results.messages.assert_equal(
on_next(350, "foo"),
on_next(400, "bar"),
on_next(450, "baz"),
on_next(450, "foo"),
on_next(500, "qux"),
on_next(500, "bar"),
on_next(550, "baz"),
on_next(550, "foo"),
on_next(600, "qux"),
on_next(600, "bar"),
on_next(650, "baz"),
on_next(650, "foo"),
on_error(700, ex),
)
xs.subscriptions.assert_equal(subscribe(200, 700))
ys.subscriptions.assert_equal(subscribe(300, 550), subscribe(400, 650), subscribe(500, 700), subscribe(600, 700))
示例2: test_switch_inner_throws
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_cold_observable [as 别名]
def test_switch_inner_throws(self):
ex = 'ex'
scheduler = TestScheduler()
xs = scheduler.create_hot_observable(
on_next(300, scheduler.create_cold_observable(
on_next(10, 101), on_next(20, 102),
on_next(110, 103), on_next(120, 104),
on_next(210, 105), on_next(220, 106),
on_completed(230))),
on_next(400, scheduler.create_cold_observable(
on_next(10, 201), on_next(20, 202),
on_next(30, 203), on_next(40, 204),
on_error(50, ex))),
on_next(500, scheduler.create_cold_observable(
on_next(10, 301), on_next(20, 302),
on_next(30, 303), on_next(40, 304),
on_completed(150))),
on_completed(600))
def create():
return xs.pipe(ops.switch_latest())
results = scheduler.start(create)
assert results.messages == [
on_next(310, 101), on_next(320, 102), on_next(410, 201),
on_next(420, 202), on_next(430, 203), on_next(440, 204),
on_error(450, ex)]
示例3: test_debounce_duration_delay_behavior
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_cold_observable [as 别名]
def test_debounce_duration_delay_behavior(self):
scheduler = TestScheduler()
xs = scheduler.create_hot_observable(
on_next(150, -1),
on_next(250, 0),
on_next(280, 1),
on_next(310, 2),
on_next(350, 3),
on_next(400, 4),
on_completed(550))
ys = [scheduler.create_cold_observable(on_next(20, 42), on_next(25, 99)), scheduler.create_cold_observable(on_next(20, 42), on_next(25, 99)), scheduler.create_cold_observable(
on_next(20, 42), on_next(25, 99)), scheduler.create_cold_observable(on_next(20, 42), on_next(25, 99)), scheduler.create_cold_observable(on_next(20, 42), on_next(25, 99))]
def create():
def mapper(x):
return ys[x]
return xs.pipe(_.throttle_with_mapper(mapper))
results = scheduler.start(create)
assert results.messages == [on_next(250 + 20, 0), on_next(280 + 20, 1), on_next(310 + 20, 2),
on_next(350 + 20, 3), on_next(400 + 20, 4), on_completed(550)]
assert xs.subscriptions == [subscribe(200, 550)]
assert ys[0].subscriptions == [subscribe(250, 250 + 20)]
assert ys[1].subscriptions == [subscribe(280, 280 + 20)]
assert ys[2].subscriptions == [subscribe(310, 310 + 20)]
assert ys[3].subscriptions == [subscribe(350, 350 + 20)]
assert ys[4].subscriptions == [subscribe(400, 400 + 20)]
示例4: test_mergeconcat_innererror
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_cold_observable [as 别名]
def test_mergeconcat_innererror(self):
ex = 'ex'
scheduler = TestScheduler()
xs = scheduler.create_hot_observable(
on_next(210, scheduler.create_cold_observable(
on_next(50, 1), on_next(100, 2), on_next(120, 3), on_completed(140))),
on_next(260, scheduler.create_cold_observable(
on_next(20, 4), on_next(70, 5), on_completed(200))),
on_next(270, scheduler.create_cold_observable(
on_next(10, 6), on_next(90, 7), on_next(110, 8), on_error(140, ex))),
on_next(320, scheduler.create_cold_observable(
on_next(210, 9), on_next(240, 10), on_completed(300))),
on_completed(400)
)
def create():
return xs.pipe(ops.merge(max_concurrent=2))
results = scheduler.start(create)
assert results.messages == [
on_next(260, 1), on_next(280, 4), on_next(310, 2),
on_next(330, 3), on_next(330, 5), on_next(360, 6),
on_next(440, 7), on_next(460, 8), on_error(490, ex)]
assert xs.subscriptions == [subscribe(200, 400)]
示例5: test_select_many_then_complete_complete_2
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_cold_observable [as 别名]
def test_select_many_then_complete_complete_2():
scheduler = TestScheduler()
xs = scheduler.create_cold_observable(
on_next(100, 4), on_next(200, 2), on_next(300, 3), on_next(400, 1), on_completed(700)
)
ys = scheduler.create_cold_observable(
on_next(50, "foo"), on_next(100, "bar"), on_next(150, "baz"), on_next(200, "qux"), on_completed(250)
)
def factory():
return xs.select_many(ys)
results = scheduler.start(factory)
results.messages.assert_equal(
on_next(350, "foo"),
on_next(400, "bar"),
on_next(450, "baz"),
on_next(450, "foo"),
on_next(500, "qux"),
on_next(500, "bar"),
on_next(550, "baz"),
on_next(550, "foo"),
on_next(600, "qux"),
on_next(600, "bar"),
on_next(650, "baz"),
on_next(650, "foo"),
on_next(700, "qux"),
on_next(700, "bar"),
on_next(750, "baz"),
on_next(800, "qux"),
on_completed(900),
)
xs.subscriptions.assert_equal(subscribe(200, 900))
ys.subscriptions.assert_equal(subscribe(300, 550), subscribe(400, 650), subscribe(500, 750), subscribe(600, 850))
示例6: test_flat_map_then_complete_complete
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_cold_observable [as 别名]
def test_flat_map_then_complete_complete(self):
scheduler = TestScheduler()
xs = scheduler.create_cold_observable(
on_next(100, 4), on_next(200, 2), on_next(300, 3),
on_next(400, 1), on_completed(500))
ys = scheduler.create_cold_observable(
on_next(50, "foo"), on_next(100, "bar"), on_next(150, "baz"),
on_next(200, "qux"), on_completed(250))
def factory():
return xs.pipe(ops.flat_map(ys))
results = scheduler.start(factory)
assert results.messages == [
on_next(350, "foo"), on_next(400, "bar"), on_next(450, "baz"),
on_next(450, "foo"), on_next(500, "qux"), on_next(500, "bar"),
on_next(550, "baz"), on_next(550, "foo"), on_next(600, "qux"),
on_next(600, "bar"), on_next(650, "baz"), on_next(650, "foo"),
on_next(700, "qux"), on_next(700, "bar"), on_next(750, "baz"),
on_next(800, "qux"), on_completed(850)]
assert xs.subscriptions == [subscribe(200, 700)]
assert ys.subscriptions == [
subscribe(300, 550), subscribe(400, 650),
subscribe(500, 750), subscribe(600, 850)]
示例7: test_merge_observable_of_observable_outer_throws
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_cold_observable [as 别名]
def test_merge_observable_of_observable_outer_throws(self):
ex = 'ex'
scheduler = TestScheduler()
xs = scheduler.create_hot_observable(on_next(300, scheduler.create_cold_observable(on_next(10, 101), on_next(20, 102), on_completed(230))), on_next(
400, scheduler.create_cold_observable(on_next(10, 201), on_next(20, 202), on_next(30, 203), on_next(40, 200), on_completed(50))), on_error(500, ex))
def create():
return xs.pipe(ops.merge_all())
results = scheduler.start(create)
assert results.messages == [on_next(310, 101), on_next(320, 102), on_next(
410, 201), on_next(420, 202), on_next(430, 203), on_next(440, 200), on_error(500, ex)]
示例8: test_mergeconcat_basic_late
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_cold_observable [as 别名]
def test_mergeconcat_basic_late(self):
scheduler = TestScheduler()
xs = scheduler.create_hot_observable(on_next(210, scheduler.create_cold_observable(on_next(50, 1), on_next(100, 2), on_next(120, 3), on_completed(140))), on_next(260, scheduler.create_cold_observable(on_next(20, 4), on_next(70, 5), on_completed(
300))), on_next(270, scheduler.create_cold_observable(on_next(10, 6), on_next(90, 7), on_next(110, 8), on_completed(130))), on_next(420, scheduler.create_cold_observable(on_next(210, 9), on_next(240, 10), on_completed(300))), on_completed(750))
def create():
return xs.pipe(ops.merge(max_concurrent=3))
results = scheduler.start(create)
assert results.messages == [on_next(260, 1), on_next(280, 4), on_next(280, 6), on_next(310, 2), on_next(
330, 3), on_next(330, 5), on_next(360, 7), on_next(380, 8), on_next(630, 9), on_next(660, 10), on_completed(750)]
assert xs.subscriptions == [subscribe(200, 750)]
示例9: test_timeout_duration_simple_firstthrows
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_cold_observable [as 别名]
def test_timeout_duration_simple_firstthrows(self):
ex = 'ex'
scheduler = TestScheduler()
xs = scheduler.create_hot_observable(on_next(310, 1), on_next(350, 2), on_next(420, 3), on_completed(450))
ys = scheduler.create_cold_observable(on_error(50, ex))
zs = scheduler.create_cold_observable()
def create():
return xs.timeout_with_selector(ys, lambda _: zs)
results = scheduler.start(create)
results.messages.assert_equal(on_error(250, ex))
xs.subscriptions.assert_equal(subscribe(200, 250))
ys.subscriptions.assert_equal(subscribe(200, 250))
zs.subscriptions.assert_equal()
示例10: test_repeat_observable_repeat_count_basic
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_cold_observable [as 别名]
def test_repeat_observable_repeat_count_basic(self):
scheduler = TestScheduler()
xs = scheduler.create_cold_observable(on_next(5, 1), on_next(10, 2), on_next(15, 3), on_completed(20))
results = scheduler.start(lambda: xs.repeat(3))
results.messages.assert_equal(on_next(205, 1), on_next(210, 2), on_next(215, 3), on_next(225, 1), on_next(230, 2), on_next(235, 3), on_next(245, 1), on_next(250, 2), on_next(255, 3), on_completed(260))
xs.subscriptions.assert_equal(subscribe(200, 220), subscribe(220, 240), subscribe(240, 260))
示例11: test_timeout_duration_simple_never
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_cold_observable [as 别名]
def test_timeout_duration_simple_never(self):
scheduler = TestScheduler()
xs = scheduler.create_hot_observable(
on_next(310, 1),
on_next(350, 2),
on_next(420, 3),
on_completed(450)
)
ys = scheduler.create_cold_observable()
def create():
return xs.timeout_with_selector(ys, lambda _: ys)
results = scheduler.start(create)
results.messages.assert_equal(
on_next(310, 1),
on_next(350, 2),
on_next(420, 3),
on_completed(450)
)
xs.subscriptions.assert_equal(
subscribe(200, 450)
)
ys.subscriptions.assert_equal(
subscribe(200, 310),
subscribe(310, 350),
subscribe(350, 420),
subscribe(420, 450)
)
示例12: test_repeat_observable_infinite
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_cold_observable [as 别名]
def test_repeat_observable_infinite(self):
scheduler = TestScheduler()
xs = scheduler.create_cold_observable(on_next(100, 1), on_next(150, 2), on_next(200, 3))
results = scheduler.start(lambda: xs.pipe(ops.repeat()))
assert results.messages == [on_next(300, 1), on_next(350, 2), on_next(400, 3)]
assert xs.subscriptions == [subscribe(200, 1000)]
示例13: test_retry_observable_basic
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_cold_observable [as 别名]
def test_retry_observable_basic(self):
scheduler = TestScheduler()
xs = scheduler.create_cold_observable(on_next(100, 1), on_next(150, 2), on_next(200, 3), on_completed(250))
results = scheduler.start(lambda: xs.retry())
results.messages.assert_equal(on_next(300, 1), on_next(350, 2), on_next(400, 3), on_completed(450))
xs.subscriptions.assert_equal(subscribe(200, 450))
示例14: test_dowhile_always_true
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_cold_observable [as 别名]
def test_dowhile_always_true(self):
scheduler = TestScheduler()
xs = scheduler.create_cold_observable(
self.on_next(50, 1),
self.on_next(100, 2),
self.on_next(150, 3),
self.on_next(200, 4),
self.on_completed(250))
def create():
return xs.pipe(ops.do_while(lambda _: True))
results = scheduler.start(create=create)
assert results.messages == [
self.on_next(250, 1),
self.on_next(300, 2),
self.on_next(350, 3),
self.on_next(400, 4),
self.on_next(500, 1),
self.on_next(550, 2),
self.on_next(600, 3),
self.on_next(650, 4),
self.on_next(750, 1),
self.on_next(800, 2),
self.on_next(850, 3),
self.on_next(900, 4)]
assert xs.subscriptions == [
self.subscribe(200, 450),
self.subscribe(450, 700),
self.subscribe(700, 950),
self.subscribe(950, 1000)]
示例15: test_timeout_duration_simple_timeoutbycompletion
# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_cold_observable [as 别名]
def test_timeout_duration_simple_timeoutbycompletion(self):
ex = 'ex'
scheduler = TestScheduler()
xs = scheduler.create_hot_observable(on_next(310, 1), on_next(350, 2), on_next(420, 3), on_completed(450))
ys = scheduler.create_cold_observable()
zs = scheduler.create_cold_observable()
def create():
def selector(x):
if x < 3:
return zs
else:
raise Exception(ex)
return xs.timeout_with_selector(ys, selector)
results = scheduler.start(create)
results.messages.assert_equal(
on_next(310, 1),
on_next(350, 2),
on_next(420, 3),
on_error(420, ex)
)
xs.subscriptions.assert_equal(subscribe(200, 420))
ys.subscriptions.assert_equal(subscribe(200, 310))
zs.subscriptions.assert_equal(subscribe(310, 350), subscribe(350, 420))