Exemple #1
0
    def test_does_not_crash_with_mixed_unicode_and_nonascii_str(self):
        class Dummy:
            pass

        d = Dummy()
        c = Capture()
        c.start()
        printed_nonascii_str = force_unicode("test 日本").encode('utf-8')
        printed_unicode = force_unicode("Hello")
        print printed_nonascii_str
        print printed_unicode
        try:
            raise Exception("boom")
        except:
            err = sys.exc_info()
        formatted = c.formatError(d, err)
        _, fev, _ = formatted

        if py2:
            for string in [
                    force_unicode(printed_nonascii_str, encoding='utf-8'),
                    printed_unicode
            ]:
                assert string not in fev, "Output unexpectedly found in error message"
            assert d.capturedOutput == '', "capturedOutput unexpectedly non-empty"
            assert "OUTPUT ERROR" in fev
            assert "captured stdout exception traceback" in fev
            assert "UnicodeDecodeError" in fev
        else:
            for string in [repr(printed_nonascii_str), printed_unicode]:
                assert string in fev, "Output not found in error message"
                assert string in d.capturedOutput, "Output not attached to test"
Exemple #2
0
    def report(self, stream):
        """Writes an Xunit-formatted XML file
        The file includes a report of test errors and failures.
        """
        self.error_report_file = codecs.open(self.error_report_filename, 'w',
                                             self.encoding, 'replace')
        self.stats['encoding'] = self.encoding
        self.stats['total'] = (self.stats['errors'] + self.stats['failures']
                               + self.stats['passes'] + self.stats['skipped'])
        self.error_report_file.write(
            u'<?xml version="1.0" encoding="%(encoding)s"?>'
            u'<testsuite name="nosetests" tests="%(total)d" '
            u'errors="%(errors)d" failures="%(failures)d" '
            u'skip="%(skipped)d">' % self.stats)
        self.error_report_file.write(u''.join([
            force_unicode(error)
            for error
            in self.errorlist
        ]))

        self.error_report_file.write(u'</testsuite>')
        self.error_report_file.close()
        if self.config.verbosity > 1:
            stream.writeln("-" * 70)
            stream.writeln("XML: %s" % self.error_report_file.name)
        def report(self, stream):
            """Writes an Xunit-formatted XML file

            The file includes a report of test errors and failures.

            """
            efname = self.error_report_file_name.replace(
                "%IMPL%", str(self.impl))
            print "Report ---->>>>>> ", efname, " IMP ", self.impl, " CNT ", self.cnt, " Mode ", self.mode
            self.error_report_file = codecs.open(efname, self.mode,
                                                 self.encoding, 'replace')

            self.stats[
                'testsuite_name'] = self.xunit_testsuite_name + '-' + self.impl
            self.stats['total'] = (self.stats['errors'] +
                                   self.stats['failures'] +
                                   self.stats['passes'] +
                                   self.stats['skipped'])
            if self.cnt == 0:
                self.error_report_file.write(
                    u'<?xml version="1.0" encoding="%s"?>' % self.encoding)

            self.error_report_file.write(
                u'<testsuite name="%(testsuite_name)s" tests="%(total)d" '
                u'errors="%(errors)d" failures="%(failures)d" '
                u'skip="%(skipped)d">' % self.stats)

            self.error_report_file.write(u''.join(
                [force_unicode(e, self.encoding) for e in self.errorlist]))
            self.error_report_file.write(u'</testsuite>')
            self.error_report_file.close()
            if self.config.verbosity > 1:
                stream.writeln("-" * 70)
                stream.writeln("XML: %s" % self.error_report_file.name)
Exemple #4
0
    def report(self, stream):
        """Writes an Xunit-formatted XML file

        The file includes a report of test errors and failures.

        """
        self.error_report_file = codecs.open(self.error_report_filename, 'w',
                                             self.encoding, 'replace')
        self.stats['encoding'] = self.encoding
        self.stats['total'] = (self.stats['errors'] + self.stats['failures']
                               + self.stats['passes'] + self.stats['skipped'])
        self.error_report_file.write(
            u'<?xml version="1.0" encoding="%(encoding)s"?>'
            u'<testsuite name="nosetests" tests="%(total)d" '
            u'errors="%(errors)d" failures="%(failures)d" '
            u'skip="%(skipped)d">' % self.stats)
        self.error_report_file.write(u''.join([
            force_unicode(error)
            for error
            in self.errorlist
        ]))

        self.error_report_file.write(u'</testsuite>')
        self.error_report_file.close()
        if self.config.verbosity > 1:
            stream.writeln("-" * 70)
            stream.writeln("XML: %s" % self.error_report_file.name)
Exemple #5
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 <<')
     ])
Exemple #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 <<')
     ])
    def formatFailure(self, test, err):
        """Add detail from traceback inspection to error message of a failure.
        """
        ec, ev, tb = err
        tbinfo, str_ev = None, exc_to_unicode(ev)

        if tb:
            tbinfo = force_unicode(inspect_traceback(tb))
            str_ev = '\n'.join([str_ev, tbinfo])
        test.tbinfo = tbinfo
        return (ec, str_ev, tb)
Exemple #8
0
 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)
def exc_message(exc_info):
    """Return the exception's message."""
    exc = exc_info[1]
    if exc is None:
        # str exception
        result = exc_info[0]
    else:
        try:
            result = str(exc)
        except UnicodeEncodeError:
            try:
                result = unicode(exc)
            except UnicodeError:
                # Fallback to args as neither str nor
                # unicode(Exception(u'\xe6')) work in Python < 2.6
                result = exc.args[0]
    result = force_unicode(result, 'UTF-8')
    return xml_safe(result)
Exemple #10
0
 def write(self, data):
     data = force_unicode(data, self._encoding)
     for s in self._streams:
         s.write(data)
Exemple #11
0
 def wrapper(*args, **kwargs):
     return force_unicode(func(*args, **kwargs))
Exemple #12
0
 def write(self, data):
     data = force_unicode(data, self._encoding)
     for s in self._streams:
         if not isinstance(s, Tee):
             s.write(data)
Exemple #13
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 <<')])
Exemple #14
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 <<')
     ])
Exemple #15
0
 def write(self, s):
     u = force_unicode(s)
     StringIO.write(self, u)
 def write(self, data):
     data = force_unicode(data, self._encoding)
     for s in self._streams:
         s.write(data)
 def addCaptureToErr(self, ev, output):
     ev = exc_to_unicode(ev)
     output = force_unicode(output)
     return u"\n".join([ev, output])