def test_special(): p = partial(add, 0, x=0) p2 = partial(add, z=0) p3 = partial(add, 0) if IS_PYPY: # builtins in PYPY are python functions if hex(sys.hexversion) < '0x3080cf0': base, exp, mod = 'base', 'exponent', 'modulus' else: base, exp, mod = 'base', 'exp', 'mod' assert signature(pow, safe=True) == ((base, exp, mod), { mod: None }, '', '') else: assert signature(pow, safe=True) == (None, None, None, None) assert signature(p, safe=True) == (None, None, None, None) assert signature(p2, safe=True) == (('x', 'y'), {'z': 0}, '', '') assert signature(p3, safe=True) == (('y', ), {'!x': 0}, '', '') if IS_PYPY: # PYPY bug in ArgSpec for min, so use pow assert isvalid(pow, 0, 1) == True assert isvalid(pow, 0) == False assert isvalid(pow) == False else: # python >= 3.5 bug in ArgSpec for pow, so use min assert isvalid(min, 0, 1) == True assert isvalid(min, 0) == False assert isvalid(min) == False assert isvalid(p, 0, 1) == False assert isvalid(p, 0) == False assert isvalid(p) == False assert isvalid(p2, 0, 1) == False assert isvalid(p2, 0) == False assert isvalid(p2) == False assert isvalid(p3, 0, 1) == False assert isvalid(p3, 0) == True assert isvalid(p3) == False assert _keygen(p3, [], 0) == ((), {'y': 0}) assert _keygen(p2, [], 0) == ((), {'x': 0, 'z': 0}) assert _keygen(p, [], 0) == ((0, ), {}) assert _keygen(min, [], x=0, y=1) == ((), {'y': 1, 'x': 0}) assert _keygen(min, [], 0, 1) == ((0, 1), {}) assert _keygen(min, [], 0) == ((0, ), {}) assert _keygen(min, 'x', 0) == ((0, ), {}) assert _keygen(min, ['x', 'y'], 0) == ((0, ), {}) assert _keygen(min, [0, 1], 0) == ((NULL, ), {}) if IS_PYPY else ((0, ), {}) assert _keygen(min, ['*'], 0) == ((), {}) if IS_PYPY else ((0, ), {})
def test_special(): p = partial(add, 0,x=0) p2 = partial(add, z=0) p3 = partial(add, 0) if IS_PYPY: # builtins in PYPY are python functions assert signature(pow, safe=True) == (('base', 'exponent', 'modulus'), {'modulus': None}, '', '') else: assert signature(pow, safe=True) == (None, None, None, None) assert signature(p, safe=True) == (None, None, None, None) assert signature(p2, safe=True) == (('x', 'y'), {'z': 0}, '', '') assert signature(p3, safe=True) == (('y',), {'!x': 0}, '', '') if IS_PYPY: # PYPY bug in ArgSpec for min, so use pow assert isvalid(pow, 0,1) == True assert isvalid(pow, 0) == False assert isvalid(pow) == False else: # python >= 3.5 bug in ArgSpec for pow, so use min assert isvalid(min, 0,1) == True assert isvalid(min, 0) == False assert isvalid(min) == False assert isvalid(p, 0,1) == False assert isvalid(p, 0) == False assert isvalid(p) == False assert isvalid(p2, 0,1) == False assert isvalid(p2, 0) == False assert isvalid(p2) == False assert isvalid(p3, 0,1) == False assert isvalid(p3, 0) == True assert isvalid(p3) == False assert _keygen(p3, [], 0) == ((), {'y': 0}) assert _keygen(p2, [], 0) == ((), {'x': 0, 'z': 0}) assert _keygen(p, [], 0) == ((0,), {}) assert _keygen(min, [], x=0,y=1) == ((), {'y': 1, 'x': 0}) assert _keygen(min, [], 0,1) == ((0,1), {}) assert _keygen(min, [], 0) == ((0,), {}) assert _keygen(min, 'x', 0) == ((0,), {}) assert _keygen(min, ['x','y'], 0) == ((0,), {}) assert _keygen(min, [0,1], 0) == ((NULL,), {}) if IS_PYPY else ((0,), {}) assert _keygen(min, ['*'], 0) == ((), {}) if IS_PYPY else ((0,), {})
def test_special(): p = partial(add, 0, x=0) p2 = partial(add, z=0) p3 = partial(add, 0) if IS_PYPY: # builtins in PYPY are python functions assert signature(pow, safe=True) == (("base", "exponent", "modulus"), {"modulus": None}, "", "") else: assert signature(pow, safe=True) == (None, None, None, None) assert signature(p, safe=True) == (None, None, None, None) assert signature(p2, safe=True) == (("x", "y"), {"z": 0}, "", "") assert signature(p3, safe=True) == (("y",), {"!x": 0}, "", "") if IS_PYPY: # PYPY bug in ArgSpec for min, so use pow assert isvalid(pow, 0, 1) == True assert isvalid(pow, 0) == False assert isvalid(pow) == False else: # python >= 3.5 bug in ArgSpec for pow, so use min assert isvalid(min, 0, 1) == True assert isvalid(min, 0) == False assert isvalid(min) == False assert isvalid(p, 0, 1) == False assert isvalid(p, 0) == False assert isvalid(p) == False assert isvalid(p2, 0, 1) == False assert isvalid(p2, 0) == False assert isvalid(p2) == False assert isvalid(p3, 0, 1) == False assert isvalid(p3, 0) == True assert isvalid(p3) == False assert _keygen(p3, [], 0) == ((), {"y": 0}) assert _keygen(p2, [], 0) == ((), {"x": 0, "z": 0}) assert _keygen(p, [], 0) == ((0,), {}) assert _keygen(min, [], x=0, y=1) == ((), {"y": 1, "x": 0}) assert _keygen(min, [], 0, 1) == ((0, 1), {}) assert _keygen(min, [], 0) == ((0,), {}) assert _keygen(min, "x", 0) == ((0,), {}) assert _keygen(min, ["x", "y"], 0) == ((0,), {}) assert _keygen(min, [0, 1], 0) == ((NULL,), {}) if IS_PYPY else ((0,), {}) assert _keygen(min, ["*"], 0) == ((), {}) if IS_PYPY else ((0,), {})
def test_keygen(): # a partial with a 'fixed' x, and positionally 'unsettable' b p = partial(bar, 0, b=10) s = signature(p) assert s == (('y', 'z', 'a', '!b'), {'a': 1, '!x': 0, 'b': 10}, 'args', '') ignored = (0, 1, 3, 5, '*', 'b', 'c') user_args = ('0', '1', '2', '3', '4', '5', '6') user_kwds = {'a': '10', 'b': '20', 'c': '30', 'd': '40'} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == { 'a': '2', 'c': NULL, 'b': NULL, 'd': '40', 'y': NULL, 'z': NULL } ignored = (0, 1, 3, 5, '**', 'b', 'c') user_args = ('0', '1', '2', '3', '4', '5', '6') user_kwds = {'a': '10', 'b': '20', 'c': '30', 'd': '40'} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == ('4', NULL, '6') assert key_kwds == {'a': '2', 'b': NULL, 'y': NULL, 'z': NULL} ignored = ('*', '**') user_args = ('0', '1', '2', '3', '4', '5', '6') user_kwds = {'a': '10', 'b': '20', 'c': '30', 'd': '40'} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {'a': '2', 'b': '3', 'y': '0', 'z': '1'} ignored = (0, 2) user_args = ('0', '1', '2', '3', '4', '5', '6') user_kwds = {'a': '10', 'b': '20', 'c': '30', 'd': '40'} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == ('4', '5', '6') assert key_kwds == { 'a': NULL, 'c': '30', 'b': '3', 'd': '40', 'y': NULL, 'z': '1' } ignored = (0, ) user_args = ('0', '1', '2', '3', '4', '5', '6') user_kwds = {'a': '10', 'b': '20', 'c': '30', 'd': '40', 'y': 50} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == ('4', '5', '6') assert key_kwds == { 'a': '2', 'c': '30', 'b': '3', 'd': '40', 'y': NULL, 'z': '1' } ignored = ('a', 'y', 'c') user_args = ('0', '1', '2', '3', '4', '5', '6') user_kwds = {'a': '10', 'b': '20', 'c': '30', 'd': '40', 'y': 50} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == ('4', '5', '6') assert key_kwds == { 'a': NULL, 'c': NULL, 'b': '3', 'd': '40', 'y': NULL, 'z': '1' } ignored = (1, 5, 'a', 'y', 'c') user_args = ('0', '1') user_kwds = {} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {'a': NULL, 'y': NULL, 'b': 10, 'z': NULL} #XXX: c? ignored = (1, 5, 'a', 'y', 'c') user_args = () user_kwds = {'c': '30', 'd': '40', 'y': 50} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == { 'a': NULL, 'y': NULL, 'c': NULL, 'd': '40', 'b': 10, 'z': NULL } ignored = (1, 5, 'a', 'c') user_args = ('0', '1') user_kwds = {} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {'a': NULL, 'y': '0', 'b': 10, 'z': NULL} #XXX: c? ignored = () user_args = ('0', ) user_kwds = {'c': '30'} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {'a': 1, 'y': '0', 'b': 10, 'c': '30'}
15 >>> p(0,y=1,z=2) 6 ''' # a partial with a 'fixed' x, and positionally 'unsettable' b p = partial(bar, 0,b=10) s = signature(p) assert s == (('y', 'z', 'a', '!b'), {'a': 1, '!x': 0, 'b': 10}, 'args', '') ################################################################# # test _keygen ignored = (0,1,3,5,'*','b','c') user_args = ('0','1','2','3','4','5','6') user_kwds = {'a':'10','b':'20','c':'30','d':'40'} key_args,key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {'a': '2', 'c': NULL, 'b': NULL, 'd': '40', 'y': NULL, 'z': NULL} ignored = (0,1,3,5,'**','b','c') user_args = ('0','1','2','3','4','5','6') user_kwds = {'a':'10','b':'20','c':'30','d':'40'} key_args,key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == ('4', NULL, '6') assert key_kwds == {'a': '2', 'b': NULL, 'y': NULL, 'z': NULL} ignored = ('*','**') user_args = ('0','1','2','3','4','5','6') user_kwds = {'a':'10','b':'20','c':'30','d':'40'} key_args,key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == ()
def test_keygen(): # a partial with a 'fixed' x, and positionally 'unsettable' b p = partial(bar, 0, b=10) s = signature(p) assert s == (("y", "z", "a", "!b"), {"a": 1, "!x": 0, "b": 10}, "args", "") ignored = (0, 1, 3, 5, "*", "b", "c") user_args = ("0", "1", "2", "3", "4", "5", "6") user_kwds = {"a": "10", "b": "20", "c": "30", "d": "40"} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {"a": "2", "c": NULL, "b": NULL, "d": "40", "y": NULL, "z": NULL} ignored = (0, 1, 3, 5, "**", "b", "c") user_args = ("0", "1", "2", "3", "4", "5", "6") user_kwds = {"a": "10", "b": "20", "c": "30", "d": "40"} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == ("4", NULL, "6") assert key_kwds == {"a": "2", "b": NULL, "y": NULL, "z": NULL} ignored = ("*", "**") user_args = ("0", "1", "2", "3", "4", "5", "6") user_kwds = {"a": "10", "b": "20", "c": "30", "d": "40"} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {"a": "2", "b": "3", "y": "0", "z": "1"} ignored = (0, 2) user_args = ("0", "1", "2", "3", "4", "5", "6") user_kwds = {"a": "10", "b": "20", "c": "30", "d": "40"} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == ("4", "5", "6") assert key_kwds == {"a": NULL, "c": "30", "b": "3", "d": "40", "y": NULL, "z": "1"} ignored = (0,) user_args = ("0", "1", "2", "3", "4", "5", "6") user_kwds = {"a": "10", "b": "20", "c": "30", "d": "40", "y": 50} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == ("4", "5", "6") assert key_kwds == {"a": "2", "c": "30", "b": "3", "d": "40", "y": NULL, "z": "1"} ignored = ("a", "y", "c") user_args = ("0", "1", "2", "3", "4", "5", "6") user_kwds = {"a": "10", "b": "20", "c": "30", "d": "40", "y": 50} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == ("4", "5", "6") assert key_kwds == {"a": NULL, "c": NULL, "b": "3", "d": "40", "y": NULL, "z": "1"} ignored = (1, 5, "a", "y", "c") user_args = ("0", "1") user_kwds = {} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {"a": NULL, "y": NULL, "b": 10, "z": NULL} # XXX: c? ignored = (1, 5, "a", "y", "c") user_args = () user_kwds = {"c": "30", "d": "40", "y": 50} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {"a": NULL, "y": NULL, "c": NULL, "d": "40", "b": 10, "z": NULL} ignored = (1, 5, "a", "c") user_args = ("0", "1") user_kwds = {} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {"a": NULL, "y": "0", "b": 10, "z": NULL} # XXX: c? ignored = () user_args = ("0",) user_kwds = {"c": "30"} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {"a": 1, "y": "0", "b": 10, "c": "30"}
def test_keygen(): # a partial with a 'fixed' x, and positionally 'unsettable' b p = partial(bar, 0,b=10) s = signature(p) assert s == (('y', 'z', 'a', '!b'), {'a': 1, '!x': 0, 'b': 10}, 'args', '') ignored = (0,1,3,5,'*','b','c') user_args = ('0','1','2','3','4','5','6') user_kwds = {'a':'10','b':'20','c':'30','d':'40'} key_args,key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {'a': '2', 'c': NULL, 'b': NULL, 'd': '40', 'y': NULL, 'z': NULL} ignored = (0,1,3,5,'**','b','c') user_args = ('0','1','2','3','4','5','6') user_kwds = {'a':'10','b':'20','c':'30','d':'40'} key_args,key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == ('4', NULL, '6') assert key_kwds == {'a': '2', 'b': NULL, 'y': NULL, 'z': NULL} ignored = ('*','**') user_args = ('0','1','2','3','4','5','6') user_kwds = {'a':'10','b':'20','c':'30','d':'40'} key_args,key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {'a': '2', 'b': '3', 'y': '0', 'z': '1'} ignored = (0,2) user_args = ('0','1','2','3','4','5','6') user_kwds = {'a':'10','b':'20','c':'30','d':'40'} key_args,key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == ('4', '5', '6') assert key_kwds == {'a': NULL, 'c': '30', 'b': '3', 'd':'40', 'y': NULL, 'z': '1'} ignored = (0,) user_args = ('0','1','2','3','4','5','6') user_kwds = {'a':'10','b':'20','c':'30','d':'40','y':50} key_args,key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == ('4', '5', '6') assert key_kwds == {'a': '2', 'c': '30', 'b': '3', 'd':'40', 'y': NULL, 'z': '1'} ignored = ('a','y','c') user_args = ('0','1','2','3','4','5','6') user_kwds = {'a':'10','b':'20','c':'30','d':'40','y':50} key_args,key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == ('4', '5', '6') assert key_kwds == {'a': NULL, 'c': NULL, 'b': '3', 'd':'40', 'y': NULL, 'z': '1'} ignored = (1,5,'a','y','c') user_args = ('0','1') user_kwds = {} key_args,key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {'a': NULL, 'y': NULL, 'b': 10, 'z': NULL} #XXX: c? ignored = (1,5,'a','y','c') user_args = () user_kwds = {'c':'30','d':'40','y':50} key_args,key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {'a': NULL, 'y': NULL, 'c': NULL, 'd': '40', 'b': 10, 'z': NULL} ignored = (1,5,'a','c') user_args = ('0','1') user_kwds = {} key_args,key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {'a': NULL, 'y': '0', 'b': 10, 'z': NULL} #XXX: c? ignored = () user_args = ('0',) user_kwds = {'c':'30'} key_args,key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == {'a': 1, 'y': '0', 'b': 10, 'c': '30'}
>>> p(0,z=2) 15 >>> p(0,y=1,z=2) 6 ''' # a partial with a 'fixed' x, and positionally 'unsettable' b p = partial(bar, 0, b=10) s = signature(p) assert s == (('y', 'z', 'a', '!b'), {'a': 1, '!x': 0, 'b': 10}, 'args', '') ################################################################# # test _keygen ignored = (0, 1, 3, 5, '*', 'b', 'c') user_args = ('0', '1', '2', '3', '4', '5', '6') user_kwds = {'a': '10', 'b': '20', 'c': '30', 'd': '40'} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == () assert key_kwds == { 'a': '2', 'c': NULL, 'b': NULL, 'd': '40', 'y': NULL, 'z': NULL } ignored = (0, 1, 3, 5, '**', 'b', 'c') user_args = ('0', '1', '2', '3', '4', '5', '6') user_kwds = {'a': '10', 'b': '20', 'c': '30', 'd': '40'} key_args, key_kwds = _keygen(p, ignored, *user_args, **user_kwds) assert key_args == ('4', NULL, '6')