test-webkitpy: move printing-related code out of the runner
authordpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Jul 2012 23:39:13 +0000 (23:39 +0000)
committerdpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Jul 2012 23:39:13 +0000 (23:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=91289

Reviewed by Ryosuke Niwa.

More refactoring ... this moves all printing-related stuff out
of runner.py and into printer.py.

No functional changes; covered by existing tests.

* Scripts/webkitpy/test/main.py:
(Tester._run_tests):
* Scripts/webkitpy/test/printer.py:
(Printer.__init__):
(Printer):
(Printer.test_name):
(Printer.print_started_test):
(Printer.print_finished_test):
(Printer.print_result):
* Scripts/webkitpy/test/runner.py:
(Runner.__init__):
(Runner.all_test_names):
(Runner.run):
* Scripts/webkitpy/test/runner_unittest.py:
(RunnerTest.test_regular):
(RunnerTest.test_verbose):
(RunnerTest.test_timing):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@122645 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/test/main.py
Tools/Scripts/webkitpy/test/printer.py
Tools/Scripts/webkitpy/test/runner.py
Tools/Scripts/webkitpy/test/runner_unittest.py

index cfb08eb..a0aca09 100644 (file)
@@ -1,5 +1,35 @@
 2012-07-13  Dirk Pranke  <dpranke@chromium.org>
 
+        test-webkitpy: move printing-related code out of the runner
+        https://bugs.webkit.org/show_bug.cgi?id=91289
+
+        Reviewed by Ryosuke Niwa.
+
+        More refactoring ... this moves all printing-related stuff out
+        of runner.py and into printer.py.
+
+        No functional changes; covered by existing tests.
+
+        * Scripts/webkitpy/test/main.py:
+        (Tester._run_tests):
+        * Scripts/webkitpy/test/printer.py:
+        (Printer.__init__):
+        (Printer):
+        (Printer.test_name):
+        (Printer.print_started_test):
+        (Printer.print_finished_test):
+        (Printer.print_result):
+        * Scripts/webkitpy/test/runner.py:
+        (Runner.__init__):
+        (Runner.all_test_names):
+        (Runner.run):
+        * Scripts/webkitpy/test/runner_unittest.py:
+        (RunnerTest.test_regular):
+        (RunnerTest.test_verbose):
+        (RunnerTest.test_timing):
+
+2012-07-13  Dirk Pranke  <dpranke@chromium.org>
+
         webkitpy: split printing/logging code for test-webkitpy out into a new class
         https://bugs.webkit.org/show_bug.cgi?id=91282
 
index 707fac2..2048d9e 100644 (file)
@@ -114,7 +114,7 @@ class Tester(object):
             suites.append(loader.loadTestsFromName(name, None))
 
         test_suite = unittest.TestSuite(suites)
-        test_runner = Runner(self.printer.stream, self._options, loader)
+        test_runner = Runner(self.printer, self._options, loader)
 
         _log.debug("Running the tests.")
         result = test_runner.run(test_suite)
index b48d337..77e28b8 100644 (file)
@@ -22,6 +22,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 import logging
+import re
 import StringIO
 
 from webkitpy.common.system import outputcapture
@@ -33,6 +34,11 @@ class Printer(object):
     def __init__(self, stream, options=None):
         self.stream = stream
         self.options = options
+        self.test_description = re.compile("(\w+) \(([\w.]+)\)")
+
+    def test_name(self, test):
+        m = self.test_description.match(str(test))
+        return "%s.%s" % (m.group(2), m.group(1))
 
     def configure(self, options):
         self.options = options
@@ -92,6 +98,60 @@ class Printer(object):
         if self.options.pass_through:
             outputcapture.OutputCapture.stream_wrapper = _CaptureAndPassThroughStream
 
+    def print_started_test(self, test_name):
+        if self.options.verbose:
+            self.stream.write(test_name)
+
+    def print_finished_test(self, result, test_name, test_time, failure, err):
+        timing = ''
+        if self.options.timing:
+            timing = ' %.4fs' % test_time
+        if self.options.verbose:
+            if failure:
+                msg = ' failed'
+            elif err:
+                msg = ' erred'
+            else:
+                msg = ' passed'
+            self.stream.write(msg + timing + '\n')
+        else:
+            if failure:
+                msg = 'F'
+            elif err:
+                msg = 'E'
+            else:
+                msg = '.'
+            self.stream.write(msg)
+
+    def print_result(self, result, run_time):
+        self.stream.write('\n')
+
+        for (test, err) in result.errors:
+            self.stream.write("=" * 80 + '\n')
+            self.stream.write("ERROR: " + self.test_name(test) + '\n')
+            self.stream.write("-" * 80 + '\n')
+            for line in err.splitlines():
+                self.stream.write(line + '\n')
+            self.stream.write('\n')
+
+        for (test, failure) in result.failures:
+            self.stream.write("=" * 80 + '\n')
+            self.stream.write("FAILURE: " + self.test_name(test) + '\n')
+            self.stream.write("-" * 80 + '\n')
+            for line in failure.splitlines():
+                self.stream.write(line + '\n')
+            self.stream.write('\n')
+
+        self.stream.write('-' * 80 + '\n')
+        self.stream.write('Ran %d test%s in %.3fs\n' %
+            (result.testsRun, result.testsRun != 1 and "s" or "", run_time))
+
+        if result.wasSuccessful():
+            self.stream.write('\nOK\n')
+        else:
+            self.stream.write('FAILED (failures=%d, errors=%d)\n' %
+                (len(result.failures), len(result.errors)))
+
 
 class _CaptureAndPassThroughStream(object):
     def __init__(self, stream):
index 39414d8..9c95207 100644 (file)
@@ -23,7 +23,6 @@
 """code to actually run a list of python tests."""
 
 import logging
-import re
 import time
 import unittest
 
@@ -32,15 +31,10 @@ _log = logging.getLogger(__name__)
 
 
 class Runner(object):
-    def __init__(self, stream, options, loader):
+    def __init__(self, printer, options, loader):
         self.options = options
-        self.stream = stream
+        self.printer = printer
         self.loader = loader
-        self.test_description = re.compile("(\w+) \(([\w.]+)\)")
-
-    def test_name(self, test):
-        m = self.test_description.match(str(test))
-        return "%s.%s" % (m.group(2), m.group(1))
 
     def all_test_names(self, suite):
         names = []
@@ -48,7 +42,7 @@ class Runner(object):
             for t in suite._tests:
                 names.extend(self.all_test_names(t))
         else:
-            names.append(self.test_name(suite))
+            names.append(self.printer.test_name(suite))
         return names
 
     def run(self, suite):
@@ -57,8 +51,7 @@ class Runner(object):
         result = unittest.TestResult()
         stop = run_start_time
         for test_name in all_test_names:
-            if self.options.verbose:
-                self.stream.write(test_name)
+            self.printer.print_started_test(test_name)
             num_failures = len(result.failures)
             num_errors = len(result.errors)
 
@@ -75,58 +68,8 @@ class Runner(object):
                 failure = result.failures[num_failures][1]
             elif len(result.errors) > num_errors:
                 err = result.errors[num_errors][1]
-            self.write_result(result, test_name, stop - start, failure, err)
+            self.printer.print_finished_test(result, test_name, stop - start, failure, err)
 
-        self.write_summary(result, stop - run_start_time)
+        self.printer.print_result(result, stop - run_start_time)
 
         return result
-
-    def write_result(self, result, test_name, test_time, failure=None, err=None):
-        timing = ''
-        if self.options.timing:
-            timing = ' %.4fs' % test_time
-        if self.options.verbose:
-            if failure:
-                msg = ' failed'
-            elif err:
-                msg = ' erred'
-            else:
-                msg = ' passed'
-            self.stream.write(msg + timing + '\n')
-        else:
-            if failure:
-                msg = 'F'
-            elif err:
-                msg = 'E'
-            else:
-                msg = '.'
-            self.stream.write(msg)
-
-    def write_summary(self, result, run_time):
-        self.stream.write('\n')
-
-        for (test, err) in result.errors:
-            self.stream.write("=" * 80 + '\n')
-            self.stream.write("ERROR: " + self.test_name(test) + '\n')
-            self.stream.write("-" * 80 + '\n')
-            for line in err.splitlines():
-                self.stream.write(line + '\n')
-            self.stream.write('\n')
-
-        for (test, failure) in result.failures:
-            self.stream.write("=" * 80 + '\n')
-            self.stream.write("FAILURE: " + self.test_name(test) + '\n')
-            self.stream.write("-" * 80 + '\n')
-            for line in failure.splitlines():
-                self.stream.write(line + '\n')
-            self.stream.write('\n')
-
-        self.stream.write('-' * 80 + '\n')
-        self.stream.write('Ran %d test%s in %.3fs\n' %
-            (result.testsRun, result.testsRun != 1 and "s" or "", run_time))
-
-        if result.wasSuccessful():
-            self.stream.write('\nOK\n')
-        else:
-            self.stream.write('FAILED (failures=%d, errors=%d)\n' %
-                (len(result.failures), len(result.errors)))
index 22cef88..1cf0146 100644 (file)
@@ -25,6 +25,7 @@ import StringIO
 import unittest
 
 from webkitpy.tool.mocktool import MockOptions
+from webkitpy.test.printer import Printer
 from webkitpy.test.runner import Runner
 
 
@@ -74,7 +75,7 @@ class RunnerTest(unittest.TestCase):
         loader = FakeLoader(('test1 (Foo)', '.', ''),
                             ('test2 (Foo)', 'F', 'test2\nfailed'),
                             ('test3 (Foo)', 'E', 'test3\nerred'))
-        result = Runner(stream, options, loader).run(loader.top_suite())
+        result = Runner(Printer(stream, options), options, loader).run(loader.top_suite())
         self.assertFalse(result.wasSuccessful())
         self.assertEquals(result.testsRun, 3)
         self.assertEquals(len(result.failures), 1)
@@ -87,7 +88,7 @@ class RunnerTest(unittest.TestCase):
         loader = FakeLoader(('test1 (Foo)', '.', ''),
                             ('test2 (Foo)', 'F', 'test2\nfailed'),
                             ('test3 (Foo)', 'E', 'test3\nerred'))
-        result = Runner(stream, options, loader).run(loader.top_suite())
+        result = Runner(Printer(stream, options), options, loader).run(loader.top_suite())
         self.assertFalse(result.wasSuccessful())
         self.assertEquals(result.testsRun, 3)
         self.assertEquals(len(result.failures), 1)
@@ -100,7 +101,7 @@ class RunnerTest(unittest.TestCase):
         loader = FakeLoader(('test1 (Foo)', '.', ''),
                             ('test2 (Foo)', 'F', 'test2\nfailed'),
                             ('test3 (Foo)', 'E', 'test3\nerred'))
-        result = Runner(stream, options, loader).run(loader.top_suite())
+        result = Runner(Printer(stream, options), options, loader).run(loader.top_suite())
         self.assertFalse(result.wasSuccessful())
         self.assertEquals(result.testsRun, 3)
         self.assertEquals(len(result.failures), 1)