summaryrefslogtreecommitdiff
path: root/Lib/test/test_inspect.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2016-01-11 15:15:01 -0500
committerYury Selivanov <yselivanov@sprymix.com>2016-01-11 15:15:01 -0500
commitd507d724fee8dbcce5a22e10c1ea0e11f107c30e (patch)
tree7917c0570f29dac6628534f58c4cc23d8c4e9ac1 /Lib/test/test_inspect.py
parent8cbab79a2a5299485dd7ac0e645c09d2f57d77da (diff)
downloadcpython-d507d724fee8dbcce5a22e10c1ea0e11f107c30e.tar.gz
Issue #25486: Resurrect inspect.getargspec in 3.6. Backout a565aad5d6e1.
The decision is that we shouldn't remove popular APIs (however long they are depreacted) from Python 3, while 2.7 is still around and supported.
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r--Lib/test/test_inspect.py40
1 files changed, 35 insertions, 5 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index a88e7fdbd8..283c92268c 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -628,6 +628,18 @@ 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):
+ with self.assertWarns(DeprecationWarning):
+ args, varargs, varkw, defaults = inspect.getargspec(routine)
+ self.assertEqual(args, args_e)
+ self.assertEqual(varargs, varargs_e)
+ self.assertEqual(varkw, varkw_e)
+ self.assertEqual(defaults, defaults_e)
+ if formatted is not None:
+ 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,
@@ -646,6 +658,23 @@ class TestClassesAndFunctions(unittest.TestCase):
kwonlyargs, kwonlydefaults, ann),
formatted)
+ def test_getargspec(self):
+ 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, [])
+ self.assertRaises(ValueError, self.assertArgSpecEquals,
+ mod2.keyword_only_arg, [])
+
+
def test_getfullargspec(self):
self.assertFullArgSpecEquals(mod2.keyworded, [], varargs_e='arg1',
kwonlyargs_e=['arg2'],
@@ -659,19 +688,20 @@ class TestClassesAndFunctions(unittest.TestCase):
kwonlyargs_e=['arg'],
formatted='(*, arg)')
- def test_fullargspec_api_ignores_wrapped(self):
+ def test_argspec_api_ignores_wrapped(self):
# Issue 20684: low level introspection API must ignore __wrapped__
@functools.wraps(mod.spam)
def ham(x, y):
pass
# Basic check
+ self.assertArgSpecEquals(ham, ['x', 'y'], formatted='(x, y)')
self.assertFullArgSpecEquals(ham, ['x', 'y'], formatted='(x, y)')
self.assertFullArgSpecEquals(functools.partial(ham),
['x', 'y'], formatted='(x, y)')
# Other variants
def check_method(f):
- self.assertFullArgSpecEquals(f, ['self', 'x', 'y'],
- formatted='(self, x, y)')
+ self.assertArgSpecEquals(f, ['self', 'x', 'y'],
+ formatted='(self, x, y)')
class C:
@functools.wraps(mod.spam)
def ham(self, x, y):
@@ -749,11 +779,11 @@ class TestClassesAndFunctions(unittest.TestCase):
with self.assertRaises(TypeError):
inspect.getfullargspec(builtin)
- def test_getfullargspec_method(self):
+ def test_getargspec_method(self):
class A(object):
def m(self):
pass
- self.assertFullArgSpecEquals(A.m, ['self'])
+ self.assertArgSpecEquals(A.m, ['self'])
def test_classify_newstyle(self):
class A(object):