+2012-02-18 Dirk Pranke <dpranke@chromium.org>
+
+ webkitpy: remove webkitpy.common.array_stream
+ https://bugs.webkit.org/show_bug.cgi?id=78952
+
+ Reviewed by Eric Seidel.
+
+ Turns out array_stream didn't really do anything that StringIO
+ didn't do (at least as of Python 2.6). This change removes it
+ and updates all of the callers. Where possible, I changed the
+ test assertions in order to capture the intent more clearly,
+ e.g., instead of calling self.assertTrue('foo' in stream.get()),
+ we have self.assertContainsLine(stream, 'foo'), and instead of
+ self.assertTrue(stream.empty()), we have self.assertEmpty(stream) -
+ the latter isn't that much more readable, but StringIO doesn't
+ export an empty() method.
+
+ * Scripts/webkitpy/common/array_stream.py: Removed.
+ * Scripts/webkitpy/common/array_stream_unittest.py: Removed.
+ * Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py:
+ (passing_run):
+ (run_and_capture):
+ (StreamTestingMixin):
+ (StreamTestingMixin.assertContains):
+ (StreamTestingMixin.assertContainsLine):
+ (StreamTestingMixin.assertEmpty):
+ (StreamTestingMixin.assertNotEmpty):
+ (LintTest):
+ (LintTest.test_lint_test_files):
+ (LintTest.test_lint_test_files__errors):
+ (MainTest):
+ (MainTest.test_child_process_1):
+ (MainTest.test_child_processes_2):
+ (MainTest.test_child_processes_min):
+ (MainTest.test_help_printing):
+ (MainTest.test_hung_thread):
+ (MainTest.test_no_tests_found):
+ (MainTest.test_no_tests_found_2):
+ (MainTest.test_repeat_each_iterations_num_tests):
+ (MainTest.test_test_list):
+ (MainTest.test_unexpected_failures):
+ (MainTest.test_worker_model__inline_with_child_processes):
+ (MainTest.test_additional_platform_directory):
+ (RebaselineTest):
+ (RebaselineTest.assertBaselines):
+ (RebaselineTest.test_reset_results):
+ (RebaselineTest.test_missing_results):
+ (RebaselineTest.test_new_baseline):
+ * Scripts/webkitpy/layout_tests/views/metered_stream.py:
+ (MeteredStream.update):
+ * Scripts/webkitpy/layout_tests/views/metered_stream_unittest.py:
+ (TestMeteredStream.test_regular):
+ * Scripts/webkitpy/layout_tests/views/printing_unittest.py:
+ (TestUtilityFunctions.assertEmpty):
+ (TestUtilityFunctions):
+ (TestUtilityFunctions.assertNotEmpty):
+ (TestUtilityFunctions.assertWritten):
+ (TestUtilityFunctions.test_configure_logging):
+ (Testprinter.assertEmpty):
+ (Testprinter):
+ (Testprinter.assertNotEmpty):
+ (Testprinter.assertWritten):
+ (Testprinter.reset):
+ (Testprinter.get_printer):
+ (Testprinter.test_help_printer):
+ (Testprinter.do_switch_tests.do_helper):
+ (Testprinter.test_print_one_line_summary):
+ (Testprinter.test_print_test_result):
+ (Testprinter.test_print_progress):
+ (Testprinter.test_write_nothing):
+ (Testprinter.test_write_misc):
+ (Testprinter.test_write_everything):
+ (Testprinter.test_write_verbose):
+ (Testprinter.test_print_unexpected_results):
+ * Scripts/webkitpy/performance_tests/perftestsrunner_unittest.py:
+ (MainTest.assertWritten):
+ (create_runner):
+ (test_run_test_set):
+ (test_run_test_set_kills_drt_per_run):
+ (test_run_test_set_for_parser_tests):
+ (test_run_test_set_with_json_output):
+ (test_run_test_set_with_json_source):
+ (test_run_test_set_with_multiple_repositories):
+ (test_upload_json):
+
2012-02-18 Kevin Ollivier <kevino@theolliviers.com>
[wx] Add the WebCore/page/scrolling directory to the build dirs.
+++ /dev/null
-#!/usr/bin/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.
-
-"""Package that private an array-based implementation of a stream."""
-
-
-class ArrayStream(object):
- """Simple class that implmements a stream interface on top of an array.
-
- This is used primarily by unit test classes to mock output streams. It
- performs a similar function to StringIO, but (a) it is write-only, and
- (b) it can be used to retrieve each individual write(); StringIO
- concatenates all of the writes together.
- """
-
- def __init__(self, tty=False):
- self._contents = []
- self._tty = tty
-
- def write(self, msg):
- """Implement stream.write() by appending to the stream's contents."""
- self._contents.append(msg)
-
- def get(self):
- """Return the contents of a stream (as an array)."""
- return self._contents
-
- def reset(self):
- """Empty the stream."""
- self._contents = []
-
- def empty(self):
- """Return whether the stream is empty."""
- return (len(self._contents) == 0)
-
- def flush(self):
- """Flush the stream (a no-op implemented for compatibility)."""
- pass
-
- def __repr__(self):
- return '<ArrayStream: ' + str(self._contents) + '>'
-
- def isatty(self):
- return self._tty
+++ /dev/null
-#!/usr/bin/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.
-
-"""Unit tests for array_stream.py."""
-
-import pdb
-import unittest
-
-from webkitpy.common.array_stream import ArrayStream
-
-
-class ArrayStreamTest(unittest.TestCase):
- def assertEmpty(self, a_stream):
- self.assertTrue(a_stream.empty())
-
- def assertNotEmpty(self, a_stream):
- self.assertFalse(a_stream.empty())
-
- def assertContentsMatch(self, a_stream, contents):
- self.assertEquals(a_stream.get(), contents)
-
- def test_basics(self):
- a = ArrayStream()
- self.assertEmpty(a)
- self.assertContentsMatch(a, [])
-
- a.flush()
- self.assertEmpty(a)
- self.assertContentsMatch(a, [])
-
- a.write("foo")
- a.write("bar")
- self.assertNotEmpty(a)
- self.assertContentsMatch(a, ["foo", "bar"])
-
- a.flush()
- self.assertNotEmpty(a)
- self.assertContentsMatch(a, ["foo", "bar"])
-
- a.reset()
- self.assertEmpty(a)
- self.assertContentsMatch(a, [])
-
- self.assertEquals(str(a), "<ArrayStream: []>")
-
- a.write("foo")
- self.assertNotEmpty(a)
- self.assertContentsMatch(a, ["foo"])
- self.assertEquals(str(a), "<ArrayStream: ['foo']>")
-
-if __name__ == '__main__':
- unittest.main()
import logging
import Queue
import re
+import StringIO
import sys
import thread
import time
# (bug 63846).
SHOULD_TEST_PROCESSES = sys.platform not in ('cygwin', 'win32')
-from webkitpy.common import array_stream
from webkitpy.common.system import outputcapture
from webkitpy.common.system.crashlogs_unittest import make_mock_crash_report_darwin
from webkitpy.common.host_mock import MockHost
if not port_obj:
host = host or MockHost()
port_obj = host.port_factory.get(port_name=options.platform, options=options)
- buildbot_output = array_stream.ArrayStream()
- regular_output = array_stream.ArrayStream()
+ buildbot_output = StringIO.StringIO()
+ regular_output = StringIO.StringIO()
res = run_webkit_tests.run(port_obj, options, parsed_args, buildbot_output=buildbot_output, regular_output=regular_output)
- return res == 0 and regular_output.empty() and buildbot_output.empty()
+ return res == 0 and not regular_output.getvalue() and not buildbot_output.getvalue()
def logging_run(extra_args=None, port_obj=None, record_results=False, tests_included=False, host=None, new_results=False):
oc = outputcapture.OutputCapture()
try:
oc.capture_output()
- buildbot_output = array_stream.ArrayStream()
- regular_output = array_stream.ArrayStream()
+ buildbot_output = StringIO.StringIO()
+ regular_output = StringIO.StringIO()
res = run_webkit_tests.run(port_obj, options, parsed_args,
buildbot_output=buildbot_output,
regular_output=regular_output)
unexpected_tests_count = 12
-class LintTest(unittest.TestCase):
+class StreamTestingMixin(object):
+ def assertContains(self, stream, string):
+ self.assertTrue(string in stream.getvalue())
+
+ def assertContainsLine(self, stream, string):
+ self.assertTrue(string in stream.buflist)
+
+ def assertEmpty(self, stream):
+ self.assertFalse(stream.getvalue())
+
+ def assertNotEmpty(self, stream):
+ self.assertTrue(stream.getvalue())
+
+
+class LintTest(unittest.TestCase, StreamTestingMixin):
def test_all_configurations(self):
class FakePort(object):
def test_lint_test_files(self):
res, out, err, user = logging_run(['--lint-test-files'])
self.assertEqual(res, 0)
- self.assertTrue(out.empty())
- self.assertTrue(any(['Lint succeeded' in msg for msg in err.get()]))
+ self.assertEmpty(out)
+ self.assertContains(err, 'Lint succeeded')
def test_lint_test_files__errors(self):
options, parsed_args = parse_args(['--lint-test-files'])
res, out, err = run_and_capture(port_obj, options, parsed_args)
self.assertEqual(res, -1)
- self.assertTrue(out.empty())
- self.assertTrue(any(['Lint failed' in msg for msg in err.get()]))
+ self.assertEmpty(out)
+ self.assertTrue(any(['Lint failed' in msg for msg in err.buflist]))
-class MainTest(unittest.TestCase):
+class MainTest(unittest.TestCase, StreamTestingMixin):
def test_accelerated_compositing(self):
# This just tests that we recognize the command line args
self.assertTrue(passing_run(['--accelerated-video']))
if SHOULD_TEST_PROCESSES:
_, _, regular_output, _ = logging_run(
['--print', 'config', '--worker-model', 'processes', '--child-processes', '1'])
- self.assertTrue(any(['Running 1 ' in line for line in regular_output.get()]))
+ self.assertTrue(any(['Running 1 ' in line for line in regular_output.buflist]))
def test_child_processes_2(self):
# This test seems to fail on win32.
if SHOULD_TEST_PROCESSES:
_, _, regular_output, _ = logging_run(
['--print', 'config', '--worker-model', 'processes', '--child-processes', '2'])
- self.assertTrue(any(['Running 2 ' in line for line in regular_output.get()]))
+ self.assertTrue(any(['Running 2 ' in line for line in regular_output.buflist]))
def test_child_processes_min(self):
if SHOULD_TEST_PROCESSES:
_, _, regular_output, _ = logging_run(
['--print', 'config', '--worker-model', 'processes', '--child-processes', '2', 'passes'],
tests_included=True)
- self.assertTrue(any(['Running 1 ' in line for line in regular_output.get()]))
+ self.assertTrue(any(['Running 1 ' in line for line in regular_output.buflist]))
def test_dryrun(self):
batch_tests_run = get_tests_run(['--dry-run'])
def test_help_printing(self):
res, out, err, user = logging_run(['--help-printing'])
self.assertEqual(res, 0)
- self.assertTrue(out.empty())
- self.assertFalse(err.empty())
+ self.assertEmpty(out)
+ self.assertNotEmpty(err)
def test_hung_thread(self):
res, out, err, user = logging_run(['--run-singly', '--time-out-ms=50',
'failures/expected/hang.html'],
tests_included=True)
self.assertEqual(res, 0)
- self.assertFalse(out.empty())
- self.assertFalse(err.empty())
+ self.assertNotEmpty(out)
+ self.assertNotEmpty(err)
def test_keyboard_interrupt(self):
# Note that this also tests running a test marked as SKIP if
def test_no_tests_found(self):
res, out, err, user = logging_run(['resources'], tests_included=True)
self.assertEqual(res, -1)
- self.assertTrue(out.empty())
- self.assertTrue('No tests to run.\n' in err.get())
+ self.assertEmpty(out)
+ self.assertContainsLine(err, 'No tests to run.\n')
def test_no_tests_found_2(self):
res, out, err, user = logging_run(['foo'], tests_included=True)
self.assertEqual(res, -1)
- self.assertTrue(out.empty())
- self.assertTrue('No tests to run.\n' in err.get())
+ self.assertEmpty(out)
+ self.assertContainsLine(err, 'No tests to run.\n')
def test_randomize_order(self):
# FIXME: verify order was shuffled
'--print', 'everything',
'passes/text.html', 'failures/expected/text.html'],
tests_included=True, host=host, record_results=True)
- self.assertTrue("=> Results: 8/16 tests passed (50.0%)\n" in out.get())
- self.assertTrue(err.get()[-2] == "All 16 tests ran as expected.\n")
+ self.assertContainsLine(out, "=> Results: 8/16 tests passed (50.0%)\n")
+ self.assertContainsLine(err, "All 16 tests ran as expected.\n")
def test_run_chunk(self):
# Test that we actually select the right chunk
res, out, err, user = logging_run(['--test-list=%s' % filename],
tests_included=True, host=host)
self.assertEqual(res, -1)
- self.assertFalse(err.empty())
+ self.assertNotEmpty(err)
def test_test_list_with_prefix(self):
host = MockHost()
res, out, err, user = logging_run(tests_included=True)
self.assertEqual(res, unexpected_tests_count)
- self.assertFalse(out.empty())
- self.assertFalse(err.empty())
+ self.assertNotEmpty(out)
+ self.assertNotEmpty(err)
self.assertEqual(user.opened_urls, [path.abspath_to_uri('/tmp/layout-test-results/results.html')])
def test_missing_and_unexpected_results(self):
res, out, err, user = logging_run(['--worker-model', 'inline',
'--child-processes', '2'])
self.assertEqual(res, 0)
- self.assertTrue('--worker-model=inline overrides --child-processes\n' in err.get())
+ self.assertContainsLine(err, '--worker-model=inline overrides --child-processes\n')
def test_worker_model__processes(self):
if SHOULD_TEST_PROCESSES:
self.assertTrue(passing_run(['--additional-platform-directory', '/tmp/foo', '--additional-platform-directory', '/tmp/bar']))
res, buildbot_output, regular_output, user = logging_run(['--additional-platform-directory', 'foo'])
- self.assertTrue('--additional-platform-directory=foo is ignored since it is not absolute\n' in regular_output.get())
+ self.assertContainsLine(regular_output, '--additional-platform-directory=foo is ignored since it is not absolute\n')
def test_no_http_and_force(self):
# See test_run_force, using --force raises an exception.
{"expected": "PASS", "ref_file": "reftests/foo/matching-ref.html", "actual": "IMAGE", "is_mismatch_reftest": True})
-class RebaselineTest(unittest.TestCase):
+class RebaselineTest(unittest.TestCase, StreamTestingMixin):
def assertBaselines(self, file_list, file, extensions, err):
"assert that the file_list contains the baselines."""
for ext in extensions:
baseline = file + "-expected" + ext
baseline_msg = 'Writing new expected result "%s"\n' % baseline[1:]
self.assertTrue(any(f.find(baseline) != -1 for f in file_list))
- self.assertTrue(baseline_msg in err.get())
+ self.assertContainsLine(err, baseline_msg)
# FIXME: Add tests to ensure that we're *not* writing baselines when we're not
# supposed to be.
file_list = host.filesystem.written_files.keys()
file_list.remove('/tmp/layout-test-results/tests_run0.txt')
self.assertEquals(res, 0)
- self.assertTrue(out.empty())
+ self.assertEmpty(out)
self.assertEqual(len(file_list), 4)
self.assertBaselines(file_list, "/passes/image", [".txt", ".png"], err)
self.assertBaselines(file_list, "/failures/expected/missing_image", [".txt", ".png"], err)
file_list = host.filesystem.written_files.keys()
file_list.remove('/tmp/layout-test-results/tests_run0.txt')
self.assertEquals(res, 0)
- self.assertFalse(out.empty())
+ self.assertNotEmpty(out)
self.assertEqual(len(file_list), 6)
self.assertBaselines(file_list, "/failures/unexpected/missing_text", [".txt"], err)
self.assertBaselines(file_list, "/platform/test-mac-leopard/failures/unexpected/missing_image", [".png"], err)
file_list = host.filesystem.written_files.keys()
file_list.remove('/tmp/layout-test-results/tests_run0.txt')
self.assertEquals(res, 0)
- self.assertTrue(out.empty())
+ self.assertEmpty(out)
self.assertEqual(len(file_list), 4)
self.assertBaselines(file_list,
"/platform/test-mac-leopard/passes/image", [".txt", ".png"], err)
"""Write a message that will be overwritten by subsequent update() or write() calls."""
self._overwrite(txt)
- def flush(self):
- # This seems to be needed on Python 2.5 for some reason.
- self._stream.flush()
-
def _overwrite(self, txt):
# Print the necessary number of backspaces to erase the previous
# message.
# (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 StringIO
import unittest
-from webkitpy.common.array_stream import ArrayStream
from webkitpy.layout_tests.views.metered_stream import MeteredStream
class TestMeteredStream(unittest.TestCase):
def test_regular(self):
- a = ArrayStream()
- m = MeteredStream(stream=a)
- self.assertTrue(a.empty())
+ a = StringIO.StringIO()
+ m = MeteredStream(a)
+ self.assertFalse(a.getvalue())
# basic test
m.write("foo")
exp = ['foo']
- self.assertEquals(a.get(), exp)
+ self.assertEquals(a.buflist, exp)
# now check that a second write() does not overwrite the first.
m.write("bar")
exp.append('bar')
- self.assertEquals(a.get(), exp)
+ self.assertEquals(a.buflist, exp)
m.update("batter")
exp.append('batter')
- self.assertEquals(a.get(), exp)
+ self.assertEquals(a.buflist, exp)
# The next update() should overwrite the laste update() but not the
# other text. Note that the cursor is effectively positioned at the
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)
+ self.assertEquals(a.buflist, exp)
# now check that a write() does overwrite the update
m.write("foo")
exp.append('\b\b\b \b\b\b')
exp.append('foo')
- self.assertEquals(a.get(), exp)
+ self.assertEquals(a.buflist, 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()
+ a = StringIO.StringIO()
+ m = MeteredStream(a)
m.update("foo\nbar")
m.update("baz")
- self.assertEquals(a.get(), ['foo\nbar', '\b\b\b \b\b\b', 'baz'])
+ self.assertEquals(a.buflist, ['foo\nbar', '\b\b\b \b\b\b', 'baz'])
if __name__ == '__main__':
import logging
import optparse
+import StringIO
import time
import unittest
-from webkitpy.common import array_stream
from webkitpy.common.host_mock import MockHost
from webkitpy.common.system import logtesting
class TestUtilityFunctions(unittest.TestCase):
+ def assertEmpty(self, stream):
+ self.assertFalse(stream.getvalue())
+
+ def assertNotEmpty(self, stream):
+ self.assertTrue(stream.getvalue())
+
+ def assertWritten(self, stream, contents):
+ self.assertEquals(stream.buflist, contents)
+
def test_configure_logging(self):
options, args = get_options([])
- stream = array_stream.ArrayStream()
+ stream = StringIO.StringIO()
handler = printing._configure_logging(stream, options.verbose)
logging.info("this should be logged")
- self.assertFalse(stream.empty())
+ self.assertNotEmpty(stream)
- stream.reset()
+ stream = StringIO.StringIO()
logging.debug("this should not be logged")
- self.assertTrue(stream.empty())
+ self.assertEmpty(stream)
printing._restore_logging(handler)
- stream.reset()
+ stream = StringIO.StringIO()
options, args = get_options(['--verbose'])
handler = printing._configure_logging(stream, options.verbose)
logging.debug("this should be logged")
- self.assertFalse(stream.empty())
+ self.assertNotEmpty(stream)
printing._restore_logging(handler)
def test_print_options(self):
class Testprinter(unittest.TestCase):
+ def assertEmpty(self, stream):
+ self.assertFalse(stream.getvalue())
+
+ def assertNotEmpty(self, stream):
+ self.assertTrue(stream.getvalue())
+
+ def assertWritten(self, stream, contents):
+ self.assertEquals(stream.buflist, contents)
+
+ def reset(self, stream):
+ stream.buflist = []
+ stream.buf = ''
+
def get_printer(self, args=None, tty=False):
args = args or []
printing_options = printing.print_options()
self._port = host.port_factory.get('test', options)
nproc = 2
- regular_output = array_stream.ArrayStream(tty=tty)
- buildbot_output = array_stream.ArrayStream()
+ regular_output = StringIO.StringIO()
+ regular_output.isatty = lambda: tty
+ buildbot_output = StringIO.StringIO()
printer = printing.Printer(self._port, options, regular_output,
buildbot_output, configure_logging=True)
return printer, regular_output, buildbot_output
# This routine should print something to stdout. testing what it is
# is kind of pointless.
printer.help_printing()
- self.assertFalse(err.empty())
- self.assertTrue(out.empty())
+ self.assertNotEmpty(err)
+ self.assertEmpty(out)
def do_switch_tests(self, method_name, switch, to_buildbot,
message='hello', exp_err=None, exp_bot=None):
def do_helper(method_name, switch, message, exp_err, exp_bot):
printer, err, bot = self.get_printer(['--print', switch], tty=True)
getattr(printer, method_name)(message)
- self.assertEqual(err.get(), exp_err)
- self.assertEqual(bot.get(), exp_bot)
+ self.assertEqual(err.buflist, exp_err)
+ self.assertEqual(bot.buflist, exp_bot)
if to_buildbot:
if exp_err is None:
def test_print_one_line_summary(self):
printer, err, out = self.get_printer(['--print', 'nothing'])
printer.print_one_line_summary(1, 1, 0)
- self.assertTrue(err.empty())
+ self.assertEmpty(err)
printer, err, out = self.get_printer(['--print', 'one-line-summary'])
printer.print_one_line_summary(1, 1, 0)
- self.assertEquals(err.get(), ["All 1 tests ran as expected.\n", "\n"])
+ self.assertWritten(err, ["All 1 tests ran as expected.\n", "\n"])
printer, err, out = self.get_printer(['--print', 'everything'])
printer.print_one_line_summary(1, 1, 0)
- self.assertEquals(err.get(), ["All 1 tests ran as expected.\n", "\n"])
+ self.assertWritten(err, ["All 1 tests ran as expected.\n", "\n"])
- err.reset()
+ printer, err, out = self.get_printer(['--print', 'everything'])
printer.print_one_line_summary(2, 1, 1)
- self.assertEquals(err.get(),
- ["1 test ran as expected, 1 didn't:\n", "\n"])
+ self.assertWritten(err, ["1 test ran as expected, 1 didn't:\n", "\n"])
- err.reset()
+ printer, err, out = self.get_printer(['--print', 'everything'])
printer.print_one_line_summary(3, 2, 1)
- self.assertEquals(err.get(),
- ["2 tests ran as expected, 1 didn't:\n", "\n"])
+ self.assertWritten(err, ["2 tests ran as expected, 1 didn't:\n", "\n"])
- err.reset()
+ printer, err, out = self.get_printer(['--print', 'everything'])
printer.print_one_line_summary(3, 2, 0)
- self.assertEquals(err.get(),
- ['\n', "2 tests ran as expected (1 didn't run).\n",
- '\n'])
+ self.assertWritten(err, ['\n', "2 tests ran as expected (1 didn't run).\n", '\n'])
def test_print_test_result(self):
result = self.get_result('passes/image.html')
printer.print_test_result(result, expected=False, exp_str='',
got_str='')
- self.assertTrue(err.empty())
+ self.assertEmpty(err)
printer, err, out = self.get_printer(['--print', 'unexpected'])
printer.print_test_result(result, expected=True, exp_str='',
got_str='')
- self.assertTrue(err.empty())
+ self.assertEmpty(err)
printer.print_test_result(result, expected=False, exp_str='',
got_str='')
- self.assertEquals(err.get(),
- [' passes/image.html -> unexpected pass\n'])
+ self.assertWritten(err, [' passes/image.html -> unexpected pass\n'])
printer, err, out = self.get_printer(['--print', 'everything'])
printer.print_test_result(result, expected=True, exp_str='',
got_str='')
- self.assertTrue(err.empty())
+ self.assertEmpty(err)
printer.print_test_result(result, expected=False, exp_str='',
got_str='')
- self.assertEquals(err.get(),
- [' passes/image.html -> unexpected pass\n'])
+ self.assertWritten(err, [' passes/image.html -> unexpected pass\n'])
printer, err, out = self.get_printer(['--print', 'nothing'])
printer.print_test_result(result, expected=False, exp_str='',
got_str='')
- self.assertTrue(err.empty())
+ self.assertEmpty(err)
printer, err, out = self.get_printer(['--print',
'trace-unexpected'])
printer.print_test_result(result, expected=True, exp_str='',
got_str='')
- self.assertTrue(err.empty())
+ self.assertEmpty(err)
printer, err, out = self.get_printer(['--print',
'trace-unexpected'])
printer.print_test_result(result, expected=False, exp_str='',
got_str='')
- self.assertFalse(err.empty())
+ self.assertNotEmpty(err)
printer, err, out = self.get_printer(['--print',
'trace-unexpected'])
result = self.get_result("passes/text.html")
printer.print_test_result(result, expected=False, exp_str='',
got_str='')
- self.assertFalse(err.empty())
+ self.assertNotEmpty(err)
- err.reset()
+ printer, err, out = self.get_printer(['--print',
+ 'trace-unexpected'])
+ result = self.get_result("passes/text.html")
printer.print_test_result(result, expected=False, exp_str='',
got_str='')
- self.assertFalse(err.empty())
+ self.assertNotEmpty(err)
printer, err, out = self.get_printer(['--print', 'trace-everything'])
result = self.get_result('passes/image.html')
result = self.get_result('failures/expected/missing_image.html')
printer.print_test_result(result, expected=True, exp_str='',
got_str='')
- self.assertFalse(err.empty())
+ self.assertNotEmpty(err)
- err.reset()
+ printer, err, out = self.get_printer(['--print', 'trace-everything'])
+ result = self.get_result('passes/image.html')
printer.print_test_result(result, expected=False, exp_str='',
got_str='')
# First, test that we print nothing.
printer.print_progress(rs, False, paths)
- self.assertTrue(out.empty())
- self.assertTrue(err.empty())
+ self.assertEmpty(out)
+ self.assertEmpty(err)
printer.print_progress(rs, True, paths)
- self.assertTrue(out.empty())
- self.assertTrue(err.empty())
+ self.assertEmpty(out)
+ self.assertEmpty(err)
self.times = [1, 2, 12, 13, 14, 23, 33]
printer, err, out = self.get_printer(['--print', 'one-line-progress'])
printer.print_progress(rs, False, paths)
printer.print_progress(rs, False, paths)
- self.assertTrue(out.empty())
- self.assertTrue(err.empty())
+ self.assertEmpty(out)
+ self.assertEmpty(err)
printer.print_progress(rs, False, paths)
- self.assertTrue(out.empty())
- self.assertFalse(err.empty())
+ self.assertEmpty(out)
+ self.assertNotEmpty(err)
- err.reset()
- out.reset()
+ self.reset(err)
+ self.reset(out)
printer.print_progress(rs, True, paths)
- self.assertTrue(out.empty())
- self.assertTrue(err.empty())
+ self.assertEmpty(out)
+ self.assertEmpty(err)
printer.print_progress(rs, True, paths)
- self.assertTrue(out.empty())
- self.assertFalse(err.empty())
+ self.assertEmpty(out)
+ self.assertNotEmpty(err)
# Now reconfigure the printer to test printing to a TTY instead of a file.
self.times = [1, 1.01, 2, 3]
printer, err, out = self.get_printer(['--print', 'one-line-progress'], tty=True)
printer.print_progress(rs, False, paths)
printer.print_progress(rs, False, paths)
- self.assertTrue(out.empty())
- self.assertTrue(err.empty())
+ self.assertEmpty(out)
+ self.assertEmpty(err)
printer.print_progress(rs, False, paths)
- self.assertTrue(out.empty())
- self.assertFalse(err.empty())
+ self.assertEmpty(out)
+ self.assertNotEmpty(err)
- err.reset()
- out.reset()
+ self.reset(err)
+ self.reset(out)
printer.print_progress(rs, True, paths)
- self.assertTrue(out.empty())
- self.assertFalse(err.empty())
+ self.assertEmpty(out)
+ self.assertNotEmpty(err)
finally:
time.time = orig_time
def test_write_nothing(self):
printer, err, out = self.get_printer(['--print', 'nothing'])
printer.write("foo")
- self.assertTrue(err.empty())
+ self.assertEmpty(err)
def test_write_misc(self):
printer, err, out = self.get_printer(['--print', 'misc'])
printer.write("foo")
- self.assertFalse(err.empty())
- err.reset()
+ self.assertNotEmpty(err)
+
+ printer, err, out = self.get_printer(['--print', 'misc'])
printer.write("foo", "config")
- self.assertTrue(err.empty())
+ self.assertEmpty(err)
def test_write_everything(self):
printer, err, out = self.get_printer(['--print', 'everything'])
printer.write("foo")
- self.assertFalse(err.empty())
- err.reset()
+ self.assertNotEmpty(err)
+
+ printer, err, out = self.get_printer(['--print', 'everything'])
printer.write("foo", "config")
- self.assertFalse(err.empty())
+ self.assertNotEmpty(err)
def test_write_verbose(self):
printer, err, out = self.get_printer(['--verbose'])
printer.write("foo")
- self.assertTrue(not err.empty() and "foo" in err.get()[0])
- self.assertTrue(out.empty())
+ self.assertTrue("foo" in err.buflist[0])
+ self.assertEmpty(out)
def test_print_unexpected_results(self):
# This routine is the only one that prints stuff that the bots
printer, err, out = self.get_printer(['--print', 'nothing'])
ur = get_unexpected_results(expected=False, passing=False, flaky=False)
printer.print_unexpected_results(ur)
- self.assertTrue(err.empty())
- self.assertTrue(out.empty())
+ self.assertEmpty(err)
+ self.assertEmpty(out)
printer, err, out = self.get_printer(['--print', 'unexpected-results'])
# test everything running as expected
ur = get_unexpected_results(expected=True, passing=False, flaky=False)
printer.print_unexpected_results(ur)
- self.assertTrue(err.empty())
- self.assertTrue(out.empty())
+ self.assertEmpty(err)
+ self.assertEmpty(out)
# test failures
- err.reset()
- out.reset()
+ printer, err, out = self.get_printer(['--print', 'unexpected-results'])
ur = get_unexpected_results(expected=False, passing=False, flaky=False)
printer.print_unexpected_results(ur)
- self.assertTrue(err.empty())
- self.assertFalse(out.empty())
+ self.assertEmpty(err)
+ self.assertNotEmpty(out)
# test unexpected flaky
- err.reset()
- out.reset()
+ printer, err, out = self.get_printer(['--print', 'unexpected-results'])
ur = get_unexpected_results(expected=False, passing=False, flaky=True)
printer.print_unexpected_results(ur)
- self.assertTrue(err.empty())
- self.assertFalse(out.empty())
+ self.assertEmpty(err)
+ self.assertNotEmpty(out)
- err.reset()
- out.reset()
printer, err, out = self.get_printer(['--print', 'everything'])
ur = get_unexpected_results(expected=False, passing=False, flaky=False)
printer.print_unexpected_results(ur)
- self.assertTrue(err.empty())
- self.assertFalse(out.empty())
+ self.assertEmpty(err)
+ self.assertNotEmpty(out)
expectations = """
BUGX : failures/expected/crash.html = CRASH
BUGX : failures/expected/timeout.html = TIMEOUT
"""
- err.reset()
- out.reset()
+ printer, err, out = self.get_printer(['--print', 'unexpected-results'])
ur = get_unexpected_results(expected=False, passing=False, flaky=False)
printer.print_unexpected_results(ur)
- self.assertTrue(err.empty())
- self.assertFalse(out.empty())
+ self.assertEmpty(err)
+ self.assertNotEmpty(out)
- err.reset()
- out.reset()
+ printer, err, out = self.get_printer(['--print', 'unexpected-results'])
ur = get_unexpected_results(expected=False, passing=True, flaky=False)
printer.print_unexpected_results(ur)
- self.assertTrue(err.empty())
- self.assertFalse(out.empty())
+ self.assertEmpty(err)
+ self.assertNotEmpty(out)
# Test handling of --verbose as well.
- err.reset()
- out.reset()
printer, err, out = self.get_printer(['--verbose'])
ur = get_unexpected_results(expected=False, passing=False, flaky=False)
printer.print_unexpected_results(ur)
# FIXME: debug output from the port and scm objects may or may not go
# to stderr, so there's no point in testing its contents here.
- self.assertFalse(out.empty())
+ self.assertNotEmpty(out)
def test_print_unexpected_results_buildbot(self):
# FIXME: Test that print_unexpected_results() produces the printer the
import json
import unittest
-from webkitpy.common import array_stream
from webkitpy.common.host_mock import MockHost
from webkitpy.common.system.filesystem_mock import MockFileSystem
from webkitpy.common.system.outputcapture import OutputCapture
class MainTest(unittest.TestCase):
+ def assertWritten(self, stream, contents):
+ self.assertEquals(stream.buflist, contents)
+
class TestDriver:
def run_test(self, driver_input):
text = ''
"""do nothing"""
def create_runner(self, buildbot_output=None, args=[], regular_output=None, driver_class=TestDriver):
- buildbot_output = buildbot_output or array_stream.ArrayStream()
- regular_output = regular_output or array_stream.ArrayStream()
+ buildbot_output = buildbot_output or StringIO.StringIO()
+ regular_output = regular_output or StringIO.StringIO()
options, parsed_args = PerfTestsRunner._parse_args(args)
test_port = TestPort(host=MockHost(), options=options)
self.assertFalse(self.run_test('crash.html'))
def test_run_test_set(self):
- buildbot_output = array_stream.ArrayStream()
+ buildbot_output = StringIO.StringIO()
runner = self.create_runner(buildbot_output)
dirname = runner._base_path + '/inspector/'
tests = [dirname + 'pass.html', dirname + 'silent.html', dirname + 'failed.html',
dirname + 'tonguey.html', dirname + 'timeout.html', dirname + 'crash.html']
unexpected_result_count = runner._run_tests_set(tests, runner._port)
self.assertEqual(unexpected_result_count, len(tests) - 1)
- self.assertEqual(len(buildbot_output.get()), 1)
- self.assertEqual(buildbot_output.get()[0], 'RESULT group_name: test_name= 42 ms\n')
+ self.assertWritten(buildbot_output, ['RESULT group_name: test_name= 42 ms\n'])
def test_run_test_set_kills_drt_per_run(self):
def stop(self):
TestDriverWithStopCount.stop_count += 1
- buildbot_output = array_stream.ArrayStream()
+ buildbot_output = StringIO.StringIO()
runner = self.create_runner(buildbot_output, driver_class=TestDriverWithStopCount)
dirname = runner._base_path + '/inspector/'
def start(self):
TestDriverWithStartCount.start_count += 1
- buildbot_output = array_stream.ArrayStream()
+ buildbot_output = StringIO.StringIO()
runner = self.create_runner(buildbot_output, args=["--pause-before-testing"], driver_class=TestDriverWithStartCount)
dirname = runner._base_path + '/inspector/'
self.assertEqual(logs, "Running inspector/pass.html (1 of 1)\n\n")
def test_run_test_set_for_parser_tests(self):
- buildbot_output = array_stream.ArrayStream()
+ buildbot_output = StringIO.StringIO()
runner = self.create_runner(buildbot_output)
tests = [runner._base_path + '/Bindings/event-target-wrapper.html', runner._base_path + '/Parser/some-parser.html']
unexpected_result_count = runner._run_tests_set(tests, runner._port)
self.assertEqual(unexpected_result_count, 0)
- self.assertEqual(buildbot_output.get()[0], 'RESULT Bindings: event-target-wrapper= 1489.05 ms\n')
- self.assertEqual(buildbot_output.get()[1], 'median= 1487.0 ms, stdev= 14.46 ms, min= 1471.0 ms, max= 1510.0 ms\n')
- self.assertEqual(buildbot_output.get()[2], 'RESULT Parser: some-parser= 1100.0 ms\n')
- self.assertEqual(buildbot_output.get()[3], 'median= 1101.0 ms, stdev= 11.0 ms, min= 1080.0 ms, max= 1120.0 ms\n')
+ self.assertWritten(buildbot_output, ['RESULT Bindings: event-target-wrapper= 1489.05 ms\n',
+ 'median= 1487.0 ms, stdev= 14.46 ms, min= 1471.0 ms, max= 1510.0 ms\n',
+ 'RESULT Parser: some-parser= 1100.0 ms\n',
+ 'median= 1101.0 ms, stdev= 11.0 ms, min= 1080.0 ms, max= 1120.0 ms\n'])
def test_run_test_set_with_json_output(self):
- buildbot_output = array_stream.ArrayStream()
+ buildbot_output = StringIO.StringIO()
runner = self.create_runner(buildbot_output, args=['--output-json-path=/mock-checkout/output.json'])
runner._host.filesystem.files[runner._base_path + '/inspector/pass.html'] = True
runner._host.filesystem.files[runner._base_path + '/Bindings/event-target-wrapper.html'] = True
runner._timestamp = 123456789
self.assertEqual(runner.run(), 0)
- self.assertEqual(len(buildbot_output.get()), 3)
- self.assertEqual(buildbot_output.get()[0], 'RESULT Bindings: event-target-wrapper= 1489.05 ms\n')
- self.assertEqual(buildbot_output.get()[1], 'median= 1487.0 ms, stdev= 14.46 ms, min= 1471.0 ms, max= 1510.0 ms\n')
- self.assertEqual(buildbot_output.get()[2], 'RESULT group_name: test_name= 42 ms\n')
+ self.assertWritten(buildbot_output, ['RESULT Bindings: event-target-wrapper= 1489.05 ms\n',
+ 'median= 1487.0 ms, stdev= 14.46 ms, min= 1471.0 ms, max= 1510.0 ms\n',
+ 'RESULT group_name: test_name= 42 ms\n'])
self.assertEqual(json.loads(runner._host.filesystem.files['/mock-checkout/output.json']), {
"timestamp": 123456789, "results":
"webkit-revision": 5678})
def test_run_test_set_with_json_source(self):
- buildbot_output = array_stream.ArrayStream()
+ buildbot_output = StringIO.StringIO()
runner = self.create_runner(buildbot_output, args=['--output-json-path=/mock-checkout/output.json',
'--source-json-path=/mock-checkout/source.json'])
runner._host.filesystem.files['/mock-checkout/source.json'] = '{"key": "value"}'
runner._host.filesystem.files[runner._base_path + '/Bindings/event-target-wrapper.html'] = True
runner._timestamp = 123456789
self.assertEqual(runner.run(), 0)
- self.assertEqual(len(buildbot_output.get()), 3)
- self.assertEqual(buildbot_output.get()[0], 'RESULT Bindings: event-target-wrapper= 1489.05 ms\n')
- self.assertEqual(buildbot_output.get()[1], 'median= 1487.0 ms, stdev= 14.46 ms, min= 1471.0 ms, max= 1510.0 ms\n')
- self.assertEqual(buildbot_output.get()[2], 'RESULT group_name: test_name= 42 ms\n')
+ self.assertWritten(buildbot_output, ['RESULT Bindings: event-target-wrapper= 1489.05 ms\n',
+ 'median= 1487.0 ms, stdev= 14.46 ms, min= 1471.0 ms, max= 1510.0 ms\n',
+ 'RESULT group_name: test_name= 42 ms\n'])
self.assertEqual(json.loads(runner._host.filesystem.files['/mock-checkout/output.json']), {
"timestamp": 123456789, "results":
"key": "value"})
def test_run_test_set_with_multiple_repositories(self):
- buildbot_output = array_stream.ArrayStream()
+ buildbot_output = StringIO.StringIO()
runner = self.create_runner(buildbot_output, args=['--output-json-path=/mock-checkout/output.json'])
runner._host.filesystem.files[runner._base_path + '/inspector/pass.html'] = True
runner._timestamp = 123456789
self.assertEqual(runner.run(), -3)
def test_upload_json(self):
- regular_output = array_stream.ArrayStream()
+ regular_output = StringIO.StringIO()
runner = self.create_runner(regular_output=regular_output)
runner._host.filesystem.files['/mock-checkout/some.json'] = 'some content'