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
28 from datetime import date
35 samples_dir = os.getenv("DATA_DIR")
38 if samples_dir is not None:
39 samples_dir = os.path.normpath(samples_dir)
40 datadir = samples_dir + "/MedFiles/"
41 tablesdir = samples_dir + "/Tables/"
43 # Graphica files extension
44 pictureext = os.getenv("PIC_EXT")
45 if pictureext == None:
50 class RepresentationType:
52 Types of representation.
62 _type2name = {OUTLINE: 'Outline',
64 WIREFRAME: 'Wireframe',
66 SURFACEEDGES: 'Surface With Edges',
68 POINTSPRITE: 'Point Sprite'}
71 def get_name(cls, type):
72 """Return paraview representation type by the primitive type."""
73 return cls._type2name[type]
76 class SalomeSession(object):
80 #sys.argv += ["--killall"]
81 #sys.argv += ["--portkill=" + port]
82 sys.argv += ["--show-desktop=1"]
83 sys.argv += ["--splash=0"]
84 sys.argv += ["--modules=MED,PARAVIS"]
85 sys.argv += ["--standalone=study"]
86 sys.argv += ["--embedded=SalomeAppEngine,cppContainer,registry,moduleCatalog"]
87 clt, d = runSalome.main()
92 #VTN: workaround for crash on CentOS.6.3.64
94 #os.system('killSalomeWithPort.py {0}'.format(self.port))
95 #os.system('killSalomeWithPort.py ' + self.port)
96 #import killSalomeWithPort
97 #killSalomeWithPort.killMyPort(self.port)
102 # Auxiliary functions
103 def test_values(value, et_value, check_error=0):
107 et_length = len(et_value)
108 if (length != et_length):
109 err_msg = "ERROR!!! There is different number of created " + str(length) + " and etalon " + str(et_length) + " values!!!"
113 for i in range(et_length):
114 if abs(et_value[i]) > 1:
115 max_val = abs(0.001 * et_value[i])
116 if abs(et_value[i] - value[i]) > max_val:
117 err_msg = "ERROR!!! Got value " + str(value[i]) + " is not equal to etalon value " + str(ret_value[i]) + "!!!"
122 if abs(et_value[i] - value[i]) > max_val:
123 err_msg = "ERROR!!! Got value " + value[i] + " is not equal to etalon value " + et_value[i] + "!!!"
125 if check_error and error > 0:
126 err_msg = ("There is(are) some error(s) was(were) found... "
127 "For more info see ERRORs above...")
128 raise RuntimeError(err_msg)
132 def get_picture_dir(pic_dir, subdir):
137 # Add current date and subdirectory for the case to the directory path
138 cur_date = date.today().strftime("%d%m%Y")
139 res_dir += "/test_" + cur_date + "/" + subdir
140 # Create the directory if doesn't exist
141 res_dir = os.path.normpath(res_dir)
142 if not os.path.exists(res_dir):
145 # Clean the directory
146 for root, dirs, files in os.walk(res_dir):
148 os.remove(os.path.join(root, f))
153 def call_and_check(prs, property_name, value, do_raise=1, compare_toler=-1.0):
154 """Utility function for 3D viewer test for common check of different
155 types of presentation parameters set"""
157 prs.SetPropertyWithName(property_name, value)
159 error_string = (str(value) + "value of " + property_name + " is not available for this type of presentations")
162 is_good = (error_string is None)
165 raise RuntimeError(error_string)
169 # compare just set value and the one got from presentation
170 really_set_value = prs.GetPropertyValue(property_name)
172 if compare_toler > 0:
173 is_equal = (fabs(really_set_value - value) < compare_toler)
175 is_equal = (really_set_value == value)
177 msg = str(really_set_value) + " has been set instead"
179 raise RuntimeError(msg)
187 def setShaded(view, shading):
188 """Utility function to set shaded mode in view"""
190 view.LightDiffuseColor = [1, 1, 1]
192 view.LightDiffuseColor = [0, 0, 0]
196 salome_session = SalomeSession()