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)
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) )
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)
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})
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))
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): # positional and keyword args self.assertEqual(getargs_keyword_only(1, 2, keyword_only=3), (1, 2, 3))
def test_keyword_args(self): # all keywords self.assertEqual( getargs_keyword_only(required=1, optional=2, keyword_only=3), (1, 2, 3))
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})
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))
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))
def test_keyword_args(self): # all keywords self.assertEqual( getargs_keyword_only(required=1, optional=2, keyword_only=3), (1, 2, 3) )
def test_mixed_args(self): # positional and keyword args self.assertEqual( getargs_keyword_only(1, 2, keyword_only=3), (1, 2, 3) )
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))