예제 #1
0
    def testSigMismatchIsError(self):
        """Tests that signature mismatch is an error (when configured so)."""
        if not np_utils._supports_signature():
            self.skipTest('inspect.signature not supported')

        np_utils.set_is_sig_mismatch_an_error(True)

        def np_fun(x, y=1, **kwargs):
            return

        with self.assertRaisesRegex(TypeError, 'Cannot find parameter'):

            @np_utils.np_doc(None, np_fun=np_fun)
            def f1(a):
                return

        with self.assertRaisesRegex(TypeError, 'is of kind'):

            @np_utils.np_doc(None, np_fun=np_fun)
            def f2(x, kwargs):
                return

        with self.assertRaisesRegex(
                TypeError, 'Parameter "y" should have a default value'):

            @np_utils.np_doc(None, np_fun=np_fun)
            def f3(x, y):
                return
예제 #2
0
    def testSigMismatchIsNotError(self):
        """Tests that signature mismatch is not an error (when configured so)."""
        np_utils.set_is_sig_mismatch_an_error(False)

        def np_fun(x, y=1, **kwargs):
            return

        # The following functions all have signature mismatches, but they shouldn't
        # throw errors when is_sig_mismatch_an_error() is False.

        @np_utils.np_doc(None, np_fun=np_fun)
        def f1(a):
            return

        def f2(x, kwargs):
            return

        @np_utils.np_doc(None, np_fun=np_fun)
        def f3(x, y):
            return
예제 #3
0
 def tearDown(self):
     np_utils.set_np_doc_form(self._old_np_doc_form)
     np_utils.set_is_sig_mismatch_an_error(
         self._old_is_sig_mismatch_an_error)
     super(UtilsTest, self).tearDown()