|
27 | 27 | from test.test_setup import AWorkingDirectoryTest
|
28 | 28 | from json_io.json_importer import JsonImporter
|
29 | 29 | from json_io.json_exporter import JsonExporter
|
30 |
| -from test.json_io.test_json_data import TEST_JSON_FULL_VISCUBE |
| 30 | +from test.json_io.test_json_data import TEST_JSON_FULL_VISCUBE, TEST_JSON_FULL_GEOMETRY |
31 | 31 | from json_io.json_definitions import JSON_PRODUCTS, JSON_ELEMNT_CHILDREN, JSON_ELEMENT_NAME, \
|
32 |
| - JSON_ELEMENT_ROT_X, JSON_ELEMENT_ROT_Y, JSON_ELEMENT_ROT_Z |
| 32 | + JSON_ELEMENT_ROT_X, JSON_ELEMENT_ROT_Y, JSON_ELEMENT_ROT_Z, JSON_ELEMENT_STL_PATH, JSON_PARTS |
33 | 33 | import json
|
| 34 | +from module.environment import Environment |
| 35 | +import os |
| 36 | +from shutil import copyfile |
| 37 | +import Mesh |
34 | 38 |
|
35 | 39 |
|
36 | 40 | class TestJsonExporter(AWorkingDirectoryTest):
|
@@ -75,4 +79,33 @@ def test_full_export_shape_none(self):
|
75 | 79 | pass
|
76 | 80 |
|
77 | 81 | def test_full_export_shape_geometry(self):
|
78 |
| - pass |
| 82 | + json_importer = JsonImporter(self._WORKING_DIRECTORY) |
| 83 | + json_object = json.loads(TEST_JSON_FULL_GEOMETRY) |
| 84 | + |
| 85 | + # get the current module path and get the directory for the test resource |
| 86 | + # place that path into the json object before executing the transformations |
| 87 | + stl_test_resource_path = Environment.get_test_resource_path("Switch.stl") |
| 88 | + stl_test_resource_path_cp = os.path.join(self._WORKING_DIRECTORY, "Switch_cp.stl") |
| 89 | + copyfile(stl_test_resource_path, stl_test_resource_path_cp) |
| 90 | + copy_time = os.path.getmtime(stl_test_resource_path_cp) |
| 91 | + json_object[JSON_PARTS][0][JSON_ELEMENT_STL_PATH] = stl_test_resource_path_cp |
| 92 | + |
| 93 | + _, _, active_document = json_importer.full_import(json_object) |
| 94 | + |
| 95 | + json_exporter = JsonExporter(self._WORKING_DIRECTORY) |
| 96 | + exported_json = json_exporter.full_export(active_document) |
| 97 | + |
| 98 | + self.assertJsonObjectsAlmostEqual(exported_json, json_object, [], "JSON in and out equal each other", static_keys=[]) |
| 99 | + |
| 100 | + # check time stamps to make sure the file get's overridden |
| 101 | + last_edit_time = os.path.getmtime(stl_test_resource_path_cp) |
| 102 | + self.assertGreater(last_edit_time, copy_time, "File got edited after copying it") |
| 103 | + |
| 104 | + # check STL file meshes almost equal |
| 105 | + # points will differ, but we assume equality if area and volume are within a delta |
| 106 | + mesh_before = Mesh.Mesh(stl_test_resource_path) |
| 107 | + mesh_after = Mesh.Mesh(stl_test_resource_path_cp) |
| 108 | + delta = 0.1 |
| 109 | + |
| 110 | + self.assertAlmostEqual(float(mesh_before.Area), float(mesh_after.Area), msg="Areas are almost equal", delta=delta) |
| 111 | + self.assertAlmostEqual(float(mesh_before.Volume), float(mesh_after.Volume), msg="Volumes are almost equal", delta=delta) |
0 commit comments