Пример #1
0
 def outcomeDetail(self, event):
     """Append captured log messages to ``event.extraDetail``"""
     logs = event.outcomeEvent.metadata.get('logs', None)
     if logs:
         event.extraDetail.append(ln('>> begin captured logging <<'))
         event.extraDetail.extend(logs)
         event.extraDetail.append(ln('>> end captured logging <<'))
Пример #2
0
 def _get_stream_unicode_save(self, stream, buffer):
     buf = ''
     stream_buffer_exc_info = None
     try:
         buf = buffer.getvalue()
     except (UnicodeError, UnicodeDecodeError):
         # python2's StringIO.StringIO [1] class has this warning:
         #
         #     The StringIO object can accept either Unicode or 8-bit strings,
         #     but mixing the two may take some care. If both are used, 8-bit
         #     strings that cannot be interpreted as 7-bit ASCII (that use the
         #     8th bit) will cause a UnicodeError to be raised when getvalue()
         #     is called.
         #
         # This exception handler is a protection against crashes
         # caused by this exception (such as [2] in the original
         # nose application). Capturing the exception info allows us
         # to display it back to the user.
         #
         # [1] <https://github.com/python/cpython/blob/2.7/Lib/StringIO.py#L258>
         # [2] <https://github.com/nose-devs/nose/issues/816>
         stream_buffer_exc_info = sys.exc_info()
     extraDetail = []
     extraDetail.append(
         ln('>> begin captured %s <<' % stream))
     extraDetail.append(buf)
     extraDetail.append(ln('>> end captured %s <<' % stream))
     if stream_buffer_exc_info:
         extraDetail.append('OUTPUT ERROR: Could not get captured %s output.' % stream)
         extraDetail.append("The test might've printed both 'unicode' strings and non-ASCII 8-bit 'str' strings.")
         extraDetail.append(ln('>> begin captured %s exception traceback <<' % stream))
         extraDetail.append(''.join(traceback.format_exception(*stream_buffer_exc_info)))
         extraDetail.append(ln('>> end captured %s exception traceback <<' % stream))
     return "\n".join(extraDetail)
Пример #3
0
 def outcomeDetail(self, event):
     """Add buffered output to event.extraDetail"""
     for stream in ('stdout', 'stderr'):
         if stream in event.outcomeEvent.metadata:
             buf = event.outcomeEvent.metadata[stream].getvalue()
             if not buf:
                 continue
             event.extraDetail.append(ln('>> begin captured %s <<' % stream))
             event.extraDetail.append(buf)
             event.extraDetail.append(ln('>> end captured %s <<' % stream))
Пример #4
0
    def beforeSummaryReport(self, event):
        """Output profiling results"""
        # write prof output to stream
        class Stream:
            def write(self, *msg):
                for m in msg:
                    event.stream.write(m)
                    event.stream.write(" ")
                event.stream.flush()

        stream = Stream()
        self.prof.close()
        prof_stats = stats.load(self.pfile)
        prof_stats.sort_stats(self.sort)
        event.stream.writeln(util.ln("Profiling results"))
        tmp = prof_stats.stream
        prof_stats.stream = stream
        try:
            if self.restrict:
                prof_stats.print_stats(*self.restrict)
            else:
                prof_stats.print_stats()
        finally:
            prof_stats.stream = tmp
        self.prof.close()
        event.stream.writeln("")

        if self.clean:
            if self.fileno:
                try:
                    os.close(self.fileno)
                except OSError:
                    pass
            try:
                os.unlink(self.pfile)
            except OSError:
                pass
Пример #5
0
    def beforeSummaryReport(self, event):
        """Output profiling results"""
        # write prof output to stream
        class Stream:

            def write(self, *msg):
                for m in msg:
                    event.stream.write(m)
                    event.stream.write(' ')
                event.stream.flush()
        stream = Stream()
        prof_stats = pstats.Stats(self.prof, stream=stream)
        prof_stats.sort_stats(self.sort)
        event.stream.writeln(util.ln("Profiling results"))
        if self.restrict:
            prof_stats.print_stats(*self.restrict)
        else:
            prof_stats.print_stats()

        if self.pfile:
            prof_stats.dump_stats(self.pfile)

        self.prof.disable()
        event.stream.writeln('')