Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Mnt/multi imageset #25734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 45 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e908a41
MNT: py312 deprecates pickling objects in itertools
tacaswell Jun 20, 2023
7c1e630
FIX: also account for itertools.count used in _AxesStack
tacaswell Jun 20, 2023
94e0988
CI: skip tk tests on GHA as well
tacaswell Jun 20, 2023
0fe8d37
Revert "Revert " Merge pull request #4019 from myshen/annot_neg_coords""
tacaswell Jun 15, 2023
9c21fdc
TST: not clear how this ever worked
tacaswell Jun 15, 2023
803b4c8
TST: update test images for text baseline changes
tacaswell Jun 15, 2023
54a04c5
WIP: add a ENV to look for the baseline images out-of-tree
tacaswell Mar 10, 2023
94518d2
TST: add ENV to cause the test suite to generate baseline images
tacaswell Mar 10, 2023
4b8f248
DOC: start to sketch documentation
tacaswell Mar 30, 2023
4d13089
WIP: barely working proof-of-concept
tacaswell Apr 20, 2023
b1b8677
MNT: handle creating the metadata json file if needed
tacaswell Apr 20, 2023
69bf1e1
MNT: make keys Path objects
tacaswell Apr 21, 2023
d8dc57c
MNT: refactor directory generation functions
tacaswell May 18, 2023
eadd0ac
TST: initial checking of list of test images
tacaswell May 18, 2023
f0650f3
TST: add mpl_toolkits image lists
tacaswell May 18, 2023
d99c51d
TST: checkin generated json
tacaswell May 18, 2023
8321c88
TST: fail if git blame fails
tacaswell May 18, 2023
14747cf
TODO: temporarly xfail the test of the image comparison code
tacaswell May 18, 2023
e47cfea
TST: fix pgf tests
tacaswell May 18, 2023
cfa4d10
CI: try moving the test images on GHA
tacaswell May 18, 2023
fb8dc45
MNT: make the "do the images exist" test aware of the new ENV
tacaswell May 18, 2023
e81b503
TST: spell path correctly
tacaswell May 18, 2023
bdad428
TST: put the missing path in the error message
tacaswell May 18, 2023
2436828
TST: also adjust the guards in the mpl_toolkits test/__init__.py
tacaswell May 18, 2023
0f07609
TST: re-order eps patch magic
tacaswell May 18, 2023
b5e30d5
MNT: try to use Paths everywhere to try and fix windows
tacaswell May 19, 2023
7a4a0a3
MNT: special case the pdf for eps tests
tacaswell May 19, 2023
1138c99
CI: copy rather than move files
tacaswell May 19, 2023
79906c5
MNT: refactor compare / generate into stand alone methods
tacaswell May 19, 2023
ad48c12
ENH: add image helper CLI tool
tacaswell May 19, 2023
d36c6f8
ENH: add pytest collector to only select image tests to run
SidharthBansal Jul 1, 2020
c5b6287
Shorten the flag name
SidharthBansal Aug 10, 2020
bb7d8a0
ENH: Added Pytest Plugin to run image generation
SidharthBansal Aug 24, 2020
cffa655
MNT: remove errors on baseline images missing
tacaswell Jun 15, 2023
5516ddc
MNT: change the default libpath to match Matplotlib
tacaswell Jun 15, 2023
9680166
WIP: improve cli tool
tacaswell Jun 15, 2023
406bc96
MNT: switch to using ts*100 as int for image list timestamp
tacaswell Jun 15, 2023
2d1bb5f
MNT: add new test image
tacaswell Jun 15, 2023
30f4519
WIP: regenerate json
tacaswell Jun 15, 2023
cccab00
MNT: remove images from image_list
tacaswell Jun 15, 2023
db78223
WIP
tacaswell Jun 16, 2023
74f69b8
MNT: use - instead of _ in CLI flags
tacaswell Jun 20, 2023
cab2a30
ENH: add pytest flag + restore default values via ENV
tacaswell Jun 21, 2023
39480ab
PRF: add naive caching
tacaswell Jun 21, 2023
639ab9b
PERF: skip existing images when generating
tacaswell Jun 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,24 @@ jobs:
rm -rf ~/.cache/matplotlib
if: matrix.delete-font-cache

- name: extract baseline images
run: |
mkdir -p /tmp/test_images/matplotlib/tests
cp -r lib/matplotlib/tests/baseline_images /tmp/test_images/matplotlib/tests
mkdir -p /tmp/test_images/mpl_toolkits/axes_grid1/tests/
cp -r lib/mpl_toolkits/axes_grid1/tests/baseline_images /tmp/test_images/mpl_toolkits/axes_grid1/tests/
mkdir -p /tmp/test_images/mpl_toolkits/axisartist/tests/
cp -r lib/mpl_toolkits/axisartist/tests/baseline_images /tmp/test_images/mpl_toolkits/axisartist/tests/
mkdir -p /tmp/test_images/mpl_toolkits/mplot3d/tests/
cp -r lib/mpl_toolkits/mplot3d/tests/baseline_images /tmp/test_images/mpl_toolkits/mplot3d/tests/

