本文整理汇总了Python中aplus.Promise.reject方法的典型用法代码示例。如果您正苦于以下问题:Python Promise.reject方法的具体用法?Python Promise.reject怎么用?Python Promise.reject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aplus.Promise
的用法示例。
在下文中一共展示了Promise.reject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_done_all
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import reject [as 别名]
def test_done_all():
counter = [0]
def inc(_):
counter[0] += 1
def dec(_):
counter[0] -= 1
p = Promise()
p.done_all()
p.done_all((inc, dec))
p.done_all([
(inc, dec),
(inc, dec),
{'success': inc, 'failure': dec},
])
p.fulfill(4)
assert_equals(counter[0], 4)
p = Promise()
p.done_all()
p.done_all((inc, dec))
p.done_all([
(inc, dec),
{'success': inc, 'failure': dec},
])
p.reject(Exception())
assert_equals(counter[0], 1)
示例2: test_3_2_6_3_if_fulfilled
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import reject [as 别名]
def test_3_2_6_3_if_fulfilled():
"""
Testing return of pending promises to make
sure they are properly chained.
This covers the case where the root promise
is fulfilled before the chaining is defined.
"""
p1 = Promise()
p1.fulfill(10)
pending = Promise()
pending.fulfill(5)
pf = p1.then(lambda r: pending)
assert pending.isFulfilled()
assert_equals(5, pending.value)
assert pf.isFulfilled()
assert_equals(5, pf.value)
p2 = Promise()
p2.fulfill(10)
bad = Promise()
bad.reject("Error")
pr = p2.then(lambda r: bad)
assert bad.isRejected()
assert_equals("Error", bad.reason)
assert pr.isRejected()
assert_equals("Error", pr.reason)
示例3: testNonFunction
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import reject [as 别名]
def testNonFunction(nonFunction):
def foo(k, r):
results[k] = r
p1 = Promise()
p2 = p1.then(nonFunction, lambda r: foo(str(nonFunction), r))
p1.reject(Exception("Error: " + str(nonFunction)))
示例4: test_3_2_6_3_when_fulfilled
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import reject [as 别名]
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(Exception("Error"))
assert bad.isRejected
assert_exception(bad.reason, Exception, "Error")
assert pr.isRejected
assert_exception(pr.reason, Exception, "Error")
示例5: test_then_all
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import reject [as 别名]
def test_then_all():
p = Promise()
handlers = [
((lambda x: x * x), (lambda r: 1)),
{'success': (lambda x: x + x), 'failure': (lambda r: 2)},
]
results = p.then_all() + p.then_all(((lambda x: x * x), (lambda r: 1))) + p.then_all(handlers)
p.fulfill(4)
assert_equals(results[0].value, 16)
assert_equals(results[1].value, 16)
assert_equals(results[2].value, 8)
p = Promise()
handlers = [
((lambda x: x * x), (lambda r: 1)),
{'success': (lambda x: x + x), 'failure': (lambda r: 2)},
]
results = p.then_all() + p.then_all(((lambda x: x * x), (lambda r: 1))) + p.then_all(handlers)
p.reject(Exception())
assert_equals(results[0].value, 1)
assert_equals(results[1].value, 1)
assert_equals(results[2].value, 2)
示例6: test_3_2_6_5_rejected
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import reject [as 别名]
def test_3_2_6_5_rejected():
"""
Handles the case where the arguments to then
are values, not functions or promises.
"""
p1 = Promise()
p1.reject(Exception("Error"))
p2 = p1.then(None, 5)
assert_exception(p1.reason, Exception, "Error")
assert p2.isRejected
assert_exception(p2.reason, Exception, "Error")
示例7: test_exceptions
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import reject [as 别名]
def test_exceptions():
def throws(v):
assert False
p1 = Promise()
p1.addCallback(throws)
p1.fulfill(5)
p2 = Promise()
p2.addErrback(throws)
p2.reject("Error")
示例8: test_3_2_1
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import reject [as 别名]
def test_3_2_1():
"""
Test that the arguments to 'then' are optional.
"""
p1 = Promise()
p2 = p1.then()
p3 = Promise()
p4 = p3.then()
p1.fulfill(5)
p3.reject("How dare you!")
示例9: test_3_2_6_5_rejected
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import reject [as 别名]
def test_3_2_6_5_rejected():
"""
Handles the case where the arguments to then
are values, not functions or promises.
"""
p1 = Promise()
p1.reject("Error")
p2 = p1.then(None, 5)
assert_equals("Error", p1.reason)
assert p2.isRejected()
assert_equals("Error", p2.reason)
示例10: test_3_2_2_3
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import reject [as 别名]
def test_3_2_2_3():
"""
Make sure fulfilled callback never called if promise is rejected
"""
cf = Counter()
cr = Counter()
p1 = Promise()
p2 = p1.then(lambda v: cf.tick(), lambda r: cr.tick())
p1.reject("Error")
assert_equals(0, cf.value())
assert_equals(1, cr.value())
示例11: test_exceptions
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import reject [as 别名]
def test_exceptions():
def throws(v):
assert False
p1 = Promise()
p1.addCallback(throws)
p1.fulfill(5)
p2 = Promise()
p2.addErrback(throws)
p2.reject(Exception())
assert_raises(Exception, p2.get)
示例12: test_3_2_3_1
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import reject [as 别名]
def test_3_2_3_1():
"""
The second argument to 'then' must be called when a promise is
rejected.
"""
c = Counter()
def check(r, c):
assert_equals(r, "Error")
c.tick()
p1 = Promise()
p2 = p1.then(None, lambda r: check(r, c))
p1.reject("Error")
assert_equals(1, c.value())
示例13: test_3_2_6_1
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import reject [as 别名]
def test_3_2_6_1():
"""
Promises returned by then must be fulfilled when the promise
they are chained from is fulfilled IF the fulfillment value
is not a promise.
"""
p1 = Promise()
pf = p1.then(lambda v: v*v)
p1.fulfill(5)
assert_equals(pf.value, 25)
p2 = Promise()
pr = p2.then(None, lambda r: 5)
p2.reject("Error")
assert_equals(5, pr.value)
示例14: test_3_2_3_2
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import reject [as 别名]
def test_3_2_3_2():
"""
Make sure callbacks are never called more than once.
"""
c = Counter()
p1 = Promise()
p2 = p1.then(None, lambda v: c.tick())
p1.reject("Error")
try:
# I throw an exception
p1.reject("Error")
assert False # Should not get here!
except AssertionError:
# This is expected
pass
assert_equals(1, c.value())
示例15: test_3_2_5_2_if
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import reject [as 别名]
def test_3_2_5_2_if():
"""
Then can be called multiple times on the same promise
and callbacks must be called in the order of the
then calls.
"""
def add(l, v):
l.append(v)
p1 = Promise()
p1.reject("Error")
order = []
p2 = p1.then(None, lambda v: add(order, "p2"))
p3 = p1.then(None, lambda v: add(order, "p3"))
assert_equals(2, len(order))
assert_equals("p2", order[0])
assert_equals("p3", order[1])