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.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from unittest import TestCase
|
||||
|
||||
import sys
|
||||
from six import PY3
|
||||
import functools
|
||||
@ -19,12 +17,12 @@ import pytest
|
||||
from sphinx.util import inspect
|
||||
|
||||
|
||||
class TestGetArgSpec(TestCase):
|
||||
def test_getargspec_builtin_type(self):
|
||||
def test_getargspec_builtin_type():
|
||||
with pytest.raises(TypeError):
|
||||
inspect.getargspec(int)
|
||||
|
||||
def test_getargspec_partial(self):
|
||||
|
||||
def test_getargspec_partial():
|
||||
def fun(a, b, c=1, d=2):
|
||||
pass
|
||||
p = functools.partial(fun, 10, c=11)
|
||||
@ -46,7 +44,8 @@ class TestGetArgSpec(TestCase):
|
||||
|
||||
assert expected == inspect.getargspec(p)
|
||||
|
||||
def test_getargspec_bound_methods(self):
|
||||
|
||||
def test_getargspec_bound_methods():
|
||||
def f_expected_unbound(self, arg1, **kwargs):
|
||||
pass
|
||||
expected_unbound = inspect.getargspec(f_expected_unbound)
|
||||
@ -75,8 +74,7 @@ class TestGetArgSpec(TestCase):
|
||||
assert expected_bound == inspect.getargspec(wrapped_bound_method)
|
||||
|
||||
|
||||
class TestSafeGetAttr(TestCase):
|
||||
def test_safe_getattr_with_default(self):
|
||||
def test_safe_getattr_with_default():
|
||||
class Foo(object):
|
||||
def __getattr__(self, item):
|
||||
raise Exception
|
||||
@ -87,7 +85,8 @@ class TestSafeGetAttr(TestCase):
|
||||
|
||||
assert result == 'baz'
|
||||
|
||||
def test_safe_getattr_with_exception(self):
|
||||
|
||||
def test_safe_getattr_with_exception():
|
||||
class Foo(object):
|
||||
def __getattr__(self, item):
|
||||
raise Exception
|
||||
@ -97,11 +96,12 @@ class TestSafeGetAttr(TestCase):
|
||||
try:
|
||||
inspect.safe_getattr(obj, 'bar')
|
||||
except AttributeError as exc:
|
||||
self.assertEqual(exc.args[0], 'bar')
|
||||
assert exc.args[0] == 'bar'
|
||||
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):
|
||||
@property
|
||||
def bar(self):
|
||||
@ -112,11 +112,12 @@ class TestSafeGetAttr(TestCase):
|
||||
try:
|
||||
inspect.safe_getattr(obj, 'bar')
|
||||
except AttributeError as exc:
|
||||
self.assertEqual(exc.args[0], 'bar')
|
||||
assert exc.args[0] == 'bar'
|
||||
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):
|
||||
@property
|
||||
def __dict__(self):
|
||||
@ -127,6 +128,6 @@ class TestSafeGetAttr(TestCase):
|
||||
try:
|
||||
inspect.safe_getattr(obj, 'bar')
|
||||
except AttributeError as exc:
|
||||
self.assertEqual(exc.args[0], 'bar')
|
||||
assert exc.args[0] == 'bar'
|
||||
else:
|
||||
self.fail('AttributeError not raised')
|
||||
pytest.fail('AttributeError not raised')
|
||||
|
Loading…
Reference in New Issue
Block a user