diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-09 13:30:29 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-09 13:30:29 (GMT) |
commit | f41b82fb19d1b91f99ab657e4c6a751c44152f12 (patch) | |
tree | d646a40450ae5321aaa384609fb7b027639363e6 /Lib/test/test_getargs2.py | |
parent | 339880809a10bc63967b6f94aadc4cd7d406ba54 (diff) | |
download | cpython-f41b82fb19d1b91f99ab657e4c6a751c44152f12.zip cpython-f41b82fb19d1b91f99ab657e4c6a751c44152f12.tar.gz cpython-f41b82fb19d1b91f99ab657e4c6a751c44152f12.tar.bz2 |
Issue #26282: PyArg_ParseTupleAndKeywords() and Argument Clinic now support
positional-only and keyword parameters in the same function.
Diffstat (limited to 'Lib/test/test_getargs2.py')
-rw-r--r-- | Lib/test/test_getargs2.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_getargs2.py b/Lib/test/test_getargs2.py index ecc1908..16e163a 100644 --- a/Lib/test/test_getargs2.py +++ b/Lib/test/test_getargs2.py @@ -658,6 +658,39 @@ class KeywordOnly_TestCase(unittest.TestCase): getargs_keyword_only(1, 2, **{'\uDC80': 10}) +class PositionalOnlyAndKeywords_TestCase(unittest.TestCase): + from _testcapi import getargs_positional_only_and_keywords as getargs + + def test_positional_args(self): + # using all possible positional args + self.assertEqual(self.getargs(1, 2, 3), (1, 2, 3)) + + def test_mixed_args(self): + # positional and keyword args + self.assertEqual(self.getargs(1, 2, keyword=3), (1, 2, 3)) + + def test_optional_args(self): + # missing optional args + self.assertEqual(self.getargs(1, 2), (1, 2, -1)) + self.assertEqual(self.getargs(1, keyword=3), (1, -1, 3)) + + def test_required_args(self): + self.assertEqual(self.getargs(1), (1, -1, -1)) + # required positional arg missing + with self.assertRaisesRegex(TypeError, + "Function takes at least 1 positional arguments \(0 given\)"): + self.getargs() + + with self.assertRaisesRegex(TypeError, + "Function takes at least 1 positional arguments \(0 given\)"): + self.getargs(keyword=3) + + def test_empty_keyword(self): + with self.assertRaisesRegex(TypeError, + "'' is an invalid keyword argument for this function"): + self.getargs(1, 2, **{'': 666}) + + class Bytes_TestCase(unittest.TestCase): def test_c(self): from _testcapi import getargs_c |