Esempio n. 1
0
def test_dictionary_conversion():
    """
    Test converting dictionaries to tuples and ensuring proper key order.
    """
    assert convert_to_hashable({}) == ()

    expected = (('a', 1), ('b', 2))
    assert convert_to_hashable({'a': 1, 'b': 2}) == expected
    assert convert_to_hashable({'b': 2, 'a': 1}) == expected

    assert convert_to_hashable(('a', [1, 2, 3, 4])) == ('a', (1, 2, 3, 4))
    assert convert_to_hashable(('a', {'b': {3: [1, 2, 3, 4]}})) == ('a', (('b', ((3, (1, 2, 3, 4)), )), ))
Esempio n. 2
0
def argument_hash(function, *args, **kwargs):
    # TODO: Allow usage of a different postprocessor than MD5.
    # TODO: Replace `hash` with a safe hashing implementation.

    arguments = inspect.getcallargs(function, *args, **kwargs)
    arguments = convert_to_hashable(arguments)
    return md5(':'.join(map(lambda value: str(hash(value)), arguments)))
Esempio n. 3
0
def argument_hash(function, *args, **kwargs):
    # TODO: Allow usage of a different postprocessor than MD5.
    # TODO: Replace `hash` with a safe hashing implementation.

    arguments = inspect.getcallargs(function, *args, **kwargs)
    arguments = convert_to_hashable(arguments)
    return md5(':'.join(map(lambda value: str(hash(value)), arguments)))
Esempio n. 4
0
def test_dictionary_conversion():
    """
    Test converting dictionaries to tuples and ensuring proper key order.
    """
    assert convert_to_hashable({}) == ()

    expected = (('a', 1), ('b', 2))
    assert convert_to_hashable({'a': 1, 'b': 2}) == expected
    assert convert_to_hashable({'b': 2, 'a': 1}) == expected

    assert convert_to_hashable(('a', [1, 2, 3, 4])) == ('a', (1, 2, 3, 4))
    assert convert_to_hashable(('a', {
        'b': {
            3: [1, 2, 3, 4]
        }
    })) == ('a', (('b', ((3, (1, 2, 3, 4)), )), ))