Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_exporter_unittest.py

Issue 2544173002: Skip commits that don't generate a patch + fixes to get export working (Closed)
Patch Set: Merge ChromiumWPT functionality into TestExporter, expose exportable_commits Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 ''
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 self.wpt_github = MockWPTGitHub(pull_requests=[{'id': 1}, {'id': 2}])
17 wpt_github = MockWPTGitHub(pull_requests=[{'id': 1}, {'id': 2}])
18 31
19 # TODO: make Exception more specific 32 # TODO: make Exception more specific
20 with self.assertRaises(Exception): 33 with self.assertRaises(Exception):
21 TestExporter(host, wpt_github).run() 34 TestExporter(self.host, self.wpt_github).run()
22 35
23 def test_if_pr_exists_merges_it(self): 36 def test_if_pr_exists_merges_it(self):
24 host = MockHost() 37 self.wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'a bc'}])
25 wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}] ) 38 TestExporter(self.host, self.wpt_github).run()
26 TestExporter(host, wpt_github).run()
27 39
28 self.assertIn('merge_pull_request', wpt_github.calls) 40 self.assertIn('merge_pull_request', self.wpt_github.calls)
29 41
30 def test_merge_failure_errors_out(self): 42 def test_merge_failure_errors_out(self):
31 host = MockHost() 43 self.wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'a bc'}],
32 wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}] , 44 unsuccessful_merge=True)
33 unsuccessful_merge=True)
34 45
35 # TODO: make Exception more specific 46 # TODO: make Exception more specific
36 with self.assertRaises(Exception): 47 with self.assertRaises(Exception):
37 TestExporter(host, wpt_github).run() 48 TestExporter(self.host, self.wpt_github).run()
38 49
39 def test_dry_run_stops_before_creating_pr(self): 50 def test_dry_run_stops_before_creating_pr(self):
40 host = MockHost() 51 self.wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'a bc'}])
41 host.executive = MockExecutive2(output='beefcafe')
42 wpt_github = MockWPTGitHub(pull_requests=[{'number': 1, 'title': 'abc'}] )
43 TestExporter(host, wpt_github, dry_run=True).run()
44 52
45 self.assertEqual(wpt_github.calls, ['in_flight_pull_requests']) 53 TestExporter(self.host, self.wpt_github, dry_run=True).run()
54 self.assertEqual(self.wpt_github.calls, ['in_flight_pull_requests'])
46 55
47 def test_creates_pull_request_for_earliest_commit(self): 56 def test_creates_pull_request_for_earliest_commit(self):
48 host = MockHost()
49
50 def mock_command(args): 57 def mock_command(args):
51 git_command = args[1] 58 git_command = args[1]
52 if git_command == 'rev-list': 59 if git_command == 'rev-list':
53 return 'facebeef\ncafedad5' 60 return 'facebeef\ncafedad5'
54 elif git_command == 'footers': 61 elif git_command == 'footers':
55 return 'fake-cr-position' 62 return 'fake-cr-position'
56 elif git_command == 'show': 63 elif git_command == 'show':
57 if 'cafedad5' in args: 64 if 'cafedad5' in args:
58 return 'newer fake text' 65 return 'newer fake text'
59 elif 'facebeef' in args: 66 elif 'facebeef' in args:
60 return 'older fake text' 67 return 'older fake text'
68 elif git_command == 'remote':
69 return 'github'
70 elif git_command == 'format-patch':
71 return 'fake patch'
72 elif git_command == 'diff':
73 return 'fake patch diff'
74 elif git_command == 'diff-tree':
75 return 'fake\nfiles\nchanged'
61 else: 76 else:
62 return '' 77 return ''
63 78
64 host.executive = MockExecutive2(run_command_fn=mock_command) 79 self.host.executive = MockExecutive2(run_command_fn=mock_command)
80 TestExporter(self.host, self.wpt_github).run()
81
82 self.assertEqual(self.wpt_github.calls, ['in_flight_pull_requests', 'cre ate_pr'])
83 self.assertEqual(self.wpt_github.pull_requests_created,
84 [('chromium-export-try', 'older fake text', 'older fake text')])
85
86 def test_exportable_commits_since(self):
qyearsley 2016/12/15 20:59:14 Name: test_exportable_commits
87 self.host.executive = mock_command_exec({
88 'show': 'fake message',
89 'rev-list': 'badbeef8',
90 'rev-parse': 'badbeef8',
91 'crrev-parse': 'badbeef8',
92 'diff': 'fake diff',
93 'diff-tree': 'some\nfiles',
94 'format-patch': 'hey I\'m a patch',
95 'footers': 'cr-rev-position',
96 })
97 test_exporter = TestExporter(self.host, self.wpt_github)
98
99 commits = test_exporter.exportable_commits()
100 self.assertEqual(len(commits), 1)
101 self.assertIsInstance(commits[0], ChromiumCommit)
102
103 def test_ignores_commits_with_noexport_true(self):
104 self.host.executive = mock_command_exec({
105 'show': 'Commit message\nNOEXPORT=true',
106 'rev-list': 'badbeef8',
107 'rev-parse': 'badbeef8',
108 'footers': 'cr-rev-position',
109 })
110 test_exporter = TestExporter(self.host, self.wpt_github)
111
112 commits = test_exporter.exportable_commits()
113 self.assertEqual(len(commits), 0)
114
115 def test_ignores_reverted_commits_with_noexport_true(self):
116 self.host.executive = mock_command_exec({
117 'show': 'Commit message\n> NOEXPORT=true',
118 'rev-list': 'badbeef8',
119 'rev-parse': 'badbeef8',
120 'footers': 'cr-rev-position',
121 })
65 wpt_github = MockWPTGitHub(pull_requests=[]) 122 wpt_github = MockWPTGitHub(pull_requests=[])
123 test_exporter = TestExporter(self.host, wpt_github)
66 124
67 TestExporter(host, wpt_github).run() 125 commits = test_exporter.exportable_commits()
126 self.assertEqual(len(commits), 0)
68 127
69 self.assertEqual(wpt_github.calls, ['in_flight_pull_requests', 'create_p r']) 128 def test_ignores_commits_that_start_with_import(self):
70 self.assertEqual(wpt_github.pull_requests_created, 129 self.host.executive = mock_command_exec({
71 [('chromium-export-try', 'older fake text', 'older fake text')]) 130 'show': 'Import rutabaga@deadbeef',
131 'rev-list': 'badbeef8',
132 'rev-parse': 'badbeef8',
133 'footers': 'cr-rev-position',
134 })
135 wpt_github = MockWPTGitHub(pull_requests=[])
136 test_exporter = TestExporter(self.host, wpt_github)
137
138 commits = test_exporter.exportable_commits()
139 self.assertEqual(len(commits), 0)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698