18 mevisAvailable = hasattr(mevis,
'MLAB')
and hasattr(mevis.MLAB,
'isDebug')
and mevis.MLAB.isDebug()
is not None
20 mevisAvailable =
False
23 from .Utils
import deprecated
30 import xml.etree.cElementTree
as etree
32 if sys.version_info.major >= 3:
38 path = os.path.join( mevis.MLABFileManager.getUserApplicationSupportDirectory(),
'Settings' )
41 path = os.path.join( os.environ[
'HOME'],
'Library',
'Application Support',
'MeVisLab',
'Settings' )
44 path = os.path.join( os.environ[
'LOCALAPPDATA' ],
'MeVis',
'MeVisLab' )
48 path = mevis.MLABFileManager.getUserApplicationSupportDirectory()
51 path = os.path.join( os.environ[
'HOME'],
'.local',
'share',
'MeVis',
'MeVisLab' )
56 if (
not os.path.isdir( path )):
59 filePattern =
"test_case_manager_cfg_{}.xml" if isTestCaseManager
else "tc_cfg_{}.xml"
60 return os.path.join( path, filePattern.format( sys.platform ))
64 if not os.path.isfile(cfgFile):
74 class ReportConfig(object):
78 reportDir = os.path.join(os.getenv(
"USERPROFILE"),
"TestCenterReports")
81 reportDir = os.path.join(mevis.MLABFileManager.getUserApplicationSupportDirectory(),
"TestCenterReports")
83 reportDir = os.path.join(os.environ[
'HOME'],
'Library',
'Application Support',
'MeVisLab',
'TestCenterReports')
85 reportDir = os.path.join(os.getenv(
"HOME"),
"TestCenterReports")
91 directory = getReportDir(),
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):
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.
125 cfgFileToLoad = filePath
126 if not os.path.isfile(cfgFileToLoad):
130 if os.path.isfile(cfgFileToLoad):
131 self.
__load__load(cfgFileToLoad)
133 if autoSave
and not os.path.isfile(filePath):
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)))
139 print(
"Config file %s does not exist: creating it." % (filePath))
140 self.
savesave(filePath)
147 def __setDefaultValues (self):
149 arguments = [
"-nosplash",
"-noide",
"-quick"]
152 arguments.append(
"-unique")
160 executablePath = os.path.dirname(mevis.MLABFileManager.getExecutable(
"MeVisLab"))
162 executablePath = mevis.MLABFileManager.macGetBundleDir()
164 executablePath = os.path.dirname(mevis.MLABFileManager.getExecutable(
"MeVisLab"))
165 elif 'MLAB_BUILD' in os.environ:
167 executablePath = os.path.abspath(
168 os.path.join(os.environ.get(
'MLAB_BUILD'),
'MeVisLab',
'IDE',
'bin'))
171 thisDir = os.path.dirname(os.path.abspath(__file__))
172 thisMLABRoot = os.path.normpath(os.path.join(thisDir,
'..',
'..',
'..',
'..',
'..',
'..'))
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
179 path = os.path.abspath(os.path.join(thisMLABRoot,
'..',
'..'))
180 if os.path.isdir(os.path.join(path,
'Contents')):
181 executablePath = path
183 path = os.path.join(os.environ[
'HOME'],
'Applications',
'MeVisLab.app')
184 if os.path.isdir(path):
185 executablePath = path
187 path = os.path.abspath(os.path.join(thisMLABRoot,
'..',
'bin'))
188 if os.path.isfile(os.path.join(path,
'MeVisLab')):
189 executablePath = path
191 return executablePath
194 if Utils.isUnsupportedPlatform:
195 raise Exception(
"Unsupported platform (%s)" % (sys.platform))
220 exclusionExpressions = [
"*/TestSupport/*",
221 "*/TestCenterAdvanced/*",
222 "*/MLABPythonTools/*",
225 "*/IDE/mevislabInternal.py",
226 "*/__mevislab_bootstrap_importlib.py",
227 "*/Standard/Modules/Scripts/python/PackageSorter.py",
228 "*/BuildTools/Scripts/MeVisPython.py",
229 "*/@@scriptconsole*",
234 os.path.normpath(expression)
for expression
in exclusionExpressions
248 def __load (self, filename):
249 if not os.path.isfile(filename):
250 raise Exception(
"Given file does not exist: %s" % (filename))
252 xmlTree = etree.parse(filename)
253 xmlRoot = xmlTree.getroot()
264 return node
is not None and node.text
is not None
268 node = xmlRoot.find(
"mlab/usecurrent")
270 self.
__MLABUseCurrent__MLABUseCurrent = node.text.lower()
in [
"true",
"1",
"yes",
"on"]
274 node = xmlRoot.find(
"mlab/executable")
279 mode = node.get(
"compilemode")
282 elif node.get(
"usedebug") ==
"True":
287 node = xmlRoot.find(
"mlab/arguments")
291 node = xmlRoot.find(
"mlab/resultdir")
295 node = xmlRoot.find(
"mlab/resultfile")
299 node = xmlRoot.find(
"mlab/slavelogfile")
303 node = xmlRoot.find(
"mlab/timeout")
307 node = xmlRoot.find(
"mlab/restartinterval")
311 node = xmlRoot.find(
"mlab/MaximumTestTimeout")
319 node = xmlRoot.find(
"report/directory")
321 self.
__report__report.directory = node.text
323 node = xmlRoot.find(
"report/name")
325 self.
__report__report.name = node.text
327 node = xmlRoot.find(
"report/timestamp")
329 self.
__report__report.timestampTemplate = node.text
333 reportNode = xmlRoot.find(
"report")
334 if not reportNode
is None:
336 self.
__report__report.appendTestCaseName,
337 "appendTestCaseName")
339 self.
__report__report.appendTimestamp,
342 self.
__report__report.collapseFunctions,
345 self.
__report__report.showFailedFunctionsOnly,
348 self.
__report__report.hideInfoMessages,
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")
364 attributeValue = node.get(attributeName)
365 if attributeValue
is not None:
366 boolean = attributeValue ==
"True"
374 attributeValue = node.get(attributeName)
375 if attributeValue
is not None:
377 result = int(attributeValue)
379 print(
"Error: Can't parse %s with value %s as int." % (attributeName, attributeValue))
383 node = xmlRoot.find(
"TestCaseManager")
385 b = self.
getBooleangetBoolean(node,
True,
"reloadPythonModulesBeforeTestExecution")
389 node = etree.SubElement(xmlRoot,
"TestCaseManager")
394 coverageNode = xmlRoot.find(
"Coverage")
395 if not coverageNode
is None:
400 bullseyeNode = coverageNode.find(
"Bullseye")
401 if bullseyeNode
is not None:
410 pythonCoverageNode = coverageNode.find(
"Python")
411 if pythonCoverageNode
is not None:
429 loaded = set([expression.text
for expression
in coverageNode.findall(
"ExclusionExpression")])
437 node = xmlRoot.find(
"IPCConnectionTimeout")
444 def save (self, filename = None):
445 xmlRoot = etree.Element(
"Configuration")
446 xmlTree = etree.ElementTree(xmlRoot)
448 mlabNode = etree.SubElement(xmlRoot,
"mlab")
451 etree.SubElement(mlabNode,
"usecurrent").text =
"True" if self.
__MLABUseCurrent__MLABUseCurrent
else "False"
452 node = etree.SubElement(mlabNode,
"executable")
455 etree.SubElement(mlabNode,
"arguments").text =
",".join(self.
__MLABArguments__MLABArguments)
457 etree.SubElement(mlabNode,
"resultfile").text = self.
__xmlResultFileName__xmlResultFileName
459 etree.SubElement(mlabNode,
"MaximumTestTimeout").text = str(self.
__maxTestTimeoutSeconds__maxTestTimeoutSeconds)
460 etree.SubElement(mlabNode,
"restartinterval").text = str(self.
__mMLABRestartInterval__mMLABRestartInterval)
462 reportNode = etree.SubElement(xmlRoot,
"report")
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
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))
477 coverageNode = etree.SubElement(xmlRoot,
"Coverage")
479 pythonCoverageNode = etree.SubElement(coverageNode,
"Python")
484 etree.SubElement(pythonCoverageNode,
"ExclusionExpression").text = expression
486 bullseNode = etree.SubElement(coverageNode,
"Bullseye")
489 ipcConnectionTimeoutNode = etree.SubElement(xmlRoot,
"IPCConnectionTimeout")
494 Utils.indentXML(xmlRoot)
500 xmlTree.write(filename)
501 except Exception
as e:
502 mevis.MLAB.logWarningHTML(
"Unable to write config file: %s.\n%s" % (filename, e))
540 Searches for the executable in the basePath and all levels of the provided
541 subPath in a 'deepest first' manner
543 path = os.path.normpath(subPath)
544 pathComponents = path.split(os.sep)
545 pathComponents.append(executableName)
547 executablePath =
None
548 while pathComponents:
549 candidate = os.path.join(basePath, *pathComponents)
550 if os.path.isfile(candidate):
551 executablePath = candidate
554 pathComponents.pop(0)
556 if executablePath
is None:
559 return os.path.normpath(candidate)
565 mlabExecutableName =
"MeVisLab_d" if self.
useMLABDebugVersionuseMLABDebugVersion()
else "MeVisLab"
567 mlabExecutableName +=
".exe"
569 command = [self.
findMLABExecutablefindMLABExecutable(expandedMLABPath, mlabExecutableName,
"Packages/MeVisLab/IDE/bin" if Utils.isWindows
else "bin")]
571 executablePath = self.
findMLABExecutablefindMLABExecutable(expandedMLABPath,
"MeVisLab",
"Contents/MacOS")
572 command = [executablePath,
"-debug" if self.
useMLABDebugVersionuseMLABDebugVersion()
else "-release"]
591 return mevisAvailable
and mevis.MLAB.isDebug()
610 + [
'-nomateconnection',
'-runmacro', macroName,
'-c', self.
__configFilePath__configFilePath])
651 showFailedFunctionsOnly,
660 showFailedFunctionsOnly,
665 return self.
__report__report.directory
673 return self.
__report__report.timestampTemplate
677 return self.
__report__report.appendTestCaseName
681 return self.
__report__report.appendTimestamp
685 return self.
__report__report.collapseFunctions
689 return self.
__report__report.showFailedFunctionsOnly
693 return self.
__report__report.hideInfoMessages
697 return self.
__report__report.hideSystemMessages
def fetchPythonCoverageSettings(self, coverageNode)
def isPythonCoverageEnabled(self)
def setMLABExecutablePath(self, executablePath)
def hideInfoMessages(self)
def __setDefaultValues(self)
def fetchCoverageSettings(self, xmlRoot)
def hideSystemMessages(self)
def getMaxTestTimeoutSeconds(self)
def showFailedFunctionsOnly(self)
def fetchMLABSettings(self, xmlRoot)
def isBullseyeCoverageEnabled(self)
def setTestCaseManagerOptions(self, shouldReloadPythonModulesWhenReloadingTestCases)
def fetchReportNodeSettings(self, xmlRoot)
def setGlobalPythonCoverageEnabled(self, value)
def appendTestCaseNameToReportName(self)
def getBoolean(node, default, attributeName)
def appendTimestampToReportName(self)
def getMLABEffectiveBinariesPath(self)
def getReportDirectory(self)
def fetchIPCSettings(self, xmlRoot)
def setMLABArguments(self, arguments)
def __init__(self, filePath=None, autoSave=True, isTestCaseManager=False)
__shouldReloadPythonModulesWhenReloadingTestCases
__useGlobalPythonCoverage
def fetchPythonCoverageExclusionExpressions(self, coverageNode)
def setBullseyeCoverageEnabled(self, value)
def getMLABArguments(self)
def getMLABCurrentBinariesPath(self)
def __load(self, filename)
def shouldReloadPythonModulesWhenReloadingTestCases(self)
def storeTestCaseManagerSettings(self, xmlRoot)
def setResultDir(self, directory)
def getIPCConnectionTimeout(self)
def fetchUseBullseyeCoverage(self, bullseyeNode)
def collapseFunctions(self)
def fetchUsePythonCoverage(self, pythonCoverageNode)
def save(self, filename=None)
Save the configuration variables set to the file with the given name.
def getMLABExecutableCommand(self)
def getCoverageExclusions(self)
def setMLABUseDebug(self, useDebug)
def getRestartInterval(self)
__MLABCurrentExecutablePath
def fetchTestCaseManagerSettings(self, xmlRoot)
def setMLABCompileMode(self, value)
def fetchUseGlobalPythonCoverage(self, pythonCoverageNode)
def setPythonCoverageEnabled(self, value)
def fetchBullseyeCoverageSettings(self, coverageNode)
def getMLABTestCenterCommand(self, macroName)
def getMLABCompileMode(self)
def getMLABBinariesPath(self)
def fetchReportSettings(self, xmlRoot)
__pythonCoverageExclusionExpressions
def getReportTimestampTemplate(self)
def getInteger(node, default, attributeName)
def findMLABExecutable(basePath, executableName, subPath)
def isGlobalPythonCoverageEnabled(self)
def setMLABUseCurrent(self, usecurrent)
def getDefaultTestTimeoutSeconds(self)
def getSlaveLogFilePath(self)
def setReportOptions(self, directory, name, timestampTemplate, appendTestCaseName, appendTimestamp, collapseFunctions, showFailedFunctionsOnly, hideInfoMessages, hideSystemMessages)
def getMLABUseCurrent(self)
def useMLABDebugVersion(self)
def getReportOptions(self)
def nodeHasValidText(node)
__defaultTestTimeoutSeconds
def getConfigFilePath(self)
maxErrorMessagesPerTestFunction
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)
maxInfoMessagesPerTestFunction
def verifyConfiguration(cfgFile)
def getConfigFilePath(isTestCaseManager=False)