Example #1
0
    def test_retry_observable_retry_count_throws(self):
        scheduler1 = TestScheduler()
        xs = reactivex.return_value(1).pipe(ops.retry(3))
        xs.subscribe(lambda x: _raise("ex"), scheduler=scheduler1)

        self.assertRaises(RxException, scheduler1.start)

        scheduler2 = TestScheduler()
        ys = reactivex.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 = reactivex.return_value(1).pipe(ops.retry(100))
        zs.subscribe(on_completed=lambda: _raise("ex"), scheduler=scheduler3)

        with pytest.raises(RxException):
            scheduler3.start()

        xss = reactivex.create(lambda o: _raise("ex")).pipe(ops.retry(100))
        with pytest.raises(Exception):
            xss.subscribe()
Example #2
0
    def test_return_observer_throws(self):
        scheduler1 = TestScheduler()
        xs = reactivex.return_value(1)
        xs.subscribe(lambda x: _raise("ex"), scheduler=scheduler1)

        self.assertRaises(RxException, scheduler1.start)

        scheduler2 = TestScheduler()
        ys = reactivex.return_value(1)
        ys.subscribe(lambda x: x,
                     lambda ex: ex,
                     lambda: _raise("ex"),
                     scheduler=scheduler2)

        self.assertRaises(RxException, scheduler2.start)
Example #3
0
            def mapper(ys, i):
                def proj(y):
                    return "%s %s" % (i, y)

                return ys.pipe(
                    ops.map(proj),
                    ops.concat(reactivex.return_value("%s end" % i)))
Example #4
0
 async def go():
     source = reactivex.return_value(42)
     fut = next(source.__await__())
     # This used to raise an InvalidStateError before we got
     # support for cancellation.
     fut.cancel()
     await fut
Example #5
0
    def test_return_disposed_after_next(self):
        scheduler = TestScheduler()
        d = SerialDisposable()
        xs = reactivex.return_value(42)
        results = scheduler.create_observer()

        def action(scheduler, state):
            def on_next(x):
                d.dispose()
                results.on_next(x)

            def on_error(e):
                results.on_error(e)

            def on_completed():
                results.on_completed()

            d.disposable = xs.subscribe(on_next,
                                        on_error,
                                        on_completed,
                                        scheduler=scheduler)
            return d.disposable

        scheduler.schedule_absolute(100, action)
        scheduler.start()
        assert results.messages == [on_next(100, 42)]
Example #6
0
    def test_map_throws(self):
        mapper = map(lambda x: x)
        with self.assertRaises(RxException):
            return_value(1).pipe(mapper).subscribe(lambda x: _raise("ex"))

        with self.assertRaises(RxException):
            throw("ex").pipe(mapper).subscribe(on_error=lambda ex: _raise(ex))

        with self.assertRaises(RxException):
            empty().pipe(mapper).subscribe(
                lambda x: x, lambda ex: ex, lambda: _raise("ex")
            )

        def subscribe(observer, scheduler=None):
            _raise("ex")

        with self.assertRaises(RxException):
            create(subscribe).pipe(map(lambda x: x)).subscribe()
Example #7
0
    def test_retry_observable_throws(self):
        scheduler1 = TestScheduler()
        xs = reactivex.return_value(1).pipe(ops.retry())
        xs.subscribe(lambda x: _raise("ex"), scheduler=scheduler1)

        with pytest.raises(RxException):
            scheduler1.start()

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

        scheduler2.schedule_absolute(210, lambda sc, st: d.dispose())
        scheduler2.start()

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

        with pytest.raises(RxException):
            scheduler3.start()
    def test_connectable_observable_creation(self):
        y = [0]

        s2 = Subject()
        co2 = ConnectableObservable(reactivex.return_value(1), s2)

        def on_next(x):
            y[0] = x

        co2.subscribe(on_next=on_next)
        self.assertNotEqual(1, y[0])

        co2.connect()
        self.assertEqual(1, y[0])
Example #9
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()
Example #10
0
    def test_map_with_index_throws(self):
        with self.assertRaises(RxException):
            mapper = map_indexed(lambda x, index: x)

            return return_value(1).pipe(mapper).subscribe(lambda x: _raise("ex"))

        with self.assertRaises(RxException):
            return (
                throw("ex").pipe(mapper).subscribe(lambda x: x, lambda ex: _raise(ex))
            )

        with self.assertRaises(RxException):
            return (
                empty()
                .pipe(mapper)
                .subscribe(lambda x: x, lambda ex: None, lambda: _raise("ex"))
            )

        with self.assertRaises(RxException):
            return create(lambda o, s: _raise("ex")).pipe(mapper).subscribe()
Example #11
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))
Example #12
0
 async def go():
     nonlocal result
     source = reactivex.return_value(42).pipe(ops.delay(0.1))
     result = await source
Example #13
0
 async def go():
     nonlocal result
     source = reactivex.return_value(42)
     result = await source
Example #14
0
 def factory():
     return reactivex.return_value(42)