def test_dcommit(self): self.calls = ( self._dcommit_calls_1() + self._git_sanity_checks('fake_ancestor_sha', 'working') + self._dcommit_calls_normal() + self._dcommit_calls_3()) git_cl.main(['dcommit'])
def test_dcommit(self): self.calls = ( self._dcommit_calls_1() + self._git_sanity_checks("fake_ancestor_sha", "working") + self._dcommit_calls_normal() + self._dcommit_calls_3() ) git_cl.main(["dcommit"])
def _run_gerrit_upload_test( self, upload_args, description, reviewers): """Generic gerrit upload test framework.""" self.calls = self._gerrit_base_calls() self.calls += self._gerrit_upload_calls(description, reviewers) git_cl.main(['upload'] + upload_args)
def _run_gerrit_upload_test(self, upload_args, description, reviewers, squash=False): """Generic gerrit upload test framework.""" self.calls = self._gerrit_base_calls() self.calls += self._gerrit_upload_calls(description, reviewers, squash) git_cl.main(['upload'] + upload_args)
def _run_gerrit_upload_test( self, upload_args, description, reviewers, squash=False, expected_upstream_ref="origin/refs/heads/master" ): """Generic gerrit upload test framework.""" self.calls = self._gerrit_base_calls() self.calls += self._gerrit_upload_calls( description, reviewers, squash, expected_upstream_ref=expected_upstream_ref ) git_cl.main(["upload"] + upload_args)
def _run_gerrit_reviewer_test( self, upload_args, description, reviewers): """Generic gerrit reviewer test framework.""" self.calls = self._gerrit_base_calls() self.calls += self._gerrit_upload_calls(description, reviewers) git_cl.main(['upload'] + upload_args)
def test_config_gerrit_download_hook(self): self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) def ParseCodereviewSettingsContent(content): keyvals = {} keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' keyvals['GERRIT_HOST'] = 'gerrit.chromium.org' keyvals['GERRIT_PORT'] = '29418' return keyvals self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent', ParseCodereviewSettingsContent) self.mock(git_cl.os, 'access', self._mocked_call) self.mock(git_cl.os, 'chmod', self._mocked_call) src_dir = os.path.join(os.path.sep, 'usr', 'local', 'src') def AbsPath(path): if not path.startswith(os.path.sep): return os.path.join(src_dir, path) return path self.mock(git_cl.os.path, 'abspath', AbsPath) commit_msg_path = os.path.join(src_dir, '.git', 'hooks', 'commit-msg') def Exists(path): if path == commit_msg_path: return False # others paths, such as /usr/share/locale/.... return True self.mock(git_cl.os.path, 'exists', Exists) self.mock(git_cl.urllib, 'urlretrieve', self._mocked_call) self.calls = [ ((['git', 'config', 'rietveld.server', 'gerrit.chromium.org'],), ''), ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''), ((['git', 'config', '--unset-all', 'rietveld.tree-status-url'],), ''), ((['git', 'config', '--unset-all', 'rietveld.viewvc-url'],), ''), ((['git', 'config', 'gerrit.host', 'gerrit.chromium.org'],), ''), ((['git', 'config', 'gerrit.port', '29418'],), ''), # DownloadHooks(False) ((['git', 'config', 'gerrit.host'],), 'gerrit.chromium.org'), ((['git', 'config', 'rietveld.server'],), 'gerrit.chromium.org'), ((['git', 'rev-parse', '--show-cdup'],), ''), ((commit_msg_path, os.X_OK,), False), (('https://gerrit.chromium.org/tools/hooks/commit-msg', commit_msg_path,), ''), ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''), # GetCodereviewSettingsInteractively ((['git', 'config', 'rietveld.server'],), 'gerrit.chromium.org'), (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',), ''), ((['git', 'config', 'rietveld.cc'],), ''), (('CC list:',), ''), ((['git', 'config', 'rietveld.tree-status-url'],), ''), (('Tree status URL:',), ''), ((['git', 'config', 'rietveld.viewvc-url'],), ''), (('ViewVC URL:',), ''), # DownloadHooks(True) ((commit_msg_path, os.X_OK,), True), ] git_cl.main(['config'])
def test_config_gerrit_download_hook(self): self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) def ParseCodereviewSettingsContent(content): keyvals = {} keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' keyvals['GERRIT_HOST'] = 'gerrit.chromium.org' keyvals['GERRIT_PORT'] = '29418' return keyvals self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent', ParseCodereviewSettingsContent) self.mock(git_cl.os, 'access', self._mocked_call) self.mock(git_cl.os, 'chmod', self._mocked_call) src_dir = os.path.join(os.path.sep, 'usr', 'local', 'src') def AbsPath(path): if not path.startswith(os.path.sep): return os.path.join(src_dir, path) return path self.mock(git_cl.os.path, 'abspath', AbsPath) commit_msg_path = os.path.join(src_dir, '.git', 'hooks', 'commit-msg') def Exists(path): if path == commit_msg_path: return False # others paths, such as /usr/share/locale/.... return True self.mock(git_cl.os.path, 'exists', Exists) self.mock(git_cl, 'urlretrieve', self._mocked_call) self.calls = [ ((['git', 'config', 'rietveld.server', 'gerrit.chromium.org'],), ''), ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''), ((['git', 'config', '--unset-all', 'rietveld.tree-status-url'],), ''), ((['git', 'config', '--unset-all', 'rietveld.viewvc-url'],), ''), ((['git', 'config', 'gerrit.host', 'gerrit.chromium.org'],), ''), ((['git', 'config', 'gerrit.port', '29418'],), ''), # DownloadHooks(False) ((['git', 'config', 'gerrit.host'],), 'gerrit.chromium.org'), ((['git', 'config', 'rietveld.server'],), 'gerrit.chromium.org'), ((['git', 'rev-parse', '--show-cdup'],), ''), ((commit_msg_path, os.X_OK,), False), (('https://gerrit.chromium.org/tools/hooks/commit-msg', commit_msg_path,), ''), ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''), # GetCodereviewSettingsInteractively ((['git', 'config', 'rietveld.server'],), 'gerrit.chromium.org'), (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',), ''), ((['git', 'config', 'rietveld.cc'],), ''), (('CC list:',), ''), ((['git', 'config', 'rietveld.tree-status-url'],), ''), (('Tree status URL:',), ''), ((['git', 'config', 'rietveld.viewvc-url'],), ''), (('ViewVC URL:',), ''), # DownloadHooks(True) ((commit_msg_path, os.X_OK,), True), ] git_cl.main(['config'])
def test_trybots_from_PRESUBMIT(self): TEST_MASTER = 'testMaster' TEST_BUILDER = 'testBuilder' MASTERS = {TEST_MASTER:{TEST_BUILDER:['a']}} self.mock(presubmit_support, 'DoGetTryMasters', lambda *args: MASTERS) change_mock = ChangeMock() changelist_mock = ChangelistMock(change_mock) self.mock(git_cl, 'is_dirty_git_tree', lambda x: False) self.mock(git_cl, 'print_stats', lambda *arg: True) self.mock(git_cl, 'Changelist', lambda *args: changelist_mock) self.mock(git_cl, 'CreateDescriptionFromLog', lambda arg: 'Commit message') self.mock(git_cl.ChangeDescription, 'prompt', lambda self: None) self.calls = [ ((['git', 'config', 'rietveld.autoupdate',],), ''), ((['git', 'config', 'gerrit.host',],), ''), ((['git', 'rev-parse', '--show-cdup',],), ''), ((['git', 'config', 'rietveld.private',],), ''), ((['git', 'config', '--local', '--get-regexp', '^svn-remote\\.'],), ''), ((['git', 'config', 'rietveld.project',],), ''), ((['git', 'rev-parse', 'HEAD',],), ''), ] stored_description = [] def check_upload(args): i = 0 for arg in args: if arg == '--message': break i += 1 self.assertTrue(i < len(args)) stored_description.append(args[i+1]) return 1, 2 self.mock(git_cl.upload, 'RealMain', check_upload) git_cl.main(['upload', '--bypass-hooks', '--auto-bots']) found = re.search("CQ_TRYBOTS=(.*?)$", stored_description[0]) self.assertTrue(found) self.assertEqual(found.group(1), '%s:%s' % (TEST_MASTER, TEST_BUILDER))
def _run_gerrit_upload_test( self, upload_args, description, reviewers, squash=False, expected_upstream_ref='origin/refs/heads/master'): """Generic gerrit upload test framework.""" self.calls = self._gerrit_base_calls() self.calls += self._gerrit_upload_calls( description, reviewers, squash, expected_upstream_ref=expected_upstream_ref) git_cl.main(['upload'] + upload_args)
def test_patch_conflict(self): self._patch_common() self.calls += [ ((['git', 'apply', '--index', '-p0', '--3way'], ), '', subprocess2.CalledProcessError(1, '', '', '', '')), ] self.assertNotEqual(git_cl.main(['patch', '123456']), 0)
def test_patch_conflict(self): self._patch_common() self.calls += [ ((['git', 'apply', '--index', '-p0', '--3way'],), '', subprocess2.CalledProcessError(1, '', '', '', '')), ] self.assertNotEqual(git_cl.main(['patch', '123456']), 0)
def test_gerrit_patch_conflict(self): self._patch_common(is_gerrit=True) self.mock(git_cl, 'DieWithError', lambda msg: self._mocked_call(['DieWithError', msg])) class SystemExitMock(Exception): pass self.calls += [ ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo', 'refs/changes/56/123456/1'],), ''), ((['git', 'cherry-pick', 'FETCH_HEAD'],), '', subprocess2.CalledProcessError(1, '', '', '', '')), ((['DieWithError', 'git cherry-pick FETCH_HEAD" failed.\n'],), '', SystemExitMock()), ] with self.assertRaises(SystemExitMock): git_cl.main(['patch', 'https://chromium-review.googlesource.com/#/c/123456/1'])
def _run_gerrit_upload_test( self, upload_args, description, reviewers, squash=False, expected_upstream_ref='origin/refs/heads/master', post_amend_description=None): """Generic gerrit upload test framework.""" self.calls = self._gerrit_base_calls() self.calls += self._gerrit_upload_calls( description, reviewers, squash, expected_upstream_ref=expected_upstream_ref, post_amend_description=post_amend_description) # Uncomment when debugging. # print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls))) git_cl.main(['upload'] + upload_args)
def _run_reviewer_test( self, upload_args, expected_description, returned_description, final_description, reviewers, private=False): """Generic reviewer test framework.""" try: similarity = upload_args[upload_args.index('--similarity')+1] except ValueError: similarity = None if '--find-copies' in upload_args: find_copies = True elif '--no-find-copies' in upload_args: find_copies = False else: find_copies = None private = '--private' in upload_args self.calls = self._upload_calls(similarity, find_copies, private) def RunEditor(desc, _, **kwargs): self.assertEquals( '# Enter a description of the change.\n' '# This will be displayed on the codereview site.\n' '# The first line will also be used as the subject of the review.\n' '#--------------------This line is 72 characters long' '--------------------\n' + expected_description, desc) return returned_description self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) def check_upload(args): cmd_line = self._cmd_line(final_description, reviewers, similarity, find_copies, private) self.assertEquals(cmd_line, args) return 1, 2 self.mock(git_cl.upload, 'RealMain', check_upload) git_cl.main(['upload'] + upload_args)
def test_patch_successful(self): self._patch_common() self.calls += [ ((['git', 'apply', '--index', '-p0', '--3way'],), ''), ((['git', 'commit', '-m', 'patch from issue 123456 at patchset 60001 ' + '(http://crrev.com/123456#ps60001)'],), ''), ] self.assertEqual(git_cl.main(['patch', '123456']), 0)
def test_reviewer_send_mail_no_rev(self): # Fails without a reviewer. class FileMock(object): buf = StringIO.StringIO() def write(self, content): self.buf.write(content) mock = FileMock() try: self.calls = self._git_base_calls() def RunEditor(desc, _): return desc self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) self.mock(sys, 'stderr', mock) git_cl.main(['upload', '--send-mail']) self.fail() except SystemExit: self.assertEquals( 'Must specify reviewers to send email.\n', mock.buf.getvalue())
def test_reviewer_send_mail_no_rev(self): # Fails without a reviewer. class FileMock(object): buf = StringIO.StringIO() def write(self, content): self.buf.write(content) mock = FileMock() try: self.calls = self._git_base_calls(None, None) def RunEditor(desc, _): return desc self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) self.mock(sys, 'stderr', mock) git_cl.main(['upload', '--send-mail']) self.fail() except SystemExit: self.assertEquals( 'Must specify reviewers to send email.\n', mock.buf.getvalue())
def test_trybots_from_PRESUBMIT(self): TEST_MASTER = "testMaster" TEST_BUILDER = "testBuilder" MASTERS = {TEST_MASTER: {TEST_BUILDER: ["a"]}} self.mock(presubmit_support, "DoGetTryMasters", lambda *args: MASTERS) change_mock = ChangeMock() changelist_mock = ChangelistMock(change_mock) self.mock(git_cl, "is_dirty_git_tree", lambda x: False) self.mock(git_cl, "print_stats", lambda *arg: True) self.mock(git_cl, "Changelist", lambda *args: changelist_mock) self.mock(git_cl, "CreateDescriptionFromLog", lambda arg: "Commit message") self.mock(git_cl.ChangeDescription, "prompt", lambda self: None) self.calls = [ ((["git", "config", "rietveld.autoupdate"],), ""), ((["git", "config", "gerrit.host"],), ""), ((["git", "rev-parse", "--show-cdup"],), ""), ((["git", "config", "rietveld.private"],), ""), ((["git", "config", "--local", "--get-regexp", "^svn-remote\\."],), ""), ((["git", "config", "rietveld.project"],), ""), ((["git", "rev-parse", "HEAD"],), ""), ] stored_description = [] def check_upload(args): i = 0 for arg in args: if arg == "--message": break i += 1 self.assertTrue(i < len(args)) stored_description.append(args[i + 1]) return 1, 2 self.mock(git_cl.upload, "RealMain", check_upload) git_cl.main(["upload", "--bypass-hooks", "--auto-bots"]) found = re.search("CQ_TRYBOTS=(.*?)$", stored_description[0]) self.assertTrue(found) self.assertEqual(found.group(1), "%s:%s" % (TEST_MASTER, TEST_BUILDER))
def test_patch_successful(self): self._patch_common() self.calls += [ ((['git', 'apply', '--index', '-p0', '--3way'], ), ''), (([ 'git', 'commit', '-m', 'Description\n\n' + 'patch from issue 123456 at patchset 60001 ' + '(http://crrev.com/123456#ps60001)' ], ), ''), ] self.assertEqual(git_cl.main(['patch', '123456']), 0)
def test_reviewer_send_mail_no_rev(self): # Fails without a reviewer. stdout = StringIO.StringIO() stderr = StringIO.StringIO() try: self.calls = self._upload_no_rev_calls(None, None) def RunEditor(desc, _, **kwargs): return desc self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) self.mock(sys, 'stdout', stdout) self.mock(sys, 'stderr', stderr) git_cl.main(['upload', '--send-mail']) self.fail() except SystemExit: self.assertEqual( 'Using 50% similarity for rename/copy detection. Override with ' '--similarity.\n', stdout.getvalue()) self.assertEqual( 'Must specify reviewers to send email.\n', stderr.getvalue())
def test_patch_when_dirty(self): # Patch when local tree is dirty self.mock(git_common, 'is_dirty_git_tree', lambda x: True) self.calls = [ ((['git', 'symbolic-ref', 'HEAD'],), 'master'), ((['git', 'config', 'branch.master.rietveldissue'],), ''), ((['git', 'config', 'branch.master.gerritissue'],), ''), ((['git', 'config', 'rietveld.autoupdate'],), ''), ((['git', 'config', 'gerrit.host'],), ''), ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), ] self.assertNotEqual(git_cl.main(['patch', '123456']), 0)
def _run_gerrit_upload_test( self, upload_args, description, reviewers, squash=False, expected_upstream_ref='origin/refs/heads/master', post_amend_description=None, issue=None): """Generic gerrit upload test framework.""" self.calls = self._gerrit_base_calls(issue=issue) self.calls += self._gerrit_upload_calls( description, reviewers, squash, expected_upstream_ref=expected_upstream_ref, post_amend_description=post_amend_description, issue=issue) # Uncomment when debugging. # print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls))) git_cl.main(['upload'] + upload_args)
def _run_reviewer_test(self, upload_args, expected_description, returned_description, final_description, reviewers): """Generic reviewer test framework.""" self.calls = self._upload_calls() def RunEditor(desc, _): self.assertEquals( '# Enter a description of the change.\n' '# This will displayed on the codereview site.\n' '# The first line will also be used as the subject of the review.\n' + expected_description, desc) return returned_description self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) def check_upload(args): self.assertEquals(self._cmd_line(final_description, reviewers), args) return 1, 2 self.mock(git_cl.upload, 'RealMain', check_upload) git_cl.main(['upload'] + upload_args)
def test_patch_when_dirty(self): # Patch when local tree is dirty self.mock(git_common, 'is_dirty_git_tree', lambda x: True) self.calls = [ ((['git', 'symbolic-ref', 'HEAD'], ), 'master'), ((['git', 'config', 'branch.master.rietveldissue'], ), ''), ((['git', 'config', 'branch.master.gerritissue'], ), ''), ((['git', 'config', 'rietveld.autoupdate'], ), ''), ((['git', 'config', 'gerrit.host'], ), ''), ((['git', 'config', 'rietveld.server'], ), 'codereview.example.com'), ] self.assertNotEqual(git_cl.main(['patch', '123456']), 0)
def test_gerrit_patch_url_successful(self): self._patch_common(is_gerrit=True) self.calls += [ ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo', 'refs/changes/56/123456/1'],), ''), ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''), ((['git', 'config', 'branch.master.gerritissue', '123456'],), ''), ((['git', 'config', 'branch.master.gerritserver', 'https://chromium-review.googlesource.com'],), ''), ((['git', 'config', 'branch.master.gerritpatchset', '1'],), ''), ] self.assertEqual(git_cl.main( ['patch', 'https://chromium-review.googlesource.com/#/c/123456/1']), 0)
def _run_reviewer_test( self, upload_args, expected_description, returned_description, final_description, reviewers): """Generic reviewer test framework.""" self.calls = self._upload_calls() def RunEditor(desc, _): self.assertEquals( '# Enter a description of the change.\n' '# This will displayed on the codereview site.\n' '# The first line will also be used as the subject of the review.\n' + expected_description, desc) return returned_description self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) def check_upload(args): self.assertEquals(self._cmd_line(final_description, reviewers), args) return 1, 2 self.mock(git_cl.upload, 'RealMain', check_upload) git_cl.main(['upload'] + upload_args)
def test_gerrit_patch_conflict(self): self._patch_common(is_gerrit=True) self.mock(git_cl, 'DieWithError', lambda msg: self._mocked_call(['DieWithError', msg])) class SystemExitMock(Exception): pass self.calls += [ (([ 'git', 'fetch', 'https://chromium.googlesource.com/my/repo', 'refs/changes/56/123456/1' ], ), ''), ((['git', 'cherry-pick', 'FETCH_HEAD'], ), '', subprocess2.CalledProcessError(1, '', '', '', '')), ((['DieWithError', 'git cherry-pick FETCH_HEAD" failed.\n'], ), '', SystemExitMock()), ] with self.assertRaises(SystemExitMock): git_cl.main([ 'patch', 'https://chromium-review.googlesource.com/#/c/123456/1' ])
def test_patch_successful(self): self._patch_common() self.calls += [ ((['git', 'apply', '--index', '-p0', '--3way'],), ''), ((['git', 'commit', '-m', 'Description\n\n' + 'patch from issue 123456 at patchset 60001 ' + '(http://crrev.com/123456#ps60001)'],), ''), ((['git', 'config', 'branch.master.rietveldissue', '123456'],), ''), ((['git', 'config', 'branch.master.rietveldserver'],), ''), ((['git', 'config', 'branch.master.rietveldserver', 'https://codereview.example.com'],), ''), ((['git', 'config', 'branch.master.rietveldpatchset', '60001'],), ''), ] self.assertEqual(git_cl.main(['patch', '123456']), 0)
def test_patch_successful(self): self._patch_common() self.calls += [ ((["git", "apply", "--index", "-p0", "--3way"],), ""), ( ( [ "git", "commit", "-m", "Description\n\n" + "patch from issue 123456 at patchset 60001 " + "(http://crrev.com/123456#ps60001)", ], ), "", ), ] self.assertEqual(git_cl.main(["patch", "123456"]), 0)
def test_gerrit_patch_url_successful(self): self._patch_common(is_gerrit=True) self.calls += [ (([ 'git', 'fetch', 'https://chromium.googlesource.com/my/repo', 'refs/changes/56/123456/1' ], ), ''), ((['git', 'cherry-pick', 'FETCH_HEAD'], ), ''), ((['git', 'config', 'branch.master.gerritissue', '123456'], ), ''), (([ 'git', 'config', 'branch.master.gerritserver', 'https://chromium-review.googlesource.com' ], ), ''), ((['git', 'config', 'branch.master.gerritpatchset', '1'], ), ''), ] self.assertEqual( git_cl.main([ 'patch', 'https://chromium-review.googlesource.com/#/c/123456/1' ]), 0)
def test_patch_successful(self): self._patch_common() self.calls += [ ((['git', 'apply', '--index', '-p0', '--3way'], ), ''), (([ 'git', 'commit', '-m', 'Description\n\n' + 'patch from issue 123456 at patchset 60001 ' + '(http://crrev.com/123456#ps60001)' ], ), ''), ((['git', 'config', 'branch.master.rietveldissue', '123456'], ), ''), ((['git', 'config', 'branch.master.rietveldserver'], ), ''), (([ 'git', 'config', 'branch.master.rietveldserver', 'https://codereview.example.com' ], ), ''), ((['git', 'config', 'branch.master.rietveldpatchset', '60001'], ), ''), ] self.assertEqual(git_cl.main(['patch', '123456']), 0)
def test_trybots_from_PRESUBMIT(self): TEST_MASTER = 'testMaster' TEST_BUILDER = 'testBuilder' MASTERS = {TEST_MASTER: {TEST_BUILDER: ['a']}} self.mock(presubmit_support, 'DoGetTryMasters', lambda *args: MASTERS) change_mock = ChangeMock() changelist_mock = ChangelistMock(change_mock) self.mock(git_cl, 'is_dirty_git_tree', lambda x: False) self.mock(git_cl, 'print_stats', lambda *arg: True) self.mock(git_cl, 'Changelist', lambda *args: changelist_mock) self.mock(git_cl, 'CreateDescriptionFromLog', lambda arg: 'Commit message') self.mock(git_cl.ChangeDescription, 'prompt', lambda self: None) self.calls = [ (([ 'git', 'config', 'rietveld.autoupdate', ], ), ''), (([ 'git', 'config', 'gerrit.host', ], ), ''), (([ 'git', 'rev-parse', '--show-cdup', ], ), ''), (([ 'git', 'config', 'rietveld.private', ], ), ''), ((['git', 'config', '--local', '--get-regexp', '^svn-remote\\.'], ), ''), (([ 'git', 'config', 'rietveld.project', ], ), ''), (([ 'git', 'rev-parse', 'HEAD', ], ), ''), ] stored_description = [] def check_upload(args): i = 0 for arg in args: if arg == '--message': break i += 1 self.assertTrue(i < len(args)) stored_description.append(args[i + 1]) return 1, 2 self.mock(git_cl.upload, 'RealMain', check_upload) git_cl.main(['upload', '--bypass-hooks', '--auto-bots']) found = re.search("CQ_TRYBOTS=(.*?)$", stored_description[0]) self.assertTrue(found) self.assertEqual(found.group(1), '%s:%s' % (TEST_MASTER, TEST_BUILDER))
def test_dcommit(self): self.calls = ( self._dcommit_calls_1() + self._dcommit_calls_normal() + self._dcommit_calls_3()) git_cl.main(['dcommit'])
def test_dcommit_bypass_hooks(self): self.calls = (self._dcommit_calls_1() + self._dcommit_calls_bypassed() + self._dcommit_calls_3()) git_cl.main(['dcommit', '--bypass-hooks'])
def test_patch_when_dirty(self): # Patch when local tree is dirty self.mock(git_common, 'is_dirty_git_tree', lambda x: True) self.assertNotEqual(git_cl.main(['patch', '123456']), 0)
def test_diff_when_dirty(self): # Do 'git cl diff' when local tree is dirty self.mock(git_common, 'is_dirty_git_tree', lambda x: True) self.assertNotEqual(git_cl.main(['diff']), 0)
def test_patch_conflict(self): self._patch_common() self.calls += [ ((["git", "apply", "--index", "-p0", "--3way"],), "", subprocess2.CalledProcessError(1, "", "", "", "")) ] self.assertNotEqual(git_cl.main(["patch", "123456"]), 0)
def test_diff_when_dirty(self): # Do 'git cl diff' when local tree is dirty self.mock(git_common, "is_dirty_git_tree", lambda x: True) self.assertNotEqual(git_cl.main(["diff"]), 0)
def test_patch_when_dirty(self): # Patch when local tree is dirty self.mock(git_common, "is_dirty_git_tree", lambda x: True) self.assertNotEqual(git_cl.main(["patch", "123456"]), 0)
def test_dcommit_bypass_hooks(self): self.calls = self._dcommit_calls_1() + self._dcommit_calls_bypassed() + self._dcommit_calls_3() git_cl.main(["dcommit", "--bypass-hooks"])
def test_dcommit_bypass_hooks(self): self.calls = ( self._dcommit_calls_1() + self._dcommit_calls_bypassed() + self._dcommit_calls_3()) git_cl.main(['dcommit', '--bypass-hooks'])
def test_config_gerrit_download_hook(self): self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) def ParseCodereviewSettingsContent(content): keyvals = {} keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' keyvals['GERRIT_HOST'] = 'True' return keyvals self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent', ParseCodereviewSettingsContent) self.mock(git_cl.os, 'access', self._mocked_call) self.mock(git_cl.os, 'chmod', self._mocked_call) src_dir = os.path.join(os.path.sep, 'usr', 'local', 'src') def AbsPath(path): if not path.startswith(os.path.sep): return os.path.join(src_dir, path) return path self.mock(git_cl.os.path, 'abspath', AbsPath) commit_msg_path = os.path.join(src_dir, '.git', 'hooks', 'commit-msg') def Exists(path): if path == commit_msg_path: return False # others paths, such as /usr/share/locale/.... return True self.mock(git_cl.os.path, 'exists', Exists) self.mock(git_cl, 'urlretrieve', self._mocked_call) self.mock(git_cl, 'hasSheBang', self._mocked_call) self.calls = [ ((['git', 'config', 'rietveld.autoupdate'], ), ''), ((['git', 'config', 'rietveld.server', 'gerrit.chromium.org'], ), ''), ((['git', 'config', '--unset-all', 'rietveld.cc'], ), ''), ((['git', 'config', '--unset-all', 'rietveld.private'], ), ''), ((['git', 'config', '--unset-all', 'rietveld.tree-status-url'], ), ''), ((['git', 'config', '--unset-all', 'rietveld.viewvc-url'], ), ''), ((['git', 'config', '--unset-all', 'rietveld.bug-prefix'], ), ''), ((['git', 'config', '--unset-all', 'rietveld.cpplint-regex'], ), ''), (([ 'git', 'config', '--unset-all', 'rietveld.force-https-commit-url' ], ), ''), (([ 'git', 'config', '--unset-all', 'rietveld.cpplint-ignore-regex' ], ), ''), ((['git', 'config', '--unset-all', 'rietveld.project'], ), ''), ((['git', 'config', '--unset-all', 'rietveld.pending-ref-prefix'], ), ''), (([ 'git', 'config', '--unset-all', 'rietveld.run-post-upload-hook' ], ), ''), ((['git', 'config', 'gerrit.host', 'True'], ), ''), # DownloadHooks(False) ((['git', 'config', 'gerrit.host'], ), 'True'), ((['git', 'rev-parse', '--show-cdup'], ), ''), (( commit_msg_path, os.X_OK, ), False), (( 'https://gerrit-review.googlesource.com/tools/hooks/commit-msg', commit_msg_path, ), ''), ((commit_msg_path, ), True), (( commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR, ), ''), # GetCodereviewSettingsInteractively ((['git', 'config', 'rietveld.server'], ), 'gerrit.chromium.org'), (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:', ), ''), ((['git', 'config', 'rietveld.cc'], ), ''), (('CC list:', ), ''), ((['git', 'config', 'rietveld.private'], ), ''), (('Private flag (rietveld only):', ), ''), ((['git', 'config', 'rietveld.tree-status-url'], ), ''), (('Tree status URL:', ), ''), ((['git', 'config', 'rietveld.viewvc-url'], ), ''), (('ViewVC URL:', ), ''), # DownloadHooks(True) ((['git', 'config', 'rietveld.bug-prefix'], ), ''), (('Bug Prefix:', ), ''), ((['git', 'config', 'rietveld.run-post-upload-hook'], ), ''), (('Run Post Upload Hook:', ), ''), (( commit_msg_path, os.X_OK, ), True), ] git_cl.main(['config'])
def test_config_gerrit_download_hook(self): self.mock(git_cl, "FindCodereviewSettingsFile", CodereviewSettingsFileMock) def ParseCodereviewSettingsContent(content): keyvals = {} keyvals["CODE_REVIEW_SERVER"] = "gerrit.chromium.org" keyvals["GERRIT_HOST"] = "gerrit.chromium.org" keyvals["GERRIT_PORT"] = "29418" return keyvals self.mock(git_cl.gclient_utils, "ParseCodereviewSettingsContent", ParseCodereviewSettingsContent) self.mock(git_cl.os, "access", self._mocked_call) self.mock(git_cl.os, "chmod", self._mocked_call) src_dir = os.path.join(os.path.sep, "usr", "local", "src") def AbsPath(path): if not path.startswith(os.path.sep): return os.path.join(src_dir, path) return path self.mock(git_cl.os.path, "abspath", AbsPath) commit_msg_path = os.path.join(src_dir, ".git", "hooks", "commit-msg") def Exists(path): if path == commit_msg_path: return False # others paths, such as /usr/share/locale/.... return True self.mock(git_cl.os.path, "exists", Exists) self.mock(git_cl, "urlretrieve", self._mocked_call) self.mock(git_cl, "hasSheBang", self._mocked_call) self.calls = [ ((["git", "config", "rietveld.autoupdate"],), ""), ((["git", "config", "rietveld.server", "gerrit.chromium.org"],), ""), ((["git", "config", "--unset-all", "rietveld.cc"],), ""), ((["git", "config", "--unset-all", "rietveld.private"],), ""), ((["git", "config", "--unset-all", "rietveld.tree-status-url"],), ""), ((["git", "config", "--unset-all", "rietveld.viewvc-url"],), ""), ((["git", "config", "--unset-all", "rietveld.bug-prefix"],), ""), ((["git", "config", "--unset-all", "rietveld.cpplint-regex"],), ""), ((["git", "config", "--unset-all", "rietveld.force-https-commit-url"],), ""), ((["git", "config", "--unset-all", "rietveld.cpplint-ignore-regex"],), ""), ((["git", "config", "--unset-all", "rietveld.project"],), ""), ((["git", "config", "--unset-all", "rietveld.pending-ref-prefix"],), ""), ((["git", "config", "--unset-all", "rietveld.run-post-upload-hook"],), ""), ((["git", "config", "gerrit.host", "gerrit.chromium.org"],), ""), # DownloadHooks(False) ((["git", "config", "gerrit.host"],), "gerrit.chromium.org"), ((["git", "rev-parse", "--show-cdup"],), ""), ((commit_msg_path, os.X_OK), False), (("https://gerrit-review.googlesource.com/tools/hooks/commit-msg", commit_msg_path), ""), ((commit_msg_path,), True), ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR), ""), # GetCodereviewSettingsInteractively ((["git", "config", "rietveld.server"],), "gerrit.chromium.org"), (("Rietveld server (host[:port]) [https://gerrit.chromium.org]:",), ""), ((["git", "config", "rietveld.cc"],), ""), (("CC list:",), ""), ((["git", "config", "rietveld.private"],), ""), (("Private flag (rietveld only):",), ""), ((["git", "config", "rietveld.tree-status-url"],), ""), (("Tree status URL:",), ""), ((["git", "config", "rietveld.viewvc-url"],), ""), (("ViewVC URL:",), ""), # DownloadHooks(True) ((["git", "config", "rietveld.bug-prefix"],), ""), (("Bug Prefix:",), ""), ((["git", "config", "rietveld.run-post-upload-hook"],), ""), (("Run Post Upload Hook:",), ""), ((commit_msg_path, os.X_OK), True), ] git_cl.main(["config"])
def test_config_gerrit_download_hook(self): self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) def ParseCodereviewSettingsContent(content): keyvals = {} keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' keyvals['GERRIT_HOST'] = 'True' return keyvals self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent', ParseCodereviewSettingsContent) self.mock(git_cl.os, 'access', self._mocked_call) self.mock(git_cl.os, 'chmod', self._mocked_call) src_dir = os.path.join(os.path.sep, 'usr', 'local', 'src') def AbsPath(path): if not path.startswith(os.path.sep): return os.path.join(src_dir, path) return path self.mock(git_cl.os.path, 'abspath', AbsPath) commit_msg_path = os.path.join(src_dir, '.git', 'hooks', 'commit-msg') def Exists(path): if path == commit_msg_path: return False # others paths, such as /usr/share/locale/.... return True self.mock(git_cl.os.path, 'exists', Exists) self.mock(git_cl, 'urlretrieve', self._mocked_call) self.mock(git_cl, 'hasSheBang', self._mocked_call) self.calls = [ ((['git', 'config', 'rietveld.autoupdate'],), ''), ((['git', 'config', 'rietveld.server', 'gerrit.chromium.org'],), ''), ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''), ((['git', 'config', '--unset-all', 'rietveld.private'],), ''), ((['git', 'config', '--unset-all', 'rietveld.tree-status-url'],), ''), ((['git', 'config', '--unset-all', 'rietveld.viewvc-url'],), ''), ((['git', 'config', '--unset-all', 'rietveld.bug-prefix'],), ''), ((['git', 'config', '--unset-all', 'rietveld.cpplint-regex'],), ''), ((['git', 'config', '--unset-all', 'rietveld.force-https-commit-url'],), ''), ((['git', 'config', '--unset-all', 'rietveld.cpplint-ignore-regex'],), ''), ((['git', 'config', '--unset-all', 'rietveld.project'],), ''), ((['git', 'config', '--unset-all', 'rietveld.pending-ref-prefix'],), ''), ((['git', 'config', '--unset-all', 'rietveld.run-post-upload-hook'],), ''), ((['git', 'config', 'gerrit.host', 'True'],), ''), # DownloadHooks(False) ((['git', 'config', 'gerrit.host'],), 'True'), ((['git', 'rev-parse', '--show-cdup'],), ''), ((commit_msg_path, os.X_OK,), False), (('https://gerrit-review.googlesource.com/tools/hooks/commit-msg', commit_msg_path,), ''), ((commit_msg_path,), True), ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''), # GetCodereviewSettingsInteractively ((['git', 'config', 'rietveld.server'],), 'gerrit.chromium.org'), (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',), ''), ((['git', 'config', 'rietveld.cc'],), ''), (('CC list:',), ''), ((['git', 'config', 'rietveld.private'],), ''), (('Private flag (rietveld only):',), ''), ((['git', 'config', 'rietveld.tree-status-url'],), ''), (('Tree status URL:',), ''), ((['git', 'config', 'rietveld.viewvc-url'],), ''), (('ViewVC URL:',), ''), # DownloadHooks(True) ((['git', 'config', 'rietveld.bug-prefix'],), ''), (('Bug Prefix:',), ''), ((['git', 'config', 'rietveld.run-post-upload-hook'],), ''), (('Run Post Upload Hook:',), ''), ((commit_msg_path, os.X_OK,), True), ] git_cl.main(['config'])