當前位置: 首頁>>代碼示例>>Python>>正文


Python Device.from_path方法代碼示例

本文整理匯總了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)
開發者ID:csleex,項目名稱:pyudev,代碼行數:30,代碼來源:test_observer.py

示例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"
開發者ID:bjornarg,項目名稱:pyudev,代碼行數:10,代碼來源:test_device.py

示例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
開發者ID:rnixx,項目名稱:pyudev,代碼行數:10,代碼來源:_attributes_tests.py

示例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
開發者ID:csleex,項目名稱:pyudev,代碼行數:11,代碼來源:test_enumerate.py

示例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
開發者ID:dwlehman,項目名稱:pyudev,代碼行數:12,代碼來源:_attributes_tests.py

示例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
開發者ID:rnixx,項目名稱:pyudev,代碼行數:12,代碼來源:_attributes_tests.py

示例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)
開發者ID:dwlehman,項目名稱:pyudev,代碼行數:14,代碼來源:_attributes_tests.py

示例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
開發者ID:rnixx,項目名稱:pyudev,代碼行數:15,代碼來源:_attributes_tests.py

示例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)
開發者ID:dwlehman,項目名稱:pyudev,代碼行數:22,代碼來源:test_observer.py

示例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)
開發者ID:dwlehman,項目名稱:pyudev,代碼行數:6,代碼來源:test_observer.py

示例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)
開發者ID:cjmayo,項目名稱:pyudev,代碼行數:7,代碼來源:_tags_tests.py

示例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):
    """
開發者ID:cjmayo,項目名稱:pyudev,代碼行數:33,代碼來源:_constants.py

示例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')
開發者ID:csleex,項目名稱:pyudev,代碼行數:5,代碼來源:test_device.py

示例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)
開發者ID:csleex,項目名稱:pyudev,代碼行數:7,代碼來源:test_device.py

示例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)
開發者ID:bjornarg,項目名稱:pyudev,代碼行數:7,代碼來源:test_device.py


注:本文中的pyudev.Device.from_path方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。