本文整理汇总了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
示例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)
示例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
示例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())
示例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())
示例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())
示例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())
示例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)
示例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
示例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
示例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)
示例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]
示例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)
示例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)
示例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)