Skip to content

Commit

Permalink
Add missing unit tests for decorated class methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
tantale committed Jan 21, 2018
1 parent e748ab9 commit aed57e4
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@ def foo():
return Foo.foo


@pytest.fixture(scope="module", params=_PARAMS)
def classic_deprecated_class_method(request):
if request.param is None:
class Foo(object):
@classmethod
@deprecated.classic.deprecated
def foo(cls):
pass

return Foo
else:
args, kwargs = request.param

class Foo(object):
@classmethod
@deprecated.classic.deprecated(*args, **kwargs)
def foo(cls):
pass

return Foo


# noinspection PyShadowingNames
def test_classic_deprecated_function__warns(classic_deprecated_function):
with warnings.catch_warnings(record=True) as warns:
Expand Down Expand Up @@ -143,6 +165,18 @@ def test_classic_deprecated_static_method__warns(classic_deprecated_static_metho
assert "deprecated function (or staticmethod)" in str(warn.message)


# noinspection PyShadowingNames
def test_classic_deprecated_class_method__warns(classic_deprecated_class_method):
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter("always")
cls = classic_deprecated_class_method()
cls.foo()
assert len(warns) == 1
warn = warns[0]
assert issubclass(warn.category, DeprecationWarning)
assert "deprecated function (or staticmethod)" in str(warn.message)


def test_should_raise_type_error():
try:
deprecated.classic.deprecated(5)
Expand Down
34 changes: 34 additions & 0 deletions tests/test_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,28 @@ def foo():
return Foo.foo


@pytest.fixture(scope="module", params=_PARAMS)
def sphinx_deprecated_class_method(request):
if request.param is None:
class Foo(object):
@classmethod
@deprecated.sphinx.deprecated
def foo(cls):
pass

return Foo
else:
args, kwargs = request.param

class Foo(object):
@classmethod
@deprecated.sphinx.deprecated(*args, **kwargs)
def foo(cls):
pass

return Foo


# noinspection PyShadowingNames
def test_sphinx_deprecated_function__warns(sphinx_deprecated_function):
with warnings.catch_warnings(record=True) as warns:
Expand Down Expand Up @@ -206,6 +228,18 @@ def test_sphinx_deprecated_static_method__warns(sphinx_deprecated_static_method)
assert "deprecated function (or staticmethod)" in str(warn.message)


# noinspection PyShadowingNames
def test_sphinx_deprecated_class_method__warns(sphinx_deprecated_class_method):
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter("always")
cls = sphinx_deprecated_class_method()
cls.foo()
assert len(warns) == 1
warn = warns[0]
assert issubclass(warn.category, DeprecationWarning)
assert "deprecated function (or staticmethod)" in str(warn.message)


def test_should_raise_type_error():
try:
deprecated.sphinx.deprecated(5)
Expand Down

0 comments on commit aed57e4

Please sign in to comment.