Skip to content

Commit f45e869

Browse files
committed
Add tests
Signed-off-by: Conor MacBride <[email protected]>
1 parent 304f9b0 commit f45e869

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

tests/test_pytest_mpl.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,14 +441,18 @@ def test_results_always(tmpdir):
441441
code = call_pytest(['--mpl', test_file, '--mpl-results-always',
442442
rf'--mpl-hash-library={hash_library}',
443443
rf'--mpl-baseline-path={baseline_dir_abs}',
444-
'--mpl-generate-summary=html',
444+
'--mpl-generate-summary=html,json',
445445
rf'--mpl-results-path={results_path.strpath}'])
446446
assert code == 0 # hashes correct, so all should pass
447447

448448
comparison_file = results_path.join('fig_comparison.html')
449449
with open(comparison_file, 'r') as f:
450450
html = f.read()
451451

452+
json_file = results_path.join('results.json')
453+
with open(json_file, 'r') as f:
454+
json_results = json.load(f)
455+
452456
# each test, and which images should exist
453457
for test, exists in [
454458
('test_modified', ['baseline', 'result-failed-diff', 'result']),
@@ -458,14 +462,22 @@ def test_results_always(tmpdir):
458462

459463
test_name = f'test.{test}'
460464

461-
summary = f'{test_name} (passed)'
465+
summary = f'<div class="test-name">{test_name}</div>'
462466
assert summary in html
463467

468+
assert test_name in json_results.keys()
469+
json_res = json_results[test_name]
470+
assert json_res['status'] == 'passed'
471+
464472
for image_type in ['baseline', 'result-failed-diff', 'result']:
465473
image = f'{test_name}/{image_type}.png'
466-
assert image in html # <img> is present even if 404
467474
image_exists = results_path.join(*image.split('/')).exists()
475+
json_image_key = f"{image_type.split('-')[-1]}_image"
468476
if image_type in exists: # assert image so pytest prints it on error
469477
assert image and image_exists
478+
assert image in html
479+
assert json_res[json_image_key] == image
470480
else:
471481
assert image and not image_exists
482+
assert image not in html
483+
assert json_res[json_image_key] is None

0 commit comments

Comments
 (0)