1 # Copyright (C) 2010-2013 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 This module provides auxiliary classes, functions and variables for testing.
24 #from __future__ import print_function
30 from datetime import date
37 samples_dir = os.getenv("DATA_DIR")
40 if samples_dir is not None:
41 samples_dir = os.path.normpath(samples_dir)
42 datadir = samples_dir + "/MedFiles/"
43 tablesdir = samples_dir + "/Tables/"
45 # Graphica files extension
46 pictureext = os.getenv("PIC_EXT")
47 if pictureext == None:
52 class RepresentationType:
54 Types of representation.
64 _type2name = {OUTLINE: 'Outline',
66 WIREFRAME: 'Wireframe',
68 SURFACEEDGES: 'Surface With Edges',
70 POINTSPRITE: 'Point Sprite'}
73 def get_name(cls, type):
74 """Return paraview representation type by the primitive type."""
75 return cls._type2name[type]
78 class SalomeSession(object):
82 #sys.argv += ["--killall"]
83 #sys.argv += ["--portkill=" + port]
84 sys.argv += ["--show-desktop=1"]
85 sys.argv += ["--splash=0"]
86 sys.argv += ["--modules=MED,PARAVIS"]
87 sys.argv += ["--standalone=study"]
88 sys.argv += ["--embedded=SalomeAppEngine,cppContainer,registry,moduleCatalog"]
89 clt, d = runSalome.main()
94 #VTN: workaround for crash on CentOS.6.3.64
96 #os.system('killSalomeWithPort.py {0}'.format(self.port))
97 #os.system('killSalomeWithPort.py ' + self.port)
98 #import killSalomeWithPort
99 #killSalomeWithPort.killMyPort(self.port)
104 # Auxiliary functions
105 def test_values(value, et_value, check_error=0):
109 et_length = len(et_value)
110 if (length != et_length):
111 err_msg = "ERROR!!! There is different number of created " + str(length) + " and etalon " + str(et_length) + " values!!!"
115 for i in range(et_length):
116 if abs(et_value[i]) > 1:
117 max_val = abs(0.001 * et_value[i])
118 if abs(et_value[i] - value[i]) > max_val:
119 err_msg = "ERROR!!! Got value " + str(value[i]) + " is not equal to etalon value " + str(ret_value[i]) + "!!!"
124 if abs(et_value[i] - value[i]) > max_val:
125 err_msg = "ERROR!!! Got value " + value[i] + " is not equal to etalon value " + et_value[i] + "!!!"
127 if check_error and error > 0:
128 err_msg = ("There is(are) some error(s) was(were) found... "
129 "For more info see ERRORs above...")
130 raise RuntimeError(err_msg)
134 def get_picture_dir(subdir):
135 res_dir = os.getenv("PARAVIS_TEST_PICS")
137 # Add username and current date to unify the directory
138 cur_user = getpass.getuser()
139 cur_date = date.today().strftime("%Y%m%d")
140 res_dir = tempfile.gettempdir() + \
141 "/pic_" + cur_user + \
143 # Add subdirectory for the case to the directory path
144 res_dir += "/" + subdir
145 # Create the directory if doesn't exist
146 res_dir = os.path.normpath(res_dir)
147 if not os.path.exists(res_dir):
150 # Clean the directory
151 for root, dirs, files in os.walk(res_dir):
153 os.remove(os.path.join(root, f))
158 def call_and_check(prs, property_name, value, do_raise=1, compare_toler=-1.0):
159 """Utility function for 3D viewer test for common check of different
160 types of presentation parameters set"""
162 prs.SetPropertyWithName(property_name, value)
164 error_string = (str(value) + "value of " + property_name + " is not available for this type of presentations")
167 is_good = (error_string is None)
170 raise RuntimeError(error_string)
174 # compare just set value and the one got from presentation
175 really_set_value = prs.GetPropertyValue(property_name)
177 if compare_toler > 0:
178 is_equal = (fabs(really_set_value - value) < compare_toler)
180 is_equal = (really_set_value == value)
182 msg = str(really_set_value) + " has been set instead"
184 raise RuntimeError(msg)
192 def setShaded(view, shading):
193 """Utility function to set shaded mode in view"""
195 view.LightDiffuseColor = [1, 1, 1]
197 view.LightDiffuseColor = [0, 0, 0]
201 salome_session = SalomeSession()