@@ -441,14 +441,18 @@ def test_results_always(tmpdir):
441
441
code = call_pytest (['--mpl' , test_file , '--mpl-results-always' ,
442
442
rf'--mpl-hash-library={ hash_library } ' ,
443
443
rf'--mpl-baseline-path={ baseline_dir_abs } ' ,
444
- '--mpl-generate-summary=html' ,
444
+ '--mpl-generate-summary=html,json ' ,
445
445
rf'--mpl-results-path={ results_path .strpath } ' ])
446
446
assert code == 0 # hashes correct, so all should pass
447
447
448
448
comparison_file = results_path .join ('fig_comparison.html' )
449
449
with open (comparison_file , 'r' ) as f :
450
450
html = f .read ()
451
451
452
+ json_file = results_path .join ('results.json' )
453
+ with open (json_file , 'r' ) as f :
454
+ json_results = json .load (f )
455
+
452
456
# each test, and which images should exist
453
457
for test , exists in [
454
458
('test_modified' , ['baseline' , 'result-failed-diff' , 'result' ]),
@@ -458,14 +462,22 @@ def test_results_always(tmpdir):
458
462
459
463
test_name = f'test.{ test } '
460
464
461
- summary = f'{ test_name } (passed) '
465
+ summary = f'<div class="test-name"> { test_name } </div> '
462
466
assert summary in html
463
467
468
+ assert test_name in json_results .keys ()
469
+ json_res = json_results [test_name ]
470
+ assert json_res ['status' ] == 'passed'
471
+
464
472
for image_type in ['baseline' , 'result-failed-diff' , 'result' ]:
465
473
image = f'{ test_name } /{ image_type } .png'
466
- assert image in html # <img> is present even if 404
467
474
image_exists = results_path .join (* image .split ('/' )).exists ()
475
+ json_image_key = f"{ image_type .split ('-' )[- 1 ]} _image"
468
476
if image_type in exists : # assert image so pytest prints it on error
469
477
assert image and image_exists
478
+ assert image in html
479
+ assert json_res [json_image_key ] == image
470
480
else :
471
481
assert image and not image_exists
482
+ assert image not in html
483
+ assert json_res [json_image_key ] is None
0 commit comments