18 mevisAvailable = hasattr(mevis,
'MLAB')
and hasattr(mevis.MLAB,
'isDebug')
and mevis.MLAB.isDebug()
is not None
20 mevisAvailable =
False
23from .Utils
import deprecated
30import xml.etree.cElementTree
as etree
32if sys.version_info.major >= 3:
37 path = os.path.join( os.environ[
'LOCALAPPDATA' ],
'MeVis',
'MeVisLab' )
41 path = mevis.MLABFileManager.getUserApplicationSupportDirectory()
44 path = os.path.join( os.environ[
'HOME'],
'.local',
'share',
'MeVis',
'MeVisLab' )
49 if (
not os.path.isdir( path )):
52 filePattern =
"test_case_manager_cfg_{}.xml" if isTestCaseManager
else "tc_cfg_{}.xml"
53 return os.path.join( path, filePattern.format( sys.platform ))
57 if not os.path.isfile(cfgFile):
71 reportDir = os.path.join(os.getenv(
"USERPROFILE"),
"TestCenterReports")
73 reportDir = os.path.join(os.getenv(
"HOME"),
"TestCenterReports")
79 directory = getReportDir(),
81 timestampTemplate =
"_%y_%m_%d__%H_%M",
82 appendTestCaseName =
False,
83 appendTimestamp =
False,
84 collapseFunctions =
False,
85 showFailedFuctionsOnly =
False,
86 hideInfoMessages =
False,
87 hideSystemMessages =
False):
101 def __init__ (self, filePath=None, autoSave=True, isTestCaseManager=False):
102 """ Loads configuration from given file or creates configuration with default values.
103 If a configuration is created and @a autoSave is True then the configuration is
104 automatically saved. Otherwise, you have to save is explicitly.
113 cfgFileToLoad = filePath
114 if not os.path.isfile(cfgFileToLoad):
118 if os.path.isfile(cfgFileToLoad):
119 self.
__load(cfgFileToLoad)
121 if autoSave
and not os.path.isfile(filePath):
123 warningTemplate =
"Config file <a href='mlab-open:{filePath}'>{fileName}</a> does not exist: creating it."
124 mevis.MLAB.logHTML(warningTemplate.format(filePath=filePath,
125 fileName=os.path.basename(filePath)))
127 print(
"Config file %s does not exist: creating it." % (filePath))
135 def __setDefaultValues (self):
137 return [
"-nosplash",
"-noide",
"-quick"]
143 executablePath = os.path.dirname(mevis.MLABFileManager.getExecutable(
"MeVisLab"))
145 executablePath = os.path.dirname(mevis.MLABFileManager.getExecutable(
"MeVisLab"))
146 elif 'MLAB_BUILD' in os.environ:
148 executablePath = os.path.abspath(
149 os.path.join(os.environ.get(
'MLAB_BUILD'),
'MeVisLab',
'IDE',
'bin'))
152 thisDir = os.path.dirname(os.path.abspath(__file__))
153 thisMLABRoot = os.path.normpath(os.path.join(thisDir,
'..',
'..',
'..',
'..',
'..',
'..'))
155 path = os.path.abspath(os.path.join(thisMLABRoot,
'MeVisLab',
'IDE',
'bin'))
156 if os.path.isfile(os.path.join(path,
'MeVisLab.exe')):
157 executablePath = path
159 path = os.path.abspath(os.path.join(thisMLABRoot,
'..',
'bin'))
160 if os.path.isfile(os.path.join(path,
'MeVisLab')):
161 executablePath = path
163 return executablePath
166 if Utils.isUnsupportedPlatform:
167 raise Exception(
"Unsupported platform (%s)" % (sys.platform))
192 exclusionExpressions = [
"*/TestSupport/*",
193 "*/TestCenterAdvanced/*",
194 "*/MLABPythonTools/*",
197 "*/IDE/mevislabInternal.py",
198 "*/__mevislab_bootstrap_importlib.py",
199 "*/Standard/Modules/Scripts/python/PackageSorter.py",
200 "*/BuildTools/Scripts/MeVisPython.py",
201 "*/@@scriptconsole*",
207 os.path.normpath(expression)
for expression
in exclusionExpressions
223 def __load (self, filename):
224 if not os.path.isfile(filename):
225 raise Exception(
"Given file does not exist: %s" % (filename))
227 xmlTree = etree.parse(filename)
228 xmlRoot = xmlTree.getroot()
239 return node
is not None and node.text
is not None
243 node = xmlRoot.find(
"mlab/usecurrent")
249 node = xmlRoot.find(
"mlab/executable")
254 mode = node.get(
"compilemode")
257 elif node.get(
"usedebug") ==
"True":
262 node = xmlRoot.find(
"mlab/arguments")
266 node = xmlRoot.find(
"mlab/resultdir")
270 node = xmlRoot.find(
"mlab/resultfile")
274 node = xmlRoot.find(
"mlab/slavelogfile")
278 node = xmlRoot.find(
"mlab/timeout")
282 node = xmlRoot.find(
"mlab/restartinterval")
286 node = xmlRoot.find(
"mlab/MaximumTestTimeout")
294 node = xmlRoot.find(
"report/directory")
298 node = xmlRoot.find(
"report/name")
302 node = xmlRoot.find(
"report/timestamp")
304 self.
__report.timestampTemplate = node.text
308 reportNode = xmlRoot.find(
"report")
309 if not reportNode
is None:
312 "appendTestCaseName")
320 self.
__report.showFailedFunctionsOnly,
327 "hideSystemMessages")
329 self.
__report.maxInfoMessagesPerTestFunction,
330 "maxInfoMessagesPerTestFunction")
332 self.
__report.maxErrorMessagesPerTestFunction,
333 "maxErrorMessagesPerTestFunction")
339 attributeValue = node.get(attributeName)
340 if attributeValue
is not None:
341 boolean = attributeValue ==
"True"
349 attributeValue = node.get(attributeName)
350 if attributeValue
is not None:
352 result = int(attributeValue)
354 print(
"Error: Can't parse %s with value %s as int." % (attributeName, attributeValue))
358 node = xmlRoot.find(
"TestCaseManager")
360 b = self.
getBoolean(node,
True,
"reloadPythonModulesBeforeTestExecution")
364 node = etree.SubElement(xmlRoot,
"TestCaseManager")
369 coverageNode = xmlRoot.find(
"Coverage")
370 if not coverageNode
is None:
375 bullseyeNode = coverageNode.find(
"Bullseye")
376 if bullseyeNode
is not None:
385 pythonCoverageNode = coverageNode.find(
"Python")
386 if pythonCoverageNode
is not None:
405 loaded = set([expression.text
for expression
in coverageNode.findall(
"ExclusionExpression")])
414 loaded = set([expression.text
for expression
in coverageNode.findall(
"InclusionExpression")])
422 node = xmlRoot.find(
"IPCConnectionTimeout")
429 def save (self, filename = None):
430 xmlRoot = etree.Element(
"Configuration")
431 xmlTree = etree.ElementTree(xmlRoot)
433 mlabNode = etree.SubElement(xmlRoot,
"mlab")
436 etree.SubElement(mlabNode,
"usecurrent").text =
"True" if self.
__MLABUseCurrent else "False"
437 node = etree.SubElement(mlabNode,
"executable")
440 etree.SubElement(mlabNode,
"arguments").text =
",".join(self.
__MLABArguments)
447 reportNode = etree.SubElement(xmlRoot,
"report")
449 etree.SubElement(reportNode,
"directory").text = self.
__report.directory
450 etree.SubElement(reportNode,
"name").text = self.
__report.name
451 etree.SubElement(reportNode,
"timestamp").text = self.
__report.timestampTemplate
453 reportNode.set(
"appendTestCaseName",
unicode(self.
__report.appendTestCaseName))
454 reportNode.set(
"appendTimestamp",
unicode(self.
__report.appendTimestamp))
455 reportNode.set(
"collapseFunctions",
unicode(self.
__report.collapseFunctions))
456 reportNode.set(
"showFailedOnly",
unicode(self.
__report.showFailedFunctionsOnly))
458 reportNode.set(
"hideSystemMessages",
unicode(self.
__report.hideSystemMessages))
459 reportNode.set(
"maxErrorMessagesPerTestFunction",
unicode(self.
__report.maxErrorMessagesPerTestFunction))
460 reportNode.set(
"maxInfoMessagesPerTestFunction",
unicode(self.
__report.maxInfoMessagesPerTestFunction))
462 coverageNode = etree.SubElement(xmlRoot,
"Coverage")
464 pythonCoverageNode = etree.SubElement(coverageNode,
"Python")
469 etree.SubElement(pythonCoverageNode,
"ExclusionExpression").text = expression
472 etree.SubElement(pythonCoverageNode,
"InclusionExpression").text = expression
474 bullseNode = etree.SubElement(coverageNode,
"Bullseye")
477 ipcConnectionTimeoutNode = etree.SubElement(xmlRoot,
"IPCConnectionTimeout")
482 Utils.indentXML(xmlRoot)
488 xmlTree.write(filename)
489 except Exception
as e:
490 mevis.MLAB.logWarningHTML(
"Unable to write config file: %s.\n%s" % (filename, e))
528 Searches for the executable in the basePath and all levels of the provided
529 subPath in a 'deepest first' manner
531 path = os.path.normpath(subPath)
532 pathComponents = path.split(os.sep)
533 pathComponents.append(executableName)
535 executablePath =
None
536 while pathComponents:
537 candidate = os.path.join(basePath, *pathComponents)
538 if os.path.isfile(candidate):
539 executablePath = candidate
542 pathComponents.pop(0)
544 if executablePath
is None:
547 return os.path.normpath(candidate)
554 mlabExecutableName +=
".exe"
556 command = [self.
findMLABExecutable(expandedMLABPath, mlabExecutableName,
"Packages/MeVisLab/IDE/bin" if Utils.isWindows
else "bin")]
575 return mevisAvailable
and mevis.MLAB.isDebug()
594 + [
'-nomateconnection',
'-runmacro', macroName,
'-c', self.
__configFilePath])
631 showFailedFunctionsOnly,
640 showFailedFunctionsOnly,
653 return self.
__report.timestampTemplate
657 return self.
__report.appendTestCaseName
661 return self.
__report.appendTimestamp
665 return self.
__report.collapseFunctions
669 return self.
__report.showFailedFunctionsOnly
673 return self.
__report.hideInfoMessages
677 return self.
__report.hideSystemMessages
getBoolean(node, default, attributeName)
save(self, filename=None)
Save the configuration variables set to the file with the given name.
setTestCaseManagerOptions(self, shouldReloadPythonModulesWhenReloadingTestCases)
__init__(self, filePath=None, autoSave=True, isTestCaseManager=False)
getMLABExecutableCommand(self)
getIPCConnectionTimeout(self)
setMLABArguments(self, arguments)
fetchBullseyeCoverageSettings(self, coverageNode)
useMLABDebugVersion(self)
getMLABCurrentBinariesPath(self)
setMLABExecutablePath(self, executablePath)
__pythonCoverageInclusionExpressions
fetchIPCSettings(self, xmlRoot)
fetchUsePythonCoverage(self, pythonCoverageNode)
findMLABExecutable(basePath, executableName, subPath)
storeTestCaseManagerSettings(self, xmlRoot)
getMLABTestCenterCommand(self, macroName)
appendTestCaseNameToReportName(self)
fetchReportSettings(self, xmlRoot)
isPythonCoverageEnabled(self)
fetchPythonCoverageExclusionExpressions(self, coverageNode)
fetchCoverageSettings(self, xmlRoot)
fetchUseGlobalPythonCoverage(self, pythonCoverageNode)
fetchTestCaseManagerSettings(self, xmlRoot)
__shouldReloadPythonModulesWhenReloadingTestCases
__useGlobalPythonCoverage
shouldReloadPythonModulesWhenReloadingTestCases(self)
fetchReportNodeSettings(self, xmlRoot)
setResultDir(self, directory)
setMLABUseCurrent(self, usecurrent)
fetchUseBullseyeCoverage(self, bullseyeNode)
getCoverageExclusions(self)
isBullseyeCoverageEnabled(self)
__MLABCurrentExecutablePath
setMLABCompileMode(self, value)
setBullseyeCoverageEnabled(self, value)
getMLABEffectiveBinariesPath(self)
fetchMLABSettings(self, xmlRoot)
setPythonCoverageEnabled(self, value)
isGlobalPythonCoverageEnabled(self)
getMLABBinariesPath(self)
setReportOptions(self, directory, name, timestampTemplate, appendTestCaseName, appendTimestamp, collapseFunctions, showFailedFunctionsOnly, hideInfoMessages, hideSystemMessages)
__pythonCoverageExclusionExpressions
setMLABUseDebug(self, useDebug)
setGlobalPythonCoverageEnabled(self, value)
appendTimestampToReportName(self)
getInteger(node, default, attributeName)
getSlaveLogFilePath(self)
getMaxTestTimeoutSeconds(self)
fetchPythonCoverageInclusionExpressions(self, coverageNode)
getDefaultTestTimeoutSeconds(self)
fetchPythonCoverageSettings(self, coverageNode)
__defaultTestTimeoutSeconds
showFailedFunctionsOnly(self)
getCoverageInclusions(self)
getReportTimestampTemplate(self)
__init__(self, directory=getReportDir(), name="Report", timestampTemplate="_%y_%m_%d__%H_%M", appendTestCaseName=False, appendTimestamp=False, collapseFunctions=False, showFailedFuctionsOnly=False, hideInfoMessages=False, hideSystemMessages=False)
maxErrorMessagesPerTestFunction
maxInfoMessagesPerTestFunction
getConfigFilePath(isTestCaseManager=False)
verifyConfiguration(cfgFile)