本文整理汇总了Python中pyudev.Devices.from_device_number方法的典型用法代码示例。如果您正苦于以下问题:Python Devices.from_device_number方法的具体用法?Python Devices.from_device_number怎么用?Python Devices.from_device_number使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyudev.Devices
的用法示例。
在下文中一共展示了Devices.from_device_number方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_device_number
# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_device_number [as 别名]
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
示例2: test_from_device_number_wrong_type
# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_device_number [as 别名]
def test_from_device_number_wrong_type(
self,
a_context,
device_datum
):
mode = os.stat(device_datum.device_node).st_mode
# deliberately use the wrong type here to cause either failure
# or at least device mismatch
typ = 'char' if stat.S_ISBLK(mode) else 'block'
try:
# this either fails, in which case the caught exception is
# raised, or succeeds, but returns a wrong device
# (device numbers are not unique across device types)
device = Devices.from_device_number(
a_context, typ, device_datum.device_number)
# if it succeeds, the resulting device must not match the
# one, we are actually looking for!
assert device.device_path != device_datum.device_path
except DeviceNotFoundByNumberError as error:
# check the correctness of the exception attributes
assert error.device_type == typ
assert error.device_number == device_datum.device_number
示例3: test_from_device_number_invalid_type
# 需要导入模块: from pyudev import Devices [as 别名]
# 或者: from pyudev.Devices import from_device_number [as 别名]
def test_from_device_number_invalid_type(self, a_context):
with pytest.raises(DeviceNotFoundByNumberError):
Devices.from_device_number(a_context, 'foobar', 100)