2011-01-18 Dirk Pranke <dpranke@chromium.org>
authordpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jan 2011 21:43:15 +0000 (21:43 +0000)
committerdpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Jan 2011 21:43:15 +0000 (21:43 +0000)
        Reviewed by Ojan Vafai.

        Update rebaseline-chromium-webkit-tests unit tests to use a mock
        filesystem. Also fix a couple of "with" statements missed by
        r76050.

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

        * Scripts/webkitpy/layout_tests/rebaseline_chromium_webkit_tests_unittest.py:

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

Tools/ChangeLog
Tools/Scripts/webkitpy/layout_tests/rebaseline_chromium_webkit_tests.py
Tools/Scripts/webkitpy/layout_tests/rebaseline_chromium_webkit_tests_unittest.py

index 9bed6bbfedbfc415eacd14fdbd63ef57435abdd5..2f7e9d6f3ef3d5dbd4227b779ed97fb0939436a1 100644 (file)
@@ -1,3 +1,15 @@
+2011-01-18  Dirk Pranke  <dpranke@chromium.org>
+
+        Reviewed by Ojan Vafai.
+
+        Update rebaseline-chromium-webkit-tests unit tests to use a mock
+        filesystem. Also fix a couple of "with" statements missed by
+        r76050.
+
+        https://bugs.webkit.org/show_bug.cgi?id=52487
+
+        * Scripts/webkitpy/layout_tests/rebaseline_chromium_webkit_tests_unittest.py:
+
 2011-01-18  Sergio Villar Senin  <svillar@igalia.com>
 
         Reviewed by Martin Robinson.
index 7641f55d2fa266d35ed1621463fa376e21a94955..848079e36c8a9ca3aa65bcce08ad6cafeaa84124 100644 (file)
@@ -554,9 +554,10 @@ class Rebaseliner(object):
         base_file = get_result_file_fullpath(self._filesystem, self._options.html_directory,
                                              baseline_filename, self._platform,
                                              'old')
-        # We should be using an explicit encoding here.
-        with open(base_file, "wb") as file:
-            file.write(output)
+        if base_file.upper().endswith('.PNG'):
+            self._filesystem.write_binary_file(base_file, output)
+        else:
+            self._filesystem.write_text_file(base_file, output)
         _log.info('  Html: created old baseline file: "%s".',
                   base_file)
 
@@ -567,8 +568,7 @@ class Rebaseliner(object):
                 diff_file = get_result_file_fullpath(self._filesystem,
                     self._options.html_directory, baseline_filename,
                     self._platform, 'diff')
-                with open(diff_file, 'wb') as file:
-                    file.write(output)
+                self._filesystem.write_text_file(diff_file, output)
                 _log.info('  Html: created baseline diff file: "%s".',
                           diff_file)
 
index 6c4c68925ce09c1adb5157b0ac5a75b799b5511b..50c02043b8449849a702c8745ef002ae7cd7ad7d 100644 (file)
 
 """Unit tests for rebaseline_chromium_webkit_tests.py."""
 
-import sys
 import unittest
 
 from webkitpy.tool import mocktool
+from webkitpy.common.system import filesystem_mock
 from webkitpy.common.system.executive import Executive, ScriptError
 
 import port
@@ -88,9 +88,10 @@ class TestRebaseliner(unittest.TestCase):
     def make_rebaseliner(self):
         options = mocktool.MockOptions(configuration=None,
                                        html_directory=None)
-        host_port_obj = port.get('test', options)
+        filesystem = filesystem_mock.MockFileSystem()
+        host_port_obj = port.get('test', options, filesystem=filesystem)
         target_options = options
-        target_port_obj = port.get('test', target_options)
+        target_port_obj = port.get('test', target_options, filesystem=filesystem)
         platform = 'test'
         return rebaseline_chromium_webkit_tests.Rebaseliner(
             host_port_obj, target_port_obj, platform, options)
@@ -128,9 +129,9 @@ class TestRebaseliner(unittest.TestCase):
 
 
 class TestHtmlGenerator(unittest.TestCase):
-    def make_generator(self, tests):
+    def make_generator(self, files, tests):
         options = mocktool.MockOptions(configuration=None, html_directory='/tmp')
-        host_port = port.get('test', options)
+        host_port = port.get('test', options, filesystem=filesystem_mock.MockFileSystem(files))
         generator = rebaseline_chromium_webkit_tests.HtmlGenerator(
             host_port,
             target_port=None,
@@ -140,17 +141,16 @@ class TestHtmlGenerator(unittest.TestCase):
         return generator, host_port
 
     def test_generate_baseline_links(self):
-        orig_platform = sys.platform
-        try:
-            # FIXME: Use the mock filesystem instead of monkey-patching sys.platform
-            sys.platform = 'darwin'
-            generator, host_port = self.make_generator(["foo.txt"])
-            host_port._filesystem.exists = lambda x: True
-            links = generator._generate_baseline_links("foo", ".txt", "mac")
-            expected_links = '<td align=center><a href="file:///tmp/foo-expected-mac-old.txt">foo-expected.txt</a></td><td align=center><a href="file:///tmp/foo-expected-mac-new.txt">foo-expected.txt</a></td><td align=center><a href="file:///tmp/foo-expected-mac-diff.txt">Diff</a></td>'
-            self.assertEqual(links, expected_links)
-        finally:
-            sys.platform = orig_platform
+        files = {
+            "/tmp/foo-expected-mac-old.txt": "",
+            "/tmp/foo-expected-mac-new.txt": "",
+            "/tmp/foo-expected-mac-diff.txt": "",
+        }
+        tests = ["foo.txt"]
+        generator, host_port = self.make_generator(files, tests)
+        links = generator._generate_baseline_links("foo", ".txt", "mac")
+        expected_links = '<td align=center><a href="file:///tmp/foo-expected-mac-old.txt">foo-expected.txt</a></td><td align=center><a href="file:///tmp/foo-expected-mac-new.txt">foo-expected.txt</a></td><td align=center><a href="file:///tmp/foo-expected-mac-diff.txt">Diff</a></td>'
+        self.assertEqual(links, expected_links)
 
 
 if __name__ == '__main__':