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

Side by Side Diff: tests/scm_unittest.py

Issue 393001: Split scm-specific functions out of gclient_scm.py to scm.py. (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/gclient_utils_test.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
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
4 # found in the LICENSE file.
5
6 """Unit tests for scm.py."""
7
8 from gclient_test import BaseTestCase
9 import scm
10 from super_mox import mox
11
12
13 class BaseSCMTestCase(BaseTestCase):
14 def setUp(self):
15 BaseTestCase.setUp(self)
16 self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCall')
17 self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCallAndFilter')
18
19
20 class RootTestCase(BaseSCMTestCase):
21 def testMembersChanged(self):
22 self.mox.ReplayAll()
23 members = [
24 'CaptureGit', 'CaptureGitStatus', 'GIT_COMMAND',
25 'CaptureSVN', 'CaptureSVNHeadRevision', 'CaptureSVNInfo',
26 'CaptureSVNStatus', 'RunSVN', 'RunSVNAndFilterOutput',
27 'RunSVNAndGetFileList', 'SVN_COMMAND',
28 'gclient_utils', 'os', 're', 'subprocess', 'sys', 'xml',
29 ]
30 # If this test fails, you should add the relevant test.
31 self.compareMembers(scm, members)
32
33
34 class GitWrapperTestCase(BaseSCMTestCase):
35 sample_git_import = """blob
36 mark :1
37 data 6
38 Hello
39
40 blob
41 mark :2
42 data 4
43 Bye
44
45 reset refs/heads/master
46 commit refs/heads/master
47 mark :3
48 author Bob <bob@example.com> 1253744361 -0700
49 committer Bob <bob@example.com> 1253744361 -0700
50 data 8
51 A and B
52 M 100644 :1 a
53 M 100644 :2 b
54
55 blob
56 mark :4
57 data 10
58 Hello
59 You
60
61 blob
62 mark :5
63 data 8
64 Bye
65 You
66
67 commit refs/heads/origin
68 mark :6
69 author Alice <alice@example.com> 1253744424 -0700
70 committer Alice <alice@example.com> 1253744424 -0700
71 data 13
72 Personalized
73 from :3
74 M 100644 :4 a
75 M 100644 :5 b
76
77 reset refs/heads/master
78 from :3
79 """
80
81 def CreateGitRepo(self, git_import, path):
82 try:
83 subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,
84 stderr=subprocess.STDOUT, cwd=path).communicate()
85 except WindowsError:
86 # git is not available, skip this test.
87 return False
88 subprocess.Popen(['git', 'fast-import'], stdin=subprocess.PIPE,
89 stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
90 cwd=path).communicate(input=git_import)
91 subprocess.Popen(['git', 'checkout'], stdout=subprocess.PIPE,
92 stderr=subprocess.STDOUT, cwd=path).communicate()
93 return True
94
95 def setUp(self):
96 BaseSCMTestCase.setUp(self)
97 self.args = self.Args()
98 self.url = 'git://foo'
99 self.root_dir = tempfile.mkdtemp()
100 self.relpath = '.'
101 self.base_path = os.path.join(self.root_dir, self.relpath)
102 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
103
104 def tearDown(self):
105 shutil.rmtree(self.root_dir)
106 gclient_test.BaseTestCase.tearDown(self)
107
108
109 class SVNTestCase(BaseSCMTestCase):
110 def setUp(self):
111 BaseSCMTestCase.setUp(self)
112 self.root_dir = self.Dir()
113 self.args = self.Args()
114 self.url = self.Url()
115 self.relpath = 'asf'
116
117 def testGetSVNFileInfo(self):
118 xml_text = r"""<?xml version="1.0"?>
119 <info>
120 <entry kind="file" path="%s" revision="14628">
121 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url>
122 <repository><root>http://src.chromium.org/svn</root></repository>
123 <wc-info>
124 <schedule>add</schedule>
125 <depth>infinity</depth>
126 <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from- url>
127 <copy-from-rev>14628</copy-from-rev>
128 <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum>
129 </wc-info>
130 </entry>
131 </info>
132 """ % self.url
133 self.mox.StubOutWithMock(scm, 'CaptureSVN')
134 scm.CaptureSVN(['info', '--xml', self.url], '.', True).AndReturn(xml_text)
135 expected = {
136 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d',
137 'UUID': None,
138 'Repository Root': 'http://src.chromium.org/svn',
139 'Schedule': 'add',
140 'Copied From URL':
141 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS',
142 'Copied From Rev': '14628',
143 'Path': self.url,
144 'Revision': 14628,
145 'Node Kind': 'file',
146 }
147 self.mox.ReplayAll()
148 file_info = scm.CaptureSVNInfo(self.url, '.', True)
149 self.assertEquals(sorted(file_info.items()), sorted(expected.items()))
150
151 def testCaptureSvnInfo(self):
152 xml_text = """<?xml version="1.0"?>
153 <info>
154 <entry
155 kind="dir"
156 path="."
157 revision="35">
158 <url>%s</url>
159 <repository>
160 <root>%s</root>
161 <uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid>
162 </repository>
163 <wc-info>
164 <schedule>normal</schedule>
165 <depth>infinity</depth>
166 </wc-info>
167 <commit
168 revision="35">
169 <author>maruel</author>
170 <date>2008-12-04T20:12:19.685120Z</date>
171 </commit>
172 </entry>
173 </info>
174 """ % (self.url, self.root_dir)
175 self.mox.StubOutWithMock(scm, 'CaptureSVN')
176 scm.CaptureSVN(['info', '--xml', self.url], '.', True).AndReturn(xml_text)
177 self.mox.ReplayAll()
178 file_info = scm.CaptureSVNInfo(self.url, '.', True)
179 expected = {
180 'URL': self.url,
181 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb',
182 'Revision': 35,
183 'Repository Root': self.root_dir,
184 'Schedule': 'normal',
185 'Copied From URL': None,
186 'Copied From Rev': None,
187 'Path': '.',
188 'Node Kind': 'dir',
189 }
190 self.assertEqual(file_info, expected)
191
192 def testCaptureSVNStatus(self):
193 text =r"""<?xml version="1.0"?>
194 <status>
195 <target path=".">
196 <entry path="unversionned_file.txt">
197 <wc-status props="none" item="unversioned"></wc-status>
198 </entry>
199 <entry path="build\internal\essential.vsprops">
200 <wc-status props="normal" item="modified" revision="14628">
201 <commit revision="13818">
202 <author>ajwong@chromium.org</author>
203 <date>2009-04-16T00:42:06.872358Z</date>
204 </commit>
205 </wc-status>
206 </entry>
207 <entry path="chrome\app\d">
208 <wc-status props="none" copied="true" tree-conflicted="true" item="added">
209 </wc-status>
210 </entry>
211 <entry path="chrome\app\DEPS">
212 <wc-status props="modified" item="modified" revision="14628">
213 <commit revision="1279">
214 <author>brettw@google.com</author>
215 <date>2008-08-23T17:16:42.090152Z</date>
216 </commit>
217 </wc-status>
218 </entry>
219 <entry path="scripts\master\factory\gclient_factory.py">
220 <wc-status props="normal" item="conflicted" revision="14725">
221 <commit revision="14633">
222 <author>nsylvain@chromium.org</author>
223 <date>2009-04-27T19:37:17.977400Z</date>
224 </commit>
225 </wc-status>
226 </entry>
227 </target>
228 </status>
229 """
230 proc = self.mox.CreateMockAnything()
231 scm.subprocess.Popen(['svn', 'status', '--xml', '.'],
232 cwd=None,
233 shell=scm.sys.platform.startswith('win'),
234 stderr=None,
235 stdout=scm.subprocess.PIPE).AndReturn(proc)
236 proc.communicate().AndReturn((text, 0))
237
238 self.mox.ReplayAll()
239 info = scm.CaptureSVNStatus('.')
240 expected = [
241 ('? ', 'unversionned_file.txt'),
242 ('M ', 'build\\internal\\essential.vsprops'),
243 ('A + ', 'chrome\\app\\d'),
244 ('MM ', 'chrome\\app\\DEPS'),
245 ('C ', 'scripts\\master\\factory\\gclient_factory.py'),
246 ]
247 self.assertEquals(sorted(info), sorted(expected))
248
249 def testRunSVN(self):
250 param2 = 'bleh'
251 scm.gclient_utils.SubprocessCall(['svn', 'foo', 'bar'],
252 param2).AndReturn(None)
253 self.mox.ReplayAll()
254 scm.RunSVN(['foo', 'bar'], param2)
255
256 def testCaptureSVNStatusEmpty(self):
257 text = r"""<?xml version="1.0"?>
258 <status>
259 <target
260 path="perf">
261 </target>
262 </status>"""
263 proc = self.mox.CreateMockAnything()
264 scm.subprocess.Popen(['svn', 'status', '--xml'],
265 cwd=None,
266 shell=scm.sys.platform.startswith('win'),
267 stderr=None,
268 stdout=scm.subprocess.PIPE).AndReturn(proc)
269 proc.communicate().AndReturn((text, 0))
270 self.mox.ReplayAll()
271 info = scm.CaptureSVNStatus(None)
272 self.assertEquals(info, [])
273
274
275 if __name__ == '__main__':
276 import unittest
277 unittest.main()
278
279 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « tests/gclient_utils_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698