Skip to content

Commit 241f60d

Browse files
feat(list_geode_objects): test is_loadable
BREAKING CHANGE : arg extension -> file_absolute_path
1 parent 1c1574d commit 241f60d

File tree

3 files changed

+100
-59
lines changed

3 files changed

+100
-59
lines changed

src/opengeodeweb_back/geode_functions.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def missing_files(geode_object: str, file_absolute_path: str):
3434
return geode_object_value(geode_object)["missing_files"](file_absolute_path)
3535

3636

37+
def is_loadable(geode_object: str, file_absolute_path: str):
38+
return geode_object_value(geode_object)["is_loadable"](file_absolute_path)
39+
40+
3741
def load(geode_object: str, file_absolute_path: str):
3842
return geode_object_value(geode_object)["load"](file_absolute_path)
3943

@@ -112,7 +116,7 @@ def geode_object_output_extensions(geode_object: str):
112116
def list_input_extensions(key: str = None):
113117
extensions_list = []
114118
for geode_object, value in geode_objects_dict().items():
115-
if key != None:
119+
if key != None and key != "":
116120
if key in value:
117121
if type(value[key]) == bool:
118122
if value[key] == True:
@@ -131,23 +135,28 @@ def has_creator(geode_object: str, extension: str):
131135
return input_factory(geode_object).has_creator(extension)
132136

133137

134-
def list_geode_objects(extension: str, key: str = None):
135-
geode_objects_list = []
136-
for geode_object, value in geode_objects_dict().items():
137-
if key != None:
138-
if key in value:
139-
if type(value[key]) == bool:
140-
if value[key] == True:
141-
if has_creator(geode_object, extension):
142-
geode_objects_list.append(geode_object)
143-
elif has_creator(geode_object, extension):
144-
geode_objects_list.append(geode_object)
145-
else:
146-
if has_creator(geode_object, extension):
147-
geode_objects_list.append(geode_object)
138+
def list_geode_objects(
139+
file_absolute_path: str,
140+
key: str = None,
141+
):
142+
return_dict = {}
143+
file_extension = extension_from_filename(os.path.basename(file_absolute_path))
148144

149-
geode_objects_list.sort()
150-
return geode_objects_list
145+
for geode_object, value in geode_objects_dict().items():
146+
if has_creator(geode_object, file_extension):
147+
file_is_loadable = is_loadable(geode_object, file_absolute_path)
148+
if key != None and key != "":
149+
if key in value:
150+
if type(value[key]) == bool:
151+
if value[key] == True:
152+
return_dict[geode_object] = {
153+
"is_loadable": file_is_loadable
154+
}
155+
else:
156+
return_dict[geode_object] = {"is_loadable": file_is_loadable}
157+
else:
158+
return_dict[geode_object] = {"is_loadable": file_is_loadable}
159+
return return_dict
151160

152161

153162
def geode_objects_output_extensions(geode_object: str, data):

