def testFailureXcpt(sDetails = ''): """ Reports a failure with exception. We count these calls and testDone will use them to report PASSED or FAILED. Returns False so that a return False line can be saved. """ # Extract exception info. try: oType, oValue, oTraceback = sys.exc_info(); except: oType = oValue, oTraceback = None; if oType is not None: sCaller = utils.getCallerName(oTraceback.tb_frame); sXcpt = ' '.join(traceback.format_exception_only(oType, oValue)); else: sCaller = utils.getCallerName(); sXcpt = 'No exception at %s' % (sCaller,); # Use testFailure to do the work. g_oLock.acquire(); if sDetails == '': g_oReporter.testFailure('Exception: %s' % (sXcpt,), sCaller); else: g_oReporter.testFailure('%s: %s' % (sDetails, sXcpt), sCaller); g_oLock.release(); return False;
def testFailureXcpt(sDetails=''): """ Reports a failure with exception. We count these calls and testDone will use them to report PASSED or FAILED. Returns False so that a return False line can be saved. """ # Extract exception info. try: oType, oValue, oTraceback = sys.exc_info() except: oType = oValue, oTraceback = None if oType is not None: sCaller = utils.getCallerName(oTraceback.tb_frame) sXcpt = ' '.join(traceback.format_exception_only(oType, oValue)) else: sCaller = utils.getCallerName() sXcpt = 'No exception at %s' % (sCaller, ) # Use testFailure to do the work. g_oLock.acquire() if sDetails == '': g_oReporter.testFailure('Exception: %s' % (sXcpt, ), sCaller) else: g_oReporter.testFailure('%s: %s' % (sDetails, sXcpt), sCaller) g_oLock.release() return False
def logXcptWorker(iLevel, fIncErrors, sPrefix="", sText=None, cFrames=1): """ Log an exception, optionally with a preceeding message and more than one call frame. """ g_oLock.acquire(); if fIncErrors: g_oReporter.testIncErrors(); ## @todo skip all this if iLevel is too high! # Try get exception info. sTsPrf = utils.getTimePrefix(); try: oType, oValue, oTraceback = sys.exc_info(); except: oType = oValue = oTraceback = None; if oType is not None: # Try format the info try: rc = 0; sCaller = utils.getCallerName(oTraceback.tb_frame); if sText is not None: rc = g_oReporter.log(iLevel, "%s%s" % (sPrefix, sText), sCaller, sTsPrf); asInfo = []; try: asInfo = asInfo + traceback.format_exception_only(oType, oValue); if cFrames is not None and cFrames <= 1: asInfo = asInfo + traceback.format_tb(oTraceback, 1); else: asInfo.append('Traceback:') asInfo = asInfo + traceback.format_tb(oTraceback, cFrames); asInfo.append('Stack:') asInfo = asInfo + traceback.format_stack(oTraceback.tb_frame.f_back, cFrames); except: g_oReporter.log(0, 'internal-error: Hit exception #2! %s' % (traceback.format_exc()), sCaller, sTsPrf); if len(asInfo) > 0: # Do the logging. for sItem in asInfo: asLines = sItem.splitlines(); for sLine in asLines: rc = g_oReporter.log(iLevel, '%s%s' % (sPrefix, sLine), sCaller, sTsPrf); else: g_oReporter.log(iLevel, 'No exception info...', sCaller, sTsPrf); rc = -3; except: g_oReporter.log(0, 'internal-error: Hit exception! %s' % (traceback.format_exc()), None, sTsPrf); rc = -2; else: g_oReporter.log(0, 'internal-error: No exception! %s' % (utils.getCallerName(iFrame=3)), utils.getCallerName(iFrame=3), sTsPrf); rc = -1; g_oLock.release(); return rc;
def _logXcptWorker(fnLogger, sPrefix = '', sText = None, cFrames = 1, fnLogger1 = log): """ Log an exception, optionally with a preceeding message and more than one call frame. """ ## @todo skip all this if iLevel is too high! # Try get exception info. sTsPrf = utils.getTimePrefix(); try: oType, oValue, oTraceback = sys.exc_info(); except: oType = oValue = oTraceback = None; if oType is not None: # Try format the info try: rc = 0; sCaller = utils.getCallerName(oTraceback.tb_frame); if sText is not None: rc = fnLogger('%s%s' % (sPrefix, sText), sCaller, sTsPrf); asInfo = []; try: asInfo = asInfo + traceback.format_exception_only(oType, oValue); if cFrames is not None and cFrames <= 1: asInfo = asInfo + traceback.format_tb(oTraceback, 1); else: asInfo.append('Traceback:') asInfo = asInfo + traceback.format_tb(oTraceback, cFrames); asInfo.append('Stack:') asInfo = asInfo + traceback.format_stack(oTraceback.tb_frame.f_back, cFrames); except: fnLogger1('internal-error: Hit exception #2! %s' % (traceback.format_exc()), sCaller, sTsPrf); if len(asInfo) > 0: # Do the logging. for sItem in asInfo: asLines = sItem.splitlines(); for sLine in asLines: rc = fnLogger('%s%s' % (sPrefix, sLine), sCaller, sTsPrf); else: fnLogger('No exception info...', sCaller, sTsPrf); rc = -3; except: fnLogger1('internal-error: Hit exception! %s' % (traceback.format_exc()), None, sTsPrf); rc = -2; else: fnLogger1('internal-error: No exception! %s' % (utils.getCallerName(iFrame=3)), utils.getCallerName(iFrame=3), sTsPrf); rc = -1; return rc;
def logAllStacks(cFrames=None): """ Logs the stacks of all python threads. """ sTsPrf = utils.getTimePrefix() sCaller = utils.getCallerName() g_oLock.acquire() cThread = 0 for idThread, oStack in sys._current_frames().items(): # >=2.5, a bit ugly - pylint: disable=W0212 try: if cThread > 0: g_oReporter.log(1, '', sCaller, sTsPrf) g_oReporter.log(1, 'Thread %s (%#x)' % (idThread, idThread), sCaller, sTsPrf) try: asInfo = traceback.format_stack(oStack, cFrames) except: g_oReporter.log(1, ' Stack formatting failed w/ exception', sCaller, sTsPrf) else: for sInfo in asInfo: asLines = sInfo.splitlines() for sLine in asLines: g_oReporter.log(1, sLine, sCaller, sTsPrf) except: pass cThread += 1 g_oLock.release() return None
def addLogFile(sFilename, sKind, sDescription='', sAltName=None): """ Adds the specified log file to the report if the file exists. The sDescription is a free form description of the log file. The sKind parameter is for adding some machine parsable hint what kind of log file this really is. Returns True on success, False on failure (no ENOENT errors are logged). """ sTsPrf = utils.getTimePrefix() sCaller = utils.getCallerName() fRc = False if sAltName is None: sAltName = sFilename try: oSrcFile = utils.openNoInherit(sFilename, 'rb') except IOError, oXcpt: if oXcpt.errno != errno.ENOENT: logXcpt('addLogFile(%s,%s,%s)' % (sFilename, sDescription, sKind)) else: logXcpt('addLogFile(%s,%s,%s) IOError' % (sFilename, sDescription, sKind))
def logAllStacks(cFrames = None): """ Logs the stacks of all python threads. """ sTsPrf = utils.getTimePrefix(); sCaller = utils.getCallerName(); g_oLock.acquire(); cThread = 0; for idThread, oStack in sys._current_frames().items(): # >=2.5, a bit ugly - pylint: disable=W0212 try: if cThread > 0: g_oReporter.log(1, '', sCaller, sTsPrf); g_oReporter.log(1, 'Thread %s (%#x)' % (idThread, idThread), sCaller, sTsPrf); try: asInfo = traceback.format_stack(oStack, cFrames); except: g_oReporter.log(1, ' Stack formatting failed w/ exception', sCaller, sTsPrf); else: for sInfo in asInfo: asLines = sInfo.splitlines(); for sLine in asLines: g_oReporter.log(1, sLine, sCaller, sTsPrf); except: pass; cThread += 1; g_oLock.release(); return None;
def testStart(sName): """ Starts a new test (pushes it). """ g_oLock.acquire() rc = g_oReporter.testStart(sName, utils.getCallerName()) g_oLock.release() return rc
def execute(self, sOperation, aoArgs = None): """ Execute a query or command. Mostly a wrapper around the psycopg2 cursor method with the same name, but collect data for traceback. """ return self.executeInternal(self._oCursor, sOperation, aoArgs, utils.getCallerName());
def testValue(sName, sValue, sUnit): """ Reports a benchmark value or something simiarlly useful. """ g_oLock.acquire(); rc = g_oReporter.testValue(sName, str(sValue), sUnit, utils.getCallerName()); g_oLock.release(); return rc;
def callProc(self, sProcedure, aoArgs = None): """ Call a stored procedure. Mostly a wrapper around the psycopg2 cursor method 'callproc', but collect data for traceback. """ return self.callProcInternal(self._oCursor, sProcedure, aoArgs, utils.getCallerName());
def testStart(sName): """ Starts a new test (pushes it). """ g_oLock.acquire(); rc = g_oReporter.testStart(sName, utils.getCallerName()); g_oLock.release(); return rc;
def rollback(self): """ Wrapper around Psycopg2.connection.rollback.""" nsStart = utils.timestampNano(); oRc = self._oConn.rollback(); cNsElapsed = utils.timestampNano() - nsStart; self._aoTraceBack.append([nsStart, 'ROLLBACK', cNsElapsed, 0, utils.getCallerName(), None]); self._endedTransaction(); return oRc;
def begin(self): """ Currently just for marking where a transaction starts in the code. """ assert self._oConn is not None; assert self.isAutoCommitting() is False; self._aoTraceBack.append([utils.timestampNano(), 'START TRANSACTION', 0, 0, utils.getCallerName(), None]); self._startedTransaction(); return True;
def testValue(sName, sValue, sUnit): """ Reports a benchmark value or something simiarlly useful. """ g_oLock.acquire() rc = g_oReporter.testValue(sName, str(sValue), sUnit, utils.getCallerName()) g_oLock.release() return rc
def maybeCommit(self, fCommit): """ Commits if fCommit is True. Returns True if committed, False if not. """ if fCommit is True: self.commit(utils.getCallerName()) return True return False
def maybeCommit(self, fCommit): """ Commits if fCommit is True. Returns True if committed, False if not. """ if fCommit is True: self.commit(utils.getCallerName()); return True; return False;
def log2(sText): """Log level 2: Writes the specfied text to the log.""" g_oLock.acquire(); try: rc = g_oReporter.log(2, sText, utils.getCallerName(), utils.getTimePrefix()); except: rc = -1; g_oLock.release(); return rc;
def testDone(fSkipped = False): """ Completes the current test (pops it), logging PASSED / FAILURE. Returns a tuple with the name of the test and its error count. """ g_oLock.acquire(); rc = g_oReporter.testDone(fSkipped, utils.getCallerName()); g_oLock.release(); return rc;
def testDone(fSkipped=False): """ Completes the current test (pops it), logging PASSED / FAILURE. Returns a tuple with the name of the test and its error count. """ g_oLock.acquire() rc = g_oReporter.testDone(fSkipped, utils.getCallerName()) g_oLock.release() return rc
def log2(sText): """Log level 2: Writes the specfied text to the log.""" g_oLock.acquire() try: rc = g_oReporter.log(2, sText, utils.getCallerName(), utils.getTimePrefix()) except: rc = -1 g_oLock.release() return rc
def testFailure(sDetails): """ Reports a failure. We count these calls and testDone will use them to report PASSED or FAILED. Returns False so that a return False line can be saved. """ g_oLock.acquire() g_oReporter.testFailure(sDetails, utils.getCallerName()) g_oLock.release() return False
def testCleanup(): """ Closes all open tests with a generic error condition. Returns True if no open tests, False if something had to be closed with failure. """ g_oLock.acquire(); fRc = g_oReporter.testCleanup(utils.getCallerName()); g_oReporter.xmlFlush(fRetry = False, fForce = True); g_oLock.release(); return fRc;
def testFailure(sDetails): """ Reports a failure. We count these calls and testDone will use them to report PASSED or FAILED. Returns False so that a return False line can be saved. """ g_oLock.acquire(); g_oReporter.testFailure(sDetails, utils.getCallerName()); g_oLock.release(); return False;
def testCleanup(): """ Closes all open tests with a generic error condition. Returns True if no open tests, False if something had to be closed with failure. """ g_oLock.acquire() fRc = g_oReporter.testCleanup(utils.getCallerName()) g_oReporter.xmlFlush(fRetry=False, fForce=True) g_oLock.release() return fRc
def commit(self, sCallerName = None): """ Wrapper around Psycopg2.connection.commit.""" assert self._fTransaction is True; nsStart = utils.timestampNano(); oRc = self._oConn.commit(); cNsElapsed = utils.timestampNano() - nsStart; if sCallerName is None: sCallerName = utils.getCallerName(); self._aoTraceBack.append([nsStart, 'COMMIT', cNsElapsed, 0, sCallerName, None]); self._endedTransaction(); return oRc;
def fatal(sText): """ Writes a fatal error to the log. This will add an error to the current test. Always returns False for the convenience of methods returning boolean success indicators. """ g_oLock.acquire(); g_oReporter.testIncErrors(); try: g_oReporter.log(0, 'fatal error: %s' % (sText), utils.getCallerName(), utils.getTimePrefix()); except: pass g_oLock.release(); return False;
def errorTimeout(sText): """ Flags the current test as having timed out and writes the specified message to the log. This will add an error to the current test. Always returns False for the convenience of methods returning boolean success indicators. """ g_oLock.acquire(); g_oReporter.testSetTimedOut(); try: g_oReporter.log(0, 'timeout-error: %s' % (sText), utils.getCallerName(), utils.getTimePrefix()); except: pass; g_oLock.release(); return False;
def write(self, sText): """file.write""" if isinstance(sText, array.array): try: sText = sText.tostring(); except: pass; g_oLock.acquire(); try: sTsPrf = utils.getTimePrefix(); sCaller = utils.getCallerName(); asLines = sText.splitlines(); for sLine in asLines: g_oReporter.log(0, '%s: %s' % (self.sPrefix, sLine), sCaller, sTsPrf); except: traceback.print_exc(); g_oLock.release(); return None;
def errorTimeout(sText): """ Flags the current test as having timed out and writes the specified message to the log. This will add an error to the current test. Always returns False for the convenience of methods returning boolean success indicators. """ g_oLock.acquire() g_oReporter.testSetTimedOut() try: g_oReporter.log(0, 'timeout-error: %s' % (sText), utils.getCallerName(), utils.getTimePrefix()) except: pass g_oLock.release() return False
def fatal(sText): """ Writes a fatal error to the log. This will add an error to the current test. Always returns False for the convenience of methods returning boolean success indicators. """ g_oLock.acquire() g_oReporter.testIncErrors() try: g_oReporter.log(0, 'fatal error: %s' % (sText), utils.getCallerName(), utils.getTimePrefix()) except: pass g_oLock.release() return False
def write(self, sText): """file.write""" if isinstance(sText, array.array): try: sText = sText.tostring() except: pass g_oLock.acquire() try: sTsPrf = utils.getTimePrefix() sCaller = utils.getCallerName() asLines = sText.splitlines() for sLine in asLines: g_oReporter.log(0, '%s: %s' % (self.sPrefix, sLine), sCaller, sTsPrf) except: traceback.print_exc() g_oLock.release() return None
def write(self, sText): """file.write""" # lazy start. if self.fStarted is not True: try: g_oReporter.subXmlStart(self); except: traceback.print_exc(); self.fStarted = True; if isinstance(sText, array.array): try: sText = sText.tostring(); except: pass; try: g_oReporter.subXmlWrite(self, sText, utils.getCallerName()); except: traceback.print_exc(); return None;
def write(self, sText): """file.write""" # lazy start. if self.fStarted is not True: try: g_oReporter.subXmlStart(self) except: traceback.print_exc() self.fStarted = True if isinstance(sText, array.array): try: sText = sText.tostring() except: pass try: g_oReporter.subXmlWrite(self, sText, utils.getCallerName()) except: traceback.print_exc() return None
def addLogFile(sFilename, sKind, sDescription = '', sAltName = None): """ Adds the specified log file to the report if the file exists. The sDescription is a free form description of the log file. The sKind parameter is for adding some machine parsable hint what kind of log file this really is. Returns True on success, False on failure (no ENOENT errors are logged). """ sTsPrf = utils.getTimePrefix(); sCaller = utils.getCallerName(); fRc = False; if sAltName is None: sAltName = sFilename; try: oSrcFile = utils.openNoInherit(sFilename, 'rb'); except IOError, oXcpt: if oXcpt.errno != errno.ENOENT: logXcpt('addLogFile(%s,%s,%s)' % (sFilename, sDescription, sKind)); else: logXcpt('addLogFile(%s,%s,%s) IOError' % (sFilename, sDescription, sKind));
def insertList(self, sInsertSql, aoList, fnEntryFmt): """ Optimizes the insertion of a list of values. """ return self.insertListInternal(self._oCursor, sInsertSql, aoList, fnEntryFmt, utils.getCallerName());
def logXcptWorker(iLevel, fIncErrors, sPrefix="", sText=None, cFrames=1): """ Log an exception, optionally with a preceeding message and more than one call frame. """ g_oLock.acquire() if fIncErrors: g_oReporter.testIncErrors() ## @todo skip all this if iLevel is too high! # Try get exception info. sTsPrf = utils.getTimePrefix() try: oType, oValue, oTraceback = sys.exc_info() except: oType = oValue = oTraceback = None if oType is not None: # Try format the info try: rc = 0 sCaller = utils.getCallerName(oTraceback.tb_frame) if sText is not None: rc = g_oReporter.log(iLevel, "%s%s" % (sPrefix, sText), sCaller, sTsPrf) asInfo = [] try: asInfo = asInfo + traceback.format_exception_only( oType, oValue) if cFrames is not None and cFrames <= 1: asInfo = asInfo + traceback.format_tb(oTraceback, 1) else: asInfo.append('Traceback:') asInfo = asInfo + traceback.format_tb(oTraceback, cFrames) asInfo.append('Stack:') asInfo = asInfo + traceback.format_stack( oTraceback.tb_frame.f_back, cFrames) except: g_oReporter.log( 0, 'internal-error: Hit exception #2! %s' % (traceback.format_exc()), sCaller, sTsPrf) if len(asInfo) > 0: # Do the logging. for sItem in asInfo: asLines = sItem.splitlines() for sLine in asLines: rc = g_oReporter.log(iLevel, '%s%s' % (sPrefix, sLine), sCaller, sTsPrf) else: g_oReporter.log(iLevel, 'No exception info...', sCaller, sTsPrf) rc = -3 except: g_oReporter.log( 0, 'internal-error: Hit exception! %s' % (traceback.format_exc()), None, sTsPrf) rc = -2 else: g_oReporter.log( 0, 'internal-error: No exception! %s' % (utils.getCallerName(iFrame=3)), utils.getCallerName(iFrame=3), sTsPrf) rc = -1 g_oLock.release() return rc
def callProc(self, sProcedure, aoArgs=None): """ See TMDatabaseConnection.callProc()""" return self._oDb.callProcInternal(self._oCursor, sProcedure, aoArgs, utils.getCallerName())
def execute(self, sOperation, aoArgs=None): """ See TMDatabaseConnection.execute()""" return self._oDb.executeInternal(self._oCursor, sOperation, aoArgs, utils.getCallerName())
def insertList(self, sInsertSql, aoList, fnEntryFmt): """ See TMDatabaseConnection.insertList. """ return self._oDb.insertListInternal(self._oCursor, sInsertSql, aoList, fnEntryFmt, utils.getCallerName());
def callProc(self, sProcedure, aoArgs = None): """ See TMDatabaseConnection.callProc()""" return self._oDb.callProcInternal(self._oCursor, sProcedure, aoArgs, utils.getCallerName());
def execute(self, sOperation, aoArgs = None): """ See TMDatabaseConnection.execute()""" return self._oDb.executeInternal(self._oCursor, sOperation, aoArgs, utils.getCallerName());
def insertList(self, sInsertSql, aoList, fnEntryFmt): """ Optimizes the insertion of a list of values. """ return self.insertListInternal(self._oCursor, sInsertSql, aoList, fnEntryFmt, utils.getCallerName())
def insertList(self, sInsertSql, aoList, fnEntryFmt): """ See TMDatabaseConnection.insertList. """ return self._oDb.insertListInternal(self._oCursor, sInsertSql, aoList, fnEntryFmt, utils.getCallerName())