From: Vladimír Vondruš Date: Wed, 21 Aug 2024 09:23:20 +0000 (+0200) Subject: Stop using deprecated distutils.version.LooseVersion in tests. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=8f080819783f2daf085d8b8d954dcbee4d27c2a9;p=blog.git Stop using deprecated distutils.version.LooseVersion in tests. I was waiting *half a decade* for this to get resolved in a less than insane way, but NOPE. Instead of using builtin functionality for such a basic operation as version comparison (heck, even CMake has that builtin!!) we're now instructed to PIP INSTALL PACKAGING. Where did the "batteries included" spirit go? Why is everything increasingly overengineered? Why can't a project stay in place for a few years, WHY DO I HAVE TO ADAPT TO MEANINGLESS CHANGES ALL THE TIME?! --- diff --git a/documentation/test_doxygen/__init__.py b/documentation/test_doxygen/__init__.py index c289bcde..ec046ea8 100644 --- a/documentation/test_doxygen/__init__.py +++ b/documentation/test_doxygen/__init__.py @@ -37,7 +37,12 @@ from doxygen import State, parse_doxyfile, run, default_templates, default_wildc _camelcase_to_snakecase = re.compile('((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))') def doxygen_version(): - return subprocess.check_output(['doxygen', '-v']).decode('utf-8').strip() + return subprocess.check_output(['doxygen', '-v']).decode('utf-8').strip().split(' ')[0] + +# A copy of the same utility that's in plugins/m/test/__init__.py because +# distutils is deprecated and alternatives are insane. See there for details. +def parse_version(string: str): + return tuple([int(i) for i in string.split('.')]) class BaseTestCase(unittest.TestCase): def __init__(self, *args, dir=None, **kwargs): diff --git a/documentation/test_doxygen/test_compound.py b/documentation/test_doxygen/test_compound.py index 36960b94..4c8d5302 100644 --- a/documentation/test_doxygen/test_compound.py +++ b/documentation/test_doxygen/test_compound.py @@ -26,9 +26,7 @@ import os import unittest -from distutils.version import LooseVersion - -from . import IntegrationTestCase, doxygen_version +from . import IntegrationTestCase, doxygen_version, parse_version class Listing(IntegrationTestCase): def test_index_pages(self): @@ -206,7 +204,7 @@ class NamespaceMembersInFileScope(IntegrationTestCase): # The namespace should have the detailed docs self.assertEqual(*self.actual_expected_contents('namespaceNamespace.html')) - @unittest.skipUnless(LooseVersion(doxygen_version()) > LooseVersion("1.8.14"), + @unittest.skipUnless(parse_version(doxygen_version()) > parse_version("1.8.14"), "https://github.com/doxygen/doxygen/pull/653") def test_file(self): self.run_doxygen(wildcard='File_8h.xml') @@ -215,7 +213,7 @@ class NamespaceMembersInFileScope(IntegrationTestCase): self.assertEqual(*self.actual_expected_contents('File_8h.html')) class NamespaceMembersInFileScopeDefineBaseUrl(IntegrationTestCase): - @unittest.skipUnless(LooseVersion(doxygen_version()) > LooseVersion("1.8.14"), + @unittest.skipUnless(parse_version(doxygen_version()) > parse_version("1.8.14"), "https://github.com/doxygen/doxygen/pull/653") def test(self): self.run_doxygen(wildcard='File_8h.xml') diff --git a/documentation/test_doxygen/test_contents.py b/documentation/test_doxygen/test_contents.py index 58300d90..4035037c 100644 --- a/documentation/test_doxygen/test_contents.py +++ b/documentation/test_doxygen/test_contents.py @@ -32,9 +32,7 @@ import unittest from hashlib import sha1 -from distutils.version import LooseVersion - -from . import BaseTestCase, IntegrationTestCase, doxygen_version +from . import BaseTestCase, IntegrationTestCase, doxygen_version, parse_version def dot_version(): return re.match(".*version (?P\d+\.\d+\.\d+).*", subprocess.check_output(['dot', '-V'], stderr=subprocess.STDOUT).decode('utf-8').strip()).group('version') @@ -44,7 +42,7 @@ class Typography(IntegrationTestCase): self.run_doxygen(wildcard='indexpage.xml') self.assertEqual(*self.actual_expected_contents('index.html')) - @unittest.skipUnless(LooseVersion(doxygen_version()) > LooseVersion("1.8.17"), "new features in 1.8.17") + @unittest.skipUnless(parse_version(doxygen_version()) > parse_version("1.8.17"), "new features in 1.8.17") def test_1817(self): self.run_doxygen(wildcard='doxygen1817.xml') self.assertEqual(*self.actual_expected_contents('doxygen1817.html')) @@ -56,7 +54,7 @@ class Blocks(IntegrationTestCase): # Multiple xrefitems should be merged into one self.assertEqual(*self.actual_expected_contents('File_8h.html')) - @unittest.skipUnless(LooseVersion(doxygen_version()) > LooseVersion("1.8.18"), "new features in 1.8.18") + @unittest.skipUnless(parse_version(doxygen_version()) > parse_version("1.8.18"), "new features in 1.8.18") def test_1818(self): self.run_doxygen(wildcard='*.xml') self.assertEqual(*self.actual_expected_contents('doxygen1818.html')) @@ -64,16 +62,16 @@ class Blocks(IntegrationTestCase): def test_xrefitem(self): self.run_doxygen(wildcard='*.xml') - if LooseVersion(doxygen_version()) > LooseVersion("1.8.14"): + if parse_version(doxygen_version()) > parse_version("1.8.14"): self.assertEqual(*self.actual_expected_contents('todo.html')) # https://github.com/doxygen/doxygen/pull/6587 fucking broke this else: self.assertEqual(*self.actual_expected_contents('todo.html', 'todo_1814.html')) # 1.8.18 to 1.8.20 has a different order, not sure why - if LooseVersion(doxygen_version()) >= LooseVersion("1.8.18") and LooseVersion(doxygen_version()) < LooseVersion("1.9.0"): + if parse_version(doxygen_version()) >= parse_version("1.8.18") and parse_version(doxygen_version()) < parse_version("1.9.0"): self.assertEqual(*self.actual_expected_contents('old.html', 'old_1818.html')) - elif LooseVersion(doxygen_version()) > LooseVersion("1.8.14"): + elif parse_version(doxygen_version()) > parse_version("1.8.14"): self.assertEqual(*self.actual_expected_contents('old.html')) else: self.assertEqual(*self.actual_expected_contents('old.html', 'old_1814.html')) @@ -100,19 +98,19 @@ class Code(IntegrationTestCase): ]) class CodeLanguage(IntegrationTestCase): - @unittest.skipUnless(LooseVersion(doxygen_version()) > LooseVersion("1.8.13"), + @unittest.skipUnless(parse_version(doxygen_version()) > parse_version("1.8.13"), "https://github.com/doxygen/doxygen/pull/621") def test(self): self.run_doxygen(wildcard='indexpage.xml') self.assertEqual(*self.actual_expected_contents('index.html')) - @unittest.skipUnless(LooseVersion(doxygen_version()) > LooseVersion("1.8.13"), + @unittest.skipUnless(parse_version(doxygen_version()) > parse_version("1.8.13"), "https://github.com/doxygen/doxygen/pull/623") def test_ansi(self): self.run_doxygen(wildcard='ansi.xml') self.assertEqual(*self.actual_expected_contents('ansi.html')) - @unittest.skipUnless(LooseVersion(doxygen_version()) > LooseVersion("1.8.13"), + @unittest.skipUnless(parse_version(doxygen_version()) > parse_version("1.8.13"), "https://github.com/doxygen/doxygen/pull/621") def test_warnings(self): with self.assertLogs() as cm: @@ -140,7 +138,7 @@ class Image(IntegrationTestCase): "WARNING:root:warnings.xml: image nonexistent.png was not found in XML_OUTPUT" ]) - @unittest.skipUnless(LooseVersion(doxygen_version()) > LooseVersion("1.8.15"), + @unittest.skipUnless(parse_version(doxygen_version()) > parse_version("1.8.15"), "fully fixed after 1.8.15") def test_imagelink(self): self.run_doxygen(wildcard='imagelink.xml') @@ -284,7 +282,7 @@ class Custom(IntegrationTestCase): self.run_doxygen(wildcard='dot.xml') # Used to be >= 2.44.0, but 2.42.2 appears to have the same output - if LooseVersion(dot_version()) >= LooseVersion("2.42.2"): + if parse_version(dot_version()) >= parse_version("2.42.2"): file = 'dot.html' else: file = 'dot-240.html' @@ -310,7 +308,7 @@ class AutobriefBlockquote(IntegrationTestCase): # properly. class AutobriefHr(IntegrationTestCase): - @unittest.skipUnless(LooseVersion(doxygen_version()) < LooseVersion("1.8.15"), + @unittest.skipUnless(parse_version(doxygen_version()) < parse_version("1.8.15"), "1.8.15 doesn't put into anymore") def test_1814(self): with self.assertLogs() as cm: @@ -323,7 +321,7 @@ class AutobriefHr(IntegrationTestCase): "WARNING:root:namespaceNamespace.xml: JAVADOC_AUTOBRIEF / QT_AUTOBRIEF produced a brief description with block elements. That's not supported, ignoring the whole contents of
" ]) - @unittest.skipUnless(LooseVersion(doxygen_version()) >= LooseVersion("1.8.15"), + @unittest.skipUnless(parse_version(doxygen_version()) >= parse_version("1.8.15"), "1.8.15 doesn't put into anymore") def test(self): # No warnings should be produced here @@ -346,7 +344,7 @@ class AutobriefMultiline(IntegrationTestCase): ]) class AutobriefHeading(IntegrationTestCase): - @unittest.skipUnless(LooseVersion(doxygen_version()) < LooseVersion("1.8.15"), + @unittest.skipUnless(parse_version(doxygen_version()) < parse_version("1.8.15"), "1.8.15 doesn't put into anymore") def test_1814(self): with self.assertLogs() as cm: @@ -359,7 +357,7 @@ class AutobriefHeading(IntegrationTestCase): "WARNING:root:namespaceNamespace.xml: JAVADOC_AUTOBRIEF / QT_AUTOBRIEF produced a brief description with block elements. That's not supported, ignoring the whole contents of

