| 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.w3c.chromium_commit import ChromiumCommit | |
| 10 from webkitpy.w3c.test_exporter import TestExporter | 9 from webkitpy.w3c.test_exporter import TestExporter |
| 11 from webkitpy.w3c.wpt_github_mock import MockWPTGitHub | 10 from webkitpy.w3c.wpt_github_mock import MockWPTGitHub |
| 12 | 11 |
| 13 | 12 |
| 14 def mock_command_exec(vals): | |
| 15 def run_fn(args): | |
| 16 sub_command = args[1] | |
| 17 return vals.get(sub_command, '') | |
| 18 return MockExecutive(run_command_fn=run_fn) | |
| 19 | |
| 20 | |
| 21 class TestExporterTest(unittest.TestCase): | 13 class TestExporterTest(unittest.TestCase): |
| 22 | 14 |
| 23 def setUp(self): | 15 def setUp(self): |
| 24 self.host = MockHost() | 16 self.host = MockHost() |
| 25 self.wpt_github = MockWPTGitHub(pull_requests=[]) | 17 self.wpt_github = MockWPTGitHub(pull_requests=[]) |
| 26 | 18 |
| 27 def test_stops_if_more_than_one_pr_is_in_flight(self): | 19 def test_stops_if_more_than_one_pr_is_in_flight(self): |
| 28 host = MockHost() | 20 host = MockHost() |
| 29 wpt_github = MockWPTGitHub(pull_requests=[{'id': 1}, {'id': 2}]) | 21 wpt_github = MockWPTGitHub(pull_requests=[{'id': 1}, {'id': 2}]) |
| 30 | 22 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 return canned_git_outputs.get(args[1], '') | 64 return canned_git_outputs.get(args[1], '') |
| 73 | 65 |
| 74 host.executive = MockExecutive(run_command_fn=mock_command) | 66 host.executive = MockExecutive(run_command_fn=mock_command) |
| 75 wpt_github = MockWPTGitHub(pull_requests=[]) | 67 wpt_github = MockWPTGitHub(pull_requests=[]) |
| 76 | 68 |
| 77 TestExporter(host, wpt_github).run() | 69 TestExporter(host, wpt_github).run() |
| 78 | 70 |
| 79 self.assertEqual(wpt_github.calls, ['in_flight_pull_requests', 'create_p
r']) | 71 self.assertEqual(wpt_github.calls, ['in_flight_pull_requests', 'create_p
r']) |
| 80 self.assertEqual(wpt_github.pull_requests_created, | 72 self.assertEqual(wpt_github.pull_requests_created, |
| 81 [('chromium-export-try', 'older fake text', 'older fake
text')]) | 73 [('chromium-export-try', 'older fake text', 'older fake
text')]) |
| 82 | |
| 83 def test_exportable_commits_since(self): | |
| 84 self.host.executive = mock_command_exec({ | |
| 85 'show': 'fake message', | |
| 86 'rev-list': 'badbeef8', | |
| 87 'rev-parse': 'badbeef8', | |
| 88 'crrev-parse': 'badbeef8', | |
| 89 'diff': 'fake diff', | |
| 90 'diff-tree': 'some\nfiles', | |
| 91 'format-patch': 'hey I\'m a patch', | |
| 92 'footers': 'cr-rev-position', | |
| 93 }) | |
| 94 test_exporter = TestExporter(self.host, self.wpt_github) | |
| 95 | |
| 96 commits = test_exporter.exportable_commits_since('beefcafe') | |
| 97 self.assertEqual(len(commits), 1) | |
| 98 self.assertIsInstance(commits[0], ChromiumCommit) | |
| 99 self.assertEqual(self.host.executive.calls, [ | |
| 100 ['git', 'clone', 'https://chromium.googlesource.com/external/w3c/web
-platform-tests.git', '/tmp/wpt'], | |
| 101 ['git', 'remote'], | |
| 102 ['git', 'remote', 'add', 'github', 'git@github.com:w3c/web-platform-
tests.git'], | |
| 103 ['git', 'rev-parse', '--show-toplevel'], | |
| 104 ['git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--', 'badbeef8/t
hird_party/WebKit/LayoutTests/external/wpt/'], | |
| 105 ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'badbeef
8', '--', | |
| 106 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt'], | |
| 107 ['git', 'format-patch', '-1', '--stdout', 'badbeef8', '--', 'some',
'files'], | |
| 108 ['git', 'reset', '--hard', 'HEAD'], | |
| 109 ['git', 'clean', '-fdx'], | |
| 110 ['git', 'checkout', 'origin/master'], | |
| 111 ['git', 'branch', '-a'], | |
| 112 ['git', 'apply', '-'], | |
| 113 ['git', 'add', '.'], | |
| 114 ['git', 'diff', 'origin/master'], | |
| 115 ['git', 'reset', '--hard', 'HEAD'], | |
| 116 ['git', 'clean', '-fdx'], | |
| 117 ['git', 'checkout', 'origin/master'], | |
| 118 ['git', 'branch', '-a'], | |
| 119 ['git', 'show', '--format=%B', '--no-patch', 'badbeef8'], | |
| 120 ['git', 'show', '--format=%B', '--no-patch', 'badbeef8']]) | |
| 121 | |
| 122 def test_ignores_commits_with_noexport_true(self): | |
| 123 self.host.executive = mock_command_exec({ | |
| 124 'show': 'Commit message\nNOEXPORT=true', | |
| 125 'rev-list': 'badbeef8', | |
| 126 'rev-parse': 'badbeef8', | |
| 127 'footers': 'cr-rev-position', | |
| 128 }) | |
| 129 test_exporter = TestExporter(self.host, self.wpt_github) | |
| 130 | |
| 131 commits = test_exporter.exportable_commits_since('beefcafe') | |
| 132 self.assertEqual(len(commits), 0) | |
| 133 self.assertEqual(self.host.executive.calls, [ | |
| 134 ['git', 'clone', 'https://chromium.googlesource.com/external/w3c/web
-platform-tests.git', '/tmp/wpt'], | |
| 135 ['git', 'remote'], | |
| 136 ['git', 'remote', 'add', 'github', 'git@github.com:w3c/web-platform-
tests.git'], | |
| 137 ['git', 'rev-parse', '--show-toplevel'], | |
| 138 ['git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--', | |
| 139 'badbeef8/third_party/WebKit/LayoutTests/external/wpt/'], | |
| 140 ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'badbeef
8', '--', | |
| 141 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt']]) | |
| 142 | |
| 143 def test_ignores_reverted_commits_with_noexport_true(self): | |
| 144 self.host.executive = mock_command_exec({ | |
| 145 'show': 'Commit message\n> NOEXPORT=true', | |
| 146 'rev-list': 'badbeef8', | |
| 147 'rev-parse': 'badbeef8', | |
| 148 'footers': 'cr-rev-position', | |
| 149 }) | |
| 150 wpt_github = MockWPTGitHub(pull_requests=[]) | |
| 151 test_exporter = TestExporter(self.host, wpt_github) | |
| 152 | |
| 153 commits = test_exporter.exportable_commits_since('beefcafe') | |
| 154 self.assertEqual(len(commits), 0) | |
| 155 self.assertEqual(self.host.executive.calls, [ | |
| 156 ['git', 'clone', 'https://chromium.googlesource.com/external/w3c/web
-platform-tests.git', '/tmp/wpt'], | |
| 157 ['git', 'remote'], | |
| 158 ['git', 'remote', 'add', 'github', 'git@github.com:w3c/web-platform-
tests.git'], | |
| 159 ['git', 'rev-parse', '--show-toplevel'], | |
| 160 ['git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--', | |
| 161 'badbeef8/third_party/WebKit/LayoutTests/external/wpt/'], | |
| 162 ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'badbeef
8', '--', | |
| 163 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt']]) | |
| 164 | |
| 165 def test_ignores_commits_that_start_with_import(self): | |
| 166 self.host.executive = mock_command_exec({ | |
| 167 'show': 'Import rutabaga@deadbeef', | |
| 168 'rev-list': 'badbeef8', | |
| 169 'rev-parse': 'badbeef8', | |
| 170 'footers': 'cr-rev-position', | |
| 171 }) | |
| 172 wpt_github = MockWPTGitHub(pull_requests=[]) | |
| 173 test_exporter = TestExporter(self.host, wpt_github) | |
| 174 | |
| 175 commits = test_exporter.exportable_commits_since('beefcafe') | |
| 176 self.assertEqual(len(commits), 0) | |
| 177 self.assertEqual(self.host.executive.calls, [ | |
| 178 ['git', 'clone', 'https://chromium.googlesource.com/external/w3c/web
-platform-tests.git', '/tmp/wpt'], | |
| 179 ['git', 'remote'], | |
| 180 ['git', 'remote', 'add', 'github', 'git@github.com:w3c/web-platform-
tests.git'], | |
| 181 ['git', 'rev-parse', '--show-toplevel'], | |
| 182 ['git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--', | |
| 183 'badbeef8/third_party/WebKit/LayoutTests/external/wpt/'], | |
| 184 ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'badbeef
8', '--', | |
| 185 '/mock-checkout/third_party/WebKit/LayoutTests/external/wpt']]) | |
| OLD | NEW |