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

Side by Side Diff: tests/git_cl_test.py

Issue 9264065: Add minimal Gerrit support to 'git cl config' and 'git cl upload' (Closed) Base URL: svn://chrome-svn/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 8 years, 10 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 | « git_cl.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/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 git_cl.py.""" 6 """Unit tests for git_cl.py."""
7 7
8 import os 8 import os
9 import StringIO 9 import StringIO
10 import sys 10 import sys
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 self._calls_done += 1 81 self._calls_done += 1
82 return result 82 return result
83 83
84 @classmethod 84 @classmethod
85 def _upload_calls(cls): 85 def _upload_calls(cls):
86 return cls._git_base_calls() + cls._git_upload_calls() 86 return cls._git_base_calls() + cls._git_upload_calls()
87 87
88 @staticmethod 88 @staticmethod
89 def _git_base_calls(): 89 def _git_base_calls():
90 return [ 90 return [
91 ((['git', 'config', 'gerrit.host'],), ''),
91 ((['git', 'update-index', '--refresh', '-q'],), ''), 92 ((['git', 'update-index', '--refresh', '-q'],), ''),
92 ((['git', 'diff-index', 'HEAD'],), ''), 93 ((['git', 'diff-index', 'HEAD'],), ''),
93 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), 94 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'),
94 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 95 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
95 ((['git', 'config', 'branch.master.merge'],), 'master'), 96 ((['git', 'config', 'branch.master.merge'],), 'master'),
96 ((['git', 'config', 'branch.master.remote'],), 'origin'), 97 ((['git', 'config', 'branch.master.remote'],), 'origin'),
97 ((['git', 'rev-parse', '--show-cdup'],), ''), 98 ((['git', 'rev-parse', '--show-cdup'],), ''),
98 ((['git', 'rev-parse', 'HEAD'],), '12345'), 99 ((['git', 'rev-parse', 'HEAD'],), '12345'),
99 ((['git', 'diff', '--name-status', '-r', 'master...', '.'],), 100 ((['git', 'diff', '--name-status', '-r', 'master...', '.'],),
100 'M\t.gitignore\n'), 101 'M\t.gitignore\n'),
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 git_cl.main(['dcommit']) 315 git_cl.main(['dcommit'])
315 316
316 def test_dcommit_bypass_hooks(self): 317 def test_dcommit_bypass_hooks(self):
317 self.calls = ( 318 self.calls = (
318 self._dcommit_calls_1() + 319 self._dcommit_calls_1() +
319 self._dcommit_calls_bypassed() + 320 self._dcommit_calls_bypassed() +
320 self._dcommit_calls_3()) 321 self._dcommit_calls_3())
321 git_cl.main(['dcommit', '--bypass-hooks']) 322 git_cl.main(['dcommit', '--bypass-hooks'])
322 323
323 324
325 @staticmethod
326 def _gerrit_base_calls():
327 return [
328 ((['git', 'config', 'gerrit.host'],), 'gerrit.example.com'),
329 ((['git', 'update-index', '--refresh', '-q'],), ''),
330 ((['git', 'diff-index', 'HEAD'],), ''),
331 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'),
332 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
333 ((['git', 'config', 'branch.master.merge'],), 'master'),
334 ((['git', 'config', 'branch.master.remote'],), 'origin'),
335 ((['git', 'rev-parse', '--show-cdup'],), ''),
336 ((['git', 'rev-parse', 'HEAD'],), '12345'),
337 ((['git', 'diff', '--name-status', '-r', 'master...', '.'],),
338 'M\t.gitignore\n'),
339 ((['git', 'rev-parse', '--git-dir'],), '.git'),
340 ((['git', 'config', 'branch.master.rietveldissue'],), ''),
341 ((['git', 'config', 'branch.master.rietveldpatchset'],), ''),
342 ((['git', 'log', '--pretty=format:%s%n%n%b', 'master...'],), 'foo'),
343 ((['git', 'config', 'user.email'],), 'me@example.com'),
344 ((['git', 'diff', '--no-ext-diff', '--stat', '-M', 'master...'],),
345 '+dat'),
346 ]
347
348 @staticmethod
349 def _gerrit_upload_calls(description, reviewers):
350 calls = [
351 ((['git', 'log', '--pretty=format:%s\n\n%b', 'master..'],),
352 description),
353 ((['git', 'config', 'rietveld.cc'],), '')
354 ]
355 receive_pack = '--receive-pack="git receive-pack '
356 receive_pack += '--cc=joe@example.com' # from watch list
357 if reviewers:
358 receive_pack += ' '
359 receive_pack += ' '.join(['--reviewer=' + email for email in reviewers])
360 receive_pack += '"'
361 calls += [
362 ((['git', 'push', receive_pack, 'origin', 'HEAD:refs/for/master'],),
363 '')
364 ]
365 return calls
366
367 def _run_gerrit_reviewer_test(
368 self,
369 upload_args,
370 description,
371 reviewers):
372 """Generic gerrit reviewer test framework."""
373 self.calls = self._gerrit_base_calls()
374 self.calls += self._gerrit_upload_calls(description, reviewers)
375 git_cl.main(['upload'] + upload_args)
376
377 def test_gerrit_no_reviewer(self):
378 self._run_gerrit_reviewer_test(
379 [],
380 'desc\n\nBUG=\nTEST=\n',
381 [])
382
383 def test_gerrit_reviewers_cmd_line(self):
384 self._run_gerrit_reviewer_test(
385 ['-r', 'foo@example.com'],
386 'desc\n\nBUG=\nTEST=\n',
387 ['foo@example.com'])
388
389 def test_gerrit_reviewer_multiple(self):
390 self._run_gerrit_reviewer_test(
391 [],
392 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n',
393 ['reviewer@example.com', 'another@example.com'])
394
395
324 if __name__ == '__main__': 396 if __name__ == '__main__':
325 unittest.main() 397 unittest.main()
OLDNEW
« no previous file with comments | « git_cl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698