# 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
        funcname = "udev_device_get_usec_since_initialized"
        spec = lambda d: None
        with mock.patch.object(a_device._libudev, funcname, autospec=spec) as func:
            func.return_value = 100
            assert a_device.time_since_initialized.microseconds == 100
            func.assert_called_once_with(a_device)

    @given(_CONTEXT_STRATEGY, strategies.sampled_from(_DEVICE_DATA))
    @settings(max_examples=5)
    def test_links(self, a_context, device_datum):
        device = Devices.from_path(a_context, device_datum.device_path)
        assert sorted(device.device_links) == sorted(device_datum.device_links)
        for link in device.device_links:
            assert is_unicode_string(link)

    @given(strategies.sampled_from(_DEVICES))
    @settings(max_examples=5)
    def test_action(self, a_device):
        assert a_device.action is None

    @given(strategies.sampled_from(_DEVICES))
    @settings(max_examples=5)
    def test_action_mock(self, a_device):
        funcname = "udev_device_get_action"
        spec = lambda d: None
        with mock.patch.object(a_device._libudev, funcname, autospec=spec) as func:
            func.return_value = b"spam"
            assert a_device.action == "spam"
            func.assert_called_once_with(a_device)
            func.reset_mock()

# 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

        funcname = "udev_device_get_usec_since_initialized"
        spec = lambda d: None
        with mock.patch.object(a_device._libudev, funcname, autospec=spec) as func:
            func.return_value = 100
            assert a_device.time_since_initialized.microseconds == 100
            func.assert_called_once_with(a_device)

    @given(_CONTEXT_STRATEGY, strategies.sampled_from(_DEVICE_DATA))
    @settings(max_examples=5)
    def test_links(self, a_context, device_datum):
        device = Devices.from_path(a_context, device_datum.device_path)
        assert sorted(device.device_links) == sorted(device_datum.device_links)
        for link in device.device_links:
            assert is_unicode_string(link)

    @given(strategies.sampled_from(_DEVICES))
    @settings(max_examples=5)
    def test_action(self, a_device):
        assert a_device.action is None

    @given(strategies.sampled_from(_DEVICES))
    @settings(max_examples=5)
    def test_action_mock(self, a_device):
        funcname = "udev_device_get_action"
        spec = lambda d: None
        with mock.patch.object(a_device._libudev, funcname, autospec=spec) as func:
            func.return_value = b"spam"
            assert a_device.action == "spam"
            func.assert_called_once_with(a_device)
            func.reset_mock()

            assert is_unicode_string(a_device.action)