• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python promises.promise函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中vine.promises.promise函数的典型用法代码示例。如果您正苦于以下问题:Python promise函数的具体用法?Python promise怎么用?Python promise使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了promise函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:cloudera,项目名称:hue,代码行数:10,代码来源:test_promises.py


示例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())
开发者ID:celery,项目名称:vine,代码行数:10,代码来源:test_funtools.py


示例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())
开发者ID:adamchainz,项目名称:vine,代码行数:10,代码来源:test_promises.py


示例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())
开发者ID:cloudera,项目名称:hue,代码行数:10,代码来源:test_promises.py


示例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)
开发者ID:cloudera,项目名称:hue,代码行数:14,代码来源:test_promises.py


示例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)
开发者ID:cloudera,项目名称:hue,代码行数:15,代码来源:test_promises.py


示例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()
开发者ID:celery,项目名称:vine,代码行数:7,代码来源:test_synchronization.py


示例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())
开发者ID:adamchainz,项目名称:vine,代码行数:16,代码来源:test_synchronization.py


示例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())
开发者ID:celery,项目名称:vine,代码行数:16,代码来源:test_synchronization.py


示例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
开发者ID:celery,项目名称:vine,代码行数:8,代码来源:test_synchronization.py


示例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()
开发者ID:celery,项目名称:vine,代码行数:8,代码来源:test_promises.py


示例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
开发者ID:cloudera,项目名称:hue,代码行数:8,代码来源:test_promises.py


示例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)
开发者ID:cloudera,项目名称:hue,代码行数:18,代码来源:test_promises.py


示例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({})
开发者ID:celery,项目名称:vine,代码行数:12,代码来源:test_funtools.py


示例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)
开发者ID:cloudera,项目名称:hue,代码行数:21,代码来源:test_promises.py


示例16: test_weak_reference_bound

    def test_weak_reference_bound(self):
        class Example(object):
            def __init__(self, y):
                self.y = y

            def f(self, x):
                return self.y + x ** 2

        example = Example(5)
        promise_f = promise(example.f, weak=True)

        assert isinstance(promise_f.fun, weakref.ref)
        assert promise_f(2) == 9
开发者ID:cloudera,项目名称:hue,代码行数:13,代码来源:test_promises.py


示例17: test_throw_with_tb

    def test_throw_with_tb(self):
        p = promise()

        def foo():
            raise KeyError()

        try:
            foo()
        except KeyError:
            try:
                p.throw()
            except KeyError:
                err = traceback.format_exc()
                self.assertIn("in foo\n    raise KeyError()", err)
            else:
                raise AssertionError("Did not throw.")
开发者ID:adamchainz,项目名称:vine,代码行数:16,代码来源:test_promises.py


示例18: test_throw_with_tb

    def test_throw_with_tb(self):
        p = promise()

        def foo():
            raise KeyError()

        try:
            foo()
        except KeyError:
            try:
                p.throw()
            except KeyError:
                err = traceback.format_exc()
                assert 'in foo\n    raise KeyError()' in err
            else:
                raise AssertionError('Did not throw.')
开发者ID:cloudera,项目名称:hue,代码行数:16,代码来源:test_promises.py


示例19: test_throw_from_cb

    def test_throw_from_cb(self):
        ae = promise(Mock(name='ae'))
        a = Mock(name='a')
        be = promise(Mock(name='be'))
        b = promise(Mock(name='b'), on_error=be)
        ce = promise(Mock(name='ce'))
        c = promise(Mock(name='c'), on_error=ce)

        exc = a.side_effect = KeyError()
        p1 = promise(a, on_error=ae)
        p1.then(b)
        assert p1._svpending
        p1(42)
        p1.on_error.fun.assert_called_with(exc)

        p2 = promise(a)
        p2.then(b).then(c)
        with pytest.raises(KeyError):
            p2(42)

        de = promise(Mock(name='de'))
        d = promise(Mock(name='d'), on_error=de)
        p2.then(d)
        de.fun.assert_called_with(exc)
开发者ID:cloudera,项目名称:hue,代码行数:24,代码来源:test_promises.py


示例20: test_throw_with_other_tb

    def test_throw_with_other_tb(self):
        p = promise()

        def foo():
            raise KeyError()

        def bar():
            raise ValueError()

        try:
            bar()
        except ValueError:
            tb = sys.exc_info()[2]

        try:
            foo()
        except KeyError as exc:
            try:
                p.throw(exc, tb)
            except KeyError:
                err = traceback.format_exc()
                assert 'in bar\n    raise ValueError()' in err
            else:
                raise AssertionError('Did not throw.')
开发者ID:cloudera,项目名称:hue,代码行数:24,代码来源:test_promises.py



注:本文中的vine.promises.promise函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python vintage.transform_selection函数代码示例发布时间:2022-05-26
下一篇:
Python vine.starpromise函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap