当前位置: 首页>>代码示例>>Python>>正文


Python kombu.Hub类代码示例

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


在下文中一共展示了Hub类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_enter__exit

    def test_enter__exit(self):
        hub = Hub()
        P = hub.poller = Mock()
        hub.init = Mock()

        on_close = Mock()
        hub.on_close.append(on_close)

        hub.init()
        try:
            hub.init.assert_called_with()

            read_A = Mock()
            read_B = Mock()
            hub.update_readers({10: read_A, File(11): read_B})
            write_A = Mock()
            write_B = Mock()
            hub.update_writers({20: write_A, File(21): write_B})
            self.assertTrue(hub.readers)
            self.assertTrue(hub.writers)
        finally:
            hub.close()
        self.assertFalse(hub.readers)
        self.assertFalse(hub.writers)

        P.unregister.assert_has_calls([
            call(10), call(11), call(20), call(21),
        ], any_order=True)

        on_close.assert_called_with(hub)
开发者ID:jamesdear,项目名称:celery,代码行数:30,代码来源:test_hub.py

示例2: test_repr_active

 def test_repr_active(self):
     hub = Hub()
     hub.readers = {1: Mock(), 2: Mock()}
     hub.writers = {3: Mock(), 4: Mock()}
     for value in list(hub.readers.values()) + list(hub.writers.values()):
         value.__name__ = "mock"
     self.assertTrue(hub.repr_active())
开发者ID:NotSqrt,项目名称:celery,代码行数:7,代码来源:test_hub.py

示例3: test_repr_events

 def test_repr_events(self):
     hub = Hub()
     hub.readers = {6: Mock(), 7: Mock(), 8: Mock()}
     hub.writers = {9: Mock()}
     for value in list(hub.readers.values()) + list(hub.writers.values()):
         value.__name__ = "mock"
     self.assertTrue(hub.repr_events([(6, READ), (7, ERR), (8, READ | ERR), (9, WRITE), (10, 13213)]))
开发者ID:NotSqrt,项目名称:celery,代码行数:7,代码来源:test_hub.py

示例4: test_add_raises_ValueError

 def test_add_raises_ValueError(self):
     hub = Hub()
     hub._add = Mock()
     hub._add.side_effect = ValueError()
     hub._discard = Mock()
     hub.add([2], Mock(), READ)
     hub._discard.assert_called_with(2)
开发者ID:jamesdear,项目名称:celery,代码行数:7,代码来源:test_hub.py

示例5: test_add_raises_ValueError

 def test_add_raises_ValueError(self):
     hub = Hub()
     hub.poller = Mock(name='hub.poller')
     hub.poller.register.side_effect = ValueError()
     hub._discard = Mock(name='hub.discard')
     hub.add(2, Mock(), READ)
     hub._discard.assert_called_with(2)
开发者ID:AnSavvides,项目名称:celery,代码行数:7,代码来源:test_hub.py

示例6: test_start_stop

    def test_start_stop(self, poll):
        hub = Hub()
        hub.start()
        poll.assert_called_with()

        hub.stop()
        hub.poller.close.assert_called_with()
开发者ID:jamesdear,项目名称:celery,代码行数:7,代码来源:test_hub.py

示例7: test_init

    def test_init(self):
        hub = Hub()
        cb1 = Mock()
        cb2 = Mock()
        hub.on_init.extend([cb1, cb2])

        hub.init()
        cb1.assert_called_with(hub)
        cb2.assert_called_with(hub)
开发者ID:jamesdear,项目名称:celery,代码行数:9,代码来源:test_hub.py

示例8: test_callback_for

    def test_callback_for(self):
        hub = Hub()
        reader, writer = Mock(), Mock()
        hub.readers = {6: reader}
        hub.writers = {7: writer}

        self.assertEqual(callback_for(hub, 6, READ), reader)
        self.assertEqual(callback_for(hub, 7, WRITE), writer)
        with self.assertRaises(KeyError):
            callback_for(hub, 6, WRITE)
        self.assertEqual(callback_for(hub, 6, WRITE, 'foo'), 'foo')
开发者ID:EvaSDK,项目名称:celery,代码行数:11,代码来源:test_hub.py

示例9: test_start_stop

    def test_start_stop(self, poll):
        self.hub = Hub()
        poll.assert_called_with()

        poller = self.hub.poller
        self.hub.stop()
        self.hub.close()
        poller.close.assert_called_with()
开发者ID:megwill4268,项目名称:kombu,代码行数:8,代码来源:test_hub.py

示例10: test_fire_timers_raises

    def test_fire_timers_raises(self):
        hub = Hub()
        eback = Mock()
        eback.side_effect = KeyError("foo")
        hub.timer = Mock()
        hub.scheduler = iter([(0, eback)])
        with self.assertRaises(KeyError):
            hub.fire_timers(propagate=(KeyError,))

        eback.side_effect = ValueError("foo")
        hub.scheduler = iter([(0, eback)])
        with patch("kombu.async.hub.logger") as logger:
            with self.assertRaises(StopIteration):
                hub.fire_timers()
            self.assertTrue(logger.error.called)
