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

Side by Side Diff: cros_mark_as_stable_unittest.py

Issue 6286040: Remove buildbot code that has been added to chromite. (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: Verify Created 9 years, 10 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 | « cros_mark_as_stable_blacklist ('k') | gflags.py » ('j') | 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
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Unit tests for cros_mark_as_stable.py."""
8
9 import fileinput
10 import mox
11 import os
12 import sys
13 import unittest
14
15 import cros_mark_as_stable
16
17 class NonClassTests(mox.MoxTestBase):
18 def setUp(self):
19 mox.MoxTestBase.setUp(self)
20 self.mox.StubOutWithMock(cros_mark_as_stable, '_SimpleRunCommand')
21 self._branch = 'test_branch'
22 self._tracking_branch = 'cros/test'
23
24 def testPushChange(self):
25 git_log = 'Marking test_one as stable\nMarking test_two as stable\n'
26 fake_description = 'Marking set of ebuilds as stable\n\n%s' % git_log
27 self.mox.StubOutWithMock(cros_mark_as_stable, '_DoWeHaveLocalCommits')
28 self.mox.StubOutWithMock(cros_mark_as_stable.GitBranch, 'CreateBranch')
29 self.mox.StubOutWithMock(cros_mark_as_stable.GitBranch, 'Exists')
30
31 cros_mark_as_stable._DoWeHaveLocalCommits(
32 self._branch, self._tracking_branch).AndReturn(True)
33 cros_mark_as_stable.GitBranch.CreateBranch()
34 cros_mark_as_stable.GitBranch.Exists().AndReturn(True)
35 cros_mark_as_stable._SimpleRunCommand('git log --format=format:%s%n%n%b ' +
36 self._tracking_branch + '..').AndReturn(git_log)
37 cros_mark_as_stable._SimpleRunCommand('repo sync .')
38 cros_mark_as_stable._SimpleRunCommand('git merge --squash %s' %
39 self._branch)
40 cros_mark_as_stable._SimpleRunCommand('git commit -m "%s"' %
41 fake_description)
42 cros_mark_as_stable._SimpleRunCommand('git config push.default tracking')
43 cros_mark_as_stable._SimpleRunCommand('git push')
44 self.mox.ReplayAll()
45 cros_mark_as_stable.PushChange(self._branch, self._tracking_branch)
46 self.mox.VerifyAll()
47
48
49 class GitBranchTest(mox.MoxTestBase):
50
51 def setUp(self):
52 mox.MoxTestBase.setUp(self)
53 # Always stub RunCommmand out as we use it in every method.
54 self.mox.StubOutWithMock(cros_mark_as_stable, '_SimpleRunCommand')
55 self._branch = self.mox.CreateMock(cros_mark_as_stable.GitBranch)
56 self._branch_name = 'test_branch'
57 self._branch.branch_name = self._branch_name
58 self._tracking_branch = 'cros/test'
59 self._branch.tracking_branch = self._tracking_branch
60
61 def testCheckoutCreate(self):
62 # Test init with no previous branch existing.
63 self._branch.Exists().AndReturn(False)
64 cros_mark_as_stable._SimpleRunCommand(
65 'git checkout -b %s %s' % (self._branch_name, self._tracking_branch))
66 self.mox.ReplayAll()
67 cros_mark_as_stable.GitBranch.Checkout(self._branch)
68 self.mox.VerifyAll()
69
70 def testCheckoutNoCreate(self):
71 # Test init with previous branch existing.
72 self._branch.Exists().AndReturn(True)
73 cros_mark_as_stable._SimpleRunCommand('git checkout %s' % (
74 self._branch_name))
75 self.mox.ReplayAll()
76 cros_mark_as_stable.GitBranch.Checkout(self._branch)
77 self.mox.VerifyAll()
78
79 def testDelete(self):
80 self.mox.StubOutWithMock(cros_mark_as_stable.GitBranch, 'Checkout')
81 branch = cros_mark_as_stable.GitBranch(self._branch_name,
82 self._tracking_branch)
83 cros_mark_as_stable.GitBranch.Checkout(mox.IgnoreArg())
84 cros_mark_as_stable._SimpleRunCommand('git branch -D ' + self._branch_name)
85 self.mox.ReplayAll()
86 branch.Delete()
87 self.mox.VerifyAll()
88
89 def testExists(self):
90 branch = cros_mark_as_stable.GitBranch(self._branch_name,
91 self._tracking_branch)
92 # Test if branch exists that is created
93 cros_mark_as_stable._SimpleRunCommand('git branch').AndReturn(
94 '%s' % self._branch_name)
95 self.mox.ReplayAll()
96 self.assertTrue(branch.Exists())
97 self.mox.VerifyAll()
98
99
100 class EBuildTest(mox.MoxTestBase):
101
102 def setUp(self):
103 mox.MoxTestBase.setUp(self)
104
105 def testParseEBuildPath(self):
106 # Test with ebuild with revision number.
107 fake_ebuild_path = '/path/to/test_package/test_package-0.0.1-r1.ebuild'
108 self.mox.StubOutWithMock(fileinput, 'input')
109 fileinput.input(fake_ebuild_path).AndReturn('')
110 self.mox.ReplayAll()
111 fake_ebuild = cros_mark_as_stable.EBuild(fake_ebuild_path)
112 self.mox.VerifyAll()
113 self.assertEquals(fake_ebuild.version_no_rev, '0.0.1')
114 self.assertEquals(fake_ebuild.ebuild_path_no_revision,
115 '/path/to/test_package/test_package-0.0.1')
116 self.assertEquals(fake_ebuild.ebuild_path_no_version,
117 '/path/to/test_package/test_package')
118 self.assertEquals(fake_ebuild.current_revision, 1)
119
120 def testParseEBuildPathNoRevisionNumber(self):
121 # Test with ebuild without revision number.
122 fake_ebuild_path = '/path/to/test_package/test_package-9999.ebuild'
123 self.mox.StubOutWithMock(fileinput, 'input')
124 fileinput.input(fake_ebuild_path).AndReturn('')
125 self.mox.ReplayAll()
126 fake_ebuild = cros_mark_as_stable.EBuild(fake_ebuild_path)
127 self.mox.VerifyAll()
128
129 self.assertEquals(fake_ebuild.version_no_rev, '9999')
130 self.assertEquals(fake_ebuild.ebuild_path_no_revision,
131 '/path/to/test_package/test_package-9999')
132 self.assertEquals(fake_ebuild.ebuild_path_no_version,
133 '/path/to/test_package/test_package')
134 self.assertEquals(fake_ebuild.current_revision, 0)
135
136
137 class EBuildStableMarkerTest(mox.MoxTestBase):
138
139 def setUp(self):
140 mox.MoxTestBase.setUp(self)
141 self.mox.StubOutWithMock(cros_mark_as_stable, '_SimpleRunCommand')
142 self.mox.StubOutWithMock(cros_mark_as_stable, 'RunCommand')
143 self.mox.StubOutWithMock(os, 'unlink')
144 self.m_ebuild = self.mox.CreateMock(cros_mark_as_stable.EBuild)
145 self.m_ebuild.is_stable = True
146 self.m_ebuild.package = 'test_package/test_package'
147 self.m_ebuild.version_no_rev = '0.0.1'
148 self.m_ebuild.current_revision = 1
149 self.m_ebuild.ebuild_path_no_revision = '/path/test_package-0.0.1'
150 self.m_ebuild.ebuild_path_no_version = '/path/test_package'
151 self.m_ebuild.ebuild_path = '/path/test_package-0.0.1-r1.ebuild'
152 self.revved_ebuild_path = '/path/test_package-0.0.1-r2.ebuild'
153 self.unstable_ebuild_path = '/path/test_package-9999.ebuild'
154
155 def testRevWorkOnEBuild(self):
156 self.mox.StubOutWithMock(cros_mark_as_stable.fileinput, 'input')
157 self.mox.StubOutWithMock(cros_mark_as_stable.os.path, 'exists')
158 self.mox.StubOutWithMock(cros_mark_as_stable.shutil, 'copyfile')
159 m_file = self.mox.CreateMock(file)
160
161 # Prepare mock fileinput. This tests to make sure both the commit id
162 # and keywords are changed correctly.
163 mock_file = ['EAPI=2', 'CROS_WORKON_COMMIT=old_id',
164 'KEYWORDS=\"~x86 ~arm\"', 'src_unpack(){}']
165
166 ebuild_9999 = self.m_ebuild.ebuild_path_no_version + '-9999.ebuild'
167 cros_mark_as_stable.os.path.exists(ebuild_9999).AndReturn(True)
168 cros_mark_as_stable.shutil.copyfile(ebuild_9999, self.revved_ebuild_path)
169 cros_mark_as_stable.fileinput.input(self.revved_ebuild_path,
170 inplace=1).AndReturn(mock_file)
171 m_file.write('EAPI=2')
172 m_file.write('CROS_WORKON_COMMIT="my_id"\n')
173 m_file.write('KEYWORDS="x86 arm"')
174 m_file.write('src_unpack(){}')
175 diff_cmd = ['diff', '-Bu', self.m_ebuild.ebuild_path,
176 self.revved_ebuild_path]
177 cros_mark_as_stable.RunCommand(diff_cmd, exit_code=True,
178 print_cmd=False, redirect_stderr=True,
179 redirect_stdout=True).AndReturn(1)
180 cros_mark_as_stable._SimpleRunCommand('git add ' + self.revved_ebuild_path)
181 cros_mark_as_stable._SimpleRunCommand('git rm ' + self.m_ebuild.ebuild_path)
182
183 self.mox.ReplayAll()
184 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild)
185 result = marker.RevWorkOnEBuild('my_id', redirect_file=m_file)
186 self.mox.VerifyAll()
187 self.assertEqual(result, 'test_package/test_package-0.0.1-r2')
188
189 def testRevUnchangedEBuild(self):
190 self.mox.StubOutWithMock(cros_mark_as_stable.fileinput, 'input')
191 self.mox.StubOutWithMock(cros_mark_as_stable.os.path, 'exists')
192 self.mox.StubOutWithMock(cros_mark_as_stable.shutil, 'copyfile')
193 m_file = self.mox.CreateMock(file)
194
195 # Prepare mock fileinput. This tests to make sure both the commit id
196 # and keywords are changed correctly.
197 mock_file = ['EAPI=2', 'CROS_WORKON_COMMIT=old_id',
198 'KEYWORDS=\"~x86 ~arm\"', 'src_unpack(){}']
199
200 ebuild_9999 = self.m_ebuild.ebuild_path_no_version + '-9999.ebuild'
201 cros_mark_as_stable.os.path.exists(ebuild_9999).AndReturn(True)
202 cros_mark_as_stable.shutil.copyfile(ebuild_9999, self.revved_ebuild_path)
203 cros_mark_as_stable.fileinput.input(self.revved_ebuild_path,
204 inplace=1).AndReturn(mock_file)
205 m_file.write('EAPI=2')
206 m_file.write('CROS_WORKON_COMMIT="my_id"\n')
207 m_file.write('KEYWORDS="x86 arm"')
208 m_file.write('src_unpack(){}')
209 diff_cmd = ['diff', '-Bu', self.m_ebuild.ebuild_path,
210 self.revved_ebuild_path]
211 cros_mark_as_stable.RunCommand(diff_cmd, exit_code=True,
212 print_cmd=False, redirect_stderr=True,
213 redirect_stdout=True).AndReturn(0)
214 cros_mark_as_stable.os.unlink(self.revved_ebuild_path)
215
216 self.mox.ReplayAll()
217 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild)
218 result = marker.RevWorkOnEBuild('my_id', redirect_file=m_file)
219 self.mox.VerifyAll()
220 self.assertEqual(result, None)
221
222 def testRevMissingEBuild(self):
223 self.mox.StubOutWithMock(cros_mark_as_stable.fileinput, 'input')
224 self.mox.StubOutWithMock(cros_mark_as_stable.os.path, 'exists')
225 self.mox.StubOutWithMock(cros_mark_as_stable.shutil, 'copyfile')
226 self.mox.StubOutWithMock(cros_mark_as_stable, 'Die')
227 m_file = self.mox.CreateMock(file)
228
229 revved_ebuild_path = self.m_ebuild.ebuild_path
230 self.m_ebuild.ebuild_path = self.unstable_ebuild_path
231 self.m_ebuild.is_stable = False
232 self.m_ebuild.current_revision = 0
233
234 # Prepare mock fileinput. This tests to make sure both the commit id
235 # and keywords are changed correctly.
236 mock_file = ['EAPI=2', 'CROS_WORKON_COMMIT=old_id',
237 'KEYWORDS=\"~x86 ~arm\"', 'src_unpack(){}']
238
239 ebuild_9999 = self.m_ebuild.ebuild_path_no_version + '-9999.ebuild'
240 cros_mark_as_stable.os.path.exists(ebuild_9999).AndReturn(False)
241 cros_mark_as_stable.Die("Missing unstable ebuild: %s" % ebuild_9999)
242 cros_mark_as_stable.shutil.copyfile(ebuild_9999, revved_ebuild_path)
243 cros_mark_as_stable.fileinput.input(revved_ebuild_path,
244 inplace=1).AndReturn(mock_file)
245 m_file.write('EAPI=2')
246 m_file.write('CROS_WORKON_COMMIT="my_id"\n')
247 m_file.write('KEYWORDS="x86 arm"')
248 m_file.write('src_unpack(){}')
249 diff_cmd = ['diff', '-Bu', self.unstable_ebuild_path, revved_ebuild_path]
250 cros_mark_as_stable.RunCommand(diff_cmd, exit_code=True,
251 print_cmd=False, redirect_stderr=True,
252 redirect_stdout=True).AndReturn(1)
253 cros_mark_as_stable._SimpleRunCommand('git add ' + revved_ebuild_path)
254
255 self.mox.ReplayAll()
256 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild)
257 result = marker.RevWorkOnEBuild('my_id', redirect_file=m_file)
258 self.mox.VerifyAll()
259 self.assertEqual(result, 'test_package/test_package-0.0.1-r1')
260
261
262 def testCommitChange(self):
263 mock_message = 'Commit me'
264 cros_mark_as_stable._SimpleRunCommand(
265 'git commit -am "%s"' % mock_message)
266 self.mox.ReplayAll()
267 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild)
268 marker.CommitChange(mock_message)
269 self.mox.VerifyAll()
270
271
272 class _Package(object):
273 def __init__(self, package):
274 self.package = package
275
276
277 class BuildEBuildDictionaryTest(mox.MoxTestBase):
278
279 def setUp(self):
280 mox.MoxTestBase.setUp(self)
281 self.mox.StubOutWithMock(cros_mark_as_stable.os, 'walk')
282 self.mox.StubOutWithMock(cros_mark_as_stable, 'RunCommand')
283 self.package = 'chromeos-base/test_package'
284 self.root = '/overlay/chromeos-base/test_package'
285 self.package_path = self.root + '/test_package-0.0.1.ebuild'
286 paths = [[self.root, [], []]]
287 cros_mark_as_stable.os.walk("/overlay").AndReturn(paths)
288 self.mox.StubOutWithMock(cros_mark_as_stable, '_FindUprevCandidates')
289
290
291 def testWantedPackage(self):
292 overlays = {"/overlay": []}
293 package = _Package(self.package)
294 cros_mark_as_stable._FindUprevCandidates([]).AndReturn(package)
295 self.mox.ReplayAll()
296 cros_mark_as_stable._BuildEBuildDictionary(overlays, False, [self.package])
297 self.mox.VerifyAll()
298 self.assertEquals(len(overlays), 1)
299 self.assertEquals(overlays["/overlay"], [package])
300
301 def testUnwantedPackage(self):
302 overlays = {"/overlay": []}
303 package = _Package(self.package)
304 cros_mark_as_stable._FindUprevCandidates([]).AndReturn(package)
305 self.mox.ReplayAll()
306 cros_mark_as_stable._BuildEBuildDictionary(overlays, False, [])
307 self.assertEquals(len(overlays), 1)
308 self.assertEquals(overlays["/overlay"], [])
309 self.mox.VerifyAll()
310
311
312 if __name__ == '__main__':
313 unittest.main()
OLDNEW
« no previous file with comments | « cros_mark_as_stable_blacklist ('k') | gflags.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698