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
示例#3
0
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'
示例#4
0
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_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
示例#6
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
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"
示例#8
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"
示例#9
0
def test_deferred_list_fails():
    d1 = Deferred()
    d2 = Deferred()
    d3 = Deferred()

    dl = DeferredList([1, succeed(2), d1, d2, d3])

    assert not dl.called

    e1 = Exception('d1 failed')
    d1.errback(e1)
    d2.errback(Exception('d2 failed'))
    d3.callback('hello')

    assert dl.called
    assert isinstance(dl.result, DeferredException)
    assert dl.result.value == e1
def test_deferred_list_fails():
    d1 = Deferred()
    d2 = Deferred()
    d3 = Deferred()

    dl = DeferredList([
        1,
        succeed(2),
        d1,
        d2,
        d3
    ])

    assert not dl.called

    e1 = Exception('d1 failed')
    d1.errback(e1)
    d2.errback(Exception('d2 failed'))
    d3.callback('hello')

    assert dl.called
    assert isinstance(dl.result, DeferredException)
    assert dl.result.value == e1
def test_cant_errback_twice():
    d1 = Deferred()
    d1.errback(Exception('hello'))

    with raises(AlreadyCalledDeferred):
        d1.errback(Exception('world'))
示例#12
0
def test_cant_errback_twice():
    d1 = Deferred()
    d1.errback(Exception('hello'))

    with raises(AlreadyCalledDeferred):
        d1.errback(Exception('world'))