예제 #1
0
 def repr_failure(self, excinfo):
     if excinfo.errisinstance(doctest.DocTestFailure):
         doctestfailure = excinfo.value
         example = doctestfailure.example
         test = doctestfailure.test
         filename = test.filename 
         lineno = test.lineno + example.lineno + 1
         message = excinfo.type.__name__
         reprlocation = ReprFileLocation(filename, lineno, message)
         checker = doctest.OutputChecker() 
         REPORT_UDIFF = doctest.REPORT_UDIFF
         filelines = py.path.local(filename).readlines(cr=0)
         i = max(test.lineno, max(0, lineno - 10)) # XXX? 
         lines = []
         for line in filelines[i:lineno]:
             lines.append("%03d %s" % (i+1, line))
             i += 1
         lines += checker.output_difference(example, 
                 doctestfailure.got, REPORT_UDIFF).split("\n")
         return ReprFailDoctest(reprlocation, lines)
     elif excinfo.errisinstance(doctest.UnexpectedException):
         excinfo = py.code.ExceptionInfo(excinfo.value.exc_info)
         return super(DoctestItem, self).repr_failure(excinfo)
     else: 
         return super(DoctestItem, self).repr_failure(excinfo)
예제 #2
0
 def __init__(self, item, level):
     msg = 'Failure: Qt messages with level {0} or above emitted'
     path, line_index, _ = item.location
     self.fileloc = ReprFileLocation(path,
                                     lineno=line_index + 1,
                                     message=msg.format(level.upper()))
     self.sections = []
예제 #3
0
 def __init__(self, item, level, is_modeltest_error):
     if is_modeltest_error:
         msg = "Qt modeltester errors"
     else:
         msg = "Failure: Qt messages with level {0} or above emitted"
     path, line_index, _ = item.location
     self.fileloc = ReprFileLocation(path,
                                     lineno=line_index + 1,
                                     message=msg.format(level.upper()))
     self.sections = []
예제 #4
0
 def repr_failure(self, excinfo):
     import doctest
     if excinfo.errisinstance(
         (doctest.DocTestFailure, doctest.UnexpectedException)):
         doctestfailure = excinfo.value
         example = doctestfailure.example
         test = doctestfailure.test
         filename = test.filename
         if test.lineno is None:
             lineno = None
         else:
             lineno = test.lineno + example.lineno + 1
         message = excinfo.type.__name__
         reprlocation = ReprFileLocation(filename, lineno, message)
         checker = _get_unicode_checker()
         REPORT_UDIFF = doctest.REPORT_UDIFF
         if lineno is not None:
             lines = doctestfailure.test.docstring.splitlines(False)
             # add line numbers to the left of the error message
             lines = [
                 "%03d %s" % (i + test.lineno + 1, x)
                 for (i, x) in enumerate(lines)
             ]
             # trim docstring error lines to 10
             lines = lines[example.lineno - 9:example.lineno + 1]
         else:
             lines = [
                 'EXAMPLE LOCATION UNKNOWN, not showing all tests of that example'
             ]
             indent = '>>>'
             for line in example.source.splitlines():
                 lines.append('??? %s %s' % (indent, line))
                 indent = '...'
         if excinfo.errisinstance(doctest.DocTestFailure):
             lines += checker.output_difference(example, doctestfailure.got,
                                                REPORT_UDIFF).split("\n")
         else:
             inner_excinfo = py.code.ExceptionInfo(excinfo.value.exc_info)
             lines += [
                 "UNEXPECTED EXCEPTION: %s" % repr(inner_excinfo.value)
             ]
             lines += traceback.format_exception(*excinfo.value.exc_info)
         return ReprFailDoctest(reprlocation, lines)
     else:
         return super(DoctestItem, self).repr_failure(excinfo)
예제 #5
0
 def repr_failure(self, excinfo):
     doctest = py.std.doctest
     if excinfo.errisinstance(
         (doctest.DocTestFailure, doctest.UnexpectedException)):
         doctestfailure = excinfo.value
         example = doctestfailure.example
         test = doctestfailure.test
         filename = test.filename
         if test.lineno is None:
             lineno = None
         else:
             lineno = test.lineno + example.lineno + 1
         message = excinfo.type.__name__
         reprlocation = ReprFileLocation(filename, lineno, message)
         checker = py.std.doctest.OutputChecker()
         REPORT_UDIFF = py.std.doctest.REPORT_UDIFF
         filelines = py.path.local(filename).readlines(cr=0)
         lines = []
         if lineno is not None:
             i = max(test.lineno, max(0, lineno - 10))  # XXX?
             for line in filelines[i:lineno]:
                 lines.append("%03d %s" % (i + 1, line))
                 i += 1
         else:
             lines.append(
                 'EXAMPLE LOCATION UNKNOWN, not showing all tests of that example'
             )
             indent = '>>>'
             for line in example.source.splitlines():
                 lines.append('??? %s %s' % (indent, line))
                 indent = '...'
         if excinfo.errisinstance(doctest.DocTestFailure):
             lines += checker.output_difference(example, doctestfailure.got,
                                                REPORT_UDIFF).split("\n")
         else:
             inner_excinfo = py.code.ExceptionInfo(excinfo.value.exc_info)
             lines += [
                 "UNEXPECTED EXCEPTION: %s" % repr(inner_excinfo.value)
             ]
             lines += py.std.traceback.format_exception(
                 *excinfo.value.exc_info)
         return ReprFailDoctest(reprlocation, lines)
     else:
         return super(DoctestItem, self).repr_failure(excinfo)
예제 #6
0
 def _get_repr_file_location(self, failure):
     filename, linenum = failure.get_file_reference()
     return ReprFileLocation(filename, linenum, 'C++ failure')