def test_clear_checkpoints_object(): _checkpoints = { (functional_hash('a'), 'b', 'c'): 1, (functional_hash('d'), 'e', 'f'): 2, } clear_checkpoints(_checkpoints, object='d') assert _checkpoints == {(functional_hash('a'), 'b', 'c'): 1}
def test_clear_checkpoints_object(): _checkpoints = { (functional_hash('a'), 'b', 'c'): 1, (functional_hash('d'), 'e', 'f'): 2, } clear_checkpoints(_checkpoints, object='d') assert _checkpoints == {(functional_hash('a'), 'b', 'c'): 1}
def test_functional_hash__lamba_globals_ignore_one(): global global_func global_func = times_2() hash_1 = functional_hash(ignore_globals('global_func')(lambda x: global_func(x) - 3)) global_func = times_3() hash_2 = functional_hash(ignore_globals('global_func')(lambda x: global_func(x) - 3)) assert hash_1 == hash_2
def test_recursive_hash(): o = {} o['o'] = o functional_hash(o) l = [] l.append(l) functional_hash(l)
def test_functional_hash__lamba_globals(): global global_func global_func = times_2() hash_1 = functional_hash(lambda x: global_func(x) - 3) hash_2 = functional_hash(lambda x: global_func(x) - 3) global_func = times_3() hash_3 = functional_hash(lambda x: global_func(x) - 3) assert hash_1 == hash_2 assert hash_1 != hash_3
def test_general_object(): class foo_object(object): def __init__(self, foo): self.foo = foo o1 = foo_object('bar') o2 = foo_object('bar') o3 = foo_object('baz') print('o1') print(get_hash_parts(functional_system, o1)) print(get_hash_parts(functional_system, o1, recursive=False)) print('o3') print(get_hash_parts(functional_system, o3)) print(get_hash_parts(functional_system, o3, recursive=False)) assert functional_hash(o1) == functional_hash(o2) assert functional_hash(o1) != functional_hash(o3)
def test_chained__hash(): hash_1 = functional_hash(chained(lambda a: 2 * a, lambda a: a - 3)) hash_2 = functional_hash(chained(lambda a: 2 * a, lambda a: a - 3)) assert hash_1 == hash_2
def test_chained__hash(): hash_1 = functional_hash(chained(lambda a: 2 * a, lambda a: a - 3)) hash_2 = functional_hash(chained(lambda a: 2 * a, lambda a: a - 3)) assert hash_1 == hash_2
def test_functional_hash__builtins(): assert functional_hash(any) == functional_hash(any)
def test_functional_hash__lambda__closure(): def gen_func(a): return lambda x: x + a assert functional_hash(gen_func(0)) == functional_hash(gen_func(0)) assert functional_hash(gen_func(0)) != functional_hash(gen_func(1))
def test_functional_hash__lambda(): hash_1 = functional_hash(lambda x: 2 * x) hash_2 = functional_hash(lambda x: 2 * x) assert hash_1 == hash_2