Chromium Code Reviews| 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 public_overlay_path = os.path.join(fake_path, 'src/overlays') |
| 203 'arm-tegra2_vogue': os.path.join( | 209 private_overlay_path = os.path.join(fake_path, |
| 204 prebuilt._BINHOST_BASE_DIR, | 210 prebuilt._PRIVATE_OVERLAY_DIR) |
| 205 'overlay-variant-arm-tegra2-vogue', 'prebuilt.conf'),} | 211 path_dict = {'private_overlay_path': private_overlay_path, |
| 206 for target in targets: | 212 'public_overlay_path': public_overlay_path} |
| 207 self.assertEqual(prebuilt.DeterminePrebuiltConfFile(target), | 213 # format for targets |
| 208 targets[target]) | 214 # board target key in dictionar |
| 215 # Tuple containing cmd run, expected results as cmd obj, and expected output | |
| 209 | 216 |
| 210 def testPrivatePrebuiltConf(self): | 217 # Mock output from cros_overlay_list |
| 211 """Test that we get a different path for private prebuilts""" | 218 x86_out = ('%(private_overlay_path)s//chromeos-overlay\n' |
|
sosa
2011/01/19 22:16:52
Dbl slash?
scottz
2011/01/19 22:21:24
Oh snap :) thanks
On 2011/01/19 22:16:52, sosa wr
| |
| 212 targets = {'amd64': os.path.join(prebuilt._PREBUILT_MAKE_CONF['amd64']), | 219 '%(public_overlay_path)s/overlay-x86-generic\n' % path_dict) |
| 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 |
| 220 self.mox.StubOutWithMock(prebuilt.os.path, 'exists') | 221 x86_cmd = './cros_overlay_list --board x86-generic' |
| 221 # Add mocks for every target we check | 222 x86_expected_path = os.path.join(public_overlay_path, 'overlay-x86-generic', |
| 222 for mock_count in range(len(targets)): | 223 'prebuilt.conf') |
| 223 prebuilt.os.path.exists(prebuilt._PRIVATE_OVERLAY_DIR).AndReturn(True) | 224 # Mock output from cros_overlay_list |
| 225 tegra2_out = ('%(private_overlay_path)s/chromeos-overlay\n' | |
| 226 '%(public_overlay_path)s/overlay-tegra2\n' | |
| 227 '%(public_overlay_path)s/overlay-variant-tegra2-seaboard\n' | |
| 228 '%(private_overlay_path)s/overlay-tegra2-private\n' | |
| 229 '%(private_overlay_path)s/' | |
| 230 'overlay-variant-tegra2-seaboard-private\n' % path_dict) | |
| 231 tegra2_cmd = './cros_overlay_list --board tegra2 --variant seaboard' | |
| 232 tegra2_expected_path = os.path.join( | |
| 233 private_overlay_path, 'overlay-variant-tegra2-seaboard-private', | |
| 234 'prebuilt.conf') | |
| 235 | |
| 236 | |
| 237 targets = {'x86-generic': {'cmd': x86_cmd, | |
| 238 'output': x86_out, | |
| 239 'result': x86_expected_path}, | |
| 240 'tegra2_seaboard': {'cmd': tegra2_cmd, | |
| 241 'output': tegra2_out, | |
| 242 'result': tegra2_expected_path} | |
| 243 } | |
| 244 | |
| 245 self.mox.StubOutWithMock(prebuilt.cros_build_lib, 'RunCommand') | |
| 246 for target, expected_results in targets.iteritems(): | |
| 247 # create command object for output | |
| 248 cmd_result_obj = cros_build_lib.CommandResult() | |
| 249 cmd_result_obj.output = expected_results['output'] | |
| 250 prebuilt.cros_build_lib.RunCommand( | |
| 251 expected_results['cmd'].split(), redirect_stdout=True, | |
| 252 cwd=script_path).AndReturn(cmd_result_obj) | |
| 253 | |
| 224 self.mox.ReplayAll() | 254 self.mox.ReplayAll() |
| 225 | 255 for target, expected_results in targets.iteritems(): |
| 226 for target in targets: | 256 self.assertEqual( |
| 227 self.assertEqual(prebuilt.DeterminePrebuiltConfFile(target), | 257 prebuilt.DeterminePrebuiltConfFile(fake_path, target), |
| 228 targets[target]) | 258 expected_results['result']) |
| 229 | 259 |
| 230 def testDeterminePrebuiltConfGarbage(self): | 260 def testDeterminePrebuiltConfGarbage(self): |
| 231 """Ensure an exception is raised on bad input.""" | 261 """Ensure an exception is raised on bad input.""" |
| 232 self.assertRaises(prebuilt.UnknownBoardFormat, | 262 self.assertRaises(prebuilt.UnknownBoardFormat, |
| 233 prebuilt.DeterminePrebuiltConfFile, 'asdfasdf') | 263 prebuilt.DeterminePrebuiltConfFile, |
| 264 'fake_path', 'asdfasdf') | |
| 234 | 265 |
| 235 | 266 |
| 236 class TestPackagesFileFiltering(unittest.TestCase): | 267 class TestPackagesFileFiltering(unittest.TestCase): |
| 237 | 268 |
| 238 def testFilterPkgIndex(self): | 269 def testFilterPkgIndex(self): |
| 239 pkgindex = SimplePackageIndex() | 270 pkgindex = SimplePackageIndex() |
| 240 pkgindex.RemoveFilteredPackages(lambda pkg: pkg in PRIVATE_PACKAGES) | 271 pkgindex.RemoveFilteredPackages(lambda pkg: pkg in PRIVATE_PACKAGES) |
| 241 self.assertEqual(pkgindex.packages, PUBLIC_PACKAGES) | 272 self.assertEqual(pkgindex.packages, PUBLIC_PACKAGES) |
| 242 self.assertEqual(pkgindex.modified, True) | 273 self.assertEqual(pkgindex.modified, True) |
| 243 | 274 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 pkgindex = SimplePackageIndex() | 362 pkgindex = SimplePackageIndex() |
| 332 self.mox.StubOutWithMock(pkgindex, 'Write') | 363 self.mox.StubOutWithMock(pkgindex, 'Write') |
| 333 pkgindex.Write(mox.IgnoreArg()) | 364 pkgindex.Write(mox.IgnoreArg()) |
| 334 self.mox.ReplayAll() | 365 self.mox.ReplayAll() |
| 335 f = pkgindex.WriteToNamedTemporaryFile() | 366 f = pkgindex.WriteToNamedTemporaryFile() |
| 336 self.assertEqual(f.read(), '') | 367 self.assertEqual(f.read(), '') |
| 337 | 368 |
| 338 | 369 |
| 339 if __name__ == '__main__': | 370 if __name__ == '__main__': |
| 340 unittest.main() | 371 unittest.main() |
| OLD | NEW |