Exemple #1
0
    def test_events_real(self, context, monitor):
        # make sure that the module is unloaded initially
        pytest.unload_dummy()
        monitor.filter_by('net')
        monitor.start()
        self.prepare_test(monitor)
        # setup signal handlers
        event_callback = mock.Mock(side_effect=self.stop_when_done)
        added_callback = mock.Mock(side_effect=self.stop_when_done)
        removed_callback = mock.Mock(side_effect=self.stop_when_done)
        self.connect_signal(event_callback)
        self.connect_signal(added_callback, action='add')
        self.connect_signal(removed_callback, action='remove')

        # test add event
        self.start_event_loop(pytest.load_dummy)
        device = Device.from_path(context, '/devices/virtual/net/dummy0')
        event_callback.assert_called_with('add', device)
        added_callback.assert_called_with(device)
        assert not removed_callback.called

        for callback in (event_callback, added_callback, removed_callback):
            callback.reset_mock()

        self.start_event_loop(pytest.unload_dummy)
        event_callback.assert_called_with('remove', device)
        assert not added_callback.called
        removed_callback.assert_called_with(device)
Exemple #2
0
    def test_events_real(self, context, monitor):
        # make sure that the module is unloaded initially
        pytest.unload_dummy()
        monitor.filter_by('net')
        monitor.start()
        self.prepare_test(monitor)
        # setup signal handlers
        event_callback = Mock(side_effect=self.stop_when_done)
        added_callback = Mock(side_effect=self.stop_when_done)
        removed_callback = Mock(side_effect=self.stop_when_done)
        self.connect_signal(event_callback)
        self.connect_signal(added_callback, action='add')
        self.connect_signal(removed_callback, action='remove')

        # test add event
        self.start_event_loop(pytest.load_dummy)
        device = Device.from_path(context, '/devices/virtual/net/dummy0')
        event_callback.assert_called_with('add', device)
        added_callback.assert_called_with(device)
        assert not removed_callback.called

        for mock in (event_callback, added_callback, removed_callback):
            mock.reset_mock()

        self.start_event_loop(pytest.unload_dummy)
        event_callback.assert_called_with('remove', device)
        assert not added_callback.called
        removed_callback.assert_called_with(device)
 def test_real(self, context, monitor):
     observer = self.make_observer(monitor)
     pytest.unload_dummy()
     monitor.filter_by('net')
     monitor.start()
     observer.start()
     pytest.load_dummy()
     pytest.unload_dummy()
     observer.join(2)
     if observer.is_alive():
         observer.stop()
     assert [d.action for d in self.events] == ['add', 'remove']
     for device in self.events:
         assert device.device_path == '/devices/virtual/net/dummy0'
Exemple #4
0
 def test_real(self, context, monitor):
     observer = self.make_observer(monitor)
     pytest.unload_dummy()
     monitor.filter_by('net')
     monitor.start()
     observer.start()
     pytest.load_dummy()
     pytest.unload_dummy()
     observer.join(2)
     if observer.is_alive():
         observer.stop()
     assert [d.action for d in self.events] == ['add', 'remove']
     for device in self.events:
         assert device.device_path == '/devices/virtual/net/dummy0'
Exemple #5
0
 def test_iter(self, monitor):
     pytest.unload_dummy()
     monitor.filter_by('net')
     monitor.enable_receiving()
     pytest.load_dummy()
     iterator = iter(monitor)
     action, device = next(iterator)
     assert action == 'add'
     assert device.subsystem == 'net'
     assert device.device_path == '/devices/virtual/net/dummy0'
     pytest.unload_dummy()
     action, device = next(iterator)
     assert action == 'remove'
     assert device.subsystem == 'net'
     assert device.device_path == '/devices/virtual/net/dummy0'
     iterator.close()
Exemple #6
0
 def test_observer(self, binding, monitor):
     binding.import_or_skip()
     pytest.unload_dummy()
     monitor.filter_by('net')
     monitor.enable_receiving()
     event_slot, action_slot = binding.trigger_observer(
         'add', monitor, pytest.load_dummy)
     action, device = event_slot.call_args[0]
     assert action == 'add'
     assert device.subsystem == 'net'
     assert device.device_path == '/devices/virtual/net/dummy0'
     event_slot, action_slot = binding.trigger_observer(
         'remove', monitor, pytest.unload_dummy)
     action, device = event_slot.call_args[0]
     assert action == 'remove'
     assert device.subsystem == 'net'
     assert device.device_path == '/devices/virtual/net/dummy0'
