本文整理汇总了Python中kombu.Hub.add_reader方法的典型用法代码示例。如果您正苦于以下问题:Python Hub.add_reader方法的具体用法?Python Hub.add_reader怎么用?Python Hub.add_reader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kombu.Hub
的用法示例。
在下文中一共展示了Hub.add_reader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_enter__exit
# 需要导入模块: from kombu import Hub [as 别名]
# 或者: from kombu.Hub import add_reader [as 别名]
def test_enter__exit(self):
hub = Hub()
P = hub.poller = Mock()
on_close = Mock()
hub.on_close.add(on_close)
try:
read_A = Mock()
read_B = Mock()
hub.add_reader(10, read_A)
hub.add_reader(File(11), read_B)
write_A = Mock()
write_B = Mock()
hub.add_writer(20, write_A)
hub.add_writer(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)
示例2: test_add_remove_readers
# 需要导入模块: from kombu import Hub [as 别名]
# 或者: from kombu.Hub import add_reader [as 别名]
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)])
示例3: test_Hub
# 需要导入模块: from kombu import Hub [as 别名]
# 或者: from kombu.Hub import add_reader [as 别名]
#.........这里部分代码省略.........
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)
P.register.assert_has_calls([
call(10, self.hub.READ | self.hub.ERR),
call(11, self.hub.READ | self.hub.ERR),
], any_order=True)
self.assertEqual(self.hub.readers[10], (read_A, (10,)))
self.assertEqual(self.hub.readers[11], (read_B, (11,)))
self.hub.remove(10)
self.assertNotIn(10, self.hub.readers)
self.hub.remove(File(11))
self.assertNotIn(11, self.hub.readers)
P.unregister.assert_has_calls([
call(10), call(11),
])
def test_can_remove_unknown_fds(self):
self.hub.poller = Mock()
self.hub.remove(30)
self.hub.remove(File(301))
def test_remove__unregister_raises(self):
self.hub.poller = Mock()
self.hub.poller.unregister.side_effect = OSError()
self.hub.remove(313)
def test_add_writers(self):
P = self.hub.poller = Mock()
示例4: setup
# 需要导入模块: from kombu import Hub [as 别名]
# 或者: from kombu.Hub import add_reader [as 别名]
#.........这里部分代码省略.........
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)
P.register.assert_has_calls([
call(10, self.hub.READ | self.hub.ERR),
call(11, self.hub.READ | self.hub.ERR),
], any_order=True)
assert self.hub.readers[10] == (read_A, (10,))
assert self.hub.readers[11] == (read_B, (11,))
self.hub.remove(10)
assert 10 not in self.hub.readers
self.hub.remove(File(11))
assert 11 not in self.hub.readers
P.unregister.assert_has_calls([
call(10), call(11),
])
def test_can_remove_unknown_fds(self):
self.hub.poller = Mock()
self.hub.remove(30)
self.hub.remove(File(301))
def test_remove__unregister_raises(self):
self.hub.poller = Mock()
self.hub.poller.unregister.side_effect = OSError()
self.hub.remove(313)
def test_add_writers(self):
P = self.hub.poller = Mock()