Skip to content

Commit a19c652

Browse files
Print combined regeneration command for multiple example failures
1 parent aff64a7 commit a19c652

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

tests/regenerate-example-result.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# ./tests/regenerate-example-result.sh SUTRAExample1
77
# See https://github.com/NREL/GEOPHIRES-X/issues/107
88

9-
# Note: make sure your virtualenv is activated before runnning or this script will fail
9+
# Note: make sure your virtualenv is activated before running or this script will fail
1010
# or generate incorrect results.
1111

1212
cd "$(dirname "$0")"

tests/test_geophires_x.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import tempfile
23
import uuid
34
from pathlib import Path
@@ -166,6 +167,7 @@ def get_output_file_for_example(example_file: str):
166167
)
167168

168169
assert len(example_files) > 0 # test integrity check - no files means something is misconfigured
170+
regenerate_cmds = []
169171
for example_file_path in example_files:
170172
with self.subTest(msg=example_file_path):
171173
print(f'Running example test {example_file_path}')
@@ -193,6 +195,15 @@ def get_output_file_for_example(example_file: str):
193195
'Wanju_Yuan_Closed-Loop_Geothermal_Energy_Recovery.txt',
194196
]
195197
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+
196207
if allow_almost_equal:
197208
log.warning(
198209
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):
203214
places=1,
204215
msg=f'Example test: {example_file_path}',
205216
)
217+
regenerate_cmds.pop()
206218
else:
207-
msg = 'Results are not approximately equal within any percentage <100'
219+
220+
msg = 'Results are not approximately equal within any percentage <100.'
208221
percent_diff = self._get_unequal_dicts_approximate_percent_difference(
209222
expected_result.result, geophires_result.result
210223
)
211224

212225
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)'
218229

219230
raise AssertionError(msg) from ae
220231

232+
if len(regenerate_cmds) > 0:
233+
print(f'Command to regenerate {len(regenerate_cmds)} failed examples:\n{" && ".join(regenerate_cmds)}')
234+
221235
def _get_unequal_dicts_approximate_percent_difference(self, d1: dict, d2: dict) -> Optional[float]:
222236
for i in range(99):
223237
try:

0 commit comments

Comments
 (0)