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

Side by Side Diff: tests/gcl_unittest.py

Issue 4127013: Refactor ChangeInfo.Load() to make it easier to support mulitple format. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 10 years, 1 month 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
« gcl.py ('K') | « gcl.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/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 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 gcl.py.""" 6 """Unit tests for gcl.py."""
7 7
8 # Fixes include path. 8 # Fixes include path.
9 from super_mox import mox, SuperMoxTestBase 9 from super_mox import mox, SuperMoxTestBase
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 'GetCacheDir', 46 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 'GetCacheDir',
47 'GetCachedFile', 'GetChangelistInfoFile', 'GetChangesDir', 47 'GetCachedFile', 'GetChangelistInfoFile', 'GetChangesDir',
48 'GetCodeReviewSetting', 'GetEditor', 'GetFilesNotInCL', 'GetInfoDir', 48 'GetCodeReviewSetting', 'GetEditor', 'GetFilesNotInCL', 'GetInfoDir',
49 'GetIssueDescription', 'GetModifiedFiles', 'GetRepositoryRoot', 49 'GetIssueDescription', 'GetModifiedFiles', 'GetRepositoryRoot',
50 'ListFiles', 50 'ListFiles',
51 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG', 51 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG',
52 'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT', 52 'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT',
53 'RunShell', 'RunShellWithReturnCode', 'SVN', 53 'RunShell', 'RunShellWithReturnCode', 'SVN',
54 'SendToRietveld', 'TryChange', 'UnknownFiles', 'Warn', 54 'SendToRietveld', 'TryChange', 'UnknownFiles', 'Warn',
55 'attrs', 'breakpad', 'defer_attributes', 'gclient_utils', 'getpass', 55 'attrs', 'breakpad', 'defer_attributes', 'gclient_utils', 'getpass',
56 'main', 'need_change', 'need_change_and_args', 'no_args', 'os', 56 'json', 'main', 'need_change', 'need_change_and_args', 'no_args', 'os',
57 'random', 're', 'string', 'subprocess', 'sys', 'tempfile', 57 'random', 're', 'string', 'subprocess', 'sys', 'tempfile',
58 'time', 'upload', 'urllib2', 58 'time', 'upload', 'urllib2',
59 ] 59 ]
60 # If this test fails, you should add the relevant test. 60 # If this test fails, you should add the relevant test.
61 self.compareMembers(gcl, members) 61 self.compareMembers(gcl, members)
62 62
63 def testIsSVNMoved(self): 63 def testIsSVNMoved(self):
64 # TODO(maruel): TEST ME 64 # TODO(maruel): TEST ME
65 pass 65 pass
66 66
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 self.assertEquals(o.GetFileNames(), ['foo', 'bar']) 159 self.assertEquals(o.GetFileNames(), ['foo', 'bar'])
160 self.assertEquals(o.GetFiles(), files) 160 self.assertEquals(o.GetFiles(), files)
161 self.assertEquals(o.GetLocalRoot(), self.fake_root_dir) 161 self.assertEquals(o.GetLocalRoot(), self.fake_root_dir)
162 162
163 def testLoadWithIssue(self): 163 def testLoadWithIssue(self):
164 description = ["This is some description.", "force an extra separator."] 164 description = ["This is some description.", "force an extra separator."]
165 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') 165 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
166 gcl.os.path.exists('bleeeh').AndReturn(True) 166 gcl.os.path.exists('bleeeh').AndReturn(True)
167 gcl.gclient_utils.FileRead('bleeeh', 'r').AndReturn( 167 gcl.gclient_utils.FileRead('bleeeh', 'r').AndReturn(
168 gcl.ChangeInfo._SEPARATOR.join(["42, 53", "G b.cc"] + description)) 168 gcl.ChangeInfo._SEPARATOR.join(["42, 53", "G b.cc"] + description))
169 # Does an upgrade.
170 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
171 gcl.gclient_utils.FileWrite('bleeeh', mox.IgnoreArg())
169 self.mox.ReplayAll() 172 self.mox.ReplayAll()
170 173
171 change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False) 174 change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False)
172 self.assertEquals(change_info.name, 'bleh') 175 self.assertEquals(change_info.name, 'bleh')
173 self.assertEquals(change_info.issue, 42) 176 self.assertEquals(change_info.issue, 42)
174 self.assertEquals(change_info.patchset, 53) 177 self.assertEquals(change_info.patchset, 53)
175 self.assertEquals(change_info.description, 178 self.assertEquals(change_info.description,
176 gcl.ChangeInfo._SEPARATOR.join(description)) 179 gcl.ChangeInfo._SEPARATOR.join(description))
177 self.assertEquals(change_info.GetFiles(), [('G ', 'b.cc')]) 180 self.assertEquals(change_info.GetFiles(), [('G ', 'b.cc')])
178 181
179 def testLoadEmpty(self): 182 def testLoadEmpty(self):
180 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') 183 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
181 gcl.os.path.exists('bleeeh').AndReturn(True) 184 gcl.os.path.exists('bleeeh').AndReturn(True)
182 gcl.gclient_utils.FileRead('bleeeh', 'r').AndReturn( 185 gcl.gclient_utils.FileRead('bleeeh', 'r').AndReturn(
183 gcl.ChangeInfo._SEPARATOR.join(["", "", ""])) 186 gcl.ChangeInfo._SEPARATOR.join(["", "", ""]))
187 # Does an upgrade.
188 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
189 gcl.gclient_utils.FileWrite('bleeeh', mox.IgnoreArg())
184 self.mox.ReplayAll() 190 self.mox.ReplayAll()
185 191
186 change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False) 192 change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False)
187 self.assertEquals(change_info.name, 'bleh') 193 self.assertEquals(change_info.name, 'bleh')
188 self.assertEquals(change_info.issue, 0) 194 self.assertEquals(change_info.issue, 0)
189 self.assertEquals(change_info.patchset, 0) 195 self.assertEquals(change_info.patchset, 0)
190 self.assertEquals(change_info.description, "") 196 self.assertEquals(change_info.description, "")
191 self.assertEquals(change_info.GetFiles(), []) 197 self.assertEquals(change_info.GetFiles(), [])
192 198
193 def testSaveEmpty(self): 199 def testSaveEmpty(self):
194 gcl.GetChangelistInfoFile('').AndReturn('foo') 200 gcl.GetChangelistInfoFile('').AndReturn('foo')
201 values = {
202 'description': '', 'patchset': 2, 'issue': 1,
203 'files': [], 'needs_upload': False}
195 gcl.gclient_utils.FileWrite( 204 gcl.gclient_utils.FileWrite(
196 'foo', 205 'foo', gcl.json.dumps(values, sort_keys=True, indent=2))
197 gcl.ChangeInfo._SEPARATOR.join(['0, 0, clean', '', '']))
198 self.mox.ReplayAll() 206 self.mox.ReplayAll()
199 207
200 change_info = gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir) 208 change_info = gcl.ChangeInfo('', 1, 2, '', None, self.fake_root_dir)
201 change_info.Save() 209 change_info.Save()
202 210
203 def testSaveDirty(self): 211 def testSaveDirty(self):
204 gcl.GetChangelistInfoFile('').AndReturn('foo') 212 gcl.GetChangelistInfoFile('n').AndReturn('foo')
213 values = {
214 'description': 'des', 'patchset': 0, 'issue': 0,
215 'files': [], 'needs_upload': True}
205 gcl.gclient_utils.FileWrite( 216 gcl.gclient_utils.FileWrite(
206 'foo', 217 'foo', gcl.json.dumps(values, sort_keys=True, indent=2))
207 gcl.ChangeInfo._SEPARATOR.join(['0, 0, dirty', '', '']))
208 self.mox.ReplayAll() 218 self.mox.ReplayAll()
209 219
210 change_info = gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir, 220 change_info = gcl.ChangeInfo('n', 0, 0, 'des', None, self.fake_root_dir,
211 needs_upload=True) 221 needs_upload=True)
212 change_info.Save() 222 change_info.Save()
213 223
214 224
215 class CMDuploadUnittest(GclTestsBase): 225 class CMDuploadUnittest(GclTestsBase):
216 def setUp(self): 226 def setUp(self):
217 GclTestsBase.setUp(self) 227 GclTestsBase.setUp(self)
218 self.mox.StubOutWithMock(gcl, 'CheckHomeForFile') 228 self.mox.StubOutWithMock(gcl, 'CheckHomeForFile')
219 self.mox.StubOutWithMock(gcl, 'DoPresubmitChecks') 229 self.mox.StubOutWithMock(gcl, 'DoPresubmitChecks')
220 self.mox.StubOutWithMock(gcl, 'GenerateDiff') 230 self.mox.StubOutWithMock(gcl, 'GenerateDiff')
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 try: 357 try:
348 gcl.CMDupload(['naame', '-s', 'foo']) 358 gcl.CMDupload(['naame', '-s', 'foo'])
349 self.fail() 359 self.fail()
350 except SystemExit: 360 except SystemExit:
351 pass 361 pass
352 362
353 363
354 if __name__ == '__main__': 364 if __name__ == '__main__':
355 import unittest 365 import unittest
356 unittest.main() 366 unittest.main()
OLDNEW
« gcl.py ('K') | « gcl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698