| Index: tests/git_cl_test.py
|
| diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..4aa59a24bb10bb458875f9b1405dec046bf319d1
|
| --- /dev/null
|
| +++ b/tests/git_cl_test.py
|
| @@ -0,0 +1,154 @@
|
| +#!/usr/bin/env python
|
| +# Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +"""Unit tests for git_cl.py."""
|
| +
|
| +import os
|
| +import sys
|
| +import unittest
|
| +
|
| +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| +
|
| +from testing_support.auto_stub import TestCase
|
| +
|
| +import git_cl
|
| +import subprocess2
|
| +
|
| +
|
| +class TestGitCl(TestCase):
|
| + def setUp(self):
|
| + super(TestGitCl, self).setUp()
|
| + self.calls = []
|
| + self._calls_done = 0
|
| + def mock_call(args, **kwargs):
|
| + expected_args, result = self.calls.pop(0)
|
| + self.assertEquals(
|
| + expected_args,
|
| + args,
|
| + '@%d Expected: %r Actual: %r' % (
|
| + self._calls_done, expected_args, args))
|
| + self._calls_done += 1
|
| + return result
|
| + self.mock(subprocess2, 'call', mock_call)
|
| + self.mock(subprocess2, 'check_call', mock_call)
|
| + self.mock(subprocess2, 'check_output', mock_call)
|
| + self.mock(subprocess2, 'communicate', mock_call)
|
| + self.mock(subprocess2, 'Popen', mock_call)
|
| +
|
| + self.mock(git_cl, 'FindCodereviewSettingsFile', lambda: '')
|
| +
|
| + class Presubmit(object):
|
| + def __init__(self, *args, **kwargs):
|
| + pass
|
| + @staticmethod
|
| + def should_continue():
|
| + return True
|
| + self.mock(git_cl.presubmit_support, 'DoPresubmitChecks', Presubmit)
|
| +
|
| + class Rietveld(object):
|
| + def __init__(self, *args, **kwargs):
|
| + pass
|
| + self.mock(git_cl.rietveld, 'Rietveld', Rietveld)
|
| +
|
| + self.mock(git_cl.upload, 'RealMain', self.fail)
|
| +
|
| + class Watchlists(object):
|
| + def __init__(self, _):
|
| + pass
|
| + @staticmethod
|
| + def GetWatchersForPaths(_):
|
| + return ['joe@example.com']
|
| + self.mock(git_cl.watchlists, 'Watchlists', Watchlists)
|
| + # It's important to reset settings to not have inter-tests interference.
|
| + git_cl.settings = None
|
| +
|
| + def tearDown(self):
|
| + if not self.has_failed():
|
| + self.assertEquals([], self.calls)
|
| + super(TestGitCl, self).tearDown()
|
| +
|
| + @staticmethod
|
| + def _upload_calls():
|
| + return [
|
| + (['git', 'update-index', '--refresh', '-q'], ''),
|
| + (['git', 'diff-index', 'HEAD'], ''),
|
| + (['git', 'config', 'rietveld.server'], 'codereview.example.com'),
|
| + (['git', 'symbolic-ref', 'HEAD'], 'master'),
|
| + (['git', 'config', 'branch.master.merge'], 'master'),
|
| + (['git', 'config', 'branch.master.remote'], 'origin'),
|
| + (['git', 'rev-parse', '--show-cdup'], ''),
|
| + (['git', 'rev-parse', 'HEAD'], '12345'),
|
| + (['git', 'diff', '--name-status', '-r', 'master...', '.'],
|
| + 'M\t.gitignore\n'),
|
| + (['git', 'rev-parse', '--git-dir'], '.git'),
|
| + (['git', 'config', 'branch.master.rietveldissue'], ''),
|
| + (['git', 'config', 'branch.master.rietveldpatchset'], ''),
|
| + (['git', 'log', '--pretty=format:%s%n%n%b', 'master...'], 'foo'),
|
| + (['git', 'config', 'user.email'], 'me@example.com'),
|
| + (['git', 'diff', '--no-ext-diff', '--stat', '-M', 'master...'], '+dat'),
|
| + (['git', 'log', '--pretty=format:%s\n\n%b', 'master..'], 'desc\n'),
|
| + (['git', 'config', 'rietveld.cc'], ''),
|
| + (['git', 'config', '--get-regexp', '^svn-remote\\.'], (('', None), 0)),
|
| + (['git', 'rev-parse', '--show-cdup'], ''),
|
| + (['git', 'svn', 'info'], ''),
|
| + (['git', 'config', 'branch.master.rietveldissue', '1'], ''),
|
| + (['git', 'config', 'branch.master.rietveldserver',
|
| + 'http://codereview.example.com'], ''),
|
| + (['git', 'config', 'branch.master.rietveldpatchset', '2'], ''),
|
| + ]
|
| +
|
| + def test_reviewers(self):
|
| + 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'
|
| + 'desc\n\nR=foo@example.com\nBUG=\nTEST=', desc)
|
| + return desc
|
| + self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor)
|
| + def check_upload(args):
|
| + self.assertEquals(
|
| + ['upload', '--assume_yes', '--server',
|
| + 'http://codereview.example.com',
|
| + '--message', 'desc',
|
| + '--description', 'desc\n\nR=foo@example.com\nBUG=\nTEST=\n',
|
| + # Reviewer is used from the command line.
|
| + '--reviewers', 'foo@example.com',
|
| + '--cc', 'joe@example.com',
|
| + 'master...'],
|
| + args)
|
| + return 1, 2
|
| + self.mock(git_cl.upload, 'RealMain', check_upload)
|
| + git_cl.main(['upload', '-r' 'foo@example.com'])
|
| +
|
| + def test_reviewer_tbr_overriden(self):
|
| + 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'
|
| + 'desc\n\nR=foo@example.com\nBUG=\nTEST=', desc)
|
| + return '\n\nFoo Bar\nTBR=reviewer@example.com\n\n'
|
| + self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor)
|
| + def check_upload(args):
|
| + self.assertEquals(
|
| + ['upload', '--assume_yes', '--server',
|
| + 'http://codereview.example.com',
|
| + '--message', 'Foo Bar',
|
| + '--description', 'Foo Bar\nTBR=reviewer@example.com\n',
|
| + # Reviewer is updated from the CL description.
|
| + '--reviewers', 'reviewer@example.com',
|
| + '--cc', 'joe@example.com',
|
| + 'master...'],
|
| + args)
|
| + return 1, 2
|
| + self.mock(git_cl.upload, 'RealMain', check_upload)
|
| + git_cl.main(['upload', '-r' 'foo@example.com'])
|
| +
|
| +
|
| +if __name__ == '__main__':
|
| + unittest.main()
|
|
|