diff --git a/src/geophires_x/Outputs.py b/src/geophires_x/Outputs.py index b262ce1a..271c7bac 100644 --- a/src/geophires_x/Outputs.py +++ b/src/geophires_x/Outputs.py @@ -716,7 +716,7 @@ def read_parameters(self, model: Model, default_output_path: Path = None) -> Non if not Path(ParameterReadIn.sValue).is_absolute() and default_output_path is not None: original_val = ParameterReadIn.sValue ParameterReadIn.sValue = str( - default_output_path.joinpath(ParameterReadIn.sValue).absolute()) + default_output_path.joinpath(Path(ParameterReadIn.sValue)).absolute()) model.logger.info(f'Adjusted {key} path to {ParameterReadIn.sValue} because original value ' f'({original_val}) was not an absolute path.') diff --git a/tests/geophires_x_tests/test_outputs.py b/tests/geophires_x_tests/test_outputs.py new file mode 100644 index 00000000..8d06e4ae --- /dev/null +++ b/tests/geophires_x_tests/test_outputs.py @@ -0,0 +1,45 @@ +import os +import sys +from pathlib import Path + +from geophires_x.Model import Model +from geophires_x_client import GeophiresInputParameters +from tests.base_test_case import BaseTestCase + + +class OutputsTestCase(BaseTestCase): + + def test_relative_output_file_path(self): + input_file = GeophiresInputParameters({'HTML Output File': 'foo.html'}).as_file_path() + m = self._new_model(input_file=input_file, original_cwd=Path('/tmp/')) # noqa: S108 + html_filepath = Path(m.outputs.html_output_file.value) + self.assertTrue(html_filepath.is_absolute()) + self.assertEqual(str(html_filepath), '/tmp/foo.html') # noqa: S108 + + def test_absolute_output_file_path(self): + input_file = GeophiresInputParameters( + {'HTML Output File': '/home/user/my-geophires-project/foo.html'} + ).as_file_path() + m = self._new_model(input_file=input_file, original_cwd=Path('/tmp/')) # noqa: S108 + html_filepath = Path(m.outputs.html_output_file.value) + self.assertTrue(html_filepath.is_absolute()) + self.assertEqual(str(html_filepath), '/home/user/my-geophires-project/foo.html') + + def _new_model(self, input_file=None, original_cwd=None) -> Model: + stash_cwd = Path.cwd() + stash_sys_argv = sys.argv + + sys.argv = [''] + + if input_file is not None: + sys.argv.append(input_file) + + m = Model(enable_geophires_logging_config=False) + + if input_file is not None: + m.read_parameters(default_output_path=original_cwd) + + sys.argv = stash_sys_argv + os.chdir(stash_cwd) + + return m