本文整理汇总了Python中celery.worker.hub.Hub类的典型用法代码示例。如果您正苦于以下问题:Python Hub类的具体用法?Python Hub怎么用?Python Hub使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Hub类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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()
示例2: 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)
示例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)]))
示例4: 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())
示例5: 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)
示例6: 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)
示例7: 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 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)
hub.timer.apply_entry.assert_has_calls([call(x) for x in [e3, e2, e1]])
entries[:] = [Mock() for _ in range(11)]
keep = list(entries)
self.assertEqual(hub.fire_timers(max_timers=10, min_delay=1.13), 1.13)
hub.timer.apply_entry.assert_has_calls(
[call(x) for x in reversed(keep[1:])]
)
self.assertEqual(hub.fire_timers(max_timers=10), 3.982)
hub.timer.apply_entry.assert_has_calls(call(keep[0]))
示例8: 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 = Mock()
hub.scheduler.next.return_value = 3.743, None
self.assertEqual(hub.fire_timers(), 3.743)
e1, e2, e3 = Mock(), Mock(), Mock()
entries = [e1, e2, e3]
def se():
if entries:
return None, entries.pop()
return 3.982, None
hub.scheduler.next = Mock()
hub.scheduler.next.side_effect = se
self.assertEqual(hub.fire_timers(max_timers=10), 3.982)
hub.timer.apply_entry.assert_has_calls(map(call, [e3, e2, e1]))
entries[:] = [Mock() for _ in xrange(11)]
keep = list(entries)
self.assertEqual(hub.fire_timers(max_timers=10, min_delay=1.13), 1.13)
hub.timer.apply_entry.assert_has_calls(
map(call, reversed(keep[1:])),
)
self.assertEqual(hub.fire_timers(max_timers=10), 3.982)
hub.timer.apply_entry.assert_has_calls(call(keep[0]))
示例9: test_callback_for
def test_callback_for(self):
hub = Hub()
reader, writer = Mock(), Mock()
hub.readers = {6: reader}
hub.writers = {7: writer}
self.assertEqual(hub._callback_for(6, READ), reader)
self.assertEqual(hub._callback_for(7, WRITE), writer)
with self.assertRaises(KeyError):
hub._callback_for(6, WRITE)
self.assertEqual(hub._callback_for(6, WRITE, "foo"), "foo")
示例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("celery.worker.hub.logger") as logger:
with self.assertRaises(StopIteration):
hub.fire_timers()
self.assertTrue(logger.error.called)
示例11: 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]
reset = lambda: [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()
示例12: 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)])
示例13: 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)])
示例14: 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 = Mock()
hub.scheduler.next.return_value = 3.743, None
self.assertEqual(hub.fire_timers(), 3.743)
e1, e2, e3 = Mock(), Mock(), Mock()
entries = [e1, e2, e3]
reset = lambda: [m.reset() for m in [e1, e2, e3]]
def se():
if entries:
return None, entries.pop()
return 3.982, None
hub.scheduler.next = Mock()
hub.scheduler.next.side_effect = 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 xrange(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()
示例15: test_remove__unregister_raises
def test_remove__unregister_raises(self):
hub = Hub()
hub.poller = Mock()
hub.poller.unregister.side_effect = OSError()
hub.remove(313)