def test_verbose(self):
        a = ArrayStream()
        m = metered_stream.MeteredStream(verbose=True, stream=a)
        self.assertTrue(a.empty())
        m.write("foo")
        self.assertEquals(a.get(), ['foo'])

        m.update("bar")
        # FIXME: figure out how to test that this went to the logger. Is this
        # good enough?
        self.assertEquals(a.get(), ['foo'])

        m.progress("dropped")
        self.assertEquals(a.get(), ['foo'])
    def test_regular(self):
        a = ArrayStream()
        m = metered_stream.MeteredStream(verbose=False, stream=a)
        self.assertTrue(a.empty())

        # basic test - note that the flush() is a no-op, but we include it
        # for coverage.
        m.write("foo")
        m.flush()
        exp = ['foo']
        self.assertEquals(a.get(), exp)

        # now check that a second write() does not overwrite the first.
        m.write("bar")
        exp.append('bar')
        self.assertEquals(a.get(), exp)

        m.update("batter")
        exp.append('batter')
        self.assertEquals(a.get(), exp)

        # The next update() should overwrite the laste update() but not the
        # other text. Note that the cursor is effectively positioned at the
        # end of 'foo', even though we had to erase three more characters.
        m.update("foo")
        exp.append('\b\b\b\b\b\b      \b\b\b\b\b\b')
        exp.append('foo')
        self.assertEquals(a.get(), exp)

        m.progress("progress")
        exp.append('\b\b\b   \b\b\b')
        exp.append('progress')
        self.assertEquals(a.get(), exp)

        # now check that a write() does overwrite the progress bar
        m.write("foo")
        exp.append('\b\b\b\b\b\b\b\b        \b\b\b\b\b\b\b\b')
        exp.append('foo')
        self.assertEquals(a.get(), exp)

        # Now test that we only back up to the most recent newline.

        # Note also that we do not back up to erase the most recent write(),
        # i.e., write()s do not get erased.
        a.reset()
        m.update("foo\nbar")
        m.update("baz")
        self.assertEquals(a.get(), ['foo\nbar', '\b\b\b   \b\b\b', 'baz'])
    def test_verbose(self):
        a = ArrayStream()
        m = metered_stream.MeteredStream(verbose=True, stream=a)
        self.assertTrue(a.empty())
        m.write("foo")
        self.assertEquals(a.get(), ['foo'])

        import logging
        b = ArrayStream()
        logger = logging.getLogger()
        handler = logging.StreamHandler(b)
        logger.addHandler(handler)
        m.update("bar")
        logger.handlers.remove(handler)
        self.assertEquals(a.get(), ['foo'])
        self.assertEquals(b.get(), ['bar\n'])

        m.progress("dropped")
        self.assertEquals(a.get(), ['foo'])
        self.assertEquals(b.get(), ['bar\n'])
Пример #4
0
    def __init__(self, port, options, regular_output, buildbot_output,
                 child_processes, is_fully_parallel):
        """
        Args
          port               interface to port-specific routines
          options            OptionParser object with command line settings
          regular_output     stream to which output intended only for humans
                             should be written
          buildbot_output    stream to which output intended to be read by
                             the buildbots (and humans) should be written
          child_processes    number of parallel threads running (usually
                             controlled by --child-processes)
          is_fully_parallel  are the tests running in a single queue, or
                             in shards (usually controlled by
                             --experimental-fully-parallel)

        Note that the last two args are separate rather than bundled into
        the options structure so that this object does not assume any flags
        set in options that weren't returned from logging_options(), above.
        The two are used to determine whether or not we can sensibly use
        the 'detailed-progress' option, or can only use 'one-line-progress'.
        """
        self._buildbot_stream = buildbot_output
        self._options = options
        self._port = port
        self._stream = regular_output

        # These are used for --print detailed-progress to track status by
        # directory.
        self._current_dir = None
        self._current_progress_str = ""
        self._current_test_number = 0

        self._meter = metered_stream.MeteredStream(options.verbose,
                                                   regular_output)
        self._logging_handler = _configure_logging(self._meter,
                                                   options.verbose)

        self.switches = parse_print_options(options.print_options,
                                            options.verbose, child_processes,
                                            is_fully_parallel)