当前位置: 首页>>代码示例>>Python>>正文


Python Devices.from_path方法代码示例

本文整理汇总了Python中pyudev.Devices.from_path方法的典型用法代码示例。如果您正苦于以下问题:Python Devices.from_path方法的具体用法?Python Devices.from_path怎么用?Python Devices.from_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyudev.Devices的用法示例。


在下文中一共展示了Devices.from_path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _check_device

# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_path [as 别名]
def _check_device(device):
    """
    Check that device exists by getting it.
    """
    try:
        Devices.from_path(_CONTEXT, device.sys_path)
        return True
    except DeviceNotFoundError:
        return False
开发者ID:chzhong,项目名称:pyudev,代码行数:11,代码来源:_constants.py

示例2: test_iteration_and_contains

# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_path [as 别名]
 def test_iteration_and_contains(self, a_context, device_datum):
     """
     Test that iteration yields all tags and contains checks them.
     """
     device = Devices.from_path(a_context, device_datum.device_path)
     assert frozenset(device.tags) == frozenset(device_datum.tags)
     assert all(is_unicode_string(tag) for tag in device.tags)
开发者ID:chzhong,项目名称:pyudev,代码行数:9,代码来源:_tags_tests.py

示例3: test_getitem_devname

# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_path [as 别名]
 def test_getitem_devname(self, a_context, device_datum):
     device = Devices.from_path(a_context, device_datum.device_path)
     data_devname = os.path.join(
         a_context.device_path, device_datum.properties['DEVNAME'])
     device_devname = \
        os.path.join(a_context.device_path, device.properties['DEVNAME'])
     assert device_devname == data_devname
开发者ID:chzhong,项目名称:pyudev,代码行数:9,代码来源:_device_tests.py

示例4: test_key_subset

# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_path [as 别名]
 def test_key_subset(self, a_context, device_datum):
     """
     Verify that the device contains all the keys in the device datum.
     """
     device = Devices.from_path(a_context, device_datum.device_path)
     assert frozenset(device_datum.properties.keys()) <= \
        frozenset(device.properties.keys())
开发者ID:chzhong,项目名称:pyudev,代码行数:9,代码来源:_device_tests.py

示例5: test_length

# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_path [as 别名]
 def test_length(self, a_context, device_datum):
     """
     Verify that the keys in the device and in the datum are equal.
     """
     device = Devices.from_path(a_context, device_datum.device_path)
     assert frozenset(device_datum.properties.keys()) == \
        frozenset(device.properties.keys())
开发者ID:chzhong,项目名称:pyudev,代码行数:9,代码来源:_device_tests.py

示例6: test_asstring

# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_path [as 别名]
 def test_asstring(self, a_context, device_datum):
     """
     Test that attribute exists for actual device and is unicode.
     """
     device = Devices.from_path(a_context, device_datum.device_path)
     assert all(is_unicode_string(device.attributes.asstring(key)) \
        for key in device_datum.attributes.keys())
开发者ID:chzhong,项目名称:pyudev,代码行数:9,代码来源:_attributes_tests.py

示例7: test_getitem

# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_path [as 别名]
 def test_getitem(self, a_context, device_datum):
     """
     Test that attribute value exists and is instance of bytes.
     """
     device = Devices.from_path(a_context, device_datum.device_path)
     assert all(isinstance(device.attributes.get(key), bytes) \
        for key in device_datum.attributes.keys())
开发者ID:chzhong,项目名称:pyudev,代码行数:9,代码来源:_attributes_tests.py

示例8: test_events_real

# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_path [as 别名]
    def test_events_real(self, context, monitor):
        # make sure that the module is unloaded initially
        pytest.unload_dummy()
        monitor.filter_by('net')
        monitor.start()
        self.prepare_test(monitor)
        # setup signal handlers
        event_callback = mock.Mock(side_effect=self.stop_when_done)
        added_callback = mock.Mock(side_effect=self.stop_when_done)
        removed_callback = mock.Mock(side_effect=self.stop_when_done)
        self.connect_signal(event_callback)
        self.connect_signal(added_callback, action='add')
        self.connect_signal(removed_callback, action='remove')

        # test add event
        self.start_event_loop(pytest.load_dummy)
        device = Devices.from_path(context, '/devices/virtual/net/dummy0')
        event_callback.assert_called_with('add', device)
        added_callback.assert_called_with(device)
        assert not removed_callback.called

        for callback in (event_callback, added_callback, removed_callback):
            callback.reset_mock()

        self.start_event_loop(pytest.unload_dummy)
        event_callback.assert_called_with('remove', device)
        assert not added_callback.called
        removed_callback.assert_called_with(device)
