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

Side by Side Diff: tests/pending_manager_test.py

Issue 6880115: Add post_processing code to update copyright year automatically. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/commit-queue
Patch Set: Significantly simplify code 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 | « tests/chromium_copyright_test.py ('k') | no next file » | 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 re
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 { 95 {
96 "date": "2010-12-27 03:23:32.489999", 96 "date": "2010-12-27 03:23:32.489999",
97 "text": "hi!", 97 "text": "hi!",
98 "sender": "author@example.com", 98 "sender": "author@example.com",
99 "recipients": ["rev@example.com", "cc@example.com"], 99 "recipients": ["rev@example.com", "cc@example.com"],
100 }, 100 },
101 ], 101 ],
102 "commit": True, 102 "commit": True,
103 }, 103 },
104 } 104 }
105 self.patchsets = []
105 106
106 def get_pending_issues(self): 107 def get_pending_issues(self):
107 return self.issues.keys() 108 return self.issues.keys()
108 109
109 def get_issue_properties(self, issue_id, _): 110 def get_issue_properties(self, issue_id, _):
110 return self.issues[issue_id] 111 return self.issues[issue_id]
111 112
112 def close_issue(self, issue): 113 def close_issue(self, issue):
113 pass 114 pass
114 115
115 def update_description(self, issue, text): 116 def update_description(self, issue, text):
116 pass 117 pass
117 118
118 def set_flag(self, issue, patchset, flag, value): 119 def set_flag(self, issue, patchset, flag, value):
119 pass 120 pass
120 121
121 def add_comment(self, issue, text): 122 def add_comment(self, issue, text):
122 pass 123 pass
123 124
124 def get_patch(self, issue, patchset): 125 def get_patch(self, issue, patchset):
125 return patch.PatchSet([ 126 self.patchsets.append(patch.PatchSet([
126 patch.FilePatchDiff('chrome/file.cc', SVN_PATCH, []), 127 patch.FilePatchDiff('chrome/file.cc', SVN_PATCH, []),
127 patch.FilePatchDelete('other/place/foo', True), 128 patch.FilePatchDelete('other/place/foo', True),
128 patch.FilePatchBinary('foo', 'data', []), 129 patch.FilePatchBinary('foo', 'data', []),
129 ]) 130 ]))
131 return self.patchsets[-1]
130 132
131 133
132 class FakeCheckout(object): 134 class FakeCheckout(object):
133 project_path = os.getcwd() 135 project_path = os.getcwd()
134 136
135 def __init__(self): 137 def __init__(self):
136 self._prepare = 0 138 self._prepare = 0
137 self._commit = [] 139 self._commit = []
138 self._apply_patch = [] 140 self._apply_patch = []
139 141
140 def prepare(self): 142 def prepare(self):
141 self._prepare += 1 143 self._prepare += 1
142 144
143 def apply_patch(self, patchset): 145 def apply_patch(self, *args):
144 self._apply_patch.append(patchset) 146 self._apply_patch.append(args)
145 147
146 def commit(self, message, author): 148 def commit(self, *args):
147 self._commit.append((message, author)) 149 self._commit.append(args)
148 150
149 def get_settings(self, key): 151 def get_settings(self, key):
150 return None 152 return None
151 153
152 154
153 class PendingManager(unittest.TestCase): 155 class TestPendingManager(unittest.TestCase):
154 def setUp(self): 156 def setUp(self):
155 super(PendingManager, self).setUp() 157 super(TestPendingManager, self).setUp()
156 self.root_dir = ROOT_DIR 158 self.root_dir = ROOT_DIR
157 self._old_send_stack = pending_manager.breakpad.SendStack 159 self._old_send_stack = pending_manager.breakpad.SendStack
158 pending_manager.breakpad.SendStack = _SendStackFail 160 pending_manager.breakpad.SendStack = _SendStackFail
159 161
160 def tearDown(self): 162 def tearDown(self):
161 pending_manager.breakpad.SendStack = self._old_send_stack 163 pending_manager.breakpad.SendStack = self._old_send_stack
162 super(PendingManager, self).tearDown() 164 super(TestPendingManager, self).tearDown()
163 165
164 def testLoadSave(self): 166 def testLoadSave(self):
165 pc = pending_manager.PendingManager( 167 pc = pending_manager.PendingManager(
166 None, None, [fake.FakeVerifier(base.SUCCEEDED)], []) 168 None, None, [fake.FakeVerifier(base.SUCCEEDED)], [], [])
167 filename = os.path.join(self.root_dir, 'foo.json') 169 filename = os.path.join(self.root_dir, 'foo.json')
168 empty = """{ 170 empty = """{
169 "__persistent_module__": "pending_manager", 171 "__persistent_module__": "pending_manager",
170 "__persistent_type__": "PendingQueue", 172 "__persistent_type__": "PendingQueue",
171 "pending_commits": [] 173 "pending_commits": []
172 } 174 }
173 """ 175 """
174 write(filename, empty) 176 write(filename, empty)
175 try: 177 try:
176 pc.load(filename) 178 pc.load(filename)
177 self.assertEquals(pc.queue.pending_commits, []) 179 self.assertEquals(pc.queue.pending_commits, [])
178 pc.save(filename) 180 pc.save(filename)
179 self.assertEquals(trim(empty), trim(read(filename))) 181 self.assertEquals(trim(empty), trim(read(filename)))
180 finally: 182 finally:
181 os.remove(filename) 183 os.remove(filename)
182 if os.path.exists(filename + '.old'): 184 if os.path.exists(filename + '.old'):
183 os.remove(filename + '.old') 185 os.remove(filename + '.old')
184 186
185 def _get_pc(self, verifiers_no_patch, verifiers): 187 def _get_pc(self, verifiers_no_patch, verifiers):
186 pc = pending_manager.PendingManager( 188 pc = pending_manager.PendingManager(
187 FakeRietveld(), FakeCheckout(), verifiers_no_patch, verifiers) 189 FakeRietveld(), FakeCheckout(), verifiers_no_patch, verifiers, [])
188 190
189 def apply_patch(pending, revision): 191 def apply_patch(pending, revision):
190 pc._patch_applied = True 192 pc._patch_applied = True
191 193
192 pc._apply_patch = apply_patch 194 pc._apply_patch = apply_patch
193 pc._patch_applied = False 195 pc._patch_applied = False
194 return pc 196 return pc
195 197
196 def testNoVerification(self): 198 def testNoVerification(self):
197 try: 199 try:
198 pending_manager.PendingManager( 200 pending_manager.PendingManager(
199 FakeRietveld(), FakeCheckout(), [], []) 201 FakeRietveld(), FakeCheckout(), [], [], [])
200 self.fail() 202 self.fail()
201 except AssertionError: 203 except AssertionError:
202 pass 204 pass
203 try: 205 try:
204 pending_manager.PendingManager( 206 pending_manager.PendingManager(
205 FakeRietveld(), 207 FakeRietveld(),
206 FakeCheckout(), 208 FakeCheckout(),
207 [fake.FakeVerifier(base.SUCCEEDED)], 209 [fake.FakeVerifier(base.SUCCEEDED)],
208 [fake.FakeVerifier(base.SUCCEEDED)]) 210 [fake.FakeVerifier(base.SUCCEEDED)],
211 [])
209 self.fail() 212 self.fail()
210 except AssertionError: 213 except AssertionError:
211 pass 214 pass
212 215
213 def _check_1(self, pc, result): 216 def _check_1(self, pc, result):
214 self.assertEquals(len(pc.queue.pending_commits), 0) 217 self.assertEquals(len(pc.queue.pending_commits), 0)
215 pc.look_for_new_pending_commit() 218 pc.look_for_new_pending_commit()
216 self.assertEquals(len(pc.queue.pending_commits), 1) 219 self.assertEquals(len(pc.queue.pending_commits), 1)
217 commit = pc.queue.pending_commits[0] 220 commit = pc.queue.pending_commits[0]
218 self.assertEquals(len(commit.verifications), 0) 221 self.assertEquals(len(commit.verifications), 0)
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 406
404 def testDefer4Verification3rdFail(self): 407 def testDefer4Verification3rdFail(self):
405 self._check_defer_4( 408 self._check_defer_4(
406 base.SUCCEEDED, base.SUCCEEDED, base.FAILED, base.SUCCEEDED) 409 base.SUCCEEDED, base.SUCCEEDED, base.FAILED, base.SUCCEEDED)
407 410
408 def testRelPath(self): 411 def testRelPath(self):
409 verifiers = [ 412 verifiers = [
410 project_base.ProjectBaseUrlVerifier( 413 project_base.ProjectBaseUrlVerifier(
411 [r'^%s(.*)$' % re.escape(r'http://example.com/')]), 414 [r'^%s(.*)$' % re.escape(r'http://example.com/')]),
412 ] 415 ]
416 r = FakeRietveld()
417 processors = [object()]
413 pc = pending_manager.PendingManager( 418 pc = pending_manager.PendingManager(
414 FakeRietveld(), FakeCheckout(), verifiers, []) 419 r, FakeCheckout(), verifiers, [], processors)
415 pc.rietveld.issues[31337]['base_url'] = 'http://example.com/sub/dir' 420 pc.rietveld.issues[31337]['base_url'] = 'http://example.com/sub/dir'
416 pc.look_for_new_pending_commit() 421 pc.look_for_new_pending_commit()
417 self.assertEquals(1, len(pc.queue.pending_commits)) 422 self.assertEquals(1, len(pc.queue.pending_commits))
418 pc.process_new_pending_commit() 423 pc.process_new_pending_commit()
419 self.assertEquals('sub/dir', pc.queue.pending_commits[0].relpath) 424 self.assertEquals('sub/dir', pc.queue.pending_commits[0].relpath)
420 self.assertEquals(1, pc.checkout._prepare) 425 self.assertEquals(1, pc.checkout._prepare)
421 self.assertEquals(1, len(pc.checkout._apply_patch)) 426 self.assertEquals([(r.patchsets[0], processors)], pc.checkout._apply_patch)
422 self.assertEquals([], pc.checkout._commit) 427 self.assertEquals([], pc.checkout._commit)
423 pc.update_status() 428 pc.update_status()
424 self.assertEquals(1, pc.checkout._prepare) 429 self.assertEquals(1, pc.checkout._prepare)
425 self.assertEquals(1, len(pc.checkout._apply_patch)) 430 self.assertEquals([(r.patchsets[0], processors)], pc.checkout._apply_patch)
426 self.assertEquals([], pc.checkout._commit) 431 self.assertEquals([], pc.checkout._commit)
427 patches = pc.checkout._apply_patch[0] 432 patches = pc.checkout._apply_patch[0]
428 self.assertEquals( 433 self.assertEquals(
429 ['sub/dir/chrome/file.cc', 'sub/dir/other/place/foo', 'sub/dir/foo'], 434 ['sub/dir/chrome/file.cc', 'sub/dir/other/place/foo', 'sub/dir/foo'],
430 patches.filenames) 435 patches[0].filenames)
431 pc.scan_results() 436 pc.scan_results()
432 self.assertEquals(2, pc.checkout._prepare) 437 self.assertEquals(2, pc.checkout._prepare)
433 self.assertEquals(2, len(pc.checkout._apply_patch)) 438 self.assertEquals(
439 [(r.patchsets[0], processors), (r.patchsets[1], processors)],
440 pc.checkout._apply_patch)
434 self.assertEquals( 441 self.assertEquals(
435 [('foo\n\nReview URL: http://nowhere/31337', 'author@example.com')], 442 [('foo\n\nReview URL: http://nowhere/31337', 'author@example.com')],
436 pc.checkout._commit) 443 pc.checkout._commit)
437 444
438 445
439 if __name__ == '__main__': 446 if __name__ == '__main__':
440 logging.basicConfig(level=logging.ERROR) 447 logging.basicConfig(level=logging.ERROR)
441 unittest.main() 448 unittest.main()
OLDNEW
« no previous file with comments | « tests/chromium_copyright_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698