Skip to content

Commit

Permalink
remove unzipped test files and add setup/teardown methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed Aug 15, 2024
1 parent 8b41c28 commit 6aa01ea
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 24,449 deletions.
3 changes: 2 additions & 1 deletion pyvcell/solvers/fvsolver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path

from pyvcell_fvsolver import solve as _fv_solve, version as _fv_version # type: ignore[import-untyped]
from pyvcell_fvsolver import solve as _fv_solve # type: ignore[import-untyped]
from pyvcell_fvsolver import version as _fv_version


def solve(input_file: Path | str, vcg_file: Path | str, output_dir: Path | str) -> int:
Expand Down
13 changes: 4 additions & 9 deletions tests/fv_mesh_mapping_test.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import tarfile
from pathlib import Path

from pyvcell.simdata.mesh import CartesianMesh
from pyvcell.simdata.vtk.fv_mesh_mapping import from_mesh3d_membrane, from_mesh3d_volume
from pyvcell.simdata.vtk.vtkmesh_fv import write_finite_volume_smoothed_vtk_grid_and_index_data
from tests.test_fixture import setup_files, teardown_files

test_data_dir = (Path(__file__).parent / "test_data").absolute()


def extract_simdata() -> None:
if (test_data_dir / "SimID_946368938_0_.log").exists():
return
with tarfile.open(test_data_dir / "SimID_946368938_simdata.tgz", "r:gz") as tar:
tar.extractall(path=test_data_dir)


def test_mesh_parse() -> None:
extract_simdata()
setup_files()

mesh = CartesianMesh(mesh_file=test_data_dir / "SimID_946368938_0_.mesh")
mesh.read()
Expand All @@ -40,3 +33,5 @@ def test_mesh_parse() -> None:
(test_data_dir / "plasma_membrane.json").unlink()
if (test_data_dir / "cytosol.json").exists():
(test_data_dir / "cytosol.json").unlink()

teardown_files()
40 changes: 26 additions & 14 deletions tests/fvsolver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,47 @@
from pathlib import Path

from pyvcell.solvers.fvsolver import solve, version
from tests.test_fixture import setup_files, teardown_files

# get parent directory of this script as a path
parent_dir: Path = Path(os.path.dirname(os.path.realpath(__file__))).parent
test_data_dir = (Path(__file__).parent / "test_data").absolute()
fv_input_file = test_data_dir / "SimID_946368938_0_.fvinput"
vcg_input_file = test_data_dir / "SimID_946368938_0_.vcg"
test_output_dir_1 = parent_dir / "test_output_1"
test_output_dir_2 = parent_dir / "test_output_2"
test_output_dir = parent_dir / "test_output"


def test_version_func() -> None:
assert version() is not None


def test_solve() -> None:
# empty directory test_output_dir_1 and test_output_dir_2
for file in test_output_dir_1.iterdir() if test_output_dir_1.exists() else []:
file.unlink()
for file in test_output_dir_2.iterdir() if test_output_dir_2.exists() else []:
file.unlink()
setup_files()

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
if not test_output_dir.exists():
test_output_dir.mkdir()

# empty directory test_output_dir_1 and test_output_dir_2
for file in test_output_dir_1.iterdir() if test_output_dir_1.exists() else []:
for file in test_output_dir.iterdir():
file.unlink()
for file in test_output_dir_2.iterdir() if test_output_dir_2.exists() else []:

# copy fv_input_file into test_output_dir
fv_input_file_copy = test_output_dir / fv_input_file.name
with open(fv_input_file, "rb") as src, open(fv_input_file_copy, "wb") as dst:
dst.write(src.read())

# copy vcg_input_file into test_output_dir
vcg_input_file_copy = test_output_dir / vcg_input_file.name
with open(vcg_input_file, "rb") as src, open(vcg_input_file_copy, "wb") as dst:
dst.write(src.read())

retcode: int = solve(input_file=fv_input_file_copy, vcg_file=vcg_input_file_copy, output_dir=test_output_dir)
assert test_output_dir.exists()
assert len(list(test_output_dir.iterdir())) > 0

# empty test output directory
for file in test_output_dir.iterdir():
file.unlink()

print(f"retcode_1: {retcode_1}")
assert retcode == 0

teardown_files()
17 changes: 0 additions & 17 deletions tests/test_data/SimID_946368938_0_.functions

This file was deleted.

264 changes: 0 additions & 264 deletions tests/test_data/SimID_946368938_0_.fvinput

This file was deleted.

Binary file removed tests/test_data/SimID_946368938_0_.hdf5
Binary file not shown.
Loading

0 comments on commit 6aa01ea

Please sign in to comment.