当前位置: 首页>>代码示例>>Python>>正文


Python TestScheduler.create_observer方法代码示例

本文整理汇总了Python中rx.testing.TestScheduler.create_observer方法的典型用法代码示例。如果您正苦于以下问题:Python TestScheduler.create_observer方法的具体用法?Python TestScheduler.create_observer怎么用?Python TestScheduler.create_observer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rx.testing.TestScheduler的用法示例。


在下文中一共展示了TestScheduler.create_observer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_paused_with_observable_controller_and_pause_and_unpause_after_end

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_observer [as 别名]
    def test_paused_with_observable_controller_and_pause_and_unpause_after_end(self):
        scheduler = TestScheduler()

        results = scheduler.create_observer()

        xs = scheduler.create_hot_observable(
            on_next(150, 1),
            on_next(210, 2),
            on_next(230, 3),
            on_next(301, 4),
            on_next(350, 5),
            on_next(399, 6),
            on_next(450, 7),
            on_next(470, 8),
            on_completed(500),
        )

        controller = scheduler.create_hot_observable(on_next(201, True), on_next(300, False), on_next(600, True))

        def create():
            return xs.pausable_buffered(controller)

        results = scheduler.start(create)

        results.messages.assert_equal(
            on_next(210, 2),
            on_next(230, 3),
            on_next(600, 4),
            on_next(600, 5),
            on_next(600, 6),
            on_next(600, 7),
            on_next(600, 8),
            on_completed(600),
        )
开发者ID:michaelandersen,项目名称:RxPY,代码行数:36,代码来源:test_pausablebuffered.py

示例2: test_paused_skip_initial_elements

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_observer [as 别名]
    def test_paused_skip_initial_elements(self):
        subscription = [None]
        scheduler = TestScheduler()

        controller = Subject()
        results = scheduler.create_observer()

        xs = scheduler.create_hot_observable(on_next(150, 1), on_next(230, 2), on_next(270, 3), on_completed(400))

        def action1(scheduler, state):
            subscription[0] = xs.pausable_buffered(controller).subscribe(results)
            controller.on_next(False)

        scheduler.schedule_absolute(200, action1)

        def action2(scheduler, state):
            controller.on_next(True)

        scheduler.schedule_absolute(280, action2)

        def action3(scheduler, state):
            subscription[0].dispose()

        scheduler.schedule_absolute(1000, action3)

        scheduler.start()
        results.messages.assert_equal(on_next(280, 2), on_next(280, 3), on_completed(400))
开发者ID:michaelandersen,项目名称:RxPY,代码行数:29,代码来源:test_pausablebuffered.py

示例3: test_select_with_index_dispose_inside_selector

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_observer [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
开发者ID:Reactive-Extensions,项目名称:RxPy,代码行数:27,代码来源:test_select.py

示例4: test_paused_with_state_change_in_subscriber

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_observer [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)
        )
开发者ID:michaelandersen,项目名称:RxPY,代码行数:35,代码来源:test_pausablebuffered.py

示例5: test_paused_with_immediate_unpause

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_observer [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)
        )
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:29,代码来源:test_pausablebuffered.py

示例6: test_multicast_hot_6

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_observer [as 别名]
    def test_multicast_hot_6(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_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)
        scheduler.schedule_absolute(400, action2)

        scheduler.start()
        assert o.messages == [on_completed(400)]
        assert xs.subscriptions == [subscribe(100, 390)]
开发者ID:MichaelSchneeberger,项目名称:RxPY,代码行数:27,代码来源:test_multicast.py

示例7: test_never_basic

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_observer [as 别名]
 def test_never_basic(self):
     scheduler = TestScheduler()
     xs = Observable.never()
     results = scheduler.create_observer()
     xs.subscribe(results)
     scheduler.start()
     results.messages.assert_equal()
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:9,代码来源:test_never.py

