From: Vladimír Vondruš Date: Fri, 13 Sep 2024 00:24:49 +0000 (+0200) Subject: m.plots: replace hashes in test files before comparing. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=d0f183fe6072115e84575daf66d725d60d0e268b;p=blog.git m.plots: replace hashes in test files before comparing. Similarly to what I did for doxygen, the damn thing now has hashes differing even between machines. How the hell is one supposed to make reproducible builds with that, I don't know. The 3.4 variant got removed, because it differs from 3.2 only in those hashes, so it isn't needed anymore. Now I can finally unpin it from 3.7 on the CI and stop being afraid that it changes again with 3.9.3. --- diff --git a/documentation/test_python/page_plugins/plots-34.html b/documentation/test_python/page_plugins/plots-34.html deleted file mode 100644 index a0b54cf8..00000000 --- a/documentation/test_python/page_plugins/plots-34.html +++ /dev/null @@ -1,163 +0,0 @@ - - - - - And now something totally different | My Python Project - - - - - -
-
-
-
-
-

- And now something totally different -

-
- - - - - - - - - - 15.0 meters, i guess? - - - 30.0 meters, i guess? - - - - - - - - - - - - - - 0 - - - - - - - - - - 5 - - - - - - - - - - 10 - - - - - - - - - - 15 - - - - - - - - - - 20 - - - - - - - - - - 25 - - - - - - - - - - 30 - - - - meters, i guess? - - - - - - - - - - - - - - First - - - - - - - - - - Second - - - - - A plot with a single color - - - - - - - - - -
-
-
-
-
- - diff --git a/documentation/test_python/test_page.py b/documentation/test_python/test_page.py index 94e9459c..1c365892 100644 --- a/documentation/test_python/test_page.py +++ b/documentation/test_python/test_page.py @@ -30,6 +30,9 @@ import subprocess from . import BaseTestCase, parse_version +# Same as in the m.plots test case, see there for details +_normalize_matplotlib_hashes = re.compile('([mp])[0-9a-f]{10}') + def dot_version(): return re.match(r'.*version (?P\d+\.\d+\.\d+).*', subprocess.check_output(['dot', '-V'], stderr=subprocess.STDOUT).decode('utf-8').strip()).group('version') @@ -99,11 +102,15 @@ class Plugins(BaseTestCase): file = 'plots.html' elif parse_version(matplotlib.__version__) >= parse_version('3.5'): file = 'plots-35.html' - elif parse_version(matplotlib.__version__) >= parse_version('3.4'): - file = 'plots-34.html' else: file = 'plots-32.html' - self.assertEqual(*self.actual_expected_contents('plots.html', file)) + + # The element hashes change wildly between versions, replace them with + # something stable before comparison + plots_actual_contents, plots_expected_contents = self.actual_expected_contents('plots.html', file) + plots_actual_contents = _normalize_matplotlib_hashes.sub(r'\1gggggggggg', plots_actual_contents) + plots_expected_contents = _normalize_matplotlib_hashes.sub(r'\1gggggggggg', plots_expected_contents) + self.assertEqual(plots_actual_contents, plots_expected_contents) self.assertTrue(os.path.exists(os.path.join(self.path, 'output/tiny.png'))) import fancyline diff --git a/package/ci/circleci.yml b/package/ci/circleci.yml index cdc3b549..3a958bbc 100644 --- a/package/ci/circleci.yml +++ b/package/ci/circleci.yml @@ -243,7 +243,7 @@ jobs: - install-base: extra: graphviz cmake ninja-build wget - install-python-deps: - # Matplotlib 3.6 has slightly different output, be sure to have at + # Matplotlib 3.6+ has slightly different output, be sure to have at # least one job testing 3.5 so we don't regress matplotlib-version: ==3.5.2 # Docutils 0.18.0 dropped `in_footnote_list` and made some changes that @@ -267,9 +267,9 @@ jobs: # libtinfo5 needed by doxygen 1.8.18, wtf extra: graphviz cmake ninja-build wget libtinfo5 - install-python-deps: - # Matplotlib 3.8+ has significantly different output AGAIN, pin on 3.7 - # until I can be bothered testing yet again - matplotlib-version: ==3.7.4 + # Matplotlib 3.6 to 3.9.2 is known to have output as expected, pin it + # to ensure we don't regress once new versions change something again + matplotlib-version: ==3.9.2 # NumPy 2.0 only works with pybind 2.12+ numpy-version: ==1.26.4 - checkout @@ -290,9 +290,6 @@ jobs: # libtinfo5 needed by doxygen 1.8.18, wtf extra: graphviz cmake ninja-build wget libtinfo5 - install-python-deps: - # Matplotlib 3.8+ has significantly different output AGAIN, pin on 3.7 - # until I can be bothered testing yet again - matplotlib-version: ==3.7.4 # NumPy 2.0 doesn't work with pybind 2.11, see below numpy-version: ==1.26.4 - checkout diff --git a/plugins/m/test/plots/page-34.html b/plugins/m/test/plots/page-34.html deleted file mode 100644 index 87863bad..00000000 --- a/plugins/m/test/plots/page-34.html +++ /dev/null @@ -1,682 +0,0 @@ - - - - - m.plots | A Pelican Blog - - - - - - -
-
-
-
-
-
-

