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


Python Hub.repr_events方法代码示例

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


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

示例1: test_repr_events

# 需要导入模块: from kombu import Hub [as 别名]
# 或者: from kombu.Hub import repr_events [as 别名]
 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,代码行数:9,代码来源:test_hub.py

示例2: test_Hub

# 需要导入模块: from kombu import Hub [as 别名]
# 或者: from kombu.Hub import repr_events [as 别名]

#.........这里部分代码省略.........
        self.assertIn(2, self.hub.consolidate)
        self.assertIsNone(self.hub.writers[2])

    @patch('kombu.async.hub.logger')
    def test_on_callback_error(self, logger):
        self.hub.on_callback_error(Mock(name='callback'), KeyError())
        self.assertTrue(logger.error.called)

    def test_loop_property(self):
        self.hub._loop = None
        self.hub.create_loop = Mock(name='hub.create_loop')
        self.assertIs(self.hub.loop, self.hub.create_loop())
        self.assertIs(self.hub._loop, self.hub.create_loop())

    def test_run_forever(self):
        self.hub.run_once = Mock(name='hub.run_once')
        self.hub.run_once.side_effect = Stop()
        self.hub.run_forever()

    def test_run_once(self):
        self.hub._loop = iter([1])
        self.hub.run_once()
        self.hub.run_once()
        self.assertIsNone(self.hub._loop)

    def test_repr_active(self):
        self.hub.readers = {1: Mock(), 2: Mock()}
        self.hub.writers = {3: Mock(), 4: Mock()}
        for value in list(
                self.hub.readers.values()) + list(self.hub.writers.values()):
            value.__name__ = 'mock'
        self.assertTrue(self.hub.repr_active())

    def test_repr_events(self):
        self.hub.readers = {6: Mock(), 7: Mock(), 8: Mock()}
        self.hub.writers = {9: Mock()}
        for value in list(
                self.hub.readers.values()) + list(self.hub.writers.values()):
            value.__name__ = 'mock'
        self.assertTrue(self.hub.repr_events([
            (6, READ),
            (7, ERR),
            (8, READ | ERR),
            (9, WRITE),
            (10, 13213),
        ]))

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

        self.assertEqual(callback_for(self.hub, 6, READ), reader)
        self.assertEqual(callback_for(self.hub, 7, WRITE), writer)
        with self.assertRaises(KeyError):
            callback_for(self.hub, 6, WRITE)
        self.assertEqual(callback_for(self.hub, 6, WRITE, 'foo'), 'foo')

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

        read_A = Mock()
        read_B = Mock()
        self.hub.add_reader(10, read_A, 10)
        self.hub.add_reader(File(11), read_B, 11)
开发者ID:megwill4268,项目名称:kombu,代码行数:69,代码来源:test_hub.py

示例3: setup

# 需要导入模块: from kombu import Hub [as 别名]
# 或者: from kombu.Hub import repr_events [as 别名]

#.........这里部分代码省略.........
        assert 2 in self.hub.consolidate
        assert self.hub.writers[2] is None

    @patch('kombu.async.hub.logger')
    def test_on_callback_error(self, logger):
        self.hub.on_callback_error(Mock(name='callback'), KeyError())
        logger.error.assert_called()

    def test_loop_property(self):
        self.hub._loop = None
        self.hub.create_loop = Mock(name='hub.create_loop')
        assert self.hub.loop is self.hub.create_loop()
        assert self.hub._loop is self.hub.create_loop()

    def test_run_forever(self):
        self.hub.run_once = Mock(name='hub.run_once')
        self.hub.run_once.side_effect = Stop()
        self.hub.run_forever()

    def test_run_once(self):
        self.hub._loop = iter([1])
        self.hub.run_once()
        self.hub.run_once()
        assert self.hub._loop is None

    def test_repr_active(self):
        self.hub.readers = {1: Mock(), 2: Mock()}
        self.hub.writers = {3: Mock(), 4: Mock()}
        for value in list(
                self.hub.readers.values()) + list(self.hub.writers.values()):
            value.__name__ = 'mock'
        assert self.hub.repr_active()

    def test_repr_events(self):
        self.hub.readers = {6: Mock(), 7: Mock(), 8: Mock()}
        self.hub.writers = {9: Mock()}
        for value in list(
                self.hub.readers.values()) + list(self.hub.writers.values()):
            value.__name__ = 'mock'
        assert self.hub.repr_events([
            (6, READ),
            (7, ERR),
            (8, READ | ERR),
            (9, WRITE),
            (10, 13213),
        ])

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

        assert callback_for(self.hub, 6, READ) == reader
        assert callback_for(self.hub, 7, WRITE) == writer
        with pytest.raises(KeyError):
            callback_for(self.hub, 6, WRITE)
        assert callback_for(self.hub, 6, WRITE, 'foo') == 'foo'

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

        read_A = Mock()
        read_B = Mock()
        self.hub.add_reader(10, read_A, 10)
        self.hub.add_reader(File(11), read_B, 11)
开发者ID:Erve1879,项目名称:kombu,代码行数:69,代码来源:test_hub.py


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