Skip to content

Commit 6aa01ea

Browse files
committed
remove unzipped test files and add setup/teardown methods
1 parent 8b41c28 commit 6aa01ea

18 files changed

+67
-24449
lines changed

pyvcell/solvers/fvsolver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pathlib import Path
22

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

56

67
def solve(input_file: Path | str, vcg_file: Path | str, output_dir: Path | str) -> int:

tests/fv_mesh_mapping_test.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
import tarfile
21
from pathlib import Path
32

43
from pyvcell.simdata.mesh import CartesianMesh
54
from pyvcell.simdata.vtk.fv_mesh_mapping import from_mesh3d_membrane, from_mesh3d_volume
65
from pyvcell.simdata.vtk.vtkmesh_fv import write_finite_volume_smoothed_vtk_grid_and_index_data
6+
from tests.test_fixture import setup_files, teardown_files
77

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

1010

11-
def extract_simdata() -> None:
12-
if (test_data_dir / "SimID_946368938_0_.log").exists():
13-
return
14-
with tarfile.open(test_data_dir / "SimID_946368938_simdata.tgz", "r:gz") as tar:
15-
tar.extractall(path=test_data_dir)
16-
17-
1811
def test_mesh_parse() -> None:
19-
extract_simdata()
12+
setup_files()
2013

2114
mesh = CartesianMesh(mesh_file=test_data_dir / "SimID_946368938_0_.mesh")
2215
mesh.read()
@@ -40,3 +33,5 @@ def test_mesh_parse() -> None:
4033
(test_data_dir / "plasma_membrane.json").unlink()
4134
if (test_data_dir / "cytosol.json").exists():
4235
(test_data_dir / "cytosol.json").unlink()
36+
37+
teardown_files()

tests/fvsolver_test.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,47 @@
22
from pathlib import Path
33

44
from pyvcell.solvers.fvsolver import solve, version
5+
from tests.test_fixture import setup_files, teardown_files
56

67
# get parent directory of this script as a path
78
parent_dir: Path = Path(os.path.dirname(os.path.realpath(__file__))).parent
89
test_data_dir = (Path(__file__).parent / "test_data").absolute()
910
fv_input_file = test_data_dir / "SimID_946368938_0_.fvinput"
1011
vcg_input_file = test_data_dir / "SimID_946368938_0_.vcg"
11-
test_output_dir_1 = parent_dir / "test_output_1"
12-
test_output_dir_2 = parent_dir / "test_output_2"
12+
test_output_dir = parent_dir / "test_output"
1313

1414

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

1818

1919
def test_solve() -> None:
20-
# empty directory test_output_dir_1 and test_output_dir_2
21-
for file in test_output_dir_1.iterdir() if test_output_dir_1.exists() else []:
22-
file.unlink()
23-
for file in test_output_dir_2.iterdir() if test_output_dir_2.exists() else []:
24-
file.unlink()
20+
setup_files()
2521

26-
retcode_1: int = solve(input_file=fv_input_file, vcg_file=vcg_input_file, output_dir=test_output_dir_1)
27-
assert test_output_dir_1.exists()
28-
assert len(list(test_output_dir_1.iterdir())) > 0
22+
if not test_output_dir.exists():
23+
test_output_dir.mkdir()
2924

30-
# empty directory test_output_dir_1 and test_output_dir_2
31-
for file in test_output_dir_1.iterdir() if test_output_dir_1.exists() else []:
25+
for file in test_output_dir.iterdir():
3226
file.unlink()
33-
for file in test_output_dir_2.iterdir() if test_output_dir_2.exists() else []:
27+
28+
# copy fv_input_file into test_output_dir
29+
fv_input_file_copy = test_output_dir / fv_input_file.name
30+
with open(fv_input_file, "rb") as src, open(fv_input_file_copy, "wb") as dst:
31+
dst.write(src.read())
32+
33+
# copy vcg_input_file into test_output_dir
34+
vcg_input_file_copy = test_output_dir / vcg_input_file.name
35+
with open(vcg_input_file, "rb") as src, open(vcg_input_file_copy, "wb") as dst:
36+
dst.write(src.read())
37+
38+
retcode: int = solve(input_file=fv_input_file_copy, vcg_file=vcg_input_file_copy, output_dir=test_output_dir)
39+
assert test_output_dir.exists()
40+
assert len(list(test_output_dir.iterdir())) > 0
41+
42+
# empty test output directory
43+
for file in test_output_dir.iterdir():
3444
file.unlink()
3545

36-
print(f"retcode_1: {retcode_1}")
46+
assert retcode == 0
47+
48+
teardown_files()

tests/test_data/SimID_946368938_0_.functions

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/test_data/SimID_946368938_0_.fvinput

Lines changed: 0 additions & 264 deletions
This file was deleted.
-217 KB
Binary file not shown.

0 commit comments

Comments
 (0)