-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_salome_utilities.py
86 lines (67 loc) · 3.31 KB
/
test_salome_utilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# _ __ _ ___ _ ___ _ _
# | |/ /_ _ __ _| |_ ___ __/ __| __ _| |___ _ __ ___| _ \ |_ _ __ _(_)_ _
# | ' <| '_/ _` | _/ _ (_-<__ \/ _` | / _ \ ' \/ -_) _/ | || / _` | | ' \
# |_|\_\_| \__,_|\__\___/__/___/\__,_|_\___/_|_|_\___|_| |_|\_,_\__, |_|_||_|
# |___/
# License: BSD License ; see LICENSE
#
# Main authors: Philipp Bucher (https://github.com/philbucher)
#
# set up testing environment (before anything else)
import initialize_testing_environment
# python imports
import os
import shutil
import unittest
# plugin imports
from kratos_salome_plugin import salome_utilities
# tests imports
import testing_utilities
# salome imports
import salome
import GEOM
import SMESH
class TestSalomeUtilities(testing_utilities.SalomeTestCaseWithBox):
def test_GetSalomeObject(self):
object_id_list = [
(salome.smesh.smeshBuilder.meshProxy, "0:1:2:3"),
(salome.smesh.smeshBuilder.submeshProxy, "0:1:2:3:7:1"),
(salome.smesh.smeshBuilder.submeshProxy, "0:1:2:3:10:1"),
(GEOM._objref_GEOM_Object, "0:1:1:1"),
(GEOM._objref_GEOM_Object, "0:1:1:1:1"),
(GEOM._objref_GEOM_Object, "0:1:1:1:5")
]
for obj_id in object_id_list:
self.assertTrue(salome_utilities.ObjectExists(obj_id[1]))
self.assertEqual(obj_id[0], type(salome_utilities.GetSalomeObject(obj_id[1])))
def test_GetSalomeID(self):
# this test might fail if salome orders the ids differently in different versions
# it should not, since the order in which the objects are added is always the same
object_id_list = [
("0:1:2:3", self.mesh_tetra.GetMesh()),
("0:1:2:3:7:1", self.sub_mesh_tetra_f_1),
("0:1:2:3:10:1", self.sub_mesh_tetra_g_1),
("0:1:1:1", self.box),
("0:1:1:1:1", self.face_1),
("0:1:1:1:5", self.group_faces)
]
for obj_id in object_id_list:
self.assertEqual(obj_id[0], salome_utilities.GetSalomeID(obj_id[1]))
def test_GetObjectName(self):
identifier = salome_utilities.GetSalomeID(self.box)
self.assertEqual(salome_utilities.GetObjectName(identifier), self.name_main_box)
identifier = salome_utilities.GetSalomeID(self.mesh_tetra.GetMesh())
self.assertEqual(salome_utilities.GetObjectName(identifier), self.name_main_mesh_tetra)
identifier = salome_utilities.GetSalomeID(self.sub_mesh_hexa_g_2)
self.assertEqual(salome_utilities.GetObjectName(identifier), self.name_mesh_group)
def test_ObjectExists(self):
identifier = salome_utilities.GetSalomeID(self.box)
self.assertTrue(salome_utilities.ObjectExists(identifier))
identifier = salome_utilities.GetSalomeID(self.mesh_tetra.GetMesh())
self.assertTrue(salome_utilities.ObjectExists(identifier))
identifier = salome_utilities.GetSalomeID(self.sub_mesh_hexa_g_2)
self.assertTrue(salome_utilities.ObjectExists(identifier))
self.assertFalse(salome_utilities.ObjectExists("0:1:2:4:10:2:1:1:4:7:8")) # random identifier, should not exist
self.assertFalse(salome_utilities.ObjectExists("0:15555")) # random identifier, should not exist
if __name__ == '__main__':
unittest.main()