def test_no_mutually_exclusive_args_provided(self): """Test for passing no args (valid) to a function that specifies mutually exclusive parameters. """ _func = mutually_exclusive_parameters('arg1', 'arg2')(undecorated_func) self.assertEquals(_func(), 'foo') self.assertEquals(_func(arg3='hello'), 'foo')
def test_no_mutually_exclusive_args_provided(self): """Test for passing no args (valid) to a function that specifies mutually exclusive parameters. """ _func = mutually_exclusive_parameters('arg1', 'arg2')(undecorated_func) self.assertEqual(_func(), 'foo') self.assertEqual(_func(arg3='hello'), 'foo')
def test_one_mutually_exclusive_arg_provided(self): """Test for passing one arg (the right number) to a function that specifies mutually exclusive parameters. """ _func = mutually_exclusive_parameters('arg1', 'arg2')(undecorated_func) self.assertEqual(_func('hello'), 'foo') self.assertEqual(_func(arg1='hello'), 'foo') self.assertEqual(_func(arg2='hello'), 'foo')
def test_one_mutually_exclusive_arg_provided(self): """Test for passing one arg (the right number) to a function that specifies mutually exclusive parameters. """ _func = mutually_exclusive_parameters('arg1', 'arg2')(undecorated_func) self.assertEquals(_func('hello'), 'foo') self.assertEquals(_func(arg1='hello'), 'foo') self.assertEquals(_func(arg2='hello'), 'foo')
def test_two_mutually_exclusive_args_provided(self): """Test that InvalidParameterError is raised if more than one mutually exclusive argument is provided. """ from plone.api.exc import InvalidParameterError _func = mutually_exclusive_parameters('arg1', 'arg2')(undecorated_func) self.assertRaises(InvalidParameterError, _func, 'ahoy', 'there') self.assertRaises( InvalidParameterError, _func, arg1='ahoy', arg2='there')
def test_two_mutually_exclusive_args_provided(self): """Test that InvalidParameterError is raised if more than one mutually exclusive argument is provided. """ from plone.api.exc import InvalidParameterError _func = mutually_exclusive_parameters('arg1', 'arg2')(undecorated_func) with self.assertRaises(InvalidParameterError): _func('ahoy', 'there') with self.assertRaises(InvalidParameterError): _func(arg1='ahoy', arg2='there')
def test_non_existant_required_arg(self): """Test that ValueError is returned if the decorator requires a parameter that doesn't exist in the function signature. """ with self.assertRaises(ValueError): _func = required_parameters('arg1', 'wibble', 'wobble') _func(undecorated_func) with self.assertRaises(ValueError): _func = mutually_exclusive_parameters('arg1', 'wibble', 'wobble') _func(undecorated_func)
def test_non_existant_required_arg(self): """Test that ValueError is returned if the decorator requires a parameter that doesn't exist in the function signature. """ self.assertRaises( ValueError, required_parameters('arg1', 'wibble', 'wobble'), undecorated_func) self.assertRaises( ValueError, mutually_exclusive_parameters('arg1', 'wibble', 'wobble'), undecorated_func)