Skip tests not supported in non-git env if in non-git env

Some depot_tools commands now fail explicitly on cog. Skip their
non-supported tests too if on cog.

Bug: b/333744051
Change-Id: Ifa4116d1f8951d4cc28826570c4ea06773a71502
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5742101
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
changes/01/5742101/3
Gavin Mak 1 year ago committed by LUCI CQ
parent fca881606e
commit 99198b3f70

@ -1272,6 +1272,8 @@ class TestGitCl(unittest.TestCase):
scm.GIT.GetBranchConfig('', 'main', scm.GIT.GetBranchConfig('', 'main',
git_cl.GERRIT_SQUASH_HASH_CONFIG_KEY)) git_cl.GERRIT_SQUASH_HASH_CONFIG_KEY))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_gerrit_upload_traces_no_gitcookies(self): def test_gerrit_upload_traces_no_gitcookies(self):
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
['--no-squash'], ['--no-squash'],
@ -1281,6 +1283,8 @@ class TestGitCl(unittest.TestCase):
change_id='Ixxx', change_id='Ixxx',
gitcookies_exists=False) gitcookies_exists=False)
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_gerrit_upload_without_change_id_nosquash(self): def test_gerrit_upload_without_change_id_nosquash(self):
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
['--no-squash'], ['--no-squash'],
@ -1289,6 +1293,8 @@ class TestGitCl(unittest.TestCase):
post_amend_description='desc ✔\n\nBUG=\n\nChange-Id: Ixxx', post_amend_description='desc ✔\n\nBUG=\n\nChange-Id: Ixxx',
change_id='Ixxx') change_id='Ixxx')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_gerrit_upload_without_change_id_override_nosquash(self): def test_gerrit_upload_without_change_id_override_nosquash(self):
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
[], [],
@ -1298,6 +1304,8 @@ class TestGitCl(unittest.TestCase):
post_amend_description='desc ✔\n\nBUG=\n\nChange-Id: Ixxx', post_amend_description='desc ✔\n\nBUG=\n\nChange-Id: Ixxx',
change_id='Ixxx') change_id='Ixxx')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_gerrit_no_reviewer(self): def test_gerrit_no_reviewer(self):
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
[], [],
@ -1306,6 +1314,8 @@ class TestGitCl(unittest.TestCase):
squash_mode='override_nosquash', squash_mode='override_nosquash',
change_id='I123456789') change_id='I123456789')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_gerrit_push_opts(self): def test_gerrit_push_opts(self):
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
['-o', 'wip'], ['-o', 'wip'],
@ -1315,6 +1325,8 @@ class TestGitCl(unittest.TestCase):
change_id='I123456789', change_id='I123456789',
push_opts=['-o', 'wip']) push_opts=['-o', 'wip'])
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_gerrit_no_reviewer_non_chromium_host(self): def test_gerrit_no_reviewer_non_chromium_host(self):
# TODO(crbug/877717): remove this test case. # TODO(crbug/877717): remove this test case.
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
@ -1325,6 +1337,8 @@ class TestGitCl(unittest.TestCase):
short_hostname='other', short_hostname='other',
change_id='I123456789') change_id='I123456789')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_gerrit_patchset_title_special_chars_nosquash(self): def test_gerrit_patchset_title_special_chars_nosquash(self):
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
['-f', '-t', 'We\'ll escape ^_ ^ special chars...@{u}'], ['-f', '-t', 'We\'ll escape ^_ ^ special chars...@{u}'],
@ -1334,6 +1348,8 @@ class TestGitCl(unittest.TestCase):
change_id='I123456789', change_id='I123456789',
title='We\'ll escape ^_ ^ special chars...@{u}') title='We\'ll escape ^_ ^ special chars...@{u}')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_gerrit_reviewers_cmd_line(self): def test_gerrit_reviewers_cmd_line(self):
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
['-r', 'foo@example.com', '--send-mail'], ['-r', 'foo@example.com', '--send-mail'],
@ -1346,6 +1362,8 @@ class TestGitCl(unittest.TestCase):
final_description=( final_description=(
'desc ✔\n\nBUG=\nR=foo@example.com\n\nChange-Id: I123456789')) 'desc ✔\n\nBUG=\nR=foo@example.com\n\nChange-Id: I123456789'))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_gerrit_reviewers_cmd_line_send_email(self): def test_gerrit_reviewers_cmd_line_send_email(self):
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
['-r', 'foo@example.com', '--send-email'], ['-r', 'foo@example.com', '--send-email'],
@ -2377,6 +2395,8 @@ class TestGitCl(unittest.TestCase):
}, },
} }
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_patch_gerrit_default(self): def test_patch_gerrit_default(self):
self._patch_common() self._patch_common()
self.calls += [ self.calls += [
@ -2389,6 +2409,8 @@ class TestGitCl(unittest.TestCase):
self.assertEqual(git_cl.main(['patch', '123456']), 0) self.assertEqual(git_cl.main(['patch', '123456']), 0)
self.assertIssueAndPatchset() self.assertIssueAndPatchset()
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_patch_gerrit_new_branch(self): def test_patch_gerrit_new_branch(self):
self._patch_common() self._patch_common()
self.calls += [ self.calls += [
@ -2401,6 +2423,8 @@ class TestGitCl(unittest.TestCase):
self.assertEqual(git_cl.main(['patch', '-b', 'feature', '123456']), 0) self.assertEqual(git_cl.main(['patch', '-b', 'feature', '123456']), 0)
self.assertIssueAndPatchset(branch='feature') self.assertIssueAndPatchset(branch='feature')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_patch_gerrit_force(self): def test_patch_gerrit_force(self):
self._patch_common('host') self._patch_common('host')
self.calls += [ self.calls += [
@ -2413,6 +2437,8 @@ class TestGitCl(unittest.TestCase):
self.assertEqual(git_cl.main(['patch', '123456', '--force']), 0) self.assertEqual(git_cl.main(['patch', '123456', '--force']), 0)
self.assertIssueAndPatchset(git_short_host='host') self.assertIssueAndPatchset(git_short_host='host')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_patch_gerrit_guess_by_url(self): def test_patch_gerrit_guess_by_url(self):
self._patch_common('else') self._patch_common('else')
self.calls += [ self.calls += [
@ -2428,6 +2454,8 @@ class TestGitCl(unittest.TestCase):
0) 0)
self.assertIssueAndPatchset(patchset='1', git_short_host='else') self.assertIssueAndPatchset(patchset='1', git_short_host='else')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_patch_gerrit_guess_by_url_with_repo(self): def test_patch_gerrit_guess_by_url_with_repo(self):
self._patch_common('else') self._patch_common('else')
self.calls += [ self.calls += [
@ -2444,6 +2472,8 @@ class TestGitCl(unittest.TestCase):
]), 0) ]), 0)
self.assertIssueAndPatchset(patchset='1', git_short_host='else') self.assertIssueAndPatchset(patchset='1', git_short_host='else')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
@mock.patch('sys.stderr', io.StringIO()) @mock.patch('sys.stderr', io.StringIO())
def test_patch_gerrit_conflict(self): def test_patch_gerrit_conflict(self):
self._patch_common() self._patch_common()
@ -2459,6 +2489,8 @@ class TestGitCl(unittest.TestCase):
self.assertEqual('Command "git cherry-pick FETCH_HEAD" failed.\n\n', self.assertEqual('Command "git cherry-pick FETCH_HEAD" failed.\n\n',
sys.stderr.getvalue()) sys.stderr.getvalue())
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
@mock.patch('gerrit_util.GetChangeDetail', @mock.patch('gerrit_util.GetChangeDetail',
side_effect=gerrit_util.GerritError(404, '')) side_effect=gerrit_util.GerritError(404, ''))
@mock.patch('sys.stderr', io.StringIO()) @mock.patch('sys.stderr', io.StringIO())
@ -2475,6 +2507,8 @@ class TestGitCl(unittest.TestCase):
scm.GIT.SetConfig('', 'branch.ger-branch.gerritissue', '123456') scm.GIT.SetConfig('', 'branch.ger-branch.gerritissue', '123456')
scm.GIT.SetConfig('', 'branch.gbranch654.gerritissue', '654321') scm.GIT.SetConfig('', 'branch.gbranch654.gerritissue', '654321')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_checkout_gerrit(self): def test_checkout_gerrit(self):
"""Tests git cl checkout <issue>.""" """Tests git cl checkout <issue>."""
self._checkout_config() self._checkout_config()
@ -2632,18 +2666,26 @@ class TestGitCl(unittest.TestCase):
}, notify, None), ''), }, notify, None), ''),
] ]
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_cmd_set_commit_gerrit_clear(self): def test_cmd_set_commit_gerrit_clear(self):
self._cmd_set_commit_gerrit_common(0) self._cmd_set_commit_gerrit_common(0)
self.assertEqual(0, git_cl.main(['set-commit', '-c'])) self.assertEqual(0, git_cl.main(['set-commit', '-c']))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_cmd_set_commit_gerrit_dry(self): def test_cmd_set_commit_gerrit_dry(self):
self._cmd_set_commit_gerrit_common(1, notify=False) self._cmd_set_commit_gerrit_common(1, notify=False)
self.assertEqual(0, git_cl.main(['set-commit', '-d'])) self.assertEqual(0, git_cl.main(['set-commit', '-d']))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_cmd_set_commit_gerrit(self): def test_cmd_set_commit_gerrit(self):
self._cmd_set_commit_gerrit_common(2) self._cmd_set_commit_gerrit_common(2)
self.assertEqual(0, git_cl.main(['set-commit'])) self.assertEqual(0, git_cl.main(['set-commit']))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_description_display(self): def test_description_display(self):
mock.patch('git_cl.Changelist', ChangelistMock).start() mock.patch('git_cl.Changelist', ChangelistMock).start()
ChangelistMock.desc = 'foo\n' ChangelistMock.desc = 'foo\n'
@ -2651,6 +2693,8 @@ class TestGitCl(unittest.TestCase):
self.assertEqual(0, git_cl.main(['description', '-d'])) self.assertEqual(0, git_cl.main(['description', '-d']))
self.assertEqual('foo\n', sys.stdout.getvalue()) self.assertEqual('foo\n', sys.stdout.getvalue())
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
@mock.patch('sys.stderr', io.StringIO()) @mock.patch('sys.stderr', io.StringIO())
def test_StatusFieldOverrideIssueMissingArgs(self): def test_StatusFieldOverrideIssueMissingArgs(self):
try: try:
@ -2659,6 +2703,8 @@ class TestGitCl(unittest.TestCase):
self.assertIn('--field must be given when --issue is set.', self.assertIn('--field must be given when --issue is set.',
sys.stderr.getvalue()) sys.stderr.getvalue())
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_StatusFieldOverrideIssue(self): def test_StatusFieldOverrideIssue(self):
def assertIssue(cl_self, *_args): def assertIssue(cl_self, *_args):
self.assertEqual(cl_self.issue, 1) self.assertEqual(cl_self.issue, 1)
@ -2669,6 +2715,8 @@ class TestGitCl(unittest.TestCase):
git_cl.main(['status', '--issue', '1', '--field', 'desc']), 0) git_cl.main(['status', '--issue', '1', '--field', 'desc']), 0)
self.assertEqual(sys.stdout.getvalue(), 'foobar\n') self.assertEqual(sys.stdout.getvalue(), 'foobar\n')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_SetCloseOverrideIssue(self): def test_SetCloseOverrideIssue(self):
def assertIssue(cl_self, *_args): def assertIssue(cl_self, *_args):
self.assertEqual(cl_self.issue, 1) self.assertEqual(cl_self.issue, 1)
@ -2678,6 +2726,8 @@ class TestGitCl(unittest.TestCase):
mock.patch('git_cl.Changelist.CloseIssue', lambda *_: None).start() mock.patch('git_cl.Changelist.CloseIssue', lambda *_: None).start()
self.assertEqual(git_cl.main(['set-close', '--issue', '1']), 0) self.assertEqual(git_cl.main(['set-close', '--issue', '1']), 0)
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_description(self): def test_description(self):
scm.GIT.SetConfig('', 'remote.origin.url', scm.GIT.SetConfig('', 'remote.origin.url',
'https://chromium.googlesource.com/my/repo') 'https://chromium.googlesource.com/my/repo')
@ -2700,6 +2750,8 @@ class TestGitCl(unittest.TestCase):
])) ]))
self.assertEqual('foobar\n', sys.stdout.getvalue()) self.assertEqual('foobar\n', sys.stdout.getvalue())
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_description_set_raw(self): def test_description_set_raw(self):
mock.patch('git_cl.Changelist', ChangelistMock).start() mock.patch('git_cl.Changelist', ChangelistMock).start()
mock.patch('git_cl.sys.stdin', io.StringIO('hihi')).start() mock.patch('git_cl.sys.stdin', io.StringIO('hihi')).start()
@ -2707,6 +2759,8 @@ class TestGitCl(unittest.TestCase):
self.assertEqual(0, git_cl.main(['description', '-n', 'hihi'])) self.assertEqual(0, git_cl.main(['description', '-n', 'hihi']))
self.assertEqual('hihi', ChangelistMock.desc) self.assertEqual('hihi', ChangelistMock.desc)
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_description_appends_bug_line(self): def test_description_appends_bug_line(self):
current_desc = 'Some.\n\nChange-Id: xxx' current_desc = 'Some.\n\nChange-Id: xxx'
@ -2733,6 +2787,8 @@ class TestGitCl(unittest.TestCase):
scm.GIT.SetConfig('', 'branch.main.gerritissue', '123') scm.GIT.SetConfig('', 'branch.main.gerritissue', '123')
self.assertEqual(0, git_cl.main(['description'])) self.assertEqual(0, git_cl.main(['description']))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_description_does_not_append_bug_line_if_fixed_is_present(self): def test_description_does_not_append_bug_line_if_fixed_is_present(self):
current_desc = 'Some.\n\nFixed: 123\nChange-Id: xxx' current_desc = 'Some.\n\nFixed: 123\nChange-Id: xxx'
@ -2753,6 +2809,8 @@ class TestGitCl(unittest.TestCase):
scm.GIT.SetConfig('', 'branch.main.gerritissue', '123') scm.GIT.SetConfig('', 'branch.main.gerritissue', '123')
self.assertEqual(0, git_cl.main(['description'])) self.assertEqual(0, git_cl.main(['description']))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_description_set_stdin(self): def test_description_set_stdin(self):
mock.patch('git_cl.Changelist', ChangelistMock).start() mock.patch('git_cl.Changelist', ChangelistMock).start()
mock.patch('git_cl.sys.stdin', mock.patch('git_cl.sys.stdin',
@ -2761,6 +2819,8 @@ class TestGitCl(unittest.TestCase):
self.assertEqual(0, git_cl.main(['description', '-n', '-'])) self.assertEqual(0, git_cl.main(['description', '-n', '-']))
self.assertEqual('hi\n\t there\n\nman', ChangelistMock.desc) self.assertEqual('hi\n\t there\n\nman', ChangelistMock.desc)
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_archive(self): def test_archive(self):
self.calls = [ self.calls = [
((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'], ), ((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'], ),
@ -2781,6 +2841,8 @@ class TestGitCl(unittest.TestCase):
self.assertEqual(0, git_cl.main(['archive', '-f'])) self.assertEqual(0, git_cl.main(['archive', '-f']))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_archive_tag_collision(self): def test_archive_tag_collision(self):
self.calls = [ self.calls = [
((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'], ), ((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'], ),
@ -2801,6 +2863,8 @@ class TestGitCl(unittest.TestCase):
self.assertEqual(0, git_cl.main(['archive', '-f'])) self.assertEqual(0, git_cl.main(['archive', '-f']))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_archive_current_branch_fails(self): def test_archive_current_branch_fails(self):
self.calls = [ self.calls = [
((['git', 'for-each-ref', '--format=%(refname)', ((['git', 'for-each-ref', '--format=%(refname)',
@ -2817,6 +2881,8 @@ class TestGitCl(unittest.TestCase):
self.assertEqual(1, git_cl.main(['archive', '-f'])) self.assertEqual(1, git_cl.main(['archive', '-f']))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_archive_dry_run(self): def test_archive_dry_run(self):
self.calls = [ self.calls = [
((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'], ), ((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'], ),
@ -2835,6 +2901,8 @@ class TestGitCl(unittest.TestCase):
self.assertEqual(0, git_cl.main(['archive', '-f', '--dry-run'])) self.assertEqual(0, git_cl.main(['archive', '-f', '--dry-run']))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_archive_no_tags(self): def test_archive_no_tags(self):
self.calls = [ self.calls = [
((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'], ), ((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'], ),
@ -2853,6 +2921,8 @@ class TestGitCl(unittest.TestCase):
self.assertEqual(0, git_cl.main(['archive', '-f', '--notags'])) self.assertEqual(0, git_cl.main(['archive', '-f', '--notags']))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_archive_tag_cleanup_on_branch_deletion_error(self): def test_archive_tag_cleanup_on_branch_deletion_error(self):
self.calls = [ self.calls = [
((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'], ), ((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'], ),
@ -2876,6 +2946,8 @@ class TestGitCl(unittest.TestCase):
self.assertEqual(0, git_cl.main(['archive', '-f'])) self.assertEqual(0, git_cl.main(['archive', '-f']))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_archive_with_format(self): def test_archive_with_format(self):
self.calls = [ self.calls = [
((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'], ), ((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'], ),
@ -2896,6 +2968,8 @@ class TestGitCl(unittest.TestCase):
0, git_cl.main(['archive', '-f', '-p', 0, git_cl.main(['archive', '-f', '-p',
'archived/{issue}-{branch}'])) 'archived/{issue}-{branch}']))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_cmd_issue_erase_existing(self): def test_cmd_issue_erase_existing(self):
scm.GIT.SetConfig('', 'branch.main.gerritissue', '123') scm.GIT.SetConfig('', 'branch.main.gerritissue', '123')
scm.GIT.SetConfig('', 'branch.main.gerritserver', scm.GIT.SetConfig('', 'branch.main.gerritserver',
@ -2907,6 +2981,8 @@ class TestGitCl(unittest.TestCase):
self.assertIsNone(scm.GIT.GetConfig('root', 'branch.main.gerritissue')) self.assertIsNone(scm.GIT.GetConfig('root', 'branch.main.gerritissue'))
self.assertIsNone(scm.GIT.GetConfig('root', 'branch.main.gerritserver')) self.assertIsNone(scm.GIT.GetConfig('root', 'branch.main.gerritserver'))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_cmd_issue_erase_existing_with_change_id(self): def test_cmd_issue_erase_existing_with_change_id(self):
scm.GIT.SetConfig('', 'branch.main.gerritissue', '123') scm.GIT.SetConfig('', 'branch.main.gerritissue', '123')
scm.GIT.SetConfig('', 'branch.main.gerritserver', scm.GIT.SetConfig('', 'branch.main.gerritserver',
@ -2924,6 +3000,8 @@ class TestGitCl(unittest.TestCase):
self.assertIsNone(scm.GIT.GetConfig('root', 'branch.main.gerritissue')) self.assertIsNone(scm.GIT.GetConfig('root', 'branch.main.gerritissue'))
self.assertIsNone(scm.GIT.GetConfig('root', 'branch.main.gerritserver')) self.assertIsNone(scm.GIT.GetConfig('root', 'branch.main.gerritserver'))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_cmd_issue_json(self): def test_cmd_issue_json(self):
scm.GIT.SetConfig('', 'branch.main.gerritissue', '123') scm.GIT.SetConfig('', 'branch.main.gerritissue', '123')
scm.GIT.SetConfig('', 'branch.main.gerritserver', scm.GIT.SetConfig('', 'branch.main.gerritserver',
@ -3161,6 +3239,8 @@ class TestGitCl(unittest.TestCase):
self.assertIn('However, your configured .gitcookies file is missing.', self.assertIn('However, your configured .gitcookies file is missing.',
sys.stdout.getvalue()) sys.stdout.getvalue())
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_git_cl_comment_add_gerrit(self): def test_git_cl_comment_add_gerrit(self):
git_new_branch.create_new_branch(None) # hits mock from scm_mock.GIT. git_new_branch.create_new_branch(None) # hits mock from scm_mock.GIT.
scm.GIT.SetConfig('', 'remote.origin.url', scm.GIT.SetConfig('', 'remote.origin.url',
@ -3171,6 +3251,8 @@ class TestGitCl(unittest.TestCase):
] ]
self.assertEqual(0, git_cl.main(['comment', '-i', '10', '-a', 'msg'])) self.assertEqual(0, git_cl.main(['comment', '-i', '10', '-a', 'msg']))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
@mock.patch('git_cl.Changelist.GetBranch', return_value='foo') @mock.patch('git_cl.Changelist.GetBranch', return_value='foo')
def test_git_cl_comments_fetch_gerrit(self, *_mocks): def test_git_cl_comments_fetch_gerrit(self, *_mocks):
scm.GIT.SetConfig('', 'remote.origin.url', scm.GIT.SetConfig('', 'remote.origin.url',
@ -3324,6 +3406,8 @@ class TestGitCl(unittest.TestCase):
self.assertEqual( self.assertEqual(
0, git_cl.main(['comments', '-i', '1', '-j', 'output.json'])) 0, git_cl.main(['comments', '-i', '1', '-j', 'output.json']))
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_git_cl_comments_robot_comments(self): def test_git_cl_comments_robot_comments(self):
# git cl comments also fetches robot comments (which are considered a # git cl comments also fetches robot comments (which are considered a
# type of autogenerated comment), and unlike other types of comments, # type of autogenerated comment), and unlike other types of comments,
@ -3531,6 +3615,8 @@ class TestGitCl(unittest.TestCase):
cl = git_cl.Changelist(issue=123456) cl = git_cl.Changelist(issue=123456)
self.assertEqual(cl._GerritChangeIdentifier(), '123456') self.assertEqual(cl._GerritChangeIdentifier(), '123456')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_gerrit_new_default(self): def test_gerrit_new_default(self):
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
[], [],
@ -3540,6 +3626,8 @@ class TestGitCl(unittest.TestCase):
change_id='I123456789', change_id='I123456789',
default_branch='main') default_branch='main')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def test_gerrit_nosquash_with_issue(self): def test_gerrit_nosquash_with_issue(self):
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
[], [],
@ -4267,6 +4355,8 @@ class CMDTestCaseBase(unittest.TestCase):
self.addCleanup(mock.patch.stopall) self.addCleanup(mock.patch.stopall)
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
class CMDPresubmitTestCase(CMDTestCaseBase): class CMDPresubmitTestCase(CMDTestCaseBase):
_RUN_HOOK_RETURN = { _RUN_HOOK_RETURN = {
'errors': [], 'errors': [],
@ -4382,6 +4472,8 @@ class CMDTryResultsTestCase(CMDTestCaseBase):
',builds.*.createTime,builds.*.tags'), ',builds.*.createTime,builds.*.tags'),
} }
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def testNoJobs(self): def testNoJobs(self):
git_cl._call_buildbucket.return_value = {} git_cl._call_buildbucket.return_value = {}
@ -4391,6 +4483,8 @@ class CMDTryResultsTestCase(CMDTestCaseBase):
mock.ANY, 'cr-buildbucket.appspot.com', 'SearchBuilds', mock.ANY, 'cr-buildbucket.appspot.com', 'SearchBuilds',
self._DEFAULT_REQUEST) self._DEFAULT_REQUEST)
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def testTrivialCommits(self): def testTrivialCommits(self):
self.assertEqual(0, git_cl.main(['try-results'])) self.assertEqual(0, git_cl.main(['try-results']))
git_cl._call_buildbucket.assert_called_with( git_cl._call_buildbucket.assert_called_with(
@ -4422,6 +4516,8 @@ class CMDTryResultsTestCase(CMDTestCaseBase):
], ],
sys.stdout.getvalue().splitlines()) sys.stdout.getvalue().splitlines())
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def testPrintToStdout(self): def testPrintToStdout(self):
self.assertEqual(0, git_cl.main(['try-results'])) self.assertEqual(0, git_cl.main(['try-results']))
self.assertEqual([ self.assertEqual([
@ -4446,6 +4542,8 @@ class CMDTryResultsTestCase(CMDTestCaseBase):
mock.ANY, 'cr-buildbucket.appspot.com', 'SearchBuilds', mock.ANY, 'cr-buildbucket.appspot.com', 'SearchBuilds',
self._DEFAULT_REQUEST) self._DEFAULT_REQUEST)
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
def testPrintToStdoutWithMasters(self): def testPrintToStdoutWithMasters(self):
self.assertEqual(0, git_cl.main(['try-results', '--print-master'])) self.assertEqual(0, git_cl.main(['try-results', '--print-master']))
self.assertEqual([ self.assertEqual([
@ -4470,6 +4568,8 @@ class CMDTryResultsTestCase(CMDTestCaseBase):
mock.ANY, 'cr-buildbucket.appspot.com', 'SearchBuilds', mock.ANY, 'cr-buildbucket.appspot.com', 'SearchBuilds',
self._DEFAULT_REQUEST) self._DEFAULT_REQUEST)
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
@mock.patch('git_cl.write_json') @mock.patch('git_cl.write_json')
def testWriteToJson(self, mockJsonDump): def testWriteToJson(self, mockJsonDump):
self.assertEqual(0, git_cl.main(['try-results', '--json', 'file.json'])) self.assertEqual(0, git_cl.main(['try-results', '--json', 'file.json']))
@ -4529,6 +4629,8 @@ class CMDTryResultsTestCase(CMDTestCaseBase):
class CMDTryTestCase(CMDTestCaseBase): class CMDTryTestCase(CMDTestCaseBase):
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
@mock.patch('git_cl.Changelist.SetCQState') @mock.patch('git_cl.Changelist.SetCQState')
def testSetCQDryRunByDefault(self, mockSetCQState): def testSetCQDryRunByDefault(self, mockSetCQState):
mockSetCQState.return_value = 0 mockSetCQState.return_value = 0
@ -4538,6 +4640,8 @@ class CMDTryTestCase(CMDTestCaseBase):
sys.stdout.getvalue(), 'Scheduling CQ dry run on: ' sys.stdout.getvalue(), 'Scheduling CQ dry run on: '
'https://chromium-review.googlesource.com/123456\n') 'https://chromium-review.googlesource.com/123456\n')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
@mock.patch('git_cl._call_buildbucket') @mock.patch('git_cl._call_buildbucket')
def testScheduleOnBuildbucket(self, mockCallBuildbucket): def testScheduleOnBuildbucket(self, mockCallBuildbucket):
mockCallBuildbucket.return_value = {} mockCallBuildbucket.return_value = {}
@ -4591,6 +4695,8 @@ class CMDTryTestCase(CMDTestCaseBase):
'cr-buildbucket.appspot.com', 'cr-buildbucket.appspot.com',
'Batch', expected_request) 'Batch', expected_request)
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
@mock.patch('git_cl._call_buildbucket') @mock.patch('git_cl._call_buildbucket')
def testScheduleOnBuildbucketWithRevision(self, mockCallBuildbucket): def testScheduleOnBuildbucketWithRevision(self, mockCallBuildbucket):
mockCallBuildbucket.return_value = {} mockCallBuildbucket.return_value = {}
@ -4694,6 +4800,8 @@ class CMDTryTestCase(CMDTestCaseBase):
'cr-buildbucket.appspot.com', 'cr-buildbucket.appspot.com',
'Batch', expected_request) 'Batch', expected_request)
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
@mock.patch('sys.stderr', io.StringIO()) @mock.patch('sys.stderr', io.StringIO())
def testScheduleOnBuildbucket_WrongBucket(self): def testScheduleOnBuildbucket_WrongBucket(self):
with self.assertRaises(SystemExit): with self.assertRaises(SystemExit):
@ -4703,6 +4811,8 @@ class CMDTryTestCase(CMDTestCaseBase):
]) ])
self.assertIn('Invalid bucket: not-a-bucket.', sys.stderr.getvalue()) self.assertIn('Invalid bucket: not-a-bucket.', sys.stderr.getvalue())
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
@mock.patch('git_cl._call_buildbucket') @mock.patch('git_cl._call_buildbucket')
@mock.patch('git_cl._fetch_tryjobs') @mock.patch('git_cl._fetch_tryjobs')
def testScheduleOnBuildbucketRetryFailed(self, mockFetchTryJobs, def testScheduleOnBuildbucketRetryFailed(self, mockFetchTryJobs,
@ -5102,6 +5212,8 @@ class CMDFormatTestCase(unittest.TestCase):
self._check_yapf_filtering(files, expected) self._check_yapf_filtering(files, expected)
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
class CMDStatusTestCase(CMDTestCaseBase): class CMDStatusTestCase(CMDTestCaseBase):
# Return branch names a,..,f with comitterdates in increasing order, i.e. # Return branch names a,..,f with comitterdates in increasing order, i.e.
# 'f' is the most-recently changed branch. # 'f' is the most-recently changed branch.
@ -5201,6 +5313,8 @@ class CMDStatusTestCase(CMDTestCaseBase):
'x\n') 'x\n')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
class CMDOwnersTestCase(CMDTestCaseBase): class CMDOwnersTestCase(CMDTestCaseBase):
def setUp(self): def setUp(self):
super(CMDOwnersTestCase, self).setUp() super(CMDOwnersTestCase, self).setUp()
@ -5284,6 +5398,8 @@ class CMDLintTestCase(CMDTestCaseBase):
self.assertIn('pdf.cc:3: (cpplint) Do not indent within a namespace', self.assertIn('pdf.cc:3: (cpplint) Do not indent within a namespace',
git_cl.sys.stderr.getvalue()) git_cl.sys.stderr.getvalue())
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
@mock.patch('git_cl.Changelist.GetAffectedFiles', @mock.patch('git_cl.Changelist.GetAffectedFiles',
return_value=['chg-1.h', 'chg-2.cc']) return_value=['chg-1.h', 'chg-2.cc'])
@mock.patch('git_cl.Changelist.GetCommonAncestorWithUpstream', @mock.patch('git_cl.Changelist.GetCommonAncestorWithUpstream',

@ -14,9 +14,12 @@ from unittest import mock
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import gclient_utils
import git_find_releases import git_find_releases
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
class TestGitFindReleases(unittest.TestCase): class TestGitFindReleases(unittest.TestCase):
@mock.patch('sys.stdout', StringIO()) @mock.patch('sys.stdout', StringIO())
@mock.patch('git_common.run', return_value='') @mock.patch('git_common.run', return_value='')

@ -249,6 +249,8 @@ My commit message is my best friend. It is my life.
'message\n\nKey: value\nSome: footer\nKey: value', 'Key'), 'message\n\nKey: value\nSome: footer\nKey: value', 'Key'),
'message\n\nSome: footer') 'message\n\nSome: footer')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
@mock.patch('sys.stdout', StringIO()) @mock.patch('sys.stdout', StringIO())
@mock.patch( @mock.patch(
'sys.stdin', 'sys.stdin',
@ -257,6 +259,8 @@ My commit message is my best friend. It is my life.
self.assertEqual(git_footers.main([]), 0) self.assertEqual(git_footers.main([]), 0)
self.assertEqual(sys.stdout.getvalue(), 'Still: footer\nFoo: baz\n') self.assertEqual(sys.stdout.getvalue(), 'Still: footer\nFoo: baz\n')
@unittest.skipIf(gclient_utils.IsEnvCog(),
'not supported in non-git environment')
@mock.patch('sys.stdin', @mock.patch('sys.stdin',
StringIO('line\r\nany spaces\r\n\r\n\r\nFoo: 1\nBar: 2\nFoo: 3') StringIO('line\r\nany spaces\r\n\r\n\r\nFoo: 1\nBar: 2\nFoo: 3')
) )

Loading…
Cancel
Save