Commit e6034d22 authored by dpranke@chromium.org's avatar dpranke@chromium.org
Browse files

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:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76059 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c1e6b6bb
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.
......@@ -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)
......
......@@ -29,10 +29,10 @@
"""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__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment