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

Side by Side Diff: tests/gcl_unittest.py

Issue 115217: Revert changes 15823 and 15824 because they broke gclient revert. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 11 years, 7 months 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 | « gclient.py ('k') | tests/gclient_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/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
9 import os 8 import os
10 import sys
11 import unittest 9 import unittest
12 10
13 # Local imports 11 # Local imports
14 import gcl 12 import gcl
15 13
16 14
17 class GclTestsBase(unittest.TestCase): 15 class GclTestsBase(unittest.TestCase):
18 """Setups and tear downs the mocks but doesn't test anything as-is.""" 16 """Setups and tear downs the mocks but doesn't test anything as-is."""
19 def setUp(self): 17 def setUp(self):
20 def RunShellMock(filename): 18 def RunShellMock(filename):
(...skipping 20 matching lines...) Expand all
41 39
42 class GclUnittest(GclTestsBase): 40 class GclUnittest(GclTestsBase):
43 """General gcl.py tests.""" 41 """General gcl.py tests."""
44 def testMembersChanged(self): 42 def testMembersChanged(self):
45 members = [ 43 members = [
46 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', 'CPP_EXTENSIONS', 44 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', 'CPP_EXTENSIONS',
47 'Change', 'ChangeInfo', 'Changes', 'Commit', 'DoPresubmitChecks', 45 'Change', 'ChangeInfo', 'Changes', 'Commit', 'DoPresubmitChecks',
48 'ErrorExit', 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 46 'ErrorExit', 'GenerateChangeName', 'GenerateDiff', 'GetCLs',
49 'GetChangelistInfoFile', 'GetCodeReviewSetting', 'GetEditor', 47 'GetChangelistInfoFile', 'GetCodeReviewSetting', 'GetEditor',
50 'GetFilesNotInCL', 'GetInfoDir', 'GetIssueDescription', 48 'GetFilesNotInCL', 'GetInfoDir', 'GetIssueDescription',
51 'GetModifiedFiles', 'GetRepositoryRoot', 'GetSVNStatus', 49 'GetModifiedFiles', 'GetNamedNodeText', 'GetNodeNamedAttributeText',
50 'GetRepositoryRoot', 'GetSVNFileInfo', 'GetSVNStatus',
52 'GetSVNFileProperty', 'Help', 'IGNORE_PATHS', 'IsSVNMoved', 'IsTreeOpen', 51 'GetSVNFileProperty', 'Help', 'IGNORE_PATHS', 'IsSVNMoved', 'IsTreeOpen',
53 'Lint', 'LoadChangelistInfo', 'LoadChangelistInfoForMultiple', 52 'Lint', 'LoadChangelistInfo', 'LoadChangelistInfoForMultiple',
54 'MISSING_TEST_MSG', 'Opened', 'PresubmitCL', 'ReadFile', 53 'MISSING_TEST_MSG', 'Opened', 'ParseXML', 'PresubmitCL', 'ReadFile',
55 'RunShell', 54 'RunShell',
56 'RunShellWithReturnCode', 'SEPARATOR', 'SendToRietveld', 'TryChange', 55 'RunShellWithReturnCode', 'SEPARATOR', 'SendToRietveld', 'TryChange',
57 'UnknownFiles', 'UploadCL', 'Warn', 'WriteFile', 'gclient', 56 'UnknownFiles', 'UploadCL', 'Warn', 'WriteFile', 'gcl_info_dir',
58 'gcl_info_dir', 'getpass', 'main', 'os', 'random', 're', 'read_gcl_info', 57 'getpass', 'main', 'os', 'random', 're', 'read_gcl_info',
59 'repository_root', 'string', 'subprocess', 'sys', 'tempfile', 'upload', 58 'repository_root', 'string', 'subprocess', 'sys', 'tempfile', 'upload',
60 'urllib2', 'use_shell', 'xml', 59 'urllib2', 'use_shell', 'xml',
61 60
62 ] 61 ]
63 # If this test fails, you should add the relevant test. 62 # If this test fails, you should add the relevant test.
64 self.compareMembers(gcl, members) 63 self.compareMembers(gcl, members)
65 64
65 def testGetSVNFileInfo(self):
66 def RunShellMock(command):
67 return r"""<?xml version="1.0"?>
68 <info>
69 <entry kind="file" path="%s" revision="14628">
70 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url>
71 <repository><root>http://src.chromium.org/svn</root></repository>
72 <wc-info>
73 <schedule>add</schedule>
74 <depth>infinity</depth>
75 <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from- url>
76 <copy-from-rev>14628</copy-from-rev>
77 <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum>
78 </wc-info>
79 </entry>
80 </info>
81 """ % command[3]
82 gcl.RunShell = RunShellMock
83 filename = os.path.join('app', 'd')
84 info = gcl.GetSVNFileInfo(filename)
85 expected = {
86 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d',
87 'Repository Root': 'http://src.chromium.org/svn',
88 'Schedule': 'add',
89 'Copied From URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS' ,
90 'Copied From Rev': '14628',
91 'Path': filename,
92 'Node Kind': 'file',
93 }
94 self.assertEquals(sorted(info.items()), sorted(expected.items()))
95
66 def testGetSVNStatus(self): 96 def testGetSVNStatus(self):
67 def RunShellMock(command): 97 def RunShellMock(command):
68 return r"""<?xml version="1.0"?> 98 return r"""<?xml version="1.0"?>
69 <status> 99 <status>
70 <target path="."> 100 <target path=".">
71 <entry path="unversionned_file.txt"> 101 <entry path="unversionned_file.txt">
72 <wc-status props="none" item="unversioned"></wc-status> 102 <wc-status props="none" item="unversioned"></wc-status>
73 </entry> 103 </entry>
74 <entry path="build\internal\essential.vsprops"> 104 <entry path="build\internal\essential.vsprops">
75 <wc-status props="normal" item="modified" revision="14628"> 105 <wc-status props="normal" item="modified" revision="14628">
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 <status> 149 <status>
120 <target 150 <target
121 path="perf"> 151 path="perf">
122 </target> 152 </target>
123 </status> 153 </status>
124 """ 154 """
125 gcl.RunShell = RunShellMock 155 gcl.RunShell = RunShellMock
126 info = gcl.GetSVNStatus(None) 156 info = gcl.GetSVNStatus(None)
127 self.assertEquals(info, []) 157 self.assertEquals(info, [])
128 158
129 def testHelp(self):
130 stdout = sys.stdout
131 dummy = StringIO.StringIO()
132 sys.stdout = dummy
133 gcl.Help()
134 sys.stdout = stdout
135 self.assertEquals(len(dummy.getvalue()), 1718)
136
137 def testGetRepositoryRoot(self):
138 try:
139 gcl.GetRepositoryRoot()
140 except Exception,e:
141 self.assertEquals(e.args[0], "gcl run outside of repository")
142
143
144 class ChangeInfoUnittest(GclTestsBase):
145 def testChangeInfoMembers(self):
146 members = [
147 'CloseIssue', 'Delete', 'FileList', 'MissingTests', 'Save',
148 'UpdateRietveldDescription', 'description', 'files', 'issue', 'name',
149 'patch'
150 ]
151 # If this test fails, you should add the relevant test.
152 self.compareMembers(gcl.ChangeInfo(), members)
153
154 def testChangeInfoBase(self):
155 files = [('M', 'foo'), ('A', 'bar')]
156 o = gcl.ChangeInfo('name2', 'issue2', 'description2', files)
157 self.assertEquals(o.name, 'name2')
158 self.assertEquals(o.issue, 'issue2')
159 self.assertEquals(o.description, 'description2')
160 self.assertEquals(o.files, files)
161 self.assertEquals(o.patch, None)
162 self.assertEquals(o.FileList(), ['foo', 'bar'])
163
164 159
165 if __name__ == '__main__': 160 if __name__ == '__main__':
166 unittest.main() 161 unittest.main()
OLDNEW
« no previous file with comments | « gclient.py ('k') | tests/gclient_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698