本文整理汇总了Python中vine.promises.promise函数的典型用法代码示例。如果您正苦于以下问题:Python promise函数的具体用法?Python promise怎么用?Python promise使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了promise函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_svpending_raises
def test_svpending_raises(self):
p = promise()
a_on_error = promise(Mock(name='a_on_error'))
a = promise(Mock(name='a'), on_error=a_on_error)
p.then(a)
exc = KeyError()
a.fun.side_effect = exc
p(42)
a_on_error.fun.assert_called_with(exc)
示例2: test_wrap
def test_wrap():
cb1 = Mock()
cb2 = Mock()
x = wrap(promise(cb1))
x(1, y=2)
cb1.assert_called_with(1, y=2)
p2 = promise(cb2)
x(p2)
p2()
cb1.assert_called_with(cb2())
示例3: test_cancel_sv
def test_cancel_sv(self):
p = promise()
a = promise(Mock(name='a'))
p.then(a)
p.cancel()
self.assertTrue(p.cancelled)
self.assertTrue(a.cancelled)
p.throw(KeyError())
p.throw1(KeyError())
示例4: test_cancel_sv
def test_cancel_sv(self):
p = promise()
a = promise(Mock(name='a'))
p.then(a)
p.cancel()
assert p.cancelled
assert a.cancelled
p.throw(KeyError())
p.throw1(KeyError())
示例5: test_shallow_filter
def test_shallow_filter(self):
a, b = promise(Mock(name='a')), promise(Mock(name='b'))
p = promise(a, callback=b)
assert p._svpending is not None
assert p._lvpending is None
p(30)
assert p._svpending is None
a.fun.assert_called_with(30)
b.fun.assert_called_with(a.fun.return_value)
c, d = Mock(name='c'), Mock(name='d')
promise(c, callback=d)(1)
c.assert_called_with(1)
d.assert_called_with(c.return_value)
示例6: test_chained_filter
def test_chained_filter(self):
a = promise(Mock(name='a'))
b = promise(Mock(name='b'))
c = promise(Mock(name='c'))
d = promise(Mock(name='d'))
p = promise(a)
p.then(b).then(c).then(d)
p(42, kw=300)
a.fun.assert_called_with(42, kw=300)
b.fun.assert_called_with(a.fun.return_value)
c.fun.assert_called_with(b.fun.return_value)
d.fun.assert_called_with(c.fun.return_value)
示例7: test_reverse
def test_reverse(self):
callback = Mock()
x = barrier(self.ps, callback=promise(callback))
for p in self.ps:
p()
assert x.ready
callback.assert_called_with()
示例8: test_evaluate
def test_evaluate(self):
x = barrier(self.ps)
x()
self.assertFalse(x.ready)
x()
self.assertFalse(x.ready)
x.add(promise())
x()
self.assertFalse(x.ready)
x()
self.assertTrue(x.ready)
x()
x()
with self.assertRaises(ValueError):
x.add(promise())
示例9: test_evaluate
def test_evaluate(self):
x = barrier(self.ps)
x()
assert not x.ready
x()
assert not x.ready
x.add(promise())
x()
assert not x.ready
x()
assert x.ready
x()
x()
with pytest.raises(ValueError):
x.add(promise())
示例10: test_cancel
def test_cancel(self):
x = barrier(self.ps)
x.cancel()
for p in self.ps:
p()
x.add(promise())
x.throw(KeyError())
assert not x.ready
示例11: test_call_ignore_result
def test_call_ignore_result(self):
fun = Mock(name='fun')
callback = Mock(name='callback')
a = promise(fun=fun, ignore_result=True)
a.then(callback)
a()
fun.assert_called_once_with()
callback.assert_called_once_with()
示例12: test_weak_reference_unbound
def test_weak_reference_unbound(self):
def f(x):
return x ** 2
promise_f = promise(f, weak=True)
assert isinstance(promise_f.fun, weakref.ref)
assert promise_f(2) == 4
示例13: test_lvpending_raises
def test_lvpending_raises(self):
p = promise()
a_on_error = promise(Mock(name='a_on_error'))
a = promise(Mock(name='a'), on_error=a_on_error)
b_on_error = promise(Mock(name='b_on_error'))
b = promise(Mock(name='a'), on_error=b_on_error)
p.then(a)
p.then(b)
exc = KeyError()
a.fun.side_effect = exc
a.then(Mock(name='foobar'))
a.then(Mock(name='foozi'))
p.on_error = a_on_error
p(42)
a_on_error.fun.assert_called_with(exc)
b.fun.assert_called_with(42)
示例14: test_transform
def test_transform():
callback = Mock()
def filter_key_value(key, filter_, mapping):
return filter_(mapping[key])
x = transform(filter_key_value, promise(callback), 'Value', int)
x({'Value': 303})
callback.assert_called_with(303)
with pytest.raises(KeyError):
x({})
示例15: test_deep_filter
def test_deep_filter(self):
a = promise(Mock(name='a'))
b1, b2, b3 = (
promise(Mock(name='a1')),
promise(Mock(name='a2')),
promise(Mock(name='a3')),
)
p = promise(a)
p.then(b1)
assert p._lvpending is None
assert p._svpending is not None
p.then(b2)
assert p._lvpending is not None
assert p._svpending is None
p.then(b3)
p(42)
a.fun.assert_called_with(42)
b1.fun.assert_called_with(a.fun.return_value)
b2.fun.assert_called_with(a.fun.return_value)
b3.fun.assert_called_with(a.fun.return_value)