Skip to content

Commit a9482f0

Browse files
committed
fix tests
1 parent f549b73 commit a9482f0

10 files changed

Lines changed: 126 additions & 78 deletions

bindings/python/tests/basic/test-py-attribute.py

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,61 +30,80 @@
3030

3131

3232
def test_constant_attribute(manager):
33-
constant_attribute = manager.find_or_create_attribute_constant_bool(
33+
34+
constant_attribute_id = manager.create_attribute_constant_bool(
3435
"bool", True)
35-
36-
attribute = manager.find_attribute_bool("bool")
36+
constant_attribute = manager.find_attribute_constant_bool(constant_attribute_id)
37+
attribute = manager.read_attribute_bool(constant_attribute_id)
3738
if not attribute.value(0):
3839
raise ValueError("[Test] Should be equal to True")
3940

4041
constant_attribute.set_value(False)
4142
if attribute.value(12):
4243
raise ValueError("[Test] Should be equal to False")
44+
return constant_attribute_id
4345

4446

4547
def test_int_variable_attribute(manager):
46-
variable_attribute = manager.find_or_create_attribute_variable_int(
48+
variable_attribute_id = manager.create_attribute_variable_int(
4749
"int", 12)
50+
variable_attribute = manager.find_attribute_variable_int(variable_attribute_id)
4851
variable_attribute.set_value(3, 3)
4952
if not variable_attribute.is_genericable():
5053
raise ValueError("[Test] Should be genericable")
5154

52-
manager.set_attribute_properties("int",basic.AttributeProperties(True,True))
55+
manager.set_attribute_properties(variable_attribute_id,basic.AttributeProperties(True,True))
5356
if not variable_attribute.properties().assignable or not variable_attribute.properties().interpolable :
5457
raise ValueError("[Test] Should be assignable and interpolable")
5558

56-
attribute = manager.find_attribute_int("int")
57-
if attribute.value(3) != 3:
59+
read_attribute = manager.read_attribute_int(variable_attribute_id)
60+
if variable_attribute.value(3) != 3:
5861
raise ValueError("[Test] Should be equal to 3")
59-
if attribute.value(6) != 12:
62+
if variable_attribute.value(6) != 12:
63+
raise ValueError("[Test] Should be equal to 12")
64+
if read_attribute.value(3) != 3:
65+
raise ValueError("[Test] Should be equal to 3")
66+
if read_attribute.value(6) != 12:
6067
raise ValueError("[Test] Should be equal to 12")
6168

6269
variable_attribute.set_value(3, 5)
63-
if attribute.value(3) != 5:
70+
if variable_attribute.value(3) != 5:
71+
raise ValueError("[Test] Should be equal to 5")
72+
if read_attribute.value(3) != 5:
6473
raise ValueError("[Test] Should be equal to 5")
6574

6675

6776
def test_double_sparse_attribute(manager):
68-
sparse_attribute = manager.find_or_create_attribute_sparse_double(
77+
sparse_attribute_id = manager.create_attribute_sparse_double(
6978
"double", 12)
70-
sparse_attribute.set_value(3, 3)
71-
sparse_attribute.set_value(7, 7)
79+
attribute = manager.find_attribute_sparse_double(sparse_attribute_id)
80+
attribute.set_value(3, 3)
81+
attribute.set_value(7, 7)
7282

73-
attribute = manager.find_attribute_double("double")
83+
read_attribute = manager.read_attribute_double(sparse_attribute_id)
7484
if attribute.value(3) != 3:
7585
raise ValueError("[Test] Should be equal to 3")
7686
if attribute.value(6) != 12:
7787
raise ValueError("[Test] Should be equal to 12")
7888
if attribute.value(7) != 7:
7989
raise ValueError("[Test] Should be equal to 7")
90+
if read_attribute.value(3) != 3:
91+
raise ValueError("[Test] Should be equal to 3")
92+
if read_attribute.value(6) != 12:
93+
raise ValueError("[Test] Should be equal to 12")
94+
if read_attribute.value(7) != 7:
95+
raise ValueError("[Test] Should be equal to 7")
8096

81-
sparse_attribute.set_value(3, 5)
97+
attribute.set_value(3, 5)
8298
if attribute.value(3) != 5:
8399
raise ValueError("[Test] Should be equal to 5")
100+
if read_attribute.value(3) != 5:
101+
raise ValueError("[Test] Should be equal to 5")
102+
return sparse_attribute_id
84103

85104

86105
def test_number_of_attributes(manager, nb):
87-
if len(manager.attribute_names()) != nb:
106+
if len(manager.attribute_ids()) != nb:
88107
raise ValueError(
89108
"[Test] Not the correct number of attributes in the manager")
90109

@@ -99,8 +118,8 @@ def test_delete_attribute_elements(manager):
99118
"[Test] Two attribute elements should have been removed")
100119

101120

102-
def test_sparse_attribute_after_element_deletion(manager):
103-
sparse_attribute = manager.find_attribute_double("double")
121+
def test_sparse_attribute_after_element_deletion(manager, double_attribute_id):
122+
sparse_attribute = manager.read_attribute_double(double_attribute_id)
104123
if sparse_attribute.value(0) != 12:
105124
raise ValueError("Element 0 of sparse attribute should be 12 ")
106125
if sparse_attribute.value(5) != 7:
@@ -114,17 +133,17 @@ def test_sparse_attribute_after_element_deletion(manager):
114133
manager.resize(10)
115134
if manager.nb_elements() != 10:
116135
raise ValueError("[Test] Manager should have 10 elements")
117-
test_constant_attribute(manager)
136+
bool_attribute_id = test_constant_attribute(manager)
118137
test_int_variable_attribute(manager)
119138
test_double_sparse_attribute(manager)
120-
test_double_sparse_attribute(manager)
139+
double_attribute_id = test_double_sparse_attribute(manager)
121140
test_delete_attribute_elements(manager)
122-
test_sparse_attribute_after_element_deletion(manager)
141+
test_sparse_attribute_after_element_deletion(manager,double_attribute_id)
142+
test_number_of_attributes(manager, 4)
143+
manager.delete_attribute(bool_attribute_id)
123144
test_number_of_attributes(manager, 3)
124-
manager.delete_attribute("bool")
125-
test_number_of_attributes(manager, 2)
126145
manager.clear_attributes()
127-
test_number_of_attributes(manager, 2)
146+
test_number_of_attributes(manager, 3)
128147
manager.resize(10)
129148
if manager.nb_elements() != 10:
130149
raise ValueError("[Test] Manager should have 10 elements")

bindings/python/tests/mesh/test-py-edged-curve.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ def test_edge_requests(edged_curve, builder):
123123

124124

125125
def test_clone(edged_curve):
126-
attribute = edged_curve.edge_attribute_manager(
127-
).find_or_create_attribute_variable_int("test", 0)
126+
attribute_id = edged_curve.edge_attribute_manager(
127+
).create_attribute_variable_int("test", 0)
128+
129+
attribute = edged_curve.edge_attribute_manager().find_attribute_variable_int(attribute_id)
128130
attribute.set_value(0, 42)
129131

130132
edged_curve2 = edged_curve.clone()
@@ -133,7 +135,7 @@ def test_clone(edged_curve):
133135
if edged_curve2.nb_edges() != 3:
134136
raise ValueError("[Test] EdgedCurve2 should have 3 edge")
135137

136-
attribute2 = edged_curve2.edge_attribute_manager().find_attribute_int("test")
138+
attribute2 = edged_curve2.edge_attribute_manager().read_attribute_int(attribute_id)
137139
if attribute2.value(0) != 42:
138140
raise ValueError("[Test] EdgedCurve2 attribute should be 42")
139141

bindings/python/tests/mesh/test-py-gradient-computation.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def test_gradient_grid2D():
3535
builder = mesh.RegularGridBuilder2D.create( grid )
3636
builder.initialize_cartesian_grid( geom.Point2D([ 0, 0 ] ), [ 3, 3 ], 1 )
3737
scalar_function_name = "scalar_function"
38-
attribute = grid.vertex_attribute_manager().find_or_create_attribute_variable_double( scalar_function_name, 0 )
38+
attribute_id = grid.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, 0 )
39+
attribute = grid.vertex_attribute_manager().find_attribute_variable_double( attribute_id )
3940
attribute.set_value( 1, 1 )
4041
attribute.set_value( 4, 1 )
4142
attribute.set_value( 6, 1 )
@@ -50,7 +51,7 @@ def test_gradient_grid2D():
5051
attribute.set_value( 13, 2 )
5152
attribute.set_value( 14, 3 )
5253
attribute.set_value( 15, 8 )
53-
gradient_name = mesh.compute_surface_scalar_function_gradient2D( grid, scalar_function_name )
54+
gradient_name = mesh.compute_surface_scalar_function_gradient2D( grid, attribute_id )
5455
print("Gradient attribute name: ", gradient_name)
5556
mesh.save_regular_grid2D( grid, "grid_with_gradient.og_rgd2d" )
5657

@@ -80,7 +81,8 @@ def test_gradient_triangulated_surface2D():
8081
builder.create_polygon( [ 5, 6, 8 ] )
8182
builder.compute_polygon_adjacencies()
8283
scalar_function_name = "scalar_function"
83-
attribute = surface.vertex_attribute_manager().find_or_create_attribute_variable_double( scalar_function_name, 0 )
84+
attribute_id = surface.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, 0 )
85+
attribute = surface.vertex_attribute_manager().find_attribute_variable_double( attribute_id )
8486
attribute.set_value( 1, 1 )
8587
attribute.set_value( 2, 1 )
8688
attribute.set_value( 3, 1 )
@@ -89,7 +91,7 @@ def test_gradient_triangulated_surface2D():
8991
attribute.set_value( 9, 3 )
9092
attribute.set_value( 7, 2 )
9193
attribute.set_value( 8, 2 )
92-
gradient_name = mesh.compute_surface_scalar_function_gradient2D( surface, scalar_function_name )
94+
gradient_name = mesh.compute_surface_scalar_function_gradient2D( surface, attribute_id )
9395
print("Gradient attribute name: ", gradient_name)
9496
mesh.save_triangulated_surface2D( surface, "mesh_with_gradient.og_tsf2d" )
9597

