| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2009 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 # Local imports | 8 # Local imports |
| 9 import gcl | 9 import gcl |
| 10 from super_mox import mox, SuperMoxTestBase | 10 from super_mox import mox, SuperMoxTestBase |
| 11 | 11 |
| 12 | 12 |
| 13 class GclTestsBase(SuperMoxTestBase): | 13 class GclTestsBase(SuperMoxTestBase): |
| 14 """Setups and tear downs the mocks but doesn't test anything as-is.""" | 14 """Setups and tear downs the mocks but doesn't test anything as-is.""" |
| 15 def setUp(self): | 15 def setUp(self): |
| 16 SuperMoxTestBase.setUp(self) | 16 SuperMoxTestBase.setUp(self) |
| 17 self.fake_root_dir = self.RootDir() | 17 self.fake_root_dir = self.RootDir() |
| 18 self.mox.StubOutWithMock(gcl, 'RunShell') | 18 self.mox.StubOutWithMock(gcl, 'RunShell') |
| 19 self.mox.StubOutWithMock(gcl.SVN, 'CaptureInfo') | 19 self.mox.StubOutWithMock(gcl.SVN, 'CaptureInfo') |
| 20 self.mox.StubOutWithMock(gcl, 'tempfile') | 20 self.mox.StubOutWithMock(gcl, 'tempfile') |
| 21 self.mox.StubOutWithMock(gcl.upload, 'RealMain') | 21 self.mox.StubOutWithMock(gcl.upload, 'RealMain') |
| 22 self.mox.StubOutWithMock(gcl, 'ReadFile') | 22 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileRead') |
| 23 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileWrite') | 23 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileWrite') |
| 24 | 24 |
| 25 | 25 |
| 26 class GclUnittest(GclTestsBase): | 26 class GclUnittest(GclTestsBase): |
| 27 """General gcl.py tests.""" | 27 """General gcl.py tests.""" |
| 28 def testMembersChanged(self): | 28 def testMembersChanged(self): |
| 29 self.mox.ReplayAll() | 29 self.mox.ReplayAll() |
| 30 members = [ | 30 members = [ |
| 31 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', 'Change', | 31 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', 'Change', |
| 32 'ChangeInfo', 'Changes', 'Commit', 'DEFAULT_LINT_IGNORE_REGEX', | 32 'ChangeInfo', 'Changes', 'Commit', 'DEFAULT_LINT_IGNORE_REGEX', |
| 33 'DEFAULT_LINT_REGEX', 'DeleteEmptyChangeLists', 'DoPresubmitChecks', | 33 'DEFAULT_LINT_REGEX', 'DeleteEmptyChangeLists', 'DoPresubmitChecks', |
| 34 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenerateChangeName', | 34 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenerateChangeName', |
| 35 'GenerateDiff', 'GetCLs', 'GetCacheDir', 'GetCachedFile', | 35 'GenerateDiff', 'GetCLs', 'GetCacheDir', 'GetCachedFile', |
| 36 'GetChangelistInfoFile', 'GetChangesDir', 'GetCodeReviewSetting', | 36 'GetChangelistInfoFile', 'GetChangesDir', 'GetCodeReviewSetting', |
| 37 'GetEditor', 'GetFilesNotInCL', 'GetInfoDir', 'GetIssueDescription', | 37 'GetEditor', 'GetFilesNotInCL', 'GetInfoDir', 'GetIssueDescription', |
| 38 'GetModifiedFiles', 'GetRepositoryRoot', 'Help', 'Lint', | 38 'GetModifiedFiles', 'GetRepositoryRoot', 'Help', 'Lint', |
| 39 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG', 'Opened', | 39 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG', 'Opened', |
| 40 'OptionallyDoPresubmitChecks', 'PresubmitCL', 'REPOSITORY_ROOT', | 40 'OptionallyDoPresubmitChecks', 'PresubmitCL', 'REPOSITORY_ROOT', |
| 41 'ReadFile', 'RunShell', 'RunShellWithReturnCode', 'SVN', | 41 'RunShell', 'RunShellWithReturnCode', 'SVN', |
| 42 'SendToRietveld', 'TryChange', 'UnknownFiles', 'UploadCL', 'Warn', | 42 'SendToRietveld', 'TryChange', 'UnknownFiles', 'UploadCL', 'Warn', |
| 43 'breakpad', 'gclient_utils', 'getpass', 'main', 'os', 'random', 're', | 43 'breakpad', 'gclient_utils', 'getpass', 'main', 'os', 'random', 're', |
| 44 'shutil', 'string', 'subprocess', 'sys', 'tempfile', 'upload', | 44 'shutil', 'string', 'subprocess', 'sys', 'tempfile', 'upload', |
| 45 'urllib2', | 45 'urllib2', |
| 46 ] | 46 ] |
| 47 # If this test fails, you should add the relevant test. | 47 # If this test fails, you should add the relevant test. |
| 48 self.compareMembers(gcl, members) | 48 self.compareMembers(gcl, members) |
| 49 | 49 |
| 50 def testIsSVNMoved(self): | 50 def testIsSVNMoved(self): |
| 51 # TODO(maruel): TEST ME | 51 # TODO(maruel): TEST ME |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 self.assertEquals(o.description, 'description2') | 178 self.assertEquals(o.description, 'description2') |
| 179 self.assertEquals(o.patch, None) | 179 self.assertEquals(o.patch, None) |
| 180 self.assertEquals(o.GetFileNames(), ['foo', 'bar']) | 180 self.assertEquals(o.GetFileNames(), ['foo', 'bar']) |
| 181 self.assertEquals(o.GetFiles(), files) | 181 self.assertEquals(o.GetFiles(), files) |
| 182 self.assertEquals(o.GetLocalRoot(), self.fake_root_dir) | 182 self.assertEquals(o.GetLocalRoot(), self.fake_root_dir) |
| 183 | 183 |
| 184 def testLoadWithIssue(self): | 184 def testLoadWithIssue(self): |
| 185 description = ["This is some description.", "force an extra separator."] | 185 description = ["This is some description.", "force an extra separator."] |
| 186 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') | 186 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') |
| 187 gcl.os.path.exists('bleeeh').AndReturn(True) | 187 gcl.os.path.exists('bleeeh').AndReturn(True) |
| 188 gcl.ReadFile('bleeeh').AndReturn( | 188 gcl.gclient_utils.FileRead('bleeeh', 'r').AndReturn( |
| 189 gcl.ChangeInfo._SEPARATOR.join(["42, 53", "G b.cc"] + description)) | 189 gcl.ChangeInfo._SEPARATOR.join(["42, 53", "G b.cc"] + description)) |
| 190 self.mox.ReplayAll() | 190 self.mox.ReplayAll() |
| 191 | 191 |
| 192 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) |
| 193 self.assertEquals(change_info.name, 'bleh') | 193 self.assertEquals(change_info.name, 'bleh') |
| 194 self.assertEquals(change_info.issue, 42) | 194 self.assertEquals(change_info.issue, 42) |
| 195 self.assertEquals(change_info.patchset, 53) | 195 self.assertEquals(change_info.patchset, 53) |
| 196 self.assertEquals(change_info.description, | 196 self.assertEquals(change_info.description, |
| 197 gcl.ChangeInfo._SEPARATOR.join(description)) | 197 gcl.ChangeInfo._SEPARATOR.join(description)) |
| 198 self.assertEquals(change_info.GetFiles(), [('G ', 'b.cc')]) | 198 self.assertEquals(change_info.GetFiles(), [('G ', 'b.cc')]) |
| 199 | 199 |
| 200 def testLoadEmpty(self): | 200 def testLoadEmpty(self): |
| 201 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') | 201 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') |
| 202 gcl.os.path.exists('bleeeh').AndReturn(True) | 202 gcl.os.path.exists('bleeeh').AndReturn(True) |
| 203 gcl.ReadFile('bleeeh').AndReturn( | 203 gcl.gclient_utils.FileRead('bleeeh', 'r').AndReturn( |
| 204 gcl.ChangeInfo._SEPARATOR.join(["", "", ""])) | 204 gcl.ChangeInfo._SEPARATOR.join(["", "", ""])) |
| 205 self.mox.ReplayAll() | 205 self.mox.ReplayAll() |
| 206 | 206 |
| 207 change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False) | 207 change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False) |
| 208 self.assertEquals(change_info.name, 'bleh') | 208 self.assertEquals(change_info.name, 'bleh') |
| 209 self.assertEquals(change_info.issue, 0) | 209 self.assertEquals(change_info.issue, 0) |
| 210 self.assertEquals(change_info.patchset, 0) | 210 self.assertEquals(change_info.patchset, 0) |
| 211 self.assertEquals(change_info.description, "") | 211 self.assertEquals(change_info.description, "") |
| 212 self.assertEquals(change_info.GetFiles(), []) | 212 self.assertEquals(change_info.GetFiles(), []) |
| 213 | 213 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 self.mox.ReplayAll() | 352 self.mox.ReplayAll() |
| 353 | 353 |
| 354 gcl.UploadCL(change_info, args) | 354 gcl.UploadCL(change_info, args) |
| 355 self.assertEquals(change_info.issue, 1) | 355 self.assertEquals(change_info.issue, 1) |
| 356 self.assertEquals(change_info.patchset, 2) | 356 self.assertEquals(change_info.patchset, 2) |
| 357 | 357 |
| 358 | 358 |
| 359 if __name__ == '__main__': | 359 if __name__ == '__main__': |
| 360 import unittest | 360 import unittest |
| 361 unittest.main() | 361 unittest.main() |
| OLD | NEW |