m.plots

- -

Note: the test uses DejaVu Sans instead of Source Sans Pro in order to have -predictable rendering on the CIs.

-
- - - - - - - - - - 15.0 meters, i guess? - - - 30.0 meters, i guess? - - - - - - - - - - - - - - 0 - - - - - - - - - - 5 - - - - - - - - - - 10 - - - - - - - - - - 15 - - - - - - - - - - 20 - - - - - - - - - - 25 - - - - - - - - - - 30 - - - - meters, i guess? - - - - - - - - - - - - - - First - - - - - - - - - - Second - - - - - A plot with a single color - - - - - - - - - -
-
-

A plot with separate colors, extra labels, error bars and custom width + height

-
- - - - - - - - - - 3.0 ± 0.1 Mondays - - - 4.0 ± 2.1 Mondays - - - 5.0 ± 1.0 Mondays - - - - - - - - - - - - - - 0 - - - - - - - - - - 1 - - - - - - - - - - 2 - - - - - - - - - - 3 - - - - - - - - - - 4 - - - - - - - - - - 5 - - - - - - - - - - 6 - - - - Mondays - - - - - - - - - - - - - - January - - - - - - - - - - - February - - - - - - - - - - March - - - - - - - - - - - - - - - - - - - - - - - - - - - - - a paradise - - - - hell! - - - Yes. - - - - - - - - - -
-
-
- - - - - - - - - - 111.9 kB - - - 74.4 kB - - - 52.1 kB - - - 731.2 kB - - - 226.3 kB - - - 226.0 kB - - - - - - - - - - - - - - 0 - - - - - - - - - - 100 - - - - - - - - - - 200 - - - - - - - - - - 300 - - - - - - - - - - 400 - - - - - - - - - - 500 - - - - - - - - - - 600 - - - - - - - - - - 700 - - - - - - - - - - 800 - - - - kB - - - - - - - - - - - - - - A - - - - - - - - - - B - - - - - - - - - - C - - - - - Stacked plot - - - - - - - - - -
-
- - - - - - - - - - 111.9 ± 25.0 kB - - - 74.4 ± 15.3 kB - - - 731.2 ± 200.0 kB - - - 226.3 ± 5.0 kB - - - - - - - - - - - - - - 0 - - - - - - - - - - 200 - - - - - - - - - - 400 - - - - - - - - - - 600 - - - - - - - - - - 800 - - - - - - - - - - 1000 - - - - kB - - - - - - - - - - - - - - A - - - - - - - - - - B - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Stacked plot with errors and full colors - - - - - - - - - -
- -
-
-
-
-
- - diff --git a/plugins/m/test/test_plots.py b/plugins/m/test/test_plots.py index 0e932352..8261e459 100644 --- a/plugins/m/test/test_plots.py +++ b/plugins/m/test/test_plots.py @@ -25,11 +25,18 @@ import matplotlib import os +import re import sys import unittest from . import PelicanPluginTestCase, parse_version +# Basically every matplotlib version causes the hashes to change, and 3.9.2 has +# them also different on different machines. Yay software developers. Replace +# them with a static string when comparing. The actual file is not changed in +# order to make it possible to actually view it, it's only for the comparison. +_normalize_hashes = re.compile('([mp])[0-9a-f]{10}') + class Plots(PelicanPluginTestCase): def __init__(self, *args, **kwargs): super().__init__(__file__, '', *args, **kwargs) @@ -46,8 +53,6 @@ class Plots(PelicanPluginTestCase): file = 'page.html' elif parse_version(matplotlib.__version__) >= parse_version('3.5'): file = 'page-35.html' - elif parse_version(matplotlib.__version__) >= parse_version('3.4'): - file = 'page-34.html' elif parse_version(matplotlib.__version__) >= parse_version('3.2'): file = 'page-32.html' elif parse_version(matplotlib.__version__) >= parse_version('3.0'): @@ -55,4 +60,9 @@ class Plots(PelicanPluginTestCase): else: file = 'page-22.html' - self.assertEqual(*self.actual_expected_contents('page.html', file)) + # The element hashes change wildly between versions, replace them with + # something stable before comparison + actual_contents, expected_contents = self.actual_expected_contents('page.html', file) + actual_contents = _normalize_hashes.sub(r'\1gggggggggg', actual_contents) + expected_contents = _normalize_hashes.sub(r'\1gggggggggg', expected_contents) + self.assertEqual(actual_contents, expected_contents)