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

Skip to content

Commit 69d70c9

Browse files
Run only image comparison test with python3 -mpytest filename -v -m basleine_image_generation_test
1 parent c885729 commit 69d70c9

6 files changed

Lines changed: 76 additions & 66 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,7 @@ lib/matplotlib/backends/web_backend/package-lock.json
108108
# Matplotlib tempenv #
109109
######################
110110
temp/testenv
111+
112+
# Baseline Images #
113+
###################
114+
lib/matplotlib/tests/baseline_images/

lib/matplotlib/testing/decorators.py

Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -483,65 +483,72 @@ def _image_directories(func):
483483
doesn't exist.
484484
"""
485485
module_path = Path(sys.modules[func.__module__].__file__)
486-
if func.__module__.startswith("matplotlib."):
487-
try:
488-
import matplotlib_baseline_images
489-
except:
490-
generate_matplotlib_baseline_images_from_previous_commit()
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-
generate_matplotlib_baseline_images_from_previous_commit()
498-
baseline_dir = (Path(mpl_toolkits_baseline_images.__file__).parent /
499-
module_path.stem)
500-
else:
501-
baseline_dir = (module_path.parent /
502-
"baseline_images" /
503-
module_path.stem)
486+
'''
487+
# if func.__module__.startswith("matplotlib."):
488+
#
489+
# try:
490+
# import matplotlib_baseline_images
491+
# except:
492+
# generate_matplotlib_baseline_images_from_previous_commit()
493+
# baseline_dir = (Path(matplotlib_baseline_images.__file__).parent /
494+
# module_path.stem)
495+
# elif func.__module__.startswith("mpl_toolkits."):
496+
497+
# try:
498+
# import mpl_toolkits_baseline_images
499+
# except:
500+
# generate_matplotlib_baseline_images_from_previous_commit()
501+
502+
# baseline_dir = (Path(mpl_toolkits_baseline_images.__file__).parent /
503+
# module_path.stem)
504+
# else:
505+
'''
506+
baseline_dir = (module_path.parent /
507+
"baseline_images" /
508+
module_path.stem)
504509
result_dir = Path().resolve() / "result_images" / module_path.stem
505510
result_dir.mkdir(parents=True, exist_ok=True)
506511
return baseline_dir, result_dir
507512

508513

509-
def generate_matplotlib_baseline_images_from_previous_commit():
510-
mplRepoPath = Path(mpl.__file__).parent
511-
# Check that git is installed.
512-
run_text_mode(shutil.which('git')) == None
513-
# Check if current repository is a git repository
514-
run_text_mode(['git', 'status'],
515-
cwd = mplRepoPath) == None
516-
# Create virtual env in tmpdir.
517-
if not (mplRepoPath / 'testenv').exists():
518-
modify_existing_baseline_images()
519-
else
520-
# Clone mpl repo to tmpvenv and run pytests from new mpl repo created
521-
run_text_mode(["git", "worktree", "add", "testenv"],
522-
cwd = mplRepoPath)
523-
testenvPath = mplRepoPath / testenv
524-
run_text_mode([sys.executable, "-mvenv", "venv"],
525-
cwd = testenvPath)
526-
run_text_mode(["source", "venv/bin/activate"],
527-
cwd = testenvPath)
528-
run_text_mode(["git", "checkout", "HEAD~"],
529-
cwd = testenvPath)
530-
run_text_mode(["python", "-mpip", "install", "-e", mplRepoPath],
531-
cwd = testenvPath)
532-
run_text_mode(["python", "-mpytest"],
533-
cwd = testenvPath)
534-
# Copy result_images in the temporary directory and cache it
535-
run_text_mode(shutil.copytree(testenvPath / "result_images",
536-
mplRepoPath / ".pytest_cache"),
537-
cwd = mplRepoPath)
538-
539-
def modify_existing_baseline_images():
540-
# TODO
541-
return
542-
543-
def run_text_mode(*args, **kwargs):
544-
return subprocess.run(*args, **kwargs,
545-
stderr=subprocess.STDOUT,
546-
stdout = open(os.devnull, 'w'),
547-
universal_newlines=True)
514+
'''
515+
#def generate_matplotlib_baseline_images_from_previous_commit():
516+
# mplRepoPath = Path(mpl.__file__).parent
517+
# # Check that git is installed.
518+
# run_text_mode(shutil.which('git')) == None
519+
# # Check if current repository is a git repository
520+
# run_text_mode(['git', 'status'],
521+
# cwd = mplRepoPath) == None
522+
# # Create virtual env in tmpdir.
523+
# if not (mplRepoPath / 'testenv').exists():
524+
# modify_existing_baseline_images()
525+
# else
526+
# # Clone mpl repo to tmpvenv and run pytests from new mpl repo created
527+
# run_text_mode(["git", "worktree", "add", "testenv"],
528+
# cwd = mplRepoPath)
529+
# testenvPath = mplRepoPath / testenv
530+
# run_text_mode([sys.executable, "-mvenv", "venv"],
531+
# cwd = testenvPath)
532+
# run_text_mode(["source", "venv/bin/activate"],
533+
# cwd = testenvPath)
534+
# run_text_mode(["git", "checkout", "HEAD~"],
535+
# cwd = testenvPath)
536+
# run_text_mode(["python", "-mpip", "install", "-e", mplRepoPath],
537+
# cwd = testenvPath)
538+
# run_text_mode(["python", "-mpytest"],
539+
# cwd = testenvPath)
540+
# # Copy result_images in the temporary directory and cache it
541+
# run_text_mode(shutil.copytree(testenvPath / "result_images",
542+
# mplRepoPath / ".pytest_cache"),
543+
# cwd = mplRepoPath)
544+
545+
# def modify_existing_baseline_images():
546+
## # TODO
547+
# return
548+
549+
#def run_text_mode(*args, **kwargs):
550+
# return subprocess.run(*args, **kwargs,
551+
# stderr=subprocess.STDOUT,
552+
# stdout = open(os.devnull, 'w'),
553+
# universal_newlines=True)
554+
'''

lib/matplotlib/tests/__init__.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
11
# Check for the matplotlib_baseline_images.
2-
try:
3-
import matplotlib_baseline_images
4-
except:
5-
raise ImportError(
6-
'The baseline image directory does not exist. '
7-
'This is most likely because the test data is not installed. '
8-
'You may need to install matplotlib_baseline_images to get the '
9-
'test data.')

lib/matplotlib/tests/test_agg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def test_long_path():
8080
fig.savefig(buff, format='png')
8181

8282

83+
@pytest.mark.baseline_image_generation_test
8384
@image_comparison(['agg_filter.png'], remove_text=True)
8485
def test_agg_filter():
8586
def smooth1d(x, window_len):

lib/matplotlib/tests/test_agg_filter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import numpy as np
2-
2+
import pytest
33
import matplotlib.pyplot as plt
44
from matplotlib.testing.decorators import image_comparison
55

66

7+
@pytest.mark.baseline_image_generation_test
78
@image_comparison(baseline_images=['agg_filter_alpha'],
89
extensions=['png', 'pdf'])
910
def test_agg_filter_alpha():

pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ minversion = 3.6
55
testpaths = lib
66
python_files = test_*.py
77
junit_family = xunit2
8+
9+
10+
markers =
11+
baseline_image_generation_test: marks tests as baseline_image_generation_test (deselect with '-m "not baseline_image_generation_test"')
12+
serial

0 commit comments

Comments
 (0)