OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import copy | 6 import copy |
7 import mox | 7 import mox |
8 import os | 8 import os |
9 import prebuilt | 9 import prebuilt |
10 import shutil | 10 import shutil |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 pkgs = [{ 'CPV': 'public1' }] | 188 pkgs = [{ 'CPV': 'public1' }] |
189 result = prebuilt.GenerateUploadDict(base_local_path, gs_bucket_path, pkgs) | 189 result = prebuilt.GenerateUploadDict(base_local_path, gs_bucket_path, pkgs) |
190 expected = { local_path: gs_bucket_path + '/public1.tbz2' } | 190 expected = { local_path: gs_bucket_path + '/public1.tbz2' } |
191 self.assertEqual(result, expected) | 191 self.assertEqual(result, expected) |
192 | 192 |
193 def testFailonUploadFail(self): | 193 def testFailonUploadFail(self): |
194 """Make sure we fail if one of the upload processes fail.""" | 194 """Make sure we fail if one of the upload processes fail.""" |
195 files = {'test': '/uasd'} | 195 files = {'test': '/uasd'} |
196 self.assertEqual(prebuilt.RemoteUpload(files), set([('test', '/uasd')])) | 196 self.assertEqual(prebuilt.RemoteUpload(files), set([('test', '/uasd')])) |
197 | 197 |
198 def testDeterminePrebuiltConfHost(self): | |
199 """Test that the host prebuilt path comes back properly.""" | |
200 expected_path = os.path.join(prebuilt._PREBUILT_MAKE_CONF['amd64']) | |
201 self.assertEqual(prebuilt.DeterminePrebuiltConfFile('fake_path', 'amd64'), | |
202 expected_path) | |
203 | |
198 def testDeterminePrebuiltConf(self): | 204 def testDeterminePrebuiltConf(self): |
199 """Test the different known variants of boards for proper path discovery.""" | 205 """Test the different known variants of boards for proper path discovery.""" |
200 targets = {'amd64': os.path.join(prebuilt._PREBUILT_MAKE_CONF['amd64']), | 206 fake_path = '/b/cbuild' |
201 'x86-generic': os.path.join(prebuilt._BINHOST_BASE_DIR, | 207 script_path = os.path.join(fake_path, 'src/scripts/bin') |
202 'overlay-x86-generic', 'prebuilt.conf'), | 208 _BINHOST_BASE_DIR = 'src/overlays' |
203 'arm-tegra2_vogue': os.path.join( | 209 # format for targets |
204 prebuilt._BINHOST_BASE_DIR, | 210 # board target key in dictionar |
205 'overlay-variant-arm-tegra2-vogue', 'prebuilt.conf'),} | 211 # Tuple containing cmd run, expected results as cmd obj, and expected output |
212 | |
213 # Mock output from cros_overlay_list | |
214 x86_out = ('%(fake_path)s/private-overlays/chromeos-overlay\n' | |
215 '%(fake_path)s/src/overlays/overlay-x86-generic\n' | |
sosa
2011/01/19 21:51:15
You shouldn't need to indent here
scottz
2011/01/19 22:11:06
I renamed the variable and forgot to re-align :) t
| |
216 % {'fake_path': fake_path}) | |
217 x86_cmd = './cros_overlay_list --board x86-generic' | |
218 x86_expected_path = os.path.join(fake_path, _BINHOST_BASE_DIR, | |
sosa
2011/01/19 21:51:15
Could have better reuse of paths from before here
scottz
2011/01/19 22:11:06
I knew that was coming :)
Done.
| |
219 'overlay-x86-generic', 'prebuilt.conf') | |
220 # Mock output from cros_overlay_list | |
221 tegra2_out = ('%(fake_path)s/src/private-overlays/chromeos-overlay\n' | |
222 '%(fake_path)s/src/overlays/overlay-tegra2\n' | |
223 '%(fake_path)s/src/overlays/overlay-variant-tegra2-seaboard\n' | |
224 '%(fake_path)s/src/private-overlays/overlay-tegra2-private\n' | |
225 '%(fake_path)s/src/private-overlays/' | |
226 'overlay-variant-tegra2-seaboard-private\n' | |
227 % {'fake_path': fake_path}) | |
228 tegra2_cmd = './cros_overlay_list --board tegra2 --variant seaboard' | |
229 tegra2_expected_path = os.path.join( | |
230 fake_path, prebuilt._PRIVATE_OVERLAY_DIR, | |
231 'overlay-variant-tegra2-seaboard-private', 'prebuilt.conf') | |
232 | |
233 | |
234 targets = {'x86-generic': (x86_cmd, x86_out, x86_expected_path), | |
sosa
2011/01/19 21:51:15
May wanna consider using a dict of dicts to make i
scottz
2011/01/19 22:11:06
I like it
| |
235 'tegra2_seaboard': (tegra2_cmd, tegra2_out, tegra2_expected_path) | |
236 } | |
237 | |
238 self.mox.StubOutWithMock(prebuilt.cros_build_lib, 'RunCommand') | |
239 for target, expected_results in targets.iteritems(): | |
240 # create command object for output | |
241 cmd_result_obj = cros_build_lib.CommandResult() | |
242 cmd_result_obj.output = expected_results[1] | |
243 prebuilt.cros_build_lib.RunCommand(expected_results[0].split(), | |
244 redirect_stdout=True, | |
245 cwd=script_path).AndReturn( | |
sosa
2011/01/19 21:51:15
fix indentation
scottz
2011/01/19 22:11:06
Done.
| |
246 cmd_result_obj) | |
247 | |
248 self.mox.ReplayAll() | |
206 for target in targets: | 249 for target in targets: |
207 self.assertEqual(prebuilt.DeterminePrebuiltConfFile(target), | 250 self.assertEqual( |
208 targets[target]) | 251 prebuilt.DeterminePrebuiltConfFile(fake_path, target), |
209 | 252 targets[target][2]) |
210 def testPrivatePrebuiltConf(self): | |
211 """Test that we get a different path for private prebuilts""" | |
212 targets = {'amd64': os.path.join(prebuilt._PREBUILT_MAKE_CONF['amd64']), | |
213 'x86-generic': os.path.join( | |
214 prebuilt._PRIVATE_OVERLAY_DIR, 'overlay-x86-generic', | |
215 'prebuilt.conf'), | |
216 'arm-tegra2_vogue': os.path.join( | |
217 prebuilt._PRIVATE_OVERLAY_DIR, | |
218 'overlay-variant-arm-tegra2-vogue', 'prebuilt.conf'),} | |
219 | |
220 self.mox.StubOutWithMock(prebuilt.os.path, 'exists') | |
221 # Add mocks for every target we check | |
222 for mock_count in range(len(targets)): | |
223 prebuilt.os.path.exists(prebuilt._PRIVATE_OVERLAY_DIR).AndReturn(True) | |
224 self.mox.ReplayAll() | |
225 | |
226 for target in targets: | |
227 self.assertEqual(prebuilt.DeterminePrebuiltConfFile(target), | |
228 targets[target]) | |
229 | 253 |
230 def testDeterminePrebuiltConfGarbage(self): | 254 def testDeterminePrebuiltConfGarbage(self): |
231 """Ensure an exception is raised on bad input.""" | 255 """Ensure an exception is raised on bad input.""" |
232 self.assertRaises(prebuilt.UnknownBoardFormat, | 256 self.assertRaises(prebuilt.UnknownBoardFormat, |
233 prebuilt.DeterminePrebuiltConfFile, 'asdfasdf') | 257 prebuilt.DeterminePrebuiltConfFile, |
258 'fake_path', 'asdfasdf') | |
234 | 259 |
235 | 260 |
236 class TestPackagesFileFiltering(unittest.TestCase): | 261 class TestPackagesFileFiltering(unittest.TestCase): |
237 | 262 |
238 def testFilterPkgIndex(self): | 263 def testFilterPkgIndex(self): |
239 pkgindex = SimplePackageIndex() | 264 pkgindex = SimplePackageIndex() |
240 pkgindex.RemoveFilteredPackages(lambda pkg: pkg in PRIVATE_PACKAGES) | 265 pkgindex.RemoveFilteredPackages(lambda pkg: pkg in PRIVATE_PACKAGES) |
241 self.assertEqual(pkgindex.packages, PUBLIC_PACKAGES) | 266 self.assertEqual(pkgindex.packages, PUBLIC_PACKAGES) |
242 self.assertEqual(pkgindex.modified, True) | 267 self.assertEqual(pkgindex.modified, True) |
243 | 268 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 pkgindex = SimplePackageIndex() | 356 pkgindex = SimplePackageIndex() |
332 self.mox.StubOutWithMock(pkgindex, 'Write') | 357 self.mox.StubOutWithMock(pkgindex, 'Write') |
333 pkgindex.Write(mox.IgnoreArg()) | 358 pkgindex.Write(mox.IgnoreArg()) |
334 self.mox.ReplayAll() | 359 self.mox.ReplayAll() |
335 f = pkgindex.WriteToNamedTemporaryFile() | 360 f = pkgindex.WriteToNamedTemporaryFile() |
336 self.assertEqual(f.read(), '') | 361 self.assertEqual(f.read(), '') |
337 | 362 |
338 | 363 |
339 if __name__ == '__main__': | 364 if __name__ == '__main__': |
340 unittest.main() | 365 unittest.main() |
OLD | NEW |