Skip to content

Commit 40d84d5

Browse files
1 parent 6f99d65 commit 40d84d5

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

src/geophires_x/GeoPHIRESUtils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,9 @@ def read_input_file(return_dict_1, logger=None, input_file_name=None):
520520
# successful read of data into list. Now make a dictionary with all the parameter entries.
521521
# Index will be the unique name of the parameter.
522522
# The value will be a "ParameterEntry" structure, with name, value (optionally with units), optional comment
523-
for line in content:
524-
if line.startswith('#'):
523+
for raw_line in content:
524+
line = raw_line.strip()
525+
if any([line.startswith(x) for x in ['#', '--', '*']]):
525526
# skip any line that starts with "#" - # will be the comment parameter
526527
continue
527528

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# comment
2+
# foo, bar
3+
# foo, bar, baz
4+
# foo, bar, baz, qux corge
5+
6+
Gradient 1, 69
7+
Reservoir Depth, 5, -- comment here
8+
End-Use Option, 1, # another comment
9+
Power Plant Type, 4, comments galore
10+
11+
# another, comment, with, commas, down here
12+
# comment with space
13+
# comment with space, and comma
14+
# comment with space, and commas, plural?!
15+
16+
-- another comment style
17+
--- three is not the charm, hopefully
18+
19+
**** A legacy-but-still-supported header comment style, indeed ****
20+
*******************************************************************

tests/geophires_x_client_tests/test_geophires_input_parameters.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pathlib import Path
44

55
from geophires_x_client import GeophiresInputParameters
6+
from geophires_x_client import GeophiresXClient
67
from tests.base_test_case import BaseTestCase
78

89

@@ -44,3 +45,9 @@ def test_init_with_input_file_and_parameters(self):
4445

4546
with open(input_params.as_file_path(), encoding='UTF-8') as f:
4647
self.assertEqual('Foo, Bar\nBaz, Qux\nBaz, Quux\nQuuz, 2\n', f.read())
48+
49+
def test_input_file_comments(self):
50+
result = GeophiresXClient().get_geophires_result(
51+
GeophiresInputParameters(from_file_path=self._get_test_file_path('input_comments.txt'))
52+
)
53+
self.assertIsNotNone(result)

tests/test_geophires_utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import sys
22
import unittest
3+
from pathlib import Path
34

5+
from geophires_x import GeoPHIRESUtils
46
from geophires_x.GeoPHIRESUtils import RecoverableHeat
57
from geophires_x.GeoPHIRESUtils import UtilEff_func
68
from geophires_x.GeoPHIRESUtils import _interp_util_eff_func
@@ -12,6 +14,8 @@
1214
from geophires_x.GeoPHIRESUtils import quantity
1315
from geophires_x.GeoPHIRESUtils import vapor_pressure_water_kPa
1416
from geophires_x.GeoPHIRESUtils import viscosity_water_Pa_sec
17+
from geophires_x.Parameter import ParameterEntry
18+
from tests.base_test_case import BaseTestCase
1519

1620

1721
class TestCelsiusToKelvin(unittest.TestCase):
@@ -524,5 +528,23 @@ def test_close_temperature(self):
524528
self.assertAlmostEqual(result, 419.1703812859442, places=3)
525529

526530

531+
class GeophiresUtilsTestCase(BaseTestCase):
532+
def test_input_comments(self):
533+
d = {}
534+
GeoPHIRESUtils.read_input_file(
535+
d, input_file_name=Path(self._get_test_file_path('geophires_x_client_tests/input_comments.txt')).absolute()
536+
)
537+
self.assertIsNotNone(d)
538+
self.assertDictEqual(
539+
d,
540+
{
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'),
545+
},
546+
)
547+
548+
527549
if __name__ == '__main__':
528550
unittest.main()

0 commit comments

Comments
 (0)