Esempio n. 1
0
    def test_repeat_observable_repeat_count_throws(self):
        scheduler1 = TestScheduler()
        xs = reactivex.return_value(1).pipe(ops.repeat(3))
        xs.subscribe(lambda x: _raise("ex"), scheduler=scheduler1)

        with self.assertRaises(RxException):
            scheduler1.start()

        scheduler2 = TestScheduler()
        ys = reactivex.throw("ex1").pipe(ops.repeat(3))
        ys.subscribe(on_error=lambda ex: _raise("ex2"), scheduler=scheduler2)

        with self.assertRaises(RxException):
            scheduler2.start()
Esempio n. 2
0
    def test_concat_repeat(self):
        with marbles_testing() as (start, cold, hot, exp):
            e1 = cold("-e11-e12|")
            e2 = cold("-e21-e22|")
            ex = exp("-e11-e12-e21-e22-e11-e12-e21-e22|")

            obs = e1.pipe(ops.concat(e2), ops.repeat(2))

            results = start(obs)
            assert results == ex
Esempio n. 3
0
    def test_repeat_observable_repeat_count_infinite(self):
        scheduler = TestScheduler()
        xs = scheduler.create_cold_observable(on_next(100, 1), on_next(150, 2),
                                              on_next(200, 3))
        results = scheduler.start(lambda: xs.pipe(ops.repeat(3)))

        assert results.messages == [
            on_next(300, 1), on_next(350, 2),
            on_next(400, 3)
        ]
        assert xs.subscriptions == [subscribe(200, 1000)]
Esempio n. 4
0
 def test_repeat_observable_repeat_count_dispose(self):
     scheduler = TestScheduler()
     xs = scheduler.create_cold_observable(on_next(5, 1), on_next(10, 2),
                                           on_next(15, 3), on_completed(20))
     results = scheduler.start(lambda: xs.pipe(ops.repeat(3)), disposed=231)
     assert results.messages == [
         on_next(205, 1),
         on_next(210, 2),
         on_next(215, 3),
         on_next(225, 1),
         on_next(230, 2),
     ]
     assert xs.subscriptions == [subscribe(200, 220), subscribe(220, 231)]
Esempio n. 5
0
    def test_repeat_observable_throws(self):
        scheduler1 = TestScheduler()
        xs = reactivex.return_value(11).pipe(ops.repeat())
        xs.subscribe(lambda x: _raise("ex"), scheduler=scheduler1)

        with self.assertRaises(RxException):
            scheduler1.start()

        scheduler2 = TestScheduler()
        ys = reactivex.throw("ex").pipe(ops.repeat())
        ys.subscribe(lambda ex: _raise("ex"), scheduler=scheduler2)

        with self.assertRaises(Exception):
            scheduler2.start()

        scheduler3 = TestScheduler()
        zs = reactivex.return_value(1).pipe(ops.repeat())
        d = zs.subscribe(on_completed=lambda: _raise("ex"),
                         scheduler=scheduler3)

        scheduler3.schedule_absolute(210, lambda sc, st: d.dispose())
        scheduler3.start()
Esempio n. 6
0
    def test_repeat_observable_repeat_count_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.pipe(ops.repeat(3)))

        assert results.messages == [
            on_next(300, 1),
            on_next(350, 2),
            on_next(400, 3),
            on_error(450, ex),
        ]
        assert xs.subscriptions == [subscribe(200, 450)]
Esempio n. 7
0
def repeat_value_(value: _T,
                  repeat_count: Optional[int] = None) -> Observable[_T]:
    """Generates an observable sequence that repeats the given element
    the specified number of times.

    Examples:
        1 - res = repeat_value(42)
        2 - res = repeat_value(42, 4)

    Args:
        value: Element to repeat.
        repeat_count: [Optional] Number of times to repeat the element.
            If not specified, repeats indefinitely.

    Returns:
        An observable sequence that repeats the given element the
        specified number of times.
    """

    if repeat_count == -1:
        repeat_count = None

    xs = reactivex.return_value(value)
    return xs.pipe(ops.repeat(repeat_count))
Esempio n. 8
0
    def test_repeat_observable_basic(self):
        scheduler = TestScheduler()
        xs = scheduler.create_cold_observable(on_next(100, 1), on_next(200, 3),
                                              on_next(150, 2),
                                              on_completed(250))
        results = scheduler.start(lambda: xs.pipe(ops.repeat()))

        assert results.messages == [
            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),
        ]
        assert xs.subscriptions == [
            subscribe(200, 450),
            subscribe(450, 700),
            subscribe(700, 950),
            subscribe(950, 1000),
        ]
Esempio n. 9
0
 def create():
     return reactivex.generate(
         0,
         lambda x: x <= 3,
         lambda x: x + 1,
     ).pipe(ops.repeat(2))