diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2010-03-23 14:18:44 +0100 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2010-03-23 14:18:44 +0100 |
| commit | 37650a078f5504dfbc6622d2c06f4435a3302dd4 (patch) | |
| tree | 35d7df75535420cbe0712a5f7b7b66d61f5e44d1 /tests/old | |
| parent | 2aa709e41d8896ef897863ea9181c409c4c87a8c (diff) | |
| parent | 3a08cfb10590d5cf5df1f45d94a424ef6a0f674b (diff) | |
| download | python-apt-37650a078f5504dfbc6622d2c06f4435a3302dd4.tar.gz | |
merged from lp:~mvo/python-apt/mvo
Diffstat (limited to 'tests/old')
| -rw-r--r-- | tests/old/__init__.py | 13 | ||||
| -rw-r--r-- | tests/old/apt-test.py | 26 | ||||
| -rw-r--r-- | tests/old/cache.py | 51 | ||||
| -rw-r--r-- | tests/old/depcache.py | 54 | ||||
| -rw-r--r-- | tests/old/hashsum_test.data | 1 | ||||
| -rw-r--r-- | tests/old/hashsum_test_with_zero.data | bin | 0 -> 7 bytes | |||
| -rw-r--r-- | tests/old/lock.py | 47 | ||||
| -rwxr-xr-x | tests/old/memleak.py | 46 | ||||
| -rw-r--r-- | tests/old/pkgproblemresolver.py | 70 | ||||
| -rw-r--r-- | tests/old/pkgrecords.py | 40 | ||||
| -rw-r--r-- | tests/old/pkgsrcrecords.py | 29 | ||||
| -rwxr-xr-x | tests/old/refcount.py | 54 | ||||
| -rwxr-xr-x | tests/old/test_debextract.py | 18 | ||||
| -rw-r--r-- | tests/old/test_enhances.py | 17 | ||||
| -rw-r--r-- | tests/old/test_extract_archive.py | 10 | ||||
| -rw-r--r-- | tests/old/test_hashsums.py | 67 |
16 files changed, 543 insertions, 0 deletions
diff --git a/tests/old/__init__.py b/tests/old/__init__.py new file mode 100644 index 00000000..afd0f074 --- /dev/null +++ b/tests/old/__init__.py @@ -0,0 +1,13 @@ +import os +import unittest + + + +if __name__ == '__main__': + os.chdir(os.path.dirname(__file__)) + print os.getcwd() + + for path in os.listdir('.'): + if path.endswith('.py'): + exec 'from %s import *' % path[:-3] + unittest.main() diff --git a/tests/old/apt-test.py b/tests/old/apt-test.py new file mode 100644 index 00000000..fac2ff43 --- /dev/null +++ b/tests/old/apt-test.py @@ -0,0 +1,26 @@ +import warnings +warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning) +import apt + + +if __name__ == "__main__": + progress = apt.progress.OpTextProgress() + cache = apt.Cache(progress) + print cache + for pkg in cache: + if pkg.isUpgradable: + pkg.markInstall() + for pkg in cache.getChanges(): + #print pkg.Name() + pass + print "Broken: %s " % cache._depcache.BrokenCount + print "InstCount: %s " % cache._depcache.InstCount + + # get a new cache + cache = apt.Cache(progress) + for name in cache.keys(): + import random + 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/old/cache.py b/tests/old/cache.py new file mode 100644 index 00000000..f0bf6761 --- /dev/null +++ b/tests/old/cache.py @@ -0,0 +1,51 @@ +#!/usr/bin/python +# +# Test for the pkgCache code +# + +import apt_pkg +import sys + + +def main(): + apt_pkg.init() + cache = apt_pkg.Cache() + depcache = apt_pkg.DepCache(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) diff --git a/tests/old/depcache.py b/tests/old/depcache.py new file mode 100644 index 00000000..0d59648e --- /dev/null +++ b/tests/old/depcache.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python2.4 +# +# Test for the DepCache code +# + +import apt_pkg +import sys + + +def main(): + apt_pkg.init() + cache = apt_pkg.Cache() + depcache = apt_pkg.DepCache(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 is not 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 "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) diff --git a/tests/old/hashsum_test.data b/tests/old/hashsum_test.data new file mode 100644 index 00000000..19102815 --- /dev/null +++ b/tests/old/hashsum_test.data @@ -0,0 +1 @@ +foo
\ No newline at end of file diff --git a/tests/old/hashsum_test_with_zero.data b/tests/old/hashsum_test_with_zero.data Binary files differnew file mode 100644 index 00000000..2ec9a6df --- /dev/null +++ b/tests/old/hashsum_test_with_zero.data diff --git a/tests/old/lock.py b/tests/old/lock.py new file mode 100644 index 00000000..d45b3964 --- /dev/null +++ b/tests/old/lock.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python2.4 +# +# Test for the pkgCache code +# + +import apt_pkg +import sys +import os + + +if __name__ == "__main__": + lock = "/tmp/test.lck" + + apt_pkg.init() + + # system-lock + apt_pkg.PkgSystemLock() + + pid = os.fork() + if pid == 0: + try: + apt_pkg.PkgSystemLock() + except SystemError, s: + print "Can't get lock: (error text:\n%s)" % s + sys.exit(0) + + apt_pkg.PkgSystemUnLock() + + # low-level lock + 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) + print "Lockfile fd (child): %s" % fd + sys.exit(0) + + # try to get lock with error flag + pid = os.fork() + if pid == 0: + # child + fd = apt_pkg.GetLock(lock, True) + print "Lockfile fd (child): %s" % fd + sys.exit(0) diff --git a/tests/old/memleak.py b/tests/old/memleak.py new file mode 100755 index 00000000..5299f35f --- /dev/null +++ b/tests/old/memleak.py @@ -0,0 +1,46 @@ +#!/usr/bin/python + +import apt +import apt_pkg +import time +import gc +import sys + + +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 +#for i in range(100): +# 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.Cache() + depcache = apt_pkg.DepCache(cache) + records = apt_pkg.PackageRecords(cache) + list = apt_pkg.SourceList() + 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/old/pkgproblemresolver.py b/tests/old/pkgproblemresolver.py new file mode 100644 index 00000000..0d6d0611 --- /dev/null +++ b/tests/old/pkgproblemresolver.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python2.4 +# +# Test for the DepCache code +# + +import apt_pkg +import sys + + +def main(): + apt_pkg.init() + cache = apt_pkg.Cache() + depcache = apt_pkg.DepCache(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 is not None: + depcache.MarkInstall(pkg) + if depcache.BrokenCount > 0: + fixer = apt_pkg.ProblemResolver(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 "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) diff --git a/tests/old/pkgrecords.py b/tests/old/pkgrecords.py new file mode 100644 index 00000000..2fe6ad20 --- /dev/null +++ b/tests/old/pkgrecords.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python2.4 +# +# Test for the PkgSrcRecords code +# it segfaults for python-apt < 0.5.37 +# + +import apt_pkg +import sys + + +def main(): + apt_pkg.init() + cache = apt_pkg.Cache() + depcache = apt_pkg.DepCache(cache) + depcache.Init() + i=0 + print "Running PkgRecords test on all packages:" + for pkg in cache.Packages: + i += 1 + records = apt_pkg.PackageRecords(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) diff --git a/tests/old/pkgsrcrecords.py b/tests/old/pkgsrcrecords.py new file mode 100644 index 00000000..2ea9dd3a --- /dev/null +++ b/tests/old/pkgsrcrecords.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python2.4 +# +# Test for the PkgSrcRecords code +# it segfaults for python-apt < 0.5.37 +# + +import apt_pkg +import sys + + +def main(): + apt_pkg.init() + cache = apt_pkg.Cache() + i=0 + print "Running PkgSrcRecords test on all packages:" + for x in cache.Packages: + i += 1 + src = apt_pkg.SourceRecords() + 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) diff --git a/tests/old/refcount.py b/tests/old/refcount.py new file mode 100755 index 00000000..a29744ae --- /dev/null +++ b/tests/old/refcount.py @@ -0,0 +1,54 @@ +#!/usr/bin/python-dbg + +from pprint import pprint, pformat +import apt +import sys +import gc +import difflib + +# get initial cache +print sys.gettotalrefcount() +progress= apt.progress.OpTextProgress() +c = apt.Cache(progress) +print "refcount after first cache instance: ", sys.gettotalrefcount() + +# test open() +c.open(progress) +print "refcount after cache open: ", sys.gettotalrefcount() +#pprint(sys.getobjects(10)) + +c.open(apt.progress.OpProgress()) +print "refcount after seconf cache open: ", sys.gettotalrefcount() +#pprint(sys.getobjects(10)) + +# FIXME: find a way to get a efficient diff +#before = gc.get_objects() +#c.open(apt.progress.OpProgress()) +#after = gc.get_objects() + + +# test update() +print "refcount before cache.update(): ", sys.gettotalrefcount() +c.update() +gc.collect() +print "refcount after cache.update(): ", sys.gettotalrefcount() +c.update() +gc.collect() +print "refcount after second cache.update(): ", sys.gettotalrefcount() +#pprint(sys.getobjects(20)) + + +# test install() +c.open(apt.progress.OpProgress()) +gc.collect() +print "refcount before cache['hello'].markInstall(): ", sys.gettotalrefcount() +c["hello"].markInstall() +c.commit(apt.progress.FetchProgress(), apt.progress.InstallProgress()) +gc.collect() +print "refcount after: ", sys.gettotalrefcount() +c.open(apt.progress.OpProgress()) +c["hello"].markDelete() +c.commit(apt.progress.FetchProgress(), apt.progress.InstallProgress()) +gc.collect() +print "refcount after: ", sys.gettotalrefcount() +pprint(sys.getobjects(10)) diff --git a/tests/old/test_debextract.py b/tests/old/test_debextract.py new file mode 100755 index 00000000..4ba498ae --- /dev/null +++ b/tests/old/test_debextract.py @@ -0,0 +1,18 @@ +#!/usr/bin/python +import sys + +import apt_inst + + +def Callback(What, Name, Link, Mode, UID, GID, Size, MTime, Major, Minor): + print "%s '%s','%s',%u,%u,%u,%u,%u,%u,%u" % ( + What, Name, Link, Mode, UID, GID, Size, MTime, Major, Minor) + + +def main(): + member = "data.tar.lzma" + if len(sys.argv) > 2: + member = sys.argv[2] + apt_inst.debExtract(open(sys.argv[1]), Callback, member) + +main() diff --git a/tests/old/test_enhances.py b/tests/old/test_enhances.py new file mode 100644 index 00000000..3eced9f9 --- /dev/null +++ b/tests/old/test_enhances.py @@ -0,0 +1,17 @@ +#!/usr/bin/python + +import apt + +cache = apt.Cache() + +for pkg in cache: + if pkg.installed and pkg.installed.enhances: + s = "%s enhances:" % pkg.name + for or_list in pkg.installed.enhances: + for enhances in or_list.or_dependencies: + s += " %s" % enhances.name + if (cache.has_key(enhances.name) and + not cache[enhances.name].isInstalled): + s += "(*missing*) " + s += "," + print s[:-1] diff --git a/tests/old/test_extract_archive.py b/tests/old/test_extract_archive.py new file mode 100644 index 00000000..ce202b06 --- /dev/null +++ b/tests/old/test_extract_archive.py @@ -0,0 +1,10 @@ +#!/usr/bin/python + +import apt +import apt_inst +import os +import sys + +print os.getcwd() +apt_inst.debExtractArchive(open(sys.argv[1]), "/tmp/") +print os.getcwd() diff --git a/tests/old/test_hashsums.py b/tests/old/test_hashsums.py new file mode 100644 index 00000000..0cf6beb7 --- /dev/null +++ b/tests/old/test_hashsums.py @@ -0,0 +1,67 @@ +#!/usr/bin/python + +import unittest +import apt_pkg + + +class testHashes(unittest.TestCase): + " test the hashsum functions against strings and files " + + def testMD5(self): + # simple + s = "foo" + s_md5 = "acbd18db4cc2f85cedef654fccc4a4d8" + res = apt_pkg.md5sum(s) + self.assert_(res == s_md5) + # file + res = apt_pkg.md5sum(open("hashsum_test.data")) + self.assert_(res == s_md5) + # with zero (\0) in the string + s = "foo\0bar" + s_md5 = "f6f5f8cd0cb63668898ba29025ae824e" + res = apt_pkg.md5sum(s) + self.assert_(res == s_md5) + # file + res = apt_pkg.md5sum(open("hashsum_test_with_zero.data")) + self.assert_(res == s_md5) + + def testSHA1(self): + # simple + s = "foo" + s_hash = "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33" + res = apt_pkg.sha1sum(s) + self.assert_(res == s_hash) + # file + res = apt_pkg.sha1sum(open("hashsum_test.data")) + self.assert_(res == s_hash) + # with zero (\0) in the string + s = "foo\0bar" + s_hash = "e2c300a39311a2dfcaff799528415cb74c19317f" + res = apt_pkg.sha1sum(s) + self.assert_(res == s_hash) + # file + res = apt_pkg.sha1sum(open("hashsum_test_with_zero.data")) + self.assert_(res == s_hash) + + def testSHA256(self): + # simple + s = "foo" + s_hash = \ + "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae" + res = apt_pkg.sha256sum(s) + self.assert_(res == s_hash) + # file + res = apt_pkg.sha256sum(open("hashsum_test.data")) + self.assert_(res == s_hash) + # with zero (\0) in the string + s = "foo\0bar" + s_hash = \ + "d6b681bfce7155d44721afb79c296ef4f0fa80a9dd6b43c5cf74dd0f64c85512" + res = apt_pkg.sha256sum(s) + self.assert_(res == s_hash) + # file + res = apt_pkg.sha256sum(open("hashsum_test_with_zero.data")) + self.assert_(res == s_hash) + +if __name__ == "__main__": + unittest.main() |
