示例#1
0
class _QtLogLevelErrorRepr(TerminalRepr):
    """
    TerminalRepr of a test which didn't fail by normal means, but emitted
    messages at or above the allowed level.
    """

    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 = []

    def addsection(self, name, content, sep="-"):
        self.sections.append((name, content, sep))

    def toterminal(self, out):
        self.fileloc.toterminal(out)
        for name, content, sep in self.sections:
            out.sep(sep, name)
            out.line(content)
示例#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
class _QtLogLevelErrorRepr(TerminalRepr):
    """
    TerminalRepr of a test which didn't fail by normal means, but emitted
    messages at or above the allowed level.
    """

    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 = []

    def addsection(self, name, content, sep="-"):
        self.sections.append((name, content, sep))

    def toterminal(self, out):
        self.fileloc.toterminal(out)
        for name, content, sep in self.sections:
            out.sep(sep, name)
            out.line(content)
示例#4
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 = []
示例#5
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)
示例#6
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 = []
示例#7
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)
示例#8
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)
示例#9
0
 def __init__(self, item, level):
     msg = 'Failure: Qt messages with level {0} or above emitted'
     path, line, _ = item.location
     self.fileloc = ReprFileLocation(path, line, msg.format(level.upper()))
     self.sections = []
示例#10
0
 def _get_repr_file_location(self, failure):
     filename, linenum = failure.get_file_reference()
     return ReprFileLocation(filename, linenum, 'C++ failure')