# Path: skipper/utils.py
# def get_subset(a, keys):
#     return dict((k, a[k]) for k in keys if k in a)
# 
# def find(array, properties):
#     keys = properties.keys()
#     for a in array:
#         dict_a = a
#         if hasattr(a, '__dict__'):
#             dict_a = a.__dict__
#         subset = get_subset(dict_a, keys)
#         if subset == properties:
#             return a
#     return None
# 
# def missing_keys(a, b):
#     return [k for k in a.keys() if k not in b.keys()]
# 
# def get_index(x, index):
#     """
#     Get the element at the index of the list or return None
#     >>> example = [1, 2]
#     >>> get_index(example, 1)
#     1
#     >>> get_index(example, 7)
#     None
#     """
#     if len(x) > index:
#         return x[index]
# 
# def extract_version(event):
#     """
#     Parses the output from docker --version for the version, e.g.
# 
#     >>> extract_version("Docker version 0.11.1, build fb99f99")
#     "0.11.1"
#     """
#     match = re.search(r'Docker version ([0-9\.]+),', event)
#     if match:
#         version = match.group(1)
#     return version


from skipper.utils import (
    get_subset, find, missing_keys, get_index, extract_version)


def test_get_subset():
    foo = {'a': 1, 'b': 2, 'c': 3}
    subset = get_subset(foo, ['a'])
    assert subset == {'a': 1}
    subset = get_subset(foo, ['a', 'b'])
    assert subset == {'a': 1, 'b': 2}


def test_find():
    looking_for = {'a': 1, 'match': True}
    array = [looking_for, {'b': 1}, {'a': 2}]

# Path: skipper/utils.py
# def get_subset(a, keys):
#     return dict((k, a[k]) for k in keys if k in a)
# 
# def find(array, properties):
#     keys = properties.keys()
#     for a in array:
#         dict_a = a
#         if hasattr(a, '__dict__'):
#             dict_a = a.__dict__
#         subset = get_subset(dict_a, keys)
#         if subset == properties:
#             return a
#     return None
# 
# def missing_keys(a, b):
#     return [k for k in a.keys() if k not in b.keys()]
# 
# def get_index(x, index):
#     """
#     Get the element at the index of the list or return None
#     >>> example = [1, 2]
#     >>> get_index(example, 1)
#     1
#     >>> get_index(example, 7)
#     None
#     """
#     if len(x) > index:
#         return x[index]
# 
# def extract_version(event):
#     """
#     Parses the output from docker --version for the version, e.g.
# 
#     >>> extract_version("Docker version 0.11.1, build fb99f99")
#     "0.11.1"
#     """
#     match = re.search(r'Docker version ([0-9\.]+),', event)
#     if match:
#         version = match.group(1)
#     return version


# Path: tests/test_utils.py
from skipper.utils import (
    get_subset, find, missing_keys, get_index, extract_version)



def test_get_subset():
    foo = {'a': 1, 'b': 2, 'c': 3}
    subset = get_subset(foo, ['a'])
    assert subset == {'a': 1}
    subset = get_subset(foo, ['a', 'b'])
    assert subset == {'a': 1, 'b': 2}


def test_find():
    looking_for = {'a': 1, 'match': True}
    array = [looking_for, {'b': 1}, {'a': 2}]

    match = find(array, {'a': 1})