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

    expected = (("a", 1), ("b", 2))
    assert convert_dict_to_tuple({"a": 1, "b": 2}) == expected
    assert convert_dict_to_tuple({"b": 2, "a": 1}) == expected
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.
    # TODO: Allow recursive conversion of dictionary to tuples, probably do the
    # same for lists as well.

    arguments = inspect.getcallargs(function, *args, **kwargs)
    if 'kwargs' in arguments:
        arguments['kwargs'] = convert_dict_to_tuple(arguments['kwargs'])

    arguments = convert_dict_to_tuple(arguments)
    return md5(':'.join(map(lambda value: str(hash(value)), arguments)))