Пример #1
0
    def printErrorList(self, flavour, errors):
        """Print colorful test output:

        * Error and Failure headers are in Red.
        * The First/Last lines (Traceback heading and Exception) are Cyan.
        # Non-Django lines are Yellow.

        """

        for test, err in errors:
            self.stream.writeln(colors.red(self.separator1))
            out = "{0}: {1}".format(flavour, self.getDescription(test))
            self.stream.writeln(colors.red(out))
            self.stream.writeln(colors.red(self.separator2))
            tb = "{0}".format(err)
            lines = tb.strip().split("\n")

            # Temporarily remove the first & last lines of the Traceback.
            if len(lines) > 2:
                first_line = colors.cyan(lines.pop(0))  # Traceback header
                last_line = colors.cyan(lines.pop(-1))  # The Exception
            else:
                first_line, last_line = ('', '')

            # Python 2 tracebacks are organized into pairs of lines--a path and
            # a line of code that looks something like this:
            #
            # >>> File "/path/to/module.py", line 123, in method_name
            # >>>     some_line_of_code
            #
            # Python 3 tracebacks, however, may start with several lines of
            # output, e.g.:
            #
            # -----------------------------------------------------------------
            # Traceback (most recent call last):
            # File "/usr/lib/python/unittest/mock.py", line 1, in _whatever
            #   return getattr(thing, comp)
            # AttributeError: 'module' object has no attribute 'something'
            #
            # During handling of the above exception, another exception occurred
            #
            # -----------------------------------------------------------------
            #
            # So, rather than trying to group every two lines (like this code
            # used to do), just inspect each line and if we watch a given
            # path, highlight it and the next line of the traceback.

            i = 0
            while i < len(lines) - 1:
                if self.highlight_path in lines[i]:
                    lines[i] = colors.yellow(lines[i])
                    lines[i + 1] = colors.yellow(lines[i + 1])
                i += 1

            lines.insert(0, first_line)
            lines.append(last_line)
            self.stream.writeln("\n".join(lines))
Пример #2
0
    def printErrorList(self, flavour, errors):
        """Print colorful test output:

        * Error and Failure headers are in Red.
        * The First/Last lines (Traceback heading and Exception) are Cyan.
        # Non-Django lines are Yellow.

        """

        for test, err in errors:
            self.stream.writeln(colors.red(self.separator1))
            out = "{0}: {1}".format(flavour, self.getDescription(test))
            self.stream.writeln(colors.red(out))
            self.stream.writeln(colors.red(self.separator2))
            tb = "{0}".format(err)
            lines = tb.strip().split("\n")

            # Temporarily remove the first & last lines of the Traceback.
            if len(lines) > 2:
                first_line = colors.cyan(lines.pop(0))  # Traceback header
                last_line = colors.cyan(lines.pop(-1))  # The Exception
            else:
                first_line, last_line = ('', '')

            # Python 2 tracebacks are organized into pairs of lines--a path and
            # a line of code that looks something like this:
            #
            # >>> File "/path/to/module.py", line 123, in method_name
            # >>>     some_line_of_code
            #
            # Python 3 tracebacks, however, may start with several lines of
            # output, e.g.:
            #
            # -----------------------------------------------------------------
            # Traceback (most recent call last):
            # File "/usr/lib/python/unittest/mock.py", line 1, in _whatever
            #   return getattr(thing, comp)
            # AttributeError: 'module' object has no attribute 'something'
            #
            # During handling of the above exception, another exception occurred
            #
            # -----------------------------------------------------------------
            #
            # So, rather than trying to group every two lines (like this code
            # used to do), just inspect each line and if we watch a given
            # path, highlight it and the next line of the traceback.

            i = 0
            while i < len(lines) - 1:
                if self.highlight_path in lines[i]:
                    lines[i] = colors.yellow(lines[i])
                    lines[i + 1] = colors.yellow(lines[i + 1])
                i += 1

            lines.insert(0, first_line)
            lines.append(last_line)
            self.stream.writeln("\n".join(lines))
