Exemplo n.º 1
0
    def test_using_null(self):
        disp = [None]
        xs = [None]
        _d = [None]

        scheduler = TestScheduler()
        dispose_invoked = [0]
        create_invoked = [0]

        def create():
            def create_resources():
                dispose_invoked[0] += 1
                disp[0] = None
                return disp[0]

            def create_observable(d):
                _d[0] = d
                create_invoked[0] += 1
                xs[0] = scheduler.create_cold_observable(
                        on_next(100, scheduler.clock), on_completed(200))
                return xs[0]
            return rx.using(create_resources, create_observable)

        results = scheduler.start(create)

        assert (disp[0] == _d[0])
        assert results.messages == [on_next(300, 200), on_completed(400)]
        assert (1 == create_invoked[0])
        assert (1 == dispose_invoked[0])
        assert xs[0].subscriptions == [subscribe(200, 400)]
        assert (disp[0] is None)
Exemplo n.º 2
0
    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)
        )
Exemplo n.º 3
0
    def test_min_by_comparer_never(self):
        scheduler = TestScheduler()
        msgs = [
            on_next(150, {
                "key": 1,
                "value": 'z'
            })
        ]

        def reverse_comparer(a, b):
            if a > b:
                return -1

            if a == b:
                return 0

            return 1

        xs = scheduler.create_hot_observable(msgs)

        def create():
            return xs.pipe(ops.min_by(lambda x: x["key"], reverse_comparer))

        res = scheduler.start(create=create).messages
        assert res == []
Exemplo n.º 4
0
    def test_retry_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.retry())

        results.messages.assert_equal(on_next(300, 1), on_next(350, 2), on_next(400, 3))
        return xs.subscriptions.assert_equal(subscribe(200, 1000))
Exemplo n.º 5
0
    def test_min_by_comparer_return(self):
        scheduler = TestScheduler()
        msgs = [
            on_next(150, {
                "key": 1,
                "value": 'z'
            }), on_next(210, {
                "key": 2,
                "value": 'a'
            }), on_completed(250)
        ]

        def reverse_comparer(a, b):
            if a > b:
                return -1

            if a == b:
                return 0
            return 1

        xs = scheduler.create_hot_observable(msgs)

        def create():
            return xs.pipe(ops.min_by(lambda x: x["key"], reverse_comparer))

        res = scheduler.start(create=create).messages
        self.assertEqual(2, len(res))
        assert(res[0].value.kind == 'N')
        self.assertEqual(1, len(res[0].value.value))
        self.assertEqual(2, res[0].value.value[0]["key"])
        self.assertEqual('a', res[0].value.value[0]["value"])
        assert(res[1].value.kind == 'C' and res[1].time == 250)
Exemplo n.º 6
0
    def test_using_error(self):
        scheduler = TestScheduler()
        dispose_invoked = [0]
        create_invoked = [0]
        ex = 'ex'
        disp = [None]
        xs = [None]
        _d = [None]

        def create():
            def create_resource():
                dispose_invoked[0] += 1
                disp[0] = MockDisposable(scheduler)
                return disp[0]

            def create_observable(d):
                _d[0] = d
                create_invoked[0] += 1
                xs[0] = scheduler.create_cold_observable(
                        on_next(100, scheduler.clock), on_error(200, ex))
                return xs[0]
            return rx.using(create_resource, create_observable)
        results = scheduler.start(create)

        assert disp[0] == _d[0]
        assert results.messages == [on_next(300, 200), on_error(400, ex)]
        assert create_invoked[0] == 1
        assert dispose_invoked[0] == 1
        assert xs[0].subscriptions == [subscribe(200, 400)]
        assert disp[0].disposes == [200, 400]
Exemplo n.º 7
0
    def test_catch_throw_from_nested_catch(self):
        ex = 'ex'
        ex2 = 'ex'
        first_handler_called = [False]
        second_handler_called = [False]
        scheduler = TestScheduler()
        msgs1 = [on_next(150, 1), on_next(210, 2), on_error(215, ex)]
        msgs2 = [on_next(220, 3), on_error(225, ex2)]
        msgs3 = [on_next(230, 4), on_completed(235)]
        o1 = scheduler.create_hot_observable(msgs1)
        o2 = scheduler.create_hot_observable(msgs2)
        o3 = scheduler.create_hot_observable(msgs3)

        def create():
            def handler1(e):
                first_handler_called[0] = True
                assert(e == ex)
                return o2
            def handler2(e):
                second_handler_called[0] = True
                assert(e == ex2)
                return o3
            return o1.catch_exception(handler1).catch_exception(handler2)

        results = scheduler.start(create)

        results.messages.assert_equal(on_next(210, 2), on_next(220, 3), on_next(230, 4), on_completed(235))
        assert(first_handler_called[0])
        assert(second_handler_called[0])
Exemplo n.º 8
0
    def test_throw_disposed(self):
        scheduler = TestScheduler()
        def factory():
            return Observable.throw_exception('ex', scheduler)

        results = scheduler.start(factory, disposed=200)
        results.messages.assert_equal()
Exemplo n.º 9
0
    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))
Exemplo n.º 10
0
    def test_to_dict_error(self):
        scheduler = TestScheduler()

        ex = Exception()

        xs = scheduler.create_hot_observable(
            on_next(110, 1),
            on_next(220, 2),
            on_next(330, 3),
            on_next(440, 4),
            on_next(550, 5),
            on_error(660, ex)
        )

        def create():
            return xs.to_dict(lambda x: x * 2, lambda x: x * 4)

        res = scheduler.start(create)

        res.messages.assert_equal(
            on_error(660, ex)
        )

        xs.subscriptions.assert_equal(
           subscribe(200, 660)
        )
