• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pyudev.Devices类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_from_sys_path_device_not_found

 def test_from_sys_path_device_not_found(self, a_context):
     sys_path = 'there_will_not_be_such_a_device'
     with pytest.raises(DeviceNotFoundAtPathError) as exc_info:
         Devices.from_sys_path(a_context, sys_path)
     error = exc_info.value
     assert error.sys_path == sys_path
     assert str(error) == 'No device at {0!r}'.format(sys_path)
开发者ID:cjmayo,项目名称:pyudev,代码行数:7,代码来源:_devices_tests.py


示例2: test_from_device_file_no_device_file

 def test_from_device_file_no_device_file(self, tmpdir, a_context):
     filename = tmpdir.join('test')
     filename.ensure(file=True)
     with pytest.raises(DeviceNotFoundByFileError) as excinfo:
         Devices.from_device_file(a_context, str(filename))
     message = 'not a device file: {0!r}'.format(str(filename))
     assert str(excinfo.value) == message
开发者ID:cjmayo,项目名称:pyudev,代码行数:7,代码来源:_devices_tests.py


示例3: test_from_name_nonexisting_subsystem

 def test_from_name_nonexisting_subsystem(self, a_context):
     with pytest.raises(DeviceNotFoundByNameError) as exc_info:
         Devices.from_name(a_context, 'no_such_subsystem', 'foobar')
     error = exc_info.value
     assert error.subsystem == 'no_such_subsystem'
     assert error.sys_name == 'foobar'
     assert str(error) == 'No device {0!r} in {1!r}'.format(
         error.sys_name, error.subsystem)
开发者ID:cjmayo,项目名称:pyudev,代码行数:8,代码来源:_devices_tests.py


示例4: test_from_name_is_path

        def test_from_name_is_path(self, a_context, a_device):
            """
            Lookup using a sys_name which is actually a path should always fail.

            See: rhbz#1263351.
            """
            with pytest.raises(DeviceNotFoundByNameError):
                Devices.from_name(a_context, a_device.subsystem, a_device.sys_name)
开发者ID:dwlehman,项目名称:pyudev,代码行数:8,代码来源:_devices_tests.py


示例5: test_from_device_file_non_existing

 def test_from_device_file_non_existing(self, tmpdir, a_context):
     """
     Test that an OSError is raised when constructing a ``Device`` from
     a file that does not actually exist.
     """
     filename = tmpdir.join('test_from_device_file_non_existing')
     assert not tmpdir.check(file=True)
     with pytest.raises(DeviceNotFoundByFileError):
         Devices.from_device_file(a_context, str(filename))
开发者ID:cjmayo,项目名称:pyudev,代码行数:9,代码来源:_devices_tests.py


示例6: _check_device

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,代码行数:9,代码来源:_constants.py


示例7: test_getitem_devname

 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,代码行数:7,代码来源:_device_tests.py


示例8: test_key_subset

 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,代码行数:7,代码来源:_device_tests.py


示例9: test_length

 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,代码行数:7,代码来源:_device_tests.py


示例10: test_from_kernel_device

 def test_from_kernel_device(self, a_context, entry):
     """
     Test that kernel devices can be obtained.
     """
     kernel_device = entry['_KERNEL_DEVICE']
     device = Devices.from_kernel_device(a_context, kernel_device)
     assert device is not None
开发者ID:dwlehman,项目名称:pyudev,代码行数:7,代码来源:_devices_tests.py


示例11: test_asstring

 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,代码行数:7,代码来源:_attributes_tests.py


示例12: test_getitem

 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,代码行数:7,代码来源:_attributes_tests.py


示例13: test_iteration_and_contains

 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,代码行数:7,代码来源:_tags_tests.py


示例14: test_events_real

    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,代码行数:28,代码来源:test_observer_deprecated.py


示例15: test_from_device_file

 def test_from_device_file(self, a_context, device_datum):
     device = Devices.from_device_file(
        a_context,
        device_datum.device_node
     )
     assert device.device_node == device_datum.device_node
     assert device.device_path == device_datum.device_path
开发者ID:cjmayo,项目名称:pyudev,代码行数:7,代码来源:_devices_tests.py


示例16: test_iteration

 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,代码行数:8,代码来源:_device_tests.py


示例17: test_from_device_number

 def test_from_device_number(self, a_context, device_datum):
     mode = os.stat(device_datum.device_node).st_mode
     typ = 'block' if stat.S_ISBLK(mode) else 'char'
     device = Devices.from_device_number(
         a_context, typ, device_datum.device_number)
     assert device.device_number == device_datum.device_number
     # make sure, we are really referring to the same device
     assert device.device_path == device_datum.device_path
开发者ID:cjmayo,项目名称:pyudev,代码行数:8,代码来源:_devices_tests.py


示例18: test_from_journal_name

 def test_from_journal_name(self, a_context, entry):
     """
     Test that kernel subsystem combined with udev sysname yields
     a device.
     """
     udev_sysname = entry['_UDEV_SYSNAME']
     subsystem = entry['_KERNEL_SUBSYSTEM']
     device = Devices.from_name(a_context, subsystem, udev_sysname)
     assert device is not None
开发者ID:dwlehman,项目名称:pyudev,代码行数:9,代码来源:_devices_tests.py


示例19: test_asint

 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,代码行数:10,代码来源:_device_tests.py


示例20: test_from_name

 def test_from_name(self, a_context, a_device):
     """
     Test that getting a new device based on the name and subsystem
     yields an equivalent device.
     """
     new_device = Devices.from_name(
        a_context,
        a_device.subsystem,
        a_device.sys_name
     )
     assert new_device == a_device
开发者ID:cjmayo,项目名称:pyudev,代码行数:11,代码来源:_devices_tests.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyudev.Monitor类代码示例发布时间:2022-05-27
下一篇:
Python pyudev.Device类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap