예제 #1
0
 def addCaptureToErr(self, ev, output):
     if isinstance(ev, BaseException):
         if hasattr(ev, '__unicode__'):
             # 2.6+
             ev = unicode(ev)
         else:
             # 2.5-
             if not hasattr(ev, 'message'):
                 # 2.4
                 msg = len(ev.args) and ev.args[0] or ''
             else:
                 msg = ev.message
             if (isinstance(msg, basestring)
                     and not isinstance(msg, unicode)):
                 msg = msg.decode('utf8', 'replace')
             ev = u'%s: %s' % (ev.__class__.__name__, msg)
     elif not isinstance(ev, basestring):
         ev = repr(ev)
     if not isinstance(output, unicode):
         output = output.decode('utf8', 'replace')
     return u'\n'.join([
         ev,
         ln(u'>> begin captured stdout <<'), output,
         ln(u'>> end captured stdout <<')
     ])
예제 #2
0
 def addCaptureToErr(self, ev, output):
     if isinstance(ev, BaseException):
         if hasattr(ev, '__unicode__'):
             # 2.6+
             try:
                 ev = unicode(ev)
             except UnicodeDecodeError:
                 # We need a unicode string... take our best shot at getting,
                 # since we don't know what the original encoding is in.
                 ev = str(ev).decode('utf8', 'replace')
         else:
             # 2.5-
             if not hasattr(ev, 'message'):
                 # 2.4
                 msg = len(ev.args) and ev.args[0] or ''
             else:
                 msg = ev.message
             if (isinstance(msg, basestring)
                     and not isinstance(msg, unicode)):
                 msg = msg.decode('utf8', 'replace')
             ev = u'%s: %s' % (ev.__class__.__name__, msg)
     elif not isinstance(ev, basestring):
         ev = repr(ev)
     if not isinstance(output, unicode):
         output = output.decode('utf8', 'replace')
     return u'\n'.join([
         ev,
         ln(u'>> begin captured stdout <<'), output,
         ln(u'>> end captured stdout <<')
     ])
예제 #3
0
파일: snot.py 프로젝트: pombredanne/snot
 def addCaptureToErr(self, ev, output):
     """Override to highlight captured output.
     """
     return '\n'.join([ str(ev) 
                      , ln('>> begin captured stdout <<')
                      , '\033[1;36m' + output + '\033[0m'
                      , ln('>> end captured stdout <<')
                       ])
예제 #4
0
 def addCaptureToErr(self, ev, output):
     ev = exc_to_unicode(ev)
     output = force_unicode(output)
     return u'\n'.join([
         ev,
         ln(u'>> begin captured stderr <<'), output,
         ln(u'>> end captured stderr <<')
     ])
예제 #5
0
 def addCaptureToErr(self, ev):
     lines = []
     for (filename, description) in self._filenames_to_description.iteritems():
         lines.append(ln('>> begin ''{0}'' <<'.format(description)))
         with open(filename, 'r') as fp:
             lines += [safe_str(fp.read())]
         lines.append(ln('>> end ''{0}'' <<'.format(description)))
     lines.append(safe_str(ev))
     return '\n'.join(lines)
예제 #6
0
 def addCaptureToErr(self, ev, output):
     ev = exc_to_unicode(ev)
     output = force_unicode(output)      
     return u'\n'.join([
         ev,
         ln(u'>> begin captured stderr <<'),
         output,
         ln(u'>> end captured stderr <<')
     ])
예제 #7
0
 def _dump_logs(self, ev, test):
     ret = ev
     if isinstance(test.test, functional.FunctionalTest):
         dump = test.test.dump_logs()
         if dump:
             ret = '\n'.join([safe_str(ev),
                             ln('>> begin captured glance logging <<')] +
                             [dump] +
                             [ln('>> end captured glance logging <<')])
     return ret
예제 #8
0
파일: capture.py 프로젝트: sxt1111jy/nose
 def addCaptureToErr(self, ev, output, output_exc_info=None):
     # If given, output_exc_info should be a 3-tuple from sys.exc_info(),
     # from an exception raised while trying to get the captured output.
     ev = exc_to_unicode(ev)
     output = force_unicode(output)
     error_text = [ev, ln(u'>> begin captured stdout <<'),
                   output, ln(u'>> end captured stdout <<')]
     if output_exc_info:
         error_text.extend([u'OUTPUT ERROR: Could not get captured output.',
                            # <https://github.com/python/cpython/blob/2.7/Lib/StringIO.py#L258>
                            # <https://github.com/nose-devs/nose/issues/816>
                            u"The test might've printed both 'unicode' strings and non-ASCII 8-bit 'str' strings.",
                            ln(u'>> begin captured stdout exception traceback <<'),
                            u''.join(traceback.format_exception(*output_exc_info)),
                            ln(u'>> end captured stdout exception traceback <<')])
     return u'\n'.join(error_text)
예제 #9
0
    def formatError(self, test, err):
        """List the open files when a test errors.
        """
        open_files = _gather_open_files()

        if not open_files:
            return err

        ec, ev, tb = err
        handle_couter = collections.Counter(open_files)
        new_ev = u'\n'.join(
            [ev, ln(u'>>> There {} open file handlers for {} files: <<<'
                  .format(len(open_files), len(handle_couter)))]
            + [ln(u'* ({}) {}'.format(count, path))
               for path, count in handle_couter.items()]
            + [ln(u'>>> End of the open file list. <<<')]
        )
        return (ec, new_ev, tb)
예제 #10
0
파일: capture.py 프로젝트: rata/nose
 def addCaptureToErr(self, ev, output):
     if isinstance(ev, Exception):
         if hasattr(ev, "__unicode__"):
             # 2.6+
             ev = unicode(ev)
         else:
             # 2.5-
             if not hasattr(ev, "message"):
                 # 2.4
                 msg = len(ev.args) and ev.args[0] or ""
             else:
                 msg = ev.message
             if isinstance(msg, basestring) and not isinstance(msg, unicode):
                 msg = msg.decode("utf8", "replace")
             ev = u"%s: %s" % (ev.__class__.__name__, msg)
     if not isinstance(output, unicode):
         output = output.decode("utf8", "replace")
     return u"\n".join([ev, ln(u">> begin captured stdout <<"), output, ln(u">> end captured stdout <<")])
예제 #11
0
파일: capture.py 프로젝트: AndryulE/kitsune
 def addCaptureToErr(self, ev, output):
     if isinstance(ev, Exception):
         if hasattr(ev, '__unicode__'):
             # 2.6+
             ev = unicode(ev)
         else:
             # 2.5-
             if not hasattr(ev, 'message'):
                 # 2.4
                 msg = len(ev.args) and ev.args[0] or ''
             else:
                 msg = ev.message
             if not isinstance(msg, unicode):
                 msg = msg.decode('utf8', 'replace')
             ev = u'%s: %s' % (ev.__class__.__name__, msg)
     if not isinstance(output, unicode):
         output = output.decode('utf8', 'replace')
     return u'\n'.join([ev, ln(u'>> begin captured stdout <<'),
                        output, ln(u'>> end captured stdout <<')])
예제 #12
0
 def addCaptureToErr(self, ev, records):
     return '\n'.join([safe_str(ev), ln('>> begin captured logging <<')] + \
                       records + \
                       [ln('>> end captured logging <<')])
예제 #13
0
 def addOutputToErr(self, ev, output):
     if isinstance(ev, Exception):
         ev = unicode(ev)
     return u'\n'.join([ev, u'', ln(u'>> rerun the test <<'), output])
예제 #14
0
 def addCaptureToErr(self, ev, output):
     return '\n'.join([str(ev) , ln('>> begin captured stderr <<'),
                       output, ln('>> end captured stderr <<')])
예제 #15
0
 def addCaptureToErr(self, ev, records):
     return '\n'.join([safe_str(ev), ln('>> begin captured logging <<')] + \
                       records + \
                       [ln('>> end captured logging <<')])
예제 #16
0
 def _get_captured_stdout(self):
     output = force_unicode(self._buf)
     return u'\n'.join([
         ln(u'>> begin captured stdout <<'), output,
         ln(u'>> end captured stdout <<')
     ])
예제 #17
0
 def addCaptureToErr(self, ev, output):
     return '\n'.join([
         str(ev),
         ln('>> begin captured stderr <<'), output,
         ln('>> end captured stderr <<')
     ])
예제 #18
0
 def addOutputToErr(self, ev, output):
     if isinstance(ev, Exception):
         ev = unicode(ev)
     return u"\n".join([ev, u"", ln(u">> rerun the test <<"), output])
예제 #19
0
파일: capture.py 프로젝트: antlong/nose
 def addCaptureToErr(self, ev, output):
     return "\n".join([str(ev), ln(">> begin captured stdout <<"), output, ln(">> end captured stdout <<")])
예제 #20
0
 def _get_captured_stdout(self):
     output = force_unicode(self._buf)
     return u'\n'.join([ln(u'>> begin captured stdout <<'),
                        output, ln(u'>> end captured stdout <<')])
예제 #21
0
	def addOutputToErr(self, ev, output):
		if isinstance(ev, Exception):
			ev = unicode(ev)
		return u'\n'.join([ev, u'', ln(u'>> rerun the test <<'), output])
예제 #22
0
 def addCaptureToErr(self, ev, records):
     return "\n".join(
         [safe_str(ev), ln(">> begin captured logging <<")] + records + [ln(">> end captured logging <<")]
     )
예제 #23
0
 def addOutputToErr(self, ev, output):
     if isinstance(ev, Exception):
         ev = str(ev)
     return '\n'.join([ev, '', ln('>> rerun the test <<'), output])