示例8: test_map_disposeinsidemapper

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_observer [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
开发者ID:MichaelSchneeberger,项目名称:RxPY,代码行数:30,代码来源:test_map.py

示例9: test_where_index_dispose_in_predicate

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_observer [as 别名]
    def test_where_index_dispose_in_predicate(self):
        scheduler = TestScheduler()
        ys = [None]
        invoked = [0]
        xs = scheduler.create_hot_observable(on_next(110, 1), on_next(180, 2), on_next(230, 3), on_next(270, 4), on_next(340, 5), on_next(380, 6), on_next(390, 7), on_next(450, 8), on_next(470, 9), on_next(560, 10), on_next(580, 11), on_completed(600), on_next(610, 12), on_error(620, 'ex'), on_completed(630))
        results = scheduler.create_observer()
        d = SerialDisposable()
    
        def action1(scheduler, state):
            def predicate(x, index):
                invoked[0] += 1
                if x == 8:
                    d.dispose()
            
                return is_prime(x + index * 10)
            ys[0] = xs.filter(predicate)

        scheduler.schedule_absolute(created, action1)
    
        def action2(scheduler, state):
             d.disposable = ys[0].subscribe(results)

        scheduler.schedule_absolute(subscribed, action2)
    
        def action3(scheduler, state):
            d.dispose()

        scheduler.schedule_absolute(disposed, action3)
    
        scheduler.start()
        results.messages.assert_equal(on_next(230, 3), on_next(390, 7))
        xs.subscriptions.assert_equal(subscribe(200, 450))
        assert(invoked[0] == 6)
开发者ID:AlexMost,项目名称:RxPY,代码行数:35,代码来源:test_where.py

示例10: test_select_disposeinsideselector

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_observer [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
开发者ID:mvschaik,项目名称:RxPY,代码行数:29,代码来源:test_select.py

示例11: test_multicast_hot_21

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_observer [as 别名]
    def test_multicast_hot_21(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.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):
            return d1[0].dispose()
        scheduler.schedule_absolute(300, action3)

        scheduler.start()
        o.messages.assert_equal(on_next(210, 3), on_next(240, 4), on_next(270, 5))
        xs.subscriptions.assert_equal(subscribe(100, 390))
开发者ID:AlexMost,项目名称:RxPY,代码行数:30,代码来源:test_multicast.py

示例12: test_multicast_hot_5

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_observer [as 别名]
    def test_multicast_hot_5(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(400, action2)

        scheduler.start()
        o.messages.assert_equal(on_error(400, ex))
        xs.subscriptions.assert_equal(subscribe(100, 390))
开发者ID:AlexMost,项目名称:RxPY,代码行数:27,代码来源:test_multicast.py

示例13: test_paused_with_observable_controller_and_pause_and_unpause

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_observer [as 别名]
    def test_paused_with_observable_controller_and_pause_and_unpause(self):
        subscription = [None]

        scheduler = TestScheduler()

        results = scheduler.create_observer()

        xs = scheduler.create_hot_observable(
            on_next(150, 1),
            on_next(210, 2),
            on_next(230, 3),
            on_next(301, 4),
            on_next(350, 5),
            on_next(399, 6),
            on_next(450, 7),
            on_next(470, 8),
            on_completed(500),
        )

        controller = scheduler.create_hot_observable(on_next(201, True), on_next(300, False), on_next(400, True))

        pausable_buffered = xs.pausable_buffered(controller)

        def action1(scheduler, state):
            subscription[0] = pausable_buffered.subscribe(results)

        scheduler.schedule_absolute(200, action1)

        def action2(scheduler, state):
            pausable_buffered.pause()

        scheduler.schedule_absolute(460, action2)

        def action3(scheduler, state):
            pausable_buffered.resume()

        scheduler.schedule_absolute(480, action3)

        def action4(scheduler, state):
            subscription[0].dispose()

        scheduler.schedule_absolute(1000, action4)

        scheduler.start()

        results.messages.assert_equal(
            on_next(210, 2),
            on_next(230, 3),
            on_next(400, 4),
            on_next(400, 5),
            on_next(400, 6),
            on_next(450, 7),
            on_next(480, 8),
            on_completed(500),
        )
开发者ID:michaelandersen,项目名称:RxPY,代码行数:57,代码来源:test_pausablebuffered.py

示例14: test_partition_completed

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_observer [as 别名]
    def test_partition_completed(self):
        scheduler = TestScheduler()

        xs = scheduler.create_hot_observable(
            on_next(180, 5),
            on_next(210, 4),
            on_next(240, 3),
            on_next(290, 2),
            on_next(350, 1),
            on_completed(360)
        )

        observables = []
        subscription1 = [None]
        subscription2 = [None]
        results1 = scheduler.create_observer()
        results2 = scheduler.create_observer()

        def action0(scheduler, state):
            observables.extend(xs.partition(is_even))

        scheduler.schedule_absolute(ReactiveTest.created, action0)

        def action1(scheduler, state):
            subscription1[0] = observables[0].subscribe(results1)
            subscription2[0] = observables[1].subscribe(results2)
        scheduler.schedule_absolute(ReactiveTest.subscribed, action1)

        def action2(scheduler, state):
            subscription1[0].dispose()
            subscription2[0].dispose()
        scheduler.schedule_absolute(ReactiveTest.disposed, action2)

        scheduler.start()

        results1.messages.assert_equal(
            on_next(210, 4),
            on_next(290, 2),
            on_completed(360)
        )

        results2.messages.assert_equal(
            on_next(240, 3),
            on_next(350, 1),
            on_completed(360)
        )

        xs.subscriptions.assert_equal(
            subscribe(200, 360)
        )
开发者ID:AlexMost,项目名称:RxPY,代码行数:52,代码来源:test_partition.py

示例15: test_replay_time_basic

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import create_observer [as 别名]
    def test_replay_time_basic(self):
        subscription = [None]
        connection = [None]
        ys = [None]
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(on_next(110, 7), on_next(220, 3), on_next(280, 4), on_next(290, 1), on_next(340, 8), on_next(360, 5), on_next(
            370, 6), on_next(390, 7), on_next(410, 13), on_next(430, 2), on_next(450, 9), on_next(520, 11), on_next(560, 20), on_completed(600))
        results = scheduler.create_observer()

        def action0(scheduler, state):
            ys[0] = xs.pipe(ops.replay(window=150, scheduler=scheduler))
        scheduler.schedule_absolute(created, action0)

        def action1(scheduler, state):
            subscription[0] = ys[0].subscribe(results)
        scheduler.schedule_absolute(450, action1)

        def action2(scheduler, state):
            subscription[0].dispose()
        scheduler.schedule_absolute(disposed, action2)

        def action3(scheduler, state):
            connection[0] = ys[0].connect(scheduler)
        scheduler.schedule_absolute(300, action3)

        def action4(scheduler, state):
            connection[0].dispose()
        scheduler.schedule_absolute(400, action4)

        def action5(scheduler, state):
            connection[0] = ys[0].connect(scheduler)
        scheduler.schedule_absolute(500, action5)

        def action6(scheduler, state):
            connection[0].dispose()
        scheduler.schedule_absolute(550, action6)

        def action7(scheduler, state):
            connection[0] = ys[0].connect(scheduler)
        scheduler.schedule_absolute(650, action7)

        def action8(scheduler, state):
            connection[0].dispose()
        scheduler.schedule_absolute(800, action8)

        scheduler.start()
        assert results.messages == [on_next(450, 8), on_next(
            450, 5), on_next(450, 6), on_next(450, 7), on_next(520, 11)]
        assert xs.subscriptions == [subscribe(300, 400), subscribe(500, 550), subscribe(650, 800)]
开发者ID:MichaelSchneeberger,项目名称:RxPY,代码行数:51,代码来源:test_replay.py


注:本文中的rx.testing.TestScheduler.create_observer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。