From cbd822c9dfe8cf18d828bd558290f15775b4d837 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 17 Jul 2009 19:40:47 +0200 Subject: tests: First work on the new testsuite. The module tests.test_all will run all available tests. Each test placed herein must be using unittest and provide at least 1 test case. It must be prefixed with test_. --- tests/__init__.py | 1 + tests/apt-test.py | 26 ----- tests/cache.py | 51 --------- tests/data/sources.list | 6 -- tests/data/sources.list.testDistribution | 13 --- tests/depcache.py | 54 ---------- tests/getcache_mem_corruption.py | 24 ----- tests/hashsum_test.data | 1 - tests/hashsum_test_with_zero.data | Bin 7 -> 0 bytes tests/lock.py | 47 --------- tests/memleak.py | 46 -------- tests/old/__init__.py | 13 +++ tests/old/apt-test.py | 26 +++++ tests/old/cache.py | 51 +++++++++ tests/old/data/sources.list | 6 ++ tests/old/data/sources.list.testDistribution | 13 +++ tests/old/depcache.py | 54 ++++++++++ tests/old/getcache_mem_corruption.py | 24 +++++ tests/old/hashsum_test.data | 1 + tests/old/hashsum_test_with_zero.data | Bin 0 -> 7 bytes tests/old/lock.py | 47 +++++++++ tests/old/memleak.py | 46 ++++++++ tests/old/pkgproblemresolver.py | 70 +++++++++++++ tests/old/pkgrecords.py | 40 +++++++ tests/old/pkgsrcrecords.py | 29 +++++ tests/old/refcount.py | 54 ++++++++++ tests/old/test-data-ports/sources.list | 59 +++++++++++ tests/old/test_aptsources.py | 151 +++++++++++++++++++++++++++ tests/old/test_aptsources_ports.py | 41 ++++++++ tests/old/test_debextract.py | 18 ++++ tests/old/test_extract_archive.py | 10 ++ tests/old/test_hashsums.py | 67 ++++++++++++ tests/pkgproblemresolver.py | 70 ------------- tests/pkgrecords.py | 40 ------- tests/pkgsrcrecords.py | 29 ----- tests/refcount.py | 54 ---------- tests/test-data-ports/sources.list | 59 ----------- tests/test_all.py | 17 +++ tests/test_aptsources.py | 151 --------------------------- tests/test_aptsources_ports.py | 41 -------- tests/test_debextract.py | 18 ---- tests/test_extract_archive.py | 10 -- tests/test_hashes.py | 93 +++++++++++++++++ tests/test_hashsums.py | 67 ------------ 44 files changed, 931 insertions(+), 807 deletions(-) create mode 100644 tests/__init__.py delete mode 100644 tests/apt-test.py delete mode 100644 tests/cache.py delete mode 100644 tests/data/sources.list delete mode 100644 tests/data/sources.list.testDistribution delete mode 100644 tests/depcache.py delete mode 100644 tests/getcache_mem_corruption.py delete mode 100644 tests/hashsum_test.data delete mode 100644 tests/hashsum_test_with_zero.data delete mode 100644 tests/lock.py delete mode 100755 tests/memleak.py create mode 100644 tests/old/__init__.py create mode 100644 tests/old/apt-test.py create mode 100644 tests/old/cache.py create mode 100644 tests/old/data/sources.list create mode 100644 tests/old/data/sources.list.testDistribution create mode 100644 tests/old/depcache.py create mode 100644 tests/old/getcache_mem_corruption.py create mode 100644 tests/old/hashsum_test.data create mode 100644 tests/old/hashsum_test_with_zero.data create mode 100644 tests/old/lock.py create mode 100755 tests/old/memleak.py create mode 100644 tests/old/pkgproblemresolver.py create mode 100644 tests/old/pkgrecords.py create mode 100644 tests/old/pkgsrcrecords.py create mode 100755 tests/old/refcount.py create mode 100644 tests/old/test-data-ports/sources.list create mode 100644 tests/old/test_aptsources.py create mode 100644 tests/old/test_aptsources_ports.py create mode 100755 tests/old/test_debextract.py create mode 100644 tests/old/test_extract_archive.py create mode 100644 tests/old/test_hashsums.py delete mode 100644 tests/pkgproblemresolver.py delete mode 100644 tests/pkgrecords.py delete mode 100644 tests/pkgsrcrecords.py delete mode 100755 tests/refcount.py delete mode 100644 tests/test-data-ports/sources.list create mode 100644 tests/test_all.py delete mode 100644 tests/test_aptsources.py delete mode 100644 tests/test_aptsources_ports.py delete mode 100755 tests/test_debextract.py delete mode 100644 tests/test_extract_archive.py create mode 100644 tests/test_hashes.py delete mode 100644 tests/test_hashsums.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/apt-test.py b/tests/apt-test.py deleted file mode 100644 index fac2ff43..00000000 --- a/tests/apt-test.py +++ /dev/null @@ -1,26 +0,0 @@ -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/cache.py b/tests/cache.py deleted file mode 100644 index f0bf6761..00000000 --- a/tests/cache.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/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/data/sources.list b/tests/data/sources.list deleted file mode 100644 index 5481d4f0..00000000 --- a/tests/data/sources.list +++ /dev/null @@ -1,6 +0,0 @@ -# comment 1 -deb http://de.archive.ubuntu.com/ubuntu/ edgy main -# comment 2 -deb http://de.archive.ubuntu.com/ubuntu/ edgy restricted -# comment 3 -deb http://de.archive.ubuntu.com/ubuntu/ edgy universe \ No newline at end of file diff --git a/tests/data/sources.list.testDistribution b/tests/data/sources.list.testDistribution deleted file mode 100644 index 0f40e85a..00000000 --- a/tests/data/sources.list.testDistribution +++ /dev/null @@ -1,13 +0,0 @@ -deb http://de.archive.ubuntu.com/ubuntu/ hardy main -deb http://de.archive.ubuntu.com/ubuntu/ hardy restricted -deb http://de.archive.ubuntu.com/ubuntu/ hardy universe -deb http://de.archive.ubuntu.com/ubuntu/ hardy-updates universe multiverse -deb http://de.archive.ubuntu.com/ubuntu/ hardy-updates restricted -deb http://de.archive.ubuntu.com/ubuntu/ hardy-security main -deb http://de.archive.ubuntu.com/ubuntu/ hardy-security multiverse -deb http://ftp.debian.org/debian sid main -deb http://ubuntu.cs.uaf.edu/ubuntu/ hardy main -deb http://ubuntu.cs.uaf.edu/ubuntu/ hardy-backports main -deb http://archive.ubuntu.com/ubuntu/ intrepid main -deb cdrom:[Ubuntu 8.10 _Intrepid Ibex_ - Alpha]/ intrepid main -deb cdrom:[Ubuntu 8.04 _Hardy Heron_] hardy main \ No newline at end of file diff --git a/tests/depcache.py b/tests/depcache.py deleted file mode 100644 index 0d59648e..00000000 --- a/tests/depcache.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/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/getcache_mem_corruption.py b/tests/getcache_mem_corruption.py deleted file mode 100644 index c6e5ff80..00000000 --- a/tests/getcache_mem_corruption.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/python -import apt -import apt_pkg -import re - -import unittest - -class TestGetCache(unittest.TestCase): - - def setUp(self): - apt_pkg.InitConfig() - apt_pkg.InitSystem() - - def testWrongInvocation(self): - # wrongly invoke GetCache() rather than GetDepCache() - apt_cache = apt_pkg.Cache() - self.assertRaises(ValueError, apt_pkg.Cache, apt_cache) - - def testProperInvocation(self): - apt_cache = apt_pkg.Cache(apt.progress.OpTextProgress()) - apt_depcache = apt_pkg.DepCache(apt_cache) - -if __name__ == "__main__": - unittest.main() diff --git a/tests/hashsum_test.data b/tests/hashsum_test.data deleted file mode 100644 index 19102815..00000000 --- a/tests/hashsum_test.data +++ /dev/null @@ -1 +0,0 @@ -foo \ No newline at end of file diff --git a/tests/hashsum_test_with_zero.data b/tests/hashsum_test_with_zero.data deleted file mode 100644 index 2ec9a6df..00000000 Binary files a/tests/hashsum_test_with_zero.data and /dev/null differ diff --git a/tests/lock.py b/tests/lock.py deleted file mode 100644 index d45b3964..00000000 --- a/tests/lock.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/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/memleak.py b/tests/memleak.py deleted file mode 100755 index 5299f35f..00000000 --- a/tests/memleak.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/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/__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/data/sources.list b/tests/old/data/sources.list new file mode 100644 index 00000000..5481d4f0 --- /dev/null +++ b/tests/old/data/sources.list @@ -0,0 +1,6 @@ +# comment 1 +deb http://de.archive.ubuntu.com/ubuntu/ edgy main +# comment 2 +deb http://de.archive.ubuntu.com/ubuntu/ edgy restricted +# comment 3 +deb http://de.archive.ubuntu.com/ubuntu/ edgy universe \ No newline at end of file diff --git a/tests/old/data/sources.list.testDistribution b/tests/old/data/sources.list.testDistribution new file mode 100644 index 00000000..0f40e85a --- /dev/null +++ b/tests/old/data/sources.list.testDistribution @@ -0,0 +1,13 @@ +deb http://de.archive.ubuntu.com/ubuntu/ hardy main +deb http://de.archive.ubuntu.com/ubuntu/ hardy restricted +deb http://de.archive.ubuntu.com/ubuntu/ hardy universe +deb http://de.archive.ubuntu.com/ubuntu/ hardy-updates universe multiverse +deb http://de.archive.ubuntu.com/ubuntu/ hardy-updates restricted +deb http://de.archive.ubuntu.com/ubuntu/ hardy-security main +deb http://de.archive.ubuntu.com/ubuntu/ hardy-security multiverse +deb http://ftp.debian.org/debian sid main +deb http://ubuntu.cs.uaf.edu/ubuntu/ hardy main +deb http://ubuntu.cs.uaf.edu/ubuntu/ hardy-backports main +deb http://archive.ubuntu.com/ubuntu/ intrepid main +deb cdrom:[Ubuntu 8.10 _Intrepid Ibex_ - Alpha]/ intrepid main +deb cdrom:[Ubuntu 8.04 _Hardy Heron_] hardy main \ No newline at end of file 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/getcache_mem_corruption.py b/tests/old/getcache_mem_corruption.py new file mode 100644 index 00000000..c6e5ff80 --- /dev/null +++ b/tests/old/getcache_mem_corruption.py @@ -0,0 +1,24 @@ +#!/usr/bin/python +import apt +import apt_pkg +import re + +import unittest + +class TestGetCache(unittest.TestCase): + + def setUp(self): + apt_pkg.InitConfig() + apt_pkg.InitSystem() + + def testWrongInvocation(self): + # wrongly invoke GetCache() rather than GetDepCache() + apt_cache = apt_pkg.Cache() + self.assertRaises(ValueError, apt_pkg.Cache, apt_cache) + + def testProperInvocation(self): + apt_cache = apt_pkg.Cache(apt.progress.OpTextProgress()) + apt_depcache = apt_pkg.DepCache(apt_cache) + +if __name__ == "__main__": + unittest.main() 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 new file mode 100644 index 00000000..2ec9a6df Binary files /dev/null and b/tests/old/hashsum_test_with_zero.data differ 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-data-ports/sources.list b/tests/old/test-data-ports/sources.list new file mode 100644 index 00000000..a6b2f6ed --- /dev/null +++ b/tests/old/test-data-ports/sources.list @@ -0,0 +1,59 @@ +# +# deb cdrom:[Ubuntu-Server 8.04.1 _Hardy Heron_ - Release powerpc (20080703)]/ hardy main restricted + +# deb cdrom:[Ubuntu-Server 8.04.1 _Hardy Heron_ - Release powerpc (20080703)]/ hardy main restricted +# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to +# newer versions of the distribution. + +deb http://ports.ubuntu.com/ubuntu-ports/ hardy main restricted +deb-src http://archive.ubuntu.com/ubuntu hardy main restricted + +## Major bug fix updates produced after the final release of the +## distribution. +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-updates main restricted +deb-src http://archive.ubuntu.com/ubuntu hardy-updates main restricted + +## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu +## team, and may not be under a free licence. Please satisfy yourself as to +## your rights to use the software. Also, please note that software in +## universe WILL NOT receive any review or updates from the Ubuntu security +## team. +deb http://ports.ubuntu.com/ubuntu-ports/ hardy universe +deb-src http://archive.ubuntu.com/ubuntu hardy universe +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-updates universe +deb-src http://archive.ubuntu.com/ubuntu hardy-updates universe + +## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu +## team, and may not be under a free licence. Please satisfy yourself as to +## your rights to use the software. Also, please note that software in +## multiverse WILL NOT receive any review or updates from the Ubuntu +## security team. +deb http://ports.ubuntu.com/ubuntu-ports/ hardy multiverse +deb-src http://archive.ubuntu.com/ubuntu hardy multiverse +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-updates multiverse +deb-src http://archive.ubuntu.com/ubuntu hardy-updates multiverse + +## Uncomment the following two lines to add software from the 'backports' +## repository. +## N.B. software from this repository may not have been tested as +## extensively as that contained in the main release, although it includes +## newer versions of some applications which may provide useful features. +## Also, please note that software in backports WILL NOT receive any review +## or updates from the Ubuntu security team. +# deb http://ports.ubuntu.com/ubuntu-ports/ hardy-backports main restricted universe multiverse +# deb-src http://archive.ubuntu.com/ubuntu hardy-backports main restricted universe multiverse + +## Uncomment the following two lines to add software from Canonical's +## 'partner' repository. This software is not part of Ubuntu, but is +## offered by Canonical and the respective vendors as a service to Ubuntu +## users. +# deb http://archive.canonical.com/ubuntu hardy partner +# deb-src http://archive.canonical.com/ubuntu hardy partner + +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ hardy-security main restricted +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ hardy-security universe +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ hardy-security multiverse +deb-src http://archive.ubuntu.com/ubuntu/ hardy-proposed restricted main multiverse universe diff --git a/tests/old/test_aptsources.py b/tests/old/test_aptsources.py new file mode 100644 index 00000000..3761f3ff --- /dev/null +++ b/tests/old/test_aptsources.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python + +import unittest +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") + + def testIsMirror(self): + 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") + sources = aptsources.sourceslist.SourcesList() + self.assertEqual(len(sources.list), 6) + # test load + sources.list = [] + sources.load("data/sources.list") + self.assertEqual(len(sources.list), 6) + + def testSourcesListAdding(self): + 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/", + "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/", + "edgy", + ["restricted"]) + self.assertTrue(sources.list == before.list) + # test to add something new: multiverse + sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", + "edgy", + ["multiverse"]) + found = False + for entry in sources: + if (entry.type == "deb" and + entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and + entry.dist == "edgy" and + "multiverse" in entry.comps): + found = True + self.assertTrue(found) + # 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/", + "edgy", + ["universe", "something"]) + found_universe = 0 + found_something = 0 + for entry in sources: + if (entry.type == "deb" and + entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and + entry.dist == "edgy"): + for c in entry.comps: + if c == "universe": + found_universe += 1 + if c == "something": + found_something += 1 + #print "\n".join([s.str() for s in sources]) + self.assertEqual(found_something, 1) + self.assertEqual(found_universe, 1) + + def testMatcher(self): + 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) + # test if all suits of the current distro were detected correctly + dist_templates = set() + for s in sources: + if not s.template: + self.fail("source entry '%s' has no matcher" % s) + + def testDistribution(self): + 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) + # test if all suits of the current distro were detected correctly + dist_templates = set() + for s in sources: + if s.template: + dist_templates.add(s.template.name) + #print dist_templates + for d in ("hardy", "hardy-security", "hardy-updates", "intrepid", + "hardy-backports"): + self.assertTrue(d in dist_templates) + # test enable + comp = "restricted" + distro.enable_component(comp) + found = {} + for entry in sources: + if (entry.type == "deb" and + entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and + "edgy" in entry.dist): + for c in entry.comps: + if c == comp: + if not entry.dist in found: + 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) + + # add a not-already available component + comp = "multiverse" + distro.enable_component(comp) + found = {} + for entry in sources: + if (entry.type == "deb" and + entry.template and + entry.template.name == "edgy"): + for c in entry.comps: + if c == comp: + 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/old/test_aptsources_ports.py b/tests/old/test_aptsources_ports.py new file mode 100644 index 00000000..09d6e9d9 --- /dev/null +++ b/tests/old/test_aptsources_ports.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +import unittest + +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("APT::Architecture", "powerpc") + apt_pkg.Config.Set("Dir::Etc", os.path.abspath("test-data-ports")) + apt_pkg.Config.Set("Dir::Etc::sourceparts", "/xxx") + + def testMatcher(self): + apt_pkg.Config.Set("Dir::Etc::sourcelist", "sources.list") + sources = aptsources.sourceslist.SourcesList() + distro = aptsources.distro.get_distro("Ubuntu", "hardy", "desc", + "8.04") + distro.get_sources(sources) + # test if all suits of the current distro were detected correctly + dist_templates = set() + for s in sources: + if not s.line.strip() or s.line.startswith("#"): + continue + if not s.template: + self.fail("source entry '%s' has no matcher" % s) + + +if __name__ == "__main__": + unittest.main() 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_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() diff --git a/tests/pkgproblemresolver.py b/tests/pkgproblemresolver.py deleted file mode 100644 index 0d6d0611..00000000 --- a/tests/pkgproblemresolver.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/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/pkgrecords.py b/tests/pkgrecords.py deleted file mode 100644 index 2fe6ad20..00000000 --- a/tests/pkgrecords.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/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/pkgsrcrecords.py b/tests/pkgsrcrecords.py deleted file mode 100644 index 2ea9dd3a..00000000 --- a/tests/pkgsrcrecords.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/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/refcount.py b/tests/refcount.py deleted file mode 100755 index a29744ae..00000000 --- a/tests/refcount.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/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/test-data-ports/sources.list b/tests/test-data-ports/sources.list deleted file mode 100644 index a6b2f6ed..00000000 --- a/tests/test-data-ports/sources.list +++ /dev/null @@ -1,59 +0,0 @@ -# -# deb cdrom:[Ubuntu-Server 8.04.1 _Hardy Heron_ - Release powerpc (20080703)]/ hardy main restricted - -# deb cdrom:[Ubuntu-Server 8.04.1 _Hardy Heron_ - Release powerpc (20080703)]/ hardy main restricted -# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to -# newer versions of the distribution. - -deb http://ports.ubuntu.com/ubuntu-ports/ hardy main restricted -deb-src http://archive.ubuntu.com/ubuntu hardy main restricted - -## Major bug fix updates produced after the final release of the -## distribution. -deb http://ports.ubuntu.com/ubuntu-ports/ hardy-updates main restricted -deb-src http://archive.ubuntu.com/ubuntu hardy-updates main restricted - -## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu -## team, and may not be under a free licence. Please satisfy yourself as to -## your rights to use the software. Also, please note that software in -## universe WILL NOT receive any review or updates from the Ubuntu security -## team. -deb http://ports.ubuntu.com/ubuntu-ports/ hardy universe -deb-src http://archive.ubuntu.com/ubuntu hardy universe -deb http://ports.ubuntu.com/ubuntu-ports/ hardy-updates universe -deb-src http://archive.ubuntu.com/ubuntu hardy-updates universe - -## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu -## team, and may not be under a free licence. Please satisfy yourself as to -## your rights to use the software. Also, please note that software in -## multiverse WILL NOT receive any review or updates from the Ubuntu -## security team. -deb http://ports.ubuntu.com/ubuntu-ports/ hardy multiverse -deb-src http://archive.ubuntu.com/ubuntu hardy multiverse -deb http://ports.ubuntu.com/ubuntu-ports/ hardy-updates multiverse -deb-src http://archive.ubuntu.com/ubuntu hardy-updates multiverse - -## Uncomment the following two lines to add software from the 'backports' -## repository. -## N.B. software from this repository may not have been tested as -## extensively as that contained in the main release, although it includes -## newer versions of some applications which may provide useful features. -## Also, please note that software in backports WILL NOT receive any review -## or updates from the Ubuntu security team. -# deb http://ports.ubuntu.com/ubuntu-ports/ hardy-backports main restricted universe multiverse -# deb-src http://archive.ubuntu.com/ubuntu hardy-backports main restricted universe multiverse - -## Uncomment the following two lines to add software from Canonical's -## 'partner' repository. This software is not part of Ubuntu, but is -## offered by Canonical and the respective vendors as a service to Ubuntu -## users. -# deb http://archive.canonical.com/ubuntu hardy partner -# deb-src http://archive.canonical.com/ubuntu hardy partner - -deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security main restricted -deb-src http://ports.ubuntu.com/ubuntu-ports/ hardy-security main restricted -deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security universe -deb-src http://ports.ubuntu.com/ubuntu-ports/ hardy-security universe -deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security multiverse -deb-src http://ports.ubuntu.com/ubuntu-ports/ hardy-security multiverse -deb-src http://archive.ubuntu.com/ubuntu/ hardy-proposed restricted main multiverse universe diff --git a/tests/test_all.py b/tests/test_all.py new file mode 100644 index 00000000..ea74e09b --- /dev/null +++ b/tests/test_all.py @@ -0,0 +1,17 @@ +#!/usr/bin/python +# Copyright (C) 2009 Julian Andres Klode +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. +"""Run all available unit tests.""" +import os +import unittest + +if __name__ == '__main__': + os.chdir(os.path.dirname(__file__)) + for path in os.listdir('.'): + if path.endswith('.py') and os.path.isfile(path): + exec('from %s import *' % path[:-3]) + + unittest.main() diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py deleted file mode 100644 index 3761f3ff..00000000 --- a/tests/test_aptsources.py +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/env python - -import unittest -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") - - def testIsMirror(self): - 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") - sources = aptsources.sourceslist.SourcesList() - self.assertEqual(len(sources.list), 6) - # test load - sources.list = [] - sources.load("data/sources.list") - self.assertEqual(len(sources.list), 6) - - def testSourcesListAdding(self): - 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/", - "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/", - "edgy", - ["restricted"]) - self.assertTrue(sources.list == before.list) - # test to add something new: multiverse - sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", - "edgy", - ["multiverse"]) - found = False - for entry in sources: - if (entry.type == "deb" and - entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and - entry.dist == "edgy" and - "multiverse" in entry.comps): - found = True - self.assertTrue(found) - # 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/", - "edgy", - ["universe", "something"]) - found_universe = 0 - found_something = 0 - for entry in sources: - if (entry.type == "deb" and - entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and - entry.dist == "edgy"): - for c in entry.comps: - if c == "universe": - found_universe += 1 - if c == "something": - found_something += 1 - #print "\n".join([s.str() for s in sources]) - self.assertEqual(found_something, 1) - self.assertEqual(found_universe, 1) - - def testMatcher(self): - 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) - # test if all suits of the current distro were detected correctly - dist_templates = set() - for s in sources: - if not s.template: - self.fail("source entry '%s' has no matcher" % s) - - def testDistribution(self): - 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) - # test if all suits of the current distro were detected correctly - dist_templates = set() - for s in sources: - if s.template: - dist_templates.add(s.template.name) - #print dist_templates - for d in ("hardy", "hardy-security", "hardy-updates", "intrepid", - "hardy-backports"): - self.assertTrue(d in dist_templates) - # test enable - comp = "restricted" - distro.enable_component(comp) - found = {} - for entry in sources: - if (entry.type == "deb" and - entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and - "edgy" in entry.dist): - for c in entry.comps: - if c == comp: - if not entry.dist in found: - 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) - - # add a not-already available component - comp = "multiverse" - distro.enable_component(comp) - found = {} - for entry in sources: - if (entry.type == "deb" and - entry.template and - entry.template.name == "edgy"): - for c in entry.comps: - if c == comp: - 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_aptsources_ports.py b/tests/test_aptsources_ports.py deleted file mode 100644 index 09d6e9d9..00000000 --- a/tests/test_aptsources_ports.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python - -import unittest - -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("APT::Architecture", "powerpc") - apt_pkg.Config.Set("Dir::Etc", os.path.abspath("test-data-ports")) - apt_pkg.Config.Set("Dir::Etc::sourceparts", "/xxx") - - def testMatcher(self): - apt_pkg.Config.Set("Dir::Etc::sourcelist", "sources.list") - sources = aptsources.sourceslist.SourcesList() - distro = aptsources.distro.get_distro("Ubuntu", "hardy", "desc", - "8.04") - distro.get_sources(sources) - # test if all suits of the current distro were detected correctly - dist_templates = set() - for s in sources: - if not s.line.strip() or s.line.startswith("#"): - continue - if not s.template: - self.fail("source entry '%s' has no matcher" % s) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_debextract.py b/tests/test_debextract.py deleted file mode 100755 index 4ba498ae..00000000 --- a/tests/test_debextract.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/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/test_extract_archive.py b/tests/test_extract_archive.py deleted file mode 100644 index ce202b06..00000000 --- a/tests/test_extract_archive.py +++ /dev/null @@ -1,10 +0,0 @@ -#!/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/test_hashes.py b/tests/test_hashes.py new file mode 100644 index 00000000..24e25f9c --- /dev/null +++ b/tests/test_hashes.py @@ -0,0 +1,93 @@ +#!/usr/bin/python +# +# Copyright (C) 2009 Julian Andres Klode +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. +"""Unit tests for verifying the correctness of hashsums in apt_pkg. + +Unit tests to verify the correctness of Hashes, HashString and the various +functions like md5sum.""" +import unittest +import hashlib + +import apt_pkg + + +class TestHashes(unittest.TestCase): + """Test apt_pkg.Hashes() and the various apt_pkg.*sum() functions.""" + + def setUp(self): + """Prepare the tests, create reference values...""" + self.file = open(apt_pkg.__file__, "rb") + self.value = self.file.read() + self.hashes = apt_pkg.Hashes(self.value) + self.file.seek(0) + self.fhashes = apt_pkg.Hashes(self.file) + # Reference values. + self.md5 = hashlib.md5(self.value).hexdigest() + self.sha1 = hashlib.sha1(self.value).hexdigest() + self.sha256 = hashlib.sha256(self.value).hexdigest() + self.file.seek(0) + + def tearDown(self): + """Cleanup, Close the file object used for the tests.""" + self.file.close() + + def test_md5sum(self): + """Test apt_pkg.md5sum()""" + self.assertEqual(apt_pkg.md5sum(self.value), self.md5) + self.assertEqual(apt_pkg.md5sum(self.file), self.md5) + + def test_sha1sum(self): + """Test apt_pkg.sha1sum()""" + self.assertEqual(apt_pkg.sha1sum(self.value), self.sha1) + self.assertEqual(apt_pkg.sha1sum(self.file), self.sha1) + + def test_sha256sum(self): + """Test apt_pkg.sha256sum()""" + self.assertEqual(apt_pkg.sha256sum(self.value), self.sha256) + self.assertEqual(apt_pkg.sha256sum(self.file), self.sha256) + + def test_bytes(self): + """Test apt_pkg.Hashes(bytes)""" + self.assertEqual(self.hashes.md5, self.md5) + self.assertEqual(self.hashes.sha1, self.sha1) + self.assertEqual(self.hashes.sha256, self.sha256) + + def test_file(self): + """Test apt_pkg.Hashes(file).""" + self.assertEqual(self.hashes.md5, self.fhashes.md5) + self.assertEqual(self.hashes.sha1, self.fhashes.sha1) + self.assertEqual(self.hashes.sha256, self.fhashes.sha256) + + +class TestHashString(unittest.TestCase): + """Test apt_pkg.HashString().""" + + def setUp(self): + """Prepare the test by reading the file.""" + self.hashes = apt_pkg.Hashes(open(apt_pkg.__file__)) + self.md5 = apt_pkg.HashString("MD5Sum", self.hashes.md5) + self.sha1 = apt_pkg.HashString("SHA1", self.hashes.sha1) + self.sha256 = apt_pkg.HashString("SHA256", self.hashes.sha256) + + def test_md5(self): + """Test apt_pkg.HashString().md5""" + self.assertEqual("MD5Sum:%s" % self.hashes.md5, str(self.md5)) + self.assertTrue(self.md5.verify_file(apt_pkg.__file__)) + + def test_sha1(self): + """Test apt_pkg.HashString().sha1""" + self.assertEqual("SHA1:%s" % self.hashes.sha1, str(self.sha1)) + self.assertTrue(self.sha1.verify_file(apt_pkg.__file__)) + + def test_sha256(self): + """Test apt_pkg.HashString().sha256""" + self.assertEqual("SHA256:%s" % self.hashes.sha256, str(self.sha256)) + self.assertTrue(self.sha256.verify_file(apt_pkg.__file__)) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_hashsums.py b/tests/test_hashsums.py deleted file mode 100644 index 0cf6beb7..00000000 --- a/tests/test_hashsums.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/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() -- cgit v1.2.3