def test_single_arg_missing(self):
     """Test that MissingParameterError is raised if the
     single required parameter is missing.
     """
     from plone.api.exc import MissingParameterError
     _func = required_parameters('arg1')(undecorated_func)
     self.assertRaises(MissingParameterError, _func)
 def test_one_missing_one_provided(self):
     """Test that MissingParameterError is raised if only one of the
     required parameters is missing.
     """
     from plone.api.exc import MissingParameterError
     _func = required_parameters('arg1', 'arg2')(undecorated_func)
     self.assertRaises(MissingParameterError, _func, 'hello')
Exemple #3
0
 def test_single_arg_missing(self):
     """Test that MissingParameterError is raised if the
     single required parameter is missing.
     """
     from plone.api.exc import MissingParameterError
     _func = required_parameters('arg1')(undecorated_func)
     self.assertRaises(MissingParameterError, _func)
Exemple #4
0
 def test_one_missing_one_provided(self):
     """Test that MissingParameterError is raised if only one of the
     required parameters is missing.
     """
     from plone.api.exc import MissingParameterError
     _func = required_parameters('arg1', 'arg2')(undecorated_func)
     self.assertRaises(MissingParameterError, _func, 'hello')
Exemple #5
0
 def test_single_positional_arg_provided(self):
     """Test for passing a single required parameter
     as a positional argument.
     """
     _func = required_parameters('arg1')(undecorated_func)
     self.assertEqual(
         _func('hello'),
         'foo',
     )
Exemple #6
0
 def test_single_keyword_arg_provided(self):
     """Test for passing a single required parameter
     as a keyword argument.
     """
     _func = required_parameters('arg1')(undecorated_func)
     self.assertEqual(
         _func(arg1='hello'),
         'foo',
     )
Exemple #7
0
    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)
Exemple #9
0
    def test_decorator_works_the_same_as_explicit_calling(self):
        """Check that calling the decorator with the function as an argument
        is equivalent to decorating the function.
        """
        @required_parameters('arg1')
        def _func1_decorated(arg1=None, arg2=None, arg3=None):
            """This is my docstring"""
            pass

        def _func2_undecorated(arg1=None, arg2=None, arg3=None):
            """This is my docstring"""
            pass
        _func2_decorated = required_parameters('arg1')(_func2_undecorated)

        # Check that the decorated function gets the correct docstring
        self.assertEqual(_func1_decorated.__doc__, 'This is my docstring')

        # Check that both functions have the same docstring
        self.assertEqual(_func1_decorated.__doc__, _func2_decorated.__doc__)
Exemple #10
0
    def test_decorator_works_the_same_as_explicit_calling(self):
        """Check that calling the decorator with the function as an argument
        is equivalent to decorating the function.
        """
        @required_parameters('arg1')
        def _func1_decorated(arg1=None, arg2=None, arg3=None):
            """This is my docstring"""
            pass

        def _func2_undecorated(arg1=None, arg2=None, arg3=None):
            """This is my docstring"""
            pass
        _func2_decorated = required_parameters('arg1')(_func2_undecorated)

        # Check that the decorated function gets the correct docstring
        self.assertEquals(_func1_decorated.__doc__, 'This is my docstring')

        # Check that both functions have the same docstring
        self.assertEquals(_func1_decorated.__doc__, _func2_decorated.__doc__)