diff options
author | Ran Benita <ran@unusedvar.com> | 2020-04-27 20:31:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-27 13:31:15 -0400 |
commit | 82d2b253ca0943102a332e476f2b49a5139918fd (patch) | |
tree | 7ae4c2e67ea78e925618a275c54344d047f6053e /tests | |
parent | 7daa6740e143aea914bf81f5f843eb8c5562f2ba (diff) | |
download | python-markdown-82d2b253ca0943102a332e476f2b49a5139918fd.tar.gz |
Avoid importing packaging or pkg_resources for version validation (#948)
Importing the `pkg_resources` module has high memory and startup time
cost. A recent change in 102e01c already avoided it for loading extensions,
but it's still used for validating that __version__ is correctly formatted.
It is possible to avoid it by installing the `packaging` package, but
that adds a dependency for something quite trivial.
Instead, remove the validation and add tests which check the output is
as expected.
Since `setuptools` is no longer required at runtime, remove it from
`install_required`.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_meta.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_meta.py b/tests/test_meta.py new file mode 100644 index 0000000..10a2d33 --- /dev/null +++ b/tests/test_meta.py @@ -0,0 +1,24 @@ +import unittest +from markdown.__meta__ import _get_version, __version__ + + +class TestVersion(unittest.TestCase): + + def test_get_version(self): + """Test that _get_version formats __version_info__ as required by PEP 440.""" + + self.assertEqual(_get_version((1, 1, 2, 'dev', 0)), "1.1.2.dev0") + self.assertEqual(_get_version((1, 1, 2, 'alpha', 1)), "1.1.2a1") + self.assertEqual(_get_version((1, 2, 0, 'beta', 2)), "1.2b2") + self.assertEqual(_get_version((1, 2, 0, 'rc', 4)), "1.2rc4") + self.assertEqual(_get_version((1, 2, 0, 'final', 0)), "1.2") + + def test__version__IsValid(self): + """Test that __version__ is valid and normalized.""" + + try: + import packaging.version + except ImportError: + from pkg_resources.extern import packaging + + self.assertEqual(__version__, str(packaging.version.Version(__version__))) |