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

Skip to content

Commit f3664a1

Browse files
Added machinery for the mpl_baseline package
1 parent 06b5e1b commit f3664a1

17 files changed

Lines changed: 127 additions & 49 deletions

File tree

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ per-file-ignores =
6464
lib/matplotlib/pylab.py: F401, F403
6565
lib/matplotlib/pyplot.py: F401, F811
6666
lib/matplotlib/style/__init__.py: F401
67+
lib/matplotlib/tests/__init__.py: F401
6768
lib/matplotlib/testing/conftest.py: F401
6869
lib/matplotlib/tests/conftest.py: F401
6970
lib/matplotlib/tests/test_backend_qt.py: F401
@@ -81,6 +82,7 @@ per-file-ignores =
8182
lib/mpl_toolkits/axisartist/axes_rgb.py: F401
8283
lib/mpl_toolkits/axisartist/axislines.py: F401
8384
lib/mpl_toolkits/mplot3d/__init__.py: F401
85+
lib/mpl_toolkits/tests/__init__.py: F401
8486
lib/mpl_toolkits/tests/conftest.py: F401
8587
lib/pylab.py: F401, F403
8688

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ recursive-include tutorials *
2121
include versioneer.py
2222
include lib/matplotlib/_version.py
2323
include tests.py
24+
prune sub-wheels

azure-pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ steps:
8585

8686
- bash: |
8787
python -m pip install --upgrade pip
88+
python -m pip install --upgrade setuptools
8889
python -m pip install -r requirements/testing/travis_all.txt -r requirements/testing/travis_extra.txt ||
8990
[[ "$PYTHON_VERSION" = 'Pre' ]]
9091
displayName: 'Install dependencies with pip'

doc/devel/testing.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ tests it::
145145
ax.plot(range(10), linestyle=(0, (3, 3)), lw=5)
146146

147147
The first time this test is run, there will be no baseline image to compare
148-
against, so the test will fail. Copy the output images (in this case
149-
:file:`result_images/test_lines/test_line_dashes.png`) to the correct
150-
subdirectory of :file:`baseline_images` tree in the source directory (in this
151-
case :file:`lib/matplotlib/tests/baseline_images/test_lines`). Put this new
152-
file under source code revision control (with ``git add``). When rerunning
153-
the tests, they should now pass.
148+
against, so the test will fail. The baseline images for the :file:`lib/matplotlib` directory can be generated by using
149+
`python3 -mpytest lib/matplotlib --matplotlib_baseline_image_generation`. Similarly, the baseline images for the
150+
:file: `lib/mpl_toolkits` directory can be generated by using `python3 -mpytest lib/mpl_toolkits --matplotlib_baseline`
151+
`_image_generation`. This will create baseline images in the respective `baseline_images` directory for the matplotlib
152+
and mpl_toolkits folder. When rerunning the tests with the `matplotlib_baseline_image_generation` flag,
153+
test will pass.
154154

155155
Baseline images take a lot of space in the Matplotlib repository.
156156
An alternative approach for image comparison tests is to use the

lib/matplotlib/testing/decorators.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,25 @@ def _image_directories(func):
483483
doesn't exist.
484484
"""
485485
module_path = Path(sys.modules[func.__module__].__file__)
486-
baseline_dir = module_path.parent / "baseline_images" / module_path.stem
486+
if func.__module__.startswith("matplotlib."):
487+
try:
488+
import matplotlib_baseline_images
489+
except:
490+
raise ImportError("Not able to import matplotlib_baseline_images")
491+
baseline_dir = (Path(matplotlib_baseline_images.__file__).parent /
492+
module_path.stem)
493+
elif func.__module__.startswith("mpl_toolkits."):
494+
try:
495+
import mpl_toolkits_baseline_images
496+
except:
497+
raise ImportError("Not able to import "
498+
"mpl_toolkits_baseline_images")
499+
baseline_dir = (Path(mpl_toolkits_baseline_images.__file__).parent /
500+
module_path.stem)
501+
else:
502+
baseline_dir = (module_path.parent /
503+
"baseline_images" /
504+
module_path.stem)
487505
result_dir = Path().resolve() / "result_images" / module_path.stem
488506
result_dir.mkdir(parents=True, exist_ok=True)
489507
return baseline_dir, result_dir

lib/matplotlib/tests/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from pathlib import Path
2-
3-
4-
# Check that the test directories exist.
5-
if not (Path(__file__).parent / 'baseline_images').exists():
6-
raise IOError(
1+
# Check for the matplotlib_baseline_images.
2+
try:
3+
import matplotlib_baseline_images
4+
except:
5+
raise ImportError(
76
'The baseline image directory does not exist. '
87
'This is most likely because the test data is not installed. '
9-
'You may need to install matplotlib from source to get the '
8+
'You may need to install matplotlib_baseline_images to get the '
109
'test data.')

lib/mpl_toolkits/tests/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from pathlib import Path
2-
3-
4-
# Check that the test directories exist
5-
if not (Path(__file__).parent / "baseline_images").exists():
6-
raise IOError(
1+
# Check for the mpl_toolkits_baseline_images.
2+
try:
3+
import mpl_toolkits_baseline_images
4+
except:
5+
raise ImportError(
76
'The baseline image directory does not exist. '
87
'This is most likely because the test data is not installed. '
9-
'You may need to install matplotlib from source to get the '
8+
'You may need to install mpl_toolkits_baseline_images to get the '
109
'test data.')

requirements/testing/travis_all.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ pytest-timeout
99
pytest-xdist
1010
python-dateutil
1111
tornado
12+
-e sub-wheels/matplotlib-baseline-images

setup.cfg.template

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414

1515
[packages]
1616
# There are a number of data subpackages from Matplotlib that are
17-
# considered optional. All except 'tests' data (meaning the baseline
18-
# image files) are installed by default, but that can be changed here.
19-
#tests = False
17+
# considered optional. Sample data are installed by default, but that can be
18+
# changed here.
2019
#sample_data = True
2120

2221
[gui_support]

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
setupext.Platform(),
6060
setupext.FreeType(),
6161
setupext.SampleData(),
62-
setupext.Tests(),
6362
setupext.BackendMacOSX(),
6463
]
6564

0 commit comments

Comments
 (0)