Title: [229921] trunk/Tools
Revision
229921
Author
commit-qu...@webkit.org
Date
2018-03-23 14:19:37 -0700 (Fri, 23 Mar 2018)

Log Message

Lint web-platform-tests changes with the wpt linter before exporting
https://bugs.webkit.org/show_bug.cgi?id=183796

Patch by Brendan McLoughlin <bren...@bocoup.com> on 2018-03-23
Reviewed by Youenn Fablet.

* Scripts/webkitpy/w3c/test_exporter.py:
(TestExporter.__init__):
(TestExporter.do_export):
* Scripts/webkitpy/w3c/test_exporter_unittest.py:
(TestExporterTest.MockWPTLinter):
(TestExporterTest.MockWPTLinter.__init__):
(TestExporterTest.MockWPTLinter.lint):
(TestExporterTest.test_export):
(TestExporterTest.test_export_with_specific_branch):
* Scripts/webkitpy/w3c/wpt_linter.py: Added.
(WPTLinter):
(WPTLinter.__init__):
(WPTLinter.lint):

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (229920 => 229921)


--- trunk/Tools/ChangeLog	2018-03-23 21:18:56 UTC (rev 229920)
+++ trunk/Tools/ChangeLog	2018-03-23 21:19:37 UTC (rev 229921)
@@ -1,3 +1,24 @@
+2018-03-23  Brendan McLoughlin  <bren...@bocoup.com>
+
+        Lint web-platform-tests changes with the wpt linter before exporting
+        https://bugs.webkit.org/show_bug.cgi?id=183796
+
+        Reviewed by Youenn Fablet.
+
+        * Scripts/webkitpy/w3c/test_exporter.py:
+        (TestExporter.__init__):
+        (TestExporter.do_export):
+        * Scripts/webkitpy/w3c/test_exporter_unittest.py:
+        (TestExporterTest.MockWPTLinter):
+        (TestExporterTest.MockWPTLinter.__init__):
+        (TestExporterTest.MockWPTLinter.lint):
+        (TestExporterTest.test_export):
+        (TestExporterTest.test_export_with_specific_branch):
+        * Scripts/webkitpy/w3c/wpt_linter.py: Added.
+        (WPTLinter):
+        (WPTLinter.__init__):
+        (WPTLinter.lint):
+
 2018-03-23  David Kilzer  <ddkil...@apple.com>
 
         Stop using dispatch_set_target_queue()

Modified: trunk/Tools/Scripts/webkitpy/w3c/test_exporter.py (229920 => 229921)


--- trunk/Tools/Scripts/webkitpy/w3c/test_exporter.py	2018-03-23 21:18:56 UTC (rev 229920)
+++ trunk/Tools/Scripts/webkitpy/w3c/test_exporter.py	2018-03-23 21:19:37 UTC (rev 229921)
@@ -34,6 +34,7 @@
 from webkitpy.common.net.bugzilla import Bugzilla
 from webkitpy.common.webkit_finder import WebKitFinder
 from webkitpy.w3c.wpt_github import WPTGitHub
+from webkitpy.w3c.wpt_linter import WPTLinter
 
 _log = logging.getLogger(__name__)
 
@@ -44,7 +45,7 @@
 
 class TestExporter(object):
 
-    def __init__(self, host, options, gitClass=Git, bugzillaClass=Bugzilla, WPTGitHubClass=WPTGitHub):
+    def __init__(self, host, options, gitClass=Git, bugzillaClass=Bugzilla, WPTGitHubClass=WPTGitHub, WPTLinterClass=WPTLinter):
         self._host = host
         self._filesystem = host.filesystem
         self._options = options
@@ -64,6 +65,7 @@
             self._options.repository_directory = webkit_finder.path_from_webkit_base('WebKitBuild', 'w3c-tests', 'web-platform-tests')
 
         self._git = self._ensure_wpt_repository("https://github.com/w3c/web-platform-tests.git", self._options.repository_directory, gitClass)
+        self._linter = WPTLinterClass(self._options.repository_directory, host.filesystem)
 
         self._username = options.username
         if not self._username:
@@ -240,6 +242,13 @@
         if git_patch_file:
             self._filesystem.remove(git_patch_file)
 
