|
18 | 18 | ##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
|
20 | 20 | import os |
21 | | -import unittest |
22 | 21 |
|
23 | 22 | from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeTorus |
24 | 23 | from OCC.Core.TopoDS import TopoDS_Compound |
@@ -61,107 +60,113 @@ def get_test_fullname(filename): |
61 | 60 | A_TOPODS_SHAPE = BRepPrimAPI_MakeTorus(200, 50).Shape() |
62 | 61 |
|
63 | 62 |
|
64 | | -class TestExtendDataExchange(unittest.TestCase): |
65 | | - def check_is_file(self, filename): |
66 | | - self.assertTrue(os.path.isfile(filename)) |
| 63 | +def check_is_file(filename): |
| 64 | + assert os.path.isfile(filename) |
67 | 65 |
|
68 | | - def test_read_step_file(self): |
69 | | - read_step_file(STEP_AP203_SAMPLE_FILE) |
70 | | - read_step_file(STEP_AP214_SAMPLE_FILE) |
71 | 66 |
|
72 | | - def test_read_step_file_multiple_shape_as_root(self): |
73 | | - t = read_step_file(STEP_MULTIPLE_ROOT, as_compound=True) |
74 | | - self.assertTrue(isinstance(t, TopoDS_Compound)) |
| 67 | +def test_read_step_file(): |
| 68 | + read_step_file(STEP_AP203_SAMPLE_FILE) |
| 69 | + read_step_file(STEP_AP214_SAMPLE_FILE) |
75 | 70 |
|
76 | | - l = read_step_file(STEP_MULTIPLE_ROOT, as_compound=False) |
77 | | - self.assertEqual(len(l), 3) |
78 | 71 |
|
79 | | - def test_read_step_file_names_colors(self): |
80 | | - read_step_file_with_names_colors(STEP_AP203_SAMPLE_FILE) |
81 | | - read_step_file_with_names_colors(STEP_AP214_SAMPLE_FILE) |
| 72 | +def test_read_step_file_multiple_shape_as_root(): |
| 73 | + t = read_step_file(STEP_MULTIPLE_ROOT, as_compound=True) |
| 74 | + assert isinstance(t, TopoDS_Compound) |
82 | 75 |
|
83 | | - def test_read_iges_file(self): |
84 | | - read_iges_file(IGES_SAMPLE_FILE) |
| 76 | + l = read_step_file(STEP_MULTIPLE_ROOT, as_compound=False) |
| 77 | + assert len(l) == 3 |
85 | 78 |
|
86 | | - def test_read_iges_45_shapes(self): |
87 | | - all_shapes = read_iges_file( |
88 | | - IGES_45_FACES, return_as_shapes=True, verbosity=True |
89 | | - ) |
90 | | - self.assertEqual(len(all_shapes), 45) |
91 | 79 |
|
92 | | - def test_read_iges_45_shapes_as_one_compound(self): |
93 | | - shapes = read_iges_file(IGES_45_FACES, return_as_shapes=False, verbosity=True) |
94 | | - self.assertEqual(len(shapes), 1) |
95 | | - self.assertIsInstance(shapes[0], TopoDS_Compound) |
96 | | - topo_explorer = TopologyExplorer(shapes[0]) |
97 | | - self.assertEqual(topo_explorer.number_of_faces(), 45) |
| 80 | +def test_read_step_file_names_colors(): |
| 81 | + read_step_file_with_names_colors(STEP_AP203_SAMPLE_FILE) |
| 82 | + read_step_file_with_names_colors(STEP_AP214_SAMPLE_FILE) |
98 | 83 |
|
99 | | - def test_read_stl_file(self): |
100 | | - read_stl_file(STL_ASCII_SAMPLE_FILE) |
101 | | - read_stl_file(STL_BINARY_SAMPLE_FILE) |
102 | 84 |
|
103 | | - def test_export_shape_to_svg(self): |
104 | | - svg_filename = get_test_fullname("sample.svg") |
105 | | - export_shape_to_svg(A_TOPODS_SHAPE, svg_filename) |
106 | | - self.check_is_file(svg_filename) |
| 85 | +def test_read_iges_file(): |
| 86 | + read_iges_file(IGES_SAMPLE_FILE) |
107 | 87 |
|
108 | | - def test_read_gltf_ascii_file(self): |
109 | | - shp = read_gltf_file(GLTF_ASCII_SAMPLE_FILE) |
110 | 88 |
|
111 | | - def test_read_gltf_binary_file(self): |
112 | | - shp = read_gltf_file(GLTF_BINARY_SAMPLE_FILE) |
| 89 | +def test_read_iges_45_shapes(): |
| 90 | + all_shapes = read_iges_file(IGES_45_FACES, return_as_shapes=True, verbosity=True) |
| 91 | + assert len(all_shapes) == 45 |
113 | 92 |
|
114 | | - def test_write_step_ap203(self): |
115 | | - ap203_filename = get_test_fullname("sample_ap_203.stp") |
116 | | - write_step_file(A_TOPODS_SHAPE, ap203_filename, application_protocol="AP203") |
117 | | - self.check_is_file(ap203_filename) |
118 | 93 |
|
119 | | - def test_write_step_ap214(self): |
120 | | - as214_filename = get_test_fullname("sample_214.stp") |
121 | | - write_step_file(A_TOPODS_SHAPE, as214_filename, application_protocol="AP214IS") |
122 | | - self.check_is_file(as214_filename) |
| 94 | +def test_read_iges_45_shapes_as_one_compound(): |
| 95 | + shapes = read_iges_file(IGES_45_FACES, return_as_shapes=False, verbosity=True) |
| 96 | + assert len(shapes) == 1 |
| 97 | + assert isinstance(shapes[0], TopoDS_Compound) |
| 98 | + topo_explorer = TopologyExplorer(shapes[0]) |
| 99 | + assert topo_explorer.number_of_faces() == 45 |
123 | 100 |
|
124 | | - def test_write_step_ap242(self): |
125 | | - ap242_filename = get_test_fullname("sample_242.stp") |
126 | | - write_step_file(A_TOPODS_SHAPE, ap242_filename, application_protocol="AP242DIS") |
127 | | - self.check_is_file(ap242_filename) |
128 | 101 |
|
129 | | - def test_write_iges(self): |
130 | | - iges_filename = get_test_fullname("sample.igs") |
131 | | - write_iges_file(A_TOPODS_SHAPE, iges_filename) |
132 | | - self.check_is_file(iges_filename) |
| 102 | +def test_read_stl_file(): |
| 103 | + read_stl_file(STL_ASCII_SAMPLE_FILE) |
| 104 | + read_stl_file(STL_BINARY_SAMPLE_FILE) |
133 | 105 |
|
134 | | - def test_stl_ascii(self): |
135 | | - stl_ascii_filename = get_test_fullname("sample_ascii.stl") |
136 | | - write_stl_file(A_TOPODS_SHAPE, stl_ascii_filename, mode="ascii") |
137 | | - self.check_is_file(stl_ascii_filename) |
138 | 106 |
|
139 | | - def test_stl_binary(self): |
140 | | - stl_binary_filename = get_test_fullname("sample_binary.stl") |
141 | | - write_stl_file(A_TOPODS_SHAPE, stl_binary_filename, mode="binary") |
142 | | - self.check_is_file(stl_binary_filename) |
| 107 | +def test_export_shape_to_svg(): |
| 108 | + svg_filename = get_test_fullname("sample.svg") |
| 109 | + export_shape_to_svg(A_TOPODS_SHAPE, svg_filename) |
| 110 | + check_is_file(svg_filename) |
143 | 111 |
|
144 | | - def test_write_ply(self): |
145 | | - ply_filename = get_test_fullname("sample.ply") |
146 | | - write_ply_file(A_TOPODS_SHAPE, ply_filename) |
147 | | - self.check_is_file(ply_filename) |
148 | 112 |
|
149 | | - def test_write_obj(self): |
150 | | - obj_filename = get_test_fullname("sample.obj") |
151 | | - write_obj_file(A_TOPODS_SHAPE, obj_filename) |
152 | | - self.check_is_file(obj_filename) |
| 113 | +def test_read_gltf_ascii_file(): |
| 114 | + shp = read_gltf_file(GLTF_ASCII_SAMPLE_FILE) |
153 | 115 |
|
154 | | - def test_write_gltf(self): |
155 | | - gltf_filename = get_test_fullname("sample.gltf") |
156 | | - write_gltf_file(A_TOPODS_SHAPE, gltf_filename) |
157 | | - self.check_is_file(gltf_filename) |
158 | 116 |
|
| 117 | +def test_read_gltf_binary_file(): |
| 118 | + shp = read_gltf_file(GLTF_BINARY_SAMPLE_FILE) |
159 | 119 |
|
160 | | -def suite(): |
161 | | - test_suite = unittest.TestSuite() |
162 | | - test_suite.addTest(unittest.makeSuite(TestExtendDataExchange)) |
163 | | - return test_suite |
164 | | - |
165 | | - |
166 | | -if __name__ == "__main__": |
167 | | - unittest.main() |
| 120 | + |
| 121 | +def test_write_step_ap203(): |
| 122 | + ap203_filename = get_test_fullname("sample_ap_203.stp") |
| 123 | + write_step_file(A_TOPODS_SHAPE, ap203_filename, application_protocol="AP203") |
| 124 | + check_is_file(ap203_filename) |
| 125 | + |
| 126 | + |
| 127 | +def test_write_step_ap214(): |
| 128 | + as214_filename = get_test_fullname("sample_214.stp") |
| 129 | + write_step_file(A_TOPODS_SHAPE, as214_filename, application_protocol="AP214IS") |
| 130 | + check_is_file(as214_filename) |
| 131 | + |
| 132 | + |
| 133 | +def test_write_step_ap242(): |
| 134 | + ap242_filename = get_test_fullname("sample_242.stp") |
| 135 | + write_step_file(A_TOPODS_SHAPE, ap242_filename, application_protocol="AP242DIS") |
| 136 | + check_is_file(ap242_filename) |
| 137 | + |
| 138 | + |
| 139 | +def test_write_iges(): |
| 140 | + iges_filename = get_test_fullname("sample.igs") |
| 141 | + write_iges_file(A_TOPODS_SHAPE, iges_filename) |
| 142 | + check_is_file(iges_filename) |
| 143 | + |
| 144 | + |
| 145 | +def test_stl_ascii(): |
| 146 | + stl_ascii_filename = get_test_fullname("sample_ascii.stl") |
| 147 | + write_stl_file(A_TOPODS_SHAPE, stl_ascii_filename, mode="ascii") |
| 148 | + check_is_file(stl_ascii_filename) |
| 149 | + |
| 150 | + |
| 151 | +def test_stl_binary(): |
| 152 | + stl_binary_filename = get_test_fullname("sample_binary.stl") |
| 153 | + write_stl_file(A_TOPODS_SHAPE, stl_binary_filename, mode="binary") |
| 154 | + check_is_file(stl_binary_filename) |
| 155 | + |
| 156 | + |
| 157 | +def test_write_ply(): |
| 158 | + ply_filename = get_test_fullname("sample.ply") |
| 159 | + write_ply_file(A_TOPODS_SHAPE, ply_filename) |
| 160 | + check_is_file(ply_filename) |
| 161 | + |
| 162 | + |
| 163 | +def test_write_obj(): |
| 164 | + obj_filename = get_test_fullname("sample.obj") |
| 165 | + write_obj_file(A_TOPODS_SHAPE, obj_filename) |
| 166 | + check_is_file(obj_filename) |
| 167 | + |
| 168 | + |
| 169 | +def test_write_gltf(): |
| 170 | + gltf_filename = get_test_fullname("sample.gltf") |
| 171 | + write_gltf_file(A_TOPODS_SHAPE, gltf_filename) |
| 172 | + check_is_file(gltf_filename) |
0 commit comments