@@ -98,7 +100,8 @@ def test_gradient_grid3D():
98100
builder = mesh.RegularGridBuilder3D.create( grid )
99101
builder.initialize_cartesian_grid( geom.Point3D([ 0, 0, 0 ]), [ 2, 2, 2 ], 1 )
100102
scalar_function_name = "scalar_function"
101-
attribute = grid.vertex_attribute_manager().find_or_create_attribute_variable_double( scalar_function_name, 0 )
103+
attribute_id = grid.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, 0 )
104+
attribute = grid.vertex_attribute_manager().find_attribute_variable_double( attribute_id )
102105
attribute.set_value( 4, 1 )
103106
attribute.set_value( 10, 1 )
104107
attribute.set_value( 12, 1 )
@@ -125,8 +128,8 @@ def test_gradient_grid3D():
125128
attribute.set_value( 20, 3 )
126129
attribute.set_value( 24, 3 )
127130
attribute.set_value( 26, 3 )
128-
gradient_name = mesh.compute_solid_scalar_function_gradient3D( grid, scalar_function_name )
129-
print("Gradient attribute name: ", gradient_name)
131+
gradient_id= mesh.compute_solid_scalar_function_gradient3D( grid, attribute_id )
132+
print("Gradient attribute name: ", gradient_id)
130133
mesh.save_regular_grid3D( grid, "grid_with_gradient.og_rgd3d" )
131134

