From aaca1165167c257bf1070b192bf0601c2d3da610 Mon Sep 17 00:00:00 2001 From: Laurent LAPORTE Date: Wed, 25 Aug 2021 23:06:14 +0200 Subject: [PATCH] Add unit tests to diagnose issues #48 --- tests/test_sphinx_class.py | 65 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/test_sphinx_class.py b/tests/test_sphinx_class.py index 1a0efb8..6a2f3c2 100644 --- a/tests/test_sphinx_class.py +++ b/tests/test_sphinx_class.py @@ -82,3 +82,68 @@ class MySubClass(MyBaseClass): assert isinstance(obj, MyBaseClass) assert inspect.isclass(MyBaseClass) assert issubclass(MySubClass, MyBaseClass) + + +@pytest.mark.skipif( + sys.version_info < (3, 3), reason="Classes should have mutable docstrings -- resolved in python 3.3" +) +def test_isinstance_versionadded(): + # https://github.com/tantale/deprecated/issues/48 + @deprecated.sphinx.versionadded(version="X.Y", reason="some reason") + class VersionAddedCls: + pass + + @deprecated.sphinx.versionadded(version="X.Y", reason="some reason") + class VersionAddedChildCls(VersionAddedCls): + pass + + instance = VersionAddedChildCls() + assert isinstance(instance, VersionAddedChildCls) + assert isinstance(instance, VersionAddedCls) + + +@pytest.mark.skipif( + sys.version_info < (3, 3), reason="Classes should have mutable docstrings -- resolved in python 3.3" +) +def test_isinstance_versionchanged(): + @deprecated.sphinx.versionchanged(version="X.Y", reason="some reason") + class VersionChangedCls: + pass + + @deprecated.sphinx.versionchanged(version="X.Y", reason="some reason") + class VersionChangedChildCls(VersionChangedCls): + pass + + instance = VersionChangedChildCls() + assert isinstance(instance, VersionChangedChildCls) + assert isinstance(instance, VersionChangedCls) + + +@pytest.mark.skipif( + sys.version_info < (3, 3), reason="Classes should have mutable docstrings -- resolved in python 3.3" +) +def test_isinstance_deprecated(): + @deprecated.sphinx.deprecated(version="X.Y", reason="some reason") + class DeprecatedCls: + pass + + @deprecated.sphinx.deprecated(version="Y.Z", reason="some reason") + class DeprecatedChildCls(DeprecatedCls): + pass + + instance = DeprecatedChildCls() + assert isinstance(instance, DeprecatedChildCls) + assert isinstance(instance, DeprecatedCls) + + +@pytest.mark.skipif( + sys.version_info < (3, 3), reason="Classes should have mutable docstrings -- resolved in python 3.3" +) +def test_isinstance_versionadded_versionchanged(): + @deprecated.sphinx.versionadded(version="X.Y") + @deprecated.sphinx.versionchanged(version="X.Y.Z") + class AddedChangedCls: + pass + + instance = AddedChangedCls() + assert isinstance(instance, AddedChangedCls)