def test_acknowledge_both(self):
        """
                        ack.on_next
        WaitOnRightLeft ------------> WaitOnRightLeft
        """

        sink = TObserver(immediate_continue=0)
        obs = ControlledZipObservable(
            left=self.left, right=self.right, scheduler=self.scheduler,
            request_left=lambda left, right: left <= right,
            request_right=lambda left, right: right <= left,
            match_func=lambda left, right: left == right,
        )
        obs.observe(init_observer_info(sink))

        ack1 = self.left.on_next_list([1])
        ack2 = self.right.on_next_list([1])
        sink.ack.on_next(continue_ack)

        self.assertIsInstance(self.measure_state(obs), ControlledZipStates.WaitOnLeftRight)
        self.assertIsInstance(ack1.value, ContinueAck)
        self.assertIsInstance(ack2.value, ContinueAck)
        self.assertListEqual(sink.received, [(1, 1)])
    def test_three_sources(self):
        sink = TObserver()
        observer = FlatConcatNoBackpressureObserver(
            next_observer=sink,
            selector=lambda v: v,
            scheduler=self.scheduler,
            subscribe_scheduler=self.scheduler,
            composite_disposable=self.composite_disposable,
        )
        self.source.observe(init_observer_info(observer=observer))
        self.source.on_next_single(self.source1)
        self.source.on_next_single(self.source2)
        self.source.on_next_single(self.source3)
        self.scheduler.advance_by(1)

        self.source1.on_next_single(1)
        self.source2.on_next_single(2)
        self.source3.on_next_single(3)
        self.source1.on_completed()
        self.source2.on_completed()
        self.source3.on_completed()

        self.assertEqual([1, 2, 3], sink.received)
Exemplo n.º 3
0
    def test_wait_on_left_right_to_wait_on_right(self):
        """
                         left.on_next
        WaitOnLeftRight -----------------> WaitOnRight
         InitState                          InitState
        """

        sink = TObserver()
        obs = MergeSelectorObservable(
            left=self.left,
            right=self.right,
            # scheduler=self.scheduler,
        )
        obs.observe(init_observer_info(sink))

        ack = self.left.on_next_list([select_next, select_completed])

        self.assertIsInstance(self.measure_termination_state(obs),
                              TerminationStates.InitState)
        self.assertIsInstance(self.measure_state(obs),
                              ControlledZipStates.WaitOnRight)
        self.assertEqual([], sink.received)
        self.assertFalse(ack.is_sync)
    def test_failure_after_non_matching_element_synchronously(self):
        sink = TObserver(immediate_continue=None)
        observer = TakeWhileObserver(
            observer=sink,
            predicate=lambda v: v,
        )
        self.source.observe(init_observer_info(observer))

        def gen_iterable():
            for i in range(10):
                if i == 2:
                    yield 0
                elif i == 3:
                    raise self.exception
                else:
                    yield 1

        ack = self.source.on_next_iter(gen_iterable())

        self.assertIsInstance(ack, StopAck)
        self.assertEqual(1, sink.on_next_counter)
        self.assertListEqual([1, 1], sink.received)
        self.assertTrue(sink.is_completed)
        self.assertIsNone(sink.exception)
Exemplo n.º 5
0
 def test_initialize(self):
     sink = TObserver()
     observer = ConnectableObserver(
         sink,
     )
Exemplo n.º 6
0
 def test_initialize(self):
     sink = TObserver()
     FilterObserver(
         observer=sink,
         predicate=lambda _: True,
     )
Exemplo n.º 7
0
 def test_initialize(self):
     sink = TObserver()
     BufferedObserver(underlying=sink,
                      scheduler=self.scheduler,
                      subscribe_scheduler=self.scheduler,
                      buffer_size=0)
Exemplo n.º 8
0
 def test_initialize(self):
     sink = TObserver()
     FirstObserver(
         observer=sink,
         stack=get_stack_lines(),
     )
 def setUp(self) -> None:
     self.source = TObservable()
     self.sink = TObserver()
Exemplo n.º 10
0
import time
from threading import Thread

import rxbp
from rxbp.schedulers.timeoutscheduler import TimeoutScheduler
from rxbp.testing.tobserver import TObserver


def counter(sink):
    while True:
        time.sleep(1)
        print(f"immediate: {sink.immediate_continue}, received: ",
              sink.received)


publisher = rxbp.interval(0.5).pipe(rxbp.op.map(lambda v: "data_" + str(v)))
sink = TObserver(immediate_continue=12)
publisher.subscribe(observer=sink, subscribe_scheduler=TimeoutScheduler())

t1 = Thread(target=counter, args=(sink, ))
t1.start()
t1.join()
Exemplo n.º 11
0
 def setUp(self):
     self.scheduler = TScheduler()
     self.sink = TObserver()
 def test_initialize(self):
     sink = TObserver()
     TakeWhileObserver(
         observer=sink,
         predicate=lambda _: True,
     )
 def test_initialize(self):
     sink = TObserver()
     ToListObserver(observer=sink, )
Exemplo n.º 14
0
 def gen_observers():
     for i in range(10):
         o1 = TObserver()
         o1.immediate_continue = 5
         subject.observe(init_observer_info(o1))
         yield o1
Exemplo n.º 15
0
 def test_initialize(self):
     sink = TObserver()
     DefaultIfEmptyObserver(
         next_observer=sink,
         lazy_val=lambda: 0,
     )
Exemplo n.º 16
0
 def gen_observers():
     for _ in range(10):
         observer = TObserver()
         subject.observe(init_observer_info(observer=observer, ))
         yield observer
 def setUp(self):
     self.scheduler = TScheduler()
     self.sink = TObserver(immediate_continue=0)
Exemplo n.º 18
0
 def setUp(self) -> None:
     self.scheduler = TScheduler()
     self.composite_disposable = CompositeDisposable()
     self.sink = TObserver()
     self.exception = Exception()
 def test_initialize(self):
     sink = TObserver()
     ZipCountObserver(
         observer=sink,
         selector=lambda v, idx: (v, idx),
     )