TestCenter Reference
Config.py
Go to the documentation of this file.
1 #
2 # Copyright 2007, MeVis Medical Solutions AG
3 #
4 # The user may use this file in accordance with the license agreement provided with
5 # the Software or, alternatively, in accordance with the terms contained in a
6 # written agreement between the user and MeVis Medical Solutions AG.
7 #
8 # For further information use the contact form at https://www.mevislab.de/contact
9 #
10 
11 
13 
14 
15 # -- local imports
16 try:
17  import mevis
18  mevisAvailable = hasattr(mevis, 'MLAB') and hasattr(mevis.MLAB, 'isDebug') and mevis.MLAB.isDebug() is not None
19 except ImportError:
20  mevisAvailable = False
21 
22 from . import Utils
23 from .Utils import deprecated
24 
25 # -- system imports
26 import os
27 import sys
28 import tempfile
29 
30 import xml.etree.cElementTree as etree
31 
32 if sys.version_info.major >= 3:
33  unicode = str
34 
35 def getConfigFilePath (isTestCaseManager=False):
36  if Utils.isMac:
37  if mevisAvailable:
38  path = os.path.join( mevis.MLABFileManager.getUserApplicationSupportDirectory(), 'Settings' )
39 
40  else:
41  path = os.path.join( os.environ['HOME'], 'Library', 'Application Support', 'MeVisLab', 'Settings' )
42 
43  elif Utils.isWindows:
44  path = os.path.join( os.environ[ 'LOCALAPPDATA' ], 'MeVis', 'MeVisLab' )
45 
46  elif Utils.isLinux:
47  if mevisAvailable:
48  path = mevis.MLABFileManager.getUserApplicationSupportDirectory()
49 
50  else:
51  path = os.path.join( os.environ['HOME'], '.local', 'share', 'MeVis', 'MeVisLab' )
52 
53  else:
54  path = os.getcwd()
55 
56  if ( not os.path.isdir( path )):
57  os.makedirs( path )
58 
59  filePattern = "test_case_manager_cfg_{}.xml" if isTestCaseManager else "tc_cfg_{}.xml"
60  return os.path.join( path, filePattern.format( sys.platform ))
61 
62 
63 def verifyConfiguration (cfgFile):
64  if not os.path.isfile(cfgFile):
65  Configuration(cfgFile)
66  return False
67  return True
68 
69 
71  pass
72 
73 
74 class ReportConfig(object):
75  def getReportDir(): # @NoSelf
76  reportDir = ""
77  if Utils.isWindows:
78  reportDir = os.path.join(os.getenv("USERPROFILE"), "TestCenterReports")
79  elif Utils.isMac:
80  if mevisAvailable:
81  reportDir = os.path.join(mevis.MLABFileManager.getUserApplicationSupportDirectory(), "TestCenterReports")
82  else:
83  reportDir = os.path.join(os.environ['HOME'], 'Library', 'Application Support', 'MeVisLab', 'TestCenterReports')
84  elif Utils.isLinux:
85  reportDir = os.path.join(os.getenv("HOME"), "TestCenterReports")
86 
87  return reportDir
88 
89 
90  def __init__(self,
91  directory = getReportDir(),
92  name = "Report",
93  timestampTemplate = "_%y_%m_%d__%H_%M",
94  appendTestCaseName = False,
95  appendTimestamp = False,
96  collapseFunctions = False,
97  showFailedFuctionsOnly = False,
98  hideInfoMessages = False,
99  hideSystemMessages = False):
100  self.directorydirectory = directory
101  self.namename = name
102  self.timestampTemplatetimestampTemplate = timestampTemplate
103  self.appendTestCaseNameappendTestCaseName = appendTestCaseName
104  self.appendTimestampappendTimestamp = appendTimestamp
105  self.collapseFunctionscollapseFunctions = collapseFunctions
106  self.showFailedFunctionsOnlyshowFailedFunctionsOnly = showFailedFuctionsOnly
107  self.hideInfoMessageshideInfoMessages = hideInfoMessages
108  self.hideSystemMessageshideSystemMessages = hideSystemMessages
109  self.maxErrorMessagesPerTestFunctionmaxErrorMessagesPerTestFunction = 1000
110  self.maxInfoMessagesPerTestFunctionmaxInfoMessagesPerTestFunction = 1000
111 
112 class Configuration (object):
113  def __init__ (self, filePath=None, autoSave=True, isTestCaseManager=False):
114  """ Loads configuration from given file or creates configuration with default values.
115  If a configuration is created and @a autoSave is True then the configuration is
116  automatically saved. Otherwise, you have to save is explicitly.
117  """
118  self.__setDefaultValues__setDefaultValues()
119 
120  # The default config file name is tc_cfg_<platform>.xml which can be
121  # overwritten by explicitly specifying a filePath.
122  if not filePath:
123  filePath = getConfigFilePath(isTestCaseManager=isTestCaseManager)
124 
125  cfgFileToLoad = filePath
126  if not os.path.isfile(cfgFileToLoad):
127  # for backward compatibility: read settings from config file of automated test center
128  cfgFileToLoad = getConfigFilePath(isTestCaseManager=False)
129 
130  if os.path.isfile(cfgFileToLoad):
131  self.__load__load(cfgFileToLoad)
132 
133  if autoSave and not os.path.isfile(filePath):
134  if mevisAvailable:
135  warningTemplate = "Config file <a href='mlab-open:{filePath}'>{fileName}</a> does not exist: creating it."
136  mevis.MLAB.logHTML(warningTemplate.format(filePath=filePath,
137  fileName=os.path.basename(filePath)))
138  else:
139  print("Config file %s does not exist: creating it." % (filePath))
140  self.savesave(filePath)
141 
142  self.__configFilePath__configFilePath = os.path.abspath(filePath)
143 
144 
147  def __setDefaultValues (self):
148  def getArguments():
149  arguments = ["-nosplash", "-noide", "-quick"]
150 
151  if Utils.isMac:
152  arguments.append("-unique")
153 
154  return arguments
155 
156  def getMLABBinariesPath():
157  executablePath = ""
158  if mevisAvailable:
159  if Utils.isWindows:
160  executablePath = os.path.dirname(mevis.MLABFileManager.getExecutable("MeVisLab"))
161  elif Utils.isMac:
162  executablePath = mevis.MLABFileManager.macGetBundleDir()
163  elif Utils.isLinux:
164  executablePath = os.path.dirname(mevis.MLABFileManager.getExecutable("MeVisLab"))
165  elif 'MLAB_BUILD' in os.environ:
166  # developer environment, use that, no questions asked
167  executablePath = os.path.abspath(
168  os.path.join(os.environ.get('MLAB_BUILD'), 'MeVisLab', 'IDE', 'bin'))
169  else:
170  # check public sdk location relative to this file
171  thisDir = os.path.dirname(os.path.abspath(__file__))
172  thisMLABRoot = os.path.normpath(os.path.join(thisDir, '..', '..', '..', '..', '..', '..'))
173  if Utils.isWindows:
174  path = os.path.abspath(os.path.join(thisMLABRoot, 'MeVisLab', 'IDE', 'bin'))
175  if os.path.isfile(os.path.join(path, 'MeVisLab.exe')):
176  executablePath = path
177  elif Utils.isMac:
178  # MLAB_ROOT is MeVisLab.app/Contents/Packages
179  path = os.path.abspath(os.path.join(thisMLABRoot, '..', '..'))
180  if os.path.isdir(os.path.join(path, 'Contents')):
181  executablePath = path
182  else:
183  path = os.path.join(os.environ['HOME'], 'Applications', 'MeVisLab.app')
184  if os.path.isdir(path):
185  executablePath = path
186  elif Utils.isLinux:
187  path = os.path.abspath(os.path.join(thisMLABRoot, '..', 'bin'))
188  if os.path.isfile(os.path.join(path, 'MeVisLab')):
189  executablePath = path
190 
191  return executablePath
192 
193 
194  if Utils.isUnsupportedPlatform:
195  raise Exception("Unsupported platform (%s)" % (sys.platform))
196 
197  self.__MLABCurrentExecutablePath__MLABCurrentExecutablePath = getMLABBinariesPath()
198  self.__MLABExecutablePath__MLABExecutablePath = self.__MLABCurrentExecutablePath__MLABCurrentExecutablePath
199  self.__MLABUseCurrent__MLABUseCurrent = True
200  self.__MLABArguments__MLABArguments = getArguments()
201  self.__MLABCompileMode__MLABCompileMode = "Automatic"
202  self.__resultOutputDirectory__resultOutputDirectory = os.path.join(tempfile.gettempdir(), "TestCenter")
203  self.__xmlResultFileName__xmlResultFileName = "tc_result.xml"
204  self.__MLABSlaveLogFileName__MLABSlaveLogFileName = "mevislab_slave.log"
205  self.__defaultTestTimeoutSeconds__defaultTestTimeoutSeconds = 20
206  # Number of TestCases after which MLAB is restarted during the execution of multiple
207  # tests. If this is set to zero, MLAB is not restarted at all.
208  self.__mMLABRestartInterval__mMLABRestartInterval = 1
209  # If a test is configured with a timeout above this value, do not execute it and let it fail.
210  self.__maxTestTimeoutSeconds__maxTestTimeoutSeconds = 0
211 
212  self.__shouldReloadPythonModulesWhenReloadingTestCases__shouldReloadPythonModulesWhenReloadingTestCases = True
213 
214  self.__usePythonCoverage__usePythonCoverage = False
215  # Controls if the python coverage measured during the execution of tests is accumulated
216  # into one report (True) or if for every test a separate report is generated (False).
217  self.__useGlobalPythonCoverage__useGlobalPythonCoverage = False
218  # All files matching one of these expressions
219  # are excluded from the coverage for that test run.
220  exclusionExpressions = ["*/TestSupport/*",
221  "*/TestCenterAdvanced/*",
222  "*/MLABPythonTools/*",
223  "*/*.script*",
224  "*/*.def*",
225  "*/IDE/mevislabInternal.py",
226  "*/__mevislab_bootstrap_importlib.py",
227  "*/Standard/Modules/Scripts/python/PackageSorter.py",
228  "*/BuildTools/Scripts/MeVisPython.py",
229  "*/@@scriptconsole*",
230  "*$*"]
231 
232  #convert to native path format
233  self.__pythonCoverageExclusionExpressions__pythonCoverageExclusionExpressions = [
234  os.path.normpath(expression) for expression in exclusionExpressions
235  ]
236 
237  # C++ coverage tool
238  self.__useBullseyeCoverage__useBullseyeCoverage = False
239 
240  self.__ipcConnectionTimeout__ipcConnectionTimeout = 2
241 
242  self.__report__report = ReportConfig()
243 
244 
245 
248  def __load (self, filename):
249  if not os.path.isfile(filename):
250  raise Exception("Given file does not exist: %s" % (filename))
251 
252  xmlTree = etree.parse(filename)
253  xmlRoot = xmlTree.getroot()
254 
255  self.fetchMLABSettingsfetchMLABSettings(xmlRoot)
256  self.fetchReportSettingsfetchReportSettings(xmlRoot)
257  self.fetchCoverageSettingsfetchCoverageSettings(xmlRoot)
258  self.fetchTestCaseManagerSettingsfetchTestCaseManagerSettings(xmlRoot)
259  self.fetchIPCSettingsfetchIPCSettings(xmlRoot)
260 
261 
262  @staticmethod
263  def nodeHasValidText(node):
264  return node is not None and node.text is not None
265 
266 
267  def fetchMLABSettings(self, xmlRoot):
268  node = xmlRoot.find("mlab/usecurrent")
269  if self.nodeHasValidTextnodeHasValidText(node):
270  self.__MLABUseCurrent__MLABUseCurrent = node.text.lower() in ["true", "1", "yes", "on"]
271  else:
272  self.__MLABUseCurrent__MLABUseCurrent = True
273 
274  node = xmlRoot.find("mlab/executable")
275  if self.nodeHasValidTextnodeHasValidText(node):
276  self.__MLABExecutablePath__MLABExecutablePath = node.text
277 
278  if node is not None:
279  mode = node.get("compilemode")
280  if mode:
281  self.__MLABCompileMode__MLABCompileMode = mode
282  elif node.get("usedebug") == "True":
283  self.__MLABCompileMode__MLABCompileMode = "Debug"
284  else:
285  self.__MLABCompileMode__MLABCompileMode = "Automatic"
286 
287  node = xmlRoot.find("mlab/arguments")
288  if self.nodeHasValidTextnodeHasValidText(node):
289  self.__MLABArguments__MLABArguments = node.text.split(",")
290 
291  node = xmlRoot.find("mlab/resultdir")
292  if self.nodeHasValidTextnodeHasValidText(node):
293  self.__resultOutputDirectory__resultOutputDirectory = node.text
294 
295  node = xmlRoot.find("mlab/resultfile")
296  if self.nodeHasValidTextnodeHasValidText(node):
297  self.__xmlResultFileName__xmlResultFileName = node.text
298 
299  node = xmlRoot.find("mlab/slavelogfile")
300  if self.nodeHasValidTextnodeHasValidText(node):
301  self.__MLABSlaveLogFileName__MLABSlaveLogFileName = node.text
302 
303  node = xmlRoot.find("mlab/timeout")
304  if self.nodeHasValidTextnodeHasValidText(node):
305  self.__defaultTestTimeoutSeconds__defaultTestTimeoutSeconds = int(node.text)
306 
307  node = xmlRoot.find("mlab/restartinterval")
308  if self.nodeHasValidTextnodeHasValidText(node):
309  self.__mMLABRestartInterval__mMLABRestartInterval = int(node.text)
310 
311  node = xmlRoot.find("mlab/MaximumTestTimeout")
312  if self.nodeHasValidTextnodeHasValidText(node):
313  self.__maxTestTimeoutSeconds__maxTestTimeoutSeconds = int(node.text)
314 
315 
316  def fetchReportSettings(self, xmlRoot):
317  self.fetchReportNodeSettingsfetchReportNodeSettings(xmlRoot)
318 
319  node = xmlRoot.find("report/directory")
320  if self.nodeHasValidTextnodeHasValidText(node):
321  self.__report__report.directory = node.text
322 
323  node = xmlRoot.find("report/name")
324  if self.nodeHasValidTextnodeHasValidText(node):
325  self.__report__report.name = node.text
326 
327  node = xmlRoot.find("report/timestamp")
328  if self.nodeHasValidTextnodeHasValidText(node):
329  self.__report__report.timestampTemplate = node.text
330 
331 
332  def fetchReportNodeSettings(self, xmlRoot):
333  reportNode = xmlRoot.find("report")
334  if not reportNode is None:
335  self.__report__report.appendTestCaseName = self.getBooleangetBoolean(reportNode,
336  self.__report__report.appendTestCaseName,
337  "appendTestCaseName")
338  self.__report__report.appendTimestamp = self.getBooleangetBoolean(reportNode,
339  self.__report__report.appendTimestamp,
340  "appendTimestamp")
341  self.__report__report.collapseFunctions = self.getBooleangetBoolean(reportNode,
342  self.__report__report.collapseFunctions,
343  "collapseFunctions")
344  self.__report__report.showFailedFunctionsOnly = self.getBooleangetBoolean(reportNode,
345  self.__report__report.showFailedFunctionsOnly,
346  "showFailedOnly")
347  self.__report__report.hideInfoMessages = self.getBooleangetBoolean(reportNode,
348  self.__report__report.hideInfoMessages,
349  "hideInfos")
350  self.__report__report.hideSystemMessages = self.getBooleangetBoolean(reportNode,
351  self.__report__report.hideSystemMessages,
352  "hideSystemMessages")
353  self.__report__report.maxInfoMessagesPerTestFunction = self.getIntegergetInteger(reportNode,
354  self.__report__report.maxInfoMessagesPerTestFunction,
355  "maxInfoMessagesPerTestFunction")
356  self.__report__report.maxErrorMessagesPerTestFunction = self.getIntegergetInteger(reportNode,
357  self.__report__report.maxErrorMessagesPerTestFunction,
358  "maxErrorMessagesPerTestFunction")
359 
360  @staticmethod
361  def getBoolean(node, default, attributeName):
362  boolean = default
363 
364  attributeValue = node.get(attributeName)
365  if attributeValue is not None:
366  boolean = attributeValue == "True"
367 
368  return boolean
369 
370  @staticmethod
371  def getInteger(node, default, attributeName):
372  result = default
373 
374  attributeValue = node.get(attributeName)
375  if attributeValue is not None:
376  try:
377  result = int(attributeValue)
378  except:
379  print("Error: Can't parse %s with value %s as int." % (attributeName, attributeValue))
380  return result
381 
382  def fetchTestCaseManagerSettings(self, xmlRoot):
383  node = xmlRoot.find("TestCaseManager")
384  if not node is None:
385  b = self.getBooleangetBoolean(node, True, "reloadPythonModulesBeforeTestExecution")
386  self.__shouldReloadPythonModulesWhenReloadingTestCases__shouldReloadPythonModulesWhenReloadingTestCases = b
387 
388  def storeTestCaseManagerSettings(self, xmlRoot):
389  node = etree.SubElement(xmlRoot, "TestCaseManager")
390  node.set("reloadPythonModulesBeforeTestExecution", str(self.__shouldReloadPythonModulesWhenReloadingTestCases__shouldReloadPythonModulesWhenReloadingTestCases))
391 
392 
393  def fetchCoverageSettings(self, xmlRoot):
394  coverageNode = xmlRoot.find("Coverage")
395  if not coverageNode is None:
396  self.fetchBullseyeCoverageSettingsfetchBullseyeCoverageSettings(coverageNode)
397  self.fetchPythonCoverageSettingsfetchPythonCoverageSettings(coverageNode)
398 
399  def fetchBullseyeCoverageSettings(self, coverageNode):
400  bullseyeNode = coverageNode.find("Bullseye")
401  if bullseyeNode is not None:
402  self.fetchUseBullseyeCoveragefetchUseBullseyeCoverage(bullseyeNode)
403 
404  def fetchUseBullseyeCoverage(self, bullseyeNode):
405  self.__useBullseyeCoverage__useBullseyeCoverage = self.getBooleangetBoolean(bullseyeNode,
406  self.__useBullseyeCoverage__useBullseyeCoverage,
407  "enabled")
408 
409  def fetchPythonCoverageSettings(self, coverageNode):
410  pythonCoverageNode = coverageNode.find("Python")
411  if pythonCoverageNode is not None:
412  self.fetchUsePythonCoveragefetchUsePythonCoverage(pythonCoverageNode)
413  self.fetchUseGlobalPythonCoveragefetchUseGlobalPythonCoverage(pythonCoverageNode)
414  self.fetchPythonCoverageExclusionExpressionsfetchPythonCoverageExclusionExpressions(pythonCoverageNode)
415 
416  def fetchUsePythonCoverage(self, pythonCoverageNode):
417  self.__usePythonCoverage__usePythonCoverage = self.getBooleangetBoolean(pythonCoverageNode,
418  self.__usePythonCoverage__usePythonCoverage,
419  "enabled")
420 
421  def fetchUseGlobalPythonCoverage(self, pythonCoverageNode):
422  self.__useGlobalPythonCoverage__useGlobalPythonCoverage = self.getBooleangetBoolean(pythonCoverageNode,
423  self.__useGlobalPythonCoverage__useGlobalPythonCoverage,
424  "global")
425 
426 
428  default = set(self.__pythonCoverageExclusionExpressions__pythonCoverageExclusionExpressions)
429  loaded = set([expression.text for expression in coverageNode.findall("ExclusionExpression")])
430  #build union of default and loaded expressions using set type
431  self.__pythonCoverageExclusionExpressions__pythonCoverageExclusionExpressions = list(default | loaded)
432  #replace forward slashes with system default
433  self.__pythonCoverageExclusionExpressions__pythonCoverageExclusionExpressions = [os.path.normpath(expression)
434  for expression in self.__pythonCoverageExclusionExpressions__pythonCoverageExclusionExpressions]
435 
436  def fetchIPCSettings(self, xmlRoot):
437  node = xmlRoot.find("IPCConnectionTimeout")
438  if self.nodeHasValidTextnodeHasValidText(node):
439  self.__ipcConnectionTimeout__ipcConnectionTimeout = int(node.text)
440 
441 
444  def save (self, filename = None):
445  xmlRoot = etree.Element("Configuration")
446  xmlTree = etree.ElementTree(xmlRoot)
447 
448  mlabNode = etree.SubElement(xmlRoot, "mlab")
449 
450  etree.SubElement(mlabNode, "slavelogfile").text = self.__MLABSlaveLogFileName__MLABSlaveLogFileName
451  etree.SubElement(mlabNode, "usecurrent").text = "True" if self.__MLABUseCurrent__MLABUseCurrent else "False"
452  node = etree.SubElement(mlabNode, "executable")
453  node.set("compilemode", self.__MLABCompileMode__MLABCompileMode)
454  node.text = self.__MLABExecutablePath__MLABExecutablePath
455  etree.SubElement(mlabNode, "arguments").text = ",".join(self.__MLABArguments__MLABArguments)
456  etree.SubElement(mlabNode, "resultdir").text = self.__resultOutputDirectory__resultOutputDirectory
457  etree.SubElement(mlabNode, "resultfile").text = self.__xmlResultFileName__xmlResultFileName
458  etree.SubElement(mlabNode, "timeout").text = str(self.__defaultTestTimeoutSeconds__defaultTestTimeoutSeconds)
459  etree.SubElement(mlabNode, "MaximumTestTimeout").text = str(self.__maxTestTimeoutSeconds__maxTestTimeoutSeconds)
460  etree.SubElement(mlabNode, "restartinterval").text = str(self.__mMLABRestartInterval__mMLABRestartInterval)
461 
462  reportNode = etree.SubElement(xmlRoot, "report")
463 
464  etree.SubElement(reportNode, "directory").text = self.__report__report.directory
465  etree.SubElement(reportNode, "name").text = self.__report__report.name
466  etree.SubElement(reportNode, "timestamp").text = self.__report__report.timestampTemplate
467 
468  reportNode.set("appendTestCaseName", unicode(self.__report__report.appendTestCaseName))
469  reportNode.set("appendTimestamp", unicode(self.__report__report.appendTimestamp))
470  reportNode.set("collapseFunctions", unicode(self.__report__report.collapseFunctions))
471  reportNode.set("showFailedOnly", unicode(self.__report__report.showFailedFunctionsOnly))
472  reportNode.set("hideInfos", unicode(self.__report__report.hideInfoMessages))
473  reportNode.set("hideSystemMessages", unicode(self.__report__report.hideSystemMessages))
474  reportNode.set("maxErrorMessagesPerTestFunction", unicode(self.__report__report.maxErrorMessagesPerTestFunction))
475  reportNode.set("maxInfoMessagesPerTestFunction", unicode(self.__report__report.maxInfoMessagesPerTestFunction))
476 
477  coverageNode = etree.SubElement(xmlRoot, "Coverage")
478 
479  pythonCoverageNode = etree.SubElement(coverageNode, "Python")
480  pythonCoverageNode.set("enabled", str(self.__usePythonCoverage__usePythonCoverage))
481  pythonCoverageNode.set("global", str(self.__useGlobalPythonCoverage__useGlobalPythonCoverage))
482 
483  for expression in self.__pythonCoverageExclusionExpressions__pythonCoverageExclusionExpressions:
484  etree.SubElement(pythonCoverageNode, "ExclusionExpression").text = expression
485 
486  bullseNode = etree.SubElement(coverageNode, "Bullseye")
487  bullseNode.set("enabled", str(self.__useBullseyeCoverage__useBullseyeCoverage))
488 
489  ipcConnectionTimeoutNode = etree.SubElement(xmlRoot, "IPCConnectionTimeout")
490  ipcConnectionTimeoutNode.text = str(self.__ipcConnectionTimeout__ipcConnectionTimeout)
491 
492  self.storeTestCaseManagerSettingsstoreTestCaseManagerSettings(xmlRoot)
493 
494  Utils.indentXML(xmlRoot)
495 
496  if filename == None:
497  filename = self.__configFilePath__configFilePath
498 
499  try:
500  xmlTree.write(filename)
501  except Exception as e:
502  mevis.MLAB.logWarningHTML("Unable to write config file: %s.\n%s" % (filename, e))
503 
504 
506  return os.path.join(self.__resultOutputDirectory__resultOutputDirectory, self.__MLABSlaveLogFileName__MLABSlaveLogFileName)
507 
508 
509  def setResultDir (self, directory):
510  self.__resultOutputDirectory__resultOutputDirectory = directory
511 
512 
513  def getResultDir (self):
514  return self.__resultOutputDirectory__resultOutputDirectory
515 
516 
517  def getResultFile (self):
518  return os.path.join(self.__resultOutputDirectory__resultOutputDirectory, self.__xmlResultFileName__xmlResultFileName)
519 
520 
522  return self.__MLABCurrentExecutablePath__MLABCurrentExecutablePath
523 
524 
526  return os.path.expandvars(self.__MLABExecutablePath__MLABExecutablePath)
527 
528 
529  def getMLABUseCurrent (self):
530  return self.__MLABUseCurrent__MLABUseCurrent
531 
532 
534  return self.getMLABCurrentBinariesPathgetMLABCurrentBinariesPath() if self.getMLABUseCurrentgetMLABUseCurrent() else self.getMLABBinariesPathgetMLABBinariesPath()
535 
536 
537  @staticmethod
538  def findMLABExecutable(basePath, executableName, subPath):
539  """
540  Searches for the executable in the basePath and all levels of the provided
541  subPath in a 'deepest first' manner
542  """
543  path = os.path.normpath(subPath)
544  pathComponents = path.split(os.sep)
545  pathComponents.append(executableName)
546 
547  executablePath = None
548  while pathComponents:
549  candidate = os.path.join(basePath, *pathComponents)
550  if os.path.isfile(candidate):
551  executablePath = candidate
552  break
553 
554  pathComponents.pop(0)
555 
556  if executablePath is None:
558 
559  return os.path.normpath(candidate)
560 
561 
563  expandedMLABPath = self.getMLABEffectiveBinariesPathgetMLABEffectiveBinariesPath()
564  if not Utils.isMac:
565  mlabExecutableName = "MeVisLab_d" if self.useMLABDebugVersionuseMLABDebugVersion() else "MeVisLab"
566  if Utils.isWindows:
567  mlabExecutableName += ".exe"
568 
569  command = [self.findMLABExecutablefindMLABExecutable(expandedMLABPath, mlabExecutableName, "Packages/MeVisLab/IDE/bin" if Utils.isWindows else "bin")]
570  else:
571  executablePath = self.findMLABExecutablefindMLABExecutable(expandedMLABPath, "MeVisLab", "Contents/MacOS")
572  command = [executablePath, "-debug" if self.useMLABDebugVersionuseMLABDebugVersion() else "-release"]
573 
574  return command
575 
576 
577  def getMLABArguments (self):
578  return self.__MLABArguments__MLABArguments
579 
580 
581  def getMLABCompileMode (self):
582  return self.__MLABCompileMode__MLABCompileMode
583 
584 
586  if self.__MLABCompileMode__MLABCompileMode == "Debug":
587  return True
588  elif self.__MLABCompileMode__MLABCompileMode == "Release":
589  return False
590  else:
591  return mevisAvailable and mevis.MLAB.isDebug()
592 
593  def setMLABUseDebug (self, useDebug):
594  if useDebug:
595  self.__MLABCompileMode__MLABCompileMode = "Debug"
596  else:
597  self.__MLABCompileMode__MLABCompileMode = "Release"
598 
599 
601  return self.__shouldReloadPythonModulesWhenReloadingTestCases__shouldReloadPythonModulesWhenReloadingTestCases
602 
603  def setTestCaseManagerOptions(self, shouldReloadPythonModulesWhenReloadingTestCases):
604  self.__shouldReloadPythonModulesWhenReloadingTestCases__shouldReloadPythonModulesWhenReloadingTestCases = shouldReloadPythonModulesWhenReloadingTestCases
605 
606 
607  def getMLABTestCenterCommand (self, macroName):
608  return ( self.getMLABExecutableCommandgetMLABExecutableCommand()
609  + self.getMLABArgumentsgetMLABArguments()
610  + ['-nomateconnection', '-runmacro', macroName, '-c', self.__configFilePath__configFilePath])
611 
612 
613  def setMLABExecutablePath (self, executablePath):
614  if executablePath:
615  self.__MLABExecutablePath__MLABExecutablePath = executablePath
616 
617 
618  def setMLABUseCurrent (self, usecurrent):
619  self.__MLABUseCurrent__MLABUseCurrent = usecurrent
620 
621 
622  def setMLABArguments (self, arguments):
623  self.__MLABArguments__MLABArguments = arguments
624 
625 
626  def setMLABCompileMode (self, value):
627  self.__MLABCompileMode__MLABCompileMode = value
628 
629 
631  return self.__defaultTestTimeoutSeconds__defaultTestTimeoutSeconds
632 
633 
634  def getConfigFilePath (self):
635  return self.__configFilePath__configFilePath
636 
637  @deprecated
638  def getConfigFile(self):
639  return getConfigFilePath()
640 
641  def getReportOptions(self):
642  return self.__report__report
643 
644  def setReportOptions (self,
645  directory,
646  name,
647  timestampTemplate,
648  appendTestCaseName,
649  appendTimestamp,
650  collapseFunctions,
651  showFailedFunctionsOnly,
652  hideInfoMessages,
653  hideSystemMessages):
654  self.__report__report = ReportConfig(directory,
655  name,
656  timestampTemplate,
657  appendTestCaseName,
658  appendTimestamp,
659  collapseFunctions,
660  showFailedFunctionsOnly,
661  hideInfoMessages,
662  hideSystemMessages)
663 
664  def getReportDirectory (self):
665  return self.__report__report.directory
666 
667 
668  def getReportName (self):
669  return self.__report__report.name
670 
671 
673  return self.__report__report.timestampTemplate
674 
675 
677  return self.__report__report.appendTestCaseName
678 
679 
681  return self.__report__report.appendTimestamp
682 
683 
684  def collapseFunctions (self):
685  return self.__report__report.collapseFunctions
686 
687 
689  return self.__report__report.showFailedFunctionsOnly
690 
691 
692  def hideInfoMessages (self):
693  return self.__report__report.hideInfoMessages
694 
695 
696  def hideSystemMessages (self):
697  return self.__report__report.hideSystemMessages
698 
699 
701  return self.__pythonCoverageExclusionExpressions__pythonCoverageExclusionExpressions
702 
703 
705  return self.__usePythonCoverage__usePythonCoverage
706 
707 
709  return self.__useGlobalPythonCoverage__useGlobalPythonCoverage
710 
711 
712  def setPythonCoverageEnabled (self, value):
713  self.__usePythonCoverage__usePythonCoverage = True if value else False
714 
715 
717  self.__useGlobalPythonCoverage__useGlobalPythonCoverage = True if value else False
718 
719 
721  return self.__useBullseyeCoverage__useBullseyeCoverage
722 
723 
724  def setBullseyeCoverageEnabled (self, value):
725  self.__useBullseyeCoverage__useBullseyeCoverage = True if value else False
726 
727 
729  return self.__mMLABRestartInterval__mMLABRestartInterval
730 
731 
733  return self.__maxTestTimeoutSeconds__maxTestTimeoutSeconds
734 
736  return self.__ipcConnectionTimeout__ipcConnectionTimeout
737 
def fetchPythonCoverageSettings(self, coverageNode)
Definition: Config.py:409
def setMLABExecutablePath(self, executablePath)
Definition: Config.py:613
def fetchCoverageSettings(self, xmlRoot)
Definition: Config.py:393
def fetchMLABSettings(self, xmlRoot)
Definition: Config.py:267
def setTestCaseManagerOptions(self, shouldReloadPythonModulesWhenReloadingTestCases)
Definition: Config.py:603
def fetchReportNodeSettings(self, xmlRoot)
Definition: Config.py:332
def setGlobalPythonCoverageEnabled(self, value)
Definition: Config.py:716
def getBoolean(node, default, attributeName)
Definition: Config.py:361
def fetchIPCSettings(self, xmlRoot)
Definition: Config.py:436
def setMLABArguments(self, arguments)
Definition: Config.py:622
def __init__(self, filePath=None, autoSave=True, isTestCaseManager=False)
Definition: Config.py:113
def fetchPythonCoverageExclusionExpressions(self, coverageNode)
Definition: Config.py:427
def setBullseyeCoverageEnabled(self, value)
Definition: Config.py:724
def shouldReloadPythonModulesWhenReloadingTestCases(self)
Definition: Config.py:600
def storeTestCaseManagerSettings(self, xmlRoot)
Definition: Config.py:388
def setResultDir(self, directory)
Definition: Config.py:509
def fetchUseBullseyeCoverage(self, bullseyeNode)
Definition: Config.py:404
def fetchUsePythonCoverage(self, pythonCoverageNode)
Definition: Config.py:416
def save(self, filename=None)
Save the configuration variables set to the file with the given name.
Definition: Config.py:444
def setMLABUseDebug(self, useDebug)
Definition: Config.py:593
def fetchTestCaseManagerSettings(self, xmlRoot)
Definition: Config.py:382
def fetchUseGlobalPythonCoverage(self, pythonCoverageNode)
Definition: Config.py:421
def setPythonCoverageEnabled(self, value)
Definition: Config.py:712
def fetchBullseyeCoverageSettings(self, coverageNode)
Definition: Config.py:399
def getMLABTestCenterCommand(self, macroName)
Definition: Config.py:607
def fetchReportSettings(self, xmlRoot)
Definition: Config.py:316
def getInteger(node, default, attributeName)
Definition: Config.py:371
def findMLABExecutable(basePath, executableName, subPath)
Definition: Config.py:538
def setMLABUseCurrent(self, usecurrent)
Definition: Config.py:618
def setReportOptions(self, directory, name, timestampTemplate, appendTestCaseName, appendTimestamp, collapseFunctions, showFailedFunctionsOnly, hideInfoMessages, hideSystemMessages)
Definition: Config.py:653
def __init__(self, directory=getReportDir(), name="Report", timestampTemplate="_%y_%m_%d__%H_%M", appendTestCaseName=False, appendTimestamp=False, collapseFunctions=False, showFailedFuctionsOnly=False, hideInfoMessages=False, hideSystemMessages=False)
Definition: Config.py:99
def verifyConfiguration(cfgFile)
Definition: Config.py:63
def getConfigFilePath(isTestCaseManager=False)
Definition: Config.py:35