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