# Path: tests/_constants.py
# _CONTEXT = Context()
# 
# _CONTEXT_STRATEGY = strategies.just(_CONTEXT)
# 
# _DEVICE_DATA = [d for d in udev.DeviceDatabase.db()]
# 
# _DEVICES = [Devices.from_path(_CONTEXT, d.device_path) for d in _DEVICE_DATA]
# 
# 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)
#     )
# 
# Path: tests/utils/misc.py
# def is_unicode_string(value):
#     """
#     Return ``True``, if ``value`` is of a real unicode string type
#     (``unicode`` in python 2, ``str`` in python 3), ``False`` otherwise.
#     """
#     return isinstance(value, str)


import gc
import operator
import os
import re
import pytest
    import mock
from datetime import timedelta
from hypothesis import given, settings, strategies
from pyudev import Device, Devices
from pyudev.device import Attributes, Tags
from .._constants import _CONTEXT, _CONTEXT_STRATEGY, _DEVICE_DATA, _DEVICES, _UDEV_TEST
from ..utils import is_unicode_string
    from unittest import mock
        assert device.device_path == device_datum.device_path
        assert is_unicode_string(device.device_path)

    @given(_CONTEXT_STRATEGY, strategies.sampled_from(_DEVICE_DATA))
    @settings(max_examples=5)
    def test_subsystem(self, a_context, device_datum):
        device = Devices.from_path(a_context, device_datum.device_path)
        assert device.subsystem == device_datum.properties["SUBSYSTEM"]
        assert is_unicode_string(device.subsystem)

    @given(strategies.sampled_from(_DEVICES))
    @settings(max_examples=5)
    def test_device_sys_name(self, a_device):
        assert a_device.sys_name.replace("/", "!") == os.path.basename(
            a_device.device_path
        )
        assert is_unicode_string(a_device.sys_name)

    @given(strategies.sampled_from(_DEVICES))
    @settings(max_examples=5)
    def test_sys_number(self, a_device):
        match = re.search(r"\d+$", a_device.sys_name)
        # filter out devices with completely nummeric names (first character
        # doesn't count according to the implementation of libudev)
        if match and match.start() > 1:
            assert a_device.sys_number == match.group(0)
            assert is_unicode_string(a_device.sys_name)
        else:
            assert a_device.sys_number is None


# Path: tests/_constants.py
# _CONTEXT = Context()
# 
# _CONTEXT_STRATEGY = strategies.just(_CONTEXT)
# 
# _DEVICE_DATA = [d for d in udev.DeviceDatabase.db()]
# 
# _DEVICES = [Devices.from_path(_CONTEXT, d.device_path) for d in _DEVICE_DATA]
# 
# 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)
#     )
# 
# Path: tests/utils/misc.py
# def is_unicode_string(value):
#     """
#     Return ``True``, if ``value`` is of a real unicode string type
#     (``unicode`` in python 2, ``str`` in python 3), ``False`` otherwise.
#     """
#     return isinstance(value, str)


# Path: tests/_device_tests/_device_tests.py
import gc
import operator
import os
import re
import pytest
    import mock
from datetime import timedelta
from hypothesis import given, settings, strategies
from pyudev import Device, Devices
from pyudev.device import Attributes, Tags
from .._constants import _CONTEXT, _CONTEXT_STRATEGY, _DEVICE_DATA, _DEVICES, _UDEV_TEST
from ..utils import is_unicode_string
    from unittest import mock

        assert device.device_path == device_datum.device_path
        assert is_unicode_string(device.device_path)

    @given(_CONTEXT_STRATEGY, strategies.sampled_from(_DEVICE_DATA))
    @settings(max_examples=5)
    def test_subsystem(self, a_context, device_datum):
        device = Devices.from_path(a_context, device_datum.device_path)
        assert device.subsystem == device_datum.properties["SUBSYSTEM"]
        assert is_unicode_string(device.subsystem)

    @given(strategies.sampled_from(_DEVICES))
    @settings(max_examples=5)
    def test_device_sys_name(self, a_device):
        assert a_device.sys_name.replace("/", "!") == os.path.basename(
            a_device.device_path
        )
        assert is_unicode_string(a_device.sys_name)

    @given(strategies.sampled_from(_DEVICES))
    @settings(max_examples=5)
    def test_sys_number(self, a_device):
        match = re.search(r"\d+$", a_device.sys_name)
        # filter out devices with completely nummeric names (first character
        # doesn't count according to the implementation of libudev)
        if match and match.start() > 1:
            assert a_device.sys_number == match.group(0)
            assert is_unicode_string(a_device.sys_name)
        else:
            assert a_device.sys_number is None


    @given(_CONTEXT_STRATEGY, strategies.sampled_from(_DEVICE_DATA))