summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2011-08-01 10:11:06 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2011-08-01 10:11:06 +0200
commit46ce7f8798bc963f1c647b21839488038a79d909 (patch)
treea5fb5443b0bcdc02b35c5d83df16a06168911e38 /tests
parent941a9debfcf884aebc616053774d0fe94c2e8f59 (diff)
parentc8bd732d5cb8be16ae48f8a72a4ed8a266b4ce36 (diff)
downloadpython-apt-46ce7f8798bc963f1c647b21839488038a79d909.tar.gz
merged from the debian-sid branch
Diffstat (limited to 'tests')
-rw-r--r--tests/data/test_debs/data-tar-broken.debbin0 -> 626 bytes
-rw-r--r--tests/test_apt_cache.py31
-rw-r--r--tests/test_aptsources.py3
-rw-r--r--tests/test_aptsources_ports.py4
-rw-r--r--tests/test_cache_invocation.py4
-rw-r--r--tests/test_configuration.py30
-rw-r--r--tests/test_debfile.py6
-rw-r--r--tests/test_group.py32
-rw-r--r--tests/test_hashes.py7
-rw-r--r--tests/test_progress.py3
10 files changed, 97 insertions, 23 deletions
diff --git a/tests/data/test_debs/data-tar-broken.deb b/tests/data/test_debs/data-tar-broken.deb
new file mode 100644
index 00000000..4fd42e0f
--- /dev/null
+++ b/tests/data/test_debs/data-tar-broken.deb
Binary files differ
diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py
index cccfc9c8..aaa9f601 100644
--- a/tests/test_apt_cache.py
+++ b/tests/test_apt_cache.py
@@ -48,9 +48,9 @@ class TestAptCache(unittest.TestCase):
# tons of seek operations
r = pkg.candidate.record
self.assertEqual(r['Package'], pkg.shortname)
- self.assert_('Version' in r)
- self.assert_(len(r['Description']) > 0)
- self.assert_(str(r).startswith('Package: %s\n' % pkg.shortname))
+ self.assertTrue('Version' in r)
+ self.assertTrue(len(r['Description']) > 0)
+ self.assertTrue(str(r).startswith('Package: %s\n' % pkg.shortname))
def test_get_provided_packages(self):
cache = apt.Cache()
@@ -70,7 +70,7 @@ class TestAptCache(unittest.TestCase):
def test_low_level_pkg_provides(self):
# low level cache provides list of the pkg
- cache = apt_pkg.Cache()
+ cache = apt_pkg.Cache(progress=None)
l = cache["mail-transport-agent"].provides_list
# arbitrary number, just needs to be higher enough
self.assertTrue(len(l), 5)
@@ -89,17 +89,17 @@ class TestAptCache(unittest.TestCase):
tmpdir = tempfile.mkdtemp()
dpkg_dir = os.path.join(tmpdir,"var","lib","dpkg")
os.makedirs(os.path.join(dpkg_dir,"updates"))
- open(os.path.join(dpkg_dir,"status"), "w")
+ open(os.path.join(dpkg_dir,"status"), "w").close()
apt_pkg.config.set("Dir::State::status",
os.path.join(dpkg_dir,"status"))
cache = apt.Cache()
# test empty
self.assertFalse(cache.dpkg_journal_dirty)
# that is ok, only [0-9] are dpkg jounral entries
- open(os.path.join(dpkg_dir,"updates","xxx"), "w")
+ open(os.path.join(dpkg_dir,"updates","xxx"), "w").close()
self.assertFalse(cache.dpkg_journal_dirty)
# that is a dirty journal
- open(os.path.join(dpkg_dir,"updates","000"), "w")
+ open(os.path.join(dpkg_dir,"updates","000"), "w").close()
self.assertTrue(cache.dpkg_journal_dirty)
# reset config value
apt_pkg.config.set("Dir::State::status", old_status)
@@ -121,20 +121,19 @@ class TestAptCache(unittest.TestCase):
apt_pkg.config.set("dir::etc::sourceparts", "xxx")
# main sources.list
sources_list = base_sources
- f=open(sources_list, "w")
- repo = os.path.abspath("./data/test-repo2")
- f.write("deb copy:%s /\n" % repo)
- f.close()
+ with open(sources_list, "w") as f:
+ repo = os.path.abspath("./data/test-repo2")
+ f.write("deb copy:%s /\n" % repo)
# test single sources.list fetching
sources_list = os.path.join(rootdir, "test.list")
- f=open(sources_list, "w")
- repo_dir = os.path.abspath("./data/test-repo")
- f.write("deb copy:%s /\n" % repo_dir)
- f.close()
+ with open(sources_list, "w") as f:
+ repo_dir = os.path.abspath("./data/test-repo")
+ f.write("deb copy:%s /\n" % repo_dir)
+
self.assertTrue(os.path.exists(sources_list))
# write marker to ensure listcleaner is not run
- open("./data/tmp/var/lib/apt/lists/marker", "w")
+ open("./data/tmp/var/lib/apt/lists/marker", "w").close()
# update a single sources.list
cache = apt.Cache()
diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py
index 1597674e..193d3806 100644
--- a/tests/test_aptsources.py
+++ b/tests/test_aptsources.py
@@ -3,6 +3,7 @@
import unittest
import os
import copy
+import tempfile
import apt_pkg
import aptsources.sourceslist
@@ -17,7 +18,7 @@ class TestAptSources(unittest.TestCase):
if apt_pkg.config["APT::Architecture"] not in ('i386', 'amd64'):
apt_pkg.config.set("APT::Architecture", "i386")
apt_pkg.config.set("Dir::Etc", os.getcwd())
- apt_pkg.config.set("Dir::Etc::sourceparts", "/xxx")
+ apt_pkg.config.set("Dir::Etc::sourceparts", tempfile.mkdtemp())
if os.path.exists("./build/data/templates"):
self.templates = os.path.abspath("./build/data/templates")
elif os.path.exists("../build/data/templates"):
diff --git a/tests/test_aptsources_ports.py b/tests/test_aptsources_ports.py
index 991b532a..67c21b9c 100644
--- a/tests/test_aptsources_ports.py
+++ b/tests/test_aptsources_ports.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
import os
import unittest
-
+import tempfile
import apt_pkg
import aptsources.sourceslist
@@ -17,7 +17,7 @@ class TestAptSourcesPorts(unittest.TestCase):
apt_pkg.config.set("APT::Architecture", "powerpc")
apt_pkg.config.set("Dir::Etc",
os.path.abspath("data/aptsources_ports"))
- apt_pkg.config.set("Dir::Etc::sourceparts", "/xxx")
+ apt_pkg.config.set("Dir::Etc::sourceparts", tempfile.mkdtemp())
if os.path.exists("../build/data/templates"):
self.templates = os.path.abspath("../build/data/templates")
else:
diff --git a/tests/test_cache_invocation.py b/tests/test_cache_invocation.py
index 6f4014de..a89ef557 100644
--- a/tests/test_cache_invocation.py
+++ b/tests/test_cache_invocation.py
@@ -14,7 +14,7 @@ class TestCache(unittest.TestCase):
def test_wrong_invocation(self):
"""cache_invocation: Test wrong invocation."""
- apt_cache = apt_pkg.Cache(apt.progress.base.OpProgress())
+ apt_cache = apt_pkg.Cache(progress=None)
self.assertRaises(ValueError, apt_pkg.Cache, apt_cache)
self.assertRaises(ValueError, apt_pkg.Cache,
@@ -23,7 +23,7 @@ class TestCache(unittest.TestCase):
def test_proper_invocation(self):
"""cache_invocation: Test correct invocation."""
- apt_cache = apt_pkg.Cache(apt.progress.base.OpProgress())
+ apt_cache = apt_pkg.Cache(progress=None)
apt_depcache = apt_pkg.DepCache(apt_cache)
if __name__ == "__main__":
diff --git a/tests/test_configuration.py b/tests/test_configuration.py
new file mode 100644
index 00000000..80509cff
--- /dev/null
+++ b/tests/test_configuration.py
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2011 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 apt_pkg.Configuration"""
+import unittest
+
+import apt_pkg
+
+
+class TestConfiguration(unittest.TestCase):
+ """Test various configuration things"""
+
+ def setUp(self):
+ """Prepare the tests, create reference values..."""
+ apt_pkg.init_config()
+
+ def test_lp707416(self):
+ """configuration: Test empty arguments (LP: #707416)"""
+ self.assertRaises(ValueError, apt_pkg.parse_commandline,
+ apt_pkg.config,[], [])
+ self.assertRaises(SystemError, apt_pkg.parse_commandline,
+ apt_pkg.config,[], ["cmd", "--arg0"])
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/test_debfile.py b/tests/test_debfile.py
index 5f6d1aa2..86a51cb9 100644
--- a/tests/test_debfile.py
+++ b/tests/test_debfile.py
@@ -119,6 +119,12 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading
deb = apt.debfile.DebPackage("./data/test_debs/data-tar-xz.deb")
self.assertEqual(deb.filelist, ["./", "usr/", "usr/bin/"])
+ def test_no_supported_data_tar(self):
+ # ensure that a unknown data.tar.xxx raises a exception
+ with self.assertRaises(SystemError):
+ deb = apt.debfile.DebPackage("./data/test_debs/data-tar-broken.deb")
+
+
if __name__ == "__main__":
#logging.basicConfig(level=logging.DEBUG)
diff --git a/tests/test_group.py b/tests/test_group.py
new file mode 100644
index 00000000..3c3a5b7a
--- /dev/null
+++ b/tests/test_group.py
@@ -0,0 +1,32 @@
+import unittest
+
+import apt_pkg
+
+
+class TestGroup(unittest.TestCase):
+
+ def setUp(self):
+ apt_pkg.init()
+ self.cache = apt_pkg.Cache(progress=None)
+
+ def test_pkgingroup(self):
+ """Check that each package belongs to the corresponding group"""
+ for pkg in self.cache.packages:
+ group = apt_pkg.Group(self.cache, pkg.name)
+ assert any(pkg.id == p.id for p in group)
+
+ def test_iteration(self):
+ """Check that iteration works correctly."""
+ for pkg in self.cache.packages:
+ group = apt_pkg.Group(self.cache, pkg.name)
+
+ list(group) == list(group)
+
+
+ def test_cache_groups(self):
+ """group: Iterate over all groups"""
+ assert len(list(self.cache.groups)) == self.cache.group_count
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/test_hashes.py b/tests/test_hashes.py
index e0aabe09..660373cb 100644
--- a/tests/test_hashes.py
+++ b/tests/test_hashes.py
@@ -82,11 +82,16 @@ class TestHashString(unittest.TestCase):
def setUp(self):
"""Prepare the test by reading the file."""
- self.hashes = apt_pkg.Hashes(open(apt_pkg.__file__))
+ self.file = open(apt_pkg.__file__)
+ self.hashes = apt_pkg.Hashes(self.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 tearDown(self):
+ """Cleanup, Close the file object used for the tests."""
+ self.file.close()
+
def test_md5(self):
"""hashes: Test apt_pkg.HashString().md5"""
self.assertEqual("MD5Sum:%s" % self.hashes.md5, str(self.md5))
diff --git a/tests/test_progress.py b/tests/test_progress.py
index ffab5bc0..73853dfa 100644
--- a/tests/test_progress.py
+++ b/tests/test_progress.py
@@ -34,7 +34,8 @@ class TestProgress(unittest.TestCase):
apt_pkg.config.set("Dir::state::lists", "./tmp")
# create artifical line
deb_line = "deb file:%s/data/fake-packages/ /\n" % basedir
- open("fetch_sources.list","w").write(deb_line)
+ with open("fetch_sources.list","w") as fobj:
+ fobj.write(deb_line)
apt_pkg.config.set("Dir::Etc::sourcelist", "fetch_sources.list")
def test_acquire_progress(self):