summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/data/aptsources/sources.list.testDistribution4
-rw-r--r--tests/test_all.py1
-rw-r--r--tests/test_deps.py119
3 files changed, 122 insertions, 2 deletions
diff --git a/tests/data/aptsources/sources.list.testDistribution b/tests/data/aptsources/sources.list.testDistribution
index 4ff0fae6..79224a34 100644
--- a/tests/data/aptsources/sources.list.testDistribution
+++ b/tests/data/aptsources/sources.list.testDistribution
@@ -6,8 +6,8 @@ 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://ftp.hosteurope.de/mirror/archive.ubuntu.com/ hardy main
+deb http://ftp.hosteurope.de/mirror/archive.ubuntu.com/ 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
diff --git a/tests/test_all.py b/tests/test_all.py
index 6900e0ad..dc603dfd 100644
--- a/tests/test_all.py
+++ b/tests/test_all.py
@@ -10,6 +10,7 @@ import unittest
import sys
if __name__ == '__main__':
+ print("[tests] Running on %s" % sys.version.replace("\n", ""))
os.chdir(os.path.dirname(__file__))
# Find the path to the built apt_pkg and apt_inst extensions
if os.path.exists("../build"):
diff --git a/tests/test_deps.py b/tests/test_deps.py
new file mode 100644
index 00000000..674c9485
--- /dev/null
+++ b/tests/test_deps.py
@@ -0,0 +1,119 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2010 Julian Andres Klode <jak@debian.org>
+#
+# 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 check_dep, etc in apt_pkg."""
+import unittest
+
+import apt_pkg
+
+
+class TestDependencies(unittest.TestCase):
+
+ def setUp(self):
+ apt_pkg.init()
+
+ def testCheckDep(self):
+ """dependencies: Test apt_pkg.CheckDep() for '<' and '>'
+
+ The CheckDep function should treat '<' as '<=' and '>' as '>=', for
+ compatibility reasons."""
+ if not hasattr(apt_pkg, 'CheckDep'):
+ return
+ self.assertFalse(apt_pkg.CheckDep("1", "<", "0"))
+ self.assertTrue(apt_pkg.CheckDep("1", "<", "1"))
+ self.assertTrue(apt_pkg.CheckDep("1", "<", "2"))
+
+ self.assertFalse(apt_pkg.CheckDep("0", ">", "1"))
+ self.assertTrue(apt_pkg.CheckDep("1", ">", "1"))
+ self.assertTrue(apt_pkg.CheckDep("2", ">", "1"))
+
+ def test_check_dep(self):
+ "dependencies: Test apt_pkg.check_dep()"
+ self.assertFalse(apt_pkg.check_dep("1", "<<", "0"))
+ self.assertFalse(apt_pkg.check_dep("1", "<<", "1"))
+ self.assertTrue(apt_pkg.check_dep("1", "<<", "2"))
+
+ self.assertFalse(apt_pkg.check_dep("1", "<", "0"))
+ self.assertFalse(apt_pkg.check_dep("1", "<", "1"))
+ self.assertTrue(apt_pkg.check_dep("1", "<", "2"))
+
+ self.assertFalse(apt_pkg.check_dep("1", "<=", "0"))
+ self.assertTrue(apt_pkg.check_dep("1", "<=", "1"))
+ self.assertTrue(apt_pkg.check_dep("1", "<=", "2"))
+
+ self.assertFalse(apt_pkg.check_dep("0", "=", "1"))
+ self.assertTrue(apt_pkg.check_dep("1", "=", "1"))
+ self.assertFalse(apt_pkg.check_dep("2", "=", "1"))
+
+ self.assertFalse(apt_pkg.check_dep("0", ">=", "1"))
+ self.assertTrue(apt_pkg.check_dep("1", ">=", "1"))
+ self.assertTrue(apt_pkg.check_dep("2", ">=", "1"))
+
+ self.assertFalse(apt_pkg.check_dep("0", ">", "1"))
+ self.assertFalse(apt_pkg.check_dep("1", ">", "1"))
+ self.assertTrue(apt_pkg.check_dep("2", ">", "1"))
+
+ self.assertFalse(apt_pkg.check_dep("0", ">>", "1"))
+ self.assertFalse(apt_pkg.check_dep("1", ">>", "1"))
+ self.assertTrue(apt_pkg.check_dep("2", ">>", "1"))
+
+ def test_parse_depends(self):
+ """dependencies: Test apt_pkg.parse_depends()"""
+ deps = apt_pkg.parse_depends("p1a (<< 1a) | p1b (>> 1b)")
+ self.assertTrue(isinstance(deps, list))
+ self.assertEqual(len(deps), 1)
+ self.assertTrue(isinstance(deps[0], list))
+ self.assertEqual(len(deps[0]), 2)
+ self.assertEqual(len(deps[0][0]), 3)
+ self.assertEqual(len(deps[0][1]), 3)
+ self.assertEqual(deps[0][0][0], "p1a")
+ self.assertEqual(deps[0][0][1], "1a")
+ self.assertEqual(deps[0][0][2], "<")
+ self.assertEqual(deps[0][1][0], "p1b")
+ self.assertEqual(deps[0][1][1], "1b")
+ self.assertEqual(deps[0][1][2], ">")
+
+ # Check that the type of comparison is parsed correctly.
+ self.assertEqual("<", apt_pkg.parse_depends("p1 (<< 1)")[0][0][2])
+ self.assertEqual("<=", apt_pkg.parse_depends("p1 (< 1)")[0][0][2])
+ self.assertEqual("<=", apt_pkg.parse_depends("p1 (<= 1)")[0][0][2])
+ self.assertEqual("=", apt_pkg.parse_depends("p1 (= 1)")[0][0][2])
+ self.assertEqual(">=", apt_pkg.parse_depends("p1 (>= 1)")[0][0][2])
+ self.assertEqual(">=", apt_pkg.parse_depends("p1 (> 1)")[0][0][2])
+ self.assertEqual(">", apt_pkg.parse_depends("p1 (>> 1)")[0][0][2])
+
+ def test_parse_src_depends(self):
+ """dependencies: Test apt_pkg.parse_src_depends()."""
+ # Check that architecture exclusion works
+ # depends_this: Current architecture is included
+ # depends_this_too: Another architecture is excluded
+ # depends_other: The current architecture is excluded
+ # depends_other: Another architecture is requested.
+ architecture = apt_pkg.config["APT::Architecture"]
+ depends_this = apt_pkg.parse_src_depends("p [%s]" % architecture)
+ depends_this_too = apt_pkg.parse_src_depends("p [!not-existing-arch]")
+ depends_other = apt_pkg.parse_src_depends("p [!%s]" % architecture)
+ depends_other_too = apt_pkg.parse_src_depends("p [not-existing-arch]")
+
+ self.assertEqual(len(depends_this), len(depends_this_too), 1)
+ self.assertEqual(len(depends_other), len(depends_other_too), 0)
+
+ def testParseDepends(self):
+ """dependencies: Test apt_pkg.ParseDepends()."""
+ if not hasattr(apt_pkg, 'ParseDepends'):
+ return
+ # Check that the type of comparison is parsed correctly.
+ self.assertEqual("<<", apt_pkg.ParseDepends("p1 (<< 1)")[0][0][2])
+ self.assertEqual("<=", apt_pkg.ParseDepends("p1 (< 1)")[0][0][2])
+ self.assertEqual("<=", apt_pkg.ParseDepends("p1 (<= 1)")[0][0][2])
+ self.assertEqual("=", apt_pkg.ParseDepends("p1 (= 1)")[0][0][2])
+ self.assertEqual(">=", apt_pkg.ParseDepends("p1 (>= 1)")[0][0][2])
+ self.assertEqual(">=", apt_pkg.ParseDepends("p1 (> 1)")[0][0][2])
+ self.assertEqual(">>", apt_pkg.ParseDepends("p1 (>> 1)")[0][0][2])
+
+if __name__ == "__main__":
+ unittest.main()