chiark / gitweb /
Stop using deprecated distutils.version.LooseVersion in tests.
authorVladimír Vondruš <mosra@centrum.cz>
Wed, 21 Aug 2024 09:23:20 +0000 (11:23 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Wed, 21 Aug 2024 11:50:31 +0000 (13:50 +0200)
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?!

15 files changed:
documentation/test_doxygen/__init__.py
documentation/test_doxygen/test_compound.py
documentation/test_doxygen/test_contents.py
documentation/test_doxygen/test_cpp.py
documentation/test_doxygen/test_example.py
documentation/test_doxygen/test_page.py
documentation/test_python/__init__.py
documentation/test_python/test_inspect.py
documentation/test_python/test_page.py
pelican-theme/test/__init__.py
pelican-theme/test/test_page.py
plugins/m/test/__init__.py
plugins/m/test/test_dot.py
plugins/m/test/test_plots.py
plugins/m/test/test_qr.py

index c289bcdeea0c69dd18dee0ec56868f975c300c28..ec046ea88703627ace90d25a377f0a790f9e39a0 100644 (file)
@@ -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):
index 36960b94f39b64a60172b97787980b7ce4b4343a..4c8d5302725f80beb3a61b74675169594b5f3f52 100644 (file)
@@ -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')
index 58300d90f28a316d444c77fafa21f0bf282f77ed..4035037c5adb794dac5663bea100855743694d82 100644 (file)
@@ -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<version>\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 <hruler> into <briefdescription> 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 <hr/>"
         ])
 
-    @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 <hruler> into <briefdescription> 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 <heading> into <briefdescription> 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 <p>===============</p><h4>The Thing </h4>",
         ])
 
-    @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 <heading> into <briefdescription> 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: <p>Function that's in a group</p><p>Lines of detailed description that get merged to the brief for no freaking reason.</p>"
         ])
 
-    @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 <dotfile> 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 <dotfile> 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')
index 83e77f7b46139a65f9765517952b210656d802f1..ffe09f9f64d1d84643ad20fc9ad9eb6df0a2a24c 100644 (file)
 
 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')
index 757fcc3b4fe7c5a9d3f3d50fec624194a9e8c511..bf8bc48bad473da372324e2730c00dc39087a168 100644 (file)
@@ -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')
index 0d48fb95b4a777037b2ce3656a28e3d1ba1cdd7f..d3608c7d2acd2a3dc059e87adcf6e83bf82879d4 100644 (file)
@@ -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')
index 8627742a0cb226848785d2f4d1c383d448da215c..c8243bf57c44f98acf6eb2d317090d4555f059a4 100644 (file)
@@ -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
index 9f61698200df10888d71d4b7cfc559755d5aab56..a975fd4f21e5220a3af709de3b51849f8155442e 100644 (file)
@@ -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
index bc8333c937566141d6bbeb003bd0b907311f483d..a1cc450d2478c34b3e0e786bdb10c6030826c063 100644 (file)
@@ -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<version>\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'))
index 553b8eccd275f65f374c8000e0923b0441d3a2e7..83f1b839efd1ece27414ce63313b71ffba245c47 100644 (file)
@@ -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)
index 91a0976796496429cecf24164894714a914b3719..4113fb0925d39a9c7769f339a3084e495fb783dd 100644 (file)
@@ -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({
index 59448d4dfa4ba91523d9c03baa189c1568f46d5a..23381832dfac392f66c367d6696b817a6da0777f 100644 (file)
@@ -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)
index 2acfd727b759a3c11a9937bb3c07986faaf76037..3db606ae020a7e9042d1cb4b58a26f4e24ced401 100644 (file)
@@ -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<version>\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'
index da746d91bb4dd4d3213f46c7f80591dc01aa8ee3..a32bcb97c13c84d00d6359cb1f149ba770a720a0 100644 (file)
@@ -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'))
index bbce78af27038d0309c45fd83b5f0cc2c6b8830e..312f090b90f5cb529e762e972005807c7dc86f1d 100644 (file)
@@ -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'))