19 mevisAvailable = hasattr(mevis,
"MLAB")
and hasattr(mevis.MLAB,
"isDebug")
and mevis.MLAB.isDebug()
is not None
21 mevisAvailable =
False
24from .Utils
import deprecated
31import xml.etree.cElementTree
as etree
33if sys.version_info.major >= 3:
39 path = os.path.join(os.environ[
"LOCALAPPDATA"],
"MeVis",
"MeVisLab")
43 path = mevis.MLABFileManager.getUserApplicationSupportDirectory()
46 path = os.path.join(os.environ[
"HOME"],
".local",
"share",
"MeVis",
"MeVisLab")
51 if not os.path.isdir(path):
54 filePattern =
"test_case_manager_cfg_{}.xml" if isTestCaseManager
else "tc_cfg_{}.xml"
55 return os.path.join(path, filePattern.format(sys.platform))
59 if not os.path.isfile(cfgFile):
73 reportDir = os.path.join(os.getenv(
"USERPROFILE"),
"TestCenterReports")
75 reportDir = os.path.join(os.getenv(
"HOME"),
"TestCenterReports")
81 directory=getReportDir(),
83 timestampTemplate=
"_%y_%m_%d__%H_%M",
84 appendTestCaseName=
False,
85 appendTimestamp=
False,
86 collapseFunctions=
False,
87 showFailedFuctionsOnly=
False,
88 hideInfoMessages=
False,
89 hideSystemMessages=
False,
105 def __init__(self, filePath=None, autoSave=True, isTestCaseManager=False):
106 """Loads configuration from given file or creates configuration with default values.
107 If a configuration is created and @a autoSave is True then the configuration is
108 automatically saved. Otherwise, you have to save is explicitly.
117 cfgFileToLoad = filePath
118 if not os.path.isfile(cfgFileToLoad):
122 if os.path.isfile(cfgFileToLoad):
123 self.
__load(cfgFileToLoad)
125 if autoSave
and not os.path.isfile(filePath):
128 "Config file <a href='mlab-open:{filePath}'>{fileName}</a> does not exist: creating it."
130 mevis.MLAB.logHTML(warningTemplate.format(filePath=filePath, fileName=os.path.basename(filePath)))
132 print(
"Config file %s does not exist: creating it." % (filePath))
140 def __setDefaultValues(self):
142 return [
"-nosplash",
"-noide",
"-quick"]
148 executablePath = os.path.dirname(mevis.MLABFileManager.getExecutable(
"MeVisLab"))
150 executablePath = os.path.dirname(mevis.MLABFileManager.getExecutable(
"MeVisLab"))
151 elif "MLAB_BUILD" in os.environ:
153 executablePath = os.path.abspath(os.path.join(os.environ.get(
"MLAB_BUILD"),
"MeVisLab",
"IDE",
"bin"))
156 thisDir = os.path.dirname(os.path.abspath(__file__))
157 thisMLABRoot = os.path.normpath(os.path.join(thisDir,
"..",
"..",
"..",
"..",
"..",
".."))
159 path = os.path.abspath(os.path.join(thisMLABRoot,
"MeVisLab",
"IDE",
"bin"))
160 if os.path.isfile(os.path.join(path,
"MeVisLab.exe")):
161 executablePath = path
163 path = os.path.abspath(os.path.join(thisMLABRoot,
"..",
"bin"))
164 if os.path.isfile(os.path.join(path,
"MeVisLab")):
165 executablePath = path
167 return executablePath
169 if Utils.isUnsupportedPlatform:
170 raise Exception(
"Unsupported platform (%s)" % (sys.platform))
195 exclusionExpressions = [
197 "*/TestCenterAdvanced/*",
198 "*/MLABPythonTools/*",
201 "*/IDE/mevislabInternal.py",
202 "*/__mevislab_bootstrap_importlib.py",
203 "*/Standard/Modules/Scripts/python/PackageSorter.py",
204 "*/BuildTools/Scripts/MeVisPython.py",
205 "*/@@scriptconsole*",
212 os.path.normpath(expression)
for expression
in exclusionExpressions
227 def __load(self, filename):
228 if not os.path.isfile(filename):
229 raise Exception(
"Given file does not exist: %s" % (filename))
231 xmlTree = etree.parse(filename)
232 xmlRoot = xmlTree.getroot()
242 return node
is not None and node.text
is not None
245 node = xmlRoot.find(
"mlab/usecurrent")
251 node = xmlRoot.find(
"mlab/executable")
256 mode = node.get(
"compilemode")
259 elif node.get(
"usedebug") ==
"True":
264 node = xmlRoot.find(
"mlab/arguments")
268 node = xmlRoot.find(
"mlab/resultdir")
272 node = xmlRoot.find(
"mlab/resultfile")
276 node = xmlRoot.find(
"mlab/slavelogfile")
280 node = xmlRoot.find(
"mlab/timeout")
284 node = xmlRoot.find(
"mlab/restartinterval")
288 node = xmlRoot.find(
"mlab/MaximumTestTimeout")
295 node = xmlRoot.find(
"report/directory")
299 node = xmlRoot.find(
"report/name")
303 node = xmlRoot.find(
"report/timestamp")
305 self.
__report.timestampTemplate = node.text
308 reportNode = xmlRoot.find(
"report")
309 if not reportNode
is None:
311 reportNode, self.
__report.appendTestCaseName,
"appendTestCaseName"
314 reportNode, self.
__report.appendTimestamp,
"appendTimestamp"
317 reportNode, self.
__report.collapseFunctions,
"collapseFunctions"
320 reportNode, self.
__report.showFailedFunctionsOnly,
"showFailedOnly"
324 reportNode, self.
__report.hideSystemMessages,
"hideSystemMessages"
327 reportNode, self.
__report.maxInfoMessagesPerTestFunction,
"maxInfoMessagesPerTestFunction"
330 reportNode, self.
__report.maxErrorMessagesPerTestFunction,
"maxErrorMessagesPerTestFunction"
337 attributeValue = node.get(attributeName)
338 if attributeValue
is not None:
339 boolean = attributeValue ==
"True"
347 attributeValue = node.get(attributeName)
348 if attributeValue
is not None:
350 result = int(attributeValue)
352 print(
"Error: Can't parse %s with value %s as int." % (attributeName, attributeValue))
356 node = xmlRoot.find(
"TestCaseManager")
358 b = self.
getBoolean(node,
True,
"reloadPythonModulesBeforeTestExecution")
362 node = etree.SubElement(xmlRoot,
"TestCaseManager")
366 coverageNode = xmlRoot.find(
"Coverage")
367 if not coverageNode
is None:
372 bullseyeNode = coverageNode.find(
"Bullseye")
373 if bullseyeNode
is not None:
380 pythonCoverageNode = coverageNode.find(
"Python")
381 if pythonCoverageNode
is not None:
395 loaded = set([expression.text
for expression
in coverageNode.findall(
"ExclusionExpression")])
405 loaded = set([expression.text
for expression
in coverageNode.findall(
"InclusionExpression")])
414 node = xmlRoot.find(
"IPCConnectionTimeout")
422 xmlRoot = etree.Element(
"Configuration")
423 xmlTree = etree.ElementTree(xmlRoot)
425 mlabNode = etree.SubElement(xmlRoot,
"mlab")
428 etree.SubElement(mlabNode,
"usecurrent").text =
"True" if self.
__MLABUseCurrent else "False"
429 node = etree.SubElement(mlabNode,
"executable")
432 etree.SubElement(mlabNode,
"arguments").text =
",".join(self.
__MLABArguments)
439 reportNode = etree.SubElement(xmlRoot,
"report")
441 etree.SubElement(reportNode,
"directory").text = self.
__report.directory
442 etree.SubElement(reportNode,
"name").text = self.
__report.name
443 etree.SubElement(reportNode,
"timestamp").text = self.
__report.timestampTemplate
445 reportNode.set(
"appendTestCaseName",
unicode(self.
__report.appendTestCaseName))
446 reportNode.set(
"appendTimestamp",
unicode(self.
__report.appendTimestamp))
447 reportNode.set(
"collapseFunctions",
unicode(self.
__report.collapseFunctions))
448 reportNode.set(
"showFailedOnly",
unicode(self.
__report.showFailedFunctionsOnly))
450 reportNode.set(
"hideSystemMessages",
unicode(self.
__report.hideSystemMessages))
451 reportNode.set(
"maxErrorMessagesPerTestFunction",
unicode(self.
__report.maxErrorMessagesPerTestFunction))
452 reportNode.set(
"maxInfoMessagesPerTestFunction",
unicode(self.
__report.maxInfoMessagesPerTestFunction))
454 coverageNode = etree.SubElement(xmlRoot,
"Coverage")
456 pythonCoverageNode = etree.SubElement(coverageNode,
"Python")
461 etree.SubElement(pythonCoverageNode,
"ExclusionExpression").text = expression
464 etree.SubElement(pythonCoverageNode,
"InclusionExpression").text = expression
466 bullseNode = etree.SubElement(coverageNode,
"Bullseye")
469 ipcConnectionTimeoutNode = etree.SubElement(xmlRoot,
"IPCConnectionTimeout")
474 Utils.indentXML(xmlRoot)
480 xmlTree.write(filename)
481 except Exception
as e:
482 mevis.MLAB.logWarningHTML(
"Unable to write config file: %s.\n%s" % (filename, e))
511 Searches for the executable in the basePath and all levels of the provided
512 subPath in a 'deepest first' manner
514 path = os.path.normpath(subPath)
515 pathComponents = path.split(os.sep)
516 pathComponents.append(executableName)
518 executablePath =
None
519 while pathComponents:
520 candidate = os.path.join(basePath, *pathComponents)
521 if os.path.isfile(candidate):
522 executablePath = candidate
525 pathComponents.pop(0)
527 if executablePath
is None:
530 return os.path.normpath(candidate)
536 mlabExecutableName +=
".exe"
540 expandedMLABPath, mlabExecutableName,
"Packages/MeVisLab/IDE/bin" if Utils.isWindows
else "bin"
558 return mevisAvailable
and mevis.MLAB.isDebug()
576 + [
"-nomateconnection",
"-runmacro", macroName,
"-c", self.
__configFilePath]
609 showFailedFunctionsOnly,
620 showFailedFunctionsOnly,
632 return self.
__report.timestampTemplate
635 return self.
__report.appendTestCaseName
638 return self.
__report.appendTimestamp
641 return self.
__report.collapseFunctions
644 return self.
__report.showFailedFunctionsOnly
647 return self.
__report.hideInfoMessages
650 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)