本文整理汇总了Python中kombu.Hub.add方法的典型用法代码示例。如果您正苦于以下问题:Python Hub.add方法的具体用法?Python Hub.add怎么用?Python Hub.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kombu.Hub
的用法示例。
在下文中一共展示了Hub.add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_raises_ValueError
# 需要导入模块: from kombu import Hub [as 别名]
# 或者: from kombu.Hub import add [as 别名]
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)
示例2: test_add_raises_ValueError
# 需要导入模块: from kombu import Hub [as 别名]
# 或者: from kombu.Hub import add [as 别名]
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)
示例3: test_Hub
# 需要导入模块: from kombu import Hub [as 别名]
# 或者: from kombu.Hub import add [as 别名]
#.........这里部分代码省略.........
eback = Mock()
eback.side_effect = KeyError('foo')
self.hub.timer = Mock()
self.hub.scheduler = iter([(0, eback)])
with self.assertRaises(KeyError):
self.hub.fire_timers(propagate=(KeyError,))
eback.side_effect = ValueError('foo')
self.hub.scheduler = iter([(0, eback)])
with patch('kombu.async.hub.logger') as logger:
with self.assertRaises(StopIteration):
self.hub.fire_timers()
self.assertTrue(logger.error.called)
eback.side_effect = MemoryError('foo')
self.hub.scheduler = iter([(0, eback)])
with self.assertRaises(MemoryError):
self.hub.fire_timers()
eback.side_effect = OSError()
eback.side_effect.errno = errno.ENOMEM
self.hub.scheduler = iter([(0, eback)])
with self.assertRaises(OSError):
self.hub.fire_timers()
eback.side_effect = OSError()
eback.side_effect.errno = errno.ENOENT
self.hub.scheduler = iter([(0, eback)])
with patch('kombu.async.hub.logger') as logger:
with self.assertRaises(StopIteration):
self.hub.fire_timers()
self.assertTrue(logger.error.called)
def test_add_raises_ValueError(self):
self.hub.poller = Mock(name='hub.poller')
self.hub.poller.register.side_effect = ValueError()
self.hub._discard = Mock(name='hub.discard')
with self.assertRaises(ValueError):
self.hub.add(2, Mock(), READ)
self.hub._discard.assert_called_with(2)
def test_remove_reader(self):
self.hub.poller = Mock(name='hub.poller')
self.hub.add(2, Mock(), READ)
self.hub.add(2, Mock(), WRITE)
self.hub.remove_reader(2)
self.assertNotIn(2, self.hub.readers)
self.assertIn(2, self.hub.writers)
def test_remove_writer(self):
self.hub.poller = Mock(name='hub.poller')
self.hub.add(2, Mock(), READ)
self.hub.add(2, Mock(), WRITE)
self.hub.remove_writer(2)
self.assertIn(2, self.hub.readers)
self.assertNotIn(2, self.hub.writers)
def test_add__consolidate(self):
self.hub.poller = Mock(name='hub.poller')
self.hub.add(2, Mock(), WRITE, consolidate=True)
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())
示例4: setup
# 需要导入模块: from kombu import Hub [as 别名]
# 或者: from kombu.Hub import add [as 别名]
#.........这里部分代码省略.........
eback = Mock()
eback.side_effect = KeyError('foo')
self.hub.timer = Mock()
self.hub.scheduler = iter([(0, eback)])
with pytest.raises(KeyError):
self.hub.fire_timers(propagate=(KeyError,))
eback.side_effect = ValueError('foo')
self.hub.scheduler = iter([(0, eback)])
with patch('kombu.async.hub.logger') as logger:
with pytest.raises(StopIteration):
self.hub.fire_timers()
logger.error.assert_called()
eback.side_effect = MemoryError('foo')
self.hub.scheduler = iter([(0, eback)])
with pytest.raises(MemoryError):
self.hub.fire_timers()
eback.side_effect = OSError()
eback.side_effect.errno = errno.ENOMEM
self.hub.scheduler = iter([(0, eback)])
with pytest.raises(OSError):
self.hub.fire_timers()
eback.side_effect = OSError()
eback.side_effect.errno = errno.ENOENT
self.hub.scheduler = iter([(0, eback)])
with patch('kombu.async.hub.logger') as logger:
with pytest.raises(StopIteration):
self.hub.fire_timers()
logger.error.assert_called()
def test_add_raises_ValueError(self):
self.hub.poller = Mock(name='hub.poller')
self.hub.poller.register.side_effect = ValueError()
self.hub._discard = Mock(name='hub.discard')
with pytest.raises(ValueError):
self.hub.add(2, Mock(), READ)
self.hub._discard.assert_called_with(2)
def test_remove_reader(self):
self.hub.poller = Mock(name='hub.poller')
self.hub.add(2, Mock(), READ)
self.hub.add(2, Mock(), WRITE)
self.hub.remove_reader(2)
assert 2 not in self.hub.readers
assert 2 in self.hub.writers
def test_remove_reader__not_writeable(self):
self.hub.poller = Mock(name='hub.poller')
self.hub.add(2, Mock(), READ)
self.hub.remove_reader(2)
assert 2 not in self.hub.readers
def test_remove_writer(self):
self.hub.poller = Mock(name='hub.poller')
self.hub.add(2, Mock(), READ)
self.hub.add(2, Mock(), WRITE)
self.hub.remove_writer(2)
assert 2 in self.hub.readers
assert 2 not in self.hub.writers
def test_remove_writer__not_readable(self):
self.hub.poller = Mock(name='hub.poller')
self.hub.add(2, Mock(), WRITE)