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

Side by Side Diff: tests/git_cl_test.py

Issue 9369023: Download hooks only in "git cl config" (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 stat
10 import sys 11 import sys
11 import unittest 12 import unittest
12 13
13 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 14 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
14 15
15 from testing_support.auto_stub import TestCase 16 from testing_support.auto_stub import TestCase
16 17
17 import git_cl 18 import git_cl
18 import subprocess2 19 import subprocess2
19 20
(...skipping 15 matching lines...) Expand all
35 36
36 37
37 class WatchlistsMock(object): 38 class WatchlistsMock(object):
38 def __init__(self, _): 39 def __init__(self, _):
39 pass 40 pass
40 @staticmethod 41 @staticmethod
41 def GetWatchersForPaths(_): 42 def GetWatchersForPaths(_):
42 return ['joe@example.com'] 43 return ['joe@example.com']
43 44
44 45
46 class CodereviewSettingsFileMock(object):
47 def __init__(self):
48 pass
49 def read(self):
Marc-Antoine Ruel (Google) 2012/02/13 20:47:52 You can disable the warning at file level. It's no
50 return ("CODE_REVIEW_SERVER: gerrit.chromium.org\n" +
51 "GERRIT_HOST: gerrit.chromium.org\n" +
52 "GERRIT_PORT: 29418\n")
53
54
45 class TestGitCl(TestCase): 55 class TestGitCl(TestCase):
46 def setUp(self): 56 def setUp(self):
47 super(TestGitCl, self).setUp() 57 super(TestGitCl, self).setUp()
48 self.calls = [] 58 self.calls = []
49 self._calls_done = 0 59 self._calls_done = 0
50 self.mock(subprocess2, 'call', self._mocked_call) 60 self.mock(subprocess2, 'call', self._mocked_call)
51 self.mock(subprocess2, 'check_call', self._mocked_call) 61 self.mock(subprocess2, 'check_call', self._mocked_call)
52 self.mock(subprocess2, 'check_output', self._mocked_call) 62 self.mock(subprocess2, 'check_output', self._mocked_call)
53 self.mock(subprocess2, 'communicate', self._mocked_call) 63 self.mock(subprocess2, 'communicate', self._mocked_call)
54 self.mock(subprocess2, 'Popen', self._mocked_call) 64 self.mock(subprocess2, 'Popen', self._mocked_call)
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 'desc\n\nBUG=\nTEST=\n', 396 'desc\n\nBUG=\nTEST=\n',
387 ['foo@example.com']) 397 ['foo@example.com'])
388 398
389 def test_gerrit_reviewer_multiple(self): 399 def test_gerrit_reviewer_multiple(self):
390 self._run_gerrit_reviewer_test( 400 self._run_gerrit_reviewer_test(
391 [], 401 [],
392 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n', 402 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n',
393 ['reviewer@example.com', 'another@example.com']) 403 ['reviewer@example.com', 'another@example.com'])
394 404
395 405
406 def test_config_gerrit_download_hook(self):
407 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock)
408 def ParseCodereviewSettingsContent(content):
409 keyvals = {}
410 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org'
411 keyvals['GERRIT_HOST'] = 'gerrit.chromium.org'
412 keyvals['GERRIT_PORT'] = '29418'
413 return keyvals
414 self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent',
415 ParseCodereviewSettingsContent)
416 self.mock(git_cl.os, 'access', self._mocked_call)
417 self.mock(git_cl.os, 'chmod', self._mocked_call)
418 def AbsPath(path):
419 if not path.startswith('/'):
420 return os.path.join('/usr/local/src', path)
421 return path
422 self.mock(git_cl.os.path, 'abspath', AbsPath)
423 def Exists(path):
424 if path == '/usr/local/src/.git/hooks/commit-msg':
425 return False
426 # others paths, such as /usr/share/locale/....
427 return True
428 self.mock(git_cl.os.path, 'exists', Exists)
429 self.mock(git_cl.urllib, 'urlretrieve', self._mocked_call)
430 self.calls = [
431 ((['git', 'config', 'rietveld.server', 'gerrit.chromium.org'],), ''),
432 ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''),
433 ((['git', 'config', '--unset-all', 'rietveld.tree-status-url'],), ''),
434 ((['git', 'config', '--unset-all', 'rietveld.viewvc-url'],), ''),
435 ((['git', 'config', 'gerrit.host', 'gerrit.chromium.org'],), ''),
436 ((['git', 'config', 'gerrit.port', '29418'],), ''),
437 # DownloadHooks(False)
438 ((['git', 'config', 'gerrit.host'],), 'gerrit.chromium.org'),
439 ((['git', 'config', 'rietveld.server'],), 'gerrit.chromium.org'),
440 ((['git', 'rev-parse', '--show-cdup'],), ''),
441 (('/usr/local/src/.git/hooks/commit-msg', os.X_OK,), False),
442 (('https://gerrit.chromium.org/tools/hooks/commit-msg',
443 '/usr/local/src/.git/hooks/commit-msg',), ''),
444 (('/usr/local/src/.git/hooks/commit-msg',
445 stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''),
446 # GetCodereviewSettingsInteractively
447 ((['git', 'config', 'rietveld.server'],), 'gerrit.chromium.org'),
448 (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',),
449 ''),
450 ((['git', 'config', 'rietveld.cc'],), ''),
451 (('CC list:',), ''),
452 ((['git', 'config', 'rietveld.tree-status-url'],), ''),
453 (('Tree status URL:',), ''),
454 ((['git', 'config', 'rietveld.viewvc-url'],), ''),
455 (('ViewVC URL:',), ''),
456 # DownloadHooks(True)
457 (('/usr/local/src/.git/hooks/commit-msg', os.X_OK,), True),
458 ]
459 git_cl.main(['config'])
460
461
396 if __name__ == '__main__': 462 if __name__ == '__main__':
397 unittest.main() 463 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