Exemplo n.º 1
0
    def update(self, test, number):
        """Draw an updated progress bar.

        At the moment, the graph takes a fixed width, and the test identifier
        takes the rest of the row, truncated from the left to fit.

        test -- the test being run
        number -- how many tests have been run so far, including this one

        """
        # TODO: Play nicely with absurdly narrow terminals. (OS X's won't even
        # go small enough to hurt us.)

        # Figure out graph:
        GRAPH_WIDTH = 14
        # min() is in case we somehow get the total test count wrong. It's tricky.
        num_markers = int(round(min(1.0, float(number) / self.max) * GRAPH_WIDTH))
        # If there are any markers, replace the last one with the spinner.
        # Otherwise, have just a spinner:
        markers = '=' * (num_markers - 1) + self._spinner.next()
        graph = '[%s%s]' % (markers, ' ' * (GRAPH_WIDTH - len(markers)))

        # Figure out the test identifier portion:
        test_path = nose_selector(test)
        cols_for_path = self.cols - len(graph) - 2  # 2 spaces between path & graph
        if len(test_path) > cols_for_path:
            test_path = test_path[len(test_path) - cols_for_path:]
        else:
            test_path += ' ' * (cols_for_path - len(test_path))

        # Put them together, and let simmer:
        self.last = self._codes['bold'] + test_path + '  ' + graph + self._codes['sgr0']
        with self._at_last_line():
            self.stream.write(self.last)
Exemplo n.º 2
0
    def _printError(self, kind, err, test, isFailure=True):
        """Output a human-readable error report to the stream.

        kind -- the (string) type of incident the precipitated this call
        err -- exc_info()-style traceback triple
        test -- the test that precipitated this call

        """
        if isFailure or self._showAdvisories:
            # Don't bind third item to a local var; that can create circular
            # refs which are expensive to collect. See the sys.exc_info() docs.
            exception_type, exception_value = err[:2]
            extracted_tb = extract_tb(err[2])
            formatted_traceback = ''.join(format_list(extracted_tb))
            # TODO: Canonicalize the path to remove /kitsune/../kitsune
            # nonsense. Don't relativize, though, as that hurts the ability to
            # paste into running editors.
            writeln = self.stream.writeln
            write = self.stream.write
            with self.bar.dodging():
                writeln('\n' + (self._codes['bold'] if isFailure else '') +
                        '%s: %s' % (kind, nose_selector(test)))

                if isFailure:  # Then show traceback
                    # File name and line num in a format vi can take:
                    try:
                        address = test_address(test)
                    except TypeError:
                        # Explodes if the function passed to @with_setup
                        # applied to a test generator has an error.
                        address = None
                    if address:  # None if no such callable found. No sense
                                 # trying to find the test frame if there's no
                                 # such thing.
                        file, line = frame_of_test(address,
                                                   exception_type,
                                                   exception_value,
                                                   extracted_tb)[:2]
                        writeln(' ' * len(kind) + '  %s +%s %s' %
                                (os.environ.get('EDITOR', 'vi'), line,
                                 human_path(src(file), self._cwd)))

                    write(self._codes['sgr0'])  # end bold

                    # Traceback:
                    # TODO: Think about using self._exc_info_to_string, which
                    # does some pretty whizzy skipping of unittest frames.
                    write(formatted_traceback)

                    # Exception:
                    write(''.join(format_exception_only(exception_type,
                                                        exception_value)))
                else:
                    write(self._codes['sgr0'])  # end bold
Exemplo n.º 3
0
    def _printHeadline(self, kind, test, is_failure=True):
        """Output a 1-line error summary to the stream if appropriate.

        The line contains the kind of error and the pathname of the test.

        :arg kind: The (string) type of incident the precipitated this call
        :arg test: The test that precipitated this call

        """
        if is_failure or self._options.show_advisories:
            with self.bar.dodging():
                self.stream.writeln(
                    '\n' + (self._term.bold if is_failure else '') + '%s: %s' %
                    (kind, nose_selector(test)) +
                    (self._term.normal if is_failure else ''))  # end bold
Exemplo n.º 4
0
    def _printHeadline(self, kind, test, is_failure=True):
        """Output a 1-line error summary to the stream if appropriate.

        The line contains the kind of error and the pathname of the test.

        :arg kind: The (string) type of incident the precipitated this call
        :arg test: The test that precipitated this call

        """
        if is_failure or self._options.show_advisories:
            with self.bar.dodging():
                line = '%s: %s' % (kind, nose_selector(test))
                if is_failure:
                    line = self.fail_color(line)
                self.stream.writeln('\n' + line)
Exemplo n.º 5
0
    def _printError(self, kind, err, test, isFailure=True):
        """Output a human-readable error report to the stream.

        kind -- the (string) type of incident the precipitated this call
        err -- exc_info()-style traceback triple
        test -- the test that precipitated this call

        """
        if isFailure or self._options.show_advisories:
            writeln = self.stream.writeln
            write = self.stream.write
            with self.bar.dodging():
                writeln('\n' +
                        (self._term.bold if isFailure else '') +
                        '%s: %s' % (kind, nose_selector(test)) +
                        (self._term.normal if isFailure else ''))  # end bold

                if isFailure:  # Then show traceback
                    # Don't bind third item to a local var; that can create
                    # circular refs which are expensive to collect. See the
                    # sys.exc_info() docs.
                    exception_type, exception_value = err[:2]
                    extracted_tb = extract_relevant_tb(
                        err[2],
                        exception_type,
                        exception_type is test.failureException)
                    test_frame_index = index_of_test_frame(
                        extracted_tb,
                        exception_type,
                        exception_value,
                        test)
                    if test_frame_index:
                        # We have a good guess at which frame is the test, so
                        # trim everything until that. We don't care to see test
                        # framework frames.
                        extracted_tb = extracted_tb[test_frame_index:]

                    write(''.join(
                        format_traceback(
                            extracted_tb,
                            exception_type,
                            exception_value,
                            self._cwd,
                            self._term,
                            self._options.function_color,
                            self._options.dim_color,
                            self._options.editor)))
Exemplo n.º 6
0
 def startTest(self, test):
     """Update the progress bar."""
     super(ProgressiveResult, self).startTest(test)
     self.bar.update(nose_selector(test), self.testsRun)
 def startTest(self, test):
     """Update the progress bar."""
     super(ProgressiveResult, self).startTest(test)
     self.bar.update(nose_selector(test), self.testsRun)