Example #1
0
    def test_single_batch(self):
        sink = TObserver()
        observer = FilterObserver(
            observer=sink,
            predicate=lambda v: v > 0,
        )
        self.source.observe(init_observer_info(observer))

        self.source.on_next_list([0, 1, 0, 2])

        self.assertEqual([1, 2], sink.received)
Example #2
0
    def test_single_elem_fulfill_predicate(self):
        sink = TObserver()
        observer = FilterObserver(
            observer=sink,
            predicate=lambda v: v > 0,
        )
        self.source.observe(init_observer_info(observer))

        self.source.on_next_single(1)

        self.assertEqual([1], sink.received)
Example #3
0
    def test_on_error(self):
        sink = TObserver()
        observer = FilterObserver(
            observer=sink,
            predicate=lambda v: v > 0,
        )
        self.source.observe(init_observer_info(observer))

        self.source.on_error(self.exc)

        self.assertEqual(self.exc, sink.exception)
Example #4
0
    def test_on_complete(self):
        sink = TObserver()
        observer = FilterObserver(
            observer=sink,
            predicate=lambda v: v > 0,
        )
        self.source.observe(init_observer_info(observer))

        self.source.on_completed()

        self.assertTrue(sink.is_completed)
Example #5
0
 def observe(self, observer_info: ObserverInfo):
     subscription = observer_info.copy(observer=FilterObserver(
         observer=observer_info.observer,
         predicate=self.predicate,
     ), )
     return self.source.observe(subscription)
Example #6
0
 def test_initialize(self):
     sink = TObserver()
     FilterObserver(
         observer=sink,
         predicate=lambda _: True,
     )