-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4cb3de
commit 913c476
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
PYFILE = ( | ||
""" | ||
import matplotlib.pyplot as plt | ||
import pytest | ||
@pytest.mark.mpl_image_compare | ||
def test_mpl(): | ||
fig, ax = plt.subplots() | ||
ax.plot([1, 2, 3]) | ||
return fig | ||
""" | ||
) | ||
|
||
|
||
def test_generate_baseline_images(pytester): | ||
pytester.makepyfile(PYFILE) | ||
baseline_dir = pytester.path / "alternative_baseline" | ||
result = pytester.runpytest(f"--mpl-generate-path={baseline_dir}") | ||
result.assert_outcomes(skipped=1) | ||
assert (baseline_dir / "test_mpl.png").exists() | ||
|
||
|
||
def test_generate_baseline_hashes(pytester): | ||
pytester.makepyfile(PYFILE) | ||
hash_library = pytester.path / "alternative_baseline" / "hash_library_1.json" | ||
result = pytester.runpytest( | ||
f"--mpl-generate-hash-library={hash_library}", | ||
f"--mpl-results-path={pytester.path}", | ||
) | ||
result.assert_outcomes(failed=1) # this option enables --mpl | ||
assert hash_library.exists() | ||
assert (pytester.path / "test_generate_baseline_hashes.test_mpl" / "result.png").exists() | ||
|
||
|
||
def test_generate_baseline_images_and_hashes(pytester): | ||
pytester.makepyfile(PYFILE) | ||
baseline_dir = pytester.path / "alternative_baseline" | ||
hash_library = pytester.path / "alternative_baseline" / "hash_library_1.json" | ||
result = pytester.runpytest( | ||
f"--mpl-generate-path={baseline_dir}", | ||
f"--mpl-generate-hash-library={hash_library}", | ||
) | ||
result.assert_outcomes(skipped=1) | ||
assert (baseline_dir / "test_mpl.png").exists() | ||
assert hash_library.exists() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"ini, cli, enabled_expected", | ||
[ | ||
(None, None, False), | ||
(True, None, True), | ||
(False, None, False), | ||
(False, True, True), | ||
(True, True, True), | ||
], | ||
) | ||
def test_config(pytester, ini, cli, enabled_expected): | ||
ini = f"mpl-results-always = {ini}" if ini else "" | ||
pytester.makeini( | ||
f""" | ||
[pytest] | ||
mpl-default-style = fivethirtyeight | ||
mpl-baseline-path = {Path(__file__).parent / "baseline" / "2.0.x"} | ||
mpl-results-path = {pytester.path} | ||
{ini} | ||
""" | ||
) | ||
pytester.makepyfile( | ||
""" | ||
import matplotlib.pyplot as plt | ||
import pytest | ||
@pytest.mark.mpl_image_compare | ||
def test_base_style(): | ||
fig, ax = plt.subplots() | ||
ax.plot([1, 2, 3]) | ||
return fig | ||
""" | ||
) | ||
cli = "--mpl-results-always" if cli else "" | ||
result = pytester.runpytest("--mpl", cli) | ||
result.assert_outcomes(passed=1) | ||
assert (pytester.path / "test_config.test_base_style" / "result.png").exists() == enabled_expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"ini, cli, expected", | ||
[ | ||
("dir1", None, "dir1"), | ||
("dir1", "dir2", "dir2"), | ||
(None, "dir2", "dir2"), | ||
], | ||
) | ||
def test_config(pytester, ini, cli, expected): | ||
ini = f"mpl-results-path = {ini}" if ini else "" | ||
pytester.makeini( | ||
f""" | ||
[pytest] | ||
{ini} | ||
""" | ||
) | ||
pytester.makepyfile( | ||
""" | ||
import matplotlib.pyplot as plt | ||
import pytest | ||
@pytest.mark.mpl_image_compare | ||
def test_mpl(): | ||
fig, ax = plt.subplots() | ||
ax.plot([1, 2, 3]) | ||
return fig | ||
""" | ||
) | ||
cli = f"--mpl-results-path={cli}" if cli else "" | ||
result = pytester.runpytest("--mpl", cli) | ||
result.assert_outcomes(failed=1) | ||
assert (pytester.path / expected / "test_config.test_mpl" / "result.png").exists() |