summaryrefslogtreecommitdiff
path: root/tests/old
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-07-17 19:40:47 +0200
committerJulian Andres Klode <jak@debian.org>2009-07-17 19:40:47 +0200
commitcbd822c9dfe8cf18d828bd558290f15775b4d837 (patch)
treeb9ee1d702dd85a5dc2cbd9303e7f31ca6b8ffa52 /tests/old
parent9bd7c1dcf9942d6ce294aa5ac58d90d6c1aa9f51 (diff)
downloadpython-apt-cbd822c9dfe8cf18d828bd558290f15775b4d837.tar.gz
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_.
Diffstat (limited to 'tests/old')
-rw-r--r--tests/old/__init__.py13
-rw-r--r--tests/old/apt-test.py26
-rw-r--r--tests/old/cache.py51
-rw-r--r--tests/old/data/sources.list6
-rw-r--r--tests/old/data/sources.list.testDistribution13
-rw-r--r--tests/old/depcache.py54
-rw-r--r--tests/old/getcache_mem_corruption.py24
-rw-r--r--tests/old/hashsum_test.data1
-rw-r--r--tests/old/hashsum_test_with_zero.databin0 -> 7 bytes
-rw-r--r--tests/old/lock.py47
-rwxr-xr-xtests/old/memleak.py46
-rw-r--r--tests/old/pkgproblemresolver.py70
-rw-r--r--tests/old/pkgrecords.py40
-rw-r--r--tests/old/pkgsrcrecords.py29
-rwxr-xr-xtests/old/refcount.py54
-rw-r--r--tests/old/test-data-ports/sources.list59
-rw-r--r--tests/old/test_aptsources.py151
-rw-r--r--tests/old/test_aptsources_ports.py41
-rwxr-xr-xtests/old/test_debextract.py18
-rw-r--r--tests/old/test_extract_archive.py10
-rw-r--r--tests/old/test_hashsums.py67
21 files changed, 820 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/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
--- /dev/null
+++ b/tests/old/hashsum_test_with_zero.data
Binary files 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()