# Path: tests/_constants.py
# _ATTRIBUTE_STRATEGY = _ATTRIBUTES_STRATEGY.flatmap(
#     lambda attrs: strategies.sampled_from([a for a in attrs.available_attributes]).map(
#         lambda key: (key, attrs.get(key))
#     )
# )
# 
# _CONTEXT_STRATEGY = strategies.just(_CONTEXT)
# 
# _MATCH_PROPERTY_STRATEGY = _PROPERTY_STRATEGY.filter(lambda p: p[0][-4:] != "_ENC")
# 
# _SUBSYSTEM_STRATEGY = device_strategy().map(lambda x: x.subsystem)
# 
# _SYSNAME_STRATEGY = device_strategy().map(lambda x: x.sys_name)
# 
# _TAG_STRATEGY = _TAGS_STRATEGY.filter(lambda t: t != []).flatmap(
#     strategies.sampled_from
# )
# 
# 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)
#     )
# 
# def device_strategy(require_existing=True, filter_func=lambda x: True):
#     """
#     Strategy that yields filtered devices.
# 
#     The devices are filtered before being sampled to reduce the number
#     of health failures.
# 
#     :param bool require_existing: at the very last, verify existance
#     :param filter_func: a function to be used as a filter
#     :type filter_func: Device -> bool
#     """
#     strategy = strategies.sampled_from(
#         [x for x in _CONTEXT.list_devices() if filter_func(x)]
#     )
# 
#     if require_existing:
#         strategy = strategy.filter(_check_device)
# 
#     return strategy
# 
# Path: tests/utils/misc.py
# def failed_health_check_wrapper(func):
#     """
#     If the test fails a health check, calls skip().
#     """
# 
#     @wraps(func)
#     def the_func(*args):
#         """
#         Catch a hypothesis FailedHealthCheck exception and log it as a skip.
#         """
#         try:
#             func(*args)
#         except FailedHealthCheck:
#             pytest.skip(
#                 "failed health check for %s() (%s: %s)"
#                 % (
#                     func.__code__.co_name,
#                     func.__code__.co_filename,
#                     func.__code__.co_firstlineno,
#                 )
#             )
# 
#     return the_func


from hypothesis import given, settings, strategies
from ._constants import (
    _ATTRIBUTE_STRATEGY,
    _CONTEXT_STRATEGY,
    _MATCH_PROPERTY_STRATEGY,
    _SUBSYSTEM_STRATEGY,
    _SYSNAME_STRATEGY,
    _TAG_STRATEGY,
    _UDEV_TEST,
    device_strategy,
)
from .utils import failed_health_check_wrapper
    from unittest import mock
    import mock
        )

    @failed_health_check_wrapper
    @given(
        _CONTEXT_STRATEGY, device_strategy(filter_func=lambda d: d.parent is not None)
    )
    @settings(max_examples=5)
    def test_match_parent(self, context, device):
        """
        For a given device, verify that it is in its parent's children.

        Verify that the parent is also among the device's children,
        unless the parent lacks a subsystem

        See: rhbz#1255191
        """
        parent = device.parent
        children = list(context.list_devices().match_parent(parent))
        assert device in children


class TestEnumeratorMatchCombinations(object):
    """
    Test combinations of matches.
    """

    @given(
        _CONTEXT_STRATEGY,
        _SUBSYSTEM_STRATEGY,
        _SYSNAME_STRATEGY,

# Path: tests/_constants.py
# _ATTRIBUTE_STRATEGY = _ATTRIBUTES_STRATEGY.flatmap(
#     lambda attrs: strategies.sampled_from([a for a in attrs.available_attributes]).map(
#         lambda key: (key, attrs.get(key))
#     )
# )
# 
# _CONTEXT_STRATEGY = strategies.just(_CONTEXT)
# 
# _MATCH_PROPERTY_STRATEGY = _PROPERTY_STRATEGY.filter(lambda p: p[0][-4:] != "_ENC")
# 
# _SUBSYSTEM_STRATEGY = device_strategy().map(lambda x: x.subsystem)
# 
# _SYSNAME_STRATEGY = device_strategy().map(lambda x: x.sys_name)
# 
# _TAG_STRATEGY = _TAGS_STRATEGY.filter(lambda t: t != []).flatmap(
#     strategies.sampled_from
# )
# 
# 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)
#     )
# 
# def device_strategy(require_existing=True, filter_func=lambda x: True):
#     """
#     Strategy that yields filtered devices.
# 
#     The devices are filtered before being sampled to reduce the number
#     of health failures.
# 
#     :param bool require_existing: at the very last, verify existance
#     :param filter_func: a function to be used as a filter
#     :type filter_func: Device -> bool
#     """
#     strategy = strategies.sampled_from(
#         [x for x in _CONTEXT.list_devices() if filter_func(x)]
#     )
# 
#     if require_existing:
#         strategy = strategy.filter(_check_device)
# 
#     return strategy
# 
# Path: tests/utils/misc.py
# def failed_health_check_wrapper(func):
#     """
#     If the test fails a health check, calls skip().
#     """
# 
#     @wraps(func)
#     def the_func(*args):
#         """
#         Catch a hypothesis FailedHealthCheck exception and log it as a skip.
#         """
#         try:
#             func(*args)
#         except FailedHealthCheck:
#             pytest.skip(
#                 "failed health check for %s() (%s: %s)"
#                 % (
#                     func.__code__.co_name,
#                     func.__code__.co_filename,
#                     func.__code__.co_firstlineno,
#                 )
#             )
# 
#     return the_func


# Path: tests/test_enumerate.py
from hypothesis import given, settings, strategies
from ._constants import (
    _ATTRIBUTE_STRATEGY,
    _CONTEXT_STRATEGY,
    _MATCH_PROPERTY_STRATEGY,
    _SUBSYSTEM_STRATEGY,
    _SYSNAME_STRATEGY,
    _TAG_STRATEGY,
    _UDEV_TEST,
    device_strategy,
)
from .utils import failed_health_check_wrapper
    from unittest import mock
    import mock

        )

    @failed_health_check_wrapper
    @given(
        _CONTEXT_STRATEGY, device_strategy(filter_func=lambda d: d.parent is not None)
    )
    @settings(max_examples=5)
    def test_match_parent(self, context, device):
        """
        For a given device, verify that it is in its parent's children.

        Verify that the parent is also among the device's children,
        unless the parent lacks a subsystem

        See: rhbz#1255191
        """
        parent = device.parent
        children = list(context.list_devices().match_parent(parent))
        assert device in children


class TestEnumeratorMatchCombinations(object):
    """
    Test combinations of matches.
    """

    @given(
        _CONTEXT_STRATEGY,
        _SUBSYSTEM_STRATEGY,
        _SYSNAME_STRATEGY,

        _MATCH_PROPERTY_STRATEGY,