132135
if __name__ == '__main__':

bindings/python/tests/mesh/test-py-light-regular-grid.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,22 +287,26 @@ def test_closest_vertex(grid):
287287

288288

289289
def test_attribute_3d(grid):
290-
attribute = grid.cell_attribute_manager().find_or_create_attribute_variable_double(
290+
attribute_id = grid.cell_attribute_manager().create_attribute_variable_double(
291291
"toto", -1
292292
)
293+
attribute = grid.cell_attribute_manager().find_attribute_variable_double(attribute_id)
293294
attribute.set_value(10, 10)
294-
attribute = grid.cell_attribute_manager().find_attribute_double("toto")
295+
attribute = grid.cell_attribute_manager().read_attribute_double(attribute_id)
295296
if attribute.value(0) != -1:
296297
raise ValueError("[Test] Wrong attribute value")
297298
if attribute.value(10) != 10:
298299
raise ValueError("[Test] Wrong attribute value")
299300
if attribute.value(grid.nb_cells() - 1) != -1:
300301
raise ValueError("[Test] Wrong attribute value")
301-
attribute = (
302-
grid.grid_vertex_attribute_manager().find_or_create_attribute_variable_double(
302+
attribute_id = (
303+
grid.grid_vertex_attribute_manager().create_attribute_variable_double(
303304
"toto_vertex", 1
304305
)
305306
)
307+
attribute = grid.grid_vertex_attribute_manager().find_attribute_variable_double(
308+
attribute_id
309+
)
306310
attribute.set_value(10, 10)
307311
if attribute.value(0) != 1:
308312
raise ValueError("[Test] Wrong attribute value")
@@ -314,22 +318,26 @@ def test_attribute_3d(grid):
314318

315319
def test_attribute_2d():
316320
grid = mesh.LightRegularGrid2D(geom.Point2D([1.5, 0]), [5, 10], [1.0, 2.0])
317-
attribute = grid.cell_attribute_manager().find_or_create_attribute_variable_double(
321+
attribute_id = grid.cell_attribute_manager().create_attribute_variable_double(
318322
"toto", -1
319323
)
324+
attribute = grid.cell_attribute_manager().find_attribute_variable_double(attribute_id)
320325
attribute.set_value(10, 10)
321-
attribute = grid.cell_attribute_manager().find_attribute_double("toto")
326+
attribute = grid.cell_attribute_manager().read_attribute_double(attribute_id)
322327
if attribute.value(0) != -1:
323328
raise ValueError("[Test] Wrong attribute value")
324329
if attribute.value(10) != 10:
325330
raise ValueError("[Test] Wrong attribute value")
326331
if attribute.value(grid.nb_cells() - 1) != -1:
327332
raise ValueError("[Test] Wrong attribute value")
328-
attribute = (
329-
grid.grid_vertex_attribute_manager().find_or_create_attribute_variable_double(
333+
attribute_id = (
334+
grid.grid_vertex_attribute_manager().create_attribute_variable_double(
330335
"toto_vertex", 1
331336
)
332337
)
338+
attribute = grid.grid_vertex_attribute_manager().find_attribute_variable_double(
339+
attribute_id
340+
)
333341
attribute.set_value(10, 10)
334342
if attribute.value(0) != 1:
335343
raise ValueError("[Test] Wrong attribute value")

bindings/python/tests/mesh/test-py-point-set.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ def test_bounding_box(point_set):
5858

5959
def test_create_vertex_attribute(point_set):
6060
manager = point_set.vertex_attribute_manager()
61-
attribute = point_set.vertex_attribute_manager(
62-
).find_or_create_attribute_constant_bool("test", True)
61+
attribute_id = point_set.vertex_attribute_manager(
62+
).create_attribute_constant_bool("test", True)
63+
attribute = manager.find_attribute_constant_bool(attribute_id)
6364
if attribute.constant_value() != True:
6465
raise ValueError("[Test] PointSet attribute value should be true")
66+
return attribute_id
6567

6668

6769
def test_delete_vertex(point_set, builder):
@@ -80,12 +82,12 @@ def test_io(point_set, filename):
8082
new_point_set = mesh.load_point_set3D(filename)
8183

8284

83-
def test_clone(point_set):
85+
def test_clone(point_set, attribute_id):
8486
point_set2 = point_set.clone()
8587
if point_set2.nb_vertices() != 3:
8688
raise ValueError("[Test] PointSet2 should have 3 vertices")
8789

88-
attribute = point_set2.vertex_attribute_manager().find_attribute_bool("test")
90+
attribute = point_set2.vertex_attribute_manager().read_attribute_bool(attribute_id)
8991
if attribute.value(0) != True:
9092
raise ValueError("[Test] PointSet2 attribute value should be true")
9193

@@ -110,9 +112,9 @@ def test_permutation(point_set, builder):
110112
builder = mesh.PointSetBuilder3D.create(point_set)
111113
test_create_vertices(point_set, builder)
112114
test_bounding_box(point_set)
113-
test_create_vertex_attribute(point_set)
115+
test_attribute_id =test_create_vertex_attribute(point_set)
114116
test_io(point_set, "test." + point_set.native_extension())
115117

116118
test_permutation(point_set, builder)
117119
test_delete_vertex(point_set, builder)
118-
test_clone(point_set)
120+
test_clone(point_set, test_attribute_id)

bindings/python/tests/mesh/test-py-polygonal-surface.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ def test_create_polygons(polygonal_surface, builder):
6666

6767

6868
def test_create_edge_attribute(polygonal_surface):
69+
attribute_id = polygonal_surface.edges().edge_attribute_manager(
70+
).create_attribute_variable_uint("test", basic.NO_ID)
6971
attribute = polygonal_surface.edges().edge_attribute_manager(
70-
).find_or_create_attribute_variable_uint("test", basic.NO_ID)
72+
).find_attribute_variable_uint(attribute_id)
7173
for e in range(polygonal_surface.edges().nb_edges()):
7274
attribute.set_value(e, e)
75+
return attribute_id
7376

7477

7578
def test_polygon_adjacencies(polygonal_surface, builder):
@@ -113,7 +116,7 @@ def test_previous_next_on_border(polygonal_surface):
113116
raise ValueError("[Test] Next edge on border index is not correct")
114117

115118

116-
def test_delete_polygon(polygonal_surface, builder):
119+
def test_delete_polygon(polygonal_surface, builder, attribute_id):
117120
to_delete = [False] * polygonal_surface.nb_polygons()
118121
to_delete[0] = True
119122
builder.delete_polygons(to_delete)
@@ -133,7 +136,7 @@ def test_delete_polygon(polygonal_surface, builder):
133136
raise ValueError("[Test] PolygonalSurface should have 6 edges")
134137

135138
attribute = polygonal_surface.edges(
136-
).edge_attribute_manager().find_attribute_uint("test")
139+
).edge_attribute_manager().read_attribute_uint(attribute_id)
137140
for e in range(6):
138141
if attribute.value(e) != e:
139142
raise ValueError("[Test] Update of edge attributes after "
@@ -204,7 +207,7 @@ def test_polygon_vertex_normal():
204207
"[Test] PolygonalSurface polygon vertex normal is not correct")
205208

206209

207-
def test_io(polygonal_surface, filename):
210+
def test_io(polygonal_surface, filename, attribute_id):
208211
mesh.save_polygonal_surface3D(polygonal_surface, filename)
209212
new_polygonal_surface = mesh.load_polygonal_surface3D(filename)
210213

@@ -218,7 +221,7 @@ def test_io(polygonal_surface, filename):
218221
raise ValueError(
219222
"[Test] Reloaded PolygonalSurface should have 3 polygons")
220223
attribute = new_polygonal_surface.edges(
221-
).edge_attribute_manager().find_attribute_uint("test")
224+
).edge_attribute_manager().read_attribute_uint(attribute_id)
222225
for e in range(new_polygonal_surface.edges().nb_edges()):
223226
if attribute.value(e) != e:
224227
raise ValueError(
@@ -365,7 +368,7 @@ def test_permutation(surface, builder):
365368
test_create_vertices(polygonal_surface, builder)
366369
test_bounding_box(polygonal_surface)
367370
test_create_polygons(polygonal_surface, builder)
368-
test_create_edge_attribute(polygonal_surface)
371+
edge_attribute_id = test_create_edge_attribute(polygonal_surface)
369372
test_polygon_adjacencies(polygonal_surface, builder)
370373
test_polygon_edges_on_borders(polygonal_surface)
371374
test_previous_next_on_border(polygonal_surface)
@@ -374,10 +377,10 @@ def test_permutation(surface, builder):
374377
test_polygon_normal()
375378
test_polygon_vertex_normal()
376379

377-
test_io(polygonal_surface, "test." + polygonal_surface.native_extension())
380+
test_io(polygonal_surface, "test." + polygonal_surface.native_extension(),edge_attribute_id)
378381

379382
test_permutation(polygonal_surface, builder)
380-
test_delete_polygon(polygonal_surface, builder)
383+
test_delete_polygon(polygonal_surface, builder, edge_attribute_id)
381384
test_clone(polygonal_surface)
382385
test_set_polygon_vertex(polygonal_surface, builder)
383386
test_delete_all(polygonal_surface, builder)

0 commit comments

Comments
 (0)