Exemplo n.º 11
0
    def test_to_dict_keyselectorthrows(self):
        scheduler = TestScheduler()

        ex = Exception()

        xs = scheduler.create_hot_observable(
            on_next(110, 1),
            on_next(220, 2),
            on_next(330, 3),
            on_next(440, 4),
            on_next(550, 5),
            on_completed(600)
          )

        def create():
            def key_selector(x):
                if x < 4:
                    return x * 2
                else:
                    raise ex
            return xs.to_dict(key_selector, lambda x: x * 4)

        res = scheduler.start(create)

        res.messages.assert_equal(
            on_error(440, ex)
        )

        xs.subscriptions.assert_equal(
            subscribe(200, 440)
        )
Exemplo n.º 12
0
 def test_retry_observable_retry_count_dispose(self):
     scheduler = TestScheduler()
     ex = 'ex'
     xs = scheduler.create_cold_observable(on_next(5, 1), on_next(10, 2), on_next(15, 3), on_error(20, ex))
     results = scheduler.start(lambda: xs.retry(3), disposed=231)
     results.messages.assert_equal(on_next(205, 1), on_next(210, 2), on_next(215, 3), on_next(225, 1), on_next(230, 2))
     xs.subscriptions.assert_equal(subscribe(200, 220), subscribe(220, 231))
Exemplo n.º 13
0
    def test_to_dict_completed(self):
        scheduler = TestScheduler()

        xs = scheduler.create_hot_observable(
            on_next(110, 1),
            on_next(220, 2),
            on_next(330, 3),
            on_next(440, 4),
            on_next(550, 5),
            on_completed(660)
        )

        def create():
            return xs.to_dict(lambda x: x * 2, lambda x: x * 4)

        res = scheduler.start(create)
        print(res.messages)
        res.messages.assert_equal(
            on_next(660, {4: 8, 6: 12, 8: 16, 10: 20}),
            on_completed(660)
        )

        xs.subscriptions.assert_equal(
            subscribe(200, 660)
        )
Exemplo n.º 14
0
    def test_pairwise_error(self):
        error = Exception()
        scheduler = TestScheduler()

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

        def create():
            return xs.pairwise()

        results = scheduler.start(create)


        results.messages.assert_equal(
            on_next(240, (4,3)),
            on_error(290, error)
        )

        xs.subscriptions.assert_equal(
            subscribe(200, 290)
        )
Exemplo n.º 15
0
    def test_pairwise_not_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)
          )

        def create():
            return xs.pairwise()

        results = scheduler.start(create)


        results.messages.assert_equal(
            on_next(240, (4,3)),
            on_next(290, (3, 2)),
            on_next(350, (2, 1))
        )

        xs.subscriptions.assert_equal(
            subscribe(200, 1000)
        )
Exemplo n.º 16
0
    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),
        )
Exemplo n.º 17
0
    def test_pluck_attr_completed(self):
        scheduler = TestScheduler()

        class DummyClass:

            def __init__(self, prop):
                self.prop = prop

        xs = scheduler.create_hot_observable(
            on_next(180, DummyClass(1)),
            on_next(210, DummyClass(2)),
            on_next(240, DummyClass(3)),
            on_next(290, DummyClass(4)),
            on_next(350, DummyClass(5)),
            on_completed(400),
            on_next(410, DummyClass(-1)),
            on_completed(420),
            on_error(430, Exception('ex'))
        )
        results = scheduler.start(create=lambda: xs.pipe(ops.pluck_attr('prop')))

        assert results.messages == [
            on_next(210, 2),
            on_next(240, 3),
            on_next(290, 4),
            on_next(350, 5),
            on_completed(400)]
        assert xs.subscriptions == [subscribe(200, 400)]
Exemplo n.º 18
0
    def test_ignore_values_completed(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(on_next(180, 1), on_next(210, 2), on_next(250, 3), on_next(270, 4), on_next(310, 5), on_next(360, 6), on_next(380, 7), on_next(410, 8), on_next(590, 9), on_completed(610))
        results = scheduler.start(create=lambda: xs.ignore_elements())

        results.messages.assert_equal(on_completed(610))
        xs.subscriptions.assert_equal(subscribe(200, 610))
Exemplo n.º 19
0
    def test_catch_nested_outer_catches(self):
        ex = 'ex'
        first_handler_called = [False]
        second_handler_called = [False]
        scheduler = TestScheduler()
        msgs1 = [on_next(150, 1), on_next(210, 2), on_error(215, ex)]
        msgs2 = [on_next(220, 3), on_completed(225)]
        msgs3 = [on_next(220, 4), on_completed(225)]
        o1 = scheduler.create_hot_observable(msgs1)
        o2 = scheduler.create_hot_observable(msgs2)
        o3 = scheduler.create_hot_observable(msgs3)

        def create():
            def handler1(e, source):
                first_handler_called[0] = True
                return o2
            def handler2(e, source):
                second_handler_called[0] = True
                return o3
            return o1.pipe(ops.catch(handler1), ops.catch(handler2))

        results = scheduler.start(create)

        assert results.messages == [on_next(210, 2), on_next(220, 3), on_completed(225)]
        assert first_handler_called[0]
        assert not second_handler_called[0]
Exemplo n.º 20
0
    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))