开发者ID:chzhong,项目名称:pyudev,代码行数:30,代码来源:test_observer_deprecated.py

示例9: test_iteration

# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_path [as 别名]
 def test_iteration(self, a_context, device_datum):
     device = Devices.from_path(a_context, device_datum.device_path)
     for property in device:
         assert is_unicode_string(property)
     # test that iteration really yields all properties
     device_properties = set(device)
     for property in device_datum.properties:
         assert property in device_properties
开发者ID:dwlehman,项目名称:pyudev,代码行数:10,代码来源:_device_tests.py

示例10: test_asint

# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_path [as 别名]
 def test_asint(self, a_context, device_datum):
     device = Devices.from_path(a_context, device_datum.device_path)
     for property, value in device_datum.properties.items():
         try:
             value = int(value)
         except ValueError:
             with pytest.raises(ValueError):
                 device.asint(property)
         else:
             assert device.asint(property) == value
开发者ID:dwlehman,项目名称:pyudev,代码行数:12,代码来源:_device_tests.py

示例11: test_asint

# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_path [as 别名]
 def test_asint(self, a_context, device_datum):
     """
     Test that integer result is an int or ValueError raised.
     """
     device = Devices.from_path(a_context, device_datum.device_path)
     for key, value in device_datum.attributes.items():
         try:
             value = int(value)
         except ValueError:
             with pytest.raises(ValueError):
                 device.attributes.asint(key)
开发者ID:chzhong,项目名称:pyudev,代码行数:13,代码来源:_attributes_tests.py

示例12: test_getitem

# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_path [as 别名]
 def test_getitem(self, a_context, device_datum):
     device = Devices.from_path(a_context, device_datum.device_path)
     for prop in device_datum.properties:
         if prop == 'DEVLINKS':
             assert sorted(device.properties[prop].split(),) == \
                sorted(device_datum.properties[prop].split(),)
         elif prop == 'TAGS':
             assert sorted(device.properties[prop].split(':'),) == \
                sorted(device_datum.properties[prop].split(':'),)
         else:
             assert device.properties[prop] == device_datum.properties[prop]
开发者ID:chzhong,项目名称:pyudev,代码行数:13,代码来源:_device_tests.py

示例13: test_asbool

# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_path [as 别名]
 def test_asbool(self, a_context, device_datum):
     """
     Test that bool result is a bool or ValueError raised.
     """
     device = Devices.from_path(a_context, device_datum.device_path)
     for key, value in device_datum.attributes.items():
         if value in ('0', '1'):
             assert device.attributes.asbool(key) in (False, True)
         else:
             with pytest.raises(ValueError):
                 device.attributes.asbool(key)
开发者ID:chzhong,项目名称:pyudev,代码行数:13,代码来源:_attributes_tests.py

示例14: test_asbool

# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_path [as 别名]
 def test_asbool(self, a_context, device_datum):
     device = Devices.from_path(a_context, device_datum.device_path)
     for prop, value in device_datum.properties.items():
         if value == '1':
             assert device.asbool(prop)
         elif value == '0':
             assert not device.asbool(prop)
         else:
             with pytest.raises(ValueError) as exc_info:
                 device.asbool(prop)
             message = 'Not a boolean value: {0!r}'
             assert str(exc_info.value) == message.format(value)
开发者ID:dwlehman,项目名称:pyudev,代码行数:14,代码来源:_device_tests.py

示例15: test_asbool

# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_path [as 别名]
    def test_asbool(self, a_context, device_datum):
        """
        Test that values of 1 and 0 get properly interpreted as bool
        and that all other values raise a ValueError.

        :param Context a_context: libudev context
        :param device_datum: a device datum
        """
        device = Devices.from_path(a_context, device_datum.device_path)
        for prop, value in device_datum.properties.items():
            if value == '1':
                assert device.properties.asbool(prop)
            elif value == '0':
                assert not device.properties.asbool(prop)
            else:
                with pytest.raises(ValueError) as exc_info:
                    device.properties.asbool(prop)
开发者ID:chzhong,项目名称:pyudev,代码行数:19,代码来源:_device_tests.py


注:本文中的pyudev.Devices.from_path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。