summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIsaac Muse <faceless.shop@gmail.com>2018-10-25 07:43:27 -0600
committerWaylan Limberg <waylan.limberg@icloud.com>2018-10-25 09:43:27 -0400
commitd81207a6bd2a60c39b971baf789f8ac7fa912a21 (patch)
treec35fcfad8e76504635a4df5dd1cedb581fddf02d /tests
parentd9ee723c5cbfae4f68d66cc18414e7062e8afed4 (diff)
downloadpython-markdown-d81207a6bd2a60c39b971baf789f8ac7fa912a21.tar.gz
Deprecate version and version_info (#740)
This essentially implements the closest we can get to PEP 562 which allows for modules to control `__dir__` and `__getattr__` in order to deprecate attributes. Here we provide a wrapper class for the module in `util`. If a module has attributes that need to deprecated, we derive from the wrapper class and define the attributes as functions with the `property` decorator and the provided `deprecated` decorator. The class is instantiated with the module's `__name__` attribute and the class will properly replace the module with the wrapped module. When accessing the depracted attributes, a warning is raised. Closes #739.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_apis.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/test_apis.py b/tests/test_apis.py
index 20144e4..a9fa770 100644
--- a/tests/test_apis.py
+++ b/tests/test_apis.py
@@ -1004,3 +1004,42 @@ Some +test+ and a [+link+](http://test.com)
self.md.reset()
self.assertEqual(self.md.convert(test), result)
+
+
+class TestGeneralDeprecations(unittest.TestCase):
+ """Test general deprecations."""
+
+ def test_version_deprecation(self):
+ """Test that version is deprecated."""
+
+ with warnings.catch_warnings(record=True) as w:
+ # Cause all warnings to always be triggered.
+ warnings.simplefilter("always")
+ # Trigger a warning.
+ version = markdown.version
+ # Verify some things
+ self.assertTrue(len(w) == 1)
+ self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
+ self.assertEqual(version, markdown.__version__)
+
+ def test_version_info_deprecation(self):
+ """Test that version info is deprecated."""
+
+ with warnings.catch_warnings(record=True) as w:
+ # Cause all warnings to always be triggered.
+ warnings.simplefilter("always")
+ # Trigger a warning.
+ version_info = markdown.version_info
+ # Verify some things
+ self.assertTrue(len(w) == 1)
+ self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
+ self.assertEqual(version_info, markdown.__version_info__)
+
+ def test_deprecation_wrapper_dir(self):
+ """Tests the `__dir__` attribute of the class as it replaces the module's."""
+
+ dir_attr = dir(markdown)
+ self.assertTrue('version' in dir_attr)
+ self.assertTrue('__version__' in dir_attr)
+ self.assertTrue('version_info' in dir_attr)
+ self.assertTrue('__version_info__' in dir_attr)