本文整理汇总了Python中celery.worker.autoreload.KQueueMonitor类的典型用法代码示例。如果您正苦于以下问题:Python KQueueMonitor类的具体用法?Python KQueueMonitor怎么用?Python KQueueMonitor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KQueueMonitor类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_start
def test_start(self, osopen, kevent, kqueue):
prev = {}
flags = ["KQ_FILTER_VNODE", "KQ_EV_ADD", "KQ_EV_ENABLE",
"KQ_EV_CLEAR", "KQ_NOTE_WRITE", "KQ_NOTE_EXTEND"]
for i, flag in enumerate(flags):
prev[flag] = getattr(select, flag, None)
if not prev[flag]:
setattr(select, flag, i)
try:
kq = kqueue.return_value = Mock()
class ev(object):
ident = 10
kq.control.return_value = [ev()]
x = KQueueMonitor(["a"])
osopen.return_value = 10
calls = [0]
def on_is_set():
calls[0] += 1
if calls[0] > 2:
return True
return False
x.shutdown_event = Mock()
x.shutdown_event.is_set.side_effect = on_is_set
x.start()
finally:
for flag in flags:
if prev[flag]:
setattr(select, flag, prev[flag])
else:
delattr(select, flag)
示例2: test_register_with_event_loop_no_kqueue
def test_register_with_event_loop_no_kqueue(self):
from kombu.utils import eventio
prev, eventio.kqueue = eventio.kqueue, None
try:
x = KQueueMonitor(['a'])
x.register_with_event_loop(Mock())
finally:
eventio.kqueue = prev
示例3: test_handle_event
def test_handle_event(self):
x = KQueueMonitor(['a', 'b'])
x.on_change = Mock()
eA = Mock()
eA.ident = 'a'
eB = Mock()
eB.ident = 'b'
x.fdmap = {'a': 'A', 'b': 'B'}
x.handle_event([eA, eB])
x.on_change.assert_called_with(['A', 'B'])
示例4: test_register_with_event_loop
def test_register_with_event_loop(self, kqueue):
x = KQueueMonitor(['a', 'b'])
hub = Mock(name='hub')
x.add_events = Mock(name='add_events()')
x.register_with_event_loop(hub)
x.add_events.assert_called_with(x._kq)
self.assertEqual(
x._kq.on_file_change,
x.handle_event,
)
示例5: test_on_poll_init
def test_on_poll_init(self):
x = KQueueMonitor(['a', 'b'])
hub = Mock()
x.add_events = Mock()
x.on_poll_init(hub)
x.add_events.assert_called_with(hub.poller)
self.assertEqual(
hub.poller.on_file_change,
x.handle_event,
)
示例6: test_register_with_event_loop
def test_register_with_event_loop(self):
x = KQueueMonitor(['a', 'b'])
hub = Mock()
x.add_events = Mock()
x.register_with_event_loop(hub)
x.add_events.assert_called_with(hub.poller)
self.assertEqual(
hub.poller.on_file_change,
x.handle_event,
)
示例7: test_register_with_event_loop
def test_register_with_event_loop(self):
from kombu.utils import eventio
if eventio.kqueue is None:
raise SkipTest('version of kombu does not work with pypy')
x = KQueueMonitor(['a', 'b'])
hub = Mock(name='hub')
x.add_events = Mock(name='add_events()')
x.register_with_event_loop(hub)
x.add_events.assert_called_with(x._kq)
self.assertEqual(
x._kq.on_file_change,
x.handle_event,
)
示例8: test_stop
def test_stop(self, close, kqueue):
x = KQueueMonitor(['a', 'b'])
x.poller = Mock()
x.filemap['a'] = 10
x.stop()
x.poller.close.assert_called_with()
close.assert_called_with(10)
close.side_effect = OSError()
close.side_effect.errno = errno.EBADF
x.stop()
示例9: test_stop
def test_stop(self, close, kqueue):
x = KQueueMonitor(["a", "b"])
x._kq = Mock()
x.filemap["a"] = 10
x.stop()
x._kq.close.assert_called_with()
close.assert_called_with(10)
close.side_effect = OSError()
close.side_effect.errno = errno.EBADF
x.stop()
示例10: test_start
def test_start(self, _kq, osopen, kevent, kqueue):
from kombu.utils import eventio
prev_poll, eventio.poll = eventio.poll, kqueue
prev = {}
flags = ['KQ_FILTER_VNODE', 'KQ_EV_ADD', 'KQ_EV_ENABLE',
'KQ_EV_CLEAR', 'KQ_NOTE_WRITE', 'KQ_NOTE_EXTEND']
for i, flag in enumerate(flags):
prev[flag] = getattr(eventio, flag, None)
if not prev[flag]:
setattr(eventio, flag, i)
try:
kq = kqueue.return_value = Mock()
class ev(object):
ident = 10
filter = eventio.KQ_FILTER_VNODE
fflags = eventio.KQ_NOTE_WRITE
kq.control.return_value = [ev()]
x = KQueueMonitor(['a'])
osopen.return_value = 10
calls = [0]
def on_is_set():
calls[0] += 1
if calls[0] > 2:
return True
return False
x.shutdown_event = Mock()
x.shutdown_event.is_set.side_effect = on_is_set
x.start()
finally:
for flag in flags:
if prev[flag]:
setattr(eventio, flag, prev[flag])
else:
delattr(eventio, flag)
eventio.poll = prev_poll
示例11: test_on_event_loop_close
def test_on_event_loop_close(self):
x = KQueueMonitor(['a', 'b'])
x.close = Mock()
x._kq = Mock(name='_kq')
x.on_event_loop_close(Mock(name='hub'))
x.close.assert_called_with(x._kq)
示例12: test_on_poll_close
def test_on_poll_close(self):
x = KQueueMonitor(['a', 'b'])
x.close = Mock()
hub = Mock()
x.on_poll_close(hub)
x.close.assert_called_with(hub.poller)