コード例 #1
0
ファイル: failure.py プロジェクト: Yellowen/Vakhshour
    def printTraceback(self,
                       file=None,
                       elideFrameworkCode=0, detail='default'):
        """
        Emulate Python's standard error reporting mechanism.
        """
        if file is None:
            #file = log.logerr
            file = sys.stderr  # changed by teratorn
        w = file.write

        # Preamble
        if detail == 'verbose':
            w('*--- Failure #%d%s---\n' %
               (self.count,
                (self.pickled and ' (pickled) ') or ' '))
        elif detail == 'brief':
            if self.frames:
                hasFrames = 'Traceback'
            else:
                hasFrames = 'Traceback (failure with no frames)'
            w("%s: %s: %s\n" % (hasFrames, self.type, self.value))
        else:
            w('Traceback (most recent call last):\n')

        # Frames, formatted in appropriate style
        if self.frames:
            if not elideFrameworkCode:
                format_frames(self.stack[-traceupLength:], w, detail)
                w("%s\n" % (EXCEPTION_CAUGHT_HERE,))
            format_frames(self.frames, w, detail)
        elif not detail == 'brief':
            # Yeah, it's not really a traceback, despite looking like one...
            w("Failure: ")

        # postamble, if any
        if not detail == 'brief':
            # Unfortunately, self.type will not be a class object if this
            # Failure was created implicitly from a string exception.
            # qual() doesn't make any sense on a string, so check for this
            # case here and just write out the string if that's what we
            # have.
            if isinstance(self.type, (str, unicode)):
                w(self.type + "\n")
            else:
                w("%s: %s\n" % (reflect.qual(self.type),
                                reflect.safe_str(self.value)))
        # chaining
        if isinstance(self.value, Failure):
            # TODO: indentation for chained failures?
            file.write(" (chained Failure)\n")
            self.value.printTraceback(file, elideFrameworkCode, detail)
        if detail == 'verbose':
            w('*--- End of Failure #%d ---\n' % self.count)
コード例 #2
0
ファイル: failure.py プロジェクト: g2minhle/Treemap
 def getErrorMessage(self):
     """Get a string of the exception which caused this Failure."""
     if isinstance(self.value, Failure):
         return self.value.getErrorMessage()
     return reflect.safe_str(self.value)