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


Python TestScheduler.start方法代码示例

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


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

示例1: test_select_with_index_dispose_inside_selector

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import start [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

示例2: test_paused_with_immediate_unpause

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import start [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

示例3: test_retry_observable_retry_count_throws

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

示例4: test_never_basic

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import start [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

示例5: test_multicast_hot_6

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import start [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

示例6: test_map_disposeinsidemapper

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import start [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

示例7: test_empty_observer_throw_exception

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import start [as 别名]
    def test_empty_observer_throw_exception(self):
        scheduler = TestScheduler()
        xs = empty()
        xs.subscribe(lambda x: None, lambda ex: None, lambda: _raise('ex'), scheduler=scheduler)

        with self.assertRaises(RxException):
            scheduler.start()
开发者ID:MichaelSchneeberger,项目名称:RxPY,代码行数:9,代码来源:test_empty.py

示例8: test_multicast_hot_5

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import start [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

示例9: test_repeat_observable_repeat_count_throws

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

示例10: test_retry_observable_throws

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

示例11: test_where_index_dispose_in_predicate

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import start [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

示例12: test_interval_timespan_observer_throws

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import start [as 别名]
    def test_interval_timespan_observer_throws(self):
        scheduler = TestScheduler()
        xs = Observable.interval(1, scheduler=scheduler)
        xs.subscribe(lambda x: _raise("ex"))

        with self.assertRaises(RxException):
            scheduler.start()
开发者ID:ESSL-CQQ,项目名称:RxPY,代码行数:9,代码来源:test_interval.py

示例13: test_group_by_with_merge

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

示例14: test_multicast_hot_21

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import start [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

示例15: test_paused_skip_initial_elements

# 需要导入模块: from rx.testing import TestScheduler [as 别名]
# 或者: from rx.testing.TestScheduler import start [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


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