Example #1
0
    def test_too_many_args(self):
        with self.assertRaisesRegex(TypeError,
            "Function takes at most 2 positional arguments \(3 given\)"):
            getargs_keyword_only(1, 2, 3)

        with self.assertRaisesRegex(TypeError,
            "function takes at most 3 arguments \(4 given\)"):
            getargs_keyword_only(1, 2, 3, keyword_only=5)
Example #2
0
 def test_optional_args(self):
     # missing optional keyword args, skipping tuples
     self.assertEqual(
         getargs_keyword_only(required=1, optional=2),
         (1, 2, -1)
         )
     self.assertEqual(
         getargs_keyword_only(required=1, keyword_only=3),
         (1, -1, 3)
         )
Example #3
0
    def test_required_args(self):
        self.assertEqual(getargs_keyword_only(1), (1, -1, -1))
        self.assertEqual(getargs_keyword_only(required=1), (1, -1, -1))
        # required arg missing
        with self.assertRaisesRegex(TypeError, "Required argument 'required' \(pos 1\) not found"):
            getargs_keyword_only(optional=2)

        with self.assertRaisesRegex(TypeError, "Required argument 'required' \(pos 1\) not found"):
            getargs_keyword_only(keyword_only=3)
    def test_required_args(self):
        self.assertEqual(
            getargs_keyword_only(1),
            (1, -1, -1)
            )
        self.assertEqual(
            getargs_keyword_only(required=1),
            (1, -1, -1)
            )
        # required arg missing
        with self.assertRaisesRegex(TypeError,
            "Required argument 'required' \(pos 1\) not found"):
            getargs_keyword_only(optional=2)

        with self.assertRaisesRegex(TypeError,
            "Required argument 'required' \(pos 1\) not found"):
            getargs_keyword_only(keyword_only=3)
Example #5
0
 def test_surrogate_keyword(self):
     with self.assertRaisesRegex(
             TypeError,
             "'\udc80' is an invalid keyword argument for this function"):
         getargs_keyword_only(1, 2, **{'\uDC80': 10})
Example #6
0
 def test_optional_args(self):
     # missing optional keyword args, skipping tuples
     self.assertEqual(getargs_keyword_only(required=1, optional=2),
                      (1, 2, -1))
     self.assertEqual(getargs_keyword_only(required=1, keyword_only=3),
                      (1, -1, 3))
Example #7
0
 def test_invalid_keyword(self):
     # extraneous keyword arg
     with self.assertRaisesRegex(
             TypeError,
             "'monster' is an invalid keyword argument for this function"):
         getargs_keyword_only(1, 2, monster=666)
Example #8
0
 def test_mixed_args(self):
     # positional and keyword args
     self.assertEqual(getargs_keyword_only(1, 2, keyword_only=3), (1, 2, 3))
Example #9
0
 def test_keyword_args(self):
     # all keywords
     self.assertEqual(
         getargs_keyword_only(required=1, optional=2, keyword_only=3),
         (1, 2, 3))
Example #10
0
 def test_surrogate_keyword(self):
     with self.assertRaisesRegex(TypeError,
         "'\udc80' is an invalid keyword argument for this function"):
         getargs_keyword_only(1, 2, **{'\uDC80': 10})
Example #11
0
 def test_positional_args(self):
     # using all possible positional args
     self.assertEqual(getargs_keyword_only(1, 2), (1, 2, -1))
 def test_positional_args(self):
     self.assertEqual(getargs_keyword_only(1, 2), (1, 2, -1))
Example #13
0
 def test_invalid_keyword(self):
     # extraneous keyword arg
     with self.assertRaisesRegex(TypeError,
         "'monster' is an invalid keyword argument for this function"):
         getargs_keyword_only(1, 2, monster=666)
 def test_mixed_args(self):
     self.assertEqual(getargs_keyword_only(1, 2, keyword_only=3), (1, 2, 3))
Example #15
0
 def test_keyword_args(self):
     # all keywords
     self.assertEqual(
         getargs_keyword_only(required=1, optional=2, keyword_only=3),
         (1, 2, 3)
         )
Example #16
0
 def test_mixed_args(self):
     # positional and keyword args
     self.assertEqual(
         getargs_keyword_only(1, 2, keyword_only=3),
         (1, 2, 3)
         )
Example #17
0
 def test_positional_args(self):
     # using all possible positional args
     self.assertEqual(
         getargs_keyword_only(1, 2),
         (1, 2, -1)
         )
 def test_optional_args(self):
     self.assertEqual(getargs_keyword_only(required=1, optional=2), (1, 
         2, -1))
     self.assertEqual(getargs_keyword_only(required=1, keyword_only=3),
         (1, -1, 3))