| 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 MockExecutive2 | 8 from webkitpy.common.system.executive_mock import MockExecutive |
| 9 from webkitpy.w3c.chromium_commit import ChromiumCommit | 9 from webkitpy.w3c.chromium_commit import ChromiumCommit |
| 10 from webkitpy.w3c.test_exporter import TestExporter | 10 from webkitpy.w3c.test_exporter import TestExporter |
| 11 from webkitpy.w3c.wpt_github_mock import MockWPTGitHub | 11 from webkitpy.w3c.wpt_github_mock import MockWPTGitHub |
| 12 | 12 |
| 13 | 13 |
| 14 def mock_command_exec(vals): | 14 def mock_command_exec(vals): |
| 15 def run_fn(args): | 15 def run_fn(args): |
| 16 sub_command = args[1] | 16 sub_command = args[1] |
| 17 return vals.get(sub_command, '') | 17 return vals.get(sub_command, '') |
| 18 return MockExecutive2(run_command_fn=run_fn) | 18 return MockExecutive(run_command_fn=run_fn) |
| 19 | 19 |
| 20 | 20 |
| 21 class TestExporterTest(unittest.TestCase): | 21 class TestExporterTest(unittest.TestCase): |
| 22 | 22 |
| 23 def setUp(self): | 23 def setUp(self): |
| 24 self.host = MockHost() | 24 self.host = MockHost() |
| 25 self.wpt_github = MockWPTGitHub(pull_requests=[]) | 25 self.wpt_github = MockWPTGitHub(pull_requests=[]) |
| 26 | 26 |
| 27 def test_stops_if_more_than_one_pr_is_in_flight(self): | 27 def test_stops_if_more_than_one_pr_is_in_flight(self): |
| 28 host = MockHost() | 28 host = MockHost() |
| (...skipping 14 matching lines...) Expand all Loading... |
| 43 host = MockHost() | 43 host = MockHost() |
| 44 wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}]
, | 44 wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}]
, |
| 45 unsuccessful_merge=True) | 45 unsuccessful_merge=True) |
| 46 | 46 |
| 47 # TODO: make Exception more specific | 47 # TODO: make Exception more specific |
| 48 with self.assertRaises(Exception): | 48 with self.assertRaises(Exception): |
| 49 TestExporter(host, wpt_github).run() | 49 TestExporter(host, wpt_github).run() |
| 50 | 50 |
| 51 def test_dry_run_stops_before_creating_pr(self): | 51 def test_dry_run_stops_before_creating_pr(self): |
| 52 host = MockHost() | 52 host = MockHost() |
| 53 host.executive = MockExecutive2(output='beefcafe') | 53 host.executive = MockExecutive(output='beefcafe') |
| 54 wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}]
) | 54 wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}]
) |
| 55 TestExporter(host, wpt_github, dry_run=True).run() | 55 TestExporter(host, wpt_github, dry_run=True).run() |
| 56 | 56 |
| 57 self.assertEqual(wpt_github.calls, ['in_flight_pull_requests']) | 57 self.assertEqual(wpt_github.calls, ['in_flight_pull_requests']) |
| 58 | 58 |
| 59 def test_creates_pull_request_for_earliest_commit(self): | 59 def test_creates_pull_request_for_earliest_commit(self): |
| 60 host = MockHost() | 60 host = MockHost() |
| 61 | 61 |
| 62 def mock_command(args): | 62 def mock_command(args): |
| 63 canned_git_outputs = { | 63 canned_git_outputs = { |
| 64 'show': 'newer fake text' if 'cafedad5' in args else 'older fake
text', | 64 'show': 'newer fake text' if 'cafedad5' in args else 'older fake
text', |
| 65 'rev-list': 'facebeef\ncafedad5', | 65 'rev-list': 'facebeef\ncafedad5', |
| 66 'footers': 'fake-cr-position', | 66 'footers': 'fake-cr-position', |
| 67 'remote': 'github', | 67 'remote': 'github', |
| 68 'format-patch': 'fake patch', | 68 'format-patch': 'fake patch', |
| 69 'diff': 'fake patch diff', | 69 'diff': 'fake patch diff', |
| 70 'diff-tree': 'fake\n\files\nchanged', | 70 'diff-tree': 'fake\n\files\nchanged', |
| 71 } | 71 } |
| 72 return canned_git_outputs.get(args[1], '') | 72 return canned_git_outputs.get(args[1], '') |
| 73 | 73 |
| 74 host.executive = MockExecutive2(run_command_fn=mock_command) | 74 host.executive = MockExecutive(run_command_fn=mock_command) |
| 75 wpt_github = MockWPTGitHub(pull_requests=[]) | 75 wpt_github = MockWPTGitHub(pull_requests=[]) |
| 76 | 76 |
| 77 TestExporter(host, wpt_github).run() | 77 TestExporter(host, wpt_github).run() |
| 78 | 78 |
| 79 self.assertEqual(wpt_github.calls, ['in_flight_pull_requests', 'create_p
r']) | 79 self.assertEqual(wpt_github.calls, ['in_flight_pull_requests', 'create_p
r']) |
| 80 self.assertEqual(wpt_github.pull_requests_created, | 80 self.assertEqual(wpt_github.pull_requests_created, |
| 81 [('chromium-export-try', 'older fake text', 'older fake
text')]) | 81 [('chromium-export-try', 'older fake text', 'older fake
text')]) |
| 82 | 82 |
| 83 def test_exportable_commits_since(self): | 83 def test_exportable_commits_since(self): |
| 84 self.host.executive = mock_command_exec({ | 84 self.host.executive = mock_command_exec({ |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 167 |
| 168 commits = test_exporter.exportable_commits_since('beefcafe') | 168 commits = test_exporter.exportable_commits_since('beefcafe') |
| 169 self.assertEqual(len(commits), 0) | 169 self.assertEqual(len(commits), 0) |
| 170 self.assertEqual(self.host.executive.calls, [ | 170 self.assertEqual(self.host.executive.calls, [ |
| 171 ['git', 'clone', 'https://chromium.googlesource.com/external/w3c/web
-platform-tests.git', '/tmp/wpt'], | 171 ['git', 'clone', 'https://chromium.googlesource.com/external/w3c/web
-platform-tests.git', '/tmp/wpt'], |
| 172 ['git', 'rev-parse', '--show-toplevel'], | 172 ['git', 'rev-parse', '--show-toplevel'], |
| 173 ['git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--', | 173 ['git', 'rev-list', 'beefcafe..HEAD', '--reverse', '--', |
| 174 'badbeef8/third_party/WebKit/LayoutTests/imported/wpt/'], | 174 'badbeef8/third_party/WebKit/LayoutTests/imported/wpt/'], |
| 175 ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'badbeef
8', '--', | 175 ['git', 'diff-tree', '--name-only', '--no-commit-id', '-r', 'badbeef
8', '--', |
| 176 '/mock-checkout/third_party/WebKit/LayoutTests/imported/wpt']]) | 176 '/mock-checkout/third_party/WebKit/LayoutTests/imported/wpt']]) |
| OLD | NEW |