34
34
35
35
36
36
def run_subtest (baseline_summary_name , tmp_path , args , summaries = None , xfail = True ,
37
+ has_result_hashes = False ,
37
38
update_baseline = UPDATE_BASELINE , update_summary = UPDATE_SUMMARY ):
38
39
""" Run pytest (within pytest) and check JSON summary report.
39
40
@@ -49,6 +50,9 @@ def run_subtest(baseline_summary_name, tmp_path, args, summaries=None, xfail=Tru
49
50
Summaries to generate in addition to `json`.
50
51
xfail : bool, optional, default=True
51
52
Whether the overall pytest run should fail.
53
+ has_result_hashes : bool or str, optional, default=False
54
+ Whether a hash library is expected to exist in the results directory.
55
+ If a string, this is the name of the expected results file.
52
56
"""
53
57
# Parse arguments
54
58
if summaries is None :
@@ -110,6 +114,24 @@ def run_subtest(baseline_summary_name, tmp_path, args, summaries=None, xfail=Tru
110
114
# Ensure reported images exist
111
115
assert_existence (result_summary , path = results_path )
112
116
117
+ # Get expected name for the hash library saved to the results directory
118
+ if
6D40
isinstance (has_result_hashes , str ):
119
+ result_hash_file = tmp_path / 'results' / has_result_hashes
120
+ has_result_hashes = True # convert to bool after processing str
121
+ else :
122
+ result_hash_file = tmp_path / 'results' / HASH_LIBRARY .name
123
+
124
+ # Compare the generated hash library to the expected hash library
125
+ if has_result_hashes :
126
+ assert result_hash_file .exists ()
127
+ with open (RESULT_LIBRARY , "r" ) as f :
128
+ baseline = json .load (f )
129
+ with open (result_hash_file , "r" ) as f :
130
+ result = json .load (f )
131
+ diff_summary ({'a' : baseline }, {'a' : result })
132
+ else :
133
+ assert not result_hash_file .exists ()
134
+
113
135
114
136
def test_default (tmp_path ):
115
137
run_subtest ('test_default' , tmp_path , [])
@@ -128,21 +150,24 @@ def test_hybrid(tmp_path):
128
150
@pytest .mark .skipif (not HASH_LIBRARY .exists (), reason = "No hash library for this mpl version" )
129
151
def test_results_always (tmp_path ):
130
152
run_subtest ('test_results_always' , tmp_path ,
131
- [HASH_LIBRARY_FLAG , BASELINE_IMAGES_FLAG_ABS , '--mpl-results-always' ])
153
+ [HASH_LIBRARY_FLAG , BASELINE_IMAGES_FLAG_ABS , '--mpl-results-always' ],
154
+ has_result_hashes = True )
132
155
133
156
134
157
@pytest .mark .skipif (not HASH_LIBRARY .exists (), reason = "No hash library for this mpl version" )
135
158
def test_html (tmp_path ):
136
159
run_subtest ('test_results_always' , tmp_path ,
137
- [HASH_LIBRARY_FLAG , BASELINE_IMAGES_FLAG_ABS ], summaries = ['html' ])
160
+ [HASH_LIBRARY_FLAG , BASELINE_IMAGES_FLAG_ABS ], summaries = ['html' ],
161
+ has_result_hashes = True )
138
162
assert (tmp_path / 'results' / 'fig_comparison.html' ).exists ()
139
163
assert (tmp_path / 'results' / 'extra.js' ).exists ()
140
164
assert (tmp_path / 'results' / 'styles.css' ).exists ()
141
165
142
166
143
167
@pytest .mark .skipif (not HASH_LIBRARY .exists (), reason = "No hash library for this mpl version" )
144
168
def test_html_hashes_only (tmp_path ):
145
- run_subtest ('test_html_hashes_only' , tmp_path , [HASH_LIBRARY_FLAG ], summaries = ['html' ])
169
+ run_subtest ('test_html_hashes_only' , tmp_path , [HASH_LIBRARY_FLAG ], summaries = ['html' ],
170
+ has_result_hashes = True )
146
171
assert (tmp_path / 'results' / 'fig_comparison.html' ).exists ()
147
172
assert (tmp_path / 'results' / 'extra.js' ).exists ()
148
66C8
td>173
assert (tmp_path / 'results' / 'styles.css' ).exists ()
@@ -158,5 +183,6 @@ def test_html_images_only(tmp_path):
158
183
@pytest .mark .skipif (not HASH_LIBRARY .exists (), reason = "No hash library for this mpl version" )
159
184
def test_basic_html (tmp_path ):
160
185
run_subtest ('test_results_always' , tmp_path ,
161
- [HASH_LIBRARY_FLAG , * BASELINE_IMAGES_FLAG_REL ], summaries = ['basic-html' ])
186
+ [HASH_LIBRARY_FLAG , * BASELINE_IMAGES_FLAG_REL ], summaries = ['basic-html' ],
187
+ has_result_hashes = True )
162
188
assert (tmp_path / 'results' / 'fig_comparison_basic.html' ).exists ()
0 commit comments