Skip to content

Commit

Permalink
wrap pyvcell-fvsolver in pyvcell.solvers.fvsolver with safe typing
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed Aug 15, 2024
1 parent 5ca8914 commit 4f87a89
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
Empty file added pyvcell/solvers/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions pyvcell/solvers/fvsolver.py
Original file line number Diff line number Diff line change
@@ -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
13 changes: 5 additions & 8 deletions tests/fvsolver_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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}")

0 comments on commit 4f87a89

Please sign in to comment.