OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import unittest | 5 import unittest |
6 | 6 |
7 from webkitpy.common.host_mock import MockHost | 7 from webkitpy.common.host_mock import MockHost |
8 from webkitpy.common.system.executive_mock import MockExecutive | 8 from webkitpy.common.system.executive_mock import MockExecutive |
9 from webkitpy.common.system.filesystem_mock import MockFileSystem | 9 from webkitpy.common.system.filesystem_mock import MockFileSystem |
10 from webkitpy.w3c.local_wpt import LocalWPT | 10 from webkitpy.w3c.local_wpt import LocalWPT |
11 | 11 |
12 | 12 |
13 class LocalWPTTest(unittest.TestCase): | 13 class LocalWPTTest(unittest.TestCase): |
14 | 14 |
15 def test_fetches_if_wpt_exists(self): | 15 def test_constructor_fetches_if_wpt_dir_exists(self): |
16 host = MockHost() | 16 host = MockHost() |
17 host.filesystem = MockFileSystem(files={ | 17 host.filesystem = MockFileSystem(files={ |
18 '/tmp/wpt': '' | 18 '/tmp/wpt': '' |
19 }) | 19 }) |
20 | 20 |
21 LocalWPT(host) | 21 LocalWPT(host) |
22 | 22 |
23 self.assertEqual(len(host.executive.calls), 2) | 23 self.assertEqual(host.executive.calls, [ |
24 self.assertEqual(host.executive.calls[0][1], 'fetch') | 24 ['git', 'fetch', '--all'], |
25 self.assertEqual(host.executive.calls[1][1], 'checkout') | 25 ['git', 'checkout', 'origin/master'], |
| 26 ['git', 'remote'], |
| 27 ['git', 'remote', 'add', 'github', 'git@github.com:w3c/web-platform-
tests.git']]) |
26 | 28 |
27 def test_clones_if_wpt_does_not_exist(self): | 29 def test_constructor_clones_if_wpt_dir_does_not_exist(self): |
28 host = MockHost() | 30 host = MockHost() |
29 host.filesystem = MockFileSystem() | 31 host.filesystem = MockFileSystem() |
30 | 32 |
31 LocalWPT(host) | 33 LocalWPT(host) |
32 | 34 |
33 self.assertEqual(len(host.executive.calls), 1) | 35 self.assertEqual(len(host.executive.calls), 3) |
34 self.assertEqual(host.executive.calls[0][1], 'clone') | 36 self.assertEqual(host.executive.calls[0][1], 'clone') |
35 | 37 |
36 def test_no_fetch_flag(self): | 38 def test_constructor_no_fetch_flag(self): |
37 host = MockHost() | 39 host = MockHost() |
38 host.filesystem = MockFileSystem(files={ | 40 host.filesystem = MockFileSystem(files={ |
39 '/tmp/wpt': '' | 41 '/tmp/wpt': '' |
40 }) | 42 }) |
41 | 43 |
42 LocalWPT(host, no_fetch=True) | 44 LocalWPT(host, no_fetch=True) |
43 | 45 |
44 self.assertEqual(len(host.executive.calls), 0) | 46 self.assertEqual(len(host.executive.calls), 0) |
45 | 47 |
46 def test_run(self): | 48 def test_run(self): |
47 host = MockHost() | 49 host = MockHost() |
48 host.filesystem = MockFileSystem() | 50 host.filesystem = MockFileSystem() |
49 | 51 |
50 local_wpt = LocalWPT(host) | 52 local_wpt = LocalWPT(host) |
51 | 53 |
52 local_wpt.run(['echo', 'rutabaga']) | 54 local_wpt.run(['echo', 'rutabaga']) |
53 self.assertEqual(len(host.executive.calls), 2) | 55 self.assertEqual(len(host.executive.calls), 4) |
54 self.assertEqual(host.executive.calls[1], ['echo', 'rutabaga']) | 56 self.assertEqual(host.executive.calls[3], ['echo', 'rutabaga']) |
55 | 57 |
56 def test_last_wpt_exported_commit(self): | 58 def test_last_wpt_exported_commit(self): |
57 host = MockHost() | 59 host = MockHost() |
58 return_vals = [ | 60 return_vals = [ |
59 'deadbeefcafe', | 61 'deadbeefcafe', |
60 '123', | 62 '123', |
61 '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8', | 63 '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8', |
62 ] | 64 ] |
63 host.executive = MockExecutive(run_command_fn=lambda _: return_vals.pop(
)) | 65 host.executive = MockExecutive(run_command_fn=lambda _: return_vals.pop(
)) |
64 host.filesystem = MockFileSystem() | 66 host.filesystem = MockFileSystem() |
65 local_wpt = LocalWPT(host, no_fetch=True) | 67 local_wpt = LocalWPT(host, no_fetch=True) |
66 | 68 |
67 wpt_sha, chromium_commit = local_wpt.most_recent_chromium_commit() | 69 wpt_sha, chromium_commit = local_wpt.most_recent_chromium_commit() |
68 self.assertEqual(wpt_sha, '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8') | 70 self.assertEqual(wpt_sha, '9ea4fc353a4b1c11c6e524270b11baa4d1ddfde8') |
69 self.assertEqual(chromium_commit.position, '123') | 71 self.assertEqual(chromium_commit.position, '123') |
70 self.assertEqual(chromium_commit.sha, 'deadbeefcafe') | 72 self.assertEqual(chromium_commit.sha, 'deadbeefcafe') |
71 | 73 |
72 def test_last_wpt_exported_commit_not_found(self): | 74 def test_last_wpt_exported_commit_not_found(self): |
73 host = MockHost() | 75 host = MockHost() |
74 host.executive = MockExecutive(run_command_fn=lambda _: None) | 76 host.executive = MockExecutive(run_command_fn=lambda _: '') |
75 host.filesystem = MockFileSystem() | 77 host.filesystem = MockFileSystem() |
76 local_wpt = LocalWPT(host) | 78 local_wpt = LocalWPT(host) |
77 | 79 |
78 commit = local_wpt.most_recent_chromium_commit() | 80 commit = local_wpt.most_recent_chromium_commit() |
79 self.assertEqual(commit, (None, None)) | 81 self.assertEqual(commit, (None, None)) |
80 | 82 |
81 def test_create_branch_with_patch(self): | 83 def test_create_branch_with_patch(self): |
82 host = MockHost() | 84 host = MockHost() |
83 host.filesystem = MockFileSystem() | 85 host.filesystem = MockFileSystem() |
84 | 86 |
85 local_wpt = LocalWPT(host) | 87 local_wpt = LocalWPT(host) |
86 | 88 |
87 local_branch_name = local_wpt.create_branch_with_patch('message', 'patch
', 'author') | 89 local_branch_name = local_wpt.create_branch_with_patch('message', 'patch
', 'author') |
88 self.assertEqual(len(host.executive.calls), 10) | |
89 self.assertEqual(local_branch_name, 'chromium-export-try') | 90 self.assertEqual(local_branch_name, 'chromium-export-try') |
90 self.assertEqual(host.executive.calls, [ | 91 self.assertEqual(host.executive.calls, [ |
91 ['git', 'clone', 'https://chromium.googlesource.com/external/w3c/web
-platform-tests.git', '/tmp/wpt'], | 92 ['git', 'clone', 'https://chromium.googlesource.com/external/w3c/web
-platform-tests.git', '/tmp/wpt'], |
| 93 ['git', 'remote'], |
| 94 ['git', 'remote', 'add', 'github', 'git@github.com:w3c/web-platform-
tests.git'], |
92 ['git', 'reset', '--hard', 'HEAD'], | 95 ['git', 'reset', '--hard', 'HEAD'], |
93 ['git', 'clean', '-fdx'], | 96 ['git', 'clean', '-fdx'], |
94 ['git', 'checkout', 'origin/master'], | 97 ['git', 'checkout', 'origin/master'], |
95 ['git', 'branch', '-a'], | 98 ['git', 'branch', '-a'], |
96 ['git', 'branch', '-a'], | 99 ['git', 'branch', '-a'], |
97 ['git', 'checkout', '-b', 'chromium-export-try'], | 100 ['git', 'checkout', '-b', 'chromium-export-try'], |
98 ['git', 'apply', '-'], | 101 ['git', 'apply', '-'], |
99 ['git', 'commit', '--author', 'author', '-am', 'message'], | 102 ['git', 'commit', '--author', 'author', '-am', 'message'], |
100 ['git', 'push', 'github', 'chromium-export-try']]) | 103 ['git', 'push', 'github', 'chromium-export-try']]) |
OLD | NEW |