diff options
| author | Julian Andres Klode <jak@debian.org> | 2009-01-11 19:30:07 +0100 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2009-01-11 19:30:07 +0100 |
| commit | b237760c6d7009f9833b86e6dbfc3cbf6d059977 (patch) | |
| tree | 19dd8f4f11b1c004a7f9bbb2b9e9f545d0ed2492 /tests | |
| parent | 31cdfa2e20361f76f6e011bbcdad19f9daa1f58f (diff) | |
| parent | 7b14352c54b7acbf2a68240fa960e188c6e8742a (diff) | |
| download | python-apt-b237760c6d7009f9833b86e6dbfc3cbf6d059977.tar.gz | |
Merge Ben Finney's whitespace changes (Closes: #481563)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/apt-test.py | 2 | ||||
| -rw-r--r-- | tests/cache.py | 80 | ||||
| -rw-r--r-- | tests/depcache.py | 78 | ||||
| -rw-r--r-- | tests/lock.py | 16 | ||||
| -rwxr-xr-x | tests/memleak.py | 58 | ||||
| -rw-r--r-- | tests/pkgproblemresolver.py | 111 | ||||
| -rw-r--r-- | tests/pkgrecords.py | 52 | ||||
| -rw-r--r-- | tests/pkgsrcrecords.py | 30 | ||||
| -rwxr-xr-x | tests/refcount.py | 2 | ||||
| -rw-r--r-- | tests/test_aptsources.py | 44 | ||||
| -rw-r--r-- | tests/test_hashsums.py | 7 |
11 files changed, 252 insertions, 228 deletions
diff --git a/tests/apt-test.py b/tests/apt-test.py index 6205cf60..fac2ff43 100644 --- a/tests/apt-test.py +++ b/tests/apt-test.py @@ -20,7 +20,7 @@ if __name__ == "__main__": cache = apt.Cache(progress) for name in cache.keys(): import random - if random.randint(0,1) == 1: + if random.randint(0, 1) == 1: cache[name].markDelete() print "Broken: %s " % cache._depcache.BrokenCount print "DelCount: %s " % cache._depcache.DelCount diff --git a/tests/cache.py b/tests/cache.py index afcad00d..87a544e8 100644 --- a/tests/cache.py +++ b/tests/cache.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.4 +#!/usr/bin/python # # Test for the pkgCache code # @@ -6,44 +6,46 @@ import apt_pkg import sys + def main(): - apt_pkg.init() - cache = apt_pkg.GetCache() - depcache = apt_pkg.GetDepCache(cache) - depcache.Init() - i=0 - all=cache.PackageCount - print "Running Cache test on all packages:" - # first, get all pkgs - for pkg in cache.Packages: - i += 1 - x = pkg.Name - # then get each version - for ver in pkg.VersionList: - # get some version information - a = ver.FileList - b = ver.VerStr - c = ver.Arch - d = ver.DependsListStr - dl = ver.DependsList - # get all dependencies (a dict of string->list, - # e.g. "depends:" -> [ver1,ver2,..] - for dep in dl.keys(): - # get the list of each dependency object - for depVerList in dl[dep]: - for z in depVerList: - # get all TargetVersions of - # the dependency object - for j in z.AllTargets(): - f = j.FileList - g = ver.VerStr - h = ver.Arch - k = ver.DependsListStr - j = ver.DependsList - pass - - print "\r%i/%i=%.3f%% " % (i,all,(float(i)/float(all)*100)), + apt_pkg.init() + cache = apt_pkg.GetCache() + depcache = apt_pkg.GetDepCache(cache) + depcache.Init() + i=0 + all=cache.PackageCount + print "Running Cache test on all packages:" + # first, get all pkgs + for pkg in cache.Packages: + i += 1 + x = pkg.Name + # then get each version + for ver in pkg.VersionList: + # get some version information + a = ver.FileList + b = ver.VerStr + c = ver.Arch + d = ver.DependsListStr + dl = ver.DependsList + # get all dependencies (a dict of string->list, + # e.g. "depends:" -> [ver1,ver2,..] + for dep in dl.keys(): + # get the list of each dependency object + for depVerList in dl[dep]: + for z in depVerList: + # get all TargetVersions of + # the dependency object + for j in z.AllTargets(): + f = j.FileList + g = ver.VerStr + h = ver.Arch + k = ver.DependsListStr + j = ver.DependsList + pass + + print "\r%i/%i=%.3f%% " % (i, all, (float(i) / float(all) * 100)), + if __name__ == "__main__": - main() - sys.exit(0) + main() + sys.exit(0) diff --git a/tests/depcache.py b/tests/depcache.py index 5c78c3a1..b199c812 100644 --- a/tests/depcache.py +++ b/tests/depcache.py @@ -6,47 +6,49 @@ import apt_pkg import sys + def main(): - apt_pkg.init() - cache = apt_pkg.GetCache() - depcache = apt_pkg.GetDepCache(cache) - depcache.Init() - i=0 - all=cache.PackageCount - print "Running DepCache test on all packages" - print "(trying to install each and then mark it keep again):" - # first, get all pkgs - for pkg in cache.Packages: - i += 1 - x = pkg.Name - # then get each version - ver =depcache.GetCandidateVer(pkg) - if ver != None: - depcache.MarkInstall(pkg) - if depcache.InstCount == 0: - if depcache.IsUpgradable(pkg): - print "Error marking %s for install" % x - for p in cache.Packages: - if depcache.MarkedInstall(p): - depcache.MarkKeep(p) - if depcache.InstCount != 0: - print "Error undoing the selection for %s (InstCount: %s)" % (x,depcache.InstCount) - print "\r%i/%i=%.3f%% " % (i,all,(float(i)/float(all)*100)), + apt_pkg.init() + cache = apt_pkg.GetCache() + depcache = apt_pkg.GetDepCache(cache) + depcache.Init() + i=0 + all=cache.PackageCount + print "Running DepCache test on all packages" + print "(trying to install each and then mark it keep again):" + # first, get all pkgs + for pkg in cache.Packages: + i += 1 + x = pkg.Name + # then get each version + ver =depcache.GetCandidateVer(pkg) + if ver != None: + depcache.MarkInstall(pkg) + if depcache.InstCount == 0: + if depcache.IsUpgradable(pkg): + print "Error marking %s for install" % x + for p in cache.Packages: + if depcache.MarkedInstall(p): + depcache.MarkKeep(p) + if depcache.InstCount != 0: + print "Error undoing the selection for %s (InstCount: %s)" % ( + x, depcache.InstCount) + print "\r%i/%i=%.3f%% " % (i, all, (float(i) / float(all) * 100)), - print - print "Trying Upgrade:" - depcache.Upgrade() - print "To install: %s " % depcache.InstCount - print "To remove: %s " % depcache.DelCount - print "Kept back: %s " % depcache.KeepCount + print + print "Trying Upgrade:" + depcache.Upgrade() + print "To install: %s " % depcache.InstCount + print "To remove: %s " % depcache.DelCount + print "Kept back: %s " % depcache.KeepCount - print "Trying DistUpgrade:" - depcache.Upgrade(True) - print "To install: %s " % depcache.InstCount - print "To remove: %s " % depcache.DelCount - print "Kept back: %s " % depcache.KeepCount + print "Trying DistUpgrade:" + depcache.Upgrade(True) + print "To install: %s " % depcache.InstCount + print "To remove: %s " % depcache.DelCount + print "Kept back: %s " % depcache.KeepCount if __name__ == "__main__": - main() - sys.exit(0) + main() + sys.exit(0) diff --git a/tests/lock.py b/tests/lock.py index 86d704ea..d45b3964 100644 --- a/tests/lock.py +++ b/tests/lock.py @@ -4,7 +4,8 @@ # import apt_pkg -import sys, os +import sys +import os if __name__ == "__main__": @@ -21,27 +22,26 @@ if __name__ == "__main__": apt_pkg.PkgSystemLock() except SystemError, s: print "Can't get lock: (error text:\n%s)" % s - sys.exit(0) + sys.exit(0) apt_pkg.PkgSystemUnLock() # low-level lock - fd = apt_pkg.GetLock(lock,True) + fd = apt_pkg.GetLock(lock, True) print "Lockfile fd: %s" % fd # try to get lock without error flag pid = os.fork() if pid == 0: # child - fd = apt_pkg.GetLock(lock,False) + fd = apt_pkg.GetLock(lock, False) print "Lockfile fd (child): %s" % fd - sys.exit(0) + sys.exit(0) # try to get lock with error flag pid = os.fork() if pid == 0: # child - fd = apt_pkg.GetLock(lock,True) + fd = apt_pkg.GetLock(lock, True) print "Lockfile fd (child): %s" % fd - sys.exit(0) - + sys.exit(0) diff --git a/tests/memleak.py b/tests/memleak.py index b5d05afc..659091fc 100755 --- a/tests/memleak.py +++ b/tests/memleak.py @@ -11,36 +11,36 @@ cache = apt.Cache() # memleak for i in range(100): - cache.open(None) - print cache["apt"].name - time.sleep(1) - gc.collect() - f = open("%s" % i,"w") - for obj in gc.get_objects(): - f.write("%s\n" % str(obj)) - f.close() - -# memleak + cache.open(None) + print cache["apt"].name + time.sleep(1) + gc.collect() + f = open("%s" % i, "w") + for obj in gc.get_objects(): + f.write("%s\n" % str(obj)) + f.close() + +# memleak #for i in range(100): -# cache = apt.Cache() -# time.sleep(1) -# cache = None -# gc.collect() +# cache = apt.Cache() +# time.sleep(1) +# cache = None +# gc.collect() # no memleak, but more or less the apt.Cache.open() code for i in range(100): - cache = apt_pkg.GetCache() - depcache = apt_pkg.GetDepCache(cache) - records = apt_pkg.GetPkgRecords(cache) - list = apt_pkg.GetPkgSourceList() - list.ReadMainList() - dict = {} - for pkg in cache.Packages: - if len(pkg.VersionList) > 0: - dict[pkg.Name] = apt.Package(cache,depcache, - records, list, None, pkg) - - print cache["apt"] - time.sleep(1) - - gc.collect() + cache = apt_pkg.GetCache() + depcache = apt_pkg.GetDepCache(cache) + records = apt_pkg.GetPkgRecords(cache) + list = apt_pkg.GetPkgSourceList() + list.ReadMainList() + dict = {} + for pkg in cache.Packages: + if len(pkg.VersionList) > 0: + dict[pkg.Name] = apt.Package(cache, depcache, + records, list, None, pkg) + + print cache["apt"] + time.sleep(1) + + gc.collect() diff --git a/tests/pkgproblemresolver.py b/tests/pkgproblemresolver.py index 0ed32ea6..7d5ae682 100644 --- a/tests/pkgproblemresolver.py +++ b/tests/pkgproblemresolver.py @@ -6,64 +6,65 @@ import apt_pkg import sys + def main(): - apt_pkg.init() - cache = apt_pkg.GetCache() - depcache = apt_pkg.GetDepCache(cache) - depcache.Init() - i=0 - all=cache.PackageCount - print "Running DepCache test on all packages" - print "(trying to install each and then mark it keep again):" - # first, get all pkgs - for pkg in cache.Packages: - i += 1 - x = pkg.Name - # then get each version - ver =depcache.GetCandidateVer(pkg) - if ver != None: - depcache.MarkInstall(pkg) - if depcache.BrokenCount > 0: - fixer = apt_pkg.GetPkgProblemResolver(depcache) - fixer.Clear(pkg) - fixer.Protect(pkg) - # we first try to resolve the problem - # with the package that should be installed - # protected - try: - fixer.Resolve(True) - except SystemError: - # the pkg seems to be broken, the - # returns a exception - fixer.Clear(pkg) - fixer.Resolve(True) - if not depcache.MarkedInstall(pkg): - print "broken in archive: %s " % pkg.Name - fixer = None - if depcache.InstCount == 0: - if depcache.IsUpgradable(pkg): - print "Error marking %s for install" % x - for p in cache.Packages: - if depcache.MarkedInstall(p) or depcache.MarkedUpgrade(p): - depcache.MarkKeep(p) - if depcache.InstCount != 0: - print "Error undoing the selection for %s" % x - print "\r%i/%i=%.3f%% " % (i,all,(float(i)/float(all)*100)), + apt_pkg.init() + cache = apt_pkg.GetCache() + depcache = apt_pkg.GetDepCache(cache) + depcache.Init() + i=0 + all=cache.PackageCount + print "Running DepCache test on all packages" + print "(trying to install each and then mark it keep again):" + # first, get all pkgs + for pkg in cache.Packages: + i += 1 + x = pkg.Name + # then get each version + ver =depcache.GetCandidateVer(pkg) + if ver != None: + depcache.MarkInstall(pkg) + if depcache.BrokenCount > 0: + fixer = apt_pkg.GetPkgProblemResolver(depcache) + fixer.Clear(pkg) + fixer.Protect(pkg) + # we first try to resolve the problem + # with the package that should be installed + # protected + try: + fixer.Resolve(True) + except SystemError: + # the pkg seems to be broken, the + # returns a exception + fixer.Clear(pkg) + fixer.Resolve(True) + if not depcache.MarkedInstall(pkg): + print "broken in archive: %s " % pkg.Name + fixer = None + if depcache.InstCount == 0: + if depcache.IsUpgradable(pkg): + print "Error marking %s for install" % x + for p in cache.Packages: + if depcache.MarkedInstall(p) or depcache.MarkedUpgrade(p): + depcache.MarkKeep(p) + if depcache.InstCount != 0: + print "Error undoing the selection for %s" % x + print "\r%i/%i=%.3f%% " % (i, all, (float(i) / float(all) * 100)), - print - print "Trying Upgrade:" - depcache.Upgrade() - print "To install: %s " % depcache.InstCount - print "To remove: %s " % depcache.DelCount - print "Kept back: %s " % depcache.KeepCount + print + print "Trying Upgrade:" + depcache.Upgrade() + print "To install: %s " % depcache.InstCount + print "To remove: %s " % depcache.DelCount + print "Kept back: %s " % depcache.KeepCount - print "Trying DistUpgrade:" - depcache.Upgrade(True) - print "To install: %s " % depcache.InstCount - print "To remove: %s " % depcache.DelCount - print "Kept back: %s " % depcache.KeepCount + print "Trying DistUpgrade:" + depcache.Upgrade(True) + print "To install: %s " % depcache.InstCount + print "To remove: %s " % depcache.DelCount + print "Kept back: %s " % depcache.KeepCount if __name__ == "__main__": - main() - sys.exit(0) + main() + sys.exit(0) diff --git a/tests/pkgrecords.py b/tests/pkgrecords.py index 43723569..5866847d 100644 --- a/tests/pkgrecords.py +++ b/tests/pkgrecords.py @@ -7,30 +7,34 @@ import apt_pkg import sys + def main(): - apt_pkg.init() - cache = apt_pkg.GetCache() - depcache = apt_pkg.GetDepCache(cache) - depcache.Init() - i=0 - print "Running PkgRecords test on all packages:" - for pkg in cache.Packages: - i += 1 - records = apt_pkg.GetPkgRecords(cache) - if len(pkg.VersionList) == 0: - #print "no available version, cruft" - continue - version = depcache.GetCandidateVer(pkg) - if not version: - continue - file, index = version.FileList.pop(0) - if records.Lookup((file,index)): - #print records.FileName - x = records.FileName - y = records.LongDesc - pass - print "\r%i/%i=%.3f%% " % (i,cache.PackageCount, (float(i)/float(cache.PackageCount)*100)), + apt_pkg.init() + cache = apt_pkg.GetCache() + depcache = apt_pkg.GetDepCache(cache) + depcache.Init() + i=0 + print "Running PkgRecords test on all packages:" + for pkg in cache.Packages: + i += 1 + records = apt_pkg.GetPkgRecords(cache) + if len(pkg.VersionList) == 0: + #print "no available version, cruft" + continue + version = depcache.GetCandidateVer(pkg) + if not version: + continue + file, index = version.FileList.pop(0) + if records.Lookup((file, index)): + #print records.FileName + x = records.FileName + y = records.LongDesc + pass + print "\r%i/%i=%.3f%% " % ( + i, cache.PackageCount, + (float(i) / float(cache.PackageCount) * 100)), + if __name__ == "__main__": - main() - sys.exit(0) + main() + sys.exit(0) diff --git a/tests/pkgsrcrecords.py b/tests/pkgsrcrecords.py index 06c4a1ef..77670540 100644 --- a/tests/pkgsrcrecords.py +++ b/tests/pkgsrcrecords.py @@ -7,19 +7,23 @@ import apt_pkg import sys + def main(): - apt_pkg.init() - cache = apt_pkg.GetCache() - i=0 - print "Running PkgSrcRecords test on all packages:" - for x in cache.Packages: - i += 1 - src = apt_pkg.GetPkgSrcRecords() - if src.Lookup(x.Name): - #print src.Package - pass - print "\r%i/%i=%.3f%% " % (i,cache.PackageCount, (float(i)/float(cache.PackageCount)*100)), + apt_pkg.init() + cache = apt_pkg.GetCache() + i=0 + print "Running PkgSrcRecords test on all packages:" + for x in cache.Packages: + i += 1 + src = apt_pkg.GetPkgSrcRecords() + if src.Lookup(x.Name): + #print src.Package + pass + print "\r%i/%i=%.3f%% " % ( + i, cache.PackageCount, + (float(i) / float(cache.PackageCount) * 100)), + if __name__ == "__main__": - main() - sys.exit(0) + main() + sys.exit(0) diff --git a/tests/refcount.py b/tests/refcount.py index f3230bd3..a29744ae 100755 --- a/tests/refcount.py +++ b/tests/refcount.py @@ -1,6 +1,6 @@ #!/usr/bin/python-dbg -from pprint import pprint,pformat +from pprint import pprint, pformat import apt import sys import gc diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py index c8d84395..3761f3ff 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -1,31 +1,35 @@ #!/usr/bin/env python import unittest -import apt_pkg import os import copy - import sys + sys.path.insert(0, "../") +import apt_pkg import aptsources import aptsources.sourceslist import aptsources.distro + class TestAptSources(unittest.TestCase): + def __init__(self, methodName): unittest.TestCase.__init__(self, methodName) apt_pkg.init() apt_pkg.Config.Set("Dir::Etc", os.getcwd()) - apt_pkg.Config.Set("Dir::Etc::sourceparts","/xxx") + apt_pkg.Config.Set("Dir::Etc::sourceparts", "/xxx") def testIsMirror(self): - self.assertTrue(aptsources.sourceslist.is_mirror("http://archive.ubuntu.com", - "http://de.archive.ubuntu.com")) - self.assertFalse(aptsources.sourceslist.is_mirror("http://archive.ubuntu.com", - "http://ftp.debian.org")) + yes = aptsources.sourceslist.is_mirror("http://archive.ubuntu.com", + "http://de.archive.ubuntu.com") + no = aptsources.sourceslist.is_mirror("http://archive.ubuntu.com", + "http://ftp.debian.org") + self.assertTrue(yes) + self.assertFalse(no) def testSourcesListReading(self): - apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list") + apt_pkg.Config.Set("Dir::Etc::sourcelist", "data/sources.list") sources = aptsources.sourceslist.SourcesList() self.assertEqual(len(sources.list), 6) # test load @@ -34,22 +38,22 @@ class TestAptSources(unittest.TestCase): self.assertEqual(len(sources.list), 6) def testSourcesListAdding(self): - apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list") + apt_pkg.Config.Set("Dir::Etc::sourcelist", "data/sources.list") sources = aptsources.sourceslist.SourcesList() # test to add something that is already there (main) before = copy.deepcopy(sources) - sources.add("deb","http://de.archive.ubuntu.com/ubuntu/", + sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", "edgy", ["main"]) self.assertTrue(sources.list == before.list) # test to add something that is already there (restricted) before = copy.deepcopy(sources) - sources.add("deb","http://de.archive.ubuntu.com/ubuntu/", + sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", "edgy", ["restricted"]) self.assertTrue(sources.list == before.list) # test to add something new: multiverse - sources.add("deb","http://de.archive.ubuntu.com/ubuntu/", + sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", "edgy", ["multiverse"]) found = False @@ -63,7 +67,7 @@ class TestAptSources(unittest.TestCase): # test to add something new: multiverse *and* # something that is already there before = copy.deepcopy(sources) - sources.add("deb","http://de.archive.ubuntu.com/ubuntu/", + sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", "edgy", ["universe", "something"]) found_universe = 0 @@ -82,7 +86,8 @@ class TestAptSources(unittest.TestCase): self.assertEqual(found_universe, 1) def testMatcher(self): - apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list.testDistribution") + apt_pkg.Config.Set("Dir::Etc::sourcelist", "data/sources.list.test" + "Distribution") sources = aptsources.sourceslist.SourcesList() distro = aptsources.distro.get_distro() distro.get_sources(sources) @@ -93,7 +98,8 @@ class TestAptSources(unittest.TestCase): self.fail("source entry '%s' has no matcher" % s) def testDistribution(self): - apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list.testDistribution") + apt_pkg.Config.Set("Dir::Etc::sourcelist", "data/sources.list.test" + "Distribution") sources = aptsources.sourceslist.SourcesList() distro = aptsources.distro.get_distro() distro.get_sources(sources) @@ -103,7 +109,8 @@ class TestAptSources(unittest.TestCase): if s.template: dist_templates.add(s.template.name) #print dist_templates - for d in ["hardy","hardy-security","hardy-updates","intrepid","hardy-backports"]: + for d in ("hardy", "hardy-security", "hardy-updates", "intrepid", + "hardy-backports"): self.assertTrue(d in dist_templates) # test enable comp = "restricted" @@ -115,7 +122,7 @@ class TestAptSources(unittest.TestCase): "edgy" in entry.dist): for c in entry.comps: if c == comp: - if not found.has_key(entry.dist): + if not entry.dist in found: found[entry.dist] = 0 found[entry.dist] += 1 #print "".join([s.str() for s in sources]) @@ -132,12 +139,13 @@ class TestAptSources(unittest.TestCase): entry.template.name == "edgy"): for c in entry.comps: if c == comp: - if not found.has_key(entry.dist): + if not entry.dist in found.has_key: found[entry.dist] = 0 found[entry.dist] += 1 #print "".join([s.str() for s in sources]) for key in found: self.assertEqual(found[key], 1) + if __name__ == "__main__": unittest.main() diff --git a/tests/test_hashsums.py b/tests/test_hashsums.py index 7fa6eb60..0cf6beb7 100644 --- a/tests/test_hashsums.py +++ b/tests/test_hashsums.py @@ -3,6 +3,7 @@ import unittest import apt_pkg + class testHashes(unittest.TestCase): " test the hashsum functions against strings and files " @@ -45,7 +46,8 @@ class testHashes(unittest.TestCase): def testSHA256(self): # simple s = "foo" - s_hash = "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae" + s_hash = \ + "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae" res = apt_pkg.sha256sum(s) self.assert_(res == s_hash) # file @@ -53,7 +55,8 @@ class testHashes(unittest.TestCase): self.assert_(res == s_hash) # with zero (\0) in the string s = "foo\0bar" - s_hash = "d6b681bfce7155d44721afb79c296ef4f0fa80a9dd6b43c5cf74dd0f64c85512" + s_hash = \ + "d6b681bfce7155d44721afb79c296ef4f0fa80a9dd6b43c5cf74dd0f64c85512" res = apt_pkg.sha256sum(s) self.assert_(res == s_hash) # file |