- name: Run pytest
run: |
python -mpytest -raR -n auto \
--maxfail=50 --timeout=300 --durations=25 \
--cov-report=xml --cov=lib --log-level=DEBUG --color=yes
env:
MPLTESTIMAGEPATH: /tmp/test_images/

- name: Filter C coverage
run: |
Expand Down
2 changes: 2 additions & 0 deletions doc/devel/contribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ project that leads to a scientific publication, please follow the
Coding guidelines
=================

.. _coding_guidelines-API_changes:

API changes
-----------

Expand Down
63 changes: 61 additions & 2 deletions doc/devel/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,66 @@ and then use ``rng`` when generating the random numbers.

The seed is John Hunter's birthday.

Writing an image comparison test
--------------------------------
Image Comparison tests
----------------------

As noted in :ref:`coding_guidelines-API_changes` we consider any changes to the
visual output of Matplotlib to be an API change. To ensure that our visual
output is consistent we make heavy use of image comparison tests in the
automated test suites. By default, and with only a few exceptions, the tests
compare the expected and test output with zero tolerance which means the output
of Matplotlib is stable at the pixel level across time, platform, and
architecture.

For Agg, which directly produces raster output, we directly compare the output
with saved png. For vector outputs we use an external tool (inkscape for svg
and ghostscript for eps/pdf) to convert both the baseline and test image to a
raster that we can compare. However, different versions of FreeType slightly
shift the placement and size of the rendered text which in turn causes our
tests to fail. Thus, we have historically run the test suite with a fixed
version of FreeType.

In the past we stored a complete set of the test images, against a specific
version of FreeType, in the main source repository. While highly effective,
this was not a sustainable over the long term as the pinned version of FreeType
will eventually need to be updated. Further, while our wheels are built with
the pinned version of FreeType, most other down-stream packages (such as
conda-forge and the Linux distributions) use what ever their currently
supported Freetype is this many of our users are using a version of FreeType
that we do not test.

We now use a combination of testing for self-consistency with files generated
on a developers computer and sets of canonical baseline images generated with
every release.


Generate local baseline images from upstream branch
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Adding a test image
^^^^^^^^^^^^^^^^^^^


Update a test image
^^^^^^^^^^^^^^^^^^^


Build Matplotlib with a specific FreeType
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Fetch the baseline images for a Matplotlib Release and FreeType version
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Generate the baseline images for a Matplotlib Release and FreeType version
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



Writing an image comparison test [TODO fix]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Writing an image-based test is only slightly more difficult than a simple
test. The main consideration is that you must specify the "baseline", or
Expand Down Expand Up @@ -140,6 +198,7 @@ See the documentation of `~matplotlib.testing.decorators.image_comparison` and
`~matplotlib.testing.decorators.check_figures_equal` for additional information
about their use.


Creating a new module in matplotlib.tests
-----------------------------------------

Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,11 @@ def __getstate__(self):
for s, d in self.callbacks.items()},
# It is simpler to reconstruct this from callbacks in __setstate__.
"_func_cid_map": None,
"_cid_gen": next(self._cid_gen)
}

def __setstate__(self, state):
cid_count = state.pop('_cid_gen')
vars(self).update(state)
self.callbacks = {
s: {cid: _weak_or_strong_ref(func, self._remove_proxy)
Expand All @@ -203,6 +205,7 @@ def __setstate__(self, state):
self._func_cid_map = {
s: {proxy: cid for cid, proxy in d.items()}
for s, d in self.callbacks.items()}
self._cid_gen = itertools.count(cid_count)

def connect(self, signal, func):
"""Register *func* to be called when signal *signal* is generated."""
Expand Down
11 changes: 11 additions & 0 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ def current(self):
"""Return the active axes, or None if the stack is empty."""
return max(self._axes, key=self._axes.__getitem__, default=None)

def __getstate__(self):
return {
**vars(self),
"_counter": max(self._axes.values(), default=0)
}

def __setstate__(self, state):
next_counter = state.pop('_counter')
vars(self).update(state)
self._counter = itertools.count(next_counter)


class SubplotParams:
"""
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def pytest_configure(config):
("markers", "backend: Set alternate Matplotlib backend temporarily."),
("markers", "baseline_images: Compare output against references."),
("markers", "pytz: Tests that require pytz to be installed."),
("markers", "generate_images: Flag to generate matplotlib baseline images."),
("filterwarnings", "error"),
("filterwarnings",
"ignore:.*The py23 module has been deprecated:DeprecationWarning"),
Expand Down
Loading