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

Side by Side Diff: cros_mark_as_stable_unittest.py

Issue 3516025: Update cros_mark_as_stable.py to also update the private overlay (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git
Patch Set: Fix nits Created 10 years, 2 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.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
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 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 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Unit tests for cros_mark_as_stable.py.""" 7 """Unit tests for cros_mark_as_stable.py."""
8 8
9 9
10 import mox 10 import mox
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 self.m_ebuild = self.mox.CreateMock(cros_mark_as_stable._EBuild) 150 self.m_ebuild = self.mox.CreateMock(cros_mark_as_stable._EBuild)
151 self.m_ebuild.package = 'test_package' 151 self.m_ebuild.package = 'test_package'
152 self.m_ebuild.current_revision = 1 152 self.m_ebuild.current_revision = 1
153 self.m_ebuild.ebuild_path_no_revision = '/path/test_package-0.0.1' 153 self.m_ebuild.ebuild_path_no_revision = '/path/test_package-0.0.1'
154 self.m_ebuild.ebuild_path_no_version = '/path/test_package' 154 self.m_ebuild.ebuild_path_no_version = '/path/test_package'
155 self.m_ebuild.ebuild_path = '/path/test_package-0.0.1-r1.ebuild' 155 self.m_ebuild.ebuild_path = '/path/test_package-0.0.1-r1.ebuild'
156 self.revved_ebuild_path = '/path/test_package-0.0.1-r2.ebuild' 156 self.revved_ebuild_path = '/path/test_package-0.0.1-r2.ebuild'
157 157
158 def testRevEBuild(self): 158 def testRevEBuild(self):
159 self.mox.StubOutWithMock(cros_mark_as_stable.fileinput, 'input') 159 self.mox.StubOutWithMock(cros_mark_as_stable.fileinput, 'input')
160 self.mox.StubOutWithMock(cros_mark_as_stable.os.path, 'exists')
160 self.mox.StubOutWithMock(cros_mark_as_stable.shutil, 'copyfile') 161 self.mox.StubOutWithMock(cros_mark_as_stable.shutil, 'copyfile')
161 m_file = self.mox.CreateMock(file) 162 m_file = self.mox.CreateMock(file)
162 163
163 # Prepare mock fileinput. This tests to make sure both the commit id 164 # Prepare mock fileinput. This tests to make sure both the commit id
164 # and keywords are changed correctly. 165 # and keywords are changed correctly.
165 mock_file = ['EAPI=2', 'CROS_WORKON_COMMIT=old_id', 166 mock_file = ['EAPI=2', 'CROS_WORKON_COMMIT=old_id',
166 'KEYWORDS=\"~x86 ~arm\"', 'src_unpack(){}'] 167 'KEYWORDS=\"~x86 ~arm\"', 'src_unpack(){}']
167 168
168 cros_mark_as_stable.shutil.copyfile( 169 ebuild_9999 = self.m_ebuild.ebuild_path_no_version + '-9999.ebuild'
169 self.m_ebuild.ebuild_path_no_version + '-9999.ebuild', 170 cros_mark_as_stable.os.path.exists(ebuild_9999).AndReturn(True)
170 self.revved_ebuild_path) 171 cros_mark_as_stable.shutil.copyfile(ebuild_9999, self.revved_ebuild_path)
171 cros_mark_as_stable.fileinput.input(self.revved_ebuild_path, 172 cros_mark_as_stable.fileinput.input(self.revved_ebuild_path,
172 inplace=1).AndReturn(mock_file) 173 inplace=1).AndReturn(mock_file)
173 m_file.write('EAPI=2') 174 m_file.write('EAPI=2')
175 m_file.write('CROS_WORKON_COMMIT="my_id"\n')
176 m_file.write('KEYWORDS="x86 arm"')
177 m_file.write('src_unpack(){}')
178 cros_mark_as_stable._SimpleRunCommand('git add ' + self.revved_ebuild_path)
179 cros_mark_as_stable._SimpleRunCommand('git rm ' + self.m_ebuild.ebuild_path)
180
181 self.mox.ReplayAll()
182 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild)
183 marker.RevEBuild('my_id', redirect_file=m_file)
184 self.mox.VerifyAll()
185
186 def testRevMissingEBuild(self):
187 self.mox.StubOutWithMock(cros_mark_as_stable.fileinput, 'input')
188 self.mox.StubOutWithMock(cros_mark_as_stable.os.path, 'exists')
189 self.mox.StubOutWithMock(cros_mark_as_stable.shutil, 'copyfile')
190 self.mox.StubOutWithMock(cros_mark_as_stable, 'Die')
191 m_file = self.mox.CreateMock(file)
192
193 # Prepare mock fileinput. This tests to make sure both the commit id
194 # and keywords are changed correctly.
195 mock_file = ['EAPI=2', 'CROS_WORKON_COMMIT=old_id',
196 'KEYWORDS=\"~x86 ~arm\"', 'src_unpack(){}']
197
198 ebuild_9999 = self.m_ebuild.ebuild_path_no_version + '-9999.ebuild'
199 cros_mark_as_stable.os.path.exists(ebuild_9999).AndReturn(False)
200 cros_mark_as_stable.Die("Missing 9999 ebuild: %s" % ebuild_9999)
201 cros_mark_as_stable.shutil.copyfile(ebuild_9999, self.revved_ebuild_path)
202 cros_mark_as_stable.fileinput.input(self.revved_ebuild_path,
203 inplace=1).AndReturn(mock_file)
204 m_file.write('EAPI=2')
174 m_file.write('CROS_WORKON_COMMIT="my_id"\n') 205 m_file.write('CROS_WORKON_COMMIT="my_id"\n')
175 m_file.write('KEYWORDS="x86 arm"') 206 m_file.write('KEYWORDS="x86 arm"')
176 m_file.write('src_unpack(){}') 207 m_file.write('src_unpack(){}')
177 cros_mark_as_stable._SimpleRunCommand('git add ' + self.revved_ebuild_path) 208 cros_mark_as_stable._SimpleRunCommand('git add ' + self.revved_ebuild_path)
178 cros_mark_as_stable._SimpleRunCommand('git rm ' + self.m_ebuild.ebuild_path) 209 cros_mark_as_stable._SimpleRunCommand('git rm ' + self.m_ebuild.ebuild_path)
179 210
180 self.mox.ReplayAll() 211 self.mox.ReplayAll()
181 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild) 212 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild)
182 marker.RevEBuild('my_id', redirect_file=m_file) 213 marker.RevEBuild('my_id', redirect_file=m_file)
183 self.mox.VerifyAll() 214 self.mox.VerifyAll()
184 215
185 216
186 def testCommitChange(self): 217 def testCommitChange(self):
187 mock_message = 'Commit me' 218 mock_message = 'Commit me'
188 cros_mark_as_stable._SimpleRunCommand( 219 cros_mark_as_stable._SimpleRunCommand(
189 'git commit -am "%s"' % mock_message) 220 'git commit -am "%s"' % mock_message)
190 self.mox.ReplayAll() 221 self.mox.ReplayAll()
191 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild) 222 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild)
192 marker.CommitChange(mock_message) 223 marker.CommitChange(mock_message)
193 self.mox.VerifyAll() 224 self.mox.VerifyAll()
194 225
195 def testPushChange(self): 226 def testPushChange(self):
196 #cros_mark_as_stable._SimpleRunCommand('git push') 227 #cros_mark_as_stable._SimpleRunCommand('git push')
197 #self.mox.ReplayAll() 228 #self.mox.ReplayAll()
198 #marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild) 229 #marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild)
199 #marker.PushChange() 230 #marker.PushChange()
200 #self.mox.VerifyAll() 231 #self.mox.VerifyAll()
201 pass 232 pass
202 233
234 class BuildEBuildDictionaryTest(mox.MoxTestBase):
235
236 def setUp(self):
237 mox.MoxTestBase.setUp(self)
238 self.mox.StubOutWithMock(cros_mark_as_stable, '_SimpleRunCommand')
239 self.ebuild_path = '/path/test_package-0.0.1-r1.ebuild'
240 self.package = "test_package"
241
242 def testValidPackage(self):
243 overlays = {"/path": []}
244 cmd = ('ACCEPT_KEYWORDS="x86 arm amd64" '
245 'equery-x86-generic which %s 2> /dev/null' % self.package)
246 cros_mark_as_stable._SimpleRunCommand(cmd).AndReturn(self.ebuild_path)
247 self.mox.ReplayAll()
248 cros_mark_as_stable._BuildEBuildDictionary(overlays, [self.package], [])
249 self.assertEquals(len(overlays), 1)
250 self.assertEquals(overlays["/path"][0].package, self.package)
251 self.mox.VerifyAll()
252
253 def testPackageInDifferentOverlay(self):
254 self.mox.StubOutWithMock(cros_mark_as_stable, 'Die')
255 cros_mark_as_stable.Die("No overlay found for %s" % self.ebuild_path)
256 cmd = ('ACCEPT_KEYWORDS="x86 arm amd64" '
257 'equery-x86-generic which %s 2> /dev/null' % self.package)
258 cros_mark_as_stable._SimpleRunCommand(cmd).AndReturn(self.ebuild_path)
259 overlays = {"/newpath": []}
260 self.mox.ReplayAll()
261 cros_mark_as_stable._BuildEBuildDictionary(overlays, [self.package], [])
262 self.assertEquals(len(overlays), 1)
263 self.assertEquals(overlays["/newpath"], [])
264 self.mox.VerifyAll()
265
266 def testMissingPackage(self):
267 self.mox.StubOutWithMock(cros_mark_as_stable, 'Die')
268 cros_mark_as_stable.Die("No ebuild found for %s" % self.package)
269 cmd = ('ACCEPT_KEYWORDS="x86 arm amd64" '
270 'equery-x86-generic which %s 2> /dev/null' % self.package)
271 cros_mark_as_stable._SimpleRunCommand(cmd).AndReturn("")
272 self.mox.ReplayAll()
273 overlays = {"/path": []}
274 cros_mark_as_stable._BuildEBuildDictionary(overlays, [self.package], [])
275 self.assertEquals(len(overlays), 1)
276 self.assertEquals(overlays["/path"], [])
277 self.mox.VerifyAll()
278
203 279
204 if __name__ == '__main__': 280 if __name__ == '__main__':
205 unittest.main() 281 unittest.main()
OLDNEW
« no previous file with comments | « cros_mark_as_stable.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698