def test_deferred_exception_catch():
    def dummy_errback(deferred_exception):
        deferred_exception.catch(OSError)
        return "caught"

    deferred = Deferred()
    deferred.add_errback(dummy_errback)
    deferred.errback(OSError())
    assert deferred.result == 'caught'
def test_errback():
    holder = []
    d = Deferred()
    e = Exception('errback test')
    d.add_errback(lambda e: holder.append(e))
    d.errback(e)

    assert isinstance(holder[0], DeferredException)
    assert holder[0].value == e
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_deferred_exception_catch():
    def dummy_errback(deferred_exception):
        deferred_exception.catch(OSError)
        return "caught"

    deferred = Deferred()
    deferred.add_errback(dummy_errback)
    deferred.errback(OSError())
    assert deferred.result == 'caught'
def test_errback():
    holder = []
    d = Deferred()
    e = Exception('errback test')
    d.add_errback(lambda e: holder.append(e))
    d.errback(e)

    assert isinstance(holder[0], DeferredException)
    assert holder[0].value == e
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_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
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