# Path: ckan_api_client/tests/utils/diff.py
# def diff_mappings(left, right):
#     """
#     Compares two mappings, returning a dictionary of
#     sets of keys describing differences.
# 
#     Dictionary keys are as follows:
# 
#     - ``common`` -- keys in both mappings
#     - ``differing`` -- keys that are in both mappings, but
#       whose values differ
#     - ``left`` -- keys only in the "left" object
#     - ``right`` -- keys only in the "right" object
# 
#     :param dict-like left: "left" object to compare
#     :param dict-like right: "right" object to compare
#     :rtype: dict
#     """
# 
#     left_keys = set(left.iterkeys())
#     right_keys = set(right.iterkeys())
# 
#     common_keys = left_keys & right_keys
#     left_only_keys = left_keys - right_keys
#     right_only_keys = right_keys - left_keys
# 
#     differing = set(k for k in common_keys if left[k] != right[k])
# 
#     return {
#         'common': common_keys,
#         'left': left_only_keys,
#         'right': right_only_keys,
#         'differing': differing,
#     }
# 
# def diff_sequences(left, right):
#     """
#     Compare two sequences, return a dict containing differences
#     """
# 
#     return {
#         'length_match': len(left) == len(right),
#         'differing': set([
#             i for i, (l, r) in enumerate(zip(left, right))
#             if l != r
#         ])}


from ckan_api_client.tests.utils.diff import diff_mappings, diff_sequences
def test_diff_dicts():
    dct1 = {
        'one': 'VAL-1',
        'two': 'VAL-2',
        'three': 'VAL-3',
        'four': 'VAL-4',
        'five': 'VAL-5',
    }
    dct2 = {
        'three': 'VAL-3',
        'four': 'VAL-4-2',
        'five': 'VAL-5-2',
        'six': 'VAL-6',
        'seven': 'VAL-7',
        'eight': 'VAL-8',
    }

    diff = diff_mappings(dct1, dct2)

    assert diff['common'] == set(['three', 'four', 'five'])
    assert diff['left'] == set(['one', 'two'])
    assert diff['right'] == set(['six', 'seven', 'eight'])
    assert diff['differing'] == set(['four', 'five'])


def test_diff_sequences():
    diff = diff_sequences([1, 2, 3], [1, 2, 9])
    assert diff['length_match'] is True
    assert diff['differing'] == set([2])


# Path: ckan_api_client/tests/utils/diff.py
# def diff_mappings(left, right):
#     """
#     Compares two mappings, returning a dictionary of
#     sets of keys describing differences.
# 
#     Dictionary keys are as follows:
# 
#     - ``common`` -- keys in both mappings
#     - ``differing`` -- keys that are in both mappings, but
#       whose values differ
#     - ``left`` -- keys only in the "left" object
#     - ``right`` -- keys only in the "right" object
# 
#     :param dict-like left: "left" object to compare
#     :param dict-like right: "right" object to compare
#     :rtype: dict
#     """
# 
#     left_keys = set(left.iterkeys())
#     right_keys = set(right.iterkeys())
# 
#     common_keys = left_keys & right_keys
#     left_only_keys = left_keys - right_keys
#     right_only_keys = right_keys - left_keys
# 
#     differing = set(k for k in common_keys if left[k] != right[k])
# 
#     return {
#         'common': common_keys,
#         'left': left_only_keys,
#         'right': right_only_keys,
#         'differing': differing,
#     }
# 
# def diff_sequences(left, right):
#     """
#     Compare two sequences, return a dict containing differences
#     """
# 
#     return {
#         'length_match': len(left) == len(right),
#         'differing': set([
#             i for i, (l, r) in enumerate(zip(left, right))
#             if l != r
#         ])}


# Path: ckan_api_client/tests/unit/test_utils_diff.py
from ckan_api_client.tests.utils.diff import diff_mappings, diff_sequences

def test_diff_dicts():
    dct1 = {
        'one': 'VAL-1',
        'two': 'VAL-2',
        'three': 'VAL-3',
        'four': 'VAL-4',
        'five': 'VAL-5',
    }
    dct2 = {
        'three': 'VAL-3',
        'four': 'VAL-4-2',
        'five': 'VAL-5-2',
        'six': 'VAL-6',
        'seven': 'VAL-7',
        'eight': 'VAL-8',
    }

    diff = diff_mappings(dct1, dct2)

    assert diff['common'] == set(['three', 'four', 'five'])
    assert diff['left'] == set(['one', 'two'])
    assert diff['right'] == set(['six', 'seven', 'eight'])
    assert diff['differing'] == set(['four', 'five'])


def test_diff_sequences():
    diff = diff_sequences([1, 2, 3], [1, 2, 9])
    assert diff['length_match'] is True
    assert diff['differing'] == set([2])


    diff = diff_sequences([1, 2], [])