2011-01-20 Dirk Pranke <dpranke@chromium.org>
authordpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Jan 2011 02:26:54 +0000 (02:26 +0000)
committerdpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Jan 2011 02:26:54 +0000 (02:26 +0000)
        Reviewed by Mihai Parparita.

        remove fs refs from run_webkit_tests, rebaseline_chromium_webkit_tests

        https://bugs.webkit.org/show_bug.cgi?id=52762

        * Scripts/webkitpy/layout_tests/run_webkit_tests.py:
        * Scripts/webkitpy/layout_tests/run_webkit_tests_unittest.py:

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

Tools/ChangeLog
Tools/Scripts/webkitpy/layout_tests/run_webkit_tests.py
Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_unittest.py

index 3f53d8ccddb1457ceb0d0437d583da8f93e76eef..a0ff8fe87cf1594744b281e020759b47d8690bb5 100644 (file)
@@ -1,3 +1,14 @@
+2011-01-20  Dirk Pranke  <dpranke@chromium.org>
+
+        Reviewed by Mihai Parparita.
+
+        remove fs refs from run_webkit_tests, rebaseline_chromium_webkit_tests
+
+        https://bugs.webkit.org/show_bug.cgi?id=52762
+
+        * Scripts/webkitpy/layout_tests/run_webkit_tests.py:
+        * Scripts/webkitpy/layout_tests/run_webkit_tests_unittest.py:
+
 2011-01-20  Tony Chang  <tony@chromium.org>
 
         Reviewed by Ojan Vafai.
index c801fd17a1d49635adb5aa4c0da37082f738bef2..17b6e89986879195cdcea350a5b8a101da77adb0 100755 (executable)
@@ -32,7 +32,6 @@
 
 from __future__ import with_statement
 
-import codecs
 import errno
 import logging
 import optparse
@@ -80,7 +79,7 @@ def run(port, options, args, regular_output=sys.stderr,
         printer.cleanup()
         return 0
 
-    last_unexpected_results = _gather_unexpected_results(port, options)
+    last_unexpected_results = _gather_unexpected_results(port._filesystem, options)
     if options.print_last_failures:
         printer.write("\n".join(last_unexpected_results) + "\n")
         printer.cleanup()
@@ -146,7 +145,7 @@ def _set_up_derived_options(port_obj, options):
     if not options.use_apache:
         options.use_apache = sys.platform in ('darwin', 'linux2')
 
-    if not os.path.isabs(options.results_directory):
+    if not port_obj._filesystem.isabs(options.results_directory):
         # This normalizes the path to the build dir.
         # FIXME: how this happens is not at all obvious; this is a dumb
         # interface and should be cleaned up.
@@ -162,15 +161,15 @@ def _set_up_derived_options(port_obj, options):
     return warnings
 
 
-def _gather_unexpected_results(port, options):
+def _gather_unexpected_results(filesystem, options):
     """Returns the unexpected results from the previous run, if any."""
     last_unexpected_results = []
     if options.print_last_failures or options.retest_last_failures:
-        unexpected_results_filename = os.path.join(
-        options.results_directory, "unexpected_results.json")
-        if port._filesystem.exists(unexpected_results_filename):
-            file = port._filesystem.read_text_file(unexpected_results.json)
-            results = simplejson.load(file)
+        unexpected_results_filename = filesystem.join(
+            options.results_directory, "unexpected_results.json")
+        if filesystem.exists(unexpected_results_filename):
+            content = filesystem.read_text_file(unexpected_results_filename)
+            results = simplejson.loads(content)
             last_unexpected_results = results['tests'].keys()
     return last_unexpected_results
 
index f2ff82f529d77cd4568eb98164fa34c9b5ac6e77..ffc97dd860d8fdb90e6a8f47cc403b113892ff9a 100644 (file)
 
 """Unit tests for run_webkit_tests."""
 
+from __future__ import with_statement
+
 import codecs
 import itertools
 import logging
-import os
 import Queue
-import shutil
 import sys
-import tempfile
 import thread
 import time
 import threading
@@ -45,6 +44,7 @@ import unittest
 
 from webkitpy.common import array_stream
 from webkitpy.common.system import outputcapture
+from webkitpy.common.system import filesystem_mock
 from webkitpy.common.system import user
 from webkitpy.layout_tests import port
 from webkitpy.layout_tests import run_webkit_tests
@@ -88,12 +88,12 @@ def parse_args(extra_args=None, record_results=False, tests_included=False,
 
 
 def passing_run(extra_args=None, port_obj=None, record_results=False,
-                tests_included=False):
+                tests_included=False, filesystem=None):
     options, parsed_args = parse_args(extra_args, record_results,
                                       tests_included)
     if not port_obj:
         port_obj = port.get(port_name=options.platform, options=options,
-                            user=MockUser())
+                            user=MockUser(), filesystem=filesystem)
     res = run_webkit_tests.run(port_obj, options, parsed_args)
     return res == 0
 
@@ -239,9 +239,10 @@ class MainTest(unittest.TestCase):
             ['failures/expected/keyboard.html'], tests_included=True)
 
     def test_last_results(self):
