|
| 1 | +import shutil |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +FULL_TEST_NAME = "test_config.TestClass.test_mpl" |
| 7 | +SHORT_TEST_NAME = "test_mpl" |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.parametrize( |
| 11 | + "ini, cli, expected_baseline_name, success_expected", |
| 12 | + [ |
| 13 | + (None, None, SHORT_TEST_NAME, True), |
| 14 | + (False, None, SHORT_TEST_NAME, True), |
| 15 | + (True, None, FULL_TEST_NAME, True), |
| 16 | + (False, True, FULL_TEST_NAME, True), |
| 17 | + (None, True, FULL_TEST_NAME, True), |
| 18 | + (True, True, "bad_name", False), |
| 19 | + ], |
| 20 | +) |
| 21 | +def test_config(pytester, ini, cli, expected_baseline_name, success_expected): |
| 22 | + shutil.copyfile( # Test will only pass if baseline is at expected path |
| 23 | + Path(__file__).parent / "baseline" / "2.0.x" / "test_base_style.png", |
| 24 | + pytester.path / f"{expected_baseline_name}.png", |
| 25 | + ) |
| 26 | + ini = f"mpl-use-full-test-name = {ini}" if ini is not None else "" |
| 27 | + pytester.makeini( |
| 28 | + f""" |
| 29 | + [pytest] |
| 30 | + mpl-default-style = fivethirtyeight |
| 31 | + mpl-baseline-path = {pytester.path} |
| 32 | + {ini} |
| 33 | + """ |
| 34 | + ) |
| 35 | + pytester.makepyfile( |
| 36 | + """ |
| 37 | + import matplotlib.pyplot as plt |
| 38 | + import pytest |
| 39 | + class TestClass: |
| 40 | + @pytest.mark.mpl_image_compare |
| 41 | + def test_mpl(self): |
| 42 | + fig, ax = plt.subplots() |
| 43 | + ax.plot([1, 2, 3]) |
| 44 | + return fig |
| 45 | + """ |
| 46 | + ) |
| 47 | + cli = "--mpl-use-full-test-name" if cli else "" |
| 48 | + result = pytester.runpytest("--mpl", cli) |
| 49 | + if success_expected: |
| 50 | + result.assert_outcomes(passed=1) |
| 51 | + else: |
| 52 | + result.assert_outcomes(failed=1) |
0 commit comments