开发者ID:NotSqrt,项目名称:celery,代码行数:15,代码来源:test_hub.py

示例11: test_add_writers

    def test_add_writers(self):
        hub = Hub()
        P = hub.poller = Mock()

        write_A = Mock()
        write_B = Mock()
        hub.add_writer(20, write_A)
        hub.add_writer(File(21), write_B)

        P.register.assert_has_calls([call(20, hub.WRITE), call(File(21), hub.WRITE)], any_order=True)

        self.assertEqual(hub.writers[20], (write_A, ()))
        self.assertEqual(hub.writers[21], (write_B, ()))

        hub.remove(20)
        self.assertNotIn(20, hub.writers)
        hub.remove(File(21))
        self.assertNotIn(21, hub.writers)
        P.unregister.assert_has_calls([call(20), call(21)])
开发者ID:NotSqrt,项目名称:celery,代码行数:19,代码来源:test_hub.py

示例12: test_add_remove_readers

    def test_add_remove_readers(self):
        hub = Hub()
        P = hub.poller = Mock()

        read_A = Mock()
        read_B = Mock()
        hub.add_reader(10, read_A, 10)
        hub.add_reader(File(11), read_B, 11)

        P.register.assert_has_calls([call(10, hub.READ | hub.ERR), call(File(11), hub.READ | hub.ERR)], any_order=True)

        self.assertEqual(hub.readers[10], (read_A, (10,)))
        self.assertEqual(hub.readers[11], (read_B, (11,)))

        hub.remove(10)
        self.assertNotIn(10, hub.readers)
        hub.remove(File(11))
        self.assertNotIn(11, hub.readers)
        P.unregister.assert_has_calls([call(10), call(11)])
开发者ID:NotSqrt,项目名称:celery,代码行数:19,代码来源:test_hub.py

示例13: test_fire_timers

    def test_fire_timers(self):
        hub = Hub()
        hub.timer = Mock()
        hub.timer._queue = []
        self.assertEqual(hub.fire_timers(min_delay=42.324,
                                         max_delay=32.321), 32.321)

        hub.timer._queue = [1]
        hub.scheduler = iter([(3.743, None)])
        self.assertEqual(hub.fire_timers(), 3.743)

        e1, e2, e3 = Mock(), Mock(), Mock()
        entries = [e1, e2, e3]

        def reset():
            return [m.reset() for m in [e1, e2, e3]]

        def se():
            while 1:
                while entries:
                    yield None, entries.pop()
                yield 3.982, None
        hub.scheduler = se()

        self.assertEqual(hub.fire_timers(max_timers=10), 3.982)
        for E in [e3, e2, e1]:
            E.assert_called_with()
        reset()

        entries[:] = [Mock() for _ in range(11)]
        keep = list(entries)
        self.assertEqual(hub.fire_timers(max_timers=10, min_delay=1.13), 1.13)
        for E in reversed(keep[1:]):
            E.assert_called_with()
        reset()
        self.assertEqual(hub.fire_timers(max_timers=10), 3.982)
        keep[0].assert_called_with()
开发者ID:1995rishi,项目名称:flaskmap,代码行数:37,代码来源:test_hub.py

示例14: test_update_readers

    def test_update_readers(self):
        hub = Hub()
        P = hub.poller = Mock()

        read_A = Mock()
        read_B = Mock()
        hub.update_readers({10: read_A, File(11): read_B})

        P.register.assert_has_calls([
            call(10, hub.READ | hub.ERR),
            call(File(11), hub.READ | hub.ERR),
        ], any_order=True)

        self.assertIs(hub.readers[10], read_A)
        self.assertIs(hub.readers[11], read_B)

        hub.remove(10)
        self.assertNotIn(10, hub.readers)
        hub.remove(File(11))
        self.assertNotIn(11, hub.readers)
        P.unregister.assert_has_calls([
            call(10), call(11),
        ])
开发者ID:jamesdear,项目名称:celery,代码行数:23,代码来源:test_hub.py

示例15: test_update_writers

    def test_update_writers(self):
        hub = Hub()
        P = hub.poller = Mock()

        write_A = Mock()
        write_B = Mock()
        hub.update_writers({20: write_A, File(21): write_B})

        P.register.assert_has_calls([
            call(20, hub.WRITE),
            call(File(21), hub.WRITE),
        ], any_order=True)

        self.assertIs(hub.writers[20], write_A)
        self.assertIs(hub.writers[21], write_B)

        hub.remove(20)
        self.assertNotIn(20, hub.writers)
        hub.remove(File(21))
        self.assertNotIn(21, hub.writers)
        P.unregister.assert_has_calls([
            call(20), call(21),
        ])
开发者ID:jamesdear,项目名称:celery,代码行数:23,代码来源:test_hub.py


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