W3C test parser and converter should use test importer host
authoryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Mar 2015 20:22:36 +0000 (20:22 +0000)
committeryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Mar 2015 20:22:36 +0000 (20:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142729

Reviewed by Bem Jones-Bey.

When instantiated by TestImporter, TestParser and TestConverter are now using the same host.
This enables adding more TestImporter unit testing.
This patch also ensures that the git object instantiated by TestDownloader is using the
same Executive and FileSystem object as TestDownloader, again to enable TestImporter/TestDownloader unit testing.

* Scripts/webkitpy/common/system/filesystem_mock.py:
(MockFileSystem.copytree): Fixes implementation as it creates a runtime error.
* Scripts/webkitpy/w3c/test_downloader.py:
(TestDownloader.git): Set the executive of the git object to the one of TestDownloader. Refactoring in a new git function for future reuse.
(TestDownloader.checkout_test_repository): Making use of the new git function.
* Scripts/webkitpy/w3c/test_importer.py:
(TestImporter.find_importable_tests): Adding host as parameter to the parser.
(TestImporter.import_tests): Adding host as parameter to the converter.
* Scripts/webkitpy/w3c/test_importer_unittest.py:
(TestImporterTest.create_test_download_importer): Creating a test downloader mock, to be reused by other tests.
(TestImporterTest):
(TestImporterTest.test_harnesslinks_conversion): Adding test to check that test harness links are converted for CSS tests but not WPT tests.
* Scripts/webkitpy/w3c/test_parser.py:
(TestParser.__init__): Adding host as parameter constructor.

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

Tools/ChangeLog
Tools/Scripts/webkitpy/common/system/filesystem_mock.py
Tools/Scripts/webkitpy/w3c/test_downloader.py
Tools/Scripts/webkitpy/w3c/test_importer.py
Tools/Scripts/webkitpy/w3c/test_importer_unittest.py
Tools/Scripts/webkitpy/w3c/test_parser.py

index 148c7df..03203e9 100644 (file)
@@ -1,3 +1,30 @@
+2015-03-17  Youenn Fablet  <youenn.fablet@crf.canon.fr>
+
+        W3C test parser and converter should use test importer host
+        https://bugs.webkit.org/show_bug.cgi?id=142729
+
+        Reviewed by Bem Jones-Bey.
+
+        When instantiated by TestImporter, TestParser and TestConverter are now using the same host.
+        This enables adding more TestImporter unit testing.
+        This patch also ensures that the git object instantiated by TestDownloader is using the
+        same Executive and FileSystem object as TestDownloader, again to enable TestImporter/TestDownloader unit testing.
+
+        * Scripts/webkitpy/common/system/filesystem_mock.py:
+        (MockFileSystem.copytree): Fixes implementation as it creates a runtime error.
+        * Scripts/webkitpy/w3c/test_downloader.py:
+        (TestDownloader.git): Set the executive of the git object to the one of TestDownloader. Refactoring in a new git function for future reuse.
+        (TestDownloader.checkout_test_repository): Making use of the new git function.
+        * Scripts/webkitpy/w3c/test_importer.py:
+        (TestImporter.find_importable_tests): Adding host as parameter to the parser.
+        (TestImporter.import_tests): Adding host as parameter to the converter.
+        * Scripts/webkitpy/w3c/test_importer_unittest.py:
+        (TestImporterTest.create_test_download_importer): Creating a test downloader mock, to be reused by other tests.
+        (TestImporterTest):
+        (TestImporterTest.test_harnesslinks_conversion): Adding test to check that test harness links are converted for CSS tests but not WPT tests. 
+        * Scripts/webkitpy/w3c/test_parser.py:
+        (TestParser.__init__): Adding host as parameter constructor.
+
 2015-03-17  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] WebKitDOM objects leaking
index 688e8ca..1ae8f90 100644 (file)
@@ -400,7 +400,7 @@ class MockFileSystem(object):
         source = self.normpath(source)
         destination = self.normpath(destination)
 
-        for source_file in self.files:
+        for source_file in list(self.files):
             if source_file.startswith(source):
                 destination_path = self.join(destination, self.relpath(source_file, source))
                 self.maybe_make_directory(self.dirname(destination_path))
index c1ba1f3..5adba2c 100644 (file)
@@ -78,8 +78,11 @@ class TestDownloader(object):
             import_expectations_path = webkit_finder.path_from_webkit_base('LayoutTests', 'imported', 'w3c', 'resources', 'ImportExpectations')
             self._init_paths_from_expectations(import_expectations_path)
 