Exemplo n.º 21
0
    def test_create_with_disposable_dispose(self):
        scheduler = TestScheduler()

        def create():
            def subscribe(o):
                d = BooleanDisposable()
                o.on_next(1)
                o.on_next(2)

                def action1(scheduler, state):
                    if not d.is_disposed:
                        o.on_next(3)
                scheduler.schedule_relative(600, action1)
                
                def action2(scheduler, state):
                    if not d.is_disposed:
                        o.on_next(4)
                scheduler.schedule_relative(700, action2)

                def action3(scheduler, state):
                    if not d.is_disposed:
                        o.on_next(5)
                scheduler.schedule_relative(900, action3)
                
                def action4(scheduler, state):
                    if not d.is_disposed:
                        o.on_next(6)
                scheduler.schedule_relative(1100, action4)
                
                return d
            return Observable.create_with_disposable(subscribe)
            
        results = scheduler.start(create)
        
        results.messages.assert_equal(on_next(200, 1), on_next(200, 2), on_next(800, 3), on_next(900, 4))
Exemplo n.º 22
0
    def test_throttle_first_no_end(self):
        scheduler = TestScheduler()

        xs = scheduler.create_hot_observable(
            on_next(150, 1),
            on_next(210, 2),
            on_next(250, 3),
            on_next(310, 4),
            on_next(350, 5),
            on_next(410, 6),
            on_next(450, 7)
        )

        def create():
            return xs.throttle_first(200, scheduler)

        results = scheduler.start(create=create)

        results.messages.assert_equal(
            on_next(210, 2),
            on_next(410, 6)
        )

        xs.subscriptions.assert_equal(
            subscribe(200, 1000)
        )
Exemplo n.º 23
0
    def test_throttle_first_error(self):
        error = RxException()

        scheduler = TestScheduler()

        xs = scheduler.create_hot_observable(
          on_next(150, 1),
          on_next(210, 2),
          on_next(250, 3),
          on_next(310, 4),
          on_next(350, 5),
          on_error(410, error),
          on_next(450, 7),
          on_completed(500)
        )

        def create():
            return xs.throttle_first(200, scheduler)

        results = scheduler.start(create=create)

        results.messages.assert_equal(
          on_next(210, 2),
          on_error(410, error)
        )

        xs.subscriptions.assert_equal(
          subscribe(200, 410)
        )
Exemplo n.º 24
0
    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()
Exemplo n.º 25
0
    def test_many_select_error(self):
        scheduler = TestScheduler()

        ex = Exception()

        xs = scheduler.create_hot_observable(
            on_next(100, 1),
            on_next(220, 2),
            on_next(270, 3),
            on_next(410, 4),
            on_error(500, ex)
        )

        def create():
            return xs.many_select(lambda ys: ys.first(), scheduler).merge_all()

        res = scheduler.start(create)

        res.messages.assert_equal(
            on_next(221, 2),
            on_next(271, 3),
            on_next(411, 4),
            on_error(501, ex)
        )

        xs.subscriptions.assert_equal(
            subscribe(200, 500)
        )
Exemplo n.º 26
0
 def test_retry_observable_error(self):
     ex = 'ex'
     scheduler = TestScheduler()
     xs = scheduler.create_cold_observable(on_next(100, 1), on_next(150, 2), on_next(200, 3), on_error(250, ex))
     results = scheduler.start(lambda: xs.retry(), disposed=1100)
     results.messages.assert_equal(on_next(300, 1), on_next(350, 2), on_next(400, 3), on_next(550, 1), on_next(600, 2), on_next(650, 3), on_next(800, 1), on_next(850, 2), on_next(900, 3), on_next(1050, 1))
     return xs.subscriptions.assert_equal(subscribe(200, 450), subscribe(450, 700), subscribe(700, 950), subscribe(950, 1100))
Exemplo n.º 27
0
    def test_maxby_comparerthrows(self):
        ex = 'ex'
        scheduler = TestScheduler()
        msgs = [
            on_next(150, {
                "key": 1,
                "value": 'z'
            }), on_next(210, {
                "key": 3,
                "value": 'b'
            }), on_next(220, {
                "key": 2,
                "value": 'c'
            }), on_next(230, {
                "key": 4,
                "value": 'a'
            }), on_completed(250)
        ]
        def reverse_comparer(a, b):
            raise Exception(ex)

        xs = scheduler.create_hot_observable(msgs)

        def create():
            return xs.max_by(lambda x: x["key"], reverse_comparer)

        res = scheduler.start(create=create).messages
        res.assert_equal(on_error(220, ex))
Exemplo n.º 28
0
    def test_min_by_comparer_throws(self):
        ex = 'ex'
        scheduler = TestScheduler()
        msgs = [
            on_next(150, {
                "key": 1,
                "value": 'z'
            }), on_next(210, {
                "key": 3,
                "value": 'b'
            }), on_next(220, {
                "key": 2,
                "value": 'c'
            }), on_next(230, {
                "key": 4,
                "value": 'a'
            }), on_completed(250)
        ]

        def reverse_comparer(a, b):
            _raise(ex)

        xs = scheduler.create_hot_observable(msgs)

        def create():
            return xs.pipe(ops.min_by(lambda x: x["key"], reverse_comparer))

        res = scheduler.start(create=create).messages
        assert res == [on_error(220, ex)]
