Beispiel #1
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))
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)
Beispiel #3
0
def test_on_completed_accept_action_with_result():
    n1 = OnCompleted()

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

    res = n1.accept(on_next, on_error, on_completed)
    assert('OK' == res)
def test_close_accept_observer_with_result():
    n1 = OnCompleted()

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

    res = n1.accept(AcceptObserver(on_next, on_error, on_completed))
    assert('OK' == res)
def test_close_accept_action_with_result():
    n1 = OnCompleted()

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

    res = n1.accept(on_next, on_error, on_completed)
    assert 'OK' == res
def test_close_accept_observer_with_result():
    n1 = OnCompleted()

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

    res = n1.accept(AcceptObserver(on_next, on_error, on_completed))
    assert 'OK' == res
Beispiel #7
0
def test_on_error_equality():
    ex1 = 'ex1'
    ex2 = 'ex2'
    n1 = OnError(ex1)
    n2 = OnError(ex1)
    n3 = OnError(ex2)
    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))
Beispiel #8
0
def test_on_error_equality():
    ex1 = 'ex1'
    ex2 = 'ex2'
    n1 = OnError(ex1)
    n2 = OnError(ex1)
    n3 = OnError(ex2)
    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 test_throw_equality():
    ex1 = 'ex1'
    ex2 = 'ex2'
    n1 = OnError(ex1)
    n2 = OnError(ex1)
    n3 = OnError(ex2)
    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 test_close_accept_action():
    obs = [False]
    n1 = OnCompleted()

    def on_next(x):
        assert False
        return None
    def on_error(ex):
        assert False
        return None
    def on_completed():
        obs[0] = True
        return obs[0]

    n1.accept(on_next, on_error, on_completed)
    assert obs[0]
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'])
Beispiel #12
0
def test_on_completed_accept_action():
    obs = [False]
    n1 = OnCompleted()

    def on_next(x):
        assert(False)
        return None
    def on_error(ex):
        assert(False)
        return None
    def on_completed():
        obs[0] = True
        return obs[0]

    n1.accept(on_next, on_error, on_completed)
    assert(obs[0])
Beispiel #13
0
    def on_completed(self):
        self.has_completed = True

        if not self.enable_queue or len(self.queue) == 0:
            self.subject.on_completed()
            self.dispose_current_request()
        else:
            self.queue.append(OnCompleted())
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)
Beispiel #15
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))
Beispiel #16
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)
Beispiel #17
0
    def on_completed(self):
        with self.lock:
            # concurrent situation with acknowledgment in inner subscription or new subscriptions

            # inner subscriptions that return Continue or Stop need to be added to inactive subscriptions again
            inactive_subsriptions = self.inactive_subsriptions
            self.inactive_subsriptions = []

            # add item to buffer
            self.buffer.append(OnCompleted())

        # send notification to inactive subscriptions
        for inner_subscription in inactive_subsriptions:
            inner_subscription.notify_on_completed()
Beispiel #18
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))
Beispiel #19
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"))
 def create():
     return OnCompleted().to_observable(scheduler)
Beispiel #21
0
def test_on_completed_tostring():
    n1 = OnCompleted()
    assert ('OnCompleted' in str(n1))
Beispiel #22
0
 def on_completed(ticks: int) -> Recorded:
     return Recorded(ticks, OnCompleted())
def test_close_ctor_and_props():
    n = OnCompleted()
    assert 'C' == n.kind
    assert not n.has_value
    assert not hasattr(n, "exception")
Beispiel #24
0
 def handle_on_completed(value):
     messages.append((OnCompleted(), timedelta[0]))
     completed[0] = True
Beispiel #25
0
 def on_completed(self):
     self.messages.append(Recorded(self.scheduler.clock, OnCompleted()))
Beispiel #26
0
 def on_completed():
     observer.on_next(OnCompleted())
     observer.on_completed()
Beispiel #27
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"))
Beispiel #28
0
def test_on_completed_ctor_and_props():
    n = OnCompleted()
    assert ('C' == n.kind)
    assert (not n.has_value)
    assert (not hasattr(n, "exception"))
 def on_completed() -> None:
     self.messages.append(Recorded(scheduler.clock, OnCompleted()))
     self.completed.set()
def test_close_tostring():
    n1 = OnCompleted()
    assert 'OnCompleted' in str(n1)
Beispiel #31
0
 def on_completed(ticks):
     return Recorded(ticks, OnCompleted())
def test_close_accept_observer():
    obs = CheckOnCompletedObserver()
    n1 = OnCompleted()
    n1.accept(obs)
    assert obs.completed
Beispiel #33
0
def from_marbles(string: str, timespan=0.1) -> Observable:
    """Convert a marble diagram string to an observable sequence, using
    an optional scheduler to enumerate the events.

    Special characters:
        - = Timespan of timespan seconds
        x = on_error()
        | = on_completed()

    All other characters are treated as an on_next() event at the given
    moment they are found on the string.

    Examples:
        >>> res = rx.from_marbles("1-2-3-|")
        >>> res = rx.from_marbles("1-(42)-3-|")
        >>> res = rx.from_marbles("1-2-3-x", timeout_scheduler)

    Args:
        string: String with marble diagram
        scheduler: [Optional] Scheduler to run the the input sequence
            on.

    Returns:
        The observable sequence whose elements are pulled from the
        given marble diagram string.
    """

    disp = CompositeDisposable()
    completed = [False]
    messages = []
    timedelta = [0]

    def handle_timespan(value):
        timedelta[0] += timespan

    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]))

    def handle_on_completed(value):
        messages.append((OnCompleted(), timedelta[0]))
        completed[0] = True

    def handle_on_error(value):
        messages.append((OnError(value), timedelta[0]))
        completed[0] = True

    specials = {
        '-': handle_timespan,
        'x': handle_on_error,
        'X': handle_on_error,
        '|': handle_on_completed
    }

    for groups in _tokens.findall(string):
        for token in groups:
            if token:
                func = specials.get(token, handle_on_next)
                func(token)

    if not completed[0]:
        messages.append((OnCompleted(), timedelta[0]))

    def schedule_msg(message, observer, scheduler):
        notification, timespan = message

        def action(scheduler, state=None):
            notification.accept(observer)

        disp.add(scheduler.schedule_relative(timespan, action))

    def subscribe(observer, scheduler):
        scheduler = scheduler or new_thread_scheduler

        for message in messages:
            # Don't make closures within a loop
            schedule_msg(message, observer, scheduler)
        return disp

    return Observable(subscribe)
Beispiel #34
0
def test_on_completed_accept_observer():
    obs = CheckOnCompletedObserver()
    n1 = OnCompleted()
    n1.accept(obs)
    assert(obs.completed)