1
+ import os
1
2
import tempfile
2
3
import uuid
3
4
from pathlib import Path
@@ -166,6 +167,7 @@ def get_output_file_for_example(example_file: str):
166
167
)
167
168
168
169
assert len (example_files ) > 0 # test integrity check - no files means something is misconfigured
170
+ regenerate_cmds = []
169
171
for example_file_path in example_files :
170
172
with self .subTest (msg = example_file_path ):
171
173
print (f'Running example test { example_file_path } ' )
@@ -193,6 +195,15 @@ def get_output_file_for_example(example_file: str):
193
195
'Wanju_Yuan_Closed-Loop_Geothermal_Energy_Recovery.txt' ,
194
196
]
195
197
allow_almost_equal = example_file_path in cases_to_allow_almost_equal
198
+
199
+ cmd_script = (
200
+ './tests/regenerate-example-result.sh'
201
+ if os .name != 'nt'
202
+ else './tests/regenerate-example-result.ps1'
203
+ )
204
+ regenerate_cmd = f'{ cmd_script } { example_file_path .split ("." )[0 ]} '
205
+ regenerate_cmds .append (regenerate_cmd )
206
+
196
207
if allow_almost_equal :
197
208
log .warning (
198
209
f"Results aren't exactly equal in { example_file_path } , falling back to almostEqual..."
@@ -203,21 +214,24 @@ def get_output_file_for_example(example_file: str):
203
214
places = 1 ,
204
215
msg = f'Example test: { example_file_path } ' ,
205
216
)
217
+ regenerate_cmds .pop ()
206
218
else :
207
- msg = 'Results are not approximately equal within any percentage <100'
219
+
220
+ msg = 'Results are not approximately equal within any percentage <100.'
208
221
percent_diff = self ._get_unequal_dicts_approximate_percent_difference (
209
222
expected_result .result , geophires_result .result
210
223
)
211
224
212
225
if percent_diff is not None :
213
- msg = (
214
- f'Results are approximately equal within { percent_diff } %. '
215
- f'(Run `./tests/regenerate-example-result.sh { example_file_path .split ("." )[0 ]} ` '
216
- f'if this difference is expected due to calculation updates)'
217
- )
226
+ msg = f'Results are approximately equal within { percent_diff } %.'
227
+
228
+ msg += f' (Run `{ regenerate_cmd } ` if this is expected due to calculation updates)'
218
229
219
230
raise AssertionError (msg ) from ae
220
231
232
+ if len (regenerate_cmds ) > 0 :
233
+ print (f'Command to regenerate { len (regenerate_cmds )} failed examples:\n { " && " .join (regenerate_cmds )} ' )
234
+
221
235
def _get_unequal_dicts_approximate_percent_difference (self , d1 : dict , d2 : dict ) -> Optional [float ]:
222
236
for i in range (99 ):
223
237
try :
0 commit comments