Skip to content

Commit b50060c

Browse files
Fix client cwd stashing regression introduced in d8e2973
1 parent 4868ca1 commit b50060c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/geophires_x_client/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import atexit
2+
import os
23
import sys
34
import threading
45
from multiprocessing import Manager
56
from multiprocessing import current_process
7+
from pathlib import Path
68

79
# noinspection PyPep8Naming
810
from geophires_x import GEOPHIRESv3 as geophires
@@ -110,6 +112,7 @@ def get_geophires_result(self, input_params: GeophiresInputParameters) -> Geophi
110112

111113
def _run_simulation(self, input_params: GeophiresInputParameters) -> GeophiresXResult:
112114
"""Helper method to encapsulate the actual GEOPHIRES run."""
115+
stash_cwd = Path.cwd()
113116
stash_sys_argv = sys.argv
114117
sys.argv = ['', input_params.as_file_path(), input_params.get_output_file_path()]
115118

@@ -121,6 +124,7 @@ def _run_simulation(self, input_params: GeophiresInputParameters) -> GeophiresXR
121124
raise RuntimeError('GEOPHIRES exited without giving a reason') from None
122125
finally:
123126
sys.argv = stash_sys_argv
127+
os.chdir(stash_cwd)
124128

125129
self._logger.info(f'GEOPHIRES-X output file: {input_params.get_output_file_path()}')
126130
result = GeophiresXResult(input_params.get_output_file_path())

tests/test_geophires_x_client.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class GeophiresXClientTestCase(BaseTestCase):
1515
"""
1616
Note that these are tests of the geophires_x_client package only and not of the core geophires_x package.
17-
If a test calls geophires_x_client.GeophiresXClient.get_geophires_result then it belongs in
17+
If a test calls geophires_x_client.GeophiresXClient.get_geophires_result then it generally belongs in
1818
test_geophires_x.GeophiresXTestCase.
1919
"""
2020

@@ -615,3 +615,19 @@ def test_parse_sam_cash_flow_profile(self):
615615
cash_flow = result.result['SAM CASH FLOW PROFILE']
616616
self.assertIsNotNone(cash_flow)
617617
self.assertListEqual([''] + [f'Year {y}' for y in range(21)], cash_flow[0])
618+
619+
def test_stash_cwd(self):
620+
start_cwd = Path.cwd()
621+
GeophiresXClient().get_geophires_result(
622+
GeophiresInputParameters(
623+
{
624+
'End-Use Option': EndUseOption.DIRECT_USE_HEAT.value,
625+
'Reservoir Model': 1,
626+
'Time steps per year': 1,
627+
'Reservoir Depth': 3,
628+
'Gradient 1': 50,
629+
}
630+
)
631+
)
632+
633+
self.assertEqual(start_cwd, Path.cwd())

0 commit comments

Comments
 (0)