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


Python pyudev.Devices类代码示例

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


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


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