1
1
from unittest import TestCase
2
2
import unittest
3
+ import pytest
3
4
import numpy as np
4
5
from smithers .io .openfoam import OpenFoamHandler , FoamMesh
5
6
6
7
openfoam_mesh_path = "tests/test_datasets/openfoam_mesh"
8
+ openfoam_mesh_binary_path = "tests/test_datasets/openfoam_mesh_binary"
7
9
notime_openfoam_mesh_path = "tests/test_datasets/notime_openfoam_mesh"
8
- handler = OpenFoamHandler ()
9
- mesh = handler .read (openfoam_mesh_path )
10
+ notime_openfoam_mesh_binary_path = "tests/test_datasets/notime_openfoam_mesh_binary"
11
+ mesh_ascii = OpenFoamHandler ().read (openfoam_mesh_path )
12
+ mesh_binary = OpenFoamHandler ().read (openfoam_mesh_binary_path )
10
13
truth_mesh = FoamMesh (openfoam_mesh_path )
11
14
12
15
13
- def test_read ():
16
+ @pytest .mark .parametrize ("mesh" , [mesh_ascii , mesh_binary ])
17
+ def test_read (mesh ):
14
18
assert type (mesh ) == dict
15
19
16
20
assert "points" in mesh ["0" ]
@@ -19,7 +23,8 @@ def test_read():
19
23
assert "cells" in mesh ["0" ]
20
24
21
25
22
- def test_read_boundary_names ():
26
+ @pytest .mark .parametrize ("mesh" , [mesh_ascii , mesh_binary ])
27
+ def test_read_boundary_names (mesh ):
23
28
assert set (mesh ["0" ]["boundary" ].keys ()) == set (
24
29
[
25
30
b"inlet" ,
@@ -32,19 +37,23 @@ def test_read_boundary_names():
32
37
)
33
38
34
39
35
- def test_read_points ():
40
+ @pytest .mark .parametrize ("mesh" , [mesh_ascii , mesh_binary ])
41
+ def test_read_points (mesh ):
36
42
np .testing .assert_almost_equal (mesh ["0" ]["points" ], truth_mesh .points )
37
43
38
44
39
- def test_read_faces ():
45
+ @pytest .mark .parametrize ("mesh" , [mesh_ascii , mesh_binary ])
46
+ def test_read_faces (mesh ):
40
47
np .testing .assert_almost_equal (mesh ["0" ]["faces" ], truth_mesh .faces )
41
48
42
49
43
- def test_read_cells ():
50
+ @pytest .mark .parametrize ("mesh" , [mesh_ascii , mesh_binary ])
51
+ def test_read_cells (mesh ):
44
52
assert len (mesh ["0" ]["cells" ]) == len (truth_mesh .cell_faces )
45
53
46
54
47
- def test_read_cell_faces ():
55
+ @pytest .mark .parametrize ("mesh" , [mesh_ascii , mesh_binary ])
56
+ def test_read_cell_faces (mesh ):
48
57
a_key = list (mesh ["0" ]["cells" ].keys ())[0 ]
49
58
smithers_cell = mesh ["0" ]["cells" ][a_key ]
50
59
@@ -53,15 +62,17 @@ def test_read_cell_faces():
53
62
)
54
63
55
64
56
- def test_read_cell_neighbors ():
65
+ @pytest .mark .parametrize ("mesh" , [mesh_ascii , mesh_binary ])
66
+ def test_read_cell_neighbors (mesh ):
57
67
a_key = list (mesh ["0" ]["cells" ].keys ())[- 1 ]
58
68
smithers_cell = mesh ["0" ]["cells" ][a_key ]
59
69
np .testing .assert_almost_equal (
60
70
smithers_cell ["neighbours" ], truth_mesh .cell_neighbour [a_key ]
61
71
)
62
72
63
73
64
- def test_read_cell_points ():
74
+ @pytest .mark .parametrize ("mesh" , [mesh_ascii , mesh_binary ])
75
+ def test_read_cell_points (mesh ):
65
76
a_key = list (mesh ["0" ]["cells" ].keys ())[- 1 ]
66
77
smithers_cell = mesh ["0" ]["cells" ][a_key ]
67
78
@@ -74,7 +85,8 @@ def test_read_cell_points():
74
85
np .testing .assert_almost_equal (smithers_cell ["points" ], faces_points )
75
86
76
87
77
- def test_boundary ():
88
+ @pytest .mark .parametrize ("mesh" , [mesh_ascii , mesh_binary ])
89
+ def test_boundary (mesh ):
78
90
ofpp_obstacle = truth_mesh .boundary [b"obstacle" ]
79
91
smithers_obstacle = mesh ["0" ]["boundary" ][b"obstacle" ]
80
92
@@ -104,40 +116,46 @@ def test_boundary():
104
116
)
105
117
106
118
107
- def test_read_fields_time_instants_all ():
108
- all_numeric_mesh = handler .read (
109
- openfoam_mesh_path , time_instants = "all_numeric"
119
+ @pytest .mark .parametrize ("path" , [openfoam_mesh_path , openfoam_mesh_binary_path ])
120
+ def test_read_fields_time_instants_all (path ):
121
+ all_numeric_mesh = OpenFoamHandler ().read (
122
+ path , time_instants = "all_numeric"
110
123
)
111
124
assert set (all_numeric_mesh .keys ()) == set (["0" , "1088" , "4196" ])
112
125
113
126
114
- def test_read_fields_time_instants_first ():
127
+ @pytest .mark .parametrize ("mesh" , [mesh_ascii , mesh_binary ])
128
+ def test_read_fields_time_instants_first (mesh ):
115
129
assert set (mesh .keys ()) == set (["0" ])
116
130
117
131
118
- def test_read_fields_time_instants_list ():
119
- handler = OpenFoamHandler ()
120
- time_list_mesh = handler .read (openfoam_mesh_path , time_instants = ["1088" ])
132
+ @ pytest . mark . parametrize ( "path" , [ openfoam_mesh_path , openfoam_mesh_binary_path ])
133
+ def test_read_fields_time_instants_list ( path ):
134
+ time_list_mesh = OpenFoamHandler () .read (path , time_instants = ["1088" ])
121
135
assert set (time_list_mesh .keys ()) == set (["1088" ])
122
136
123
137
124
- def test_read_fields_all ():
138
+ @pytest .mark .parametrize ("mesh" , [mesh_ascii , mesh_binary ])
139
+ def test_read_fields_all (mesh ):
125
140
for tdc in mesh .values ():
126
141
assert set (tdc ["fields" ].keys ()) == set (["U" , "p" ])
127
142
128
143
129
- def test_read_fields_list ():
130
- fields_list_mesh = handler .read (openfoam_mesh_path , field_names = ["p" ])
144
+ @pytest .mark .parametrize ("path" , [openfoam_mesh_path , openfoam_mesh_binary_path ])
145
+ def test_read_fields_list (path ):
146
+ fields_list_mesh = OpenFoamHandler ().read (path , field_names = ["p" ])
131
147
for tdc in fields_list_mesh .values ():
132
148
assert set (tdc ["fields" ].keys ()) == set (["p" ])
133
149
134
150
135
- def test_no_time_instants ():
151
+ @pytest .mark .parametrize ("path" , [notime_openfoam_mesh_path , notime_openfoam_mesh_binary_path ])
152
+ def test_no_time_instants (path ):
136
153
# assert that this doesn't raise anything
137
- handler .read (notime_openfoam_mesh_path )
154
+ OpenFoamHandler () .read (path )
138
155
139
156
140
- def test_area ():
157
+ @pytest .mark .parametrize ("mesh" , [mesh_ascii , mesh_binary ])
158
+ def test_area (mesh ):
141
159
np .testing .assert_almost_equal (
142
160
mesh ["0" ]["boundary" ][b"obstacle" ]["faces" ]["area" ][100 ],
143
161
0.039269502373542965 ,
0 commit comments