# 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

    @given(_CONTEXT_STRATEGY, strategies.sampled_from(_DEVICE_DATA))
    @settings(max_examples=5)
    def test_device_number(self, a_context, device_datum):
        device = Devices.from_path(a_context, device_datum.device_path)
        assert device.device_number == device_datum.device_number

    @_UDEV_TEST(165, "test_is_initialized")
    @given(strategies.sampled_from(_DEVICES))
    @settings(max_examples=5)
    def test_is_initialized(self, a_device):
        assert isinstance(a_device.is_initialized, bool)

    @_UDEV_TEST(165, "test_is_initialized_mock")
    @given(strategies.sampled_from(_DEVICES))
    @settings(max_examples=5)
    def test_is_initialized_mock(self, a_device):
        funcname = "udev_device_get_is_initialized"
        spec = lambda d: None
        with mock.patch.object(a_device._libudev, funcname, autospec=spec) as func:
            func.return_value = False
            assert not a_device.is_initialized
            func.assert_called_once_with(a_device)

    @_UDEV_TEST(165, "test_time_since_initialized")
    @given(strategies.sampled_from(_DEVICES))
    @settings(max_examples=5)
    def test_time_since_initialized(self, a_device):
        assert isinstance(a_device.time_since_initialized, timedelta)


# 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


    @given(_CONTEXT_STRATEGY, strategies.sampled_from(_DEVICE_DATA))
    @settings(max_examples=5)
    def test_device_number(self, a_context, device_datum):
        device = Devices.from_path(a_context, device_datum.device_path)
        assert device.device_number == device_datum.device_number

    @_UDEV_TEST(165, "test_is_initialized")
    @given(strategies.sampled_from(_DEVICES))
    @settings(max_examples=5)
    def test_is_initialized(self, a_device):
        assert isinstance(a_device.is_initialized, bool)

    @_UDEV_TEST(165, "test_is_initialized_mock")
    @given(strategies.sampled_from(_DEVICES))
    @settings(max_examples=5)
    def test_is_initialized_mock(self, a_device):
        funcname = "udev_device_get_is_initialized"
        spec = lambda d: None
        with mock.patch.object(a_device._libudev, funcname, autospec=spec) as func:
            func.return_value = False
            assert not a_device.is_initialized
            func.assert_called_once_with(a_device)

    @_UDEV_TEST(165, "test_time_since_initialized")
    @given(strategies.sampled_from(_DEVICES))
    @settings(max_examples=5)
    def test_time_since_initialized(self, a_device):
        assert isinstance(a_device.time_since_initialized, timedelta)


    @_UDEV_TEST(165, "test_time_since_initialized_mock")