From 66c957372deae9c0d813ded27b19b17381eb78d4 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 12 Jun 2017 00:24:58 +0900 Subject: [PATCH] Add testcase for sphinx.util.inspect:getargspec() --- tests/test_util_inspect.py | 45 +++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/tests/test_util_inspect.py b/tests/test_util_inspect.py index e9730cf35..5e6439705 100644 --- a/tests/test_util_inspect.py +++ b/tests/test_util_inspect.py @@ -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