19 mevisAvailable = hasattr(mevis,
"MLAB")
and hasattr(mevis.MLAB,
"isDebug")
and mevis.MLAB.isDebug()
is not None
21 mevisAvailable =
False
29import xml.etree.cElementTree
as etree
34 path = os.path.join(os.environ[
"LOCALAPPDATA"],
"MeVis",
"MeVisLab")
38 path = mevis.MLABFileManager.getUserApplicationSupportDirectory()
41 path = os.path.join(os.environ[
"HOME"],
".local",
"share",
"MeVis",
"MeVisLab")
46 if not os.path.isdir(path):
49 filePattern =
"test_case_manager_cfg_{}.xml" if isTestCaseManager
else "tc_cfg_{}.xml"
50 return os.path.join(path, filePattern.format(sys.platform))
54 if not os.path.isfile(cfgFile):
68 return os.path.join(os.getenv(
"USERPROFILE"),
"TestCenterReports")
69 return os.path.join(os.getenv(
"HOME"),
"TestCenterReports")
73 directory=getReportDir(),
75 timestampTemplate=
"_%y_%m_%d__%H_%M",
76 appendTestCaseName=
False,
77 appendTimestamp=
False,
78 collapseFunctions=
False,
79 showFailedFuctionsOnly=
False,
80 hideInfoMessages=
False,
81 hideSystemMessages=
False,
97 def __init__(self, filePath=None, autoSave=True, isTestCaseManager=False):
98 """Loads configuration from given file or creates configuration with default values.
99 If a configuration is created and @a autoSave is True then the configuration is
100 automatically saved. Otherwise, you have to save is explicitly.
103 return [
"-nosplash",
"-noide",
"-quick"]
109 executablePath = os.path.dirname(mevis.MLABFileManager.getExecutable(
"MeVisLab"))
111 executablePath = os.path.dirname(mevis.MLABFileManager.getExecutable(
"MeVisLab"))
112 elif "MLAB_BUILD" in os.environ:
114 executablePath = os.path.abspath(os.path.join(os.environ.get(
"MLAB_BUILD"),
"MeVisLab",
"IDE",
"bin"))
117 thisDir = os.path.dirname(os.path.abspath(__file__))
118 thisMLABRoot = os.path.normpath(os.path.join(thisDir,
"..",
"..",
"..",
"..",
"..",
".."))
120 path = os.path.abspath(os.path.join(thisMLABRoot,
"MeVisLab",
"IDE",
"bin"))
121 if os.path.isfile(os.path.join(path,
"MeVisLab.exe")):
122 executablePath = path
124 path = os.path.abspath(os.path.join(thisMLABRoot,
"..",
"bin"))
125 if os.path.isfile(os.path.join(path,
"MeVisLab")):
126 executablePath = path
128 return executablePath
130 if Utils.isUnsupportedPlatform:
131 raise Exception(
"Unsupported platform (%s)" % sys.platform)
159 exclusionExpressions = [
161 "*/TestCenterAdvanced/*",
162 "*/MLABPythonTools/*",
165 "*/IDE/mevislabInternal.py",
166 "*/__mevislab_bootstrap_importlib.py",
167 "*/Standard/Modules/Scripts/python/PackageSorter.py",
168 "*/BuildTools/Scripts/MeVisPython.py",
169 "*/@@scriptconsole*",
176 os.path.normpath(expression)
for expression
in exclusionExpressions
191 cfgFileToLoad = filePath
192 if not os.path.isfile(cfgFileToLoad):
196 if os.path.isfile(cfgFileToLoad):
197 self.
__load(cfgFileToLoad)
199 if autoSave
and not os.path.isfile(filePath):
202 "Config file <a href='mlab-open:{filePath}'>{fileName}</a> does not exist: creating it."
204 mevis.MLAB.logHTML(warningTemplate.format(filePath=filePath, fileName=os.path.basename(filePath)))
206 print(
"Config file %s does not exist: creating it." % filePath)
211 def __load(self, filename):
212 """Load the configuration values from the given file.
213 The method raises an exception if the given file does not exist. The method is private as it is
214 called by the classes' __init__ method.
216 if not os.path.isfile(filename):
217 raise Exception(
"Given file does not exist: %s" % filename)
219 xmlTree = etree.parse(filename)
220 xmlRoot = xmlTree.getroot()
230 return node
is not None and node.text
is not None
233 node = xmlRoot.find(
"mlab/usecurrent")
239 node = xmlRoot.find(
"mlab/executable")
244 mode = node.get(
"compilemode")
247 elif node.get(
"usedebug") ==
"True":
252 node = xmlRoot.find(
"mlab/arguments")
256 node = xmlRoot.find(
"mlab/resultdir")
260 node = xmlRoot.find(
"mlab/resultfile")
264 node = xmlRoot.find(
"mlab/slavelogfile")
268 node = xmlRoot.find(
"mlab/timeout")
272 node = xmlRoot.find(
"mlab/restartinterval")
276 node = xmlRoot.find(
"mlab/MaximumTestTimeout")
283 node = xmlRoot.find(
"report/directory")
287 node = xmlRoot.find(
"report/name")
291 node = xmlRoot.find(
"report/timestamp")
293 self.
__report.timestampTemplate = node.text
296 reportNode = xmlRoot.find(
"report")
297 if not reportNode
is None:
299 reportNode, self.
__report.appendTestCaseName,
"appendTestCaseName"
302 reportNode, self.
__report.appendTimestamp,
"appendTimestamp"
305 reportNode, self.
__report.collapseFunctions,
"collapseFunctions"
308 reportNode, self.
__report.showFailedFunctionsOnly,
"showFailedOnly"
312 reportNode, self.
__report.hideSystemMessages,
"hideSystemMessages"
315 reportNode, self.
__report.maxInfoMessagesPerTestFunction,
"maxInfoMessagesPerTestFunction"
318 reportNode, self.
__report.maxErrorMessagesPerTestFunction,
"maxErrorMessagesPerTestFunction"
325 attributeValue = node.get(attributeName)
326 if attributeValue
is not None:
327 boolean = attributeValue ==
"True"
335 attributeValue = node.get(attributeName)
336 if attributeValue
is not None:
338 result = int(attributeValue)
340 print(
"Error: Can't parse %s with value %s as int." % (attributeName, attributeValue))
344 node = xmlRoot.find(
"TestCaseManager")
346 b = self.
getBoolean(node,
True,
"reloadPythonModulesBeforeTestExecution")
350 node = etree.SubElement(xmlRoot,
"TestCaseManager")
354 coverageNode = xmlRoot.find(
"Coverage")
355 if not coverageNode
is None:
360 bullseyeNode = coverageNode.find(
"Bullseye")
361 if bullseyeNode
is not None:
368 pythonCoverageNode = coverageNode.find(
"Python")
369 if pythonCoverageNode
is not None:
383 loaded = set([expression.text
for expression
in coverageNode.findall(
"ExclusionExpression")])
393 loaded = set([expression.text
for expression
in coverageNode.findall(
"InclusionExpression")])
402 node = xmlRoot.find(
"IPCConnectionTimeout")
410 xmlRoot = etree.Element(
"Configuration")
411 xmlTree = etree.ElementTree(xmlRoot)
413 mlabNode = etree.SubElement(xmlRoot,
"mlab")
416 etree.SubElement(mlabNode,
"usecurrent").text =
"True" if self.
__MLABUseCurrent else "False"
417 node = etree.SubElement(mlabNode,
"executable")
420 etree.SubElement(mlabNode,
"arguments").text =
",".join(self.
__MLABArguments)
427 reportNode = etree.SubElement(xmlRoot,
"report")
429 etree.SubElement(reportNode,
"directory").text = self.
__report.directory
430 etree.SubElement(reportNode,
"name").text = self.
__report.name
431 etree.SubElement(reportNode,
"timestamp").text = self.
__report.timestampTemplate
433 reportNode.set(
"appendTestCaseName", str(self.
__report.appendTestCaseName))
434 reportNode.set(
"appendTimestamp", str(self.
__report.appendTimestamp))
435 reportNode.set(
"collapseFunctions", str(self.
__report.collapseFunctions))
436 reportNode.set(
"showFailedOnly", str(self.
__report.showFailedFunctionsOnly))
437 reportNode.set(
"hideInfos", str(self.
__report.hideInfoMessages))
438 reportNode.set(
"hideSystemMessages", str(self.
__report.hideSystemMessages))
439 reportNode.set(
"maxErrorMessagesPerTestFunction", str(self.
__report.maxErrorMessagesPerTestFunction))
440 reportNode.set(
"maxInfoMessagesPerTestFunction", str(self.
__report.maxInfoMessagesPerTestFunction))
442 coverageNode = etree.SubElement(xmlRoot,
"Coverage")
444 pythonCoverageNode = etree.SubElement(coverageNode,
"Python")
449 etree.SubElement(pythonCoverageNode,
"ExclusionExpression").text = expression
452 etree.SubElement(pythonCoverageNode,
"InclusionExpression").text = expression
454 bullseNode = etree.SubElement(coverageNode,
"Bullseye")
457 ipcConnectionTimeoutNode = etree.SubElement(xmlRoot,
"IPCConnectionTimeout")
462 Utils.indentXML(xmlRoot)
468 xmlTree.write(filename)
469 except Exception
as e:
470 mevis.MLAB.logWarningHTML(
"Unable to write config file: %s.\n%s" % (filename, e))
499 Searches for the executable in the basePath and all levels of the provided
500 subPath in a 'deepest first' manner
502 path = os.path.normpath(subPath)
503 pathComponents = path.split(os.sep)
504 pathComponents.append(executableName)
506 executablePath =
None
507 while pathComponents:
508 candidate = os.path.join(basePath, *pathComponents)
509 if os.path.isfile(candidate):
510 executablePath = candidate
513 pathComponents.pop(0)
515 if executablePath
is None:
518 return os.path.normpath(candidate)
524 mlabExecutableName +=
".exe"
528 expandedMLABPath, mlabExecutableName,
"Packages/MeVisLab/IDE/bin" if Utils.isWindows
else "bin"
546 return mevisAvailable
and mevis.MLAB.isDebug()
564 + [
"-nomateconnection",
"-runmacro", macroName,
"-c", self.
__configFilePath]
597 showFailedFunctionsOnly,
608 showFailedFunctionsOnly,
620 return self.
__report.timestampTemplate
623 return self.
__report.appendTestCaseName
626 return self.
__report.appendTimestamp
629 return self.
__report.collapseFunctions
632 return self.
__report.showFailedFunctionsOnly
635 return self.
__report.hideInfoMessages
638 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)
Loads configuration from given file or creates configuration with default values.
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)
Searches for the executable in the basePath and all levels of the provided subPath in a 'deepest firs...
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)