def test_keygen_foo(): assert foo(0, 1, 2) == ("x", NULL, "y", 1, "z", 2) assert foo.valid() == True assert foo(10, 1, 2) == ("x", NULL, "y", 1, "z", 2) assert foo(0, 1) == ("x", NULL, "y", 1, "z", 2) assert foo(0, 1, 3) == ("x", NULL, "y", 1, "z", 3) assert foo(0, 1, r=3) == ("x", NULL, "y", 1, "z", 2) assert foo.valid() == False assert foo(0, 1, x=1) == ("x", NULL, "y", 1, "z", 2) assert foo.valid() == False res2 = ("x", NULL, "y", 2, "z", 10) assert foo(10, y=2, z=10) == res2 assert foo.valid() == True res1 = ("x", NULL, "y", 1, "z", 10) assert foo(0, 1, z=10) == res1 assert foo.valid() == True assert foo.call() == 11 h = hashmap(algorithm="md5") foo.register(h) if hex(sys.hexversion) < "0x30300f0": _hash1 = "2c8d801f4078eba873a5fb6909ab0f8d" _hash2 = "949883b97d9fda9c8fe6bd468fe90af9" else: # python 3.3 has hash randomization, apparently from klepto.crypto import hash _hash1 = hash(res1, "md5") _hash2 = hash(res2, "md5") assert foo(0, 1, z=10) == _hash1 assert str(foo.keymap()) == str(h) assert foo.key() == _hash1 assert foo(10, y=1, z=10) == _hash1 assert foo(10, y=2, z=10) == _hash2
def test_keygen_foo(): assert foo(0, 1, 2) == ('x', NULL, 'y', 1, 'z', 2) assert foo.valid() == True assert foo(10, 1, 2) == ('x', NULL, 'y', 1, 'z', 2) assert foo(0, 1) == ('x', NULL, 'y', 1, 'z', 2) assert foo(0, 1, 3) == ('x', NULL, 'y', 1, 'z', 3) assert foo(0, 1, r=3) == ('x', NULL, 'y', 1, 'z', 2) assert foo.valid() == False assert foo(0, 1, x=1) == ('x', NULL, 'y', 1, 'z', 2) assert foo.valid() == False res2 = ('x', NULL, 'y', 2, 'z', 10) assert foo(10, y=2, z=10) == res2 assert foo.valid() == True res1 = ('x', NULL, 'y', 1, 'z', 10) assert foo(0, 1, z=10) == res1 assert foo.valid() == True assert foo.call() == 11 h = hashmap(algorithm='md5') foo.register(h) if hex(sys.hexversion) < '0x30300f0': _hash1 = '2c8d801f4078eba873a5fb6909ab0f8d' _hash2 = '949883b97d9fda9c8fe6bd468fe90af9' else: # python 3.3 has hash randomization, apparently from klepto.crypto import hash _hash1 = hash(res1, 'md5') _hash2 = hash(res2, 'md5') assert foo(0, 1, z=10) == _hash1 assert str(foo.keymap()) == str(h) assert foo.key() == _hash1 assert foo(10, y=1, z=10) == _hash1 assert foo(10, y=2, z=10) == _hash2
def test_keygen_foo(): assert foo(0,1,2) == ('x', NULL, 'y', 1, 'z', 2) assert foo.valid() == True assert foo(10,1,2) == ('x', NULL, 'y', 1, 'z', 2) assert foo(0,1) == ('x', NULL, 'y', 1, 'z', 2) assert foo(0,1,3) == ('x', NULL, 'y', 1, 'z', 3) assert foo(0,1,r=3) == ('x', NULL, 'y', 1, 'z', 2) assert foo.valid() == False assert foo(0,1,x=1) == ('x', NULL, 'y', 1, 'z', 2) assert foo.valid() == False res2 = ('x', NULL, 'y', 2, 'z', 10) assert foo(10,y=2,z=10) == res2 assert foo.valid() == True res1 = ('x', NULL, 'y', 1, 'z', 10) assert foo(0,1,z=10) == res1 assert foo.valid() == True assert foo.call() == 11 h = hashmap(algorithm='md5') foo.register(h) if hex(sys.hexversion) < '0x30300f0': _hash1 = '2c8d801f4078eba873a5fb6909ab0f8d' _hash2 = '949883b97d9fda9c8fe6bd468fe90af9' else: # python 3.3 has hash randomization, apparently from klepto.crypto import hash _hash1 = hash(res1, 'md5') _hash2 = hash(res2, 'md5') assert foo(0,1,z=10) == _hash1 assert str(foo.keymap()) == str(h) assert foo.key() == _hash1 assert foo(10,y=1,z=10) == _hash1 assert foo(10,y=2,z=10) == _hash2
def encrypt(self, *args, **kwds): """use a non-flat scheme for generating a key""" return hash(keymap.encrypt(self, *args, **kwds), algorithm=self.__type__)
def encode(self, *args, **kwds): """use a flattened scheme for generating a key""" return hash(keymap.encode(self, *args, **kwds), algorithm=self.__type__)
assert foo.valid() == False res2 = ('x', NULL, 'y', 2, 'z', 10) assert foo(10,y=2,z=10) == res2 assert foo.valid() == True res1 = ('x', NULL, 'y', 1, 'z', 10) assert foo(0,1,z=10) == res1 assert foo.valid() == True assert foo.call() == 11 h = hashmap(algorithm='md5') foo.register(h) if hex(sys.hexversion) < '0x30300f0': _hash1 = '2c8d801f4078eba873a5fb6909ab0f8d' _hash2 = '949883b97d9fda9c8fe6bd468fe90af9' else: # python 3.3 has hash randomization, apparently from klepto.crypto import hash _hash1 = hash(res1, 'md5') _hash2 = hash(res2, 'md5') assert foo(0,1,z=10) == _hash1 assert str(foo.keymap()) == str(h) assert foo.key() == _hash1 assert foo(10,y=1,z=10) == _hash1 assert foo(10,y=2,z=10) == _hash2 ################################################################# # test special cases (builtins) for signature, isvalid, _keygen def add(x,y): return x+y p = partial(add, 0,x=0) p2 = partial(add, z=0) p3 = partial(add, 0)
assert foo.valid() == False res2 = ('x', NULL, 'y', 2, 'z', 10) assert foo(10, y=2, z=10) == res2 assert foo.valid() == True res1 = ('x', NULL, 'y', 1, 'z', 10) assert foo(0, 1, z=10) == res1 assert foo.valid() == True assert foo.call() == 11 h = hashmap(algorithm='md5') foo.register(h) if hex(sys.hexversion) < '0x30300f0': _hash1 = '2c8d801f4078eba873a5fb6909ab0f8d' _hash2 = '949883b97d9fda9c8fe6bd468fe90af9' else: # python 3.3 has hash randomization, apparently from klepto.crypto import hash _hash1 = hash(res1, 'md5') _hash2 = hash(res2, 'md5') assert foo(0, 1, z=10) == _hash1 assert str(foo.keymap()) == str(h) assert foo.key() == _hash1 assert foo(10, y=1, z=10) == _hash1 assert foo(10, y=2, z=10) == _hash2 ################################################################# # test special cases (builtins) for signature, isvalid, _keygen def add(x, y): return x + y p = partial(add, 0, x=0)