Exemplo n.º 29
0
    def test_min_by_some(self):
        scheduler = TestScheduler()
        msgs = [
            on_next(150, {
                "key": 1,
                "value": 'z'
            }), on_next(210, {
                "key": 3,
                "value": 'b'
            }), on_next(220, {
                "key": 2,
                "value": 'c'
            }), on_next(230, {
                "key": 4,
                "value": 'a'
            }), on_completed(250)
        ]

        xs = scheduler.create_hot_observable(msgs)

        def create():
            return xs.pipe(ops.min_by(lambda x: x["key"]))
        res = scheduler.start(create=create).messages

        self.assertEqual(2, len(res))
        assert(res[0].value.kind == 'N')
        self.assertEqual(1, len(res[0].value.value))
        self.assertEqual(2, res[0].value.value[0]["key"])
        self.assertEqual('c', res[0].value.value[0]["value"])
        assert(res[1].value.kind == 'C' and res[1].time == 250)
Exemplo n.º 30
0
    def test_interval_timespan_negative(self):
        scheduler = TestScheduler()
        def create():
            return Observable.interval(-1, scheduler=scheduler)

        results = scheduler.start(create, disposed=210)
        results.messages.assert_equal(on_next(201, 0), on_next(202, 1), on_next(203, 2), on_next(204, 3), on_next(205, 4), on_next(206, 5), on_next(207, 6), on_next(208, 7), on_next(209, 8))
Exemplo n.º 31
0
    def test_expand_basic(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(on_next(550, 1), on_next(850, 2),
                                             on_completed(950))

        def create():
            def selector(x):
                return scheduler.create_cold_observable(
                    on_next(100, 2 * x), on_next(200, 3 * x),
                    on_completed(300))

            return xs.expand(selector, scheduler)

        results = scheduler.start(create)

        results.messages.assert_equal(on_next(550, 1), on_next(651, 2),
                                      on_next(751, 3), on_next(752, 4),
                                      on_next(850, 2), on_next(852, 6),
                                      on_next(852, 6), on_next(853, 8),
                                      on_next(951, 4), on_next(952, 9),
                                      on_next(952, 12), on_next(953, 12),
                                      on_next(953, 12), on_next(954, 16))
        xs.subscriptions.assert_equal(subscribe(201, 950))
Exemplo n.º 32
0
    def test_filter_indexed_false(self):
        scheduler = TestScheduler()
        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))

        def create():
            def predicate(x, index):
                invoked[0] += 1
                return False

            return xs.pipe(filter_indexed(predicate))

        results = scheduler.start(create)

        assert results.messages == [on_completed(600)]
        assert xs.subscriptions == [subscribe(200, 600)]
        assert (invoked[0] == 9)
Exemplo n.º 33
0
    def test_buffer_with_count_disposed(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(
            on_next(100, 1),
            on_next(210, 2),
            on_next(240, 3),
            on_next(280, 4),
            on_next(320, 5),
            on_next(350, 6),
            on_next(380, 7),
            on_next(420, 8),
            on_next(470, 9),
            on_completed(600))

        def create():
            return xs.buffer_with_count(3, 2).map(lambda x: str(x))

        results = scheduler.start(create, disposed=370)

        assert results.messages == [
            on_next(280, str([2, 3, 4])),
            on_next(350, str([4, 5, 6]))]
        assert xs.subscriptions == [subscribe(200, 370)]
Exemplo n.º 34
0
    def test_select_many_then_error_complete(self):
        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))
