| 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 import unittest | |
| 9 | |
| 10 # Local imports | 8 # Local imports |
| 11 import gcl | 9 import gcl |
| 12 import super_mox | 10 from super_mox import mox, SuperMoxTestBase |
| 13 from super_mox import mox | |
| 14 | 11 |
| 15 | 12 |
| 16 class GclTestsBase(super_mox.SuperMoxTestBase): | 13 class GclTestsBase(SuperMoxTestBase): |
| 17 """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.""" |
| 18 def setUp(self): | 15 def setUp(self): |
| 19 super_mox.SuperMoxTestBase.setUp(self) | 16 SuperMoxTestBase.setUp(self) |
| 20 self.fake_root_dir = self.RootDir() | 17 self.fake_root_dir = self.RootDir() |
| 21 self.mox.StubOutWithMock(gcl, 'RunShell') | 18 self.mox.StubOutWithMock(gcl, 'RunShell') |
| 22 self.mox.StubOutWithMock(gcl.gclient_scm, 'CaptureSVNInfo') | 19 self.mox.StubOutWithMock(gcl.gclient_scm, 'CaptureSVNInfo') |
| 23 self.mox.StubOutWithMock(gcl.os, 'getcwd') | |
| 24 self.mox.StubOutWithMock(gcl.os, 'chdir') | |
| 25 self.mox.StubOutWithMock(gcl.os, 'close') | |
| 26 self.mox.StubOutWithMock(gcl.os, 'remove') | |
| 27 self.mox.StubOutWithMock(gcl.os, 'write') | |
| 28 self.mox.StubOutWithMock(gcl.os.path, 'exists') | |
| 29 self.mox.StubOutWithMock(gcl.os.path, 'isdir') | |
| 30 self.mox.StubOutWithMock(gcl.os.path, 'isfile') | |
| 31 self.mox.StubOutWithMock(gcl, 'tempfile') | 20 self.mox.StubOutWithMock(gcl, 'tempfile') |
| 32 self.mox.StubOutWithMock(gcl.upload, 'RealMain') | 21 self.mox.StubOutWithMock(gcl.upload, 'RealMain') |
| 33 # These are not tested. | 22 # These are not tested. |
| 34 self.mox.StubOutWithMock(gcl, 'ReadFile') | 23 self.mox.StubOutWithMock(gcl, 'ReadFile') |
| 35 self.mox.StubOutWithMock(gcl, 'WriteFile') | 24 self.mox.StubOutWithMock(gcl, 'WriteFile') |
| 36 | 25 |
| 37 | 26 |
| 38 class GclUnittest(GclTestsBase): | 27 class GclUnittest(GclTestsBase): |
| 39 """General gcl.py tests.""" | 28 """General gcl.py tests.""" |
| 40 def testMembersChanged(self): | 29 def testMembersChanged(self): |
| 41 self.mox.ReplayAll() | 30 self.mox.ReplayAll() |
| 42 members = [ | 31 members = [ |
| 43 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', | 32 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', |
| 44 'Change', 'ChangeInfo', 'Changes', 'Commit', | 33 'Change', 'ChangeInfo', 'Changes', 'Commit', |
| 45 'DEFAULT_LINT_IGNORE_REGEX', 'DEFAULT_LINT_REGEX', | 34 'DEFAULT_LINT_IGNORE_REGEX', 'DEFAULT_LINT_REGEX', |
| 46 'DeleteEmptyChangeLists', 'DoPresubmitChecks', | 35 'DeleteEmptyChangeLists', 'DoPresubmitChecks', |
| 47 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenerateChangeName', | 36 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenerateChangeName', |
| 48 'GenerateDiff', | 37 'GenerateDiff', |
| 49 'GetCacheDir', 'GetCachedFile', 'GetChangesDir', 'GetCLs', | 38 'GetCacheDir', 'GetCachedFile', 'GetChangesDir', 'GetCLs', |
| 50 'GetChangelistInfoFile', 'GetCodeReviewSetting', 'GetEditor', | 39 'GetChangelistInfoFile', 'GetCodeReviewSetting', 'GetEditor', |
| 51 'GetFilesNotInCL', 'GetInfoDir', 'GetIssueDescription', | 40 'GetFilesNotInCL', 'GetInfoDir', 'GetIssueDescription', |
| 52 'GetModifiedFiles', 'GetRepositoryRoot', | 41 'GetModifiedFiles', 'GetRepositoryRoot', |
| 53 'GetSVNFileProperty', 'Help', 'IsSVNMoved', | 42 'GetSVNFileProperty', 'Help', 'IsSVNMoved', |
| 54 'Lint', 'LoadChangelistInfoForMultiple', | 43 'Lint', 'LoadChangelistInfoForMultiple', |
| 55 'MISSING_TEST_MSG', 'Opened', 'OptionallyDoPresubmitChecks', | 44 'MISSING_TEST_MSG', 'Opened', 'OptionallyDoPresubmitChecks', |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 116 |
| 128 def testSendToRietveld(self): | 117 def testSendToRietveld(self): |
| 129 # TODO(maruel): TEST ME | 118 # TODO(maruel): TEST ME |
| 130 pass | 119 pass |
| 131 | 120 |
| 132 def testOpened(self): | 121 def testOpened(self): |
| 133 # TODO(maruel): TEST ME | 122 # TODO(maruel): TEST ME |
| 134 pass | 123 pass |
| 135 | 124 |
| 136 def testHelp(self): | 125 def testHelp(self): |
| 137 self.mox.StubOutWithMock(gcl.sys, 'stdout') | |
| 138 gcl.sys.stdout.write(mox.StrContains('GCL is a wrapper for Subversion')) | 126 gcl.sys.stdout.write(mox.StrContains('GCL is a wrapper for Subversion')) |
| 139 gcl.sys.stdout.write('\n') | 127 gcl.sys.stdout.write('\n') |
| 140 self.mox.ReplayAll() | 128 self.mox.ReplayAll() |
| 141 gcl.Help() | 129 gcl.Help() |
| 142 | 130 |
| 143 def testGenerateDiff(self): | 131 def testGenerateDiff(self): |
| 144 # TODO(maruel): TEST ME | 132 # TODO(maruel): TEST ME |
| 145 pass | 133 pass |
| 146 | 134 |
| 147 def testPresubmitCL(self): | 135 def testPresubmitCL(self): |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 gcl.TryChange(change_info, [], swallow_exception=True) | 345 gcl.TryChange(change_info, [], swallow_exception=True) |
| 358 gcl.os.chdir('somewhere') | 346 gcl.os.chdir('somewhere') |
| 359 self.mox.ReplayAll() | 347 self.mox.ReplayAll() |
| 360 | 348 |
| 361 gcl.UploadCL(change_info, args) | 349 gcl.UploadCL(change_info, args) |
| 362 self.assertEquals(change_info.issue, 1) | 350 self.assertEquals(change_info.issue, 1) |
| 363 self.assertEquals(change_info.patchset, 2) | 351 self.assertEquals(change_info.patchset, 2) |
| 364 | 352 |
| 365 | 353 |
| 366 if __name__ == '__main__': | 354 if __name__ == '__main__': |
| 355 import unittest |
| 367 unittest.main() | 356 unittest.main() |
| OLD | NEW |