Пример #3
0
    def printErrorList(self, flavour, errors):
        """Print colorful test output:

        * Error and Failure headers are in Red.
        * The First/Last lines (Traceback heading and Exception) are Cyan.
        # Non-Django lines are Yellow.

        """

        # Find the path where django is installed.
        django_path = dirname(getfile(django))

        for test, err in errors:
            self.stream.writeln(colors.red(self.separator1))
            out = "{0}: {1}".format(flavour, self.getDescription(test))
            self.stream.writeln(colors.red(out))
            self.stream.writeln(colors.red(self.separator2))
            tb = "{0}".format(err)
            lines = tb.strip().split("\n")

            # Temporarily remove the first & last lines of the Traceback.
            if len(lines) > 2:
                first_line = colors.cyan(lines.pop(0))  # Traceback header
                last_line = colors.cyan(lines.pop(-1))  # The Exception
            else:
                first_line, last_line = ('', '')

            # The traceback is organized into pairs; a path and a line of code,
            # and the pair looks something like this:
            #
            # >>> File "/path/to/module.py", line 123, in method_name
            # >>>     some_line_of_code
            #
            # So, we'll group every two lines of the traceback, and highlight
            # the pertinent parts

            i = 0  # remember which line of the Traceback we're highlighting.
            groups = zip(*[lines[x::2] for x in range(2)])
            for path, line_of_code in groups:
                if django_path not in path:
                    lines[i] = colors.yellow(path)
                    lines[i + 1] = colors.yellow(line_of_code)
                i += 2

            lines.insert(0, first_line)
            lines.append(last_line)
            self.stream.writeln("\n".join(lines))
Пример #4
0
    def printErrorList(self, flavour, errors):
        """Print colorful test output:

        * Error and Failure headers are in Red.
        * The First/Last lines (Traceback heading and Exception) are Cyan.
        # Non-Django lines are Yellow.

        """

        # Find the path where django is installed.
        django_path = dirname(getfile(django))

        for test, err in errors:
            self.stream.writeln(colors.red(self.separator1))
            out = "{0}: {1}".format(flavour, self.getDescription(test))
            self.stream.writeln(colors.red(out))
            self.stream.writeln(colors.red(self.separator2))
            tb = "{0}".format(err)
            lines = tb.strip().split("\n")

            # Temporarily remove the first & last lines of the Traceback.
            if len(lines) > 2:
                first_line = colors.cyan(lines.pop(0))  # Traceback header
                last_line = colors.cyan(lines.pop(-1))  # The Exception
            else:
                first_line, last_line = ('', '')

            # The traceback is organized into pairs; a path and a line of code,
            # and the pair looks something like this:
            #
            # >>> File "/path/to/module.py", line 123, in method_name
            # >>>     some_line_of_code
            #
            # So, we'll group every two lines of the traceback, and highlight
            # the pertinent parts

            i = 0  # remember which line of the Traceback we're highlighting.
            groups = zip(*[lines[x::2] for x in range(2)])
            for path, line_of_code in groups:
                if django_path not in path:
                    lines[i] = colors.yellow(path)
                    lines[i + 1] = colors.yellow(line_of_code)
                i += 2

            lines.insert(0, first_line)
            lines.append(last_line)
            self.stream.writeln("\n".join(lines))
Пример #5
0
 def get_elapsed_line(self, test):
     elapsed = self.get_elapsed(test)
     if elapsed is None:
         return ''
     if elapsed > (DEFAULT_TEST_THRESHOLD or self.slow_test_threshold):
         line = yellow('(%.6fs)' % (elapsed))
     else:
         line = magenta('(%.6fs)' % (elapsed))
     return line
Пример #6
0
 def print_slow_tests(self, result):
     for name, elapsed, threshold in result.getTestTimings():
         if elapsed > (threshold or self.slow_test_threshold):
             self.stream.writeln(
                 yellow(
                     '[takes ({:.03}s) margin: {}] - {}'.format(
                         elapsed,
                         threshold or self.slow_test_threshold,
                         name,
                     ), ), )