# Path: aioconsul/util.py
# def extract_attr(obj, *, keys):
#     if isinstance(obj, Mapping):
#         for key in keys:
#             if key in obj:
#                 return obj[key]
#         raise TypeError("%s not found in obj %s" % (keys, obj))
#     return obj
# 
# def extract_pattern(obj):
#     """Extract pattern from str or re.compile object
# 
#     Returns:
#         str: Extracted pattern
#     """
#     if obj is not None:
#         return getattr(obj, 'pattern', obj)
#     return obj


import pytest
import re
from aioconsul.util import extract_attr, extract_pattern


@pytest.mark.parametrize("input, keys, output", [
    (1, ["foo"], 1),
    ({"foo": 1}, ["foo"], 1)
])
def test_extract(input, keys, output):
    assert extract_attr(input, keys=keys) == output


@pytest.mark.parametrize("input, keys", [
    ({"foo": 1}, ["bar"]),
])
def test_extract_error(input, keys):
    with pytest.raises(TypeError):
        extract_attr(input, keys=keys)


@pytest.mark.parametrize("input, output", [
    ("foo", "foo"),
    (re.compile("foo"), "foo")
])
def test_extract_pattern(input, output):

# Path: aioconsul/util.py
# def extract_attr(obj, *, keys):
#     if isinstance(obj, Mapping):
#         for key in keys:
#             if key in obj:
#                 return obj[key]
#         raise TypeError("%s not found in obj %s" % (keys, obj))
#     return obj
# 
# def extract_pattern(obj):
#     """Extract pattern from str or re.compile object
# 
#     Returns:
#         str: Extracted pattern
#     """
#     if obj is not None:
#         return getattr(obj, 'pattern', obj)
#     return obj


# Path: tests/test_util.py
import pytest
import re
from aioconsul.util import extract_attr, extract_pattern



@pytest.mark.parametrize("input, keys, output", [
    (1, ["foo"], 1),
    ({"foo": 1}, ["foo"], 1)
])
def test_extract(input, keys, output):
    assert extract_attr(input, keys=keys) == output


@pytest.mark.parametrize("input, keys", [
    ({"foo": 1}, ["bar"]),
])
def test_extract_error(input, keys):
    with pytest.raises(TypeError):
        extract_attr(input, keys=keys)


@pytest.mark.parametrize("input, output", [
    ("foo", "foo"),
    (re.compile("foo"), "foo")
])
def test_extract_pattern(input, output):

    assert extract_pattern(input) == output