| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 21 self.mox.StubOutWithMock(gcl.SVN, 'GetCheckoutRoot') | 21 self.mox.StubOutWithMock(gcl.SVN, 'GetCheckoutRoot') |
| 22 self.mox.StubOutWithMock(gcl, 'tempfile') | 22 self.mox.StubOutWithMock(gcl, 'tempfile') |
| 23 self.mox.StubOutWithMock(gcl.upload, 'RealMain') | 23 self.mox.StubOutWithMock(gcl.upload, 'RealMain') |
| 24 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileRead') | 24 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileRead') |
| 25 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileWrite') | 25 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileWrite') |
| 26 gcl.REPOSITORY_ROOT = None | 26 gcl.REPOSITORY_ROOT = None |
| 27 | 27 |
| 28 | 28 |
| 29 class GclUnittest(GclTestsBase): | 29 class GclUnittest(GclTestsBase): |
| 30 """General gcl.py tests.""" | 30 """General gcl.py tests.""" |
| 31 def tearDown(self): |
| 32 gcl.CODEREVIEW_SETTINGS = {} |
| 33 |
| 31 def testMembersChanged(self): | 34 def testMembersChanged(self): |
| 32 self.mox.ReplayAll() | 35 self.mox.ReplayAll() |
| 33 members = [ | 36 members = [ |
| 34 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', | 37 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', |
| 35 'CODEREVIEW_SETTINGS_FILE_NOT_FOUND', | 38 'CODEREVIEW_SETTINGS_FILE_NOT_FOUND', |
| 36 'CMDchange', 'CMDchanges', 'CMDcommit', 'CMDdelete', 'CMDdeleteempties', | 39 'CMDchange', 'CMDchanges', 'CMDcommit', 'CMDdelete', 'CMDdeleteempties', |
| 37 'CMDdescription', 'CMDdiff', 'CMDhelp', 'CMDlint', 'CMDnothave', | 40 'CMDdescription', 'CMDdiff', 'CMDhelp', 'CMDlint', 'CMDnothave', |
| 38 'CMDopened', 'CMDpassthru', 'CMDpresubmit', 'CMDrename', 'CMDsettings', | 41 'CMDopened', 'CMDpassthru', 'CMDpresubmit', 'CMDrename', 'CMDsettings', |
| 39 'CMDstatus', 'CMDtry', 'CMDupload', | 42 'CMDstatus', 'CMDtry', 'CMDupload', |
| 40 'ChangeInfo', 'Command', 'DEFAULT_LINT_IGNORE_REGEX', | 43 'ChangeInfo', 'Command', 'DEFAULT_LINT_IGNORE_REGEX', |
| (...skipping 25 matching lines...) Expand all Loading... |
| 66 pass | 69 pass |
| 67 | 70 |
| 68 def testUnknownFiles(self): | 71 def testUnknownFiles(self): |
| 69 # TODO(maruel): TEST ME | 72 # TODO(maruel): TEST ME |
| 70 pass | 73 pass |
| 71 | 74 |
| 72 def testCheckHomeForFile(self): | 75 def testCheckHomeForFile(self): |
| 73 # TODO(maruel): TEST ME | 76 # TODO(maruel): TEST ME |
| 74 pass | 77 pass |
| 75 | 78 |
| 79 def testDefaultSettings(self): |
| 80 self.assertEquals({}, gcl.CODEREVIEW_SETTINGS) |
| 81 |
| 82 def testGetCodeReviewSettingOk(self): |
| 83 self.mox.StubOutWithMock(gcl, 'GetCachedFile') |
| 84 gcl.GetCachedFile(gcl.CODEREVIEW_SETTINGS_FILE).AndReturn( |
| 85 'foo:bar\n' |
| 86 '# comment\n' |
| 87 ' c : d \n\r' |
| 88 'e: f') |
| 89 self.mox.ReplayAll() |
| 90 self.assertEquals('bar', gcl.GetCodeReviewSetting('foo')) |
| 91 self.assertEquals('d', gcl.GetCodeReviewSetting('c')) |
| 92 self.assertEquals('f', gcl.GetCodeReviewSetting('e')) |
| 93 self.assertEquals('', gcl.GetCodeReviewSetting('other')) |
| 94 self.assertEquals( |
| 95 {'foo': 'bar', 'c': 'd', 'e': 'f', '__just_initialized': None}, |
| 96 gcl.CODEREVIEW_SETTINGS) |
| 97 |
| 98 def testGetCodeReviewSettingFail(self): |
| 99 self.mox.StubOutWithMock(gcl, 'GetCachedFile') |
| 100 gcl.GetCachedFile(gcl.CODEREVIEW_SETTINGS_FILE).AndReturn( |
| 101 'aaa\n' |
| 102 ' c : d \n\r' |
| 103 'e: f') |
| 104 self.mox.ReplayAll() |
| 105 try: |
| 106 gcl.GetCodeReviewSetting('c') |
| 107 self.fail() |
| 108 except gcl.gclient_utils.Error: |
| 109 pass |
| 110 self.assertEquals({}, gcl.CODEREVIEW_SETTINGS) |
| 111 |
| 76 def testGetRepositoryRootNone(self): | 112 def testGetRepositoryRootNone(self): |
| 77 gcl.os.getcwd().AndReturn(self.fake_root_dir) | 113 gcl.os.getcwd().AndReturn(self.fake_root_dir) |
| 78 gcl.SVN.GetCheckoutRoot(self.fake_root_dir).AndReturn(None) | 114 gcl.SVN.GetCheckoutRoot(self.fake_root_dir).AndReturn(None) |
| 79 self.mox.ReplayAll() | 115 self.mox.ReplayAll() |
| 80 self.assertRaises(gcl.gclient_utils.Error, gcl.GetRepositoryRoot) | 116 self.assertRaises(gcl.gclient_utils.Error, gcl.GetRepositoryRoot) |
| 81 | 117 |
| 82 def testGetRepositoryRootGood(self): | 118 def testGetRepositoryRootGood(self): |
| 83 root_path = gcl.os.path.join('bleh', 'prout', 'pouet') | 119 root_path = gcl.os.path.join('bleh', 'prout', 'pouet') |
| 84 gcl.os.getcwd().AndReturn(root_path) | 120 gcl.os.getcwd().AndReturn(root_path) |
| 85 gcl.SVN.GetCheckoutRoot(root_path).AndReturn(root_path + '.~') | 121 gcl.SVN.GetCheckoutRoot(root_path).AndReturn(root_path + '.~') |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 self.mox.ReplayAll() | 322 self.mox.ReplayAll() |
| 287 | 323 |
| 288 gcl.CMDupload(['naame', '--no_watchlists']) | 324 gcl.CMDupload(['naame', '--no_watchlists']) |
| 289 self.assertEquals(change_info.issue, 1) | 325 self.assertEquals(change_info.issue, 1) |
| 290 self.assertEquals(change_info.patchset, 2) | 326 self.assertEquals(change_info.patchset, 2) |
| 291 | 327 |
| 292 | 328 |
| 293 if __name__ == '__main__': | 329 if __name__ == '__main__': |
| 294 import unittest | 330 import unittest |
| 295 unittest.main() | 331 unittest.main() |
| OLD | NEW |