Esempio n. 1
0
def test_create_on_next_throw_close2():
    ex = 'ex'
    next = [True]
    error = [False]
    completed = [False]

    def on_next(x):
        assert(42 == x)
        next[0] = True

    def on_error(e):
        assert(ex == e)
        error[0] = True

    def on_completed():
        completed[0] = True

    res = AnonymousObserver(on_next, on_error, on_completed)

    res.on_next(42)

    assert(next[0])
    assert(not error[0])
    assert(not completed[0])

    res.on_error(ex)

    assert(not completed[0])
    assert(error[0])
Esempio n. 2
0
def test_create_on_next_close_has_error():
    e_ = None
    ex = 'ex'
    next = [False]
    completed = [False]

    def on_next(x):
        assert(42 == x)
        next[0] = True

    def on_completed():
        completed[0] = True

    res = AnonymousObserver(on_next, None, on_completed)

    res.on_next(42)
    assert(next[0])
    assert(not completed[0])
    try:
        res.on_error(ex)
        assert(False)
    except Exception as e:
        e_ = e.args[0]

    assert(ex == e_)
    assert(not completed[0])
Esempio n. 3
0
def test_observer_checked_reentrant_completed():
    msg = "Re-entrancy detected"
    n = [0]

    def on_next(x):
        assert(False)

    def on_error(ex):
        assert(False)

    def on_completed():
        n[0] += 1
        try:
            o.on_next(9)
        except Exception as e:
            print(str(e))
            assert str(e) == msg

        try:
            o.on_error(Exception('error'))
        except Exception as e:
            assert str(e) == msg

        try:
            o.on_completed()
        except Exception as e:
            assert str(e) == msg

    o = AnonymousObserver(on_next, on_error, on_completed).checked()

    o.on_completed()
    assert(1 == n[0])
Esempio n. 4
0
def test_observer_checked_already_terminated_error():
    m, n = [0], [0]

    def on_next(x):
        m[0] += 1

    def on_error(x):
        n[0] += 1

    def on_completed():
        assert(False)

    o = AnonymousObserver(on_next, on_error, on_completed).checked()

    o.on_next(1)
    o.on_next(2)
    o.on_error(Exception('error'))

    try:
        o.on_completed()
    except Exception:
        pass

    try:
        o.on_error(Exception('error'))
    except Exception:
        pass

    assert(2 == m[0])
    assert(1 == n[0])
Esempio n. 5
0
def test_create_on_next():
    next = [False]

    def on_next(x):
        assert(42 == x)
        next[0] = True

    res = AnonymousObserver(on_next)

    res.on_next(42)
    assert(next[0])
    return res.on_completed()
Esempio n. 6
0
def test_create_on_next_has_error():
    ex = 'ex'
    next = [False]
    _e = None

    def on_next(x):
        assert(42 == x)
        next[0] = True

    res = AnonymousObserver(on_next)

    res.on_next(42)
    assert(next[0])

    try:
        res.on_error(ex)
        assert(False)
    except Exception as e:
        e_ = e.args[0]

    assert(ex == e_)
Esempio n. 7
0
def test_create_on_next_on_error():
    ex = 'ex'
    next = [True]
    error = [False]

    def on_next(x):
        assert(42 == x)
        next[0] = True

    def on_error(e):
        assert(ex == e)
        error[0] = True

    res = AnonymousObserver(on_next, on_error)

    res.on_next(42)

    assert(next[0])
    assert(not error[0])

    res.on_error(ex)
    assert(error[0])
Esempio n. 8
0
def test_create_on_next_on_completed():
    next = [False]
    completed = [False]

    def on_next(x):
        assert(42 == x)
        next[0] = True
        return next[0]

    def on_completed():
        completed[0] = True
        return completed[0]

    res = AnonymousObserver(on_next, None, on_completed)

    res.on_next(42)

    assert(next[0])
    assert(not completed[0])

    res.on_completed()

    assert(completed[0])