Title: [197163] trunk/Tools
Revision
197163
Author
[email protected]
Date
2016-02-26 02:10:06 -0800 (Fri, 26 Feb 2016)

Log Message

W3C test importer should have an option to clean the destination directory
https://bugs.webkit.org/show_bug.cgi?id=152685

Reviewed by Darin Adler.

Adding --clean-dest-dir option to W3C test importer.
When this option is set, all files in the destination directory will be deleted
except for WebKit specific files (test expectations, .gitignore...) before new tests import.
Dangling test expectations are removed after tests import.'

Adding unit test and minor refactoring for the other tests.

* Scripts/webkitpy/w3c/test_importer.py:
(parse_args): Add '--clean-dest-dir' option.
(TestImporter.do_import):
(TestImporter._is_baseline): helper routine to capture -expected.txt files.
(TestImporter):
(TestImporter._should_not_keep_when_importing): helper routine to filter files that should not be cleaned before importing.
(TestImporter.clean_destination_directory):
(TestImporter.remove_dangling_expectations):
* Scripts/webkitpy/w3c/test_importer_unittest.py:
(TestImporterTest._parse_options):
(TestImporterTest.test_import_dir_with_no_tests_and_no_hg):
(TestImporterTest.test_import_dir_with_no_tests):
(TestImporterTest.test_import_dir_with_empty_init_py):
(test_clean_directory_option):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (197162 => 197163)


--- trunk/Tools/ChangeLog	2016-02-26 08:55:07 UTC (rev 197162)
+++ trunk/Tools/ChangeLog	2016-02-26 10:10:06 UTC (rev 197163)
@@ -1,3 +1,32 @@
+2016-02-26  Youenn Fablet  <[email protected]>
+
+        W3C test importer should have an option to clean the destination directory
+        https://bugs.webkit.org/show_bug.cgi?id=152685
+
+        Reviewed by Darin Adler.
+
+        Adding --clean-dest-dir option to W3C test importer.
+        When this option is set, all files in the destination directory will be deleted
+        except for WebKit specific files (test expectations, .gitignore...) before new tests import.
+        Dangling test expectations are removed after tests import.'
+
+        Adding unit test and minor refactoring for the other tests.
+
+        * Scripts/webkitpy/w3c/test_importer.py:
+        (parse_args): Add '--clean-dest-dir' option.
+        (TestImporter.do_import):
+        (TestImporter._is_baseline): helper routine to capture -expected.txt files.
+        (TestImporter):
+        (TestImporter._should_not_keep_when_importing): helper routine to filter files that should not be cleaned before importing.
+        (TestImporter.clean_destination_directory):
+        (TestImporter.remove_dangling_expectations):
+        * Scripts/webkitpy/w3c/test_importer_unittest.py:
+        (TestImporterTest._parse_options):
+        (TestImporterTest.test_import_dir_with_no_tests_and_no_hg):
+        (TestImporterTest.test_import_dir_with_no_tests):
+        (TestImporterTest.test_import_dir_with_empty_init_py):
+        (test_clean_directory_option):
+
 2016-02-25  Myles C. Maxfield  <[email protected]>
 
         REGRESSION(r195795): [WK2] fast/text/crash-complex-text-surrogate.html is flakey

Modified: trunk/Tools/Scripts/webkitpy/w3c/test_importer.py (197162 => 197163)


--- trunk/Tools/Scripts/webkitpy/w3c/test_importer.py	2016-02-26 08:55:07 UTC (rev 197162)
+++ trunk/Tools/Scripts/webkitpy/w3c/test_importer.py	2016-02-26 10:10:06 UTC (rev 197163)
@@ -147,6 +147,9 @@
     parser.add_argument('--import-all', action='', default=False,
          help='Ignore the ImportExpectations file. All tests will be imported. This option only applies when tests are downloaded from W3C repository')
 
+    parser.add_argument('--clean-dest-dir', action='', dest='clean_destination_directory', default=False,
+         help='Clean destination directory. All files in the destination directory will be deleted except for WebKit specific files (test expectations, .gitignore...) before new tests import. Dangling test expectations (expectation file that is no longer related to a test) are removed after tests import.')
+
     options, args = parser.parse_known_args(args)
     if len(args) > 1:
         parser.error('Incorrect number of arguments')
@@ -185,14 +188,20 @@
             self.filesystem.maybe_make_directory(self.source_directory)
             self.test_downloader().download_tests(self.source_directory, self.options.test_paths)
 
-        if not self.options.test_paths or self._importing_downloaded_tests:
-            self.find_importable_tests(self.source_directory)
-        else:
-            for test_path in self.options.test_paths:
-                self.find_importable_tests(self.filesystem.join(self.source_directory, test_path))
+        test_paths = self.options.test_paths if self.options.test_paths else [test_repository['name'] for test_repository in self.test_downloader().test_repositories]
+        for test_path in test_paths:
+            self.find_importable_tests(self.filesystem.join(self.source_directory, test_path))
 
+        if self.options.clean_destination_directory:
+            for test_path in test_paths:
+                self.clean_destination_directory(test_path)
+
         self.import_tests()
 
+        if self.options.clean_destination_directory:
+            for test_path in test_paths:
+                self.remove_dangling_expectations(test_path)
+
         if self._importing_downloaded_tests:
             self.generate_git_submodules_description_for_all_repositories()
 
@@ -220,6 +229,29 @@
             return not filename == '.htaccess'
         return False
 
