From 4f87a8967baf0860010d990b9215ad7ec0389f4c Mon Sep 17 00:00:00 2001 From: jcschaff Date: Thu, 15 Aug 2024 16:42:05 -0400 Subject: [PATCH] wrap pyvcell-fvsolver in pyvcell.solvers.fvsolver with safe typing --- pyvcell/solvers/__init__.py | 0 pyvcell/solvers/fvsolver.py | 19 +++++++++++++++++++ tests/fvsolver_test.py | 13 +++++-------- 3 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 pyvcell/solvers/__init__.py create mode 100644 pyvcell/solvers/fvsolver.py diff --git a/pyvcell/solvers/__init__.py b/pyvcell/solvers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyvcell/solvers/fvsolver.py b/pyvcell/solvers/fvsolver.py new file mode 100644 index 0000000..1e267c1 --- /dev/null +++ b/pyvcell/solvers/fvsolver.py @@ -0,0 +1,19 @@ +from pathlib import Path + +from pyvcell_fvsolver import solve as _fv_solve, version as _fv_version # type: ignore[import-untyped] + + +def solve(input_file: Path | str, vcg_file: Path | str, output_dir: Path | str) -> int: + return_code = _fv_solve(fvInputFilename=str(input_file), vcgInputFilename=str(vcg_file), outputDir=str(output_dir)) + if not isinstance(return_code, int): + raise TypeError(f"Expected int but got {type(return_code)}") + if return_code != 0: + raise ValueError(f"Error in solve: {return_code}") + return return_code + + +def version() -> str: + version_value = _fv_version() + if not isinstance(version_value, str): + raise TypeError(f"Expected str but got {type(version_value)}") + return version_value diff --git a/tests/fvsolver_test.py b/tests/fvsolver_test.py index b0c61ba..27e9706 100644 --- a/tests/fvsolver_test.py +++ b/tests/fvsolver_test.py @@ -1,7 +1,7 @@ import os from pathlib import Path -from pyvcell_fvsolver import __version__, solve, version # type: ignore[import-untyped] +from pyvcell.solvers.fvsolver import solve, version # get parent directory of this script as a path parent_dir: Path = Path(os.path.dirname(os.path.realpath(__file__))).parent @@ -12,10 +12,6 @@ test_output_dir_2 = parent_dir / "test_output_2" -def test_version_var() -> None: - assert __version__ == "0.0.4" - - def test_version_func() -> None: assert version() is not None @@ -27,7 +23,8 @@ def test_solve() -> None: for file in test_output_dir_2.iterdir() if test_output_dir_2.exists() else []: file.unlink() - retcode_1: int = solve( - fvInputFilename=str(fv_input_file), vcgInputFilename=str(vcg_input_file), outputDir=str(test_output_dir_1) - ) + retcode_1: int = solve(input_file=fv_input_file, vcg_file=vcg_input_file, output_dir=test_output_dir_1) + assert test_output_dir_1.exists() + assert len(list(test_output_dir_1.iterdir())) > 0 + print(f"retcode_1: {retcode_1}")