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

Side by Side Diff: tests/gcl_unittest.py

Issue 8508017: Standardize the sys.path fix up and fix a few pylint warnings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Previous patchset was broken Created 9 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
« no previous file with comments | « tests/fix_encoding_test.py ('k') | tests/gclient_scm_test.py » ('j') | 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/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 # pylint is too confused. 8 # pylint: disable=E1103,E1101,E1120
9 # pylint: disable=E1101,E1103,E1120,W0212,W0403
10 9
11 # Fixes include path. 10 import os
11 import sys
12
13 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
14
12 from super_mox import mox, SuperMoxTestBase 15 from super_mox import mox, SuperMoxTestBase
13 16
14 import gcl 17 import gcl
15 import presubmit_support 18 import presubmit_support
16 19
17 20
18 class GclTestsBase(SuperMoxTestBase): 21 class GclTestsBase(SuperMoxTestBase):
19 """Setups and tear downs the mocks but doesn't test anything as-is.""" 22 """Setups and tear downs the mocks but doesn't test anything as-is."""
20 def setUp(self): 23 def setUp(self):
21 SuperMoxTestBase.setUp(self) 24 SuperMoxTestBase.setUp(self)
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 GclTestsBase.setUp(self) 176 GclTestsBase.setUp(self)
174 self.mox.StubOutWithMock(gcl, 'GetChangelistInfoFile') 177 self.mox.StubOutWithMock(gcl, 'GetChangelistInfoFile')
175 self.mox.StubOutWithMock(gcl, 'GetRepositoryRoot') 178 self.mox.StubOutWithMock(gcl, 'GetRepositoryRoot')
176 179
177 def testChangeInfoMembers(self): 180 def testChangeInfoMembers(self):
178 self.mox.ReplayAll() 181 self.mox.ReplayAll()
179 members = [ 182 members = [
180 'CloseIssue', 'Delete', 'Exists', 'GetFiles', 'GetFileNames', 183 'CloseIssue', 'Delete', 'Exists', 'GetFiles', 'GetFileNames',
181 'GetLocalRoot', 'GetIssueDescription', 'Load', 'MissingTests', 184 'GetLocalRoot', 'GetIssueDescription', 'Load', 'MissingTests',
182 'NeedsUpload', 'PrimeLint', 'RpcServer', 'Save', 'SendToRietveld', 185 'NeedsUpload', 'PrimeLint', 'RpcServer', 'Save', 'SendToRietveld',
186 'SEPARATOR',
183 'UpdateRietveldDescription', 187 'UpdateRietveldDescription',
184 'description', 'issue', 'name', 188 'description', 'issue', 'name',
185 'needs_upload', 'patch', 'patchset', 'reviewers', 'rietveld', 189 'needs_upload', 'patch', 'patchset', 'reviewers', 'rietveld',
186 'subject', 190 'subject',
187 ] 191 ]
188 # If this test fails, you should add the relevant test. 192 # If this test fails, you should add the relevant test.
189 self.compareMembers( 193 self.compareMembers(
190 gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir, 'foo', False), 194 gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir, 'foo', False),
191 members) 195 members)
192 196
(...skipping 17 matching lines...) Expand all
210 self.assertEquals(o.GetFileNames(), ['foo', 'bar']) 214 self.assertEquals(o.GetFileNames(), ['foo', 'bar'])
211 self.assertEquals(o.GetFiles(), files) 215 self.assertEquals(o.GetFiles(), files)
212 self.assertEquals(o.GetLocalRoot(), self.fake_root_dir) 216 self.assertEquals(o.GetLocalRoot(), self.fake_root_dir)
213 217
214 def testLoadWithIssue(self): 218 def testLoadWithIssue(self):
215 self.mox.StubOutWithMock(gcl, 'GetCodeReviewSetting') 219 self.mox.StubOutWithMock(gcl, 'GetCodeReviewSetting')
216 description = ["This is some description.", "force an extra separator."] 220 description = ["This is some description.", "force an extra separator."]
217 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') 221 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
218 gcl.os.path.exists('bleeeh').AndReturn(True) 222 gcl.os.path.exists('bleeeh').AndReturn(True)
219 gcl.gclient_utils.FileRead('bleeeh').AndReturn( 223 gcl.gclient_utils.FileRead('bleeeh').AndReturn(
220 gcl.ChangeInfo._SEPARATOR.join(["42, 53", "G b.cc"] + description)) 224 gcl.ChangeInfo.SEPARATOR.join(["42, 53", "G b.cc"] + description))
221 gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('foo') 225 gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('foo')
222 # Does an upgrade. 226 # Does an upgrade.
223 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') 227 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
224 gcl.gclient_utils.FileWrite('bleeeh', mox.IgnoreArg()) 228 gcl.gclient_utils.FileWrite('bleeeh', mox.IgnoreArg())
225 self.mox.ReplayAll() 229 self.mox.ReplayAll()
226 230
227 change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False) 231 change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False)
228 self.assertEquals(change_info.name, 'bleh') 232 self.assertEquals(change_info.name, 'bleh')
229 self.assertEquals(change_info.issue, 42) 233 self.assertEquals(change_info.issue, 42)
230 self.assertEquals(change_info.patchset, 53) 234 self.assertEquals(change_info.patchset, 53)
231 self.assertEquals(change_info.description, 235 self.assertEquals(change_info.description,
232 gcl.ChangeInfo._SEPARATOR.join(description)) 236 gcl.ChangeInfo.SEPARATOR.join(description))
233 self.assertEquals(change_info.GetFiles(), [('G ', 'b.cc')]) 237 self.assertEquals(change_info.GetFiles(), [('G ', 'b.cc')])
234 238
235 def testLoadEmpty(self): 239 def testLoadEmpty(self):
236 self.mox.StubOutWithMock(gcl, 'GetCodeReviewSetting') 240 self.mox.StubOutWithMock(gcl, 'GetCodeReviewSetting')
237 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') 241 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
238 gcl.os.path.exists('bleeeh').AndReturn(True) 242 gcl.os.path.exists('bleeeh').AndReturn(True)
239 gcl.gclient_utils.FileRead('bleeeh').AndReturn( 243 gcl.gclient_utils.FileRead('bleeeh').AndReturn(
240 gcl.ChangeInfo._SEPARATOR.join(["", "", ""])) 244 gcl.ChangeInfo.SEPARATOR.join(["", "", ""]))
241 gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('foo') 245 gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('foo')
242 # Does an upgrade. 246 # Does an upgrade.
243 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') 247 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
244 gcl.gclient_utils.FileWrite('bleeeh', mox.IgnoreArg()) 248 gcl.gclient_utils.FileWrite('bleeeh', mox.IgnoreArg())
245 self.mox.ReplayAll() 249 self.mox.ReplayAll()
246 250
247 change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False) 251 change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False)
248 self.assertEquals(change_info.name, 'bleh') 252 self.assertEquals(change_info.name, 'bleh')
249 self.assertEquals(change_info.issue, 0) 253 self.assertEquals(change_info.issue, 0)
250 self.assertEquals(change_info.patchset, 0) 254 self.assertEquals(change_info.patchset, 0)
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 self.mockPresubmit(change_info, fail=False) 563 self.mockPresubmit(change_info, fail=False)
560 self.mockCommit(change_info, 'deescription\nReview URL: http://my_server/1', 564 self.mockCommit(change_info, 'deescription\nReview URL: http://my_server/1',
561 '') 565 '')
562 566
563 self.mox.ReplayAll() 567 self.mox.ReplayAll()
564 568
565 retval = gcl.CMDcommit(['naame']) 569 retval = gcl.CMDcommit(['naame'])
566 570
567 self.assertEquals(retval, 0) 571 self.assertEquals(retval, 0)
568 self.assertEquals(change_info.description, 'deescription') 572 self.assertEquals(change_info.description, 'deescription')
573 # pylint: disable=W0212
569 self.assertFalse(change_info._deleted) 574 self.assertFalse(change_info._deleted)
570 self.assertFalse(change_info._closed) 575 self.assertFalse(change_info._closed)
571 576
572 def testPresubmitSucceedsWithCommittedMessage(self): 577 def testPresubmitSucceedsWithCommittedMessage(self):
573 change_info = self.mockLoad() 578 change_info = self.mockLoad()
574 self.mockPresubmit(change_info, fail=False) 579 self.mockPresubmit(change_info, fail=False)
575 self.mockCommit(change_info, 'deescription\nReview URL: http://my_server/1', 580 self.mockCommit(change_info, 'deescription\nReview URL: http://my_server/1',
576 '\nCommitted revision 12345') 581 '\nCommitted revision 12345')
577 582
578 self.mox.ReplayAll() 583 self.mox.ReplayAll()
579 584
580 retval = gcl.CMDcommit(['naame']) 585 retval = gcl.CMDcommit(['naame'])
581 self.assertEquals(retval, 0) 586 self.assertEquals(retval, 0)
582 self.assertEquals(change_info.description, 587 self.assertEquals(change_info.description,
583 'deescription\n\nCommitted: http://view/12345') 588 'deescription\n\nCommitted: http://view/12345')
589 # pylint: disable=W0212
584 self.assertTrue(change_info._deleted) 590 self.assertTrue(change_info._deleted)
585 self.assertTrue(change_info._closed) 591 self.assertTrue(change_info._closed)
586 592
587 593
588 if __name__ == '__main__': 594 if __name__ == '__main__':
589 import unittest 595 import unittest
590 unittest.main() 596 unittest.main()
OLDNEW
« no previous file with comments | « tests/fix_encoding_test.py ('k') | tests/gclient_scm_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698