+        lint_errors = self._linter.lint()
+        if lint_errors:
+            _log.error("The wpt linter detected %s linting error(s). Please address the above errors before attempting to export changes to the web-platform-test repository." % (lint_errors,))
+            self.delete_local_branch()
+            self.clean()
+            return
+
         try:
             if self.push_to_wpt_fork():
                 if self._options.create_pull_request:
@@ -295,7 +304,7 @@
                 return "%s: %s" % (record.levelname, record.getMessage())
             return record.getMessage()
 
-    logger = logging.getLogger()
+    logger = logging.getLogger('webkitpy.w3c.test_exporter')
     logger.setLevel(logging.INFO)
     handler = LogHandler()
     handler.setLevel(logging.INFO)

Modified: trunk/Tools/Scripts/webkitpy/w3c/test_exporter_unittest.py (229920 => 229921)


--- trunk/Tools/Scripts/webkitpy/w3c/test_exporter_unittest.py	2018-03-23 21:18:56 UTC (rev 229920)
+++ trunk/Tools/Scripts/webkitpy/w3c/test_exporter_unittest.py	2018-03-23 21:19:37 UTC (rev 229921)
@@ -28,6 +28,7 @@
 from webkitpy.w3c.test_exporter import TestExporter, parse_args
 from webkitpy.w3c.wpt_github_mock import MockWPTGitHub
 
+mock_linter = None
 
 class TestExporterTest(unittest.TestCase):
     maxDiff = None
@@ -105,10 +106,24 @@
         def scm(self):
             return self._mockSCM
 
+    class MockWPTLinter(object):
+        def __init__(self, repository_directory, filesystem):
+            self.calls = [repository_directory]
+            # workaround to appease the style checker which thinks
+            # exporter._linter is an instance of WPTLinter and
+            # complains if we try to access the calls property which
+            # only exists on MockWPTLinter
+            global mock_linter
+            mock_linter = self
+
+        def lint(self):
+            self.calls.append('lint')
+            return 0
+
     def test_export(self):
         host = TestExporterTest.MyMockHost()
         options = parse_args(['test_exporter.py', '-g', 'HEAD', '-b', '1234', '-c', '-n', 'USER', '-t', 'TOKEN'])
-        exporter = TestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub)
+        exporter = TestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub, TestExporterTest.MockWPTLinter)
         exporter.do_export()
         self.assertEquals(exporter._github.calls, ['create_pr', 'add_label "webkit-export"'])
         self.assertTrue('WebKit export' in exporter._github.pull_requests_created[0][1])
@@ -131,11 +146,12 @@
         self.assertEquals(exporter._bugzilla.calls, [
             'fetch bug 1234',
             'post comment to bug 1234 : Submitted web-platform-tests pull request: https://github.com/w3c/web-platform-tests/pull/5678'])
+        self.assertEquals(mock_linter.calls, ['/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests', 'lint'])
 
     def test_export_with_specific_branch(self):
         host = TestExporterTest.MyMockHost()
         options = parse_args(['test_exporter.py', '-g', 'HEAD', '-b', '1234', '-c', '-n', 'USER', '-t', 'TOKEN', '-bn', 'wpt-export-branch'])
-        exporter = TestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub)
+        exporter = TestExporter(host, options, TestExporterTest.MockGit, TestExporterTest.MockBugzilla, MockWPTGitHub, TestExporterTest.MockWPTLinter)
         exporter.do_export()
         self.assertEquals(exporter._git.calls, [
             '/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests',

Added: trunk/Tools/Scripts/webkitpy/w3c/wpt_linter.py (0 => 229921)


--- trunk/Tools/Scripts/webkitpy/w3c/wpt_linter.py	                        (rev 0)
+++ trunk/Tools/Scripts/webkitpy/w3c/wpt_linter.py	2018-03-23 21:19:37 UTC (rev 229921)
@@ -0,0 +1,37 @@
+# Copyright (c) 2018, Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1.  Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. AND ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""
+ This script is a wrapper for the web-platform-tests linter
+"""
+
+import subprocess
+
+
+class WPTLinter(object):
+    def __init__(self, repository_directory, filesystem):
+        self.wpt_path = filesystem.join(repository_directory, 'wpt')
+
+    def lint(self):
+        cmd = [self.wpt_path, 'lint']
+        proc = subprocess.Popen(cmd)
+        return proc.wait()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to