OLD | NEW |
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 import fileinput | 9 import fileinput |
10 import mox | 10 import mox |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 mox.MoxTestBase.setUp(self) | 122 mox.MoxTestBase.setUp(self) |
123 | 123 |
124 def testParseEBuildPath(self): | 124 def testParseEBuildPath(self): |
125 # Test with ebuild with revision number. | 125 # Test with ebuild with revision number. |
126 fake_ebuild_path = '/path/to/test_package/test_package-0.0.1-r1.ebuild' | 126 fake_ebuild_path = '/path/to/test_package/test_package-0.0.1-r1.ebuild' |
127 self.mox.StubOutWithMock(fileinput, 'input') | 127 self.mox.StubOutWithMock(fileinput, 'input') |
128 fileinput.input(fake_ebuild_path).AndReturn('') | 128 fileinput.input(fake_ebuild_path).AndReturn('') |
129 self.mox.ReplayAll() | 129 self.mox.ReplayAll() |
130 fake_ebuild = cros_mark_as_stable.EBuild(fake_ebuild_path) | 130 fake_ebuild = cros_mark_as_stable.EBuild(fake_ebuild_path) |
131 self.mox.VerifyAll() | 131 self.mox.VerifyAll() |
132 self.assertEquals(fake_ebuild.ebuild_path_no_revision, | 132 self.assertEquals(fake_ebuild.version_no_rev, '0.0.1') |
133 '/path/to/test_package/test_package-0.0.1') | |
134 self.assertEquals(fake_ebuild.ebuild_path_no_version, | 133 self.assertEquals(fake_ebuild.ebuild_path_no_version, |
135 '/path/to/test_package/test_package') | 134 '/path/to/test_package/test_package') |
136 self.assertEquals(fake_ebuild.current_revision, 1) | 135 self.assertEquals(fake_ebuild.current_revision, 1) |
137 | 136 |
138 def testParseEBuildPathNoRevisionNumber(self): | 137 def testParseEBuildPathNoRevisionNumber(self): |
139 # Test with ebuild without revision number. | 138 # Test with ebuild without revision number. |
140 fake_ebuild_path = '/path/to/test_package/test_package-9999.ebuild' | 139 fake_ebuild_path = '/path/to/test_package/test_package-9999.ebuild' |
141 self.mox.StubOutWithMock(fileinput, 'input') | 140 self.mox.StubOutWithMock(fileinput, 'input') |
142 fileinput.input(fake_ebuild_path).AndReturn('') | 141 fileinput.input(fake_ebuild_path).AndReturn('') |
143 self.mox.ReplayAll() | 142 self.mox.ReplayAll() |
144 fake_ebuild = cros_mark_as_stable.EBuild(fake_ebuild_path) | 143 fake_ebuild = cros_mark_as_stable.EBuild(fake_ebuild_path) |
145 self.mox.VerifyAll() | 144 self.mox.VerifyAll() |
146 | 145 |
147 self.assertEquals(fake_ebuild.ebuild_path_no_revision, | 146 self.assertEquals(fake_ebuild.version_no_rev, '9999') |
148 '/path/to/test_package/test_package-9999') | |
149 self.assertEquals(fake_ebuild.ebuild_path_no_version, | 147 self.assertEquals(fake_ebuild.ebuild_path_no_version, |
150 '/path/to/test_package/test_package') | 148 '/path/to/test_package/test_package') |
151 self.assertEquals(fake_ebuild.current_revision, 0) | 149 self.assertEquals(fake_ebuild.current_revision, 0) |
152 | 150 |
153 | 151 |
154 class EBuildStableMarkerTest(mox.MoxTestBase): | 152 class EBuildStableMarkerTest(mox.MoxTestBase): |
155 | 153 |
156 def setUp(self): | 154 def setUp(self): |
157 mox.MoxTestBase.setUp(self) | 155 mox.MoxTestBase.setUp(self) |
158 self.mox.StubOutWithMock(cros_mark_as_stable, '_SimpleRunCommand') | 156 self.mox.StubOutWithMock(cros_mark_as_stable, '_SimpleRunCommand') |
159 self.mox.StubOutWithMock(cros_mark_as_stable, 'RunCommand') | 157 self.mox.StubOutWithMock(cros_mark_as_stable, 'RunCommand') |
160 self.mox.StubOutWithMock(os, 'unlink') | 158 self.mox.StubOutWithMock(os, 'unlink') |
161 self.m_ebuild = self.mox.CreateMock(cros_mark_as_stable.EBuild) | 159 self.m_ebuild = self.mox.CreateMock(cros_mark_as_stable.EBuild) |
162 self.m_ebuild.is_stable = True | 160 self.m_ebuild.is_stable = True |
163 self.m_ebuild.package = 'test_package' | 161 self.m_ebuild.package = 'test_package/test_package' |
| 162 self.m_ebuild.version_no_rev = '0.0.1' |
164 self.m_ebuild.current_revision = 1 | 163 self.m_ebuild.current_revision = 1 |
165 self.m_ebuild.ebuild_path_no_revision = '/path/test_package-0.0.1' | 164 self.m_ebuild.ebuild_path_no_revision = '/path/test_package-0.0.1' |
166 self.m_ebuild.ebuild_path_no_version = '/path/test_package' | 165 self.m_ebuild.ebuild_path_no_version = '/path/test_package' |
167 self.m_ebuild.ebuild_path = '/path/test_package-0.0.1-r1.ebuild' | 166 self.m_ebuild.ebuild_path = '/path/test_package-0.0.1-r1.ebuild' |
168 self.revved_ebuild_path = '/path/test_package-0.0.1-r2.ebuild' | 167 self.revved_ebuild_path = '/path/test_package-0.0.1-r2.ebuild' |
| 168 self.unstable_ebuild_path = '/path/test_package-9999.ebuild' |
169 | 169 |
170 def testRevWorkOnEBuild(self): | 170 def testRevWorkOnEBuild(self): |
171 self.mox.StubOutWithMock(cros_mark_as_stable.fileinput, 'input') | 171 self.mox.StubOutWithMock(cros_mark_as_stable.fileinput, 'input') |
172 self.mox.StubOutWithMock(cros_mark_as_stable.os.path, 'exists') | 172 self.mox.StubOutWithMock(cros_mark_as_stable.os.path, 'exists') |
173 self.mox.StubOutWithMock(cros_mark_as_stable.shutil, 'copyfile') | 173 self.mox.StubOutWithMock(cros_mark_as_stable.shutil, 'copyfile') |
174 m_file = self.mox.CreateMock(file) | 174 m_file = self.mox.CreateMock(file) |
175 | 175 |
176 # Prepare mock fileinput. This tests to make sure both the commit id | 176 # Prepare mock fileinput. This tests to make sure both the commit id |
177 # and keywords are changed correctly. | 177 # and keywords are changed correctly. |
178 mock_file = ['EAPI=2', 'CROS_WORKON_COMMIT=old_id', | 178 mock_file = ['EAPI=2', 'CROS_WORKON_COMMIT=old_id', |
(...skipping 11 matching lines...) Expand all Loading... |
190 diff_cmd = ['diff', '-Bu', self.m_ebuild.ebuild_path, | 190 diff_cmd = ['diff', '-Bu', self.m_ebuild.ebuild_path, |
191 self.revved_ebuild_path] | 191 self.revved_ebuild_path] |
192 cros_mark_as_stable.RunCommand(diff_cmd, exit_code=True, | 192 cros_mark_as_stable.RunCommand(diff_cmd, exit_code=True, |
193 print_cmd=False, redirect_stderr=True, | 193 print_cmd=False, redirect_stderr=True, |
194 redirect_stdout=True).AndReturn(1) | 194 redirect_stdout=True).AndReturn(1) |
195 cros_mark_as_stable._SimpleRunCommand('git add ' + self.revved_ebuild_path) | 195 cros_mark_as_stable._SimpleRunCommand('git add ' + self.revved_ebuild_path) |
196 cros_mark_as_stable._SimpleRunCommand('git rm ' + self.m_ebuild.ebuild_path) | 196 cros_mark_as_stable._SimpleRunCommand('git rm ' + self.m_ebuild.ebuild_path) |
197 | 197 |
198 self.mox.ReplayAll() | 198 self.mox.ReplayAll() |
199 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild) | 199 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild) |
200 marker.RevWorkOnEBuild('my_id', redirect_file=m_file) | 200 result = marker.RevWorkOnEBuild('my_id', redirect_file=m_file) |
201 self.mox.VerifyAll() | 201 self.mox.VerifyAll() |
| 202 self.assertEqual(result, 'test_package/test_package-0.0.1-r2') |
202 | 203 |
203 def testRevUnchangedEBuild(self): | 204 def testRevUnchangedEBuild(self): |
204 self.mox.StubOutWithMock(cros_mark_as_stable.fileinput, 'input') | 205 self.mox.StubOutWithMock(cros_mark_as_stable.fileinput, 'input') |
205 self.mox.StubOutWithMock(cros_mark_as_stable.os.path, 'exists') | 206 self.mox.StubOutWithMock(cros_mark_as_stable.os.path, 'exists') |
206 self.mox.StubOutWithMock(cros_mark_as_stable.shutil, 'copyfile') | 207 self.mox.StubOutWithMock(cros_mark_as_stable.shutil, 'copyfile') |
207 m_file = self.mox.CreateMock(file) | 208 m_file = self.mox.CreateMock(file) |
208 | 209 |
209 # Prepare mock fileinput. This tests to make sure both the commit id | 210 # Prepare mock fileinput. This tests to make sure both the commit id |
210 # and keywords are changed correctly. | 211 # and keywords are changed correctly. |
211 mock_file = ['EAPI=2', 'CROS_WORKON_COMMIT=old_id', | 212 mock_file = ['EAPI=2', 'CROS_WORKON_COMMIT=old_id', |
(...skipping 10 matching lines...) Expand all Loading... |
222 m_file.write('src_unpack(){}') | 223 m_file.write('src_unpack(){}') |
223 diff_cmd = ['diff', '-Bu', self.m_ebuild.ebuild_path, | 224 diff_cmd = ['diff', '-Bu', self.m_ebuild.ebuild_path, |
224 self.revved_ebuild_path] | 225 self.revved_ebuild_path] |
225 cros_mark_as_stable.RunCommand(diff_cmd, exit_code=True, | 226 cros_mark_as_stable.RunCommand(diff_cmd, exit_code=True, |
226 print_cmd=False, redirect_stderr=True, | 227 print_cmd=False, redirect_stderr=True, |
227 redirect_stdout=True).AndReturn(0) | 228 redirect_stdout=True).AndReturn(0) |
228 cros_mark_as_stable.os.unlink(self.revved_ebuild_path) | 229 cros_mark_as_stable.os.unlink(self.revved_ebuild_path) |
229 | 230 |
230 self.mox.ReplayAll() | 231 self.mox.ReplayAll() |
231 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild) | 232 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild) |
232 marker.RevWorkOnEBuild('my_id', redirect_file=m_file) | 233 result = marker.RevWorkOnEBuild('my_id', redirect_file=m_file) |
233 self.mox.VerifyAll() | 234 self.mox.VerifyAll() |
| 235 self.assertEqual(result, None) |
234 | 236 |
235 def testRevMissingEBuild(self): | 237 def testRevMissingEBuild(self): |
236 self.mox.StubOutWithMock(cros_mark_as_stable.fileinput, 'input') | 238 self.mox.StubOutWithMock(cros_mark_as_stable.fileinput, 'input') |
237 self.mox.StubOutWithMock(cros_mark_as_stable.os.path, 'exists') | 239 self.mox.StubOutWithMock(cros_mark_as_stable.os.path, 'exists') |
238 self.mox.StubOutWithMock(cros_mark_as_stable.shutil, 'copyfile') | 240 self.mox.StubOutWithMock(cros_mark_as_stable.shutil, 'copyfile') |
239 self.mox.StubOutWithMock(cros_mark_as_stable, 'Die') | 241 self.mox.StubOutWithMock(cros_mark_as_stable, 'Die') |
240 m_file = self.mox.CreateMock(file) | 242 m_file = self.mox.CreateMock(file) |
241 | 243 |
| 244 revved_ebuild_path = self.m_ebuild.ebuild_path |
| 245 self.m_ebuild.ebuild_path = self.unstable_ebuild_path |
| 246 self.m_ebuild.is_stable = False |
| 247 self.m_ebuild.current_revision = 0 |
| 248 |
242 # Prepare mock fileinput. This tests to make sure both the commit id | 249 # Prepare mock fileinput. This tests to make sure both the commit id |
243 # and keywords are changed correctly. | 250 # and keywords are changed correctly. |
244 mock_file = ['EAPI=2', 'CROS_WORKON_COMMIT=old_id', | 251 mock_file = ['EAPI=2', 'CROS_WORKON_COMMIT=old_id', |
245 'KEYWORDS=\"~x86 ~arm\"', 'src_unpack(){}'] | 252 'KEYWORDS=\"~x86 ~arm\"', 'src_unpack(){}'] |
246 | 253 |
247 ebuild_9999 = self.m_ebuild.ebuild_path_no_version + '-9999.ebuild' | 254 ebuild_9999 = self.m_ebuild.ebuild_path_no_version + '-9999.ebuild' |
248 cros_mark_as_stable.os.path.exists(ebuild_9999).AndReturn(False) | 255 cros_mark_as_stable.os.path.exists(ebuild_9999).AndReturn(False) |
249 cros_mark_as_stable.Die("Missing unstable ebuild: %s" % ebuild_9999) | 256 cros_mark_as_stable.Die("Missing unstable ebuild: %s" % ebuild_9999) |
250 cros_mark_as_stable.shutil.copyfile(ebuild_9999, self.revved_ebuild_path) | 257 cros_mark_as_stable.shutil.copyfile(ebuild_9999, revved_ebuild_path) |
251 cros_mark_as_stable.fileinput.input(self.revved_ebuild_path, | 258 cros_mark_as_stable.fileinput.input(revved_ebuild_path, |
252 inplace=1).AndReturn(mock_file) | 259 inplace=1).AndReturn(mock_file) |
253 m_file.write('EAPI=2') | 260 m_file.write('EAPI=2') |
254 m_file.write('CROS_WORKON_COMMIT="my_id"\n') | 261 m_file.write('CROS_WORKON_COMMIT="my_id"\n') |
255 m_file.write('KEYWORDS="x86 arm"') | 262 m_file.write('KEYWORDS="x86 arm"') |
256 m_file.write('src_unpack(){}') | 263 m_file.write('src_unpack(){}') |
257 diff_cmd = ['diff', '-Bu', self.m_ebuild.ebuild_path, | 264 diff_cmd = ['diff', '-Bu', self.unstable_ebuild_path, revved_ebuild_path] |
258 self.revved_ebuild_path] | |
259 cros_mark_as_stable.RunCommand(diff_cmd, exit_code=True, | 265 cros_mark_as_stable.RunCommand(diff_cmd, exit_code=True, |
260 print_cmd=False, redirect_stderr=True, | 266 print_cmd=False, redirect_stderr=True, |
261 redirect_stdout=True).AndReturn(1) | 267 redirect_stdout=True).AndReturn(1) |
262 cros_mark_as_stable._SimpleRunCommand('git add ' + self.revved_ebuild_path) | 268 cros_mark_as_stable._SimpleRunCommand('git add ' + revved_ebuild_path) |
263 cros_mark_as_stable._SimpleRunCommand('git rm ' + self.m_ebuild.ebuild_path) | |
264 | 269 |
265 self.mox.ReplayAll() | 270 self.mox.ReplayAll() |
266 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild) | 271 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild) |
267 marker.RevWorkOnEBuild('my_id', redirect_file=m_file) | 272 result = marker.RevWorkOnEBuild('my_id', redirect_file=m_file) |
268 self.mox.VerifyAll() | 273 self.mox.VerifyAll() |
| 274 self.assertEqual(result, 'test_package/test_package-0.0.1-r1') |
269 | 275 |
270 | 276 |
271 def testCommitChange(self): | 277 def testCommitChange(self): |
272 mock_message = 'Commit me' | 278 mock_message = 'Commit me' |
273 cros_mark_as_stable._SimpleRunCommand( | 279 cros_mark_as_stable._SimpleRunCommand( |
274 'git commit -am "%s"' % mock_message) | 280 'git commit -am "%s"' % mock_message) |
275 self.mox.ReplayAll() | 281 self.mox.ReplayAll() |
276 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild) | 282 marker = cros_mark_as_stable.EBuildStableMarker(self.m_ebuild) |
277 marker.CommitChange(mock_message) | 283 marker.CommitChange(mock_message) |
278 self.mox.VerifyAll() | 284 self.mox.VerifyAll() |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 cros_mark_as_stable._FindUprevCandidates([]).AndReturn(package) | 319 cros_mark_as_stable._FindUprevCandidates([]).AndReturn(package) |
314 self.mox.ReplayAll() | 320 self.mox.ReplayAll() |
315 cros_mark_as_stable._BuildEBuildDictionary(overlays, False, []) | 321 cros_mark_as_stable._BuildEBuildDictionary(overlays, False, []) |
316 self.assertEquals(len(overlays), 1) | 322 self.assertEquals(len(overlays), 1) |
317 self.assertEquals(overlays["/overlay"], []) | 323 self.assertEquals(overlays["/overlay"], []) |
318 self.mox.VerifyAll() | 324 self.mox.VerifyAll() |
319 | 325 |
320 | 326 |
321 if __name__ == '__main__': | 327 if __name__ == '__main__': |
322 unittest.main() | 328 unittest.main() |
OLD | NEW |