summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/inspect_fodder2.py8
-rw-r--r--Lib/test/test_inspect.py41
2 files changed, 45 insertions, 4 deletions
diff --git a/Lib/test/inspect_fodder2.py b/Lib/test/inspect_fodder2.py
index e49074c..7a9f84e 100644
--- a/Lib/test/inspect_fodder2.py
+++ b/Lib/test/inspect_fodder2.py
@@ -97,3 +97,11 @@ def f():
return 42
return X
method_in_dynamic_class = f().g.im_func
+
+#line 101
+def keyworded(*arg1, arg2=1):
+ pass
+
+#line 105
+def annotated(arg1: list):
+ pass
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index ab733fc..1858372 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -314,9 +314,8 @@ class TestClassesAndFunctions(unittest.TestCase):
got = inspect.getmro(D)
self.assertEqual(expected, got)
- def assertArgSpecEquals(self, routine, args_e, varargs_e = None,
- varkw_e = None, defaults_e = None,
- formatted = None):
+ def assertArgSpecEquals(self, routine, args_e, varargs_e=None,
+ varkw_e=None, defaults_e=None, formatted=None):
args, varargs, varkw, defaults = inspect.getargspec(routine)
self.assertEqual(args, args_e)
self.assertEqual(varargs, varargs_e)
@@ -326,14 +325,48 @@ class TestClassesAndFunctions(unittest.TestCase):
self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults),
formatted)
+ def assertFullArgSpecEquals(self, routine, args_e, varargs_e=None,
+ varkw_e=None, defaults_e=None,
+ kwonlyargs_e=[], kwonlydefaults_e=None,
+ ann_e={}, formatted=None):
+ args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = \
+ inspect.getfullargspec(routine)
+ self.assertEqual(args, args_e)
+ self.assertEqual(varargs, varargs_e)
+ self.assertEqual(varkw, varkw_e)
+ self.assertEqual(defaults, defaults_e)
+ self.assertEqual(kwonlyargs, kwonlyargs_e)
+ self.assertEqual(kwonlydefaults, kwonlydefaults_e)
+ self.assertEqual(ann, ann_e)
+ if formatted is not None:
+ self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults,
+ kwonlyargs, kwonlydefaults, ann),
+ formatted)
+
def test_getargspec(self):
- self.assertArgSpecEquals(mod.eggs, ['x', 'y'], formatted = '(x, y)')
+ self.assertArgSpecEquals(mod.eggs, ['x', 'y'], formatted='(x, y)')
self.assertArgSpecEquals(mod.spam,
['a', 'b', 'c', 'd', 'e', 'f'],
'g', 'h', (3, 4, 5),
'(a, b, c, d=3, e=4, f=5, *g, **h)')
+ self.assertRaises(ValueError, self.assertArgSpecEquals,
+ mod2.keyworded, [])
+
+ self.assertRaises(ValueError, self.assertArgSpecEquals,
+ mod2.annotated, [])
+
+ def test_getfullargspec(self):
+ self.assertFullArgSpecEquals(mod2.keyworded, [], varargs_e='arg1',
+ kwonlyargs_e=['arg2'],
+ kwonlydefaults_e={'arg2':1},
+ formatted='(*arg1, arg2=1)')
+
+ self.assertFullArgSpecEquals(mod2.annotated, ['arg1'],
+ ann_e={'arg1':types.ListType},
+ formatted='(arg1: list)')
+
def test_getargspec_method(self):
class A(object):
def m(self):