diff options
Diffstat (limited to 'WebKitTools/Scripts/webkitpy/layout_tests/layout_package')
5 files changed, 152 insertions, 33 deletions
diff --git a/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/metered_stream.py b/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/metered_stream.py index 9c42d73..20646a1 100644 --- a/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/metered_stream.py +++ b/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/metered_stream.py @@ -137,12 +137,10 @@ class MeteredStream: # Print the necessary number of backspaces to erase the previous # message. if len(self._last_update): - self._stream.write("\b" * len(self._last_update)) - if len(str): - self._stream.write(str) - num_remaining = len(self._last_update) - len(str) - if num_remaining > 0: - self._stream.write(" " * num_remaining + "\b" * num_remaining) + self._stream.write("\b" * len(self._last_update) + + " " * len(self._last_update) + + "\b" * len(self._last_update)) + self._stream.write(str) last_newline = str.rfind("\n") self._last_update = str[(last_newline + 1):] self._dirty = True diff --git a/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/metered_stream_unittest.py b/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/metered_stream_unittest.py index 926f9b3..a9c6d5b 100644 --- a/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/metered_stream_unittest.py +++ b/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/metered_stream_unittest.py @@ -50,32 +50,36 @@ class TestMeteredStream(unittest.TestCase): # for coverage. m.write("foo") m.flush() - self.assertEquals(a.get(), ['foo']) + exp = ['foo'] + self.assertEquals(a.get(), exp) # now check that a second write() does not overwrite the first. m.write("bar") - self.assertEquals(a.get(), ['foo', 'bar']) + exp.append('bar') + self.assertEquals(a.get(), exp) m.update("batter") - self.assertEquals(a.get(), ['foo', 'bar', '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") - self.assertEquals(a.get(), ['foo', 'bar', 'batter', '\b\b\b\b\b\b', - 'foo', ' \b\b\b']) + 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") - self.assertEquals(a.get(), ['foo', 'bar', 'batter', '\b\b\b\b\b\b', - 'foo', ' \b\b\b', '\b\b\b', '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") - self.assertEquals(a.get(), ['foo', 'bar', 'batter', '\b\b\b\b\b\b', - 'foo', ' \b\b\b', '\b\b\b', 'progress', - '\b\b\b\b\b\b\b\b', - 'foo', ' \b\b\b\b\b']) + 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. @@ -84,7 +88,7 @@ class TestMeteredStream(unittest.TestCase): a.reset() m.update("foo\nbar") m.update("baz") - self.assertEquals(a.get(), ['foo\nbar', '\b\b\b', 'baz']) + self.assertEquals(a.get(), ['foo\nbar', '\b\b\b \b\b\b', 'baz']) def test_verbose(self): a = ArrayStream() diff --git a/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/printing.py b/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/printing.py index 91d49c6..77de2e0 100644 --- a/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/printing.py +++ b/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/printing.py @@ -56,6 +56,8 @@ the output at the beginning of the run, during the run, or at the end: Overall options: nothing don't print anything. This overrides every other option + default include the default options. This is useful for logging + the default options plus additional settings. everything print everything (except the trace-* options and the detailed-progress option, see below for the full list ) misc print miscellaneous things like blank lines @@ -101,15 +103,19 @@ Notes: --print 'everything' is equivalent to --print '%(everything)s'. -The default is to --print '%(default)s'. +The default (--print default) is equivalent to --print '%(default)s'. """ % {'slowest': NUM_SLOW_TESTS_TO_LOG, 'everything': PRINT_EVERYTHING, 'default': PRINT_DEFAULT} def print_options(): return [ - # Note: we use print_options rather than just 'print' because print + # Note: We use print_options rather than just 'print' because print # is a reserved word. + # Note: Also, we don't specify a default value so we can detect when + # no flag is specified on the command line and use different defaults + # based on whether or not --verbose is specified (since --print + # overrides --verbose). optparse.make_option("--print", dest="print_options", help=("controls print output of test run. " "Use --help-printing for more.")), @@ -171,6 +177,10 @@ def parse_print_options(print_options, verbose, child_processes, switches.discard('everything') switches.update(set(PRINT_EVERYTHING.split(','))) + if 'default' in switches: + switches.discard('default') + switches.update(set(PRINT_DEFAULT.split(','))) + if 'detailed-progress' in switches: switches.discard('one-line-progress') @@ -310,7 +320,7 @@ class Printer(object): png_file = self._port.expected_filename(filename, '.png') if os.path.exists(png_file): self._write(' png: %s' % - self._port.relative_test_filename(filename)) + self._port.relative_test_filename(png_file)) else: self._write(' png: <none>') self._write(' exp: %s' % exp_str) @@ -486,10 +496,8 @@ class Printer(object): # from the logger :(. if self._options.verbose: _log.info(msg) - elif msg == "": - self._meter.write("\n") else: - self._meter.write(msg) + self._meter.write("%s\n" % msg) # # Utility routines used by the Controller class diff --git a/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/printing_unittest.py b/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/printing_unittest.py index 8e6aa8f..dba1194 100644 --- a/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/printing_unittest.py +++ b/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/printing_unittest.py @@ -98,6 +98,44 @@ class TestUtilityFunctions(unittest.TestCase): options, args = get_options([]) self.assertTrue(options is not None) + def test_parse_print_options(self): + def test_switches(args, verbose, child_processes, is_fully_parallel, + expected_switches_str): + options, args = get_options(args) + if expected_switches_str: + expected_switches = set(expected_switches_str.split(',')) + else: + expected_switches = set() + switches = printing.parse_print_options(options.print_options, + verbose, + child_processes, + is_fully_parallel) + self.assertEqual(expected_switches, switches) + + # test that we default to the default set of switches + test_switches([], False, 1, False, + printing.PRINT_DEFAULT) + + # test that verbose defaults to everything + test_switches([], True, 1, False, + printing.PRINT_EVERYTHING) + + # test that --print default does what it's supposed to + test_switches(['--print', 'default'], False, 1, False, + printing.PRINT_DEFAULT) + + # test that --print nothing does what it's supposed to + test_switches(['--print', 'nothing'], False, 1, False, + None) + + # test that --print everything does what it's supposed to + test_switches(['--print', 'everything'], False, 1, False, + printing.PRINT_EVERYTHING) + + # this tests that '--print X' overrides '--verbose' + test_switches(['--print', 'actual'], True, 1, False, + 'actual') + class Testprinter(unittest.TestCase): def get_printer(self, args=None, single_threaded=False, @@ -144,7 +182,7 @@ class Testprinter(unittest.TestCase): exp_bot = [message + "\n"] else: if exp_err is None: - exp_err = [message] + exp_err = [message + "\n"] if exp_bot is None: exp_bot = [] do_helper(method_name, 'nothing', 'hello', [], []) @@ -182,21 +220,21 @@ class Testprinter(unittest.TestCase): printer, err, out = self.get_printer(['--print', 'one-line-summary']) printer.print_one_line_summary(1, 1) - self.assertEquals(err.get(), ["All 1 tests ran as expected.", "\n"]) + self.assertEquals(err.get(), ["All 1 tests ran as expected.\n", "\n"]) printer, err, out = self.get_printer(['--print', 'everything']) printer.print_one_line_summary(1, 1) - self.assertEquals(err.get(), ["All 1 tests ran as expected.", "\n"]) + self.assertEquals(err.get(), ["All 1 tests ran as expected.\n", "\n"]) err.reset() printer.print_one_line_summary(2, 1) self.assertEquals(err.get(), - ["1 test ran as expected, 1 didn't:", "\n"]) + ["1 test ran as expected, 1 didn't:\n", "\n"]) err.reset() printer.print_one_line_summary(3, 2) self.assertEquals(err.get(), - ["2 tests ran as expected, 1 didn't:", "\n"]) + ["2 tests ran as expected, 1 didn't:\n", "\n"]) def test_print_test_result(self): result = get_result('foo.html') @@ -212,7 +250,7 @@ class Testprinter(unittest.TestCase): printer.print_test_result(result, expected=False, exp_str='', got_str='') self.assertEquals(err.get(), - [' foo.html -> unexpected pass']) + [' foo.html -> unexpected pass\n']) printer, err, out = self.get_printer(['--print', 'everything']) printer.print_test_result(result, expected=True, exp_str='', @@ -222,7 +260,7 @@ class Testprinter(unittest.TestCase): printer.print_test_result(result, expected=False, exp_str='', got_str='') self.assertEquals(err.get(), - [' foo.html -> unexpected pass']) + [' foo.html -> unexpected pass\n']) printer, err, out = self.get_printer(['--print', 'nothing']) printer.print_test_result(result, expected=False, exp_str='', @@ -318,7 +356,7 @@ class Testprinter(unittest.TestCase): err.reset() out.reset() printer.print_progress(rs, True, test_files) - self.assertEqual(err.get(), []) + self.assertEqual(err.get(), ['']) self.assertTrue(out.empty()) printer, err, out = self.get_printer( @@ -347,7 +385,7 @@ class Testprinter(unittest.TestCase): err.reset() out.reset() printer.print_progress(rs, True, test_files) - self.assertEqual(err.get(), []) + self.assertEqual(err.get(), ['']) self.assertTrue(out.empty()) def test_write(self): diff --git a/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/test_results_uploader.py b/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/test_results_uploader.py new file mode 100644 index 0000000..680b848 --- /dev/null +++ b/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/test_results_uploader.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# Copyright (C) 2010 Google Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import mimetypes +import socket + +from webkitpy.common.net.networktransaction import NetworkTransaction +from webkitpy.thirdparty.autoinstalled.mechanize import Browser + + +def get_mime_type(filename): + return mimetypes.guess_type(filename)[0] or "text/plain" + + +class TestResultsUploader: + def __init__(self, host): + self._host = host + self._browser = Browser() + + def _upload_files(self, attrs, file_objs): + self._browser.open("http://%s/testfile/uploadform" % self._host) + self._browser.select_form("test_result_upload") + for (name, data) in attrs: + self._browser[name] = str(data) + + for (filename, handle) in file_objs: + self._browser.add_file(handle, get_mime_type(filename), filename, + "file") + + self._browser.submit() + + def upload(self, params, files, timeout_seconds): + orig_timeout = socket.getdefaulttimeout() + file_objs = [] + try: + file_objs = [(filename, open(path, "rb")) for (filename, path) + in files] + + socket.setdefaulttimeout(timeout_seconds) + NetworkTransaction(timeout_seconds=timeout_seconds).run( + lambda: self._upload_files(params, file_objs)) + finally: + socket.setdefaulttimeout(orig_timeout) + for (filename, handle) in file_objs: + handle.close() |