def test_filter_by_tag_mock(self, monitor):
     calls = {
         'udev_monitor_filter_add_match_tag': [(monitor, b'eggs')],
         'udev_monitor_filter_update': [(monitor, )]
     }
     with pytest.calls_to_libudev(calls):
         monitor.filter_by_tag('eggs')
Exemple #2
0
 def test_from_netlink_source_kernel_mock(self, context):
     calls = {'udev_monitor_new_from_netlink': [(context, b'kernel')]}
     with pytest.calls_to_libudev(calls):
         libudev.udev_monitor_new_from_netlink.return_value = sentinel.monitor
         monitor = Monitor.from_netlink(context, 'kernel')
         assert monitor._as_parameter_ is sentinel.monitor
         assert not monitor.started
 def test_remove_filter_mock(self, monitor):
     calls = {
         'udev_monitor_filter_remove': [(monitor, )],
         'udev_monitor_filter_update': [(monitor, )]
     }
     with pytest.calls_to_libudev(calls):
         monitor.remove_filter()
 def test_from_netlink_source_kernel_mock(self, context):
     calls = {'udev_monitor_new_from_netlink': [(context, b'kernel')]}
     with pytest.calls_to_libudev(calls):
         libudev.udev_monitor_new_from_netlink.return_value = sentinel.monitor
         monitor = Monitor.from_netlink(context, 'kernel')
         assert monitor._as_parameter_ is sentinel.monitor
         assert not monitor.started
Exemple #5
0
 def test_contains_mock(self, device):
     """
     Test that ``udev_device_has_tag`` is called if available.
     """
     calls = {'udev_device_has_tag': [(device, b'foo')]}
     with pytest.calls_to_libudev(calls):
         libudev.udev_device_has_tag.return_value = 1
         assert 'foo' in device.tags
 def test_filter_by_subsystem_dev_type_mock(self, monitor):
     calls = {
         'udev_monitor_filter_add_match_subsystem_devtype':
         [(monitor, b'input', b'usb_interface')],
         'udev_monitor_filter_update': [(monitor, )]
     }
     with pytest.calls_to_libudev(calls):
         monitor.filter_by('input', 'usb_interface')
Exemple #7
0
 def test_contains_mock(self, device):
     """
     Test that ``udev_device_has_tag`` is called if available.
     """
     calls = {'udev_device_has_tag': [(device, b'foo')]}
     with pytest.calls_to_libudev(calls):
         libudev.udev_device_has_tag.return_value = 1
         assert 'foo' in device.tags
Exemple #8
0
 def test_find_parent_with_devtype_mock(self, device):
     calls = {'udev_device_get_parent_with_subsystem_devtype':
              [(device, b'subsystem', b'devtype')],
              'udev_device_ref': [(sentinel.parent_device,)]}
     with pytest.calls_to_libudev(calls):
         f = libudev.udev_device_get_parent_with_subsystem_devtype
         f.return_value = sentinel.parent_device
         libudev.udev_device_ref.return_value = sentinel.ref_device
         parent = device.find_parent('subsystem', 'devtype')
         assert isinstance(parent, Device)
         assert parent._as_parameter_ is sentinel.ref_device
Exemple #9
0
 def test_find_parent_with_devtype_mock(self, device):
     calls = {
         'udev_device_get_parent_with_subsystem_devtype':
         [(device, b'subsystem', b'devtype')],
         'udev_device_ref': [(sentinel.parent_device, )]
     }
     with pytest.calls_to_libudev(calls):
         f = libudev.udev_device_get_parent_with_subsystem_devtype
         f.return_value = sentinel.parent_device
         libudev.udev_device_ref.return_value = sentinel.ref_device
         parent = device.find_parent('subsystem', 'devtype')
         assert isinstance(parent, Device)
         assert parent._as_parameter_ is sentinel.ref_device
Exemple #10
0
 def test_events_fake_monitor(self, action, fake_monitor,
                              fake_monitor_device):
     self.prepare_test(fake_monitor)
     event_callback = Mock(side_effect=self.stop_when_done)
     action_callback = Mock(side_effect=self.stop_when_done)
     self.connect_signal(event_callback)
     self.connect_signal(action_callback, action=action)
     calls = {'udev_device_get_action': [(fake_monitor_device,),
                                         (fake_monitor_device,)]}
     with pytest.calls_to_libudev(calls):
         libudev.udev_device_get_action.return_value = action.encode('ascii')
         self.start_event_loop(fake_monitor.trigger_event)
     event_callback.assert_called_with(action, fake_monitor_device)
     action_callback.assert_called_with(fake_monitor_device)
 def test_events_fake_monitor(self, action, fake_monitor,
                              fake_monitor_device):
     self.prepare_test(fake_monitor)
     event_callback = Mock(side_effect=self.stop_when_done)
     action_callback = Mock(side_effect=self.stop_when_done)
     self.connect_signal(event_callback)
     self.connect_signal(action_callback, action=action)
     calls = {
         'udev_device_get_action': [(fake_monitor_device, ),
                                    (fake_monitor_device, )]
     }
     with pytest.calls_to_libudev(calls):
         libudev.udev_device_get_action.return_value = action.encode(
             'ascii')
         self.start_event_loop(fake_monitor.trigger_event)
     event_callback.assert_called_with(action, fake_monitor_device)
     action_callback.assert_called_with(fake_monitor_device)
Exemple #12
0
 def test_log_priority_set_mock(self, context):
     calls = {'udev_set_log_priority': [(context, sentinel.log_priority)]}
     with pytest.calls_to_libudev(calls):
         context.log_priority = sentinel.log_priority
