Пример #1
0
    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
0
 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
0
 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
Пример #4
0
 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'])
Пример #5
0
 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,
     )
Пример #6
0
 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,
     )
Пример #7
0
 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,
     )
Пример #8
0
 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,
     )
Пример #9
0
 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,
     )
Пример #10
0
 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,
     )
Пример #11
0
 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,
     )
Пример #12
0
 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,
     )
Пример #13
0
    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()
Пример #14
0
    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
Пример #15
0
    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()
Пример #16
0
    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()
Пример #17
0
    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
Пример #18
0
 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'])
Пример #19
0
 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)
Пример #20
0
 def test_on_event_loop_close(self):
     x = KQueueMonitor(['a', 'b'])
     x.close = Mock()
     hub = Mock()
     x.on_event_loop_close(hub)
     x.close.assert_called_with(hub.poller)
Пример #21
0
 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)
Пример #22
0
 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)