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')
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_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')
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
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
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)
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
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_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')
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_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
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)
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_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
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
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)
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_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()
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
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