+    def git(self, test_repository):
+        return Git(test_repository, None, executive=self._host.executive, filesystem=self._filesystem)
+
     def checkout_test_repository(self, revision, url, directory):
-        git = Git('.', None)
+        git = self.git('.')
         if not self._filesystem.exists(directory):
             _log.info('Cloning %s into %s...' % (url, directory))
             git._run_git(['clone', '-v', url, directory])
index 300f63e..06172c3 100644 (file)
@@ -240,7 +240,7 @@ class TestImporter(object):
                     copy_list.append({'src': fullpath, 'dest': filename})
                     continue
 
-                test_parser = TestParser(vars(self.options), filename=fullpath)
+                test_parser = TestParser(vars(self.options), filename=fullpath, host=self.host)
                 test_info = test_parser.analyze_test()
                 if test_info is None:
                     # If html file is in a "resources" folder, it should be copied anyway
@@ -351,7 +351,7 @@ class TestImporter(object):
                 mimetype = mimetypes.guess_type(orig_filepath)
                 if 'html' in str(mimetype[0]) or 'xml' in str(mimetype[0])  or 'css' in str(mimetype[0]):
                     try:
-                        converted_file = convert_for_webkit(new_path, filename=orig_filepath, reference_support_info=reference_support_info, convert_test_harness_links=self.should_convert_test_harness_links(subpath))
+                        converted_file = convert_for_webkit(new_path, filename=orig_filepath, reference_support_info=reference_support_info, host=self.host, convert_test_harness_links=self.should_convert_test_harness_links(subpath))
                     except:
                         _log.warn('Failed converting %s', orig_filepath)
                         failed_conversion_files.append(orig_filepath)
index 36b8e7d..90e5fee 100644 (file)
@@ -34,7 +34,7 @@ from webkitpy.common.host_mock import MockHost
 from webkitpy.common.system.filesystem_mock import MockFileSystem
 from webkitpy.common.system.executive_mock import MockExecutive2, ScriptError
 from webkitpy.common.system.outputcapture import OutputCapture
-from webkitpy.w3c.test_importer import TestImporter
+from webkitpy.w3c.test_importer import parse_args, TestImporter
 
 
 FAKE_SOURCE_DIR = '/tests/csswg'
@@ -90,4 +90,30 @@ class TestImporterTest(unittest.TestCase):
         self.assertTrue(host.filesystem.exists("/mock-checkout/LayoutTests/w3c/test2/__init__.py"))
         self.assertTrue(host.filesystem.getsize("/mock-checkout/LayoutTests/w3c/test1/__init__.py") > 0)
 
+    def import_downloaded_tests(self, args, files):
+        # files are passed as parameter as we cannot clone/fetch/checkout a repo in mock system.
+        host = MockHost()
+        host.executive = MockExecutive2()
+        host.filesystem = MockFileSystem(files=files)
+
+        options, args = parse_args(args)
+        importer = TestImporter(host, None, options)
+        importer.do_import()
+        return host.filesystem
+
+    def test_harnesslinks_conversion(self):
+        FAKE_FILES = {
+            '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/t/test.html': '<!doctype html><script src="/resources/testharness.js"></script><script src="/resources/testharnessreport.js"></script>',
+            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/t/test.html': '<!doctype html><script src="/resources/testharness.js"></script><script src="/resources/testharnessreport.js"></script>',
+            '/mock-checkout/Source/WebCore/css/CSSPropertyNames.in': '',
+            '/mock-checkout/Source/WebCore/css/CSSValueKeywords.in': '',
+        }
+
+        fs = self.import_downloaded_tests(['--no-fetch', '--import-all', '-d', 'w3c'], FAKE_FILES)
+
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/csswg-tests/t/test.html'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/test.html'))
+        self.assertTrue('src="/resources/testharness.js"' in fs.read_text_file('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/test.html'))
+        self.assertTrue('src="../' in fs.read_text_file('/mock-checkout/LayoutTests/w3c/csswg-tests/t/test.html'))
+
     # FIXME: Needs more tests.
index 0661a19..b88ff48 100755 (executable)
@@ -39,10 +39,10 @@ _log = logging.getLogger(__name__)
 
 class TestParser(object):
 
-    def __init__(self, options, filename):
+    def __init__(self, options, filename, host=Host()):
         self.options = options
         self.filename = filename
-        self.host = Host()
+        self.host = host
         self.filesystem = self.host.filesystem
 
         self.test_doc = None