summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2007-06-14 11:31:56 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2007-06-14 11:31:56 +0200
commit204ba672314d9ed07ca76770a32a6af5fbd67c25 (patch)
treef427cec965fcd27822fae3617478768d4f0f26ea /tests
parentbe05af84c65c7d4bae3cbd949304b9dd7020054f (diff)
parent3c2d0313a45668770e7cb2993dc092fb4e711bb7 (diff)
downloadpython-apt-204ba672314d9ed07ca76770a32a6af5fbd67c25.tar.gz
* build against the new apt
* support for new "aptsources" pythn module (thanks to Sebastian Heinlein) * merged support for translated package descriptions * merged support for automatic removal of unused dependencies * merged http://glatzor.de/bzr/python-apt/sebi: - this means that the new aptsources modules is available * support translated pacakge descriptions * support automatic dependency information * python/depcache.cc: - "IsGarbage()" method added (to support auto-mark)
Diffstat (limited to 'tests')
-rw-r--r--tests/data/sources.list6
-rw-r--r--tests/data/sources.list.testDistribution11
-rw-r--r--tests/pkgrecords.py2
-rw-r--r--tests/test_aptsources.py127
4 files changed, 146 insertions, 0 deletions
diff --git a/tests/data/sources.list b/tests/data/sources.list
new file mode 100644
index 00000000..5481d4f0
--- /dev/null
+++ b/tests/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/data/sources.list.testDistribution b/tests/data/sources.list.testDistribution
new file mode 100644
index 00000000..1687c504
--- /dev/null
+++ b/tests/data/sources.list.testDistribution
@@ -0,0 +1,11 @@
+deb http://de.archive.ubuntu.com/ubuntu/ edgy main
+deb http://de.archive.ubuntu.com/ubuntu/ edgy restricted
+deb http://de.archive.ubuntu.com/ubuntu/ edgy universe
+deb http://de.archive.ubuntu.com/ubuntu/ edgy-updates universe multiverse
+deb http://de.archive.ubuntu.com/ubuntu/ edgy-updates restricted
+deb http://de.archive.ubuntu.com/ubuntu/ edgy-security main
+deb http://de.archive.ubuntu.com/ubuntu/ edgy-security multiverse
+deb http://ftp.debian.org/debian sid main
+deb ftp://ubuntu.cs.utah.edu/pub/ubuntu/ubuntu/ breezy main
+deb ftp://ubuntu.cs.utah.edu/pub/ubuntu/ubuntu/ breezy-backports main
+deb http://archive.ubuntu.com/ubuntu/ hoary main
diff --git a/tests/pkgrecords.py b/tests/pkgrecords.py
index 8bfe4b82..d0616d29 100644
--- a/tests/pkgrecords.py
+++ b/tests/pkgrecords.py
@@ -21,6 +21,8 @@ def main():
#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
diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py
new file mode 100644
index 00000000..3ee106be
--- /dev/null
+++ b/tests/test_aptsources.py
@@ -0,0 +1,127 @@
+#!/usr/bin/env python
+
+import UpdateManager.Common.aptsources as aptsources
+import unittest
+import apt_pkg
+import os
+import copy
+
+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",".")
+
+ def testIsMirror(self):
+ self.assertTrue(aptsources.is_mirror("http://archive.ubuntu.com",
+ "http://de.archive.ubuntu.com"))
+ self.assertFalse(aptsources.is_mirror("http://archive.ubuntu.com",
+ "http://ftp.debian.org"))
+
+ def testSourcesListReading(self):
+ apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list")
+ sources = aptsources.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()
+ # 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 testDistribution(self):
+ apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list.testDistribution")
+ sources = aptsources.SourcesList()
+ distro = aptsources.Distribution()
+ 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 ["edgy","edgy-security","edgy-updates","hoary","breezy", "breezy-backports"]:
+ self.assertTrue(d in dist_templates)
+ # test enable
+ comp = "restricted"
+ distro.enable_component(sources, 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 found.has_key(entry.dist):
+ 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(sources, 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 found.has_key(entry.dist):
+ 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()