Exemple #7
0
 def test_receive_device(self, monitor):
     # forcibly unload the dummy module to avoid hangs
     pytest.unload_dummy()
     monitor.filter_by('net')
     monitor.enable_receiving()
     # load the dummy device to trigger an add event
     pytest.load_dummy()
     select([monitor], [], [])
     action, device = monitor.receive_device()
     assert action == 'add'
     assert device.subsystem == 'net'
     assert device.device_path == '/devices/virtual/net/dummy0'
     # and unload again
     pytest.unload_dummy()
     action, device = monitor.receive_device()
     assert action == 'remove'
     assert device.subsystem == 'net'
     assert device.device_path == '/devices/virtual/net/dummy0'
 def test_poll(self, monitor):
     # forcibly unload the dummy module to avoid hangs
     pytest.unload_dummy()
     monitor.filter_by('net')
     monitor.start()
     # load the dummy device to trigger an add event
     pytest.load_dummy()
     select([monitor], [], [])
     device = monitor.poll()
     assert device.action == 'add'
     assert device.sequence_number > 0
     assert device.subsystem == 'net'
     assert device.device_path == '/devices/virtual/net/dummy0'
     # and unload again
     pytest.unload_dummy()
     device = monitor.poll()
     assert device.action == 'remove'
     assert device.sequence_number > 0
     assert device.subsystem == 'net'
     assert device.device_path == '/devices/virtual/net/dummy0'
Exemple #9
0
    def test_events_real(self, context, monitor):
        # make sure that the module is unloaded initially
        pytest.unload_dummy()
        monitor.filter_by('net')
        monitor.start()
        self.prepare_test(monitor)
        # setup signal handlers
        event_callback = mock.Mock(
            side_effect=lambda *args: self.stop_event_loop())
        self.connect_signal(event_callback)

        # test add event
        self.start_event_loop(pytest.load_dummy)
        device = Device.from_path(context, '/devices/virtual/net/dummy0')
        event_callback.assert_called_with(device)

        event_callback.reset_mock()

        self.start_event_loop(pytest.unload_dummy)
        event_callback.assert_called_with(device)
Exemple #10
0
    def test_events_real(self, context, monitor):
        # make sure that the module is unloaded initially
        pytest.unload_dummy()
        monitor.filter_by('net')
        monitor.start()
        self.prepare_test(monitor)
        # setup signal handlers
        event_callback = mock.Mock(
            side_effect=lambda *args: self.stop_event_loop())
        self.connect_signal(event_callback)

        # test add event
        self.start_event_loop(pytest.load_dummy)
        device = Device.from_path(context, '/devices/virtual/net/dummy0')
        event_callback.assert_called_with(device)

        event_callback.reset_mock()

        self.start_event_loop(pytest.unload_dummy)
        event_callback.assert_called_with(device)
Exemple #11
0
 def test_poll(self, monitor):
     # forcibly unload the dummy module to avoid hangs
     pytest.unload_dummy()
     monitor.filter_by('net')
     monitor.start()
     # load the dummy device to trigger an add event
     pytest.load_dummy()
     select([monitor], [], [])
     device = monitor.poll()
     assert device.action == 'add'
     assert device.sequence_number > 0
     assert device.subsystem == 'net'
     assert device.device_path == '/devices/virtual/net/dummy0'
     # and unload again
     pytest.unload_dummy()
     device = monitor.poll()
     assert device.action == 'remove'
     assert device.sequence_number > 0
     assert device.subsystem == 'net'
     assert device.device_path == '/devices/virtual/net/dummy0'
 def test_iter(self, monitor):
     pytest.unload_dummy()
     monitor.filter_by('net')
     monitor.start()
     pytest.load_dummy()
     iterator = iter(monitor)
     # DeprecationWarning triggered on first invocation of generator
     action, device = pytest.deprecated_call(next, iterator)
     assert action == 'add'
     assert device.action == 'add'
     assert device.sequence_number > 0
     assert device.subsystem == 'net'
     assert device.device_path == '/devices/virtual/net/dummy0'
     pytest.unload_dummy()
     action, device = next(iterator)
     assert action == 'remove'
     assert device.action == 'remove'
     assert device.sequence_number > 0
     assert device.subsystem == 'net'
     assert device.device_path == '/devices/virtual/net/dummy0'
     iterator.close()
Exemple #13
0
 def test_iter(self, monitor):
     pytest.unload_dummy()
     monitor.filter_by('net')
     monitor.start()
     pytest.load_dummy()
     iterator = iter(monitor)
     # DeprecationWarning triggered on first invocation of generator
     action, device = pytest.deprecated_call(next, iterator)
     assert action == 'add'
     assert device.action == 'add'
     assert device.sequence_number > 0
     assert device.subsystem == 'net'
     assert device.device_path == '/devices/virtual/net/dummy0'
     pytest.unload_dummy()
     action, device = next(iterator)
     assert action == 'remove'
     assert device.action == 'remove'
     assert device.sequence_number > 0
     assert device.subsystem == 'net'
     assert device.device_path == '/devices/virtual/net/dummy0'
     iterator.close()