Exemple #1
0
def test_on_completed_equality():
    n1 = OnCompleted()
    n2 = OnCompleted()
    n3 = OnNext(2)
    assert(n1.equals(n1))
    assert(n1.equals(n2))
    assert(n2.equals(n1))
    assert(not n1.equals(None))
    assert(not n1.equals(n3))
    assert(not n3.equals(n1))
def test_close_equality():
    n1 = OnCompleted()
    n2 = OnCompleted()
    n3 = OnNext(2)
    assert n1.equals(n1)
    assert n1.equals(n2)
    assert n2.equals(n1)
    assert not n1.equals(None)
    assert not n1.equals(n3)
    assert not n3.equals(n1)
Exemple #3
0
def test_on_completed_equality():
    n1 = OnCompleted()
    n2 = OnCompleted()
    n3 = OnNext(2)
    assert (n1.equals(n1))
    assert (n1.equals(n2))
    assert (n2.equals(n1))
    assert (not n1.equals(None))
    assert (not n1.equals(n3))
    assert (not n3.equals(n1))
def test_on_next_accept_observer_with_result():
    n1 = OnNext(42)

    def on_next(x):
        return "OK"
    def on_error(err):
        assert False
    def on_completed():
        assert False

    res = n1.accept(AcceptObserver(on_next, on_error, on_completed))
    assert 'OK' == res
Exemple #5
0
def test_on_next_accept_observer_with_result():
    n1 = OnNext(42)

    def on_next(x):
        return "OK"
    def on_error(err):
        assert(False)
    def on_completed():
        assert(False)

    res = n1.accept(AcceptObserver(on_next, on_error, on_completed))
    assert('OK' == res)
Exemple #6
0
def test_on_next_accept_action():
    obs = [False]
    n1 = OnNext(42)
    def on_next(x):
        obs[0] = True
        return obs[0]
    def on_error(err):
        assert(False)
    def on_completed():
        assert(False)
    n1.accept(on_next, on_error, on_completed)

    assert(obs[0])
def test_on_next_accept_action():
    obs = [False]
    n1 = OnNext(42)
    def on_next(x):
        obs[0] = True
        return obs[0]
    def on_error(err):
        assert False
    def on_completed():
        assert False
    n1.accept(on_next, on_error, on_completed)

    assert obs[0]
Exemple #8
0
def test_on_next_accept_action_with_result():
    n1 = OnNext(42)

    def on_next(x):
        return "OK"

    def on_error(err):
        assert (False)

    def on_completed():
        assert (False)

    res = n1.accept(on_next, on_error, on_completed)
    assert ('OK' == res)
def notification(obj):
    if obj['what'] == 'on_next':
        return OnNext(obj['item'])
    elif obj['what'] == 'on_completed':
        return OnCompleted()
    elif obj['what'] == 'on_error':
        return OnError(obj['error'])
Exemple #10
0
def test_on_next_equality():
    n1 = OnNext(42)
    n2 = OnNext(42)
    n3 = OnNext(24)
    n4 = OnCompleted()
    assert(n1.equals(n1))
    assert(n1.equals(n2))
    assert(n2.equals(n1))
    assert(not n1.equals(None))
    assert(not n1.equals(n3))
    assert(not n3.equals(n1))
    assert(not n1.equals(n4))
    assert(not n4.equals(n1))
Exemple #11
0
 def on_next(self, value):
     if self.requested_count <= 0:
         self.enable_queue and self.queue.append(OnNext(value))
     else:
         self.requested_count -= 1
         if self.requested_count == 0:
             self.dispose_current_request()
         self.subject.on_next(value)
Exemple #12
0
    def handle_on_next(value):
        try:
            value = int(value)
        except Exception:
            pass

        if value in ('T', 'F'):
            value = value == 'T'
        messages.append((OnNext(value), timedelta[0]))
Exemple #13
0
def test_to_notifier_forwards():
    obsn = MyObserver()
    obsn.to_notifier()(OnNext(42))
    assert (obsn.has_on_next == 42)

    ex = 'ex'
    obse = MyObserver()
    obse.to_notifier()(OnError(ex))
    assert (ex == obse.has_on_error)

    obsc = MyObserver()
    obsc.to_notifier()(OnCompleted())
    assert (obsc.has_on_completed)
