mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Refactor test_util_inspect: Do not use unittest
This commit is contained in:
parent
f6d0b07704
commit
94b31a2f07
@ -8,8 +8,6 @@
|
|||||||
:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
|
:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
|
||||||
:license: BSD, see LICENSE for details.
|
:license: BSD, see LICENSE for details.
|
||||||
"""
|
"""
|
||||||
from unittest import TestCase
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from six import PY3
|
from six import PY3
|
||||||
import functools
|
import functools
|
||||||
@ -19,12 +17,12 @@ import pytest
|
|||||||
from sphinx.util import inspect
|
from sphinx.util import inspect
|
||||||
|
|
||||||
|
|
||||||
class TestGetArgSpec(TestCase):
|
def test_getargspec_builtin_type():
|
||||||
def test_getargspec_builtin_type(self):
|
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
inspect.getargspec(int)
|
inspect.getargspec(int)
|
||||||
|
|
||||||
def test_getargspec_partial(self):
|
|
||||||
|
def test_getargspec_partial():
|
||||||
def fun(a, b, c=1, d=2):
|
def fun(a, b, c=1, d=2):
|
||||||
pass
|
pass
|
||||||
p = functools.partial(fun, 10, c=11)
|
p = functools.partial(fun, 10, c=11)
|
||||||
@ -46,7 +44,8 @@ class TestGetArgSpec(TestCase):
|
|||||||
|
|
||||||
assert expected == inspect.getargspec(p)
|
assert expected == inspect.getargspec(p)
|
||||||
|
|
||||||
def test_getargspec_bound_methods(self):
|
|
||||||
|
def test_getargspec_bound_methods():
|
||||||
def f_expected_unbound(self, arg1, **kwargs):
|
def f_expected_unbound(self, arg1, **kwargs):
|
||||||
pass
|
pass
|
||||||
expected_unbound = inspect.getargspec(f_expected_unbound)
|
expected_unbound = inspect.getargspec(f_expected_unbound)
|
||||||
@ -75,8 +74,7 @@ class TestGetArgSpec(TestCase):
|
|||||||
assert expected_bound == inspect.getargspec(wrapped_bound_method)
|
assert expected_bound == inspect.getargspec(wrapped_bound_method)
|
||||||
|
|
||||||
|
|
||||||
class TestSafeGetAttr(TestCase):
|
def test_safe_getattr_with_default():
|
||||||
def test_safe_getattr_with_default(self):
|
|
||||||
class Foo(object):
|
class Foo(object):
|
||||||
def __getattr__(self, item):
|
def __getattr__(self, item):
|
||||||
raise Exception
|
raise Exception
|
||||||
@ -87,7 +85,8 @@ class TestSafeGetAttr(TestCase):
|
|||||||
|
|
||||||
assert result == 'baz'
|
assert result == 'baz'
|
||||||
|
|
||||||
def test_safe_getattr_with_exception(self):
|
|
||||||
|
def test_safe_getattr_with_exception():
|
||||||
class Foo(object):
|
class Foo(object):
|
||||||
def __getattr__(self, item):
|
def __getattr__(self, item):
|
||||||
raise Exception
|
raise Exception
|
||||||
@ -97,11 +96,12 @@ class TestSafeGetAttr(TestCase):
|
|||||||
try:
|
try:
|
||||||
inspect.safe_getattr(obj, 'bar')
|
inspect.safe_getattr(obj, 'bar')
|
||||||
except AttributeError as exc:
|
except AttributeError as exc:
|
||||||
self.assertEqual(exc.args[0], 'bar')
|
assert exc.args[0] == 'bar'
|
||||||
else:
|
else:
|
||||||
self.fail('AttributeError not raised')
|
pytest.fail('AttributeError not raised')
|
||||||
|
|
||||||
def test_safe_getattr_with_property_exception(self):
|
|
||||||
|
def test_safe_getattr_with_property_exception():
|
||||||
class Foo(object):
|
class Foo(object):
|
||||||
@property
|
@property
|
||||||
def bar(self):
|
def bar(self):
|
||||||
@ -112,11 +112,12 @@ class TestSafeGetAttr(TestCase):
|
|||||||
try:
|
try:
|
||||||
inspect.safe_getattr(obj, 'bar')
|
inspect.safe_getattr(obj, 'bar')
|
||||||
except AttributeError as exc:
|
except AttributeError as exc:
|
||||||
self.assertEqual(exc.args[0], 'bar')
|
assert exc.args[0] == 'bar'
|
||||||
else:
|
else:
|
||||||
self.fail('AttributeError not raised')
|
pytest.fail('AttributeError not raised')
|
||||||
|
|
||||||
def test_safe_getattr_with___dict___override(self):
|
|
||||||
|
def test_safe_getattr_with___dict___override():
|
||||||
class Foo(object):
|
class Foo(object):
|
||||||
@property
|
@property
|
||||||
def __dict__(self):
|
def __dict__(self):
|
||||||
@ -127,6 +128,6 @@ class TestSafeGetAttr(TestCase):
|
|||||||
try:
|
try:
|
||||||
inspect.safe_getattr(obj, 'bar')
|
inspect.safe_getattr(obj, 'bar')
|
||||||
except AttributeError as exc:
|
except AttributeError as exc:
|
||||||
self.assertEqual(exc.args[0], 'bar')
|
assert exc.args[0] == 'bar'
|
||||||
else:
|
else:
|
||||||
self.fail('AttributeError not raised')
|
pytest.fail('AttributeError not raised')
|
||||||
|
Loading…
Reference in New Issue
Block a user