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

Side by Side Diff: tests/pending_manager_test.py

Issue 6813044: Add relative path support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/commit-queue
Patch Set: Created 9 years, 8 months 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 | Annotate | Revision Log
« no previous file with comments | « pending_manager.py ('k') | tests/project_base_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unit tests for pending_manager.py.""" 6 """Unit tests for pending_manager.py."""
7 7
8 import logging 8 import logging
9 import os 9 import os
10 import re
10 import sys 11 import sys
11 import unittest 12 import unittest
12 import urllib2 13 import urllib2
13 14
14 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) 15 ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
15 sys.path.insert(0, os.path.join(ROOT_DIR, '..')) 16 sys.path.insert(0, os.path.join(ROOT_DIR, '..'))
16 17
18 import find_depot_tools # pylint: disable=W0611
19 import patch
20
17 import pending_manager 21 import pending_manager
18 from verification import base 22 from verification import base
19 from verification import fake 23 from verification import fake
24 from verification import project_base
20 25
21 26
22 # Access to a protected member xxx of a client class 27 # Access to a protected member xxx of a client class
23 # pylint: disable=W0212 28 # pylint: disable=W0212
24 29
25 def _SendStackFail(last_tb, stack, url=None, maxlen=50): 30 SVN_PATCH = (
31 'Index: chrome/file.cc\n'
32 '===================================================================\n'
33 '--- chrome/file.cc\t(revision 74690)\n'
34 '+++ chrome/file.cc\t(working copy)\n'
35 '@@ -80,10 +80,13 @@\n'
36 ' // Foo\n'
37 ' // Bar\n'
38 ' void foo() {\n'
39 '- return bar;\n'
40 '+ return foo;\n'
41 ' }\n'
42 ' \n'
43 ' \n')
44
45
46 def _SendStackFail(last_tb, stack, *args, **kwargs):
26 """Fails a test that calls SendStack. 47 """Fails a test that calls SendStack.
27 48
28 In practice it doesn't happen when a test pass but will when a test fails so 49 In practice it doesn't happen when a test pass but will when a test fails so
29 hook it here so breakpad doesn't send too many stack traces to maintainers. 50 hook it here so breakpad doesn't send too many stack traces to maintainers.
30 """ 51 """
52 print '_SendStackFail() was called'
31 print last_tb 53 print last_tb
32 print stack 54 print stack
33 assert False 55 assert False
34 56
35 57
36 def read(filename): 58 def read(filename):
37 f = open(filename, 'rb') 59 f = open(filename, 'rb')
38 content = f.read() 60 content = f.read()
39 f.close() 61 f.close()
40 return content 62 return content
41 63
42 64
43 def write(filename, content): 65 def write(filename, content):
44 f = open(filename, 'wb') 66 f = open(filename, 'wb')
45 f.write(content) 67 f.write(content)
46 f.close() 68 f.close()
47 69
48 70
49 def trim(x): 71 def trim(x):
50 return x.replace(' ', '').replace('\n', '') 72 return x.replace(' ', '').replace('\n', '')
51 73
52 74
53 class FakeRietveld(object): 75 class FakeRietveld(object):
54 url = 'http://nowhere' 76 url = 'http://nowhere'
55 77
56 def __init__(self, test): 78 def __init__(self):
57 self.test = test 79 self.issues = {
58 80 31337: {
59 def get_issue_properties(self, issue_id, _):
60 self.test.assertEquals(issue_id, 31337)
61 return {
62 "description": "foo", 81 "description": "foo",
63 "created": "2010-12-27 03:23:31.149045", 82 "created": "2010-12-27 03:23:31.149045",
64 "cc": ["cc@example.com",], 83 "cc": ["cc@example.com",],
65 "reviewers": ["rev@example.com"], 84 "reviewers": ["rev@example.com"],
66 "owner_email": "author@example.com", 85 "owner_email": "author@example.com",
67 "patchsets": [1], 86 "patchsets": [1],
68 "modified": "2011-01-10 20:52:39.127231", 87 "modified": "2011-01-10 20:52:39.127231",
69 "private": False, 88 "private": False,
70 "base_url": "svn://fake/repo", 89 "base_url": "svn://fake/repo",
71 "closed": False, 90 "closed": False,
72 "owner": "Author", 91 "owner": "Author",
73 "issue": issue_id, 92 "issue": 31337,
74 "subject": 'foo', 93 "subject": 'foo',
75 "messages": [ 94 "messages": [
76 { 95 {
77 "date": "2010-12-27 03:23:32.489999", 96 "date": "2010-12-27 03:23:32.489999",
78 "text": "hi!", 97 "text": "hi!",
79 "sender": "author@example.com", 98 "sender": "author@example.com",
80 "recipients": ["rev@example.com", "cc@example.com"], 99 "recipients": ["rev@example.com", "cc@example.com"],
81 }, 100 },
82 ], 101 ],
83 "commit": True, 102 "commit": True,
103 },
84 } 104 }
85 105
106 def get_pending_issues(self):
107 return self.issues.keys()
108
109 def get_issue_properties(self, issue_id, _):
110 return self.issues[issue_id]
111
86 def close_issue(self, issue): 112 def close_issue(self, issue):
87 pass 113 pass
88 114
89 def update_description(self, issue, text): 115 def update_description(self, issue, text):
90 pass 116 pass
91 117
92 def set_flag(self, issue, patchset, flag, value): 118 def set_flag(self, issue, patchset, flag, value):
93 pass 119 pass
94 120
95 def add_comment(self, issue, text): 121 def add_comment(self, issue, text):
96 pass 122 pass
97 123
124 def get_patch(self, issue, patchset):
125 return patch.PatchSet([
126 patch.FilePatchDiff('chrome/file.cc', SVN_PATCH, []),
127 patch.FilePatchDelete('other/place/foo', True),
128 patch.FilePatchBinary('foo', 'data', []),
129 ])
130
98 131
99 class FakeCheckout(object): 132 class FakeCheckout(object):
100 project_path = os.getcwd() 133 project_path = os.getcwd()
101 134
102 def __init__(self): 135 def __init__(self):
103 self._prepare = False 136 self._prepare = 0
104 self._commit = False 137 self._commit = []
138 self._apply_patch = []
105 139
106 def prepare(self): 140 def prepare(self):
107 self._prepare = True 141 self._prepare += 1
142
143 def apply_patch(self, patchset):
144 self._apply_patch.append(patchset)
108 145
109 def commit(self, message, author): 146 def commit(self, message, author):
110 self._commit = True 147 self._commit.append((message, author))
111 148
112 def get_settings(self, key): 149 def get_settings(self, key):
113 return None 150 return None
114 151
115 152
116 class PendingManager(unittest.TestCase): 153 class PendingManager(unittest.TestCase):
117 def setUp(self): 154 def setUp(self):
118 super(PendingManager, self).setUp() 155 super(PendingManager, self).setUp()
119 self.root_dir = ROOT_DIR 156 self.root_dir = ROOT_DIR
120 self._old_send_stack = pending_manager.breakpad.SendStack 157 self._old_send_stack = pending_manager.breakpad.SendStack
(...skipping 19 matching lines...) Expand all
140 self.assertEquals(pc.queue.pending_commits, []) 177 self.assertEquals(pc.queue.pending_commits, [])
141 pc.save(filename) 178 pc.save(filename)
142 self.assertEquals(trim(empty), trim(read(filename))) 179 self.assertEquals(trim(empty), trim(read(filename)))
143 finally: 180 finally:
144 os.remove(filename) 181 os.remove(filename)
145 if os.path.exists(filename + '.old'): 182 if os.path.exists(filename + '.old'):
146 os.remove(filename + '.old') 183 os.remove(filename + '.old')
147 184
148 def _get_pc(self, verifiers_no_patch, verifiers): 185 def _get_pc(self, verifiers_no_patch, verifiers):
149 pc = pending_manager.PendingManager( 186 pc = pending_manager.PendingManager(
150 FakeRietveld(self), FakeCheckout(), verifiers_no_patch, verifiers) 187 FakeRietveld(), FakeCheckout(), verifiers_no_patch, verifiers)
151 188
152 def fake_issues():
153 return [31337]
154 def apply_patch(pending, revision): 189 def apply_patch(pending, revision):
155 pc._patch_applied = True 190 pc._patch_applied = True
156 191
157 pc._fetch_pending_issues = fake_issues
158 pc._apply_patch = apply_patch 192 pc._apply_patch = apply_patch
159 pc._patch_applied = False 193 pc._patch_applied = False
160 return pc 194 return pc
161 195
162 def testNoVerification(self): 196 def testNoVerification(self):
163 try: 197 try:
164 pending_manager.PendingManager( 198 pending_manager.PendingManager(
165 FakeRietveld(self), FakeCheckout(), [], []) 199 FakeRietveld(), FakeCheckout(), [], [])
166 self.fail() 200 self.fail()
167 except AssertionError: 201 except AssertionError:
168 pass 202 pass
169 try: 203 try:
170 pending_manager.PendingManager( 204 pending_manager.PendingManager(
171 FakeRietveld(self), 205 FakeRietveld(),
172 FakeCheckout(), 206 FakeCheckout(),
173 [fake.FakeVerifier(base.SUCCEEDED)], 207 [fake.FakeVerifier(base.SUCCEEDED)],
174 [fake.FakeVerifier(base.SUCCEEDED)]) 208 [fake.FakeVerifier(base.SUCCEEDED)])
175 self.fail() 209 self.fail()
176 except AssertionError: 210 except AssertionError:
177 pass 211 pass
178 212
179 def _check_1(self, pc, result): 213 def _check_1(self, pc, result):
180 self.assertEquals(len(pc.queue.pending_commits), 0) 214 self.assertEquals(len(pc.queue.pending_commits), 0)
181 pc.look_for_new_pending_commit() 215 pc.look_for_new_pending_commit()
182 self.assertEquals(len(pc.queue.pending_commits), 1) 216 self.assertEquals(len(pc.queue.pending_commits), 1)
183 commit = pc.queue.pending_commits[0] 217 commit = pc.queue.pending_commits[0]
184 self.assertEquals(len(commit.verifications), 0) 218 self.assertEquals(len(commit.verifications), 0)
185 pc.process_new_pending_commit() 219 pc.process_new_pending_commit()
186 commit = pc.queue.pending_commits[0] 220 commit = pc.queue.pending_commits[0]
187 self.assertEquals(commit.verifications['fake'].get_state(), result) 221 self.assertEquals(commit.verifications['fake'].get_state(), result)
188 self.assertEquals(len(commit.verifications), 1) 222 self.assertEquals(len(commit.verifications), 1)
189 pc.update_status() 223 pc.update_status()
190 commit = pc.queue.pending_commits[0] 224 commit = pc.queue.pending_commits[0]
191 self.assertEquals(commit.verifications['fake'].get_state(), result) 225 self.assertEquals(commit.verifications['fake'].get_state(), result)
226 self.assertEquals('', commit.relpath)
192 self.assertEquals(len(commit.verifications), 1) 227 self.assertEquals(len(commit.verifications), 1)
193 pc.scan_results() 228 pc.scan_results()
194 self.assertEquals(len(pc.queue.pending_commits), 0) 229 self.assertEquals(len(pc.queue.pending_commits), 0)
195 self.assertEquals(pc.checkout._commit, result == base.SUCCEEDED) 230 self.assertEquals(len(pc.checkout._commit), result == base.SUCCEEDED)
196 231
197 def testNoPatchVerification(self): 232 def testNoPatchVerification(self):
198 pc = self._get_pc([fake.FakeVerifier(base.SUCCEEDED)], []) 233 pc = self._get_pc([fake.FakeVerifier(base.SUCCEEDED)], [])
199 self._check_1(pc, base.SUCCEEDED) 234 self._check_1(pc, base.SUCCEEDED)
200 235
201 def testPatchVerification(self): 236 def testPatchVerification(self):
202 pc = self._get_pc([], [fake.FakeVerifier(base.SUCCEEDED)]) 237 pc = self._get_pc([], [fake.FakeVerifier(base.SUCCEEDED)])
203 self._check_1(pc, base.SUCCEEDED) 238 self._check_1(pc, base.SUCCEEDED)
204 239
205 def testNoPatchVerificationFail(self): 240 def testNoPatchVerificationFail(self):
(...skipping 22 matching lines...) Expand all
228 self.assertEquals([True], result) 263 self.assertEquals([True], result)
229 264
230 def _check_defer_1(self, pc, result): 265 def _check_defer_1(self, pc, result):
231 self.assertEquals(len(pc.queue.pending_commits), 0) 266 self.assertEquals(len(pc.queue.pending_commits), 0)
232 pc.look_for_new_pending_commit() 267 pc.look_for_new_pending_commit()
233 self.assertEquals(len(pc.queue.pending_commits), 1) 268 self.assertEquals(len(pc.queue.pending_commits), 1)
234 commit = pc.queue.pending_commits[0] 269 commit = pc.queue.pending_commits[0]
235 self.assertEquals(len(commit.verifications), 0) 270 self.assertEquals(len(commit.verifications), 0)
236 pc.process_new_pending_commit() 271 pc.process_new_pending_commit()
237 commit = pc.queue.pending_commits[0] 272 commit = pc.queue.pending_commits[0]
273 self.assertEquals('', commit.relpath)
238 self.assertEquals(commit.verifications['fake'].get_state(), base.PROCESSING) 274 self.assertEquals(commit.verifications['fake'].get_state(), base.PROCESSING)
239 self.assertEquals(len(commit.verifications), 1) 275 self.assertEquals(len(commit.verifications), 1)
240 pc.update_status() 276 pc.update_status()
241 commit = pc.queue.pending_commits[0] 277 commit = pc.queue.pending_commits[0]
278 self.assertEquals('', commit.relpath)
242 self.assertEquals(commit.verifications['fake'].get_state(), result) 279 self.assertEquals(commit.verifications['fake'].get_state(), result)
243 self.assertEquals(len(commit.verifications), 1) 280 self.assertEquals(len(commit.verifications), 1)
244 pc.scan_results() 281 pc.scan_results()
245 self.assertEquals(len(pc.queue.pending_commits), 0) 282 self.assertEquals(len(pc.queue.pending_commits), 0)
246 self.assertEquals(pc.checkout._commit, result == base.SUCCEEDED) 283 self.assertEquals(len(pc.checkout._commit), result == base.SUCCEEDED)
247 284
248 def testDeferNoPatchVerification(self): 285 def testDeferNoPatchVerification(self):
249 pc = self._get_pc([fake.DeferredFakeVerifier(base.SUCCEEDED)], []) 286 pc = self._get_pc([fake.DeferredFakeVerifier(base.SUCCEEDED)], [])
250 self._check_defer_1(pc, base.SUCCEEDED) 287 self._check_defer_1(pc, base.SUCCEEDED)
251 288
252 def testDeferPatchVerification(self): 289 def testDeferPatchVerification(self):
253 pc = self._get_pc([], [fake.DeferredFakeVerifier(base.SUCCEEDED)]) 290 pc = self._get_pc([], [fake.DeferredFakeVerifier(base.SUCCEEDED)])
254 self._check_defer_1(pc, base.SUCCEEDED) 291 self._check_defer_1(pc, base.SUCCEEDED)
255 292
256 def testDeferNoPatchVerificationFail(self): 293 def testDeferNoPatchVerificationFail(self):
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 if nb >= 2: 335 if nb >= 2:
299 self.assertEquals(commit.verifications['fake2'].get_state(), f2) 336 self.assertEquals(commit.verifications['fake2'].get_state(), f2)
300 if nb >= 3: 337 if nb >= 3:
301 self.assertEquals(commit.verifications['fake3'].get_state(), f3) 338 self.assertEquals(commit.verifications['fake3'].get_state(), f3)
302 if nb >= 4: 339 if nb >= 4:
303 self.assertEquals(commit.verifications['fake4'].get_state(), f4) 340 self.assertEquals(commit.verifications['fake4'].get_state(), f4)
304 self.assertEquals(len(commit.verifications), nb) 341 self.assertEquals(len(commit.verifications), nb)
305 pc.scan_results() 342 pc.scan_results()
306 self.assertEquals(len(pc.queue.pending_commits), 0) 343 self.assertEquals(len(pc.queue.pending_commits), 0)
307 self.assertEquals( 344 self.assertEquals(
308 pc.checkout._commit, 345 len(pc.checkout._commit),
309 all(x == base.SUCCEEDED for x in (f1, f2, f3, f4))) 346 all(x == base.SUCCEEDED for x in (f1, f2, f3, f4)))
310 347
311 def test4thVerificationFail(self): 348 def test4thVerificationFail(self):
312 self._check_4(base.SUCCEEDED, base.SUCCEEDED, base.SUCCEEDED, base.FAILED) 349 self._check_4(base.SUCCEEDED, base.SUCCEEDED, base.SUCCEEDED, base.FAILED)
313 350
314 def test4Verification(self): 351 def test4Verification(self):
315 self._check_4( 352 self._check_4(
316 base.SUCCEEDED, base.SUCCEEDED, base.SUCCEEDED, base.SUCCEEDED) 353 base.SUCCEEDED, base.SUCCEEDED, base.SUCCEEDED, base.SUCCEEDED)
317 354
318 def test4Verification3rdFail(self): 355 def test4Verification3rdFail(self):
(...skipping 23 matching lines...) Expand all
342 self.assertEquals( 379 self.assertEquals(
343 commit.verifications['fake3'].get_state(), base.PROCESSING) 380 commit.verifications['fake3'].get_state(), base.PROCESSING)
344 self.assertEquals( 381 self.assertEquals(
345 commit.verifications['fake4'].get_state(), base.PROCESSING) 382 commit.verifications['fake4'].get_state(), base.PROCESSING)
346 self.assertEquals(len(commit.verifications), 4) 383 self.assertEquals(len(commit.verifications), 4)
347 pc.update_status() 384 pc.update_status()
348 self.assertEquals(commit.verifications['fake1'].get_state(), f1) 385 self.assertEquals(commit.verifications['fake1'].get_state(), f1)
349 self.assertEquals(commit.verifications['fake2'].get_state(), f2) 386 self.assertEquals(commit.verifications['fake2'].get_state(), f2)
350 self.assertEquals(commit.verifications['fake3'].get_state(), f3) 387 self.assertEquals(commit.verifications['fake3'].get_state(), f3)
351 self.assertEquals(commit.verifications['fake4'].get_state(), f4) 388 self.assertEquals(commit.verifications['fake4'].get_state(), f4)
389 self.assertEquals('', commit.relpath)
352 pc.scan_results() 390 pc.scan_results()
353 self.assertEquals(len(pc.queue.pending_commits), 0) 391 self.assertEquals(len(pc.queue.pending_commits), 0)
354 self.assertEquals( 392 self.assertEquals(
355 pc.checkout._commit, 393 len(pc.checkout._commit),
356 all(x == base.SUCCEEDED for x in (f1, f2, f3, f4))) 394 all(x == base.SUCCEEDED for x in (f1, f2, f3, f4)))
357 395
358 def testDefer4thVerificationFail(self): 396 def testDefer4thVerificationFail(self):
359 self._check_defer_4( 397 self._check_defer_4(
360 base.SUCCEEDED, base.SUCCEEDED, base.SUCCEEDED, base.FAILED) 398 base.SUCCEEDED, base.SUCCEEDED, base.SUCCEEDED, base.FAILED)
361 399
362 def testDefer4Verification(self): 400 def testDefer4Verification(self):
363 self._check_defer_4( 401 self._check_defer_4(
364 base.SUCCEEDED, base.SUCCEEDED, base.SUCCEEDED, base.SUCCEEDED) 402 base.SUCCEEDED, base.SUCCEEDED, base.SUCCEEDED, base.SUCCEEDED)
365 403
366 def testDefer4Verification3rdFail(self): 404 def testDefer4Verification3rdFail(self):
367 self._check_defer_4( 405 self._check_defer_4(
368 base.SUCCEEDED, base.SUCCEEDED, base.FAILED, base.SUCCEEDED) 406 base.SUCCEEDED, base.SUCCEEDED, base.FAILED, base.SUCCEEDED)
369 407
408 def testRelPath(self):
409 verifiers = [
410 project_base.ProjectBaseUrlVerifier(
411 [r'^%s(.*)$' % re.escape(r'http://example.com/')]),
412 ]
413 pc = pending_manager.PendingManager(
414 FakeRietveld(), FakeCheckout(), verifiers, [])
415 pc.rietveld.issues[31337]['base_url'] = 'http://example.com/sub/dir'
416 pc.look_for_new_pending_commit()
417 self.assertEquals(1, len(pc.queue.pending_commits))
418 pc.process_new_pending_commit()
419 self.assertEquals('sub/dir', pc.queue.pending_commits[0].relpath)
420 self.assertEquals(1, pc.checkout._prepare)
421 self.assertEquals(1, len(pc.checkout._apply_patch))
422 self.assertEquals([], pc.checkout._commit)
423 pc.update_status()
424 self.assertEquals(1, pc.checkout._prepare)
425 self.assertEquals(1, len(pc.checkout._apply_patch))
426 self.assertEquals([], pc.checkout._commit)
427 patches = pc.checkout._apply_patch[0]
428 self.assertEquals(
429 ['sub/dir/chrome/file.cc', 'sub/dir/other/place/foo', 'sub/dir/foo'],
430 patches.filenames)
431 pc.scan_results()
432 self.assertEquals(2, pc.checkout._prepare)
433 self.assertEquals(2, len(pc.checkout._apply_patch))
434 self.assertEquals(
435 [('foo\n\nReview URL: http://nowhere/31337', 'author@example.com')],
436 pc.checkout._commit)
437
370 438
371 if __name__ == '__main__': 439 if __name__ == '__main__':
372 logging.basicConfig(level=logging.ERROR) 440 logging.basicConfig(level=logging.ERROR)
373 unittest.main() 441 unittest.main()
OLDNEW
« no previous file with comments | « pending_manager.py ('k') | tests/project_base_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698