Move WPT fetch out of the LocalWPT constructor.

BUG=679955

Review-Url: https://codereview.chromium.org/2627323008
Cr-Commit-Position: refs/heads/master@{#444522}
diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py
index ef0501d..2c43c08 100644
--- a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py
+++ b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py
@@ -10,7 +10,7 @@
 from webkitpy.w3c.chromium_commit import ChromiumCommit
 
 WPT_REPO_URL = 'https://chromium.googlesource.com/external/w3c/web-platform-tests.git'
-WPT_TMP_DIR = '/tmp/wpt'
+WPT_TEMP_DIR = '/tmp/wpt'
 WPT_SSH_URL = 'git@github.com:w3c/web-platform-tests.git'
 REMOTE_NAME = 'github'
 CHROMIUM_WPT_DIR = 'third_party/WebKit/LayoutTests/external/wpt/'
@@ -20,22 +20,19 @@
 
 class LocalWPT(object):
 
-    def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False):
+    def __init__(self, host, path=WPT_TEMP_DIR):
         """
         Args:
             host: A Host object.
-            path: Optional, the directory where LocalWPT will check out web-platform-tests.
-            no_fetch: Optional, passing true will skip updating the local WPT.
-                Intended for use only in development after fetching once.
+            path: Optional, the path to the web-platform-tests repo.
+                If this directory already exists, it is assumed that the
+                web-platform-tests repo is already checked out at this path.
         """
         self.host = host
         self.path = path
         self.branch_name = 'chromium-export-try'
 
-        if no_fetch:
-            _log.info('Skipping remote WPT fetch')
-            return
-
+    def fetch(self):
         if self.host.filesystem.exists(self.path):
             _log.info('WPT checkout exists at %s, fetching latest', self.path)
             self.run(['git', 'fetch', '--all'])
@@ -122,7 +119,7 @@
             self.run(['git', 'apply', '-'], input=patch)
             self.run(['git', 'add', '.'])
             output = self.run(['git', 'diff', 'origin/master'])
-        except ScriptError as error:
+        except ScriptError:
             _log.warning('Patch did not apply cleanly, skipping...')
             output = ''
 
diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt_unittest.py b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt_unittest.py
index 0f4b380a..f90c772 100644
--- a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt_unittest.py
+++ b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt_unittest.py
@@ -12,48 +12,44 @@
 
 class LocalWPTTest(unittest.TestCase):
 
-    def test_constructor_fetches_if_wpt_dir_exists(self):
+    def test_fetch_when_wpt_dir_exists(self):
         host = MockHost()
         host.filesystem = MockFileSystem(files={
             '/tmp/wpt': ''
         })
 
-        LocalWPT(host)
+        local_wpt = LocalWPT(host)
+        local_wpt.fetch()
 
         self.assertEqual(host.executive.calls, [
             ['git', 'fetch', '--all'],
             ['git', 'checkout', 'origin/master'],
             ['git', 'remote'],
-            ['git', 'remote', 'add', 'github', 'git@github.com:w3c/web-platform-tests.git']])
+            ['git', 'remote', 'add', 'github', 'git@github.com:w3c/web-platform-tests.git']
+        ])
 
-    def test_constructor_clones_if_wpt_dir_does_not_exist(self):
+    def test_fetch_when_wpt_dir_does_not_exist(self):
         host = MockHost()
         host.filesystem = MockFileSystem()
 
-        LocalWPT(host)
+        local_wpt = LocalWPT(host)
+        local_wpt.fetch()
 
         self.assertEqual(len(host.executive.calls), 3)
         self.assertEqual(host.executive.calls[0][1], 'clone')
 
-    def test_constructor_no_fetch_flag(self):
+    def test_constructor(self):
+        #
         host = MockHost()
-        host.filesystem = MockFileSystem(files={
-            '/tmp/wpt': ''
-        })
-
-        LocalWPT(host, no_fetch=True)
-
+        LocalWPT(host)
         self.assertEqual(len(host.executive.calls), 0)
 
     def test_run(self):
         host = MockHost()
         host.filesystem = MockFileSystem()
-
         local_wpt = LocalWPT(host)
-
         local_wpt.run(['echo', 'rutabaga'])
-        self.assertEqual(len(host.executive.calls), 4)
-        self.assertEqual(host.executive.calls[3], ['echo', 'rutabaga'])
+        self.assertEqual(host.executive.calls, [['echo', 'rutabaga']])
 
     def test_last_wpt_exported_commit(self):
         host = MockHost()
@@ -64,7 +60,7 @@
         ]
         host.executive = MockExecutive(run_command_fn=lambda _: return_vals.pop())
         host.filesystem = MockFileSystem()
-        local_wpt = LocalWPT(host, no_fetch=True)
+        local_wpt = LocalWPT(host)
 
         wpt_sha, chromium_commit = local_wpt.most_recent_chromium_commit()
         self.assertEqual(wpt_sha, '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8')
@@ -85,6 +81,7 @@
         host.filesystem = MockFileSystem()
 
         local_wpt = LocalWPT(host)
+        local_wpt.fetch()
 
         local_branch_name = local_wpt.create_branch_with_patch('message', 'patch', 'author')
         self.assertEqual(local_branch_name, 'chromium-export-try')
diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_exporter.py b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_exporter.py
index 758fbd8..1eae98a 100644
--- a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_exporter.py
+++ b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_exporter.py
@@ -19,6 +19,7 @@
         self.wpt_github = wpt_github
         self.dry_run = dry_run
         self.local_wpt = LocalWPT(self.host)
+        self.local_wpt.fetch()
 
     def run(self):
         """Query in-flight pull requests, then merge PR or create one.