-        passing_run(['--clobber-old-results'], record_results=True)
+        fs = port.unit_test_filesystem()
+        passing_run(['--clobber-old-results'], record_results=True, filesystem=fs)
         (res, buildbot_output, regular_output, user) = logging_run(
-            ['--print-last-failures'])
+            ['--print-last-failures'], filesystem=fs)
         self.assertEqual(regular_output.get(), ['\n\n'])
         self.assertEqual(buildbot_output.get(), [])
 
@@ -338,7 +339,7 @@ class MainTest(unittest.TestCase):
     def test_test_list_with_prefix(self):
         fs = port.unit_test_filesystem()
         filename = '/tmp/foo.txt'
-        fs.write_text_file(filename, 'passes/text.html')
+        fs.write_text_file(filename, 'LayoutTests/passes/text.html')
         tests_run = get_tests_run(['--test-list=%s' % filename], tests_included=True, flatten_batches=True, filesystem=fs)
         self.assertEquals(['passes/text.html'], tests_run)
 
@@ -407,11 +408,11 @@ class MainTest(unittest.TestCase):
         # We run a configuration that should fail, to generate output, then
         # look for what the output results url was.
 
-        tmpdir = tempfile.mkdtemp()
-        res, out, err, user = logging_run(['--results-directory=' + tmpdir],
-                                          tests_included=True)
-        self.assertEqual(user.url, os.path.join(tmpdir, 'results.html'))
-        shutil.rmtree(tmpdir, ignore_errors=True)
+        fs = port.unit_test_filesystem()
+        with fs.mkdtemp() as tmpdir:
+            res, out, err, user = logging_run(['--results-directory=' + str(tmpdir)],
+                                              tests_included=True, filesystem=fs)
+            self.assertEqual(user.url, fs.join(tmpdir, 'results.html'))
 
     def test_results_directory_default(self):
         # We run a configuration that should fail, to generate output, then
@@ -468,18 +469,6 @@ class MainTest(unittest.TestCase):
 MainTest = skip_if(MainTest, sys.platform == 'cygwin' and compare_version(sys, '2.6')[0] < 0, 'new-run-webkit-tests tests hang on Cygwin Python 2.5.2')
 
 
-
-def _mocked_open(original_open, file_list):
-    def _wrapper(name, mode, encoding):
-        if name.find("-expected.") != -1 and mode.find("w") != -1:
-            # we don't want to actually write new baselines, so stub these out
-            name.replace('\\', '/')
-            file_list.append(name)
-            return original_open(os.devnull, mode, encoding)
-        return original_open(name, mode, encoding)
-    return _wrapper
-
-
 class RebaselineTest(unittest.TestCase):
     def assertBaselines(self, file_list, file):
         "assert that the file_list contains the baselines."""
@@ -490,49 +479,39 @@ class RebaselineTest(unittest.TestCase):
     # FIXME: Add tests to ensure that we're *not* writing baselines when we're not
     # supposed to be.
 
-    def disabled_test_reset_results(self):
-        # FIXME: This test is disabled until we can rewrite it to use a
-        # mock filesystem.
-        #
+    def test_reset_results(self):
         # Test that we update expectations in place. If the expectation
         # is missing, update the expected generic location.
-        file_list = []
+        fs = port.unit_test_filesystem()
         passing_run(['--pixel-tests',
                         '--reset-results',
                         'passes/image.html',
                         'failures/expected/missing_image.html'],
-                        tests_included=True)
+                        tests_included=True, filesystem=fs)
+        file_list = fs.written_files.keys()
+        file_list.remove('/tmp/layout-test-results/tests_run.txt')
         self.assertEqual(len(file_list), 6)
         self.assertBaselines(file_list,
-            "data/passes/image")
+            "/passes/image")
         self.assertBaselines(file_list,
-            "data/failures/expected/missing_image")
+            "/failures/expected/missing_image")
 
-    def disabled_test_new_baseline(self):
-        # FIXME: This test is disabled until we can rewrite it to use a
-        # mock filesystem.
-        #
+    def test_new_baseline(self):
         # Test that we update the platform expectations. If the expectation
         # is mssing, then create a new expectation in the platform dir.
-        file_list = []
-        original_open = codecs.open
-        try:
-            # Test that we update the platform expectations. If the expectation
-            # is mssing, then create a new expectation in the platform dir.
-            file_list = []
-            codecs.open = _mocked_open(original_open, file_list)
-            passing_run(['--pixel-tests',
-                         '--new-baseline',
-                         'passes/image.html',
-                         'failures/expected/missing_image.html'],
-                        tests_included=True)
-            self.assertEqual(len(file_list), 6)
-            self.assertBaselines(file_list,
-                "data/platform/test/passes/image")
-            self.assertBaselines(file_list,
-                "data/platform/test/failures/expected/missing_image")
-        finally:
-            codecs.open = original_open
+        fs = port.unit_test_filesystem()
+        passing_run(['--pixel-tests',
+                        '--new-baseline',
+                        'passes/image.html',
+                        'failures/expected/missing_image.html'],
+                    tests_included=True, filesystem=fs)
+        file_list = fs.written_files.keys()
+        file_list.remove('/tmp/layout-test-results/tests_run.txt')
+        self.assertEqual(len(file_list), 6)
+        self.assertBaselines(file_list,
+            "/platform/test/passes/image")
+        self.assertBaselines(file_list,
+            "/platform/test/failures/expected/missing_image")
 
 
 class DryrunTest(unittest.TestCase):