コード例 #1
0
def test_list_promise_if():
    p1 = Promise()
    p1.fulfill(5)
    p2 = Promise()
    p2.fulfill(10)
    pl = listPromise(p1, p2)
    assert p1.isFulfilled()
    assert p2.isFulfilled()
    assert pl.isFulfilled()
    assert_equals(5, p1.value)
    assert_equals(10, p2.value)
    assert_equals(5, pl.value[0])
    assert_equals(10, pl.value[1])
コード例 #2
0
ファイル: TestSuite.py プロジェクト: alin-luminoso/aplus
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)
コード例 #3
0
ファイル: TestSuite.py プロジェクト: alin-luminoso/aplus
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)
コード例 #4
0
def test_dict_promise_if():
    p1 = Promise()
    p2 = Promise()
    d = {"a": p1, "b": p2}
    pd = dictPromise(d)
    assert p1.isPending()
    assert p2.isPending()
    assert pd.isPending()
    p1.fulfill(5)
    assert p1.isFulfilled()
    assert p2.isPending()
    assert pd.isPending()
    p2.fulfill(10)
    assert p1.isFulfilled()
    assert p2.isFulfilled()
    assert pd.isFulfilled()
    assert_equals(5, p1.value)
    assert_equals(10, p2.value)
    assert_equals(5, pd.value["a"])
    assert_equals(10, pd.value["b"])
コード例 #5
0
def test_get_if():
    p1 = Promise()
    p1.fulfill(5)
    v = p1.get()
    assert p1.isFulfilled()
    assert_equals(5, v)
コード例 #6
0
def test_wait_if():
    p1 = Promise()
    p1.fulfill(5)
    p1.wait()
    assert p1.isFulfilled()