===============

The Thing

", ]) - @unittest.skipUnless(LooseVersion(doxygen_version()) >= LooseVersion("1.8.15"), + @unittest.skipUnless(parse_version(doxygen_version()) >= parse_version("1.8.15"), "1.8.15 doesn't put into anymore") def test(self): # No warnings should be produced here @@ -368,7 +366,7 @@ class AutobriefHeading(IntegrationTestCase): self.assertEqual(*self.actual_expected_contents('namespaceNamespace.html')) class BriefMultilineIngroup(IntegrationTestCase): - @unittest.skipUnless(LooseVersion(doxygen_version()) < LooseVersion("1.8.16"), + @unittest.skipUnless(parse_version(doxygen_version()) < parse_version("1.8.16"), "1.8.16 doesn't merge adjacent paragraphs into brief in presence of an @ingroup anymore") def test_1815(self): with self.assertLogs() as cm: @@ -379,7 +377,7 @@ class BriefMultilineIngroup(IntegrationTestCase): "WARNING:root:group__thatgroup.xml: ignoring brief description containing multiple paragraphs. Please modify your markup to remove any block elements from the following:

Function that's in a group

Lines of detailed description that get merged to the brief for no freaking reason.

" ]) - @unittest.skipUnless(LooseVersion(doxygen_version()) >= LooseVersion("1.8.16"), + @unittest.skipUnless(parse_version(doxygen_version()) >= parse_version("1.8.16"), "1.8.16 doesn't merge adjacent paragraphs into brief in presence of an @ingroup anymore") def test(self): # No warnings should be produced here @@ -446,14 +444,14 @@ class Dot(IntegrationTestCase): self.run_doxygen(wildcard='indexpage.xml') # Used to be >= 2.44.0, but 2.42.2 appears to have the same output - if LooseVersion(dot_version()) >= LooseVersion("2.42.2"): + if parse_version(dot_version()) >= parse_version("2.42.2"): file = 'index.html' else: file = 'index-240.html' self.assertEqual(*self.actual_expected_contents('index.html', file)) - @unittest.skipUnless(LooseVersion(doxygen_version()) >= LooseVersion("1.8.16"), + @unittest.skipUnless(parse_version(doxygen_version()) >= parse_version("1.8.16"), "1.8.16+ drops the whole tag if the file doesn't exist, which is incredibly dumb") def test_warnings(self): # No warnings should be produced here @@ -461,7 +459,7 @@ class Dot(IntegrationTestCase): self.run_doxygen(wildcard='warnings.xml') self.assertEqual(*self.actual_expected_contents('warnings.html')) - @unittest.skipUnless(LooseVersion(doxygen_version()) < LooseVersion("1.8.16"), + @unittest.skipUnless(parse_version(doxygen_version()) < parse_version("1.8.16"), "1.8.16+ drops the whole tag if the file doesn't exist, which is incredibly dumb") def test_warnings_1815(self): with self.assertLogs() as cm: @@ -477,7 +475,7 @@ class HtmlonlyHtmlinclude(IntegrationTestCase): self.run_doxygen(wildcard='indexpage.xml') self.assertEqual(*self.actual_expected_contents('index.html')) - @unittest.skipUnless(LooseVersion(doxygen_version()) >= LooseVersion("1.8.18"), + @unittest.skipUnless(parse_version(doxygen_version()) >= parse_version("1.8.18"), "1.8.17 and older doesn't include @htmlonly in XML output") def test_htmlonly(self): self.run_doxygen(wildcard='html-only.xml') diff --git a/documentation/test_doxygen/test_cpp.py b/documentation/test_doxygen/test_cpp.py index 83e77f7b..ffe09f9f 100644 --- a/documentation/test_doxygen/test_cpp.py +++ b/documentation/test_doxygen/test_cpp.py @@ -25,19 +25,17 @@ import unittest -from distutils.version import LooseVersion - -from . import IntegrationTestCase, doxygen_version +from . import IntegrationTestCase, doxygen_version, parse_version class EnumClass(IntegrationTestCase): - @unittest.skipUnless(LooseVersion(doxygen_version()) > LooseVersion("1.8.13"), + @unittest.skipUnless(parse_version(doxygen_version()) > parse_version("1.8.13"), "https://github.com/doxygen/doxygen/pull/627") def test(self): self.run_doxygen(wildcard='File_8h.xml') self.assertEqual(*self.actual_expected_contents('File_8h.html')) class TemplateAlias(IntegrationTestCase): - @unittest.skipUnless(LooseVersion(doxygen_version()) > LooseVersion("1.8.13"), + @unittest.skipUnless(parse_version(doxygen_version()) > parse_version("1.8.13"), "https://github.com/doxygen/doxygen/pull/626") def test(self): self.run_doxygen(wildcard='*.xml') @@ -58,7 +56,7 @@ class Derived(IntegrationTestCase): self.assertEqual(*self.actual_expected_contents('annotated.html')) class Friends(IntegrationTestCase): - @unittest.skipUnless(LooseVersion(doxygen_version()) > LooseVersion("1.8.13"), + @unittest.skipUnless(parse_version(doxygen_version()) > parse_version("1.8.13"), "1.8.13 produces invalid XML for friend declarations") def test(self): self.run_doxygen(wildcard='class*.xml') diff --git a/documentation/test_doxygen/test_example.py b/documentation/test_doxygen/test_example.py index 757fcc3b..bf8bc48b 100644 --- a/documentation/test_doxygen/test_example.py +++ b/documentation/test_doxygen/test_example.py @@ -25,9 +25,7 @@ import unittest -from distutils.version import LooseVersion - -from . import IntegrationTestCase, doxygen_version +from . import IntegrationTestCase, doxygen_version, parse_version class Example(IntegrationTestCase): def test_cpp(self): @@ -36,7 +34,7 @@ class Example(IntegrationTestCase): self.assertEqual(*self.actual_expected_contents('path-prefix_2configure_8h_8cmake-example.html')) self.assertEqual(*self.actual_expected_contents('path-prefix_2main_8cpp-example.html')) - @unittest.skipUnless(LooseVersion(doxygen_version()) > LooseVersion("1.8.13"), + @unittest.skipUnless(parse_version(doxygen_version()) > parse_version("1.8.13"), "needs to have file extension exposed in the XML") def test_other(self): self.run_doxygen(index_pages=[], wildcard='*.xml') diff --git a/documentation/test_doxygen/test_page.py b/documentation/test_doxygen/test_page.py index 0d48fb95..d3608c7d 100644 --- a/documentation/test_doxygen/test_page.py +++ b/documentation/test_doxygen/test_page.py @@ -26,9 +26,7 @@ import os import unittest -from distutils.version import LooseVersion - -from . import IntegrationTestCase, doxygen_version +from . import IntegrationTestCase, doxygen_version, parse_version class Order(IntegrationTestCase): def test(self): @@ -36,7 +34,7 @@ class Order(IntegrationTestCase): self.assertEqual(*self.actual_expected_contents('pages.html')) class Brief(IntegrationTestCase): - @unittest.skipUnless(LooseVersion(doxygen_version()) > LooseVersion("1.8.13"), + @unittest.skipUnless(parse_version(doxygen_version()) > parse_version("1.8.13"), "https://github.com/doxygen/doxygen/pull/624") def test(self): self.run_doxygen(wildcard='*.xml') @@ -45,7 +43,7 @@ class Brief(IntegrationTestCase): self.assertEqual(*self.actual_expected_contents('page-b.html')) class Toc(IntegrationTestCase): - @unittest.skipUnless(LooseVersion(doxygen_version()) > LooseVersion("1.8.13"), + @unittest.skipUnless(parse_version(doxygen_version()) > parse_version("1.8.13"), "https://github.com/doxygen/doxygen/pull/625") def test(self): self.run_doxygen(wildcard='page-toc.xml') @@ -74,7 +72,7 @@ class EmptyTitle(IntegrationTestCase): self.assertEqual(*self.actual_expected_contents('untitled.html')) class SubpageOfIndex(IntegrationTestCase): - @unittest.skipUnless(LooseVersion(doxygen_version()) >= LooseVersion("1.8.17"), + @unittest.skipUnless(parse_version(doxygen_version()) >= parse_version("1.8.17"), "1.8.16 and below doesn't mark the page as subpage of index") def test(self): self.run_doxygen(wildcard='*.xml') diff --git a/documentation/test_python/__init__.py b/documentation/test_python/__init__.py index 8627742a..c8243bf5 100644 --- a/documentation/test_python/__init__.py +++ b/documentation/test_python/__init__.py @@ -36,6 +36,11 @@ from python import run, default_templates, default_config # https://stackoverflow.com/a/12867228 _camelcase_to_snakecase = re.compile('((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))') +# A copy of the same utility that's in plugins/m/test/__init__.py because +# distutils is deprecated and alternatives are insane. See there for details. +def parse_version(string: str): + return tuple([int(i) for i in string.split('.')]) + # The test files are automatically detected from derived class name and # filesystem location. For a `test_inspect.NameMapping` class, it will look # for the `inspect_name_mapping` directory. If the class name is equivalent to diff --git a/documentation/test_python/test_inspect.py b/documentation/test_python/test_inspect.py index 9f616982..a975fd4f 100644 --- a/documentation/test_python/test_inspect.py +++ b/documentation/test_python/test_inspect.py @@ -29,10 +29,8 @@ import os import sys import unittest -from distutils.version import LooseVersion - from python import default_templates -from . import BaseInspectTestCase +from . import BaseInspectTestCase, parse_version sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../plugins')) import m.sphinx @@ -86,7 +84,7 @@ class AllProperty(BaseInspectTestCase): class Annotations(BaseInspectTestCase): def test(self): self.run_python() - if LooseVersion(sys.version) >= LooseVersion('3.7.0') and LooseVersion(sys.version) < LooseVersion('3.9.0'): + if sys.version_info >= (3, 7) and sys.version_info < (3, 9): self.assertEqual(*self.actual_expected_contents('inspect_annotations.html', 'inspect_annotations-py37+38.html')) else: self.assertEqual(*self.actual_expected_contents('inspect_annotations.html')) @@ -95,13 +93,13 @@ class Annotations(BaseInspectTestCase): # This should not list any internal stuff from the typing module. The # Generic.__new__() is gone in 3.9: https://bugs.python.org/issue39168 - if LooseVersion(sys.version) >= LooseVersion('3.9.0'): + if sys.version_info >= (3, 9): self.assertEqual(*self.actual_expected_contents('inspect_annotations.AContainer.html')) else: self.assertEqual(*self.actual_expected_contents('inspect_annotations.AContainer.html', 'inspect_annotations.AContainer-py36-38.html')) # https://github.com/python/cpython/pull/13394 - @unittest.skipUnless(LooseVersion(sys.version) >= LooseVersion('3.7.4'), + @unittest.skipUnless(sys.version_info >= (3, 7, 4), "signature with / for pow() is not present in 3.6, " "3.7.3 and below has a different docstring") def test_math(self): @@ -120,7 +118,7 @@ class Annotations(BaseInspectTestCase): self.assertEqual(*self.actual_expected_contents('math.html')) # https://github.com/python/cpython/pull/13394 - @unittest.skipUnless(LooseVersion(sys.version) < LooseVersion('3.7.4') and LooseVersion(sys.version) >= LooseVersion('3.7'), + @unittest.skipUnless(sys.version_info < (3, 7, 4) and sys.version_info >= (3, 7), "signature with / for pow() is not present in 3.6, " "3.7.3 and below has a different docstring") def test_math373(self): @@ -138,7 +136,7 @@ class Annotations(BaseInspectTestCase): self.assertEqual(*self.actual_expected_contents('math.html', 'math373.html')) - @unittest.skipUnless(LooseVersion(sys.version) < LooseVersion('3.7'), + @unittest.skipUnless(sys.version_info < (3, 7), "docstring for log() is different in 3.7") def test_math36(self): # From math export only pow() so we have the verification easier, and diff --git a/documentation/test_python/test_page.py b/documentation/test_python/test_page.py index bc8333c9..a1cc450d 100644 --- a/documentation/test_python/test_page.py +++ b/documentation/test_python/test_page.py @@ -28,9 +28,7 @@ import os import re import subprocess -from distutils.version import LooseVersion - -from . import BaseTestCase +from . import BaseTestCase, parse_version def dot_version(): return re.match(".*version (?P\d+\.\d+\.\d+).*", subprocess.check_output(['dot', '-V'], stderr=subprocess.STDOUT).decode('utf-8').strip()).group('version') @@ -84,7 +82,7 @@ class Plugins(BaseTestCase): self.assertEqual(*self.actual_expected_contents('index.html')) # Used to be >= 2.44.0, but 2.42.2 appears to have the same output - if LooseVersion(dot_version()) >= LooseVersion("2.42.2"): + if parse_version(dot_version()) >= parse_version("2.42.2"): file = 'dot.html' else: file = 'dot-240.html' @@ -92,9 +90,9 @@ class Plugins(BaseTestCase): # I assume this will be a MASSIVE ANNOYANCE at some point as well so # keeping it separate. (Yes, thank you past mosra. Very helpful.) - if LooseVersion(matplotlib.__version__) >= LooseVersion('3.5'): + if parse_version(matplotlib.__version__) >= parse_version('3.5'): self.assertEqual(*self.actual_expected_contents('plots.html')) - elif LooseVersion(matplotlib.__version__) >= LooseVersion('3.4'): + elif parse_version(matplotlib.__version__) >= parse_version('3.4'): self.assertEqual(*self.actual_expected_contents('plots.html', 'plots-34.html')) else: self.assertEqual(*self.actual_expected_contents('plots.html', 'plots-32.html')) diff --git a/pelican-theme/test/__init__.py b/pelican-theme/test/__init__.py index 553b8ecc..83f1b839 100644 --- a/pelican-theme/test/__init__.py +++ b/pelican-theme/test/__init__.py @@ -29,6 +29,11 @@ import unittest from pelican import read_settings, Pelican +# A copy of the same utility that's in plugins/m/test/__init__.py because +# distutils is deprecated and alternatives are insane. See there for details. +def parse_version(string: str): + return tuple([int(i) for i in string.split('.')]) + class MinimalTestCase(unittest.TestCase): def __init__(self, path, dir, *args, **kwargs): unittest.TestCase.__init__(self, *args, **kwargs) diff --git a/pelican-theme/test/test_page.py b/pelican-theme/test/test_page.py index 91a09767..4113fb09 100644 --- a/pelican-theme/test/test_page.py +++ b/pelican-theme/test/test_page.py @@ -27,9 +27,7 @@ import unittest import pelican -from distutils.version import LooseVersion - -from test import PageTestCase +from . import PageTestCase, parse_version class Page(PageTestCase): def __init__(self, *args, **kwargs): @@ -162,7 +160,7 @@ class HtmlEscape(PageTestCase): # Not merged for 4.7 yet and no time from my side to push the PR through, # so let's defer this to blow up at some point in the future. - @unittest.skipUnless(LooseVersion(pelican.__version__) > LooseVersion("5.0.0"), + @unittest.skipUnless(parse_version(pelican.__version__) > parse_version("5.0.0"), "https://github.com/getpelican/pelican/pull/2260") def test_content(self): self.run_pelican({ diff --git a/plugins/m/test/__init__.py b/plugins/m/test/__init__.py index 59448d4d..23381832 100644 --- a/plugins/m/test/__init__.py +++ b/plugins/m/test/__init__.py @@ -29,6 +29,18 @@ import unittest from pelican import read_settings, Pelican +# distutils is deprecated, so I can no longer use LooseVersion to compare +# versions. The only sane alternative was pkg_resources, suggested at +# https://stackoverflow.com/a/57634066, but that's now ALSO deprecated, and one +# is instructed to INSTALL the packaging module in order to perform BASIC +# functionality. Fuck off. +# +# This returns a tuple of integers which should behave as intended for most +# cases, a corresponding test is in test.py. Copied to pelican-theme/test, +# documentation/test_python/ and documentation/test_doxygen. +def parse_version(string: str): + return tuple([int(i) for i in string.split('.')]) + class PelicanPluginTestCase(unittest.TestCase): def __init__(self, path, dir, *args, **kwargs): unittest.TestCase.__init__(self, *args, **kwargs) diff --git a/plugins/m/test/test_dot.py b/plugins/m/test/test_dot.py index 2acfd727..3db606ae 100644 --- a/plugins/m/test/test_dot.py +++ b/plugins/m/test/test_dot.py @@ -27,9 +27,7 @@ import re import subprocess import unittest -from distutils.version import LooseVersion - -from . import PelicanPluginTestCase +from . import PelicanPluginTestCase, parse_version def dot_version(): return re.match(".*version (?P\d+\.\d+\.\d+).*", subprocess.check_output(['dot', '-V'], stderr=subprocess.STDOUT).decode('utf-8').strip()).group('version') @@ -45,7 +43,7 @@ class Dot(PelicanPluginTestCase): }) # Used to be >= 2.44.0, but 2.42.2 appears to have the same output - if LooseVersion(dot_version()) >= LooseVersion("2.42.2"): + if parse_version(dot_version()) >= parse_version("2.42.2"): file = 'page.html' else: file = 'page-240.html' diff --git a/plugins/m/test/test_plots.py b/plugins/m/test/test_plots.py index da746d91..a32bcb97 100644 --- a/plugins/m/test/test_plots.py +++ b/plugins/m/test/test_plots.py @@ -28,9 +28,7 @@ import os import sys import unittest -from distutils.version import LooseVersion - -from . import PelicanPluginTestCase +from . import PelicanPluginTestCase, parse_version class Plots(PelicanPluginTestCase): def __init__(self, *args, **kwargs): @@ -43,13 +41,13 @@ class Plots(PelicanPluginTestCase): }) # FUCK this is annoying - if LooseVersion(matplotlib.__version__) >= LooseVersion('3.5'): + if parse_version(matplotlib.__version__) >= parse_version('3.5'): self.assertEqual(*self.actual_expected_contents('page.html')) - elif LooseVersion(matplotlib.__version__) >= LooseVersion('3.4'): + elif parse_version(matplotlib.__version__) >= parse_version('3.4'): self.assertEqual(*self.actual_expected_contents('page.html', 'page-34.html')) - elif LooseVersion(matplotlib.__version__) >= LooseVersion('3.2'): + elif parse_version(matplotlib.__version__) >= parse_version('3.2'): self.assertEqual(*self.actual_expected_contents('page.html', 'page-32.html')) - elif LooseVersion(matplotlib.__version__) >= LooseVersion('3.0'): + elif parse_version(matplotlib.__version__) >= parse_version('3.0'): self.assertEqual(*self.actual_expected_contents('page.html', 'page-30.html')) else: self.assertEqual(*self.actual_expected_contents('page.html', 'page-22.html')) diff --git a/plugins/m/test/test_qr.py b/plugins/m/test/test_qr.py index bbce78af..312f090b 100644 --- a/plugins/m/test/test_qr.py +++ b/plugins/m/test/test_qr.py @@ -25,8 +25,6 @@ import sys -from distutils.version import LooseVersion - from . import PelicanPluginTestCase class Qr(PelicanPluginTestCase): @@ -38,9 +36,9 @@ class Qr(PelicanPluginTestCase): 'PLUGINS': ['m.htmlsanity', 'm.qr'] }) - if LooseVersion(sys.version) >= LooseVersion("3.8"): + if sys.version_info >= (3, 8): self.assertEqual(*self.actual_expected_contents('page.html', 'page.html')) - elif LooseVersion(sys.version) >= LooseVersion("3.7"): + elif sys.version_info >= (3, 7): self.assertEqual(*self.actual_expected_contents('page.html', 'page-py37.html')) else: self.assertEqual(*self.actual_expected_contents('page.html', 'page-py36.html'))