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

Side by Side Diff: tests/trychange_git_unittest.py

Issue 1003733006: Splitting trychange for git_try and removing no longer needed support for: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 5 years, 9 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_try.py ('k') | trychange_git.py » ('j') | trychange_git.py » ('J')
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 trychange.py.""" 6 """Unit tests for trychange.py."""
7 7
8 import os 8 import os
9 import sys 9 import sys
10 import unittest 10 import unittest
11 11
12 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 12 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
13 13
14 from testing_support.super_mox import SuperMoxTestBase 14 from testing_support.super_mox import SuperMoxTestBase
15 15
16 import subprocess2 16 import subprocess2
17 import trychange 17 import trychange_git as trychange
18 18
19 19
20 class TryChangeTestsBase(SuperMoxTestBase): 20 class TryChangeTestsBase(SuperMoxTestBase):
21 """Setups and tear downs the mocks but doesn't test anything as-is.""" 21 """Setups and tear downs the mocks but doesn't test anything as-is."""
22 def setUp(self): 22 def setUp(self):
23 SuperMoxTestBase.setUp(self) 23 SuperMoxTestBase.setUp(self)
24 self.mox.StubOutWithMock(subprocess2, 'communicate') 24 self.mox.StubOutWithMock(subprocess2, 'communicate')
25 self.mox.StubOutWithMock(trychange, 'RunGit') 25 self.mox.StubOutWithMock(trychange, 'RunGit')
26 self.mox.StubOutWithMock(trychange.scm.GIT, 'Capture') 26 self.mox.StubOutWithMock(trychange.scm.GIT, 'Capture')
27 self.mox.StubOutWithMock(trychange.scm.GIT, 'GenerateDiff') 27 self.mox.StubOutWithMock(trychange.scm.GIT, 'GenerateDiff')
(...skipping 12 matching lines...) Expand all
40 self.options.name = None 40 self.options.name = None
41 self.options.email = None 41 self.options.email = None
42 self.options.exclude = [] 42 self.options.exclude = []
43 43
44 44
45 class TryChangeUnittest(TryChangeTestsBase): 45 class TryChangeUnittest(TryChangeTestsBase):
46 """General trychange.py tests.""" 46 """General trychange.py tests."""
47 def testMembersChanged(self): 47 def testMembersChanged(self):
48 members = [ 48 members = [
49 'DieWithError', 'EPILOG', 'Escape', 'GIT', 'GIT_PATCH_DIR_BASENAME', 49 'DieWithError', 'EPILOG', 'Escape', 'GIT', 'GIT_PATCH_DIR_BASENAME',
50 'GetMungedDiff', 'GuessVCS', 'GIT_BRANCH_FILE', 50 'GetMungedDiff', 'DetectGit', 'GIT_BRANCH_FILE', 'git_cl',
51 'HELP_STRING', 'Error', 'InvalidScript', 'NoTryServerAccess', 51 'HELP_STRING', 'Error', 'NoTryServerAccess',
52 'OptionParser', 'PrintSuccess', 52 'OptionParser', 'PrintSuccess',
53 'RunCommand', 'RunGit', 'SCM', 'SVN', 'TryChange', 'USAGE', 'contextlib', 53 'RunCommand', 'RunGit', 'TryChange_Git', 'USAGE', 'contextlib',
54 'breakpad', 54 'datetime', 'errno', 'gclient_utils', 'gen_parser',
55 'datetime', 'errno', 'fix_encoding', 'gcl', 'gclient_utils',
56 'gerrit_util', 'gen_parser',
57 'getpass', 'itertools', 'json', 'logging', 'optparse', 'os', 'posixpath', 55 'getpass', 'itertools', 'json', 'logging', 'optparse', 'os', 'posixpath',
58 're', 'scm', 'shutil', 'subprocess2', 'sys', 'tempfile', 'urllib', 56 're', 'scm', 'shutil', 'subprocess2', 'sys', 'tempfile', 'urllib',
59 'urllib2', 'urlparse'] 57 'urllib2', 'urlparse']
60 # If this test fails, you should add the relevant test. 58 # If this test fails, you should add the relevant test.
61 self.compareMembers(trychange, members) 59 self.compareMembers(trychange, members)
62 60
63 61
64 class TryChangeSimpleTest(unittest.TestCase): 62 class TryChangeSimpleTest(unittest.TestCase):
65 # Doesn't require supermox to run. 63 # Doesn't require supermox to run.
66 def test_flags(self): 64 def test_flags(self):
(...skipping 29 matching lines...) Expand all
96 options, args = trychange.gen_parser(None).parse_args(cmd) 94 options, args = trychange.gen_parser(None).parse_args(cmd)
97 self.assertEquals([], args) 95 self.assertEquals([], args)
98 try: 96 try:
99 # pylint: disable=W0212 97 # pylint: disable=W0212
100 trychange._ParseBotList(options.bot, options.testfilter) 98 trychange._ParseBotList(options.bot, options.testfilter)
101 self.fail() 99 self.fail()
102 except ValueError: 100 except ValueError:
103 pass 101 pass
104 102
105 103
106 class SVNUnittest(TryChangeTestsBase):
107 """trychange.SVN tests."""
108 def testMembersChanged(self):
109 members = [
110 'AutomagicalSettings', 'CaptureStatus', 'GetCodeReviewSetting',
111 'ReadRootFile', 'GenerateDiff', 'GetFileNames', 'files', 'file_tuples',
112 ]
113 # If this test fails, you should add the relevant test.
114 self.compareMembers(trychange.SVN, members)
115
116 def testBasic(self):
117 # pylint: disable=E1103
118 trychange.os.path.abspath(self.fake_root).AndReturn(self.fake_root)
119 trychange.scm.SVN.GetCheckoutRoot(self.fake_root).AndReturn(self.fake_root)
120 trychange.scm.SVN.GenerateDiff(['foo.txt', 'bar.txt'],
121 self.fake_root,
122 full_move=True,
123 revision=None).AndReturn('A diff')
124 trychange.scm.SVN.GetEmail(self.fake_root).AndReturn('georges@example.com')
125 self.mox.ReplayAll()
126 svn = trychange.SVN(self.options, self.fake_root, self.options.files)
127 self.assertEqual(svn.GetFileNames(), self.expected_files)
128 self.assertEqual(svn.checkout_root, self.fake_root)
129 self.assertEqual(svn.GenerateDiff(), 'A diff')
130
131
132 class GITUnittest(TryChangeTestsBase): 104 class GITUnittest(TryChangeTestsBase):
133 """trychange.GIT tests.""" 105 """trychange.GIT tests."""
134 def testMembersChanged(self): 106 def testMembersChanged(self):
135 members = [ 107 members = [
136 'AutomagicalSettings', 'CaptureStatus', 'GetCodeReviewSetting', 108 'AutomagicalSettings', 'CaptureStatus', 'GetCodeReviewSetting',
137 'ReadRootFile', 'GenerateDiff', 'GetFileNames', 'files', 'file_tuples', 109 'ReadRootFile', 'GenerateDiff', 'files', 'file_tuples',
138 ] 110 ]
139 # If this test fails, you should add the relevant test. 111 # If this test fails, you should add the relevant test.
140 self.compareMembers(trychange.GIT, members) 112 self.compareMembers(trychange.GIT, members)
141 113
142 def testBasic(self): 114 def testBasic(self):
143 # pylint: disable=E1103 115 # pylint: disable=E1103
144 trychange.os.path.abspath(self.fake_root).AndReturn(self.fake_root) 116 trychange.os.path.abspath(self.fake_root).AndReturn(self.fake_root)
145 trychange.scm.GIT.GetCheckoutRoot(self.fake_root).AndReturn(self.fake_root) 117 trychange.scm.GIT.GetCheckoutRoot(self.fake_root).AndReturn(self.fake_root)
146 trychange.scm.GIT.GetUpstreamBranch(self.fake_root).AndReturn('somewhere') 118 trychange.scm.GIT.GetUpstreamBranch(self.fake_root).AndReturn('somewhere')
147 trychange.RunGit(['diff-index', 'HEAD']) 119 trychange.RunGit(['diff-index', 'HEAD'])
148 trychange.scm.GIT.GenerateDiff(self.fake_root, 120 trychange.scm.GIT.GenerateDiff(self.fake_root,
149 full_move=True, 121 full_move=True,
150 files=['foo.txt', 'bar.txt'], 122 files=['foo.txt', 'bar.txt'],
151 branch='somewhere').AndReturn('A diff') 123 branch='somewhere').AndReturn('A diff')
152 trychange.scm.GIT.GetPatchName(self.fake_root).AndReturn('bleh-1233') 124 trychange.scm.GIT.GetPatchName(self.fake_root).AndReturn('bleh-1233')
153 trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com') 125 trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com')
154 self.mox.ReplayAll() 126 self.mox.ReplayAll()
155 git = trychange.GIT(self.options, self.fake_root, self.options.files) 127 git = trychange.GIT(self.options, self.fake_root, self.options.files)
156 self.assertEqual(git.GetFileNames(), self.expected_files) 128 self.assertEqual(git.files, self.expected_files)
157 self.assertEqual(git.checkout_root, self.fake_root) 129 self.assertEqual(git.checkout_root, self.fake_root)
158 self.assertEqual(git.GenerateDiff(), 'A diff') 130 self.assertEqual(git.GenerateDiff(), 'A diff')
159 131
160 132
161 if __name__ == '__main__': 133 if __name__ == '__main__':
162 unittest.main() 134 unittest.main()
OLDNEW
« no previous file with comments | « git_try.py ('k') | trychange_git.py » ('j') | trychange_git.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698