+    def _is_baseline(self, filesystem, dirname, filename):
+        return filename.endswith('-expected.txt')
+
+    def _should_remove_before_importing(self, filesystem, dirname, filename):
+        if self._is_baseline(filesystem, dirname, filename):
+            return False
+        if filename.startswith("."):
+            return False
+        return True
+
+    def clean_destination_directory(self, filename):
+        directory = self.filesystem.join(self.destination_directory, filename)
+        for relative_path in self.filesystem.files_under(directory, file_filter=self._should_remove_before_importing):
+            self.filesystem.remove(self.filesystem.join(directory, relative_path))
+
+    def remove_dangling_expectations(self, filename):
+        #FIXME: Clean also the expected files stored in all platform specific folders.
+        directory = self.filesystem.join(self.destination_directory, filename)
+        for relative_path in self.filesystem.files_under(directory, file_filter=self._is_baseline):
+            path = self.filesystem.join(directory, relative_path)
+            if self.filesystem.glob(path.replace('-expected.txt', '*')) == [path]:
+                self.filesystem.remove(path)
+
     def find_importable_tests(self, directory):
         def should_keep_subdir(filesystem, path):
             if self._importing_downloaded_tests:

Modified: trunk/Tools/Scripts/webkitpy/w3c/test_importer_unittest.py (197162 => 197163)


--- trunk/Tools/Scripts/webkitpy/w3c/test_importer_unittest.py	2016-02-26 08:55:07 UTC (rev 197162)
+++ trunk/Tools/Scripts/webkitpy/w3c/test_importer_unittest.py	2016-02-26 10:10:06 UTC (rev 197163)
@@ -70,12 +70,16 @@
 
 class TestImporterTest(unittest.TestCase):
 
+    def _parse_options(self, args):
+        options, args = parse_args(args)
+        return options
+
     def test_import_dir_with_no_tests_and_no_hg(self):
         host = MockHost()
         host.executive = MockExecutive2(exception=OSError())
         host.filesystem = MockFileSystem(files=FAKE_FILES)
 
-        importer = TestImporter(host, FAKE_SOURCE_DIR, optparse.Values({"overwrite": False, 'destination': 'w3c', 'test_paths': [FAKE_TEST_PATH]}))
+        importer = TestImporter(host, FAKE_SOURCE_DIR, self._parse_options(['-n', '-d', 'w3c', '-t', FAKE_TEST_PATH]))
 
         oc = OutputCapture()
         oc.capture_output()
@@ -89,7 +93,7 @@
         host.executive = MockExecutive2(exception=ScriptError("abort: no repository found in '/Volumes/Source/src/wk/Tools/Scripts/webkitpy/w3c' (.hg not found)!"))
         host.filesystem = MockFileSystem(files=FAKE_FILES)
 
-        importer = TestImporter(host, FAKE_SOURCE_DIR, optparse.Values({"overwrite": False, 'destination': 'w3c', 'test_paths': [FAKE_TEST_PATH]}))
+        importer = TestImporter(host, FAKE_SOURCE_DIR, self._parse_options(['-n', '-d', 'w3c', '-t', FAKE_TEST_PATH]))
         oc = OutputCapture()
         oc.capture_output()
         try:
@@ -106,7 +110,7 @@
         host = MockHost()
         host.filesystem = MockFileSystem(files=FAKE_FILES)
 
-        importer = TestImporter(host, FAKE_SOURCE_DIR, optparse.Values({"overwrite": False, 'destination': 'w3c', 'test_paths': ['/tests/csswg']}))
+        importer = TestImporter(host, FAKE_SOURCE_DIR, self._parse_options(['-n', '-d', 'w3c', '-t', '/tests/csswg']))
         importer.do_import()
 
         self.assertTrue(host.filesystem.exists("/mock-checkout/LayoutTests/w3c/test1/__init__.py"))
@@ -185,5 +189,29 @@
         self.assertFalse(fs.exists('/mock-checkout/LayoutTests/w3c/streams-api/reference-implementation/web-platform-tests/test.html'))
         self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/streams-api/test.html'))
 
+    def test_clean_directory_option(self):
+        FAKE_FILES = {
+            '/mock-checkout/LayoutTests/w3c/web-platform-tests/.gitattributes': '-1',
+            '/mock-checkout/LayoutTests/w3c/web-platform-tests/.gitignore': '-1',
+            '/mock-checkout/LayoutTests/w3c/web-platform-tests/.svn/wc.db': '0',
+            '/mock-checkout/LayoutTests/w3c/web-platform-tests/old-test.html': '1',
+            '/mock-checkout/LayoutTests/w3c/web-platform-tests/old-test-expected.txt': '2',
+            '/mock-checkout/LayoutTests/w3c/web-platform-tests/existing-test.html': '3',
+            '/mock-checkout/LayoutTests/w3c/web-platform-tests/existing-test-expected.txt': '4',
+            '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/existing-test.html': '5',
+            '/mock-checkout/WebKitBuild/w3c-tests/csswg-tests/test.html': '1',
+        }
 
+        FAKE_FILES.update(FAKE_REPOSITORY)
+
+        fs = self.import_downloaded_tests(['--no-fetch', '--import-all', '-d', 'w3c', '--clean-dest-dir'], FAKE_FILES)
+
+        self.assertFalse(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/old-test.html'))
+        self.assertFalse(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/old-test-expected.txt'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/existing-test.html'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/existing-test-expected.txt'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/.gitattributes'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/.gitignore'))
+        self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/.svn'))
+
     # FIXME: Needs more tests.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to