Exemplo n.º 35
0
    def test_select_many_use_function(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(on_next(210, 4), on_next(220, 3),
                                             on_next(250, 5), on_next(270, 1),
                                             on_completed(290))

        def factory():
            def projection(x):
                return Observable.interval(
                    10, scheduler).map(lambda a, b: x).take(x)

            return xs.select_many(projection)

        results = scheduler.start(factory)

        results.messages.assert_equal(on_next(220, 4), on_next(230, 3),
                                      on_next(230, 4), on_next(240, 3),
                                      on_next(240, 4), on_next(250, 3),
                                      on_next(250, 4), on_next(260, 5),
                                      on_next(270, 5), on_next(280, 1),
                                      on_next(280, 5), on_next(290, 5),
                                      on_next(300, 5), on_completed(300))
        xs.subscriptions.assert_equal(subscribe(200, 290))
Exemplo n.º 36
0
    def test_delay_duration_simple1(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(on_next(150, 1), on_next(210, 10),
                                             on_next(220,
                                                     30), on_next(230, 50),
                                             on_next(240,
                                                     35), on_next(250, 20),
                                             on_completed(260))

        def create():
            def selector(x):
                return scheduler.create_cold_observable(on_next(x, '!'))

            return xs.delay_with_selector(selector)

        results = scheduler.start(create)

        results.messages.assert_equal(on_next(210 + 10, 10),
                                      on_next(220 + 30, 30),
                                      on_next(250 + 20, 20),
                                      on_next(240 + 35, 35),
                                      on_next(230 + 50, 50), on_completed(280))
        xs.subscriptions.assert_equal(subscribe(200, 260))
Exemplo n.º 37
0
    def test_min_by_comparer_throw(self):
        ex = 'ex'
        scheduler = TestScheduler()
        msgs = [
            on_next(150, {
                "key": 1,
                "value": 'z'
            }), on_error(210, ex)
        ]
        def reverse_comparer(a, b):
            if a > b:
                return -1

            if a == b:
                return 0

            return 1
        def create():
            return xs.min_by(lambda x: x["key"], reverse_comparer)

        xs = scheduler.create_hot_observable(msgs)
        res = scheduler.start(create=create).messages
        res.assert_equal(on_error(210, ex))
    def test_buffer_with_time_basic_same(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(on_next(100, 1), on_next(210, 2),
                                             on_next(240, 3), on_next(280, 4),
                                             on_next(320, 5), on_next(350, 6),
                                             on_next(380, 7), on_next(420, 8),
                                             on_next(470, 9),
                                             on_completed(600))

        def create():
            return xs.pipe(ops.buffer_with_time(100),
                           ops.map(lambda x: ",".join([str(a) for a in x])))

        results = scheduler.start(create)

        assert results.messages == [
            on_next(300, "2,3,4"),
            on_next(400, "5,6,7"),
            on_next(500, "8,9"),
            on_next(600, ""),
            on_completed(600)
        ]
        assert xs.subscriptions == [subscribe(200, 600)]
Exemplo n.º 39
0
    def test_catch_error(self):
        ex = 'ex'
        scheduler = TestScheduler()
        msgs1 = [
            on_next(150, 1),
            on_next(210, 2),
            on_next(220, 3),
            on_error(230, ex)
        ]
        msgs2 = [on_next(240, 5), on_completed(250)]
        o1 = scheduler.create_hot_observable(msgs1)
        o2 = scheduler.create_hot_observable(msgs2)

        def create():
            return o1.catch_exception(o2)

        results = scheduler.start(create)
        assert results.messages == [
            on_next(210, 2),
            on_next(220, 3),
            on_next(240, 5),
            on_completed(250)
        ]
Exemplo n.º 40
0
    def test_min_of_t_comparer_empty_ii(self):
        scheduler = TestScheduler()

        def comparer(a, b):
            if a > b:
                return -1

            if a == b:
                return 0

            return 1

        xs = scheduler.create_hot_observable(on_next(150, 'z'),
                                             on_next(210, "b"),
                                             on_next(220, "c"),
                                             on_next(230, "a"),
                                             on_completed(250))

        def create():
            return xs.pipe(ops.min(comparer))

        res = scheduler.start(create=create).messages
        assert res == [on_next(250, "c"), on_completed(250)]
Exemplo n.º 41
0
    def test_combine_latest_consecutive_end_with_error_left(self):
        ex = 'ex'
        scheduler = TestScheduler()
        msgs1 = [
            on_next(150, 1),
            on_next(215, 2),
            on_next(225, 4),
            on_error(230, ex)
        ]
        msgs2 = [
            on_next(150, 1),
            on_next(235, 6),
            on_next(240, 7),
            on_completed(250)
        ]
        e1 = scheduler.create_hot_observable(msgs1)
        e2 = scheduler.create_hot_observable(msgs2)

        def create():
            return e1.combine_latest(e2, lambda x, y: x + y)

        results = scheduler.start(create)
        results.messages.assert_equal(on_error(230, ex))
Exemplo n.º 42
0
def test_take_while_zero():
    scheduler = TestScheduler()
    xs = scheduler.create_hot_observable(on_next(90, -1), on_next(110, -1),
                                         on_next(205, 100), on_next(210, 2),
                                         on_next(260, 5), on_next(290, 13),
                                         on_next(320, 3), on_next(350, 7),
                                         on_next(390, 4), on_next(410, 17),
                                         on_next(450, 8), on_next(500, 23),
                                         on_completed(600))
    invoked = 0

    def create():
        def predicate(x):
            nonlocal invoked
            invoked += 1
            return is_prime(x)

        return xs.take_while(predicate)

    results = scheduler.start(create, disposed=300)
    results.messages.assert_equal(on_completed(205))
    xs.subscriptions.assert_equal(subscribe(200, 205))
    assert (invoked == 1)
Exemplo n.º 43
0
    def test_WhenMultipleDataAsymmetric(self):
        scheduler = TestScheduler()

        xs = scheduler.create_hot_observable(on_next(210, 1), on_next(220, 2),
                                             on_next(230, 3),
                                             on_completed(240))

        ys = scheduler.create_hot_observable(on_next(240, 4), on_next(250, 5),
                                             on_completed(270))

        def create():
            def mapper(x, y):
                return x + y

            return Observable.when(xs.and_(ys).then_do(mapper))

        results = scheduler.start(create)

        assert results.messages == [
            on_next(240, 1 + 4),
            on_next(250, 2 + 5),
            on_completed(270)
        ]
Exemplo n.º 44
0
    def test_max_of_t_comparer_empty(self):
        scheduler = TestScheduler()
        msgs = [on_next(150, 1), on_completed(250)]

        def reverse_comparer(a, b):
            if a > b:
                return -1

            if a < b:
                return 1

            return 0

        xs = scheduler.create_hot_observable(msgs)

        def create():
            return xs.pipe(ops.max(reverse_comparer))

        res = scheduler.start(create=create).messages
        self.assertEqual(1, len(res))
        assert (res[0].value.kind == 'E'
                and res[0].value.exception is not None)
        assert (res[0].time == 250)
Exemplo n.º 45
0
    def test_min_of_t_comparer_empty(self):
        scheduler = TestScheduler()

        def comparer(a, b):
            if a > b:
                return -1

            if a == b:
                return 0

            return 1

        xs = scheduler.create_hot_observable(on_next(150, 'a'),
                                             on_completed(250))

        def create():
            return xs.pipe(ops.min(comparer))

        res = scheduler.start(create=create).messages
        self.assertEqual(1, len(res))
        assert (res[0].value.kind == 'E'
                and res[0].value.exception is not None)
        assert (res[0].time == 250)
Exemplo n.º 46
0
    def test_case_with_default_throw(self):
        ex = 'ex'
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(on_next(210, 1), on_next(240, 2),
                                             on_next(270, 3),
                                             on_completed(300))
        ys = scheduler.create_hot_observable(on_next(220,
                                                     11), on_next(250, 12),
                                             on_next(280, 13),
                                             on_completed(310))
        map = {1: xs, 2: ys}

        def create():
            def selector():
                raise Exception(ex)

            return Observable.switch_case(selector, map, scheduler=scheduler)

        results = scheduler.start(create)

        results.messages.assert_equal(on_error(200, ex))
        xs.subscriptions.assert_equal()
        ys.subscriptions.assert_equal()
Exemplo n.º 47
0
    def test_skip_while_dispose_before(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(on_next(90, -1), on_next(110, -1),
                                             on_next(210, 2), on_next(260, 5),
                                             on_next(290, 13), on_next(320, 3),
                                             on_next(350, 7), on_next(390, 4),
                                             on_next(410, 17), on_next(450, 8),
                                             on_next(500, 23),
                                             on_completed(600))
        invoked = [0]

        def create():
            def predicate(x):
                invoked[0] += 1
                return is_prime(x)

            return xs.skip_while(predicate)

        results = scheduler.start(create, disposed=300)

        results.messages.assert_equal()
        xs.subscriptions.assert_equal(subscribe(200, 300))
        assert (invoked[0] == 3)
Exemplo n.º 48
0
def test_group_by_with_key_comparer():
    scheduler = TestScheduler()
    key_invoked = 0
    xs = scheduler.create_hot_observable(on_next(90, "error"),
                                         on_next(110, "error"),
                                         on_next(130, "error"),
                                         on_next(220, "  foo"),
                                         on_next(240, " FoO "),
                                         on_next(270, "baR  "),
                                         on_next(310, "foO "),
                                         on_next(350, " Baz   "),
                                         on_next(360, "  qux "),
                                         on_next(390, "   bar"),
                                         on_next(420, " BAR  "),
                                         on_next(470, "FOO "),
                                         on_next(480, "baz  "),
                                         on_next(510, " bAZ "),
                                         on_next(530, "    fOo    "),
                                         on_completed(570),
                                         on_next(580, "error"),
                                         on_completed(600),
                                         on_error(650, 'ex'))

    def factory():
        def key_selector(x):
            nonlocal key_invoked
            key_invoked += 1
            return x.lower().strip()

        return xs.group_by(key_selector, lambda x: x).select(lambda g: g.key)

    results = scheduler.start(factory)
    results.messages.assert_equal(on_next(220, "foo"), on_next(270, "bar"),
                                  on_next(350, "baz"), on_next(360, "qux"),
                                  on_completed(570))
    xs.subscriptions.assert_equal(subscribe(200, 570))
    assert (key_invoked == 12)
Exemplo n.º 49
0
    def test_min_by_comparer_some(self):
        scheduler = TestScheduler()
        msgs = [
            on_next(150, {
                "key": 1,
                "value": 'z'
            }), on_next(210, {
                "key": 3,
                "value": 'b'
            }), on_next(220, {
                "key": 20,
                "value": 'c'
            }), on_next(230, {
                "key": 4,
                "value": 'a'
            }), on_completed(250)
        ]
        def reverse_comparer(a, b):
            if a > b:
                return -1

            if a == b:
                return 0
            return 1

        xs = scheduler.create_hot_observable(msgs)

        def create():
            return xs.min_by(lambda x: x["key"], reverse_comparer)

        res = scheduler.start(create=create).messages
        self.assertEqual(2, len(res))
        assert(res[0].value.kind == 'N')
        self.assertEqual(1, len(res[0].value.value))
        self.assertEqual(20, res[0].value.value[0]["key"])
        self.assertEqual('c', res[0].value.value[0]["value"])
        assert(res[1].value.kind == 'C' and res[1].time == 250)
Exemplo n.º 50
0
    def test_merge_lots3(self):
        scheduler = TestScheduler()
        msgs1 = [
            on_next(150, 1),
            on_next(210, 2),
            on_next(225, 5),
            on_next(240, 8),
            on_completed(245)
        ]
        msgs2 = [
            on_next(150, 1),
            on_next(215, 3),
            on_next(230, 6),
            on_next(245, 9),
            on_completed(250)
        ]
        msgs3 = [
            on_next(150, 1),
            on_next(220, 4),
            on_next(235, 7),
            on_completed(240)
        ]
        o1 = scheduler.create_hot_observable(msgs1)
        o2 = scheduler.create_hot_observable(msgs2)
        o3 = scheduler.create_hot_observable(msgs3)

        def create():
            return rx.merge(o1, o2, o3)

        results = scheduler.start(create).messages
        assert (len(results) == 9)
        for i, result in enumerate(results[:-1]):
            assert (results[i].value.kind == 'N'
                    and results[i].time == 210 + i * 5
                    and results[i].value.value == i + 2)

        assert (results[8].value.kind == 'C' and results[8].time == 250)
Exemplo n.º 51
0
    def test_zip_some_data_asymmetric2(self):
        scheduler = TestScheduler()

        def msgs1_factory():
            results = []
            for i in range(10):
                results.append(on_next(205 + i * 5, i))

            return results

        msgs1 = msgs1_factory()

        def msgs2_factory():
            results = []
            for i in range(5):
                results.append(on_next(205 + i * 8, i))
            return results

        msgs2 = msgs2_factory()

        length = min(len(msgs1), len(msgs2))
        e1 = scheduler.create_hot_observable(msgs1)
        e2 = scheduler.create_hot_observable(msgs2)

        def create():
            return e1.pipe(
                ops.zip(e2),
                ops.map(sum))

        results = scheduler.start(create).messages
        assert (length == len(results))
        for i in range(length):
            _sum = msgs1[i].value.value + msgs2[i].value.value
            time = max(msgs1[i].time, msgs2[i].time)
            assert (results[i].value.kind == 'N'
                    and results[i].time == time
                    and results[i].value.value == _sum)
Exemplo n.º 52
0
    def test_publish_lambda_zip_complete(self):
        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))

        def create():
            def mapper(_xs):
                return _xs.pipe(
                    ops.zip(_xs.pipe(ops.skip(1))),
                    ops.map(sum),
                )

            return xs.pipe(ops.publish(mapper))

        results = scheduler.start(create)

        assert results.messages == [
            on_next(280, 7),
            on_next(290, 5),
            on_next(340, 9),
            on_next(360, 13),
            on_next(370, 11),
            on_next(390, 13),
            on_next(410, 20),
            on_next(430, 15),
            on_next(450, 11),
            on_next(520, 20),
            on_next(560, 31),
            on_completed(600)
        ]
        assert xs.subscriptions == [subscribe(200, 600)]
Exemplo n.º 53
0
    def test_flat_map_iterable_complete(self):
        scheduler = TestScheduler()

        xs = scheduler.create_hot_observable(
            on_next(210, 2),
            on_next(340, 4),
            on_next(420, 3),
            on_next(510, 2),
            on_completed(600)
        )
        inners = []

        def create():
            def mapper(x):
                ys = [x] * x
                inners.append(ys)
                return ys
            return xs.flat_map(mapper)
        res = scheduler.start(create)

        assert res.messages == [
            on_next(210, 2),
            on_next(210, 2),
            on_next(340, 4),
            on_next(340, 4),
            on_next(340, 4),
            on_next(340, 4),
            on_next(420, 3),
            on_next(420, 3),
            on_next(420, 3),
            on_next(510, 2),
            on_next(510, 2),
            on_completed(600)]

        assert xs.subscriptions == [
            subscribe(200, 600)]
        assert(4 == len(inners))
Exemplo n.º 54
0
    def test_debounce_duration_early_completion(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(410))
        ys = [
            scheduler.create_cold_observable(
                on_next(20, 42),
                on_next(25, 99)),
            scheduler.create_cold_observable(
                on_next(40, 42),
                on_next(45, 99)),
            scheduler.create_cold_observable(
                on_next(20, 42),
                on_next(25, 99)),
            scheduler.create_cold_observable(
                on_next(60, 42),
                on_next(65, 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(310 + 20, 2), on_next(410, 4), on_completed(410)]
        assert xs.subscriptions == [subscribe(200, 410)]
        assert ys[0].subscriptions == [subscribe(250, 250 + 20)]
        assert ys[1].subscriptions == [subscribe(280, 310)]
        assert ys[2].subscriptions == [subscribe(310, 310 + 20)]
        assert ys[3].subscriptions == [subscribe(350, 400)]
        assert ys[4].subscriptions == [subscribe(400, 410)]
Exemplo n.º 55
0
    def test_group_join_op_error_i(self):
        ex = 'ex'
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(
            on_next(210, TimeInterval(0, TimeSpan.from_ticks(10))),
            on_next(219, TimeInterval(1, TimeSpan.from_ticks(5))),
            on_next(240, TimeInterval(2, TimeSpan.from_ticks(10))),
            on_next(300, TimeInterval(3, TimeSpan.from_ticks(100))),
            on_error(310, ex))
        ys = scheduler.create_hot_observable(
            on_next(215, TimeInterval("hat", TimeSpan.from_ticks(20))),
            on_next(217, TimeInterval("bat", TimeSpan.from_ticks(1))),
            on_next(290, TimeInterval("wag", TimeSpan.from_ticks(200))),
            on_next(300, TimeInterval("pig", TimeSpan.from_ticks(10))),
            on_next(305, TimeInterval("cup", TimeSpan.from_ticks(50))),
            on_next(600, TimeInterval("yak", TimeSpan.from_ticks(90))),
            on_next(702, TimeInterval("tin", TimeSpan.from_ticks(20))),
            on_next(712, TimeInterval("man", TimeSpan.from_ticks(10))),
            on_next(722, TimeInterval("rat", TimeSpan.from_ticks(200))),
            on_next(732, TimeInterval("wig", TimeSpan.from_ticks(5))),
            on_completed(800))

        def create():
            return xs.group_join(
                ys,
                lambda x: Observable.timer(x.interval, scheduler=scheduler),
                lambda y: Observable.timer(y.interval, scheduler=scheduler),
                lambda x, yy: yy.select(lambda y: str(x.value) + y.value
                                        )).merge_observable()

        results = scheduler.start(create=create)
        results.messages.assert_equal(on_next(215,
                                              "0hat"), on_next(217, "0bat"),
                                      on_next(219,
                                              "1hat"), on_next(300, "3wag"),
                                      on_next(300, "3pig"),
                                      on_next(305, "3cup"), on_error(310, ex))
Exemplo n.º 56
0
    def test_join_op_error_i(self):
        ex = 'ex'
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(
            on_next(210, TimeInterval(0, 10)),
            on_next(219, TimeInterval(1, 5)),
            on_next(240, TimeInterval(2, 10)),
            on_next(300, TimeInterval(3, 100)),
            on_error(310, ex))
        ys = scheduler.create_hot_observable(
            on_next(215, TimeInterval("hat", 20)),
            on_next(217, TimeInterval("bat", 1)),
            on_next(290, TimeInterval("wag", 200)),
            on_next(300, TimeInterval("pig", 10)),
            on_next(305, TimeInterval("cup", 50)),
            on_next(600, TimeInterval("yak", 90)),
            on_next(702, TimeInterval("tin", 20)),
            on_next(712, TimeInterval("man", 10)),
            on_next(722, TimeInterval("rat", 200)),
            on_next(732, TimeInterval("wig", 5)),
            on_completed(800))

        def create():
            return xs.join(ys,
                lambda x: Observable.timer(x.interval, scheduler=scheduler),
                lambda y: Observable.timer(y.interval, scheduler=scheduler),
                lambda x, y: str(x.value) + y.value
            )
        results = scheduler.start(create=create, disposed=713)
        results.messages.assert_equal(
            on_next(215, "0hat"),
            on_next(217, "0bat"),
            on_next(219, "1hat"),
            on_next(300, "3wag"),
            on_next(300, "3pig"),
            on_next(305, "3cup"),
            on_error(310, ex))
Exemplo n.º 57
0
    def test_window_opening_closings_basic(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(on_next(90, 1), on_next(180, 2),
                                             on_next(250, 3), on_next(260, 4),
                                             on_next(310, 5), on_next(340, 6),
                                             on_next(410, 7), on_next(420, 8),
                                             on_next(470, 9), on_next(550, 10),
                                             on_completed(590))
        ys = scheduler.create_hot_observable(on_next(255,
                                                     50), on_next(330, 100),
                                             on_next(350,
                                                     50), on_next(400, 90),
                                             on_completed(900))

        def create():
            def closing(x):
                return Observable.timer(x)

            def mapper(w, i):
                return w.map(lambda x: str(i) + ' ' + str(x))

            return xs.window(ys,
                             closing).map(mapper_indexed=mapper).merge_all()

        results = scheduler.start(create=create)
        assert results.messages == [
            on_next(260, "0 4"),
            on_next(340, "1 6"),
            on_next(410, "1 7"),
            on_next(410, "3 7"),
            on_next(420, "1 8"),
            on_next(420, "3 8"),
            on_next(470, "3 9"),
            on_completed(900)
        ]
        assert xs.subscriptions == [subscribe(200, 900)]
        assert ys.subscriptions == [subscribe(200, 900)]
Exemplo n.º 58
0
    def test_publish_with_initial_value_lambda_zip_error(self):
        ex = 'ex'
        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_error(600, ex))

        def create():
            def mapper(_xs):
                return _xs.zip(_xs.skip(1),
                               result_mapper=lambda prev, cur: cur + prev)

            return xs.publish_value(1979, mapper)

        results = scheduler.start(create)

        assert results.messages == [
            on_next(220, 1982),
            on_next(280, 7),
            on_next(290, 5),
            on_next(340, 9),
            on_next(360, 13),
            on_next(370, 11),
            on_next(390, 13),
            on_next(410, 20),
            on_next(430, 15),
            on_next(450, 11),
            on_next(520, 20),
            on_next(560, 31),
            on_error(600, ex)
        ]
        assert xs.subscriptions == [subscribe(200, 600)]
Exemplo n.º 59
0
    def test_window_with_count_error(self):
        ex = 'ex'
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(on_next(100, 1), on_next(210, 2),
                                             on_next(240, 3), on_next(280, 4),
                                             on_next(320, 5), on_next(350, 6),
                                             on_next(380, 7), on_next(420, 8),
                                             on_next(470, 9),
                                             on_error(600, ex))

        def create():
            def mapper(w, i):
                def mapping(x):
                    return "%s %s" % (i, x)

                return w.pipe(ops.map(mapping))

            return xs.pipe(ops.window_with_count(3, 2),
                           ops.map_indexed(mapper), ops.merge_all())

        results = scheduler.start(create)

        assert results.messages == [
            on_next(210, "0 2"),
            on_next(240, "0 3"),
            on_next(280, "0 4"),
            on_next(280, "1 4"),
            on_next(320, "1 5"),
            on_next(350, "1 6"),
            on_next(350, "2 6"),
            on_next(380, "2 7"),
            on_next(420, "2 8"),
            on_next(420, "3 8"),
            on_next(470, "3 9"),
            on_error(600, ex)
        ]
        assert xs.subscriptions == [subscribe(200, 600)]
Exemplo n.º 60
0
    def test_window_time_basic(self):
        scheduler = TestScheduler()
        xs = scheduler.create_hot_observable(on_next(150, 1), on_next(210, 2),
                                             on_next(240, 3), on_next(270, 4),
                                             on_next(320, 5), on_next(360, 6),
                                             on_next(390, 7), on_next(410, 8),
                                             on_next(460, 9), on_next(470, 10),
                                             on_completed(490))

        def create():
            def mapper(ys, i):
                def proj(y):
                    return "%s %s" % (i, y)

                return ys.map(proj).concat(
                    Observable.return_value('%s end' % i))

            return xs.window_with_time(100).mapi(mapper).merge_all()

        results = scheduler.start(create)

        assert results.messages == [
            on_next(210, "0 2"),
            on_next(240, "0 3"),
            on_next(270, "0 4"),
            on_next(300, "0 end"),
            on_next(320, "1 5"),
            on_next(360, "1 6"),
            on_next(390, "1 7"),
            on_next(400, "1 end"),
            on_next(410, "2 8"),
            on_next(460, "2 9"),
            on_next(470, "2 10"),
            on_next(490, "2 end"),
            on_completed(490)
        ]
        assert xs.subscriptions == [subscribe(200, 490)]