summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_inspect.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2014-01-28 22:27:39 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2014-01-28 22:27:39 (GMT)
commit38b0d5a778c8e296374bd59e6f8bb840d317d6e0 (patch)
tree52f14a96913db8506530cd57cf0963b697302d27 /Lib/test/test_inspect.py
parent8757ead38e5a05f8525c859ff8c974dba2e290b7 (diff)
downloadcpython-38b0d5a778c8e296374bd59e6f8bb840d317d6e0.zip
cpython-38b0d5a778c8e296374bd59e6f8bb840d317d6e0.tar.gz
cpython-38b0d5a778c8e296374bd59e6f8bb840d317d6e0.tar.bz2
inspect.Signature.bind: Fix pos-only params with defaults; fix *args in named args #19140
Initial patch by Yann Kaiser (epsy).
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r--Lib/test/test_inspect.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 1d251b9..1325c7a 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -2516,6 +2516,15 @@ class TestSignatureBind(unittest.TestCase):
self.assertEqual(self.call(test, 1, 2, 4, 5, bar=6),
(1, 2, 4, 5, 6, {}))
+ self.assertEqual(self.call(test, 1, 2),
+ (1, 2, 3, 42, 50, {}))
+
+ self.assertEqual(self.call(test, 1, 2, foo=4, bar=5),
+ (1, 2, 3, 4, 5, {}))
+
+ with self.assertRaisesRegex(TypeError, "but was passed as a keyword"):
+ self.call(test, 1, 2, foo=4, bar=5, c_po=10)
+
with self.assertRaisesRegex(TypeError, "parameter is positional only"):
self.call(test, 1, 2, c_po=4)
@@ -2532,6 +2541,22 @@ class TestSignatureBind(unittest.TestCase):
ba = sig.bind(1, self=2, b=3)
self.assertEqual(ba.args, (1, 2, 3))
+ def test_signature_bind_vararg_name(self):
+ def test(a, *args):
+ return a, args
+ sig = inspect.signature(test)
+
+ with self.assertRaisesRegex(TypeError, "too many keyword arguments"):
+ sig.bind(a=0, args=1)
+
+ def test(*args, **kwargs):
+ return args, kwargs
+ self.assertEqual(self.call(test, args=1), ((), {'args': 1}))
+
+ sig = inspect.signature(test)
+ ba = sig.bind(args=1)
+ self.assertEqual(ba.arguments, {'kwargs': {'args': 1}})
+
class TestBoundArguments(unittest.TestCase):
def test_signature_bound_arguments_unhashable(self):