예제 #1
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)
예제 #2
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')
예제 #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)
예제 #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')
예제 #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',
     )
예제 #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',
     )
예제 #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)
예제 #8
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.
        """
        self.assertRaises(
            ValueError,
            required_parameters('arg1', 'wibble', 'wobble'),
            undecorated_func)

        self.assertRaises(
            ValueError,
            mutually_exclusive_parameters('arg1', 'wibble', 'wobble'),
            undecorated_func)
예제 #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__)
예제 #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__)