11 from builtins
import str
32 gStopOnFirstError =
False
44 def wrapper (*args, **kwds):
45 loggingMethod, message, type, depth, escapeHtml = func(*args, **kwds)
46 isInfoMessage = loggingMethod == mevis.MLAB.logHTML
47 if TestSupport.TestHelper.gLogInfoMessages
or not isInfoMessage:
48 message = str(message)
49 if TestHelper.getInstance().hasCallerStackFrame():
50 callerStackFrame = TestHelper.getInstance().getCallerStackFrame()
52 callerStackFrame = sys._getframe(1 + depth)
54 stackLine = traceback.extract_stack(callerStackFrame, 1)[0]
57 stackTrace = traceback.extract_stack(callerStackFrame)
59 for i, frame
in enumerate(stackTrace):
60 if frame[2] ==
'__callTestFunction':
61 stackTrace = stackTrace[i+1:]
63 stackLine = stackTrace[-1]
64 formattedStack =
''.join(traceback.format_list(stackTrace))
65 emitSpecialMessage(loggingMethod, stackLine[0], stackLine[1], type, message, escapeHtml, formattedStack)
67 if gStopOnFirstError
and gStopped:
68 raise CancelTestException
79 def info (message, stack=False, type='', depth=0):
81 mevis.MLAB.logError(
"The stack option is deprecated!")
82 return mevis.MLAB.logHTML, message, type, depth,
True
90 def infoHTML (message, type='', depth=0):
91 return mevis.MLAB.logHTML, message, type, depth,
False
100 def warning (message, stack=False, type='', depth=0):
102 mevis.MLAB.logError(
"The stack option is deprecated!")
103 return mevis.MLAB.logWarningHTML, message, type, depth,
True
112 return mevis.MLAB.logWarningHTML, message, type, depth,
False
122 def error (message, stack=False, type='', depth=0):
124 mevis.MLAB.logError(
"The stack option is deprecated!")
125 return mevis.MLAB.logErrorHTML, message, type, depth,
True
133 def errorHTML (message, type='', depth=0):
134 return mevis.MLAB.logErrorHTML, message, type, depth,
False
145 for filename
in files:
146 if not os.path.isfile(filename):
147 error(
"Image (%s) does not exist" % (filename), depth=1)
149 hash = Base_getHash(filename)
150 fileList.append(
"%s|%s" % (hash, filename))
151 if len(fileList) == 0:
152 error(
"No images given!", depth=1)
154 stackLine = traceback.extract_stack(sys._getframe(1), 1)[0]
166 for filename
in files:
167 if not os.path.isfile(filename):
168 error(
"File (%s) does not exist" % (filename), depth=1)
170 hash = Base_getHash(filename)
171 fileList.append(
"%s|%s" % (hash, filename))
172 if len(fileList) == 0:
173 error(
"No files given!", depth=1)
175 stackLine = traceback.extract_stack(sys._getframe(1), 1)[0]
188 def showDiff (description, fromLines, toLines, showOnlyContextOfDiff=False, numberOfContextLines=10):
189 if type(fromLines) != list:
190 with open(fromLines)
as fh:
191 fromLines = fh.readlines()
192 if type(toLines) != list:
193 with open(toLines)
as fh:
194 toLines = fh.readlines()
195 diff = Base_createHtmlDiff(fromLines, toLines, showOnlyContextOfDiff, numberOfContextLines)
196 baseDiffFileName = os.path.join(Base_getResultDirectory(),
"diff%s.html")
197 diffFileName = baseDiffFileName %
""
199 while os.path.exists(diffFileName):
201 diffFileName = baseDiffFileName % i
202 if not os.path.exists(Base_getResultDirectory()):
203 os.makedirs(Base_getResultDirectory())
204 with open(diffFileName,
"w")
as f:
218 for line
in traceback.extract_stack(sys._getframe(2+depth)):
219 content +=
"[[%s][%d][%s][%s]]" % (line[0], line[1], line[2], line[3])
220 return "##S[%s]" % (content)
223 from .Base
import getResultDirectory
as Base_getResultDirectory, createHtmlDiff
as Base_createHtmlDiff, getHash
as Base_getHash
def LoggingDecorator(func)
Internal decorator used for creating messages in compare methods.
def warningHTML(message, type='', depth=0)
Put a warning to the log while interpreting HTML.
def getStack(depth=0)
Get the current stack.
def error(message, stack=False, type='', depth=0)
Put an error to the log.
def warning(message, stack=False, type='', depth=0)
Put a warning to the log.
def info(message, stack=False, type='', depth=0)
Put an info message to the log.
def showFile(description, *files)
Put the FileShow command to the log.
def errorHTML(message, type='', depth=0)
Put an error to the log while interpreting HTML.
def showImage(description, *files)
Put the ImageShow command to the log.
def showDiff(description, fromLines, toLines, showOnlyContextOfDiff=False, numberOfContextLines=10)
Creates a HTML diff from the two files and puts the FileShow command to the log.
def infoHTML(message, type='', depth=0)
Put an info message to the log while interpreting HTML.
def emitSpecialCommand(file, line, type, fileList, message, escapeHtml=True)
def emitSpecialMessage(loggingMethod, file, line, type, message, escapeHtml=True, formattedStack='')