Exemple #14
0
    def on_next(self, value):

        with self.lock:
            # concurrent situation with acknowledgment in inner subscription or new subscriptions

            # empty inactive subscriptions; they are added to the list once they reach the top of the buffer again
            inactive_subsriptions = self.inactive_subsriptions
            self.inactive_subsriptions = []

            # add item to buffer
            self.buffer.append(OnNext(value))

            # current ack is used by subscriptions that weren't inactive, but reached the top of the buffer
            current_ack = Ack()
            self.current_ack = current_ack

            is_done = self.is_done

        if is_done:
            return stop_ack

        def gen_inner_ack():
            # send notification to inactive subscriptions
            for inner_subscription in inactive_subsriptions:
                inner_ack = inner_subscription.notify_on_next(value)
                yield inner_ack

        inner_ack_list = list(gen_inner_ack())

        continue_ack = [
            ack for ack in inner_ack_list if isinstance(ack, Continue)
        ]

        if 0 < len(continue_ack):
            # return any Continue ack
            return continue_ack[0]
        else:
            # return merged acknowledgments from inner subscriptions

            ack_list = [current_ack] + inner_ack_list

            upper_ack = Ack()
            rx.Observable.merge(*ack_list).first().subscribe(upper_ack)
            return upper_ack
Exemple #15
0
    def on_next(ticks: int, value: Any) -> Recorded:
        if isinstance(value, types.FunctionType):
            return Recorded(ticks, OnNextPredicate(value))

        return Recorded(ticks, OnNext(value))
def test_on_next_equality():
    n1 = OnNext(42)
    n2 = OnNext(42)
    n3 = OnNext(24)
    n4 = OnCompleted()
    assert n1.equals(n1)
    assert n1.equals(n2)
    assert n2.equals(n1)
    assert not n1.equals(None)
    assert not n1.equals(n3)
    assert not n3.equals(n1)
    assert not n1.equals(n4)
    assert not n4.equals(n1)
 def on_next(value) -> None:
     self.messages.append(Recorded(scheduler.clock, OnNext(value)))
Exemple #18
0
 def on_next(self, value):
     self.messages.append(Recorded(self.scheduler.clock, OnNext(value)))
Exemple #19
0
import rx
import rx.operators as ops
from rx.core.notification import OnNext, OnCompleted

numbers = rx.from_([OnNext(1), OnNext(2), OnNext(3), OnNext(4), OnCompleted()])

numbers.pipe(ops.dematerialize()).subscribe(
    on_next=lambda i: print("on_next {}".format(i)),
    on_error=lambda e: print("on_error: {}".format(e)),
    on_completed=lambda: print("on_completed"))
Exemple #20
0
    def on_next(cls, ticks, value):
        if isinstance(value, types.FunctionType):
            return Recorded(ticks, OnNextPredicate(value))

        return Recorded(ticks, OnNext(value))
Exemple #21
0
def test_on_next_accept_observer():
    con = CheckOnNextObserver()
    n1 = OnNext(42)
    n1.accept(con)
    assert(42 == con.value)
Exemple #22
0
from rx import Observable
from rx.core.notification import OnNext, OnCompleted

numbers = Observable.from_(
    [OnNext(1), OnNext(2),
     OnNext(3), OnNext(4),
     OnCompleted()])

numbers.dematerialize().subscribe(
    on_next=lambda i: print("on_next {}".format(i)),
    on_error=lambda e: print("on_error: {}".format(e)),
    on_completed=lambda: print("on_completed"))
Exemple #23
0
 def on_next(value):
     observer.on_next(OnNext(value))
def test_on_next_accept_observer():
    con = CheckOnNextObserver()
    n1 = OnNext(42)
    n1.accept(con)
    assert con.value == 42
def test_on_next_tostring():
    n1 = OnNext(42)
    assert "OnNext" in str(n1)
    assert "42" in str(n1)
 def create():
     return OnNext(42).to_observable(scheduler)
def test_on_next_ctor_and_props():
    n = OnNext(42)
    assert 'N' == n.kind
    assert n.has_value
    assert 42 == n.value
    assert not hasattr(n, "exception")