|
1 | 1 | import os |
| 2 | +import uuid |
2 | 3 | from src.opengeodeweb_back import geode_functions, geode_objects |
3 | 4 |
|
4 | 5 |
|
@@ -50,44 +51,75 @@ def test_missing_files(): |
50 | 51 | assert type(additional_files) is list |
51 | 52 |
|
52 | 53 |
|
53 | | -def test_load(): |
| 54 | +def test_geode_objects_output_extensions(): |
54 | 55 | for geode_object, value in geode_objects.geode_objects_dict().items(): |
55 | | - print(f"{geode_object=}") |
56 | | - input_extensions = geode_functions.geode_object_input_extensions(geode_object) |
57 | | - missing_files = geode_functions.missing_files( |
58 | | - geode_object, f"tests/data/test.{input_extension}" |
59 | | - ) |
60 | | - has_missing_files = missing_files.has_missing_files() |
61 | | - if has_missing_files: |
62 | | - mandatory_files = geode_functions.mandatory_files(missing_files) |
63 | | - print(f"{mandatory_files=}") |
64 | | - additional_files = geode_functions.additional_files(missing_files) |
65 | | - print(f"{additional_files=}") |
66 | | - file_apsolute_path = os.path.abspath(f"tests/data/test.{input_extension}") |
67 | | - |
68 | | - data = geode_functions.load(geode_object, file_apsolute_path) |
69 | | - output_extensions = geode_functions.get_geode_object_output_extensions( |
70 | | - geode_object |
| 56 | + geode_objects_and_output_extensions_list = ( |
| 57 | + geode_functions.geode_objects_output_extensions(geode_object) |
71 | 58 | ) |
| 59 | + assert type(geode_objects_and_output_extensions_list) is list |
| 60 | + for ( |
| 61 | + geode_object_and_output_extensions |
| 62 | + ) in geode_objects_and_output_extensions_list: |
| 63 | + assert type(geode_object_and_output_extensions) is dict |
| 64 | + assert "geode_object" in geode_object_and_output_extensions |
| 65 | + assert "output_extension" in geode_object_and_output_extensions |
72 | 66 |
|
73 | | - for output_extension in output_extensions: |
74 | | - print(f"{output_extension=}") |
75 | | - uu_id = str(uuid.uuid4()).replace("-", "") |
76 | | - geode_functions.save( |
77 | | - geode_object, |
78 | | - data, |
79 | | - os.path.abspath(f"output"), |
80 | | - f"{uu_id}.{output_extension}", |
81 | | - ) |
82 | 67 |
|
83 | | - if "save_viewable" in value: |
84 | | - uu_id = str(uuid.uuid4()).replace("-", "") |
85 | | - geode_functions.save_viewable( |
86 | | - geode_object, |
87 | | - data, |
88 | | - os.path.abspath(f"output"), |
89 | | - uu_id, |
| 68 | +def test_load(): |
| 69 | + for geode_object, value in geode_objects.geode_objects_dict().items(): |
| 70 | + print(f"\n{geode_object=}") |
| 71 | + input_extensions = geode_functions.geode_object_input_extensions(geode_object) |
| 72 | + for input_extension in input_extensions: |
| 73 | + if input_extension not in ["grdecl", "og_img3d", "vti", "vo"]: |
| 74 | + print(f"\t{input_extension=}") |
| 75 | + missing_files = geode_functions.missing_files( |
| 76 | + geode_object, f"tests/data/test.{input_extension}" |
90 | 77 | ) |
| 78 | + has_missing_files = missing_files.has_missing_files() |
| 79 | + if has_missing_files: |
| 80 | + mandatory_files = missing_files.mandatory_files |
| 81 | + print(f"\t\t{mandatory_files=}") |
| 82 | + additional_files = missing_files.additional_files |
| 83 | + print(f"\t\t{additional_files=}") |
| 84 | + file_apsolute_path = os.path.abspath( |
| 85 | + f"tests/data/test.{input_extension}" |
| 86 | + ) |
| 87 | + |
| 88 | + data = geode_functions.load(geode_object, file_apsolute_path) |
| 89 | + geode_functions.geode_objects_output_extensions(geode_object) |
| 90 | + for ( |
| 91 | + geode_object_and_output_extensions |
| 92 | + ) in geode_functions.geode_objects_output_extensions(geode_object): |
| 93 | + output_geode_object = geode_object_and_output_extensions[ |
| 94 | + "geode_object" |
| 95 | + ] |
| 96 | + print(f"\t\t{output_geode_object=}") |
| 97 | + output_extensions = geode_functions.geode_object_output_extensions( |
| 98 | + geode_object |
| 99 | + ) |
| 100 | + |
| 101 | + for output_extension in output_extensions: |
| 102 | + print(f"\t\t\t{output_extension=}") |
| 103 | + uu_id = str(uuid.uuid4()).replace("-", "") |
| 104 | + filename = f"{uu_id}.{output_extension}" |
| 105 | + if geode_functions.is_saveable(geode_object, data, filename): |
| 106 | + file_path = geode_functions.save( |
| 107 | + geode_object, |
| 108 | + data, |
| 109 | + os.path.abspath(f"output"), |
| 110 | + f"{uu_id}.{output_extension}", |
| 111 | + ) |
| 112 | + |
| 113 | + if "save_viewable" in value: |
| 114 | + uu_id = str(uuid.uuid4()).replace("-", "") |
| 115 | + viewable_file_path = geode_functions.save_viewable( |
| 116 | + geode_object, |
| 117 | + data, |
| 118 | + os.path.abspath(f"output"), |
| 119 | + uu_id, |
| 120 | + ) |
| 121 | + |
| 122 | + os.remove(viewable_file_path) |
91 | 123 |
|
92 | 124 |
|
93 | 125 | def test_is_model(): |
|
0 commit comments