Skip to content

Commit 7a5de3c

Browse files
Fix/update input comments unit test case. Add comments explaining list parameter parsing/special-casing
1 parent 02aaa5b commit 7a5de3c

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

src/geophires_x/Parameter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ def default_parameter_value_message(new_val: Any, param_to_modify_name: str, def
383383
ParamToModify.value.pop(position)
384384
ParamToModify.value.insert(position, New_val)
385385
else:
386+
# In an ideal world this would be handled in ParameterEntry such that its sValue and Comment are
387+
# correct; however that would only be practical if ParameterEntry had typing information to know
388+
# whether to treat text after a second comma as a comment or list entry.
386389
ParamToModify.value = [float(x.strip()) for x in ParameterReadIn.raw_entry.split('--')[0].split(',')[1:]
387390
if x.strip() != '']
388391
elif isinstance(ParamToModify, boolParameter):

tests/geophires_x_client_tests/input_comments.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Gradient 1, 69
77
Reservoir Depth, 5, -- comment here
88
End-Use Option, 1, # another comment
99
Power Plant Type, 4, comments galore
10+
Gradients, 10, 20, 30, 40, -- gradiance
11+
Thicknesses, 3,2, 1
1012

1113
# another, comment, with, commas, down here
1214
# comment with space

tests/test_geophires_utils.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,36 @@ def test_input_comments(self):
538538
self.assertDictEqual(
539539
d,
540540
{
541-
'Gradient 1': ParameterEntry(Name='Gradient 1', sValue='69', Comment=''),
542-
'Reservoir Depth': ParameterEntry(Name='Reservoir Depth', sValue='5', Comment='-- comment here'),
543-
'End-Use Option': ParameterEntry(Name='End-Use Option', sValue='1', Comment='# another comment'),
544-
'Power Plant Type': ParameterEntry(Name='Power Plant Type', sValue='4', Comment='comments galore'),
541+
'Gradient 1': ParameterEntry(Name='Gradient 1', sValue='69', Comment='', raw_entry='Gradient 1, 69'),
542+
'Reservoir Depth': ParameterEntry(
543+
Name='Reservoir Depth',
544+
sValue='5',
545+
Comment='-- comment here',
546+
raw_entry='Reservoir Depth, 5, -- comment here',
547+
),
548+
'End-Use Option': ParameterEntry(
549+
Name='End-Use Option',
550+
sValue='1',
551+
Comment='# another comment',
552+
raw_entry='End-Use Option, 1, # another comment',
553+
),
554+
'Power Plant Type': ParameterEntry(
555+
Name='Power Plant Type',
556+
sValue='4',
557+
Comment='comments galore',
558+
raw_entry='Power Plant Type, 4, comments galore',
559+
),
560+
# Note sValue and Comment are, obviously, inaccurate for list-type parameters - this is handled in
561+
# geophires_x.Parameter.ReadParameter where raw_entry value is parsed instead.
562+
'Gradients': ParameterEntry(
563+
Name='Gradients',
564+
sValue='10',
565+
Comment=' 20 30 40 -- gradiance',
566+
raw_entry='Gradients, 10, 20, 30, 40, -- gradiance',
567+
),
568+
'Thicknesses': ParameterEntry(
569+
Name='Thicknesses', sValue='3', Comment='2 1', raw_entry='Thicknesses, 3,2, 1'
570+
),
545571
},
546572
)
547573

0 commit comments

Comments
 (0)