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

Side by Side Diff: prebuilt_unittest.py

Issue 5542002: Switch from gsdview.appspot.com to commondatastorage.googleapis.com. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: 80 chars Created 10 years 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
« prebuilt.py ('K') | « prebuilt.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 # 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
11 import tempfile 11 import tempfile
12 import unittest 12 import unittest
13 import urllib
13 from chromite.lib import cros_build_lib 14 from chromite.lib import cros_build_lib
14 from chromite.lib.binpkg import PackageIndex 15 from chromite.lib.binpkg import PackageIndex
15 16
16 PUBLIC_PACKAGES = [{'CPV': 'public1', 'SHA1': '1'}, 17 PUBLIC_PACKAGES = [{'CPV': 'gtk+/public1', 'SHA1': '1'},
17 {'CPV': 'public2', 'SHA1': '2', 'PATH': 'foo.tgz'}] 18 {'CPV': 'gtk+/public2', 'SHA1': '2',
19 'PATH': 'gtk%2B/foo.tgz'}]
18 PRIVATE_PACKAGES = [{'CPV': 'private', 'SHA1': '3'}] 20 PRIVATE_PACKAGES = [{'CPV': 'private', 'SHA1': '3'}]
19 21
20 22
21 def SimplePackageIndex(header=True, packages=True): 23 def SimplePackageIndex(header=True, packages=True):
22 pkgindex = PackageIndex() 24 pkgindex = PackageIndex()
23 if header: 25 if header:
24 pkgindex.header['URI'] = 'http://www.example.com' 26 pkgindex.header['URI'] = 'http://www.example.com'
25 if packages: 27 if packages:
26 pkgindex.packages = copy.deepcopy(PUBLIC_PACKAGES + PRIVATE_PACKAGES) 28 pkgindex.packages = copy.deepcopy(PUBLIC_PACKAGES + PRIVATE_PACKAGES)
27 return pkgindex 29 return pkgindex
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 pkgindex = SimplePackageIndex(packages=False) 212 pkgindex = SimplePackageIndex(packages=False)
211 db = {} 213 db = {}
212 pkgindex._PopulateDuplicateDB(db) 214 pkgindex._PopulateDuplicateDB(db)
213 self.assertEqual(db, {}) 215 self.assertEqual(db, {})
214 216
215 def testNormalIndex(self): 217 def testNormalIndex(self):
216 pkgindex = SimplePackageIndex() 218 pkgindex = SimplePackageIndex()
217 db = {} 219 db = {}
218 pkgindex._PopulateDuplicateDB(db) 220 pkgindex._PopulateDuplicateDB(db)
219 self.assertEqual(len(db), 3) 221 self.assertEqual(len(db), 3)
220 self.assertEqual(db['1'], 'http://www.example.com/public1.tbz2') 222 self.assertEqual(db['1'], 'http://www.example.com/gtk%2B/public1.tbz2')
221 self.assertEqual(db['2'], 'http://www.example.com/foo.tgz') 223 self.assertEqual(db['2'], 'http://www.example.com/gtk%2B/foo.tgz')
222 self.assertEqual(db['3'], 'http://www.example.com/private.tbz2') 224 self.assertEqual(db['3'], 'http://www.example.com/private.tbz2')
223 225
224 def testMissingSHA1(self): 226 def testMissingSHA1(self):
225 db = {} 227 db = {}
226 pkgindex = SimplePackageIndex() 228 pkgindex = SimplePackageIndex()
227 del pkgindex.packages[0]['SHA1'] 229 del pkgindex.packages[0]['SHA1']
228 pkgindex._PopulateDuplicateDB(db) 230 pkgindex._PopulateDuplicateDB(db)
229 self.assertEqual(len(db), 2) 231 self.assertEqual(len(db), 2)
230 self.assertEqual(db['2'], 'http://www.example.com/foo.tgz') 232 self.assertEqual(db['2'], 'http://www.example.com/gtk%2B/foo.tgz')
231 self.assertEqual(db['3'], 'http://www.example.com/private.tbz2') 233 self.assertEqual(db['3'], 'http://www.example.com/private.tbz2')
232 234
233 def testFailedPopulate(self): 235 def testFailedPopulate(self):
234 db = {} 236 db = {}
235 pkgindex = SimplePackageIndex(header=False) 237 pkgindex = SimplePackageIndex(header=False)
236 self.assertRaises(KeyError, pkgindex._PopulateDuplicateDB, db) 238 self.assertRaises(KeyError, pkgindex._PopulateDuplicateDB, db)
237 pkgindex = SimplePackageIndex() 239 pkgindex = SimplePackageIndex()
238 del pkgindex.packages[0]['CPV'] 240 del pkgindex.packages[0]['CPV']
239 self.assertRaises(KeyError, pkgindex._PopulateDuplicateDB, db) 241 self.assertRaises(KeyError, pkgindex._PopulateDuplicateDB, db)
240 242
(...skipping 15 matching lines...) Expand all
256 uploads = pkgindex.ResolveDuplicateUploads([empty]) 258 uploads = pkgindex.ResolveDuplicateUploads([empty])
257 self.assertEqual(uploads, pristine.packages) 259 self.assertEqual(uploads, pristine.packages)
258 self.assertEqual(pkgindex.packages, pristine.packages) 260 self.assertEqual(pkgindex.packages, pristine.packages)
259 self.assertEqual(pkgindex.modified, False) 261 self.assertEqual(pkgindex.modified, False)
260 262
261 def testDuplicates(self): 263 def testDuplicates(self):
262 pkgindex = SimplePackageIndex() 264 pkgindex = SimplePackageIndex()
263 dup_pkgindex = SimplePackageIndex() 265 dup_pkgindex = SimplePackageIndex()
264 expected_pkgindex = SimplePackageIndex() 266 expected_pkgindex = SimplePackageIndex()
265 for pkg in expected_pkgindex.packages: 267 for pkg in expected_pkgindex.packages:
266 pkg.setdefault('PATH', pkg['CPV'] + '.tbz2') 268 pkg.setdefault('PATH', urllib.quote(pkg['CPV'] + '.tbz2'))
267 uploads = pkgindex.ResolveDuplicateUploads([dup_pkgindex]) 269 uploads = pkgindex.ResolveDuplicateUploads([dup_pkgindex])
268 self.assertEqual(pkgindex.packages, expected_pkgindex.packages) 270 self.assertEqual(pkgindex.packages, expected_pkgindex.packages)
269 271
270 def testMissingSHA1(self): 272 def testMissingSHA1(self):
271 db = {} 273 db = {}
272 pkgindex = SimplePackageIndex() 274 pkgindex = SimplePackageIndex()
273 dup_pkgindex = SimplePackageIndex() 275 dup_pkgindex = SimplePackageIndex()
274 expected_pkgindex = SimplePackageIndex() 276 expected_pkgindex = SimplePackageIndex()
275 del pkgindex.packages[0]['SHA1'] 277 del pkgindex.packages[0]['SHA1']
276 del expected_pkgindex.packages[0]['SHA1'] 278 del expected_pkgindex.packages[0]['SHA1']
(...skipping 16 matching lines...) Expand all
293 pkgindex = SimplePackageIndex() 295 pkgindex = SimplePackageIndex()
294 self.mox.StubOutWithMock(pkgindex, 'Write') 296 self.mox.StubOutWithMock(pkgindex, 'Write')
295 pkgindex.Write(mox.IgnoreArg()) 297 pkgindex.Write(mox.IgnoreArg())
296 self.mox.ReplayAll() 298 self.mox.ReplayAll()
297 f = pkgindex.WriteToNamedTemporaryFile() 299 f = pkgindex.WriteToNamedTemporaryFile()
298 self.assertEqual(f.read(), '') 300 self.assertEqual(f.read(), '')
299 301
300 302
301 if __name__ == '__main__': 303 if __name__ == '__main__':
302 unittest.main() 304 unittest.main()
OLDNEW
« prebuilt.py ('K') | « prebuilt.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698