Example #1
0
 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
Example #2
0
 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
Example #3
0
 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
Example #4
0
 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
Example #5
0
 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
Example #6
0
 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
Example #7
0
 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)
Example #8
0
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
Example #9
0
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
Example #10
0
 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)
Example #11
0
 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)
Example #12
0
 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
Example #13
0
 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)
Example #14
0
 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)
Example #15
0
 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
Example #16
0
 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)
Example #17
0
 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)
Example #18
0
 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)
Example #19
0
 def test_iteration(self, device, tags):
     assert set(device.tags) == set(tags)
     assert all(pytest.is_unicode_string(t) for t in device.tags)
Example #20
0
 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())
Example #21
0
 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)
Example #22
0
 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)
Example #23
0
 def test_subsystem(self, device, device_data):
     assert device.subsystem == device_data.properties['SUBSYSTEM']
     assert pytest.is_unicode_string(device.subsystem)
Example #24
0
 def test_device_path(self, device, device_data):
     assert device.device_path == device_data.device_path
     assert pytest.is_unicode_string(device.device_path)
Example #25
0
 def test_device_path(self, context):
     assert pytest.is_unicode_string(context.device_path)
     assert context.device_path == '/dev'
Example #26
0
 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)
Example #27
0
 def test_subsystem(self, device, properties):
     assert device.subsystem == properties['SUBSYSTEM']
     assert pytest.is_unicode_string(device.subsystem)
Example #28
0
 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)
Example #29
0
 def test_subsystem(self, device, device_data):
     assert device.subsystem == device_data.properties["SUBSYSTEM"]
     assert pytest.is_unicode_string(device.subsystem)
Example #30
0
 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)
Example #31
0
 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)
Example #32
0
 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)
Example #33
0
 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)
Example #34
0
 def test_device_path(self, context):
     assert pytest.is_unicode_string(context.device_path)
     assert context.device_path == '/dev'
Example #35
0
 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)
Example #36
0
 def test_sys_path(self, device, sys_path):
     assert device.sys_path == sys_path
     assert pytest.is_unicode_string(device.sys_path)
Example #37
0
 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
Example #38
0
 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)
Example #39
0
 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
Example #40
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)
Example #41
0
 def test_sys_path(self, context):
     assert pytest.is_unicode_string(context.sys_path)
     assert context.sys_path == '/sys'
Example #42
0
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
Example #43
0
 def test_run_path(self, context):
     assert pytest.is_unicode_string(context.run_path)
     assert context.run_path == '/run/udev'
Example #44
0
 def test_device_path(self, device, device_data):
     assert device.device_path == device_data.device_path
     assert pytest.is_unicode_string(device.device_path)
Example #45
0
 def test_sys_path(self, context):
     assert pytest.is_unicode_string(context.sys_path)
     assert context.sys_path == '/sys'
Example #46
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)
Example #47
0
 def test_run_path(self, context):
     assert pytest.is_unicode_string(context.run_path)
     assert context.run_path == '/run/udev'
Example #48
0
 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