Skip to content

Commit a5272a6

Browse files
committed
Update tests for new status_msg
1 parent de57cab commit a5272a6

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

tests/subtests/helpers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def diff_summary(baseline, result, baseline_hash_library=None, result_hash_libra
5353

5454
# Swap the baseline and result hashes in the summary
5555
# for the corresponding hashes in each hash library
56-
if baseline_hash_library:
56+
if baseline_hash_library and test in baseline_hash_library:
5757
baseline_summary = replace_hash(baseline_summary, 'baseline_hash',
5858
baseline_hash_library[test])
5959
if result_hash_library:
@@ -114,7 +114,11 @@ def diff_dict_item(baseline, result, error=''):
114114
if isinstance(baseline, (bool, type(None))) and baseline is result:
115115
return
116116

117-
# Handle str, int and float
117+
# Handle float
118+
if isinstance(baseline, float) and abs(baseline - result) < 1e-4:
119+
return
120+
121+
# Handle str and int
118122
if baseline == result:
119123
return
120124

tests/subtests/test_subtest.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
import matplotlib
88
import matplotlib.ft2font
9-
from packaging.version import Version
109
import pytest
10+
from packaging.version import Version
1111

1212
from .helpers import assert_existence, diff_summary, patch_summary
1313

@@ -20,7 +20,8 @@
2020
HASH_LIBRARY_FLAG = rf'--mpl-hash-library={HASH_LIBRARY}'
2121
FULL_BASELINE_PATH = Path(__file__).parent / 'baseline'
2222

23-
BASELINE_IMAGES_FLAG = '--mpl-baseline-path=baseline'
23+
BASELINE_IMAGES_FLAG_REL = ['--mpl-baseline-path=baseline', '--mpl-baseline-relative']
24+
BASELINE_IMAGES_FLAG_ABS = rf'--mpl-baseline-path={FULL_BASELINE_PATH}'
2425

2526
TEST_FILE = Path(__file__).parent / 'subtest.py'
2627

@@ -121,19 +122,19 @@ def test_hash(tmp_path):
121122

122123
@pytest.mark.skipif(not HASH_LIBRARY.exists(), reason="No hash library for this mpl version")
123124
def test_hybrid(tmp_path):
124-
run_subtest('test_hybrid', tmp_path, [HASH_LIBRARY_FLAG, BASELINE_IMAGES_FLAG])
125+
run_subtest('test_hybrid', tmp_path, [HASH_LIBRARY_FLAG, BASELINE_IMAGES_FLAG_ABS])
125126

126127

127128
@pytest.mark.skipif(not HASH_LIBRARY.exists(), reason="No hash library for this mpl version")
128129
def test_results_always(tmp_path):
129130
run_subtest('test_results_always', tmp_path,
130-
[HASH_LIBRARY_FLAG, BASELINE_IMAGES_FLAG, '--mpl-results-always'])
131+
[HASH_LIBRARY_FLAG, BASELINE_IMAGES_FLAG_ABS, '--mpl-results-always'])
131132

132133

133134
@pytest.mark.skipif(not HASH_LIBRARY.exists(), reason="No hash library for this mpl version")
134135
def test_html(tmp_path):
135136
run_subtest('test_results_always', tmp_path,
136-
[HASH_LIBRARY_FLAG, BASELINE_IMAGES_FLAG], summaries=['html'])
137+
[HASH_LIBRARY_FLAG, BASELINE_IMAGES_FLAG_ABS], summaries=['html'])
137138
assert (tmp_path / 'results' / 'fig_comparison.html').exists()
138139
assert (tmp_path / 'results' / 'extra.js').exists()
139140
assert (tmp_path / 'results' / 'styles.css').exists()
@@ -157,5 +158,5 @@ def test_html_images_only(tmp_path):
157158
@pytest.mark.skipif(not HASH_LIBRARY.exists(), reason="No hash library for this mpl version")
158159
def test_basic_html(tmp_path):
159160
run_subtest('test_results_always', tmp_path,
160-
[HASH_LIBRARY_FLAG, BASELINE_IMAGES_FLAG], summaries=['basic-html'])
161+
[HASH_LIBRARY_FLAG, *BASELINE_IMAGES_FLAG_REL], summaries=['basic-html'])
161162
assert (tmp_path / 'results' / 'fig_comparison_basic.html').exists()

tests/test_pytest_mpl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def test_hash_fails(tmpdir):
291291
# If we use --mpl, it should detect that the figure is wrong
292292
output = assert_pytest_fails_with(['--mpl', test_file], "doesn't match hash FAIL in library")
293293
# We didn't specify a baseline dir so we shouldn't attempt to find one
294-
assert "Unable to find baseline image" not in output, output
294+
assert "Image file not found for comparison test" not in output, output
295295

296296
# Check that the summary path is printed and that it exists.
297297
output = assert_pytest_fails_with(['--mpl', test_file, '--mpl-generate-summary=html'],
@@ -337,7 +337,7 @@ def test_hash_fail_hybrid(tmpdir):
337337
output = assert_pytest_fails_with(['--mpl', test_file,
338338
'--mpl-baseline-path=/not/a/path'],
339339
"doesn't match hash FAIL in library")
340-
assert "Unable to find baseline image" in output, output
340+
assert "Image file not found for comparison test" in output, output
341341

342342
# Assert reports image comparison succeeds
343343
output = assert_pytest_fails_with(['--mpl', test_file,

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ extras =
3333
commands =
3434
pip freeze
3535
# Make sure the tests pass with and without --mpl
36-
pytest '{toxinidir}' {posargs}
36+
# Use -m so pytest skips "subtests" which always apply --mpl
37+
pytest '{toxinidir}' -m "mpl_image_compare" {posargs}
3738
pytest '{toxinidir}' --mpl --cov pytest_mpl {posargs}
3839

3940
[testenv:codestyle]

0 commit comments

Comments
 (0)