diff options
Diffstat (limited to 'tests/old')
-rw-r--r-- | tests/old/__init__.py | 11 | ||||
-rw-r--r-- | tests/old/apt-test.py | 27 | ||||
-rw-r--r-- | tests/old/cache.py | 51 | ||||
-rw-r--r-- | tests/old/depcache.py | 57 | ||||
-rw-r--r-- | tests/old/lock.py | 47 | ||||
-rw-r--r-- | tests/old/memleak.py | 45 | ||||
-rw-r--r-- | tests/old/pkgproblemresolver.py | 71 | ||||
-rw-r--r-- | tests/old/pkgrecords.py | 41 | ||||
-rw-r--r-- | tests/old/pkgsrcrecords.py | 31 | ||||
-rwxr-xr-x | tests/old/refcount.py | 54 | ||||
-rw-r--r-- | tests/old/test_enhances.py | 16 |
11 files changed, 451 insertions, 0 deletions
diff --git a/tests/old/__init__.py b/tests/old/__init__.py new file mode 100644 index 0000000..5311641 --- /dev/null +++ b/tests/old/__init__.py @@ -0,0 +1,11 @@ +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 0000000..8c66aeb --- /dev/null +++ b/tests/old/apt-test.py @@ -0,0 +1,27 @@ +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.is_upgradable: + pkg.mark_install() + for pkg in cache.get_changes(): + # print pkg.name() + pass + print("Broken: %s " % cache._depcache.broken_count) + print("inst_count: %s " % cache._depcache.inst_count) + + # get a new cache + cache = apt.Cache(progress) + for name in cache.keys(): + import random + + if random.randint(0, 1) == 1: + cache[name].mark_delete() + print("Broken: %s " % cache._depcache.broken_count) + print("del_count: %s " % cache._depcache.del_count) diff --git a/tests/old/cache.py b/tests/old/cache.py new file mode 100644 index 0000000..3f4aa0c --- /dev/null +++ b/tests/old/cache.py @@ -0,0 +1,51 @@ +#!/usr/bin/python3 +# +# Test for the pkgCache code +# + +import sys + +import apt_pkg + + +def main(): + apt_pkg.init() + cache = apt_pkg.Cache() + depcache = apt_pkg.DepCache(cache) + depcache.init() + i = 0 + all = cache.package_count + print("Running Cache test on all packages:") + # first, get all pkgs + for pkg in cache.packages: + i += 1 + pkg.name + # then get each version + for ver in pkg.version_list: + # get some version information + ver.file_list + ver.ver_str + ver.arch + ver.depends_listStr + dl = ver.depends_list + # 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.all_targets(): + j.file_list + ver.ver_str + ver.arch + ver.depends_listStr + j = ver.depends_list + + 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 0000000..81ca574 --- /dev/null +++ b/tests/old/depcache.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python2.4 +# +# Test for the DepCache code +# + +import sys + +import apt_pkg + + +def main(): + apt_pkg.init() + cache = apt_pkg.Cache() + depcache = apt_pkg.DepCache(cache) + depcache.init() + i = 0 + all = cache.package_count + 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.get_candidate_ver(pkg) + if ver is not None: + depcache.mark_install(pkg) + if depcache.inst_count == 0: + if depcache.is_upgradable(pkg): + print("Error marking %s for install" % x) + for p in cache.packages: + if depcache.marked_install(p): + depcache.mark_keep(p) + if depcache.inst_count != 0: + print( + "Error undoing the selection for %s (inst_count: %s)" + % (x, depcache.inst_count) + ) + print("\r%i/%i=%.3f%% " % (i, all, (float(i) / float(all) * 100))) + + print() + print("Trying upgrade:") + depcache.upgrade() + print("To install: %s " % depcache.inst_count) + print("To remove: %s " % depcache.del_count) + print("Kept back: %s " % depcache.keep_count) + + print("Trying DistUpgrade:") + depcache.upgrade(True) + print("To install: %s " % depcache.inst_count) + print("To remove: %s " % depcache.del_count) + print("Kept back: %s " % depcache.keep_count) + + +if __name__ == "__main__": + main() + sys.exit(0) diff --git a/tests/old/lock.py b/tests/old/lock.py new file mode 100644 index 0000000..c09983c --- /dev/null +++ b/tests/old/lock.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python2.4 +# +# Test for the pkgCache code +# + +import os +import sys + +import apt_pkg + +if __name__ == "__main__": + lock = "/tmp/test.lck" + + apt_pkg.init() + + # system-lock + apt_pkg.pkgsystem_lock() + + pid = os.fork() + if pid == 0: + try: + apt_pkg.pkgsystem_lock() + except SystemError as s: + print("Can't get lock: (error text:\n%s)" % s) + sys.exit(0) + + apt_pkg.pkgsystem_unlock() + + # low-level lock + fd = apt_pkg.get_lock(lock, True) + print("Lockfile fd: %s" % fd) + + # try to get lock without error flag + pid = os.fork() + if pid == 0: + # child + fd = apt_pkg.get_lock(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.get_lock(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 100644 index 0000000..44b123e --- /dev/null +++ b/tests/old/memleak.py @@ -0,0 +1,45 @@ +#!/usr/bin/python3 + +import gc +import time + +import apt_pkg + +import apt + +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.read_main_list() + dict = {} + for pkg in cache.packages: + if len(pkg.version_list) > 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 0000000..89190cf --- /dev/null +++ b/tests/old/pkgproblemresolver.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python2.4 +# +# Test for the DepCache code +# + +import sys + +import apt_pkg + + +def main(): + apt_pkg.init() + cache = apt_pkg.Cache() + depcache = apt_pkg.DepCache(cache) + depcache.init() + i = 0 + all = cache.package_count + 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.get_candidate_ver(pkg) + if ver is not None: + depcache.mark_install(pkg) + if depcache.broken_count > 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.marked_install(pkg): + print("broken in archive: %s " % pkg.name) + fixer = None + if depcache.inst_count == 0: + if depcache.is_upgradable(pkg): + print("Error marking %s for install" % x) + for p in cache.packages: + if depcache.marked_install(p) or depcache.marked_upgrade(p): + depcache.mark_keep(p) + if depcache.inst_count != 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.inst_count) + print("To remove: %s " % depcache.del_count) + print("Kept back: %s " % depcache.keep_count) + + print("Trying DistUpgrade:") + depcache.upgrade(True) + print("To install: %s " % depcache.inst_count) + print("To remove: %s " % depcache.del_count) + print("Kept back: %s " % depcache.keep_count) + + +if __name__ == "__main__": + main() + sys.exit(0) diff --git a/tests/old/pkgrecords.py b/tests/old/pkgrecords.py new file mode 100644 index 0000000..b6be005 --- /dev/null +++ b/tests/old/pkgrecords.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python2.4 +# +# Test for the PkgSrcRecords code +# it segfaults for python-apt < 0.5.37 +# + +import sys + +import apt_pkg + + +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.version_list) == 0: + # print "no available version, cruft" + continue + version = depcache.get_candidate_ver(pkg) + if not version: + continue + file, index = version.file_list.pop(0) + if records.lookup((file, index)): + # print records.filename + records.filename + records.long_desc + print( + "\r%i/%i=%.3f%% " + % (i, cache.package_count, (float(i) / float(cache.package_count) * 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 0000000..ccf791f --- /dev/null +++ b/tests/old/pkgsrcrecords.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python2.4 +# +# Test for the PkgSrcRecords code +# it segfaults for python-apt < 0.5.37 +# + +import sys + +import apt_pkg + + +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.package_count, (float(i) / float(cache.package_count) * 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 0000000..0fad676 --- /dev/null +++ b/tests/old/refcount.py @@ -0,0 +1,54 @@ +#!/usr/bin/python-dbg + +import gc +import sys +from pprint import pprint + +import apt + +# 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'].mark_install(): ", sys.gettotalrefcount()) +c["hello"].mark_install() +c.commit(apt.progress.FetchProgress(), apt.progress.InstallProgress()) +gc.collect() +print("refcount after: ", sys.gettotalrefcount()) +c.open(apt.progress.OpProgress()) +c["hello"].mark_delete() +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_enhances.py b/tests/old/test_enhances.py new file mode 100644 index 0000000..79aad9a --- /dev/null +++ b/tests/old/test_enhances.py @@ -0,0 +1,16 @@ +#!/usr/bin/python3 + +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 enhances.name in cache and not cache[enhances.name].is_installed: + s += "(*missing*) " + s += "," + print(s[:-1]) |