def test_callback_resolution():
    d = Deferred()
    d.add_callback(lambda r: fail(Exception(r + "b")))
    d.add_errback(lambda e: e.value.args[0] + "c")
    d.add_callbacks(lambda r: r + "d", lambda e: e.value.args[0] + 'f')

    d.callback("a")

    assert d.result == "abcd"
Example #2
0
def test_callback_resolution():
    d = Deferred()
    d.add_callback(lambda r: fail(Exception(r + "b")))
    d.add_errback(lambda e: e.value.args[0] + "c")
    d.add_callbacks(lambda r: r + "d", lambda e: e.value.args[0] + 'f')

    d.callback("a")

    assert d.result == "abcd"
def test_errback_chain():
    holder = []
    d = Deferred()
    e = Exception('a')
    d.add_callbacks(holder.append, lambda e: Exception(e.value.args[0] + 'b'))
    d.add_callbacks(holder.append, lambda e: Exception(e.value.args[0] + 'c'))

    d.errback(e)

    assert d.result.value.args[0] == 'abc'
    assert len(holder) == 0
Example #4
0
def test_errback_chain():
    holder = []
    d = Deferred()
    e = Exception('a')
    d.add_callbacks(holder.append, lambda e: Exception(e.value.args[0] + 'b'))
    d.add_callbacks(holder.append, lambda e: Exception(e.value.args[0] + 'c'))

    d.errback(e)

    assert d.result.value.args[0] == 'abc'
    assert len(holder) == 0
Example #5
0
def test_callback_resolution_weaving():
    d = Deferred()
    d.add_callbacks(lambda r: fail(Exception(r + "b")),
                    lambda e: e.value.args[0] + 'w')
    d.add_callbacks(lambda e: Exception(e + "x"),
                    lambda e: e.value.args[0] + "c")
    d.add_callbacks(lambda r: Exception(r + "d"),
                    lambda e: e.value.args[0] + 'y')
    d.add_callbacks(lambda r: r + "z", lambda e: e.value.args[0] + 'e')

    d.callback("a")

    assert d.result == "abcde"
Example #6
0
def test_callback_resolution_weaving_2():
    d = Deferred()
    d.add_callbacks(lambda r: fail(Exception(r + "b")),
                    lambda e: e.value.args[0] + 'w')
    d.add_callbacks(lambda e: Exception(e + "x"),
                    lambda e: e.value.args[0] + "c")
    d.add_callbacks(lambda r: Exception(r + "d"),
                    lambda e: e.value.args[0] + 'y')
    d.add_callbacks(lambda r: fail(ValueError(r + "z")),
                    lambda e: e.value.args[0] + 'e')

    d.errback(Exception('v'))

    assert isinstance(d.result, DeferredException)
    assert isinstance(d.result.value, ValueError)
    assert d.result.value.args[0] == "vwxyz"
def test_callback_resolution_weaving():
    d = Deferred()
    d.add_callbacks(lambda r: fail(Exception(r + "b")), lambda e: e.value.args[0] + 'w')
    d.add_callbacks(lambda e: Exception(e + "x"), lambda e: e.value.args[0] + "c")
    d.add_callbacks(lambda r: Exception(r + "d"), lambda e: e.value.args[0] + 'y')
    d.add_callbacks(lambda r: r + "z", lambda e: e.value.args[0] + 'e')

    d.callback("a")

    assert d.result == "abcde"
def test_callback_resolution_weaving_2():
    d = Deferred()
    d.add_callbacks(lambda r: fail(Exception(r + "b")), lambda e: e.value.args[0] + 'w')
    d.add_callbacks(lambda e: Exception(e + "x"), lambda e: e.value.args[0] + "c")
    d.add_callbacks(lambda r: Exception(r + "d"), lambda e: e.value.args[0] + 'y')
    d.add_callbacks(lambda r: fail(ValueError(r + "z")), lambda e: e.value.args[0] + 'e')

    d.errback(Exception('v'))

    assert isinstance(d.result, DeferredException)
    assert isinstance(d.result.value, ValueError)
    assert d.result.value.args[0] == "vwxyz"
def test_callbacks_and_errbacks_return_original_deferred():
    d = Deferred()
    assert d.add_callback(lambda a: None) is d
    assert d.add_errback(lambda a: None) is d
    assert d.add_callbacks(lambda a: None, lambda a: None) is d
Example #10
0
def test_callbacks_and_errbacks_return_original_deferred():
    d = Deferred()
    assert d.add_callback(lambda a: None) is d
    assert d.add_errback(lambda a: None) is d
    assert d.add_callbacks(lambda a: None, lambda a: None) is d