src/opengeodeweb_back/geode_objects.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def geode_objects_dict():
1212
"input_factory": og.BRepInputFactory,
1313
"output_factory": og.BRepOutputFactory,
1414
"missing_files": og.check_brep_missing_files,
15+
"is_loadable": og.is_brep_loadable,
1516
"load": og.load_brep,
1617
"is_saveable": og.is_brep_saveable,
1718
"save": og.save_brep,
@@ -32,6 +33,7 @@ def geode_objects_dict():
3233
"input_factory": og_gs.CrossSectionInputFactory,
3334
"output_factory": og_gs.CrossSectionOutputFactory,
3435
"missing_files": og_gs.check_cross_section_missing_files,
36+
"is_loadable": og_gs.is_cross_section_loadable,
3537
"load": og_gs.load_cross_section,
3638
"is_saveable": og_gs.is_cross_section_saveable,
3739
"save": og_gs.save_cross_section,
@@ -51,6 +53,7 @@ def geode_objects_dict():
5153
"input_factory": og.EdgedCurveInputFactory2D,
5254
"output_factory": og.EdgedCurveOutputFactory2D,
5355
"missing_files": og.check_edged_curve_missing_files2D,
56+
"is_loadable": og.is_edged_curve_loadable2D,
5457
"load": og.load_edged_curve2D,
5558
"is_saveable": og.is_edged_curve_saveable2D,
5659
"save": og.save_edged_curve2D,
@@ -70,6 +73,7 @@ def geode_objects_dict():
7073
"input_factory": og.EdgedCurveInputFactory3D,
7174
"output_factory": og.EdgedCurveOutputFactory3D,
7275
"missing_files": og.check_edged_curve_missing_files3D,
76+
"is_loadable": og.is_edged_curve_loadable3D,
7377
"load": og.load_edged_curve3D,
7478
"is_saveable": og.is_edged_curve_saveable3D,
7579
"save": og.save_edged_curve3D,
@@ -89,6 +93,7 @@ def geode_objects_dict():
8993
"input_factory": og.GraphInputFactory,
9094
"output_factory": og.GraphOutputFactory,
9195
"missing_files": og.check_graph_missing_files,
96+
"is_loadable": og.is_graph_loadable,
9297
"load": og.load_graph,
9398
"is_saveable": og.is_graph_saveable,
9499
"save": og.save_graph,
@@ -101,6 +106,7 @@ def geode_objects_dict():
101106
"input_factory": og.HybridSolidInputFactory3D,
102107
"output_factory": og.HybridSolidOutputFactory3D,
103108
"missing_files": og.check_hybrid_solid_missing_files3D,
109+
"is_loadable": og.is_hybrid_solid_loadable3D,
104110
"load": og.load_hybrid_solid3D,
105111
"is_saveable": og.is_hybrid_solid_saveable3D,
106112
"save": og.save_hybrid_solid3D,
@@ -120,6 +126,7 @@ def geode_objects_dict():
120126
"input_factory": og.PointSetInputFactory2D,
121127
"output_factory": og.PointSetOutputFactory2D,
122128
"missing_files": og.check_point_set_missing_files2D,
129+
"is_loadable": og.is_point_set_loadable2D,
123130
"load": og.load_point_set2D,
124131
"is_saveable": og.is_point_set_saveable2D,
125132
"save": og.save_point_set2D,
@@ -139,6 +146,7 @@ def geode_objects_dict():
139146
"input_factory": og.PointSetInputFactory3D,
140147
"output_factory": og.PointSetOutputFactory3D,
141148
"missing_files": og.check_point_set_missing_files3D,
149+
"is_loadable": og.is_point_set_loadable3D,
142150
"load": og.load_point_set3D,
143151
"is_saveable": og.is_point_set_saveable3D,
144152
"save": og.save_point_set3D,
@@ -158,6 +166,7 @@ def geode_objects_dict():
158166
"input_factory": og.PolygonalSurfaceInputFactory2D,
159167
"output_factory": og.PolygonalSurfaceOutputFactory2D,
160168
"missing_files": og.check_polygonal_surface_missing_files2D,
169+
"is_loadable": og.is_polygonal_surface_loadable2D,
161170
"load": og.load_polygonal_surface2D,
162171
"is_saveable": og.is_polygonal_surface_saveable2D,
163172
"save": og.save_polygonal_surface2D,
@@ -177,6 +186,7 @@ def geode_objects_dict():
177186
"input_factory": og.PolygonalSurfaceInputFactory3D,
178187
"output_factory": og.PolygonalSurfaceOutputFactory3D,
179188
"missing_files": og.check_polygonal_surface_missing_files3D,
189+
"is_loadable": og.is_polygonal_surface_loadable3D,
180190
"load": og.load_polygonal_surface3D,
181191
"is_saveable": og.is_polygonal_surface_saveable3D,
182192
"save": og.save_polygonal_surface3D,
@@ -196,6 +206,7 @@ def geode_objects_dict():
196206
"input_factory": og.PolyhedralSolidInputFactory3D,
197207
"output_factory": og.PolyhedralSolidOutputFactory3D,
198208
"missing_files": og.check_polyhedral_solid_missing_files3D,
209+
"is_loadable": og.is_polyhedral_solid_loadable3D,
199210
"load": og.load_polyhedral_solid3D,
200211
"is_saveable": og.is_polyhedral_solid_saveable3D,
201212
"save": og.save_polyhedral_solid3D,
@@ -215,6 +226,7 @@ def geode_objects_dict():
215226
"input_factory": og.RasterImageInputFactory2D,
216227
"output_factory": og.RasterImageOutputFactory2D,
217228
"missing_files": og.check_raster_image_missing_files2D,
229+
"is_loadable": og.is_raster_image_loadable2D,
218230
"load": og.load_raster_image2D,
219231
"is_saveable": og.is_raster_image_saveable2D,
220232
"save": og.save_raster_image2D,
@@ -227,6 +239,7 @@ def geode_objects_dict():
227239
"input_factory": og.RasterImageInputFactory3D,
228240
"output_factory": og.RasterImageOutputFactory3D,
229241
"missing_files": og.check_raster_image_missing_files3D,
242+
"is_loadable": og.is_raster_image_loadable3D,
230243
"load": og.load_raster_image3D,
231244
"is_saveable": og.is_raster_image_saveable3D,
232245
"save": og.save_raster_image3D,
@@ -239,6 +252,7 @@ def geode_objects_dict():
239252
"input_factory": og.RegularGridInputFactory2D,
240253
"output_factory": og.RegularGridOutputFactory2D,
241254
"missing_files": og.check_regular_grid_missing_files2D,
255+
"is_loadable": og.is_regular_grid_loadable2D,
242256
"load": og.load_regular_grid2D,
243257
"is_saveable": og.is_regular_grid_saveable2D,
244258
"save": og.save_regular_grid2D,
@@ -257,6 +271,7 @@ def geode_objects_dict():
257271
"input_factory": og.RegularGridInputFactory3D,
258272
"output_factory": og.RegularGridOutputFactory3D,
259273
"missing_files": og.check_regular_grid_missing_files3D,
274+
"is_loadable": og.is_regular_grid_loadable3D,
260275
"load": og.load_regular_grid3D,
261276
"is_saveable": og.is_regular_grid_saveable3D,
262277
"save": og.save_regular_grid3D,
@@ -275,6 +290,7 @@ def geode_objects_dict():
275290
"input_factory": og.SectionInputFactory,
276291
"output_factory": og.SectionOutputFactory,
277292
"missing_files": og.check_section_missing_files,
293+
"is_loadable": og.is_section_loadable,
278294
"load": og.load_section,
279295
"is_saveable": og.is_section_saveable,
280296
"save": og.save_section,
@@ -295,6 +311,7 @@ def geode_objects_dict():
295311
"input_factory": og_gs.StructuralModelInputFactory,
296312
"output_factory": og_gs.StructuralModelOutputFactory,
297313
"missing_files": og_gs.check_structural_model_missing_files,
314+
"is_loadable": og_gs.is_structural_model_loadable,
298315
"load": og_gs.load_structural_model,
299316
"is_saveable": og_gs.is_structural_model_saveable,
300317
"save": og_gs.save_structural_model,
@@ -314,6 +331,7 @@ def geode_objects_dict():
314331
"input_factory": og.TetrahedralSolidInputFactory3D,
315332
"output_factory": og.TetrahedralSolidOutputFactory3D,
316333
"missing_files": og.check_tetrahedral_solid_missing_files3D,
334+
"is_loadable": og.is_tetrahedral_solid_loadable3D,
317335
"load": og.load_tetrahedral_solid3D,
318336
"is_saveable": og.is_tetrahedral_solid_saveable3D,
319337
"save": og.save_tetrahedral_solid3D,
@@ -333,6 +351,7 @@ def geode_objects_dict():
333351
"input_factory": og.TriangulatedSurfaceInputFactory2D,
334352
"output_factory": og.TriangulatedSurfaceOutputFactory2D,
335353
"missing_files": og.check_triangulated_surface_missing_files2D,
354+
"is_loadable": og.is_triangulated_surface_loadable2D,
336355
"load": og.load_triangulated_surface2D,
337356
"is_saveable": og.is_triangulated_surface_saveable2D,
338357
"save": og.save_triangulated_surface2D,
@@ -352,6 +371,7 @@ def geode_objects_dict():
352371
"input_factory": og.TriangulatedSurfaceInputFactory3D,
353372
"output_factory": og.TriangulatedSurfaceOutputFactory3D,
354373
"missing_files": og.check_triangulated_surface_missing_files3D,
374+
"is_loadable": og.is_triangulated_surface_loadable3D,
355375
"load": og.load_triangulated_surface3D,
356376
"is_saveable": og.is_triangulated_surface_saveable3D,
357377
"save": og.save_triangulated_surface3D,
@@ -371,6 +391,7 @@ def geode_objects_dict():
371391
"input_factory": og.VertexSetInputFactory,
372392
"output_factory": og.VertexSetOutputFactory,
373393
"missing_files": og.check_vertex_set_missing_files,
394+
"is_loadable": og.is_vertex_set_loadable,
374395
"load": og.load_vertex_set,
375396
"is_saveable": og.is_vertex_set_saveable,
376397
"save": og.save_vertex_set,

