Chromium Code Reviews| Index: third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_exporter_unittest.py |
| diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_exporter_unittest.py b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_exporter_unittest.py |
| index f8629e1baa68f72d32c18d6732d2361b8a27c439..3664f92c9f4a33e2c902a0e62c71f18a76b9ca5b 100644 |
| --- a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_exporter_unittest.py |
| +++ b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_exporter_unittest.py |
| @@ -6,47 +6,54 @@ import unittest |
| from webkitpy.common.host_mock import MockHost |
| from webkitpy.common.system.executive_mock import MockExecutive2 |
| +from webkitpy.w3c.chromium_commit import ChromiumCommit |
| from webkitpy.w3c.test_exporter import TestExporter |
| from webkitpy.w3c.wpt_github_mock import MockWPTGitHub |
| +def mock_command_exec(vals): |
| + def run_fn(args): |
| + if args[1] in vals: |
| + return vals[args[1]] |
| + else: |
| + return '' |
| + return MockExecutive2(run_command_fn=run_fn) |
| + |
| + |
| class TestExporterTest(unittest.TestCase): |
| + def setUp(self): |
| + self.host = MockHost() |
| + self.wpt_github = MockWPTGitHub(pull_requests=[]) |
| + |
| def test_stops_if_more_than_one_pr_is_in_flight(self): |
| - host = MockHost() |
| - wpt_github = MockWPTGitHub(pull_requests=[{'id': 1}, {'id': 2}]) |
| + self.wpt_github = MockWPTGitHub(pull_requests=[{'id': 1}, {'id': 2}]) |
| # TODO: make Exception more specific |
| with self.assertRaises(Exception): |
| - TestExporter(host, wpt_github).run() |
| + TestExporter(self.host, self.wpt_github).run() |
| def test_if_pr_exists_merges_it(self): |
| - host = MockHost() |
| - wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}]) |
| - TestExporter(host, wpt_github).run() |
| + self.wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}]) |
| + TestExporter(self.host, self.wpt_github).run() |
| - self.assertIn('merge_pull_request', wpt_github.calls) |
| + self.assertIn('merge_pull_request', self.wpt_github.calls) |
| def test_merge_failure_errors_out(self): |
| - host = MockHost() |
| - wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}], |
| - unsuccessful_merge=True) |
| + self.wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}], |
| + unsuccessful_merge=True) |
| # TODO: make Exception more specific |
| with self.assertRaises(Exception): |
| - TestExporter(host, wpt_github).run() |
| + TestExporter(self.host, self.wpt_github).run() |
| def test_dry_run_stops_before_creating_pr(self): |
| - host = MockHost() |
| - host.executive = MockExecutive2(output='beefcafe') |
| - wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}]) |
| - TestExporter(host, wpt_github, dry_run=True).run() |
| + self.wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}]) |
| - self.assertEqual(wpt_github.calls, ['in_flight_pull_requests']) |
| + TestExporter(self.host, self.wpt_github, dry_run=True).run() |
| + self.assertEqual(self.wpt_github.calls, ['in_flight_pull_requests']) |
| def test_creates_pull_request_for_earliest_commit(self): |
| - host = MockHost() |
| - |
| def mock_command(args): |
| git_command = args[1] |
| if git_command == 'rev-list': |
| @@ -58,14 +65,75 @@ class TestExporterTest(unittest.TestCase): |
| return 'newer fake text' |
| elif 'facebeef' in args: |
| return 'older fake text' |
| + elif git_command == 'remote': |
| + return 'github' |
| + elif git_command == 'format-patch': |
| + return 'fake patch' |
| + elif git_command == 'diff': |
| + return 'fake patch diff' |
| + elif git_command == 'diff-tree': |
| + return 'fake\nfiles\nchanged' |
| else: |
| return '' |
| - host.executive = MockExecutive2(run_command_fn=mock_command) |
| - wpt_github = MockWPTGitHub(pull_requests=[]) |
| - |
| - TestExporter(host, wpt_github).run() |
| + self.host.executive = MockExecutive2(run_command_fn=mock_command) |
| + TestExporter(self.host, self.wpt_github).run() |
| - self.assertEqual(wpt_github.calls, ['in_flight_pull_requests', 'create_pr']) |
| - self.assertEqual(wpt_github.pull_requests_created, |
| + self.assertEqual(self.wpt_github.calls, ['in_flight_pull_requests', 'create_pr']) |
| + self.assertEqual(self.wpt_github.pull_requests_created, |
| [('chromium-export-try', 'older fake text', 'older fake text')]) |
| + |
| + def test_exportable_commits_since(self): |
|
qyearsley
2016/12/15 20:59:14
Name: test_exportable_commits
|
| + self.host.executive = mock_command_exec({ |
| + 'show': 'fake message', |
| + 'rev-list': 'badbeef8', |
| + 'rev-parse': 'badbeef8', |
| + 'crrev-parse': 'badbeef8', |
| + 'diff': 'fake diff', |
| + 'diff-tree': 'some\nfiles', |
| + 'format-patch': 'hey I\'m a patch', |
| + 'footers': 'cr-rev-position', |
| + }) |
| + test_exporter = TestExporter(self.host, self.wpt_github) |
| + |
| + commits = test_exporter.exportable_commits() |
| + self.assertEqual(len(commits), 1) |
| + self.assertIsInstance(commits[0], ChromiumCommit) |
| + |
| + def test_ignores_commits_with_noexport_true(self): |
| + self.host.executive = mock_command_exec({ |
| + 'show': 'Commit message\nNOEXPORT=true', |
| + 'rev-list': 'badbeef8', |
| + 'rev-parse': 'badbeef8', |
| + 'footers': 'cr-rev-position', |
| + }) |
| + test_exporter = TestExporter(self.host, self.wpt_github) |
| + |
| + commits = test_exporter.exportable_commits() |
| + self.assertEqual(len(commits), 0) |
| + |
| + def test_ignores_reverted_commits_with_noexport_true(self): |
| + self.host.executive = mock_command_exec({ |
| + 'show': 'Commit message\n> NOEXPORT=true', |
| + 'rev-list': 'badbeef8', |
| + 'rev-parse': 'badbeef8', |
| + 'footers': 'cr-rev-position', |
| + }) |
| + wpt_github = MockWPTGitHub(pull_requests=[]) |
| + test_exporter = TestExporter(self.host, wpt_github) |
| + |
| + commits = test_exporter.exportable_commits() |
| + self.assertEqual(len(commits), 0) |
| + |
| + def test_ignores_commits_that_start_with_import(self): |
| + self.host.executive = mock_command_exec({ |
| + 'show': 'Import rutabaga@deadbeef', |
| + 'rev-list': 'badbeef8', |
| + 'rev-parse': 'badbeef8', |
| + 'footers': 'cr-rev-position', |
| + }) |
| + wpt_github = MockWPTGitHub(pull_requests=[]) |
| + test_exporter = TestExporter(self.host, wpt_github) |
| + |
| + commits = test_exporter.exportable_commits() |
| + self.assertEqual(len(commits), 0) |