Beispiel #1
0
def test_3_2_6_3_if_rejected():
    """
    Testing return of pending promises to make
    sure they are properly chained.

    This covers the case where the root promise
    is rejected before the chaining is defined.
    """

    p1 = Promise()
    p1.reject("Error")
    pending = Promise()
    pending.fulfill(10)
    pr = p1.then(None, lambda r: pending)
    assert pending.isFulfilled()
    assert_equals(10, pending.value)
    assert pr.isFulfilled()
    assert_equals(10, pr.value)

    p2 = Promise()
    p2.reject("Error")
    bad = Promise()
    bad.reject("Assertion")
    pr = p2.then(None, lambda r: bad)
    assert bad.isRejected()
    assert_equals("Assertion", bad.reason)
    assert pr.isRejected()
    assert_equals("Assertion", pr.reason)
Beispiel #2
0
def test_3_2_6_3_when_fulfilled():
    """
    Testing return of pending promises to make
    sure they are properly chained.

    This covers the case where the root promise
    is fulfilled after the chaining is defined.
    """

    p1 = Promise()
    pending = Promise()
    pf = p1.then(lambda r: pending)
    assert pending.isPending()
    assert pf.isPending()
    p1.fulfill(10)
    pending.fulfill(5)
    assert pending.isFulfilled()
    assert_equals(5, pending.value)
    assert pf.isFulfilled()
    assert_equals(5, pf.value)

    p2 = Promise()
    bad = Promise()
    pr = p2.then(lambda r: bad)
    assert bad.isPending()
    assert pr.isPending()
    p2.fulfill(10)
    bad.reject("Error")
    assert bad.isRejected()
    assert_equals("Error", bad.reason)
    assert pr.isRejected()
    assert_equals("Error", pr.reason)