def test_exec_params_kwargs_only(self): def logic(a=1, b=2, c=3): return a + 1, b + 1, c logic._argspec = inspect.getargspec(logic) kwargs = {'d': 1, 'e': 2} args = (1, 2, 3) a, b, c = exec_params(logic, *args, **kwargs) self.assertEqual(a, args[0] + 1) self.assertEqual(b, args[1] + 1) self.assertEqual(c, 3)
def test_exec_params_function(self): def logic(a, b, c=None): return a + 1, b + 1, c logic._argspec = inspect.getargspec(logic) kwargs = {'c': 1, 'd': 'a'} args = (1, 2) a, b, c = exec_params(logic, *args, **kwargs) self.assertEqual(a, args[0] + 1) self.assertEqual(b, args[1] + 1) self.assertEqual(c, kwargs['c'])
def test_exec_params_callable(self): kwargs = {'c': 1, 'd': 'a'} args = (1, 2) class Foo(object): def __call__(self, a, b, c=None): return a + 1, b + 1, c logic = Foo() logic._argspec = inspect.getargspec(logic.__call__) a, b, c = exec_params(logic, *args, **kwargs) self.assertEqual(a, args[0] + 1) self.assertEqual(b, args[1] + 1) self.assertEqual(c, kwargs['c'])
def test_exec_params_with_magic_kwargs(self): """ This test replicates a bug where if a logic function were decorated and we sendt a json body request that contained parameters not in the logic function's signature it would cause a TypeError similar to the following for the logic function defined in this test: TypeError: logic() got an unexpected keyword argument 'e' This test verifies if a logic function uses the **kwargs functionality that we pass along those to the logic function in addition to any other positional or keyword arguments. """ def logic(a, b=2, c=3, **kwargs): return (a, b, c, kwargs) logic._argspec = inspect.getargspec(logic) kwargs = {'c': 3, 'e': 2} args = (1, 2) actual = exec_params(logic, *args, **kwargs) self.assertEqual((1, 2, 3, {'e': 2}), actual)