def test_repeat_observable_repeat_count_throws(self):
        scheduler1 = TestScheduler()
        xs = rx.return_value(1).pipe(ops.repeat(3))
        xs.subscribe(lambda x: _raise('ex'), scheduler=scheduler1)

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

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

        with self.assertRaises(RxException):
            scheduler2.start()
    def test_repeat_observable_repeat_count_throws(self):
        scheduler1 = TestScheduler()
        xs = rx.return_value(1).pipe(ops.repeat(3))
        xs.subscribe(lambda x: _raise('ex'), scheduler=scheduler1)

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

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

        with self.assertRaises(RxException):
            scheduler2.start()
    def test_repeat_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.pipe(ops.repeat()))

        assert results.messages == [on_next(300, 1), on_next(350, 2), on_next(400, 3)]
        assert xs.subscriptions == [subscribe(200, 1000)]
    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)]
    def test_repeat_observable_repeat_count_basic(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)))

        assert results.messages == [on_next(205, 1), on_next(210, 2), on_next(215, 3), on_next(225, 1), on_next(
            230, 2), on_next(235, 3), on_next(245, 1), on_next(250, 2), on_next(255, 3), on_completed(260)]
        assert xs.subscriptions == [subscribe(200, 220), subscribe(220, 240), subscribe(240, 260)]
    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)]
    def test_repeat_observable_throws(self):
        scheduler1 = TestScheduler()
        xs = rx.return_value(11).pipe(ops.repeat())
        xs.subscribe(lambda x: _raise('ex'), scheduler=scheduler1)

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

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

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

        scheduler3 = TestScheduler()
        zs = rx.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()
    def test_repeat_observable_throws(self):
        scheduler1 = TestScheduler()
        xs = rx.return_value(11).pipe(ops.repeat())
        xs.subscribe(lambda x: _raise('ex'), scheduler=scheduler1)

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

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

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

        scheduler3 = TestScheduler()
        zs = rx.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()
 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)]
    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)]
Beispiel #11
0
    def _initialize_drag(self, ui: FrameUI):
        offset = rx.merge(self.on_drag_start, self.on_drag).pipe(
            ops.filter(
                lambda e: self.draggable and e.button == MouseButton.LEFT),
            ops.filter(lambda e: ui.allow_drag(self, self.position_of(e))),
            ops.filter(lambda e: not self.resizable or ui.resize_handle_at(
                self, e.position) == Nothing), ops.map(lambda e: e.position),
            ops.pairwise(), ops.map(lambda v: v[1] - v[0]),
            ops.take_until(
                self.on_drag_end.pipe(
                    ops.filter(lambda e: e.button == MouseButton.LEFT))),
            ops.repeat(), ops.take_until(self.on_dispose))

        self._drag_listener = offset.subscribe(
            self.move_by, on_error=self.context.error_handler)
Beispiel #12
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)]
Beispiel #13
0
def _repeat_value(value: Any = None, repeat_count: int = None) -> Observable:
    """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 = rx.return_value(value)
    return xs.pipe(ops.repeat(repeat_count))
Beispiel #14
0
def _repeat_value(value: Any = None, repeat_count: Optional[int] = None) -> Observable:
    """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 = rx.return_value(value)
    return xs.pipe(ops.repeat(repeat_count))
    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)
        ]
Beispiel #16
0
    op.map(lambda x: print('map call', x) or x),
    op.buffer_with_count(2),
    op.map(print),
).run()

# 3こためて先頭の2こを処理
print('call take3 !!!!!!!!!!')
rx.from_iterable((print('generator call', i) or i for i in range(10))).pipe(
    op.window_with_count(3),
    op.flat_map(lambda x: x.pipe(op.take(2))),
    op.map(print),
).run()

# delayはobservableを引数に取りobservableを返す関数
# 引数にobservable以外を渡しても関数は通るが、呼び出すときにエラーになる
print('call take4 !!!!!!!!!!')
rx.from_iterable((print('generator call', i) or i for i in range(10))).pipe(
    op.map(lambda x: op.delay(3)(rx.just(x))),
    # op.window_with_count(1),
    op.flat_map(lambda x: x),
    op.map(print),
).run()

print('=================')
# generatorはrepeatできない
# repeatはもとのoncompletedが来てから最初からやり直す
# repeatをしてできたobservable自体のon completed は1回
rx.from_iterable([1, 2, 3, 4]).pipe(
    op.repeat(3),
    op.map(print),
).subscribe(on_completed=lambda: print('on completed'))
import rx
import rx.operators as ops

numbers = rx.from_([1, 2, 3])
numbers.pipe(ops.repeat(3)).subscribe(
    on_next=lambda i: print("item: {}".format(i)),
    on_error=lambda e: print("error: {}".format(e)),
    on_completed=lambda: print("completed"))
Beispiel #18
0
import rx
import rx.operators as ops

ones = rx.just(1).pipe(ops.repeat(5))
ones.subscribe(on_next=lambda i: print("item: {}".format(i)),
               on_error=lambda e: print("error: {}".format(e)),
               on_completed=lambda: print("completed"))
Beispiel #19
0
import os, glob
import rx
import rx.operators as op
from rx.scheduler import ImmediateScheduler

l = rx.from_iterable(glob.glob('./train/*.png')).pipe(
    op.map(os.path.basename), op.map(rx.just),
    op.flat_map(
        lambda x: x.pipe(
            op.repeat(3),
            op.subscribe_on(ImmediateScheduler()),
            op.map_indexed(lambda x, i: x.replace(".png", f"_{i}.png")),
        ), ), op.to_list()).run()

print(l)

l = rx.from_iterable(glob.glob('./train/*.png')).pipe(
    op.map(os.path.basename),
    op.map(rx.just),
    op.map(op.repeat(3)),
    op.map(op.subscribe_on(ImmediateScheduler())),
    # op.flat_map(lambda x : x.pipe(op.map_indexed(lambda x,i: x.replace(".png",f"_{i}.png")))),
    # op.flat_map(lambda x: op.map_indexed(lambda x,i: x.replace(".png",f"_{i}.png"))(x) ),
    # op.flat_map(op.map_indexed(lambda x,i: x.replace(".png",f"_{i}.png"))),
    # op.flat_map(lambda x: print('way',x) or x),
    op.map(lambda x: op.map_indexed(lambda x, i: x.replace(
        ".png", f"_{i}.png"))(x)),
    op.flat_map(lambda x: x),
    # op.flat_map_indexed(lambda x,i: print(x,i) or x),
    op.map(print)).run()
Beispiel #20
0
 def create():
     return rx.generate(0,
                        lambda x: x <= 3,
                        lambda x: x + 1,
                        ) \
         .pipe(ops.repeat(2))
 def create():
     return rx.generate(0,
                        lambda x: x <= 3,
                        lambda x: x + 1,
                        ) \
         .pipe(ops.repeat(2))