本文整理汇总了Python中kombu.Hub.call_later方法的典型用法代码示例。如果您正苦于以下问题:Python Hub.call_later方法的具体用法?Python Hub.call_later怎么用?Python Hub.call_later使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kombu.Hub
的用法示例。
在下文中一共展示了Hub.call_later方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_Hub
# 需要导入模块: from kombu import Hub [as 别名]
# 或者: from kombu.Hub import call_later [as 别名]
class test_Hub(Case):
def setup(self):
self.hub = Hub()
def teardown(self):
self.hub.close()
def test_reset(self):
self.hub.close = Mock(name='close')
self.hub._create_poller = Mock(name='_create_poller')
self.hub.reset()
self.hub.close.assert_called_with()
self.hub._create_poller.assert_called_with()
def test__close_poller__no_poller(self):
self.hub.poller = None
self.hub._close_poller()
def test__close_poller(self):
poller = self.hub.poller = Mock(name='poller')
self.hub._close_poller()
poller.close.assert_called_with()
self.assertIsNone(self.hub.poller)
def test_stop(self):
self.hub.call_soon = Mock(name='call_soon')
self.hub.stop()
self.hub.call_soon.assert_called_with(_raise_stop_error)
def test_call_later(self):
callback = Mock(name='callback')
self.hub.timer = Mock(name='hub.timer')
self.hub.call_later(10.0, callback, 1, 2)
self.hub.timer.call_after.assert_called_with(10.0, callback, (1, 2))
def test_call_at(self):
callback = Mock(name='callback')
self.hub.timer = Mock(name='hub.timer')
self.hub.call_at(21231122, callback, 1, 2)
self.hub.timer.call_at.assert_called_with(21231122, callback, (1, 2))
def test_repr(self):
self.assertTrue(repr(self.hub))
def test_repr_flag(self):
self.assertEqual(repr_flag(READ), 'R')
self.assertEqual(repr_flag(WRITE), 'W')
self.assertEqual(repr_flag(ERR), '!')
self.assertEqual(repr_flag(READ | WRITE), 'RW')
self.assertEqual(repr_flag(READ | ERR), 'R!')
self.assertEqual(repr_flag(WRITE | ERR), 'W!')
self.assertEqual(repr_flag(READ | WRITE | ERR), 'RW!')
def test_repr_callback_rcb(self):
def f():
pass
self.assertEqual(_rcb(f), f.__name__)
self.assertEqual(_rcb('foo'), 'foo')
@patch('kombu.async.hub.poll')
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()
def test_fire_timers(self):
self.hub.timer = Mock()
self.hub.timer._queue = []
self.assertEqual(
self.hub.fire_timers(min_delay=42.324, max_delay=32.321),
32.321,
)
self.hub.timer._queue = [1]
self.hub.scheduler = iter([(3.743, None)])
self.assertEqual(self.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
self.hub.scheduler = se()
self.assertEqual(self.hub.fire_timers(max_timers=10), 3.982)
for E in [e3, e2, e1]:
E.assert_called_with()
#.........这里部分代码省略.........
示例2: setup
# 需要导入模块: from kombu import Hub [as 别名]
# 或者: from kombu.Hub import call_later [as 别名]
class test_Hub:
def setup(self):
self.hub = Hub()
def teardown(self):
self.hub.close()
def test_reset(self):
self.hub.close = Mock(name='close')
self.hub._create_poller = Mock(name='_create_poller')
self.hub.reset()
self.hub.close.assert_called_with()
self.hub._create_poller.assert_called_with()
def test__close_poller__no_poller(self):
self.hub.poller = None
self.hub._close_poller()
def test__close_poller(self):
poller = self.hub.poller = Mock(name='poller')
self.hub._close_poller()
poller.close.assert_called_with()
assert self.hub.poller is None
def test_stop(self):
self.hub.call_soon = Mock(name='call_soon')
self.hub.stop()
self.hub.call_soon.assert_called_with(_raise_stop_error)
@patch('kombu.async.hub.promise')
def test_call_soon(self, promise):
callback = Mock(name='callback')
ret = self.hub.call_soon(callback, 1, 2, 3)
promise.assert_called_with(callback, (1, 2, 3))
assert promise() in self.hub._ready
assert ret is promise()
def test_call_soon__promise_argument(self):
callback = promise(Mock(name='callback'), (1, 2, 3))
ret = self.hub.call_soon(callback)
assert ret is callback
assert ret in self.hub._ready
def test_call_later(self):
callback = Mock(name='callback')
self.hub.timer = Mock(name='hub.timer')
self.hub.call_later(10.0, callback, 1, 2)
self.hub.timer.call_after.assert_called_with(10.0, callback, (1, 2))
def test_call_at(self):
callback = Mock(name='callback')
self.hub.timer = Mock(name='hub.timer')
self.hub.call_at(21231122, callback, 1, 2)
self.hub.timer.call_at.assert_called_with(21231122, callback, (1, 2))
def test_repr(self):
assert repr(self.hub)
def test_repr_flag(self):
assert repr_flag(READ) == 'R'
assert repr_flag(WRITE) == 'W'
assert repr_flag(ERR) == '!'
assert repr_flag(READ | WRITE) == 'RW'
assert repr_flag(READ | ERR) == 'R!'
assert repr_flag(WRITE | ERR) == 'W!'
assert repr_flag(READ | WRITE | ERR) == 'RW!'
def test_repr_callback_rcb(self):
def f():
pass
assert _rcb(f) == f.__name__
assert _rcb('foo') == 'foo'
@patch('kombu.async.hub.poll')
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()
def test_fire_timers(self):
self.hub.timer = Mock()
self.hub.timer._queue = []
assert self.hub.fire_timers(
min_delay=42.324, max_delay=32.321) == 32.321
self.hub.timer._queue = [1]
self.hub.scheduler = iter([(3.743, None)])
assert self.hub.fire_timers() == 3.743
e1, e2, e3 = Mock(), Mock(), Mock()
entries = [e1, e2, e3]
def reset():
#.........这里部分代码省略.........