本文整理匯總了Python中pyudev.Device.from_path方法的典型用法代碼示例。如果您正苦於以下問題:Python Device.from_path方法的具體用法?Python Device.from_path怎麽用?Python Device.from_path使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyudev.Device
的用法示例。
在下文中一共展示了Device.from_path方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_events_real
# 需要導入模塊: from pyudev import Device [as 別名]
# 或者: from pyudev.Device 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(side_effect=self.stop_when_done)
added_callback = Mock(side_effect=self.stop_when_done)
removed_callback = 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 = Device.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 mock in (event_callback, added_callback, removed_callback):
mock.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)
示例2: test_device_ordering
# 需要導入模塊: from pyudev import Device [as 別名]
# 或者: from pyudev.Device import from_path [as 別名]
def test_device_ordering(self, context, operator):
try:
device = Device.from_path(context, "/devices/platform")
except DeviceNotFoundAtPathError:
pytest.skip("device not found")
with pytest.raises(TypeError) as exc_info:
operator(device, device)
assert str(exc_info.value) == "Device not orderable"
示例3: test_asstring
# 需要導入模塊: from pyudev import Device [as 別名]
# 或者: from pyudev.Device import from_path [as 別名]
def test_asstring(self, a_context, device_datum):
"""
Test that string value agrees with cli value and is unicode.
"""
device = Device.from_path(a_context, device_datum.device_path)
for key, value in non_volatile_attributes(device_datum.attributes):
assert is_unicode_string(device.attributes.asstring(key))
assert device.attributes.asstring(key) == value
示例4: test_match_parent
# 需要導入模塊: from pyudev import Device [as 別名]
# 或者: from pyudev.Device import from_path [as 別名]
def test_match_parent(self, context, device_data):
device = Device.from_path(context, device_data.device_path)
parent = device.parent
if parent is None:
pytest.skip('Device {0!r} has no parent'.format(device))
else:
children = list(context.list_devices().match_parent(parent))
assert device in children
assert parent in children
示例5: test_asint
# 需要導入模塊: from pyudev import Device [as 別名]
# 或者: from pyudev.Device import from_path [as 別名]
def test_asint(self, a_context, device_datum):
device = Device.from_path(a_context, device_datum.device_path)
for key, value in self.non_volatile_items(device_datum.attributes):
try:
value = int(value)
except ValueError:
with pytest.raises(ValueError):
device.attributes.asint(key)
else:
assert device.attributes.asint(key) == value
示例6: test_getitem
# 需要導入模塊: from pyudev import Device [as 別名]
# 或者: from pyudev.Device import from_path [as 別名]
def test_getitem(self, a_context, device_datum):
"""
Test that attribute value is the same as datum attribute value and
is instance of bytes.
"""
device = Device.from_path(a_context, device_datum.device_path)
for key, value in non_volatile_attributes(device_datum.attributes):
raw_value = value.encode(sys.getfilesystemencoding())
assert isinstance(device.attributes.get(key), bytes)
assert device.attributes.get(key) == raw_value
示例7: test_asbool
# 需要導入模塊: from pyudev import Device [as 別名]
# 或者: from pyudev.Device import from_path [as 別名]
def test_asbool(self, a_context, device_datum):
device = Device.from_path(a_context, device_datum.device_path)
for key, value in self.non_volatile_items(device_datum.attributes):
if value == '1':
assert device.attributes.asbool(key)
elif value == '0':
assert not device.attributes.asbool(key)
else:
with pytest.raises(ValueError) as exc_info:
device.attributes.asbool(key)
message = 'Not a boolean value:'
assert str(exc_info.value).startswith(message)
示例8: test_asint
# 需要導入模塊: from pyudev import Device [as 別名]
# 或者: from pyudev.Device import from_path [as 別名]
def test_asint(self, a_context, device_datum):
"""
Test that integer result is an int or ValueError raised.
"""
device = Device.from_path(a_context, device_datum.device_path)
for key, value in non_volatile_attributes(device_datum.attributes):
try:
value = int(value)
except ValueError:
with pytest.raises(ValueError):
device.attributes.asint(key)
else:
assert device.attributes.asint(key) == value
示例9: test_events_real
# 需要導入模塊: from pyudev import Device [as 別名]
# 或者: from pyudev.Device 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=lambda *args: self.stop_event_loop())
self.connect_signal(event_callback)
# test add event
self.start_event_loop(pytest.load_dummy)
device = Device.from_path(context, '/devices/virtual/net/dummy0')
event_callback.assert_called_with(device)
event_callback.reset_mock()
self.start_event_loop(pytest.unload_dummy)
event_callback.assert_called_with(device)
示例10: fake_monitor_device
# 需要導入模塊: from pyudev import Device [as 別名]
# 或者: from pyudev.Device import from_path [as 別名]
def fake_monitor_device(request):
context = request.getfuncargvalue('context')
device = get_device_sample(DeviceDatabase.db(), sample_size=1)[0]
return Device.from_path(context, device.device_path)
示例11: test_iteration
# 需要導入模塊: from pyudev import Device [as 別名]
# 或者: from pyudev.Device import from_path [as 別名]
def test_iteration(self, a_context, device_datum):
device = Device.from_path(a_context, device_datum.device_path)
assert set(device.tags) == set(device_datum.tags)
for tag in device.tags:
assert is_unicode_string(tag)
示例12: Context
# 需要導入模塊: from pyudev import Device [as 別名]
# 或者: from pyudev.Device import from_path [as 別名]
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from hypothesis import strategies
import pytest
from pyudev import Context
from pyudev import Device
from .utils import udev
_CONTEXT = Context()
_DEVICE_DATA = list(udev.get_device_sample(udev.DeviceDatabase.db()))
_DEVICES = [Device.from_path(_CONTEXT, d.device_path) for d in _DEVICE_DATA]
_CONTEXT_STRATEGY = strategies.just(_CONTEXT)
_UDEV_VERSION = int(udev.UDevAdm.adm().query_udev_version())
def _UDEV_TEST(version, node=None): # pylint: disable=invalid-name
fmt_str = "%s: udev version must be at least %s, is %s"
return pytest.mark.skipif(
_UDEV_VERSION < version,
reason=fmt_str % (node, version, _UDEV_VERSION)
)
_VOLATILE_ATTRIBUTES = ('energy_uj', 'power_on_acct')
def non_volatile_attributes(attributes):
"""
示例13: test_from_path_strips_leading_slash
# 需要導入模塊: from pyudev import Device [as 別名]
# 或者: from pyudev.Device import from_path [as 別名]
def test_from_path_strips_leading_slash(self, context):
assert Device.from_path(context, 'devices/platform') == \
Device.from_path(context, '/devices/platform')
示例14: pytest_funcarg__device
# 需要導入模塊: from pyudev import Device [as 別名]
# 或者: from pyudev.Device import from_path [as 別名]
def pytest_funcarg__device(request):
device_data = getattr(request, 'param', None) or \
request.getfuncargvalue('device_data')
context = request.getfuncargvalue('context')
return Device.from_path(context, device_data.device_path)
示例15: test_from_path
# 需要導入模塊: from pyudev import Device [as 別名]
# 或者: from pyudev.Device import from_path [as 別名]
def test_from_path(self, context, device_data):
device = Device.from_path(context, device_data.device_path)
assert device is not None
assert device == Device.from_sys_path(context, device_data.sys_path)
assert device == Device.from_path(context, device_data.sys_path)