9
9
from discretize .tree_mesh import TreeMeshNotFinalizedError
10
10
11
11
12
- @pytest .fixture
13
- def mesh ():
14
- """Return a sample TreeMesh"""
15
- nc = 16
16
- h = [nc , nc , nc ]
17
- origin = (- 32.4 , 245.4 , 192.3 )
18
- mesh = TreeMesh (h , origin , diagonal_balance = True )
19
- return mesh
20
-
21
-
22
- def refine_mesh (mesh ):
23
- """
24
- Refine the sample tree mesh.
25
-
26
- Don't finalize the mesh.
27
- """
28
- origin = mesh .origin
29
- p1 = (origin [0 ] + 0.4 , origin [1 ] + 0.4 , origin [2 ] + 0.7 )
30
- p2 = (origin [0 ] + 0.6 , origin [1 ] + 0.6 , origin [2 ] + 0.9 )
31
- mesh .refine_box (p1 , p2 , levels = 5 , finalize = False )
32
-
33
-
34
12
PROPERTIES = [
35
13
"average_cell_to_face" ,
36
14
"average_cell_to_face_x" ,
@@ -69,6 +47,39 @@ def refine_mesh(mesh):
69
47
"total_nodes" ,
70
48
]
71
49
50
+ INHERITED_PROPERTIES = [
51
+ "boundary_edge_vector_integral" ,
52
+ "boundary_face_scalar_integral" ,
53
+ "boundary_node_vector_integral" ,
54
+ "edges" ,
55
+ "faces" ,
56
+ "permute_cells" ,
57
+ "permute_edges" ,
58
+ "permute_faces" ,
59
+ ]
60
+
61
+
62
+ @pytest .fixture
63
+ def mesh ():
64
+ """Return a sample TreeMesh"""
65
+ nc = 16
66
+ h = [nc , nc , nc ]
67
+ origin = (- 32.4 , 245.4 , 192.3 )
68
+ mesh = TreeMesh (h , origin , diagonal_balance = True )
69
+ return mesh
70
+
71
+
72
+ def refine_mesh (mesh ):
73
+ """
74
+ Refine the sample tree mesh.
75
+
76
+ Don't finalize the mesh.
77
+ """
78
+ origin = mesh .origin
79
+ p1 = (origin [0 ] + 0.4 , origin [1 ] + 0.4 , origin [2 ] + 0.7 )
80
+ p2 = (origin [0 ] + 0.6 , origin [1 ] + 0.6 , origin [2 ] + 0.9 )
81
+ mesh .refine_box (p1 , p2 , levels = 5 , finalize = False )
82
+
72
83
73
84
class TestSafeGuards :
74
85
@@ -82,7 +93,7 @@ def test_errors(self, mesh, prop_name, refine):
82
93
"""
83
94
if refine :
84
95
refine_mesh (mesh )
85
- msg = re .escape (f"`TreeMesh.{ prop_name } ` requires a finalized mesh. " )
96
+ msg = re .escape (f"`TreeMesh.{ prop_name } ` requires a finalized mesh." )
86
97
with pytest .raises (TreeMeshNotFinalizedError , match = msg ):
87
98
getattr (mesh , prop_name )
88
99
@@ -96,3 +107,19 @@ def test_no_errors(self, mesh, prop_name):
96
107
mesh .finalize ()
97
108
# Accessing the property should not error out
98
109
getattr (mesh , prop_name )
110
+
111
+ @pytest .mark .parametrize ("prop_name" , INHERITED_PROPERTIES )
112
+ @pytest .mark .parametrize ("refine" , [True , False ], ids = ["refined" , "non-refined" ])
113
+ def test_errors_inherited_properties (self , mesh , prop_name , refine ):
114
+ """
115
+ Test errors when accessing inherited properties before finalizing the mesh.
116
+
117
+ These inherited properties are the ones that ``TreeMesh`` inherit, but
118
+ they depend on the ones defined by it that should not be accessed
119
+ before finalizing the mesh (e.g. ``edges`` and ``faces``).
120
+ """
121
+ if refine :
122
+ refine_mesh (mesh )
123
+ msg = r"\`TreeMesh\.[a-z_]+\`" + re .escape (" requires a finalized mesh." )
124
+ with pytest .raises (TreeMeshNotFinalizedError , match = msg ):
125
+ getattr (mesh , prop_name )
0 commit comments