Exemple #13
0
 def test_log_priority_get_mock(self, context):
     calls = {'udev_get_log_priority': [(context,)]}
     with pytest.calls_to_libudev(calls):
         libudev.udev_get_log_priority.return_value = sentinel.log_priority
         assert context.log_priority is sentinel.log_priority
 def test_log_priority_set_mock(self, context):
     calls = {'udev_set_log_priority': [(context, sentinel.log_priority)]}
     with pytest.calls_to_libudev(calls):
         context.log_priority = sentinel.log_priority
 def test_log_priority_get_mock(self, context):
     calls = {'udev_get_log_priority': [(context, )]}
     with pytest.calls_to_libudev(calls):
         libudev.udev_get_log_priority.return_value = sentinel.log_priority
         assert context.log_priority is sentinel.log_priority
Exemple #16
0
 def test_filter_by_tag_mock(self, monitor):
     calls = {'udev_monitor_filter_add_match_tag': [(monitor, b'eggs')],
              'udev_monitor_filter_update': [(monitor,)]}
     with pytest.calls_to_libudev(calls):
         monitor.filter_by_tag('eggs')
Exemple #17
0
 def test_start_mock(self, monitor):
     calls = {'udev_monitor_enable_receiving': [(monitor,)]}
     with pytest.calls_to_libudev(calls):
         assert not monitor.started
         monitor.start()
         assert monitor.started
Exemple #18
0
 def test_filter_by_subsystem_dev_type_mock(self, monitor):
     calls = {'udev_monitor_filter_add_match_subsystem_devtype':
              [(monitor, b'input', b'usb_interface')],
              'udev_monitor_filter_update': [(monitor,)]}
     with pytest.calls_to_libudev(calls):
         monitor.filter_by('input', 'usb_interface')
 def test_set_receive_buffer_size_mock(self, monitor):
     calls = {'udev_monitor_set_receive_buffer_size': [(monitor, 1000)]}
     with pytest.calls_to_libudev(calls):
         monitor.set_receive_buffer_size(1000)
 def test_match_tag_mock(self, context):
     enumerator = context.list_devices()
     calls = {'udev_enumerate_add_match_tag': [(enumerator, b'spam')]}
     with pytest.calls_to_libudev(calls):
         retval = enumerator.match_tag('spam')
         assert retval is enumerator
Exemple #21
0
 def test_action_mock(self, device):
     calls = {'udev_device_get_action': [(device, )]}
     with pytest.calls_to_libudev(calls):
         libudev.udev_device_get_action.return_value = b'spam'
         assert device.action == 'spam'
         assert pytest.is_unicode_string(device.action)
Exemple #22
0
 def test_time_since_initialized_mock(self, device):
     calls = {'udev_device_get_usec_since_initialized': [(device, )]}
     with pytest.calls_to_libudev(calls):
         libudev.udev_device_get_usec_since_initialized.return_value = 100
         assert device.time_since_initialized.microseconds == 100
Exemple #23
0
 def test_is_initialized_mock(self, device):
     calls = {'udev_device_get_is_initialized': [(device, )]}
     with pytest.calls_to_libudev(calls):
         libudev.udev_device_get_is_initialized.return_value = False
         assert not device.is_initialized
Exemple #24
0
 def test_time_since_initialized_mock(self, device):
     calls = {'udev_device_get_usec_since_initialized': [(device,)]}
     with pytest.calls_to_libudev(calls):
         libudev.udev_device_get_usec_since_initialized.return_value = 100
         assert device.time_since_initialized.microseconds == 100
 def test_fileno_mock(self, monitor):
     calls = {'udev_monitor_get_fd': [(monitor, )]}
     with pytest.calls_to_libudev(calls):
         libudev.udev_monitor_get_fd.return_value = sentinel.fileno
         assert monitor.fileno() is sentinel.fileno
Exemple #26
0
 def test_action_mock(self, device):
     calls = {'udev_device_get_action': [(device,)]}
     with pytest.calls_to_libudev(calls):
         libudev.udev_device_get_action.return_value = b'spam'
         assert device.action == 'spam'
         assert pytest.is_unicode_string(device.action)
Exemple #27
0
 def test_remove_filter_mock(self, monitor):
     calls = {'udev_monitor_filter_remove': [(monitor,)],
              'udev_monitor_filter_update': [(monitor,)]}
     with pytest.calls_to_libudev(calls):
         monitor.remove_filter()
Exemple #28
0
 def test_set_receive_buffer_size_mock(self, monitor):
     calls = {'udev_monitor_set_receive_buffer_size': [(monitor, 1000)]}
     with pytest.calls_to_libudev(calls):
         monitor.set_receive_buffer_size(1000)
 def test_start_mock(self, monitor):
     calls = {'udev_monitor_enable_receiving': [(monitor, )]}
     with pytest.calls_to_libudev(calls):
         assert not monitor.started
         monitor.start()
         assert monitor.started
 def test_match_is_initialized_mock(self, context):
     enumerator = context.list_devices()
     calls = {'udev_enumerate_add_match_is_initialized': [(enumerator,)]}
     with pytest.calls_to_libudev(calls):
         enumerator.match_is_initialized()
Exemple #31
0
 def test_is_initialized_mock(self, device):
     calls = {'udev_device_get_is_initialized': [(device,)]}
     with pytest.calls_to_libudev(calls):
         libudev.udev_device_get_is_initialized.return_value = False
         assert not device.is_initialized
Exemple #32
0
 def test_fileno_mock(self, monitor):
     calls = {'udev_monitor_get_fd': [(monitor,)]}
     with pytest.calls_to_libudev(calls):
         libudev.udev_monitor_get_fd.return_value = sentinel.fileno
         assert monitor.fileno() is sentinel.fileno