2011-01-25 Dirk Pranke <dpranke@chromium.org>
authordpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Jan 2011 22:52:17 +0000 (22:52 +0000)
committerdpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Jan 2011 22:52:17 +0000 (22:52 +0000)
        Reviewed by Tony Chang.

        Minor bug fixes and cleanup for filesystem wrappers, port/* test
        classes, test_expectations.py. This change adds "test-win" and
        "test-mac" variants to the test port so that we can better test
        rebaselining, and adds a MockUser() object for reuse in testing.

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

        * Scripts/webkitpy/common/system/filesystem.py:
        * Scripts/webkitpy/common/system/filesystem_mock.py:
        * Scripts/webkitpy/layout_tests/layout_package/test_expectations.py:
        * Scripts/webkitpy/layout_tests/port/factory.py:
        * Scripts/webkitpy/layout_tests/port/base.py:
        * Scripts/webkitpy/layout_tests/port/test.py:
        * Scripts/webkitpy/layout_tests/run_webkit_tests_unittest.py:
        * Scripts/webkitpy/layout_tests/rebaseline_chromium_webkit_tests_unittest.py:
        * Scripts/webkitpy/tool/mocktool.py:

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

Tools/ChangeLog
Tools/Scripts/webkitpy/common/system/filesystem.py
Tools/Scripts/webkitpy/common/system/filesystem_mock.py
Tools/Scripts/webkitpy/layout_tests/layout_package/test_expectations.py
Tools/Scripts/webkitpy/layout_tests/port/base.py
Tools/Scripts/webkitpy/layout_tests/port/factory.py
Tools/Scripts/webkitpy/layout_tests/port/test.py
Tools/Scripts/webkitpy/layout_tests/rebaseline_chromium_webkit_tests_unittest.py
Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_unittest.py
Tools/Scripts/webkitpy/tool/mocktool.py

index c1981161e2a473f65a0dae18d235dc0af5b6fb68..8486da01873af593f927fa4df6f294afc8aba973 100644 (file)
@@ -1,3 +1,24 @@
+2011-01-25  Dirk Pranke  <dpranke@chromium.org>
+
+        Reviewed by Tony Chang.
+
+        Minor bug fixes and cleanup for filesystem wrappers, port/* test
+        classes, test_expectations.py. This change adds "test-win" and
+        "test-mac" variants to the test port so that we can better test
+        rebaselining, and adds a MockUser() object for reuse in testing.
+
+        https://bugs.webkit.org/show_bug.cgi?id=53036
+
+        * Scripts/webkitpy/common/system/filesystem.py:
+        * Scripts/webkitpy/common/system/filesystem_mock.py:
+        * Scripts/webkitpy/layout_tests/layout_package/test_expectations.py:
+        * Scripts/webkitpy/layout_tests/port/factory.py:
+        * Scripts/webkitpy/layout_tests/port/base.py:
+        * Scripts/webkitpy/layout_tests/port/test.py:
+        * Scripts/webkitpy/layout_tests/run_webkit_tests_unittest.py:
+        * Scripts/webkitpy/layout_tests/rebaseline_chromium_webkit_tests_unittest.py:
+        * Scripts/webkitpy/tool/mocktool.py:
+
 2011-01-25  Tony Chang  <tony@chromium.org>
 
         Reviewed by Dimitri Glazkov.
index 05513a957c8519f1217ebedeb2d3adcb378b9148..b15d4c3f648c14a873b43ad8c433be60ac8c7c37 100644 (file)
@@ -165,8 +165,8 @@ class FileSystem(object):
             if e.errno != errno.EEXIST:
                 raise
 
-    def move(self, src, dest):
-        shutil.move(src, dest)
+    def move(self, source, destination):
+        shutil.move(source, destination)
 
     def mtime(self, path):
         return os.stat(path).st_mtime
index 0004944994f4b73547743e0ad178075ab9c2ed60..8ec31def3ff0dc124f2580f6335bc241fc1d2350 100644 (file)
@@ -69,6 +69,7 @@ class MockFileSystem(object):
             raise IOError(errno.EISDIR, destination, os.strerror(errno.ISDIR))
 
         self.files[destination] = self.files[source]
+        self.written_files[destination] = self.files[source]
 
     def dirname(self, path):
         return self._split(path)[0]
@@ -196,18 +197,20 @@ class MockFileSystem(object):
         # FIXME: Implement such that subsequent calls to isdir() work?
         pass
 
-    def move(self, src, dst):
-        if self.files[src] is None:
-            self._raise_not_found(src)
-        self.files[dst] = self.files[src]
-        self.files[src] = None
+    def move(self, source, destination):
+        if self.files[source] is None:
+            self._raise_not_found(source)
+        self.files[destination] = self.files[source]
+        self.written_files[destination] = self.files[destination]
+        self.files[source] = None
+        self.written_files[source] = None
 
     def normpath(self, path):
         return path
 
-    def open_binary_tempfile(self, suffix):
+    def open_binary_tempfile(self, suffix=''):
         path = self._mktemp(suffix)
-        return WritableFileObject(self, path), path
+        return (WritableFileObject(self, path), path)
 
     def open_text_file_for_writing(self, path, append=False):
         return WritableFileObject(self, path, append)
@@ -225,6 +228,7 @@ class MockFileSystem(object):
         if self.files[path] is None:
             self._raise_not_found(path)
         self.files[path] = None
+        self.written_files[path] = None
 
     def rmtree(self, path):
         if not path.endswith('/'):
index 806b66347180a8c01c08feedc80b3ff025552468..acadcb3fae1d5ccf05290cbac9cd6e42f9753674 100644 (file)
@@ -89,7 +89,7 @@ class TestExpectations:
         """Loads and parses the test expectations given in the string.
         Args:
             port: handle to object containing platform-specific functionality
-            test: list of all of the test files
+            tests: list of all of the test files
             expectations: test expectations as a string
             test_platform_name: name of the platform to match expectations
                 against. Note that this may be different than
index 6e5fabc0d4f364a3d5a37b2fc8e1eea01bc472ef..aeebc668688210c8e03a1c60288d89bb5a02bde7 100644 (file)
@@ -582,7 +582,7 @@ class Port(object):
 
         Basically this string should contain the equivalent of a
         test_expectations file. See test_expectations.py for more details."""
-        raise NotImplementedError('Port.test_expectations')
+        return self._filesystem.read_text_file(self.path_to_test_expectations_file())
 
     def test_expectations_overrides(self):
         """Returns an optional set of overrides for the test_expectations.
index 69357442aebe31e0a145d3c9a3e159077b104560..675e0c096889808cb850c60ed1116a916cd83b66 100644 (file)
@@ -70,7 +70,7 @@ def _get_kwargs(**kwargs):
         raise NotImplementedError('unknown port; sys.platform = "%s"' %
                                   sys.platform)
 
-    if port_to_use == 'test':
+    if port_to_use.startswith('test'):
         import test
         maker = test.TestPort
     elif port_to_use.startswith('dryrun'):
index 5df5c2d9d6219bf9469496f2574e63c18112ade4..a9d58840851b16bb607a85f7e551e6be0e30f25d 100644 (file)
@@ -33,6 +33,7 @@ from __future__ import with_statement
 import time
 
 from webkitpy.common.system import filesystem_mock
+from webkitpy.tool import mocktool
 
 from webkitpy.layout_tests.layout_package import test_output
 
@@ -192,26 +193,22 @@ WONTFIX SKIP : failures/expected/exception.html = CRASH
 class TestPort(base.Port):
     """Test implementation of the Port interface."""
 
-    def __init__(self, **kwargs):
-        # FIXME: what happens if we're not passed in the test filesystem
-        # and the tests don't match what's in the filesystem?
-        #
-        # We'll leave as is for now to avoid unnecessary dependencies while
-        # converting all of the unit tests over to using
-        # unit_test_filesystem(). If things get out of sync the tests should
-        # fail in fairly obvious ways. Eventually we want to just do:
-        #
-        # assert kwargs['filesystem']._tests
-        # self._tests = kwargs['filesystem']._tests
-
-        if 'filesystem' not in kwargs or kwargs['filesystem'] is None:
-            kwargs['filesystem'] = unit_test_filesystem()
-            self._tests = kwargs['filesystem']._tests
-        else:
-            self._tests = unit_test_list()
-
-        kwargs.setdefault('port_name', 'test')
-        base.Port.__init__(self, **kwargs)
+    def __init__(self, port_name=None, user=None, filesystem=None, **kwargs):
+        if not filesystem:
+            filesystem = unit_test_filesystem()
+
+        assert filesystem._tests
+        self._tests = filesystem._tests
+
+        if not user:
+            user = mocktool.MockUser()
+
+        if not port_name or port_name == 'test':
+            port_name = 'test-mac'
+
+        self._expectations_path = LAYOUT_TEST_DIR + '/platform/test/test_expectations.txt'
+        base.Port.__init__(self, port_name=port_name, filesystem=filesystem, user=user,
+                           **kwargs)
 
     def baseline_path(self):
         return self._filesystem.join(self.layout_tests_dir(), 'platform',
@@ -264,17 +261,23 @@ class TestPort(base.Port):
     def test_base_platform_names(self):
         return ('mac', 'win')
 
-    def test_expectations(self):
-        return self._filesystem.read_text_file(LAYOUT_TEST_DIR + '/platform/test/test_expectations.txt')
+    def path_to_test_expectations_file(self):
+        return self._expectations_path
 
     def test_platform_name(self):
+        if self._name == 'test-win':
+            return 'win'
         return 'mac'
 
     def test_platform_names(self):
         return self.test_base_platform_names()
 
     def test_platform_name_to_name(self, test_platform_name):
-        return test_platform_name
+        name_map = {
+            'mac': 'test-mac',
+            'win': 'test-win',
+        }
+        return name_map[test_platform_name]
 
     def version(self):
         return ''
index 50c02043b8449849a702c8745ef002ae7cd7ad7d..a0f5eeb136f4f299a4951eb0347a6eb420d80337 100644 (file)
@@ -32,7 +32,6 @@
 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,11 +87,11 @@ class TestRebaseliner(unittest.TestCase):
     def make_rebaseliner(self):
         options = mocktool.MockOptions(configuration=None,
                                        html_directory=None)
-        filesystem = filesystem_mock.MockFileSystem()
+        filesystem = port.unit_test_filesystem()
         host_port_obj = port.get('test', options, filesystem=filesystem)
         target_options = options
         target_port_obj = port.get('test', target_options, filesystem=filesystem)
-        platform = 'test'
+        platform = target_port_obj.test_platform_name()
         return rebaseline_chromium_webkit_tests.Rebaseliner(
             host_port_obj, target_port_obj, platform, options)
 
@@ -131,7 +130,7 @@ class TestRebaseliner(unittest.TestCase):
 class TestHtmlGenerator(unittest.TestCase):
     def make_generator(self, files, tests):
         options = mocktool.MockOptions(configuration=None, html_directory='/tmp')
-        host_port = port.get('test', options, filesystem=filesystem_mock.MockFileSystem(files))
+        host_port = port.get('test', options, filesystem=port.unit_test_filesystem(files))
         generator = rebaseline_chromium_webkit_tests.HtmlGenerator(
             host_port,
             target_port=None,
index 677becd25943fc43e6d3e1128440ca3a6c685974..112e402794c9ebc7bd93bf8609eb3ffe35661a33 100644 (file)
@@ -45,7 +45,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.tool import mocktool
 from webkitpy.layout_tests import port
 from webkitpy.layout_tests import run_webkit_tests
 from webkitpy.layout_tests.layout_package import dump_render_tree_thread
@@ -56,14 +56,6 @@ from webkitpy.test.skip import skip_if
 from webkitpy.thirdparty.mock import Mock
 
 
-class MockUser():
-    def __init__(self):
-        self.url = None
-
-    def open_url(self, url):
-        self.url = url
-
-
 def parse_args(extra_args=None, record_results=False, tests_included=False,
                print_nothing=True):
     extra_args = extra_args or []
@@ -93,7 +85,7 @@ def passing_run(extra_args=None, port_obj=None, record_results=False,
                                       tests_included)
     if not port_obj:
         port_obj = port.get(port_name=options.platform, options=options,
-                            user=MockUser(), filesystem=filesystem)
+                            user=mocktool.MockUser(), filesystem=filesystem)
     res = run_webkit_tests.run(port_obj, options, parsed_args)
     return res == 0
 
@@ -103,7 +95,7 @@ def logging_run(extra_args=None, port_obj=None, record_results=False, tests_incl
                                       record_results=record_results,
                                       tests_included=tests_included,
                                       print_nothing=False)
-    user = MockUser()
+    user = mocktool.MockUser()
     if not port_obj:
         port_obj = port.get(port_name=options.platform, options=options,
                             user=user, filesystem=filesystem)
@@ -135,7 +127,7 @@ def get_tests_run(extra_args=None, tests_included=False, flatten_batches=False,
         extra_args = ['passes', 'failures'] + extra_args
     options, parsed_args = parse_args(extra_args, tests_included=True)
 
-    user = MockUser()
+    user = mocktool.MockUser()
 
     test_batches = []
 
@@ -216,7 +208,8 @@ class MainTest(unittest.TestCase):
 
     def test_full_results_html(self):
         # FIXME: verify html?
-        self.assertTrue(passing_run(['--full-results-html']))
+        res, out, err, user = logging_run(['--full-results-html'])
+        self.assertEqual(res, 0)
 
     def test_help_printing(self):
         res, out, err, user = logging_run(['--help-printing'])
@@ -256,7 +249,7 @@ class MainTest(unittest.TestCase):
 
     def test_lint_test_files__errors(self):
         options, parsed_args = parse_args(['--lint-test-files'])
-        user = MockUser()
+        user = mocktool.MockUser()
         port_obj = port.get(options.platform, options=options, user=user)
         port_obj.test_expectations = lambda: "# syntax error"
         res, out, err = run_and_capture(port_obj, options, parsed_args)
@@ -352,7 +345,7 @@ class MainTest(unittest.TestCase):
         self.assertEqual(res, 3)
         self.assertFalse(out.empty())
         self.assertFalse(err.empty())
-        self.assertEqual(user.url, '/tmp/layout-test-results/results.html')
+        self.assertEqual(user.opened_urls, ['/tmp/layout-test-results/results.html'])
 
     def test_exit_after_n_failures(self):
         # Unexpected failures should result in tests stopping.
@@ -414,7 +407,7 @@ class MainTest(unittest.TestCase):
         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'))
+            self.assertEqual(user.opened_urls, [fs.join(tmpdir, 'results.html')])
 
     def test_results_directory_default(self):
         # We run a configuration that should fail, to generate output, then
@@ -422,7 +415,7 @@ class MainTest(unittest.TestCase):
 
         # This is the default location.
         res, out, err, user = logging_run(tests_included=True)
-        self.assertEqual(user.url, '/tmp/layout-test-results/results.html')
+        self.assertEqual(user.opened_urls, ['/tmp/layout-test-results/results.html'])
 
     def test_results_directory_relative(self):
         # We run a configuration that should fail, to generate output, then
@@ -430,7 +423,7 @@ class MainTest(unittest.TestCase):
 
         res, out, err, user = logging_run(['--results-directory=foo'],
                                           tests_included=True)
-        self.assertEqual(user.url, '/tmp/foo/results.html')
+        self.assertEqual(user.opened_urls, ['/tmp/foo/results.html'])
 
     def test_tolerance(self):
         class ImageDiffTestPort(TestPort):
@@ -441,7 +434,7 @@ class MainTest(unittest.TestCase):
 
         def get_port_for_run(args):
             options, parsed_args = run_webkit_tests.parse_args(args)
-            test_port = ImageDiffTestPort(options=options, user=MockUser())
+            test_port = ImageDiffTestPort(options=options, user=mocktool.MockUser())
             passing_run(args, port_obj=test_port, tests_included=True)
             return test_port
 
@@ -511,9 +504,9 @@ class RebaselineTest(unittest.TestCase):
         file_list.remove('/tmp/layout-test-results/tests_run.txt')
         self.assertEqual(len(file_list), 6)
         self.assertBaselines(file_list,
-            "/platform/test/passes/image")
+            "/platform/test-mac/passes/image")
         self.assertBaselines(file_list,
-            "/platform/test/failures/expected/missing_image")
+            "/platform/test-mac/failures/expected/missing_image")
 
 
 class DryrunTest(unittest.TestCase):
index 7db299692cdd8bb1b0b74f72aa85261e3fa14d21..3680d4cef84e6137fdba9046ce2f83e418e01f47 100644 (file)
@@ -548,6 +548,9 @@ class MockUser(object):
     def prompt_with_list(cls, list_title, list_items, can_choose_multiple=False, raw_input=raw_input):
         pass
 
+    def __init__(self):
+        self.opened_urls = []
+
     def edit(self, files):
         pass
 
@@ -565,6 +568,7 @@ class MockUser(object):
         return True
 
     def open_url(self, url):
+        self.opened_urls.append(url)
         if url.startswith("file://"):
             log("MOCK: user.open_url: file://...")
             return