Ejemplo n.º 1
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')
Ejemplo n.º 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
Ejemplo n.º 3
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()
Ejemplo n.º 4
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
Ejemplo n.º 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
Ejemplo n.º 6
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')
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 11
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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 14
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
Ejemplo n.º 15
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
Ejemplo n.º 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')
Ejemplo n.º 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
Ejemplo n.º 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')
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
 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
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 25
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
Ejemplo n.º 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)
Ejemplo n.º 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()
Ejemplo n.º 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)
Ejemplo n.º 29
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
Ejemplo n.º 30
0
 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()
Ejemplo n.º 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
Ejemplo n.º 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