forked from NREL/GEOPHIRES-X
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Path constructor, unit test default output file paths
- Loading branch information
1 parent
22b3d3a
commit dab297d
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |