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

Side by Side Diff: tests/gcl_unittest.py

Issue 113218: Starts reusing functions in gclient.py from gcl.py. (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 | « gcl.py ('k') | tests/trychange_unittest.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
8 import os 9 import os
10 import sys
9 import unittest 11 import unittest
10 12
11 # Local imports 13 # Local imports
12 import gcl 14 import gcl
13 15
14 16
15 class GclTestsBase(unittest.TestCase): 17 class GclTestsBase(unittest.TestCase):
16 """Setups and tear downs the mocks but doesn't test anything as-is.""" 18 """Setups and tear downs the mocks but doesn't test anything as-is."""
17 def setUp(self): 19 def setUp(self):
18 def RunShellMock(filename): 20 def RunShellMock(filename):
(...skipping 20 matching lines...) Expand all
39 41
40 class GclUnittest(GclTestsBase): 42 class GclUnittest(GclTestsBase):
41 """General gcl.py tests.""" 43 """General gcl.py tests."""
42 def testMembersChanged(self): 44 def testMembersChanged(self):
43 members = [ 45 members = [
44 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', 'CPP_EXTENSIONS', 46 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', 'CPP_EXTENSIONS',
45 'Change', 'ChangeInfo', 'Changes', 'Commit', 'DoPresubmitChecks', 47 'Change', 'ChangeInfo', 'Changes', 'Commit', 'DoPresubmitChecks',
46 'ErrorExit', 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 48 'ErrorExit', 'GenerateChangeName', 'GenerateDiff', 'GetCLs',
47 'GetChangelistInfoFile', 'GetCodeReviewSetting', 'GetEditor', 49 'GetChangelistInfoFile', 'GetCodeReviewSetting', 'GetEditor',
48 'GetFilesNotInCL', 'GetInfoDir', 'GetIssueDescription', 50 'GetFilesNotInCL', 'GetInfoDir', 'GetIssueDescription',
49 'GetModifiedFiles', 'GetNamedNodeText', 'GetNodeNamedAttributeText', 51 'GetModifiedFiles', 'GetRepositoryRoot', 'GetSVNStatus',
50 'GetRepositoryRoot', 'GetSVNFileInfo', 'GetSVNStatus',
51 'GetSVNFileProperty', 'Help', 'IGNORE_PATHS', 'IsSVNMoved', 'IsTreeOpen', 52 'GetSVNFileProperty', 'Help', 'IGNORE_PATHS', 'IsSVNMoved', 'IsTreeOpen',
52 'Lint', 'LoadChangelistInfo', 'LoadChangelistInfoForMultiple', 53 'Lint', 'LoadChangelistInfo', 'LoadChangelistInfoForMultiple',
53 'MISSING_TEST_MSG', 'Opened', 'ParseXML', 'PresubmitCL', 'ReadFile', 54 'MISSING_TEST_MSG', 'Opened', 'PresubmitCL', 'ReadFile',
54 'RunShell', 55 'RunShell',
55 'RunShellWithReturnCode', 'SEPARATOR', 'SendToRietveld', 'TryChange', 56 'RunShellWithReturnCode', 'SEPARATOR', 'SendToRietveld', 'TryChange',
56 'UnknownFiles', 'UploadCL', 'Warn', 'WriteFile', 'gcl_info_dir', 57 'UnknownFiles', 'UploadCL', 'Warn', 'WriteFile', 'gclient',
57 'getpass', 'main', 'os', 'random', 're', 'read_gcl_info', 58 'gcl_info_dir', 'getpass', 'main', 'os', 'random', 're', 'read_gcl_info',
58 'repository_root', 'string', 'subprocess', 'sys', 'tempfile', 'upload', 59 'repository_root', 'string', 'subprocess', 'sys', 'tempfile', 'upload',
59 'urllib2', 'use_shell', 'xml', 60 'urllib2', 'use_shell', 'xml',
60 61
61 ] 62 ]
62 # If this test fails, you should add the relevant test. 63 # If this test fails, you should add the relevant test.
63 self.compareMembers(gcl, members) 64 self.compareMembers(gcl, members)
64 65
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
96 def testGetSVNStatus(self): 66 def testGetSVNStatus(self):
97 def RunShellMock(command): 67 def RunShellMock(command):
98 return r"""<?xml version="1.0"?> 68 return r"""<?xml version="1.0"?>
99 <status> 69 <status>
100 <target path="."> 70 <target path=".">
101 <entry path="unversionned_file.txt"> 71 <entry path="unversionned_file.txt">
102 <wc-status props="none" item="unversioned"></wc-status> 72 <wc-status props="none" item="unversioned"></wc-status>
103 </entry> 73 </entry>
104 <entry path="build\internal\essential.vsprops"> 74 <entry path="build\internal\essential.vsprops">
105 <wc-status props="normal" item="modified" revision="14628"> 75 <wc-status props="normal" item="modified" revision="14628">
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 <status> 119 <status>
150 <target 120 <target
151 path="perf"> 121 path="perf">
152 </target> 122 </target>
153 </status> 123 </status>
154 """ 124 """
155 gcl.RunShell = RunShellMock 125 gcl.RunShell = RunShellMock
156 info = gcl.GetSVNStatus(None) 126 info = gcl.GetSVNStatus(None)
157 self.assertEquals(info, []) 127 self.assertEquals(info, [])
158 128
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
159 164
160 if __name__ == '__main__': 165 if __name__ == '__main__':
161 unittest.main() 166 unittest.main()
OLDNEW
« no previous file with comments | « gcl.py ('k') | tests/trychange_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698