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 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 30 matching lines...) Expand all Loading... |
49 'GetModifiedFiles', 'GetNamedNodeText', 'GetNodeNamedAttributeText', | 51 'GetModifiedFiles', 'GetNamedNodeText', 'GetNodeNamedAttributeText', |
50 'GetRepositoryRoot', 'GetSVNFileInfo', 'GetSVNStatus', | 52 'GetRepositoryRoot', 'GetSVNFileInfo', 'GetSVNStatus', |
51 'GetSVNFileProperty', 'Help', 'IGNORE_PATHS', 'IsSVNMoved', 'IsTreeOpen', | 53 'GetSVNFileProperty', 'Help', 'IGNORE_PATHS', 'IsSVNMoved', 'IsTreeOpen', |
52 'Lint', 'LoadChangelistInfo', 'LoadChangelistInfoForMultiple', | 54 'Lint', 'LoadChangelistInfo', 'LoadChangelistInfoForMultiple', |
53 'MISSING_TEST_MSG', 'Opened', 'ParseXML', 'PresubmitCL', 'ReadFile', | 55 'MISSING_TEST_MSG', 'Opened', 'ParseXML', 'PresubmitCL', 'ReadFile', |
54 'RunShell', | 56 'RunShell', |
55 'RunShellWithReturnCode', 'SEPARATOR', 'SendToRietveld', 'TryChange', | 57 'RunShellWithReturnCode', 'SEPARATOR', 'SendToRietveld', 'TryChange', |
56 'UnknownFiles', 'UploadCL', 'Warn', 'WriteFile', 'gcl_info_dir', | 58 'UnknownFiles', 'UploadCL', 'Warn', 'WriteFile', 'gcl_info_dir', |
57 'getpass', 'main', 'os', 'random', 're', 'read_gcl_info', | 59 'getpass', 'main', 'os', 'random', 're', 'read_gcl_info', |
58 'repository_root', 'string', 'subprocess', 'sys', 'tempfile', 'upload', | 60 'repository_root', 'string', 'subprocess', 'sys', 'tempfile', 'upload', |
59 'urllib2', 'use_shell', 'xml', | 61 'urllib2', 'xml', |
60 | |
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 testGetSVNFileInfo(self): |
66 def RunShellMock(command): | 67 def RunShellMock(command): |
67 return r"""<?xml version="1.0"?> | 68 return r"""<?xml version="1.0"?> |
68 <info> | 69 <info> |
69 <entry kind="file" path="%s" revision="14628"> | 70 <entry kind="file" path="%s" revision="14628"> |
70 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> | 71 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> |
71 <repository><root>http://src.chromium.org/svn</root></repository> | 72 <repository><root>http://src.chromium.org/svn</root></repository> |
72 <wc-info> | 73 <wc-info> |
73 <schedule>add</schedule> | 74 <schedule>add</schedule> |
74 <depth>infinity</depth> | 75 <depth>infinity</depth> |
75 <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from-
url> | 76 <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 <copy-from-rev>14628</copy-from-rev> |
77 <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum> | 78 <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum> |
78 </wc-info> | 79 </wc-info> |
79 </entry> | 80 </entry> |
80 </info> | 81 </info> |
81 """ % command[3] | 82 """ % command[3] |
| 83 # GclTestsBase.tearDown will restore the original. |
82 gcl.RunShell = RunShellMock | 84 gcl.RunShell = RunShellMock |
83 filename = os.path.join('app', 'd') | 85 filename = os.path.join('app', 'd') |
84 info = gcl.GetSVNFileInfo(filename) | 86 info = gcl.GetSVNFileInfo(filename) |
85 expected = { | 87 expected = { |
86 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d', | 88 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d', |
87 'Repository Root': 'http://src.chromium.org/svn', | 89 'Repository Root': 'http://src.chromium.org/svn', |
88 'Schedule': 'add', | 90 'Schedule': 'add', |
89 'Copied From URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS'
, | 91 'Copied From URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS'
, |
90 'Copied From Rev': '14628', | 92 'Copied From Rev': '14628', |
91 'Path': filename, | 93 'Path': filename, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 <wc-status props="normal" item="conflicted" revision="14725"> | 127 <wc-status props="normal" item="conflicted" revision="14725"> |
126 <commit revision="14633"> | 128 <commit revision="14633"> |
127 <author>nsylvain@chromium.org</author> | 129 <author>nsylvain@chromium.org</author> |
128 <date>2009-04-27T19:37:17.977400Z</date> | 130 <date>2009-04-27T19:37:17.977400Z</date> |
129 </commit> | 131 </commit> |
130 </wc-status> | 132 </wc-status> |
131 </entry> | 133 </entry> |
132 </target> | 134 </target> |
133 </status> | 135 </status> |
134 """ | 136 """ |
| 137 # GclTestsBase.tearDown will restore the original. |
135 gcl.RunShell = RunShellMock | 138 gcl.RunShell = RunShellMock |
136 info = gcl.GetSVNStatus('.') | 139 info = gcl.GetSVNStatus('.') |
137 expected = [ | 140 expected = [ |
138 ('? ', 'unversionned_file.txt'), | 141 ('? ', 'unversionned_file.txt'), |
139 ('M ', 'build\\internal\\essential.vsprops'), | 142 ('M ', 'build\\internal\\essential.vsprops'), |
140 ('A + ', 'chrome\\app\\d'), | 143 ('A + ', 'chrome\\app\\d'), |
141 ('MM ', 'chrome\\app\\DEPS'), | 144 ('MM ', 'chrome\\app\\DEPS'), |
142 ('C ', 'scripts\\master\\factory\\gclient_factory.py'), | 145 ('C ', 'scripts\\master\\factory\\gclient_factory.py'), |
143 ] | 146 ] |
144 self.assertEquals(sorted(info), sorted(expected)) | 147 self.assertEquals(sorted(info), sorted(expected)) |
145 | 148 |
146 def testGetSVNStatusEmpty(self): | 149 def testGetSVNStatusEmpty(self): |
147 def RunShellMock(command): | 150 def RunShellMock(command): |
148 return r"""<?xml version="1.0"?> | 151 return r"""<?xml version="1.0"?> |
149 <status> | 152 <status> |
150 <target | 153 <target |
151 path="perf"> | 154 path="perf"> |
152 </target> | 155 </target> |
153 </status> | 156 </status> |
154 """ | 157 """ |
| 158 # GclTestsBase.tearDown will restore the original. |
155 gcl.RunShell = RunShellMock | 159 gcl.RunShell = RunShellMock |
156 info = gcl.GetSVNStatus(None) | 160 info = gcl.GetSVNStatus(None) |
157 self.assertEquals(info, []) | 161 self.assertEquals(info, []) |
158 | 162 |
| 163 def testHelp(self): |
| 164 old_stdout = sys.stdout |
| 165 try: |
| 166 dummy = StringIO.StringIO() |
| 167 gcl.sys.stdout = dummy |
| 168 gcl.Help() |
| 169 self.assertEquals(len(dummy.getvalue()), 1718) |
| 170 finally: |
| 171 gcl.sys.stdout = old_stdout |
| 172 |
| 173 def testGetRepositoryRoot(self): |
| 174 try: |
| 175 def RunShellMock(filename): |
| 176 return '<?xml version="1.0"?>\n<info>' |
| 177 gcl.RunShell = RunShellMock |
| 178 gcl.GetRepositoryRoot() |
| 179 except Exception,e: |
| 180 self.assertEquals(e.args[0], "gcl run outside of repository") |
| 181 pass |
| 182 |
| 183 |
| 184 class ChangeInfoUnittest(GclTestsBase): |
| 185 def testChangeInfoMembers(self): |
| 186 members = [ |
| 187 'CloseIssue', 'Delete', 'FileList', 'MissingTests', 'Save', |
| 188 'UpdateRietveldDescription', 'description', 'files', 'issue', 'name', |
| 189 'patch' |
| 190 ] |
| 191 # If this test fails, you should add the relevant test. |
| 192 self.compareMembers(gcl.ChangeInfo(), members) |
| 193 |
| 194 def testChangeInfoBase(self): |
| 195 files = [('M', 'foo'), ('A', 'bar')] |
| 196 o = gcl.ChangeInfo('name2', 'issue2', 'description2', files) |
| 197 self.assertEquals(o.name, 'name2') |
| 198 self.assertEquals(o.issue, 'issue2') |
| 199 self.assertEquals(o.description, 'description2') |
| 200 self.assertEquals(o.files, files) |
| 201 self.assertEquals(o.patch, None) |
| 202 self.assertEquals(o.FileList(), ['foo', 'bar']) |
| 203 |
159 | 204 |
160 if __name__ == '__main__': | 205 if __name__ == '__main__': |
161 unittest.main() | 206 unittest.main() |
OLD | NEW |