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 StringIO | 8 import StringIO |
9 import os | 9 import os |
10 import sys | 10 import sys |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 print diff | 47 print diff |
48 self.assertEqual(actual_members, expected_members) | 48 self.assertEqual(actual_members, expected_members) |
49 | 49 |
50 | 50 |
51 class GclUnittest(GclTestsBase): | 51 class GclUnittest(GclTestsBase): |
52 """General gcl.py tests.""" | 52 """General gcl.py tests.""" |
53 def testMembersChanged(self): | 53 def testMembersChanged(self): |
54 members = [ | 54 members = [ |
55 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', 'CPP_EXTENSIONS', | 55 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', 'CPP_EXTENSIONS', |
56 'Change', 'ChangeInfo', 'Changes', 'Commit', 'DoPresubmitChecks', | 56 'Change', 'ChangeInfo', 'Changes', 'Commit', 'DoPresubmitChecks', |
57 'ErrorExit', 'GenerateChangeName', 'GenerateDiff', 'GetCLs', | 57 'ErrorExit', 'FILES_CACHE', 'GenerateChangeName', 'GenerateDiff', |
| 58 'GetCacheDir', 'GetCachedFile', 'GetChangesDir', 'GetCLs', |
58 'GetChangelistInfoFile', 'GetCodeReviewSetting', 'GetEditor', | 59 'GetChangelistInfoFile', 'GetCodeReviewSetting', 'GetEditor', |
59 'GetFilesNotInCL', 'GetInfoDir', 'GetIssueDescription', | 60 'GetFilesNotInCL', 'GetInfoDir', 'GetIssueDescription', |
60 'GetModifiedFiles', 'GetRepositoryRoot', | 61 'GetModifiedFiles', 'GetRepositoryRoot', |
61 'GetSVNFileProperty', 'Help', 'IGNORE_PATHS', 'IsSVNMoved', 'IsTreeOpen', | 62 'GetSVNFileProperty', 'Help', 'IGNORE_PATHS', 'IsSVNMoved', 'IsTreeOpen', |
62 'Lint', 'LoadChangelistInfo', 'LoadChangelistInfoForMultiple', | 63 'Lint', 'LoadChangelistInfo', 'LoadChangelistInfoForMultiple', |
63 'MISSING_TEST_MSG', 'Opened', 'PresubmitCL', 'ReadFile', | 64 'MISSING_TEST_MSG', 'Opened', 'PresubmitCL', 'ReadFile', |
64 'RunShell', | 65 'REPOSITORY_ROOT', 'RunShell', |
65 'RunShellWithReturnCode', 'SEPARATOR', 'SendToRietveld', 'TryChange', | 66 'RunShellWithReturnCode', 'SEPARATOR', 'SendToRietveld', 'TryChange', |
66 'UnknownFiles', 'UploadCL', 'Warn', 'WriteFile', 'gclient', | 67 'UnknownFiles', 'UploadCL', 'Warn', 'WriteFile', |
67 'gcl_info_dir', 'getpass', 'main', 'os', 'random', 're', 'read_gcl_info', | 68 'gclient', 'getpass', 'main', 'os', 'random', 're', |
68 'repository_root', 'string', 'subprocess', 'sys', 'tempfile', 'upload', | 69 'shutil', 'string', 'subprocess', 'sys', 'tempfile', |
69 'urllib2', 'xml', | 70 'upload', 'urllib2', 'xml', |
70 ] | 71 ] |
71 # If this test fails, you should add the relevant test. | 72 # If this test fails, you should add the relevant test. |
72 self.compareMembers(gcl, members) | 73 self.compareMembers(gcl, members) |
73 | 74 |
74 | 75 |
75 def testHelp(self): | 76 def testHelp(self): |
76 old_stdout = sys.stdout | 77 old_stdout = sys.stdout |
77 try: | 78 try: |
78 dummy = StringIO.StringIO() | 79 dummy = StringIO.StringIO() |
79 gcl.sys.stdout = dummy | 80 gcl.sys.stdout = dummy |
80 gcl.Help() | 81 gcl.Help() |
81 self.assertEquals(len(dummy.getvalue()), 1813) | 82 self.assertEquals(len(dummy.getvalue()), 1815) |
82 finally: | 83 finally: |
83 gcl.sys.stdout = old_stdout | 84 gcl.sys.stdout = old_stdout |
84 | 85 |
85 def testGetRepositoryRootNone(self): | 86 def testGetRepositoryRootNone(self): |
86 gcl.repository_root = None | 87 gcl.REPOSITORY_ROOT = None |
87 gcl.os.getcwd().AndReturn("/bleh/prout") | 88 gcl.os.getcwd().AndReturn("/bleh/prout") |
88 result = { | 89 result = { |
89 "Repository Root": "" | 90 "Repository Root": "" |
90 } | 91 } |
91 gcl.gclient.CaptureSVNInfo("/bleh/prout", print_error=False).AndReturn( | 92 gcl.gclient.CaptureSVNInfo("/bleh/prout", print_error=False).AndReturn( |
92 result) | 93 result) |
93 self.mox.ReplayAll() | 94 self.mox.ReplayAll() |
94 self.assertRaises(Exception, gcl.GetRepositoryRoot) | 95 self.assertRaises(Exception, gcl.GetRepositoryRoot) |
95 self.mox.VerifyAll() | 96 self.mox.VerifyAll() |
96 | 97 |
97 def testGetRepositoryRootGood(self): | 98 def testGetRepositoryRootGood(self): |
98 gcl.repository_root = None | 99 gcl.REPOSITORY_ROOT = None |
99 root_path = os.path.join('bleh', 'prout', 'pouet') | 100 root_path = os.path.join('bleh', 'prout', 'pouet') |
100 gcl.os.getcwd().AndReturn(root_path) | 101 gcl.os.getcwd().AndReturn(root_path) |
101 result1 = { "Repository Root": "Some root" } | 102 result1 = { "Repository Root": "Some root" } |
102 gcl.gclient.CaptureSVNInfo(root_path, print_error=False).AndReturn(result1) | 103 gcl.gclient.CaptureSVNInfo(root_path, print_error=False).AndReturn(result1) |
103 gcl.os.getcwd().AndReturn(root_path) | 104 gcl.os.getcwd().AndReturn(root_path) |
104 results2 = { "Repository Root": "A different root" } | 105 results2 = { "Repository Root": "A different root" } |
105 gcl.gclient.CaptureSVNInfo( | 106 gcl.gclient.CaptureSVNInfo( |
106 os.path.dirname(root_path), | 107 os.path.dirname(root_path), |
107 print_error=False).AndReturn(results2) | 108 print_error=False).AndReturn(results2) |
108 self.mox.ReplayAll() | 109 self.mox.ReplayAll() |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 ['--issue', '1', '--patchset', '2'], | 278 ['--issue', '1', '--patchset', '2'], |
278 swallow_exception=True) | 279 swallow_exception=True) |
279 gcl.os.chdir('somewhere') | 280 gcl.os.chdir('somewhere') |
280 self.mox.ReplayAll() | 281 self.mox.ReplayAll() |
281 gcl.UploadCL(change_info, args) | 282 gcl.UploadCL(change_info, args) |
282 self.mox.VerifyAll() | 283 self.mox.VerifyAll() |
283 | 284 |
284 | 285 |
285 if __name__ == '__main__': | 286 if __name__ == '__main__': |
286 unittest.main() | 287 unittest.main() |
OLD | NEW |