Skip to content

Commit a9619c3

Browse files
Unit test disabled currency conversion exceptions (NREL#236)
1 parent 0c67850 commit a9619c3

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/geophires_x/Parameter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -964,10 +964,10 @@ def ConvertOutputUnits(oparam: OutputParameter, newUnit: Units, model):
964964
print(str(ex))
965965

966966
msg = (
967-
f'Error: GEOPHIRES failed to convert your currency for {oparam.Name} to something it understands.'
968-
f'You gave {currType} - conversion may be affected by https://github.com/NREL/GEOPHIRES-X/issues/236. '
967+
f'Error: GEOPHIRES failed to convert your currency for {oparam.Name} to something it understands. '
968+
f'You gave {currType} - conversion may be affected by https://github.com/NREL/GEOPHIRES-X/issues/236. '
969969
f'Please change your units to {oparam.PreferredUnits.value} '
970-
f'to continue. Cannot continue unless you do. Exiting.'
970+
f'to continue. Cannot continue unless you do. Exiting.'
971971
)
972972

973973
print(msg)

tests/test_geophires_x.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,42 @@ def input_for_heat_prices(params) -> GeophiresInputParameters:
417417

418418
self.assertEqual(cashflow_escalating[2][4], 1.5)
419419
self.assertEqual(cashflow_escalating[-1][4], 3.0)
420+
421+
def test_disabled_currency_conversion_exceptions(self):
422+
"""
423+
TODO: this test can be removed once https://github.com/NREL/GEOPHIRES-X/issues/236 is addressed. (Its purpose
424+
is to ensure currency conversion failure behavior is as expected in the interim.)
425+
"""
426+
427+
with self.assertRaises(RuntimeError) as re_ec:
428+
GeophiresXClient().get_geophires_result(
429+
GeophiresInputParameters(
430+
from_file_path=self._get_test_file_path(Path('examples/example1_outputunits.txt')),
431+
params={'Units:Exploration cost,MEUR': 'MEUR'},
432+
)
433+
)
434+
435+
e_msg = str(re_ec.exception)
436+
437+
self.assertIn(
438+
'Error: GEOPHIRES failed to convert your currency for Exploration cost to something it understands.', e_msg
439+
)
440+
self.assertIn('You gave MEUR', e_msg)
441+
self.assertIn('https://github.com/NREL/GEOPHIRES-X/issues/236', e_msg)
442+
443+
with self.assertRaises(RuntimeError) as re_omwc:
444+
GeophiresXClient().get_geophires_result(
445+
GeophiresInputParameters(
446+
from_file_path=self._get_test_file_path(Path('examples/example1_outputunits.txt')),
447+
params={'Units:O&M Make-up Water costs': 'MEUR/yr'},
448+
)
449+
)
450+
451+
e_msg = str(re_omwc.exception)
452+
453+
self.assertIn(
454+
'Error: GEOPHIRES failed to convert your currency for O&M Make-up Water costs to something it understands.',
455+
e_msg,
456+
)
457+
self.assertIn('You gave MEUR', e_msg)
458+
self.assertIn('https://github.com/NREL/GEOPHIRES-X/issues/236', e_msg)

0 commit comments

Comments
 (0)