def test_iteration(self, device, device_data): for property in device: assert pytest.is_unicode_string(property) # test that iteration really yields all properties device_properties = set(device) for property in device_data.properties: assert property in device_properties
def test_iteration(self, device, device_data): for attribute in device.attributes: assert pytest.is_unicode_string(attribute) # check that iteration really yields all attributes device_attributes = set(device.attributes) for attribute in device_data.attributes: assert attribute in device_attributes
def test_sys_number(self, device): match = re.search(r'\d+$', device.sys_name) # filter out devices with completely nummeric names (first character # doesn't count according to the implementation of libudev) if match and match.start() > 1: assert device.sys_number == match.group(0) assert pytest.is_unicode_string(device.sys_name) else: assert device.sys_number is None
def test_sys_number(self, device): match = re.search(r"\d+$", device.sys_name) # filter out devices with completely nummeric names (first character # doesn't count according to the implementation of libudev) if match and match.start() > 1: assert device.sys_number == match.group(0) assert pytest.is_unicode_string(device.sys_name) else: assert device.sys_number is None
def test_action_mock(self, device): funcname = "udev_device_get_action" spec = lambda d: None with mock.patch.object(device._libudev, funcname, autospec=spec) as func: func.return_value = b"spam" assert device.action == "spam" func.assert_called_once_with(device) func.reset_mock() assert pytest.is_unicode_string(device.action) func.assert_called_once_with(device)
def _is_blacklisted(function): for pattern in WRAPPER_BLACKLIST_PATTERNS: if pytest.is_unicode_string(pattern): if function.name == pattern: return True else: if pattern.match(function.name): return True else: return False
def test_action_mock(self, device): funcname = 'udev_device_get_action' spec = lambda d: None with mock.patch.object(device._libudev, funcname, autospec=spec) as func: func.return_value = b'spam' assert device.action == 'spam' func.assert_called_once_with(device) func.reset_mock() assert pytest.is_unicode_string(device.action) func.assert_called_once_with(device)
def test_receive_device_mock(self, monitor): receive_device = 'udev_monitor_receive_device' get_action = 'udev_device_get_action' with pytest.nested(pytest.patch_libudev(receive_device), pytest.patch_libudev(get_action)) as (receive_device, get_action): receive_device.return_value = mock.sentinel.pointer get_action.return_value = b'action' action, device = monitor.receive_device() assert action == 'action' assert pytest.is_unicode_string(action) assert isinstance(device, Device) assert device.context is monitor.context assert device._as_parameter_ is mock.sentinel.pointer get_action.assert_called_with(mock.sentinel.pointer) receive_device.assert_called_with(monitor)
def test_type(self, device, properties): if 'DEVTYPE' in properties: assert device.device_type == properties['DEVTYPE'] assert pytest.is_unicode_string(device.device_type) else: assert device.device_type is None
def test_iteration(self, device, device_data): if not device_data.tags: pytest.skip("no tags on device") assert set(device.tags) == set(device_data.tags) for tag in device.tags: assert pytest.is_unicode_string(tag)
def test_device_node(self, device, device_data): assert device.device_node == device_data.device_node if device.device_node: assert pytest.is_unicode_string(device.device_node)
def test_device_node(self, device, device_node): if device_node: assert device.device_node == device_node assert pytest.is_unicode_string(device.device_node) else: assert device.device_node is None
def test_device_sys_name(self, device): assert device.sys_name == os.path.basename(device.device_path) assert pytest.is_unicode_string(device.sys_name)
def test_type(self, device, device_data): assert device.device_type == device_data.properties.get("DEVTYPE") if device.device_type: assert pytest.is_unicode_string(device.device_type)
def test_driver(self, device, device_data): assert device.driver == device_data.properties.get('DRIVER') if device.driver: assert pytest.is_unicode_string(device.driver)
def test_iteration(self, device, tags): assert set(device.tags) == set(tags) assert all(pytest.is_unicode_string(t) for t in device.tags)
def test_asstring(self, device, attributes): assert all(pytest.is_unicode_string(device.attributes.asstring(a)) for a in attributes) assert all(device.attributes.asstring(a) == v for a, v in attributes.items())
def test_type(self, device, device_data): assert device.device_type == device_data.properties.get('DEVTYPE') if device.device_type: assert pytest.is_unicode_string(device.device_type)
def test_subsystem(self, device, device_data): assert device.subsystem == device_data.properties['SUBSYSTEM'] assert pytest.is_unicode_string(device.subsystem)
def test_device_path(self, device, device_data): assert device.device_path == device_data.device_path assert pytest.is_unicode_string(device.device_path)
def test_device_path(self, context): assert pytest.is_unicode_string(context.device_path) assert context.device_path == '/dev'
def test_subsystem(self, device, properties): assert device.subsystem == properties['SUBSYSTEM'] assert pytest.is_unicode_string(device.subsystem)
def test_links(self, context, device, device_data): assert sorted(device.device_links) == sorted(device_data.device_links) for link in device.device_links: assert pytest.is_unicode_string(link)
def test_subsystem(self, device, device_data): assert device.subsystem == device_data.properties["SUBSYSTEM"] assert pytest.is_unicode_string(device.subsystem)
def test_iteration(self, device, attributes): device_attributes = set(device.attributes) assert all(a in device_attributes for a in attributes) assert all(pytest.is_unicode_string(a) for a in device_attributes)
def test_links(self, context, device, device_links): assert sorted(device.device_links) == sorted( os.path.join(context.device_path, l) for l in device_links) assert all(pytest.is_unicode_string(l) for l in device.device_links)
def test_iteration(self, device, properties): device_properties = set(device) assert all(p in device_properties for p in properties) assert all(pytest.is_unicode_string(p) for p in device_properties)
def test_driver(self, device, device_data): assert device.driver == device_data.properties.get("DRIVER") if device.driver: assert pytest.is_unicode_string(device.driver)
def test_sys_path(self, device, sys_path): assert device.sys_path == sys_path assert pytest.is_unicode_string(device.sys_path)
def test_driver(self, device, properties): if 'DRIVER' in properties: assert device.driver == properties['DRIVER'] assert pytest.is_unicode_string(device.driver) else: assert device.driver is None
def test_iteration(self, device, device_data): if not device_data.tags: pytest.skip('no tags on device') assert set(device.tags) == set(device_data.tags) for tag in device.tags: assert pytest.is_unicode_string(tag)
def test_asstring(self, device, device_data): for attribute, value in device_data.attributes.items(): assert pytest.is_unicode_string(device.attributes.asstring(attribute)) assert device.attributes.asstring(attribute) == value
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_sys_path(self, context): assert pytest.is_unicode_string(context.sys_path) assert context.sys_path == '/sys'
def test_ensure_unicode_string(): assert pytest.is_unicode_string( _util.ensure_unicode_string(b'hello world')) assert _util.ensure_unicode_string(b'hello world') == 'hello world' hello = 'hello world' assert _util.ensure_unicode_string(hello) is hello
def test_run_path(self, context): assert pytest.is_unicode_string(context.run_path) assert context.run_path == '/run/udev'
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_asstring(self, device, device_data): for attribute, value in device_data.attributes.items(): assert pytest.is_unicode_string( device.attributes.asstring(attribute)) assert device.attributes.asstring(attribute) == value