summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-05-16 06:55:32 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-05-16 06:55:32 (GMT)
commitacef5de6ecd1cb84420bb0ea8d0a8d6cd09682e2 (patch)
tree81376bd368d4cb32bdafaa4ef5382dd45493e15c /Lib
parentaf7cf6d2b9ec4ec2ec016fdf47c21894fef3f26a (diff)
downloadcpython-acef5de6ecd1cb84420bb0ea8d0a8d6cd09682e2.zip
cpython-acef5de6ecd1cb84420bb0ea8d0a8d6cd09682e2.tar.gz
cpython-acef5de6ecd1cb84420bb0ea8d0a8d6cd09682e2.tar.bz2
Backported tests for issue #18531.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_getargs2.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/Lib/test/test_getargs2.py b/Lib/test/test_getargs2.py
index 6491135..2e98d65 100644
--- a/Lib/test/test_getargs2.py
+++ b/Lib/test/test_getargs2.py
@@ -70,6 +70,12 @@ class BadInt3(int):
def __int__(self):
return True
+class TupleSubclass(tuple):
+ pass
+
+class DictSubclass(dict):
+ pass
+
class Unsigned_TestCase(unittest.TestCase):
def test_b(self):
@@ -321,6 +327,33 @@ class Boolean_TestCase(unittest.TestCase):
class Tuple_TestCase(unittest.TestCase):
+ def test_args(self):
+ from _testcapi import get_args
+
+ ret = get_args(1, 2)
+ self.assertEqual(ret, (1, 2))
+ self.assertIs(type(ret), tuple)
+
+ ret = get_args(1, *(2, 3))
+ self.assertEqual(ret, (1, 2, 3))
+ self.assertIs(type(ret), tuple)
+
+ ret = get_args(*[1, 2])
+ self.assertEqual(ret, (1, 2))
+ self.assertIs(type(ret), tuple)
+
+ ret = get_args(*TupleSubclass([1, 2]))
+ self.assertEqual(ret, (1, 2))
+ self.assertIsInstance(ret, tuple)
+
+ ret = get_args()
+ self.assertIn(ret, ((), None))
+ self.assertIn(type(ret), (tuple, type(None)))
+
+ ret = get_args(*())
+ self.assertIn(ret, ((), None))
+ self.assertIn(type(ret), (tuple, type(None)))
+
def test_tuple(self):
from _testcapi import getargs_tuple
@@ -336,6 +369,29 @@ class Tuple_TestCase(unittest.TestCase):
self.assertRaises(TypeError, getargs_tuple, 1, seq())
class Keywords_TestCase(unittest.TestCase):
+ def test_kwargs(self):
+ from _testcapi import get_kwargs
+
+ ret = get_kwargs(a=1, b=2)
+ self.assertEqual(ret, {'a': 1, 'b': 2})
+ self.assertIs(type(ret), dict)
+
+ ret = get_kwargs(a=1, **{'b': 2, 'c': 3})
+ self.assertEqual(ret, {'a': 1, 'b': 2, 'c': 3})
+ self.assertIs(type(ret), dict)
+
+ ret = get_kwargs(**DictSubclass({'a': 1, 'b': 2}))
+ self.assertEqual(ret, {'a': 1, 'b': 2})
+ self.assertIsInstance(ret, dict)
+
+ ret = get_kwargs()
+ self.assertIn(ret, ({}, None))
+ self.assertIn(type(ret), (dict, type(None)))
+
+ ret = get_kwargs(**{})
+ self.assertIn(ret, ({}, None))
+ self.assertIn(type(ret), (dict, type(None)))
+
def test_positional_args(self):
# using all positional args
self.assertEqual(