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

Side by Side Diff: tests/scm_unittest.py

Issue 399009: Reapply 32057, 32058, 32059, 32062 and fixes problems introduced by these changes. (Closed)
Patch Set: Created 11 years, 1 month 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
« no previous file with comments | « tests/revert_unittest.py ('k') | tests/super_mox.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) 2006-2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-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 scm.py.""" 6 """Unit tests for scm.py."""
7 7
8 import shutil
9 import tempfile
10
8 from gclient_test import BaseTestCase 11 from gclient_test import BaseTestCase
9 import scm 12 import scm
10 from super_mox import mox 13 from super_mox import mox, SuperMoxBaseTestBase
11 14
12 15
13 class BaseSCMTestCase(BaseTestCase): 16 class BaseSCMTestCase(BaseTestCase):
14 def setUp(self): 17 def setUp(self):
15 BaseTestCase.setUp(self) 18 BaseTestCase.setUp(self)
16 self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCall') 19 self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCall')
17 self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCallAndFilter') 20 self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCallAndFilter')
18 21
19 22
20 class RootTestCase(BaseSCMTestCase): 23 class RootTestCase(BaseSCMTestCase):
21 def testMembersChanged(self): 24 def testMembersChanged(self):
22 self.mox.ReplayAll() 25 self.mox.ReplayAll()
23 members = [ 26 members = [
24 'CaptureGit', 'CaptureGitStatus', 'GIT_COMMAND', 27 'GIT', 'SVN',
25 'CaptureSVN', 'CaptureSVNHeadRevision', 'CaptureSVNInfo', 28 'gclient_utils', 'os', 're', 'subprocess', 'sys', 'tempfile', 'xml',
26 'CaptureSVNStatus', 'RunSVN', 'RunSVNAndFilterOutput',
27 'RunSVNAndGetFileList', 'SVN_COMMAND',
28 'gclient_utils', 'os', 're', 'subprocess', 'sys', 'xml',
29 ] 29 ]
30 # If this test fails, you should add the relevant test. 30 # If this test fails, you should add the relevant test.
31 self.compareMembers(scm, members) 31 self.compareMembers(scm, members)
32 32
33 33
34 class GitWrapperTestCase(BaseSCMTestCase): 34 class GitWrapperTestCase(SuperMoxBaseTestBase):
35 sample_git_import = """blob 35 sample_git_import = """blob
36 mark :1 36 mark :1
37 data 6 37 data 6
38 Hello 38 Hello
39 39
40 blob 40 blob
41 mark :2 41 mark :2
42 data 4 42 data 4
43 Bye 43 Bye
44 44
(...skipping 28 matching lines...) Expand all
73 from :3 73 from :3
74 M 100644 :4 a 74 M 100644 :4 a
75 M 100644 :5 b 75 M 100644 :5 b
76 76
77 reset refs/heads/master 77 reset refs/heads/master
78 from :3 78 from :3
79 """ 79 """
80 80
81 def CreateGitRepo(self, git_import, path): 81 def CreateGitRepo(self, git_import, path):
82 try: 82 try:
83 subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE, 83 scm.subprocess.Popen(['git', 'init'],
84 stderr=subprocess.STDOUT, cwd=path).communicate() 84 stdout=scm.subprocess.PIPE,
85 except WindowsError: 85 stderr=scm.subprocess.STDOUT,
86 cwd=path).communicate()
87 except OSError:
86 # git is not available, skip this test. 88 # git is not available, skip this test.
87 return False 89 return False
88 subprocess.Popen(['git', 'fast-import'], stdin=subprocess.PIPE, 90 scm.subprocess.Popen(['git', 'fast-import'],
89 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 91 stdin=scm.subprocess.PIPE,
90 cwd=path).communicate(input=git_import) 92 stdout=scm.subprocess.PIPE,
91 subprocess.Popen(['git', 'checkout'], stdout=subprocess.PIPE, 93 stderr=scm.subprocess.STDOUT,
92 stderr=subprocess.STDOUT, cwd=path).communicate() 94 cwd=path).communicate(input=git_import)
95 scm.subprocess.Popen(['git', 'checkout'],
96 stdout=scm.subprocess.PIPE,
97 stderr=scm.subprocess.STDOUT,
98 cwd=path).communicate()
93 return True 99 return True
94 100
95 def setUp(self): 101 def setUp(self):
96 BaseSCMTestCase.setUp(self) 102 SuperMoxBaseTestBase.setUp(self)
97 self.args = self.Args() 103 self.args = self.Args()
98 self.url = 'git://foo' 104 self.url = 'git://foo'
99 self.root_dir = tempfile.mkdtemp() 105 self.root_dir = tempfile.mkdtemp()
100 self.relpath = '.' 106 self.relpath = '.'
101 self.base_path = os.path.join(self.root_dir, self.relpath) 107 self.base_path = scm.os.path.join(self.root_dir, self.relpath)
102 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) 108 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
103 109
104 def tearDown(self): 110 def tearDown(self):
105 shutil.rmtree(self.root_dir) 111 shutil.rmtree(self.root_dir)
106 gclient_test.BaseTestCase.tearDown(self) 112 SuperMoxBaseTestBase.tearDown(self)
113
114 def testMembersChanged(self):
115 self.mox.ReplayAll()
116 members = [
117 'COMMAND', 'Capture', 'CaptureStatus',
118 ]
119 # If this test fails, you should add the relevant test.
120 self.compareMembers(scm.GIT, members)
107 121
108 122
109 class SVNTestCase(BaseSCMTestCase): 123 class SVNTestCase(BaseSCMTestCase):
110 def setUp(self): 124 def setUp(self):
111 BaseSCMTestCase.setUp(self) 125 BaseSCMTestCase.setUp(self)
112 self.root_dir = self.Dir() 126 self.root_dir = self.Dir()
113 self.args = self.Args() 127 self.args = self.Args()
114 self.url = self.Url() 128 self.url = self.Url()
115 self.relpath = 'asf' 129 self.relpath = 'asf'
116 130
117 def testGetSVNFileInfo(self): 131 def testMembersChanged(self):
132 self.mox.ReplayAll()
133 members = [
134 'COMMAND', 'Capture', 'CaptureHeadRevision', 'CaptureInfo',
135 'CaptureStatus', 'DiffItem', 'GetFileProperty', 'IsMoved', 'Run',
136 'RunAndFilterOutput', 'RunAndGetFileList',
137 ]
138 # If this test fails, you should add the relevant test.
139 self.compareMembers(scm.SVN, members)
140
141 def testGetFileInfo(self):
118 xml_text = r"""<?xml version="1.0"?> 142 xml_text = r"""<?xml version="1.0"?>
119 <info> 143 <info>
120 <entry kind="file" path="%s" revision="14628"> 144 <entry kind="file" path="%s" revision="14628">
121 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> 145 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url>
122 <repository><root>http://src.chromium.org/svn</root></repository> 146 <repository><root>http://src.chromium.org/svn</root></repository>
123 <wc-info> 147 <wc-info>
124 <schedule>add</schedule> 148 <schedule>add</schedule>
125 <depth>infinity</depth> 149 <depth>infinity</depth>
126 <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from- url> 150 <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from- url>
127 <copy-from-rev>14628</copy-from-rev> 151 <copy-from-rev>14628</copy-from-rev>
128 <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum> 152 <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum>
129 </wc-info> 153 </wc-info>
130 </entry> 154 </entry>
131 </info> 155 </info>
132 """ % self.url 156 """ % self.url
133 self.mox.StubOutWithMock(scm, 'CaptureSVN') 157 self.mox.StubOutWithMock(scm.SVN, 'Capture')
134 scm.CaptureSVN(['info', '--xml', self.url], '.', True).AndReturn(xml_text) 158 scm.SVN.Capture(['info', '--xml', self.url], '.', True).AndReturn(xml_text)
135 expected = { 159 expected = {
136 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d', 160 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d',
137 'UUID': None, 161 'UUID': None,
138 'Repository Root': 'http://src.chromium.org/svn', 162 'Repository Root': 'http://src.chromium.org/svn',
139 'Schedule': 'add', 163 'Schedule': 'add',
140 'Copied From URL': 164 'Copied From URL':
141 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS', 165 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS',
142 'Copied From Rev': '14628', 166 'Copied From Rev': '14628',
143 'Path': self.url, 167 'Path': self.url,
144 'Revision': 14628, 168 'Revision': 14628,
145 'Node Kind': 'file', 169 'Node Kind': 'file',
146 } 170 }
147 self.mox.ReplayAll() 171 self.mox.ReplayAll()
148 file_info = scm.CaptureSVNInfo(self.url, '.', True) 172 file_info = scm.SVN.CaptureInfo(self.url, '.', True)
149 self.assertEquals(sorted(file_info.items()), sorted(expected.items())) 173 self.assertEquals(sorted(file_info.items()), sorted(expected.items()))
150 174
151 def testCaptureSvnInfo(self): 175 def testCaptureInfo(self):
152 xml_text = """<?xml version="1.0"?> 176 xml_text = """<?xml version="1.0"?>
153 <info> 177 <info>
154 <entry 178 <entry
155 kind="dir" 179 kind="dir"
156 path="." 180 path="."
157 revision="35"> 181 revision="35">
158 <url>%s</url> 182 <url>%s</url>
159 <repository> 183 <repository>
160 <root>%s</root> 184 <root>%s</root>
161 <uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid> 185 <uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid>
162 </repository> 186 </repository>
163 <wc-info> 187 <wc-info>
164 <schedule>normal</schedule> 188 <schedule>normal</schedule>
165 <depth>infinity</depth> 189 <depth>infinity</depth>
166 </wc-info> 190 </wc-info>
167 <commit 191 <commit
168 revision="35"> 192 revision="35">
169 <author>maruel</author> 193 <author>maruel</author>
170 <date>2008-12-04T20:12:19.685120Z</date> 194 <date>2008-12-04T20:12:19.685120Z</date>
171 </commit> 195 </commit>
172 </entry> 196 </entry>
173 </info> 197 </info>
174 """ % (self.url, self.root_dir) 198 """ % (self.url, self.root_dir)
175 self.mox.StubOutWithMock(scm, 'CaptureSVN') 199 self.mox.StubOutWithMock(scm.SVN, 'Capture')
176 scm.CaptureSVN(['info', '--xml', self.url], '.', True).AndReturn(xml_text) 200 scm.SVN.Capture(['info', '--xml', self.url], '.', True).AndReturn(xml_text)
177 self.mox.ReplayAll() 201 self.mox.ReplayAll()
178 file_info = scm.CaptureSVNInfo(self.url, '.', True) 202 file_info = scm.SVN.CaptureInfo(self.url, '.', True)
179 expected = { 203 expected = {
180 'URL': self.url, 204 'URL': self.url,
181 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb', 205 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb',
182 'Revision': 35, 206 'Revision': 35,
183 'Repository Root': self.root_dir, 207 'Repository Root': self.root_dir,
184 'Schedule': 'normal', 208 'Schedule': 'normal',
185 'Copied From URL': None, 209 'Copied From URL': None,
186 'Copied From Rev': None, 210 'Copied From Rev': None,
187 'Path': '.', 211 'Path': '.',
188 'Node Kind': 'dir', 212 'Node Kind': 'directory',
189 } 213 }
190 self.assertEqual(file_info, expected) 214 self.assertEqual(file_info, expected)
191 215
192 def testCaptureSVNStatus(self): 216 def testCaptureStatus(self):
193 text =r"""<?xml version="1.0"?> 217 text =r"""<?xml version="1.0"?>
194 <status> 218 <status>
195 <target path="."> 219 <target path=".">
196 <entry path="unversionned_file.txt"> 220 <entry path="unversionned_file.txt">
197 <wc-status props="none" item="unversioned"></wc-status> 221 <wc-status props="none" item="unversioned"></wc-status>
198 </entry> 222 </entry>
199 <entry path="build\internal\essential.vsprops"> 223 <entry path="build\internal\essential.vsprops">
200 <wc-status props="normal" item="modified" revision="14628"> 224 <wc-status props="normal" item="modified" revision="14628">
201 <commit revision="13818"> 225 <commit revision="13818">
202 <author>ajwong@chromium.org</author> 226 <author>ajwong@chromium.org</author>
(...skipping 26 matching lines...) Expand all
229 """ 253 """
230 proc = self.mox.CreateMockAnything() 254 proc = self.mox.CreateMockAnything()
231 scm.subprocess.Popen(['svn', 'status', '--xml', '.'], 255 scm.subprocess.Popen(['svn', 'status', '--xml', '.'],
232 cwd=None, 256 cwd=None,
233 shell=scm.sys.platform.startswith('win'), 257 shell=scm.sys.platform.startswith('win'),
234 stderr=None, 258 stderr=None,
235 stdout=scm.subprocess.PIPE).AndReturn(proc) 259 stdout=scm.subprocess.PIPE).AndReturn(proc)
236 proc.communicate().AndReturn((text, 0)) 260 proc.communicate().AndReturn((text, 0))
237 261
238 self.mox.ReplayAll() 262 self.mox.ReplayAll()
239 info = scm.CaptureSVNStatus('.') 263 info = scm.SVN.CaptureStatus('.')
240 expected = [ 264 expected = [
241 ('? ', 'unversionned_file.txt'), 265 ('? ', 'unversionned_file.txt'),
242 ('M ', 'build\\internal\\essential.vsprops'), 266 ('M ', 'build\\internal\\essential.vsprops'),
243 ('A + ', 'chrome\\app\\d'), 267 ('A + ', 'chrome\\app\\d'),
244 ('MM ', 'chrome\\app\\DEPS'), 268 ('MM ', 'chrome\\app\\DEPS'),
245 ('C ', 'scripts\\master\\factory\\gclient_factory.py'), 269 ('C ', 'scripts\\master\\factory\\gclient_factory.py'),
246 ] 270 ]
247 self.assertEquals(sorted(info), sorted(expected)) 271 self.assertEquals(sorted(info), sorted(expected))
248 272
249 def testRunSVN(self): 273 def testRun(self):
250 param2 = 'bleh' 274 param2 = 'bleh'
251 scm.gclient_utils.SubprocessCall(['svn', 'foo', 'bar'], 275 scm.gclient_utils.SubprocessCall(['svn', 'foo', 'bar'],
252 param2).AndReturn(None) 276 param2).AndReturn(None)
253 self.mox.ReplayAll() 277 self.mox.ReplayAll()
254 scm.RunSVN(['foo', 'bar'], param2) 278 scm.SVN.Run(['foo', 'bar'], param2)
255 279
256 def testCaptureSVNStatusEmpty(self): 280 def testCaptureStatusEmpty(self):
257 text = r"""<?xml version="1.0"?> 281 text = r"""<?xml version="1.0"?>
258 <status> 282 <status>
259 <target 283 <target
260 path="perf"> 284 path="perf">
261 </target> 285 </target>
262 </status>""" 286 </status>"""
263 proc = self.mox.CreateMockAnything() 287 proc = self.mox.CreateMockAnything()
264 scm.subprocess.Popen(['svn', 'status', '--xml'], 288 scm.subprocess.Popen(['svn', 'status', '--xml'],
265 cwd=None, 289 cwd=None,
266 shell=scm.sys.platform.startswith('win'), 290 shell=scm.sys.platform.startswith('win'),
267 stderr=None, 291 stderr=None,
268 stdout=scm.subprocess.PIPE).AndReturn(proc) 292 stdout=scm.subprocess.PIPE).AndReturn(proc)
269 proc.communicate().AndReturn((text, 0)) 293 proc.communicate().AndReturn((text, 0))
270 self.mox.ReplayAll() 294 self.mox.ReplayAll()
271 info = scm.CaptureSVNStatus(None) 295 info = scm.SVN.CaptureStatus(None)
272 self.assertEquals(info, []) 296 self.assertEquals(info, [])
273 297
274 298
275 if __name__ == '__main__': 299 if __name__ == '__main__':
276 import unittest 300 import unittest
277 unittest.main() 301 unittest.main()
278 302
279 # vim: ts=2:sw=2:tw=80:et: 303 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « tests/revert_unittest.py ('k') | tests/super_mox.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698