Chromium Code Reviews| 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 MockExecutive2 |
| 9 from webkitpy.w3c.chromium_commit import ChromiumCommit | |
| 9 from webkitpy.w3c.test_exporter import TestExporter | 10 from webkitpy.w3c.test_exporter import TestExporter |
| 10 from webkitpy.w3c.wpt_github_mock import MockWPTGitHub | 11 from webkitpy.w3c.wpt_github_mock import MockWPTGitHub |
| 11 | 12 |
| 12 | 13 |
| 14 def mock_command_exec(vals): | |
| 15 def run_fn(args): | |
| 16 if args[1] in vals: | |
| 17 return vals[args[1]] | |
| 18 else: | |
| 19 return '' | |
|
qyearsley
2016/12/16 00:45:17
Possible minor change:
def run_fn(args):
jeffcarp
2016/12/16 20:07:10
🙌🙌
| |
| 20 return MockExecutive2(run_command_fn=run_fn) | |
| 21 | |
| 22 | |
| 13 class TestExporterTest(unittest.TestCase): | 23 class TestExporterTest(unittest.TestCase): |
| 14 | 24 |
| 25 def setUp(self): | |
| 26 self.host = MockHost() | |
| 27 self.wpt_github = MockWPTGitHub(pull_requests=[]) | |
| 28 | |
| 15 def test_stops_if_more_than_one_pr_is_in_flight(self): | 29 def test_stops_if_more_than_one_pr_is_in_flight(self): |
| 16 host = MockHost() | 30 host = MockHost() |
| 17 wpt_github = MockWPTGitHub(pull_requests=[{'id': 1}, {'id': 2}]) | 31 wpt_github = MockWPTGitHub(pull_requests=[{'id': 1}, {'id': 2}]) |
| 18 | 32 |
| 19 # TODO: make Exception more specific | 33 # TODO: make Exception more specific |
| 20 with self.assertRaises(Exception): | 34 with self.assertRaises(Exception): |
| 21 TestExporter(host, wpt_github).run() | 35 TestExporter(host, wpt_github).run() |
| 22 | 36 |
| 23 def test_if_pr_exists_merges_it(self): | 37 def test_if_pr_exists_merges_it(self): |
| 24 host = MockHost() | 38 host = MockHost() |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 return '' | 76 return '' |
| 63 | 77 |
| 64 host.executive = MockExecutive2(run_command_fn=mock_command) | 78 host.executive = MockExecutive2(run_command_fn=mock_command) |
| 65 wpt_github = MockWPTGitHub(pull_requests=[]) | 79 wpt_github = MockWPTGitHub(pull_requests=[]) |
| 66 | 80 |
| 67 TestExporter(host, wpt_github).run() | 81 TestExporter(host, wpt_github).run() |
| 68 | 82 |
| 69 self.assertEqual(wpt_github.calls, ['in_flight_pull_requests', 'create_p r']) | 83 self.assertEqual(wpt_github.calls, ['in_flight_pull_requests', 'create_p r']) |
| 70 self.assertEqual(wpt_github.pull_requests_created, | 84 self.assertEqual(wpt_github.pull_requests_created, |
| 71 [('chromium-export-try', 'older fake text', 'older fake text')]) | 85 [('chromium-export-try', 'older fake text', 'older fake text')]) |
| 86 | |
| 87 def test_exportable_commits_since(self): | |
| 88 self.host.executive = mock_command_exec({ | |
| 89 'show': 'fake message', | |
| 90 'rev-list': 'badbeef8', | |
| 91 'rev-parse': 'badbeef8', | |
| 92 'crrev-parse': 'badbeef8', | |
| 93 'diff': 'fake diff', | |
| 94 'diff-tree': 'some\nfiles', | |
| 95 'format-patch': 'hey I\'m a patch', | |
| 96 'footers': 'cr-rev-position', | |
| 97 }) | |
| 98 test_exporter = TestExporter(self.host, self.wpt_github) | |
| 99 | |
| 100 commits = test_exporter.exportable_commits_since('beefcafe') | |
| 101 self.assertEqual(len(commits), 1) | |
| 102 self.assertIsInstance(commits[0], ChromiumCommit) | |
|
qyearsley
2016/12/16 00:45:17
It would be helpful to assert what calls are made
jeffcarp
2016/12/16 20:07:10
Added. I think it makes the unit tests more brittl
| |
| 103 | |
| 104 def test_ignores_commits_with_noexport_true(self): | |
| 105 self.host.executive = mock_command_exec({ | |
| 106 'show': 'Commit message\nNOEXPORT=true', | |
| 107 'rev-list': 'badbeef8', | |
| 108 'rev-parse': 'badbeef8', | |
| 109 'footers': 'cr-rev-position', | |
| 110 }) | |
| 111 test_exporter = TestExporter(self.host, self.wpt_github) | |
| 112 | |
| 113 commits = test_exporter.exportable_commits_since('beefcafe') | |
| 114 self.assertEqual(len(commits), 0) | |
| 115 | |
| 116 def test_ignores_reverted_commits_with_noexport_true(self): | |
| 117 self.host.executive = mock_command_exec({ | |
| 118 'show': 'Commit message\n> NOEXPORT=true', | |
| 119 'rev-list': 'badbeef8', | |
| 120 'rev-parse': 'badbeef8', | |
| 121 'footers': 'cr-rev-position', | |
| 122 }) | |
| 123 wpt_github = MockWPTGitHub(pull_requests=[]) | |
| 124 test_exporter = TestExporter(self.host, wpt_github) | |
| 125 | |
| 126 commits = test_exporter.exportable_commits_since('beefcafe') | |
| 127 self.assertEqual(len(commits), 0) | |
| 128 | |
| 129 def test_ignores_commits_that_start_with_import(self): | |
| 130 self.host.executive = mock_command_exec({ | |
| 131 'show': 'Import rutabaga@deadbeef', | |
| 132 'rev-list': 'badbeef8', | |
| 133 'rev-parse': 'badbeef8', | |
| 134 'footers': 'cr-rev-position', | |
| 135 }) | |
| 136 wpt_github = MockWPTGitHub(pull_requests=[]) | |
| 137 test_exporter = TestExporter(self.host, wpt_github) | |
| 138 | |
| 139 commits = test_exporter.exportable_commits_since('beefcafe') | |
| 140 self.assertEqual(len(commits), 0) | |
| OLD | NEW |