29gStopOnFirstError =
False
40def LoggingDecorator (func):
41 def wrapper (*args, **kwds):
42 loggingMethod, message, type, depth, escapeHtml = func(*args, **kwds)
43 isInfoMessage = loggingMethod == mevis.MLAB.logHTML
44 if TestSupport.TestHelper.gLogInfoMessages
or not isInfoMessage:
45 message = str(message)
46 if TestHelper.getInstance().hasCallerStackFrame():
47 callerStackFrame = TestHelper.getInstance().getCallerStackFrame()
49 callerStackFrame = sys._getframe(1 + depth)
51 stackLine = traceback.extract_stack(callerStackFrame, 1)[0]
54 stackTrace = traceback.extract_stack(callerStackFrame)
56 for i, frame
in enumerate(stackTrace):
57 if frame[2] ==
'__callTestFunction':
58 stackTrace = stackTrace[i+1:]
60 stackLine = stackTrace[-1]
61 formattedStack =
''.join(traceback.format_list(stackTrace))
62 emitSpecialMessage(loggingMethod, stackLine[0], stackLine[1], type, message, escapeHtml, formattedStack)
64 if gStopOnFirstError
and gStopped:
65 raise CancelTestException
76def info (message, stack=False, type='', depth=0):
78 mevis.MLAB.logError(
"The stack option is deprecated!")
79 return mevis.MLAB.logHTML, message, type, depth,
True
88 return mevis.MLAB.logHTML, message, type, depth,
False
97def warning (message, stack=False, type='', depth=0):
99 mevis.MLAB.logError(
"The stack option is deprecated!")
100 return mevis.MLAB.logWarningHTML, message, type, depth,
True
109 return mevis.MLAB.logWarningHTML, message, type, depth,
False
119def error (message, stack=False, type='', depth=0):
121 mevis.MLAB.logError(
"The stack option is deprecated!")
122 return mevis.MLAB.logErrorHTML, message, type, depth,
True
131 return mevis.MLAB.logErrorHTML, message, type, depth,
False
142 for filename
in files:
143 if not os.path.isfile(filename):
144 error(
"Image (%s) does not exist" % (filename), depth=1)
146 hash = Base_getHash(filename)
147 fileList.append(
"%s|%s" % (hash, filename))
148 if len(fileList) == 0:
149 error(
"No images given!", depth=1)
151 stackLine = traceback.extract_stack(sys._getframe(1), 1)[0]
152 emitSpecialCommand(stackLine[0], stackLine[1],
"ImageShow", fileList, description)
163 for filename
in files:
164 if not os.path.isfile(filename):
165 error(
"File (%s) does not exist" % (filename), depth=1)
167 hash = Base_getHash(filename)
168 fileList.append(
"%s|%s" % (hash, filename))
169 if len(fileList) == 0:
170 error(
"No files given!", depth=1)
172 stackLine = traceback.extract_stack(sys._getframe(1), 1)[0]
173 emitSpecialCommand(stackLine[0], stackLine[1],
"FileShow", fileList, description)
185def showDiff (description, fromLines, toLines, showOnlyContextOfDiff=False, numberOfContextLines=10):
186 if type(fromLines) != list:
187 with open(fromLines)
as fh:
188 fromLines = fh.readlines()
189 if type(toLines) != list:
190 with open(toLines)
as fh:
191 toLines = fh.readlines()
192 diff = Base_createHtmlDiff(fromLines, toLines, showOnlyContextOfDiff, numberOfContextLines)
193 baseDiffFileName = os.path.join(Base_getResultDirectory(),
"diff%s.html")
194 diffFileName = baseDiffFileName %
""
196 while os.path.exists(diffFileName):
198 diffFileName = baseDiffFileName % i
199 if not os.path.exists(Base_getResultDirectory()):
200 os.makedirs(Base_getResultDirectory())
201 with open(diffFileName,
"w")
as f:
215 for line
in traceback.extract_stack(sys._getframe(2+depth)):
216 content +=
"[[%s][%d][%s][%s]]" % (line[0], line[1], line[2], line[3])
217 return "##S[%s]" % (content)
220from .Base
import getResultDirectory
as Base_getResultDirectory, createHtmlDiff
as Base_createHtmlDiff, getHash
as Base_getHash
getStack(depth=0)
Get the current stack.
warningHTML(message, type='', depth=0)
Put a warning to the log while interpreting HTML.
error(message, stack=False, type='', depth=0)
Put an error to the log.
showFile(description, *files)
Put the FileShow command to the log.
errorHTML(message, type='', depth=0)
Put an error to the log while interpreting HTML.
showImage(description, *files)
Put the ImageShow command to the log.
showDiff(description, fromLines, toLines, showOnlyContextOfDiff=False, numberOfContextLines=10)
Creates a HTML diff from the two files and puts the FileShow command to the log.
infoHTML(message, type='', depth=0)
Put an info message to the log while interpreting HTML.
warning(message, stack=False, type='', depth=0)
Put a warning to the log.
info(message, stack=False, type='', depth=0)
Put an info message to the log.