tests/test_functions.py

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,33 @@ def test_missing_files():
5151
assert type(additional_files) is list
5252

5353

54+
def test_is_loadable():
55+
for geode_object, value in geode_objects.geode_objects_dict().items():
56+
input_extensions = geode_functions.geode_object_input_extensions(geode_object)
57+
for input_extension in input_extensions:
58+
file_absolute_path = os.path.abspath(f"tests/data/test.{input_extension}")
59+
is_loadable = geode_functions.is_loadable(geode_object, file_absolute_path)
60+
assert type(is_loadable) is bool
61+
62+
5463
def test_load():
5564
for geode_object, value in geode_objects.geode_objects_dict().items():
5665
print(f"\n{geode_object=}")
5766
input_extensions = geode_functions.geode_object_input_extensions(geode_object)
5867
for input_extension in input_extensions:
59-
if geode_object != "RegularGrid3D" and input_extension != "vti":
60-
print(f"\t{input_extension=}")
61-
missing_files = geode_functions.missing_files(
62-
geode_object, f"tests/data/test.{input_extension}"
63-
)
64-
has_missing_files = missing_files.has_missing_files()
65-
if has_missing_files:
66-
mandatory_files = missing_files.mandatory_files
67-
print(f"\t\t{mandatory_files=}")
68-
additional_files = missing_files.additional_files
69-
print(f"\t\t{additional_files=}")
70-
file_apsolute_path = os.path.abspath(
71-
f"tests/data/test.{input_extension}"
72-
)
73-
68+
print(f"\t{input_extension=}")
69+
missing_files = geode_functions.missing_files(
70+
geode_object, f"tests/data/test.{input_extension}"
71+
)
72+
has_missing_files = missing_files.has_missing_files()
73+
if has_missing_files:
74+
mandatory_files = missing_files.mandatory_files
75+
print(f"\t\t{mandatory_files=}")
76+
additional_files = missing_files.additional_files
77+
print(f"\t\t{additional_files=}")
78+
file_apsolute_path = os.path.abspath(f"tests/data/test.{input_extension}")
79+
if geode_functions.is_loadable(geode_object, file_apsolute_path):
7480
data = geode_functions.load(geode_object, file_apsolute_path)
75-
7681
if "save_viewable" in value:
7782
uu_id = str(uuid.uuid4()).replace("-", "")
7883
viewable_file_path = geode_functions.save_viewable(
@@ -143,22 +148,19 @@ def test_geode_object_output_extensions():
143148
print(f"\n{geode_object=}")
144149
input_extensions = geode_functions.geode_object_input_extensions(geode_object)
145150
for input_extension in input_extensions:
146-
if geode_object != "RegularGrid3D" and input_extension != "vti":
147-
print(f"\t{input_extension=}")
148-
missing_files = geode_functions.missing_files(
149-
geode_object, f"tests/data/test.{input_extension}"
150-
)
151-
has_missing_files = missing_files.has_missing_files()
152-
if has_missing_files:
153-
mandatory_files = missing_files.mandatory_files
154-
print(f"\t\t{mandatory_files=}")
155-
additional_files = missing_files.additional_files
156-
print(f"\t\t{additional_files=}")
157-
file_apsolute_path = os.path.abspath(
158-
f"tests/data/test.{input_extension}"
159-
)
160-
161-
data = geode_functions.load(geode_object, file_apsolute_path)
151+
print(f"\t{input_extension=}")
152+
missing_files = geode_functions.missing_files(
153+
geode_object, f"tests/data/test.{input_extension}"
154+
)
155+
has_missing_files = missing_files.has_missing_files()
156+
if has_missing_files:
157+
mandatory_files = missing_files.mandatory_files
158+
print(f"\t\t{mandatory_files=}")
159+
additional_files = missing_files.additional_files
160+
print(f"\t\t{additional_files=}")
161+
file_absolute_path = os.path.abspath(f"tests/data/test.{input_extension}")
162+
if geode_functions.is_loadable(geode_object, file_absolute_path):
163+
data = geode_functions.load(geode_object, file_absolute_path)
162164
geode_objets_and_output_extensions = (
163165
geode_functions.geode_objects_output_extensions(geode_object, data)
164166
)
@@ -215,27 +217,36 @@ def test_list_geode_objects():
215217
input_extensions = geode_functions.list_input_extensions(key)
216218
for geode_object, value in geode_objects.geode_objects_dict().items():
217219
for input_extension in input_extensions:
218-
geode_objects_list = geode_functions.list_geode_objects(
219-
input_extension, key
220+
file_absolute_path = os.path.abspath(
221+
f"tests/data/test.{input_extension}"
222+
)
223+
return_dict = geode_functions.list_geode_objects(
224+
file_absolute_path, key
220225
)
221-
assert type(geode_objects_list) is list
226+
assert type(return_dict) is dict
222227

223228
if key != None:
224-
assert len(geode_objects_list) > 0
229+
assert len(return_dict.keys()) > 0
225230
for invalid_geode_object in invalid_geode_objects:
226-
assert invalid_geode_object not in geode_objects_list
231+
assert invalid_geode_object not in return_dict.keys()
227232
else:
228-
assert len(geode_objects_list) >= 1
233+
assert len(return_dict.keys()) >= 1
234+
for input_geode_object, input_extension_dict in return_dict.items():
235+
assert type(input_extension_dict) is dict
236+
for (
237+
input_extension,
238+
input_extension_value,
239+
) in input_extension_dict.items():
240+
assert type(input_extension_value) is bool
229241

230242

231243
def test_geode_objects_output_extensions():
232244
for geode_object, value in geode_objects.geode_objects_dict().items():
233245
input_extensions = geode_functions.geode_object_input_extensions(geode_object)
234246
for input_extension in input_extensions:
235-
if geode_object != "RegularGrid3D" and input_extension != "vti":
236-
data = geode_functions.load(
237-
geode_object, f"tests/data/test.{input_extension}"
238-
)
247+
file_absolute_path = f"tests/data/test.{input_extension}"
248+
if geode_functions.is_loadable(geode_object, file_absolute_path):
249+
data = geode_functions.load(geode_object, file_absolute_path)
239250
geode_objects_and_output_extensions = (
240251
geode_functions.geode_objects_output_extensions(geode_object, data)
241252
)

0 commit comments

Comments
 (0)