Add testcase for sphinx.util.inspect:getargspec()

This commit is contained in:
Takeshi KOMIYA 2017-06-12 00:24:58 +09:00
parent 94b31a2f07
commit 66c957372d

View File

@ -17,12 +17,46 @@ import pytest
from sphinx.util import inspect
def test_getargspec_builtin_type():
with pytest.raises(TypeError):
inspect.getargspec(int)
def test_getargspec():
def func(a, b, c=1, d=2, *e, **f):
pass
spec = inspect.getargspec(func)
assert spec.args == ['a', 'b', 'c', 'd']
assert spec.varargs == 'e'
if PY3:
assert spec.varkw == 'f'
assert spec.defaults == (1, 2)
assert spec.kwonlyargs == []
assert spec.kwonlydefaults is None
assert spec.annotations == {}
else:
assert spec.keywords == 'f'
assert spec.defaults == [1, 2]
def test_getargspec_partial():
def func1(a, b, c=1, d=2, *e, **f):
pass
partial = functools.partial(func1, 10, c=11)
spec = inspect.getargspec(partial)
if PY3:
assert spec.args == ['b']
assert spec.varargs is None
assert spec.varkw == 'f'
assert spec.defaults is None
assert spec.kwonlyargs == ['c', 'd']
assert spec.kwonlydefaults == {'c': 11, 'd': 2}
assert spec.annotations == {}
else:
assert spec.args == ['b', 'd']
assert spec.varargs == 'e'
assert spec.keywords == 'f'
assert spec.defaults == [2]
def test_getargspec_partial2():
def fun(a, b, c=1, d=2):
pass
p = functools.partial(fun, 10, c=11)
@ -45,6 +79,11 @@ def test_getargspec_partial():
assert expected == inspect.getargspec(p)
def test_getargspec_builtin_type():
with pytest.raises(TypeError):
inspect.getargspec(int)
def test_getargspec_bound_methods():
def f_expected_unbound(self, arg1, **kwargs):
pass