Skip to content

Commit fddb402

Browse files
committed
util: better test_phys_fields.py
1 parent 448fbd9 commit fddb402

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

fluidsim/util/test_phys_fields.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1+
import pytest
2+
13
import numpy as np
24

35
import h5py
46

57
from fluidsim.util.phys_fields import (
68
name_file_from_time_approx,
79
compute_file_name,
10+
time_from_path,
811
)
912

1013

11-
def test_name_file_from_time_approx(tmp_path):
12-
dt = 0.0004
13-
times = dt * np.arange(11)
14+
dt = 0.0004
15+
times = dt * np.arange(11)
16+
1417

15-
path_dir = tmp_path / "run_dir"
16-
path_dir.mkdir()
18+
@pytest.fixture(scope="module")
19+
def path_dir_with_files(tmp_path_factory):
20+
path_dir = tmp_path_factory.mktemp("run_dir")
1721

1822
str_width, ext = 7, "h5"
1923

@@ -27,9 +31,20 @@ def test_name_file_from_time_approx(tmp_path):
2731
file.attrs["time"] = time
2832
file.attrs["it"] = it
2933

30-
# print(path_file)
34+
return path_dir
35+
36+
37+
def test_time_from_path(path_dir_with_files):
38+
paths = sorted(path_dir_with_files.glob("*.h5"))
39+
for it, path in enumerate(paths):
40+
t_from_path = time_from_path(path)
41+
assert t_from_path == round(it * dt, 3), (path.name, t_from_path, it * dt)
42+
43+
44+
def test_name_file_from_time_approx(path_dir_with_files):
45+
path_dir = path_dir_with_files
3146

3247
name_file_last = name_file_from_time_approx(path_dir)
33-
assert name_file_last == path_file.name
48+
assert name_file_last == "state_phys_t000.004_it=10.h5"
3449

3550
# TODO: add assert statements to get bugs!

0 commit comments

Comments
 (0)