summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test_apt_cache.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py
index 399d50dd..72c72bd2 100644
--- a/tests/test_apt_cache.py
+++ b/tests/test_apt_cache.py
@@ -17,6 +17,7 @@ sys.path.insert(0, get_library_dir())
import apt
import apt_pkg
+import copy
import shutil
import glob
@@ -26,6 +27,14 @@ class TestAptCache(unittest.TestCase):
def setUp(self):
# reset any config manipulations done in the individual tests
apt_pkg.init_config()
+ # save/restore the apt config
+ self._cnf = {}
+ for item in apt_pkg.config.keys():
+ self._cnf[item] = apt_pkg.config.find(item)
+
+ def tearDown(self):
+ for item in self._cnf:
+ apt_pkg.config.set(item, self._cnf[item])
def testAptCache(self):
"""cache: iterate all packages and all dependencies """
@@ -53,25 +62,21 @@ class TestAptCache(unittest.TestCase):
self.assertTrue(str(r).startswith('Package: %s\n' % pkg.shortname))
def test_get_provided_packages(self):
- cache = apt.Cache()
+ apt.apt_pkg.config.set("Apt::architecture", "i386")
+ cache = apt.Cache(rootdir="./data/test-provides/")
+ cache.open()
# a true virtual pkg
l = cache.get_providing_packages("mail-transport-agent")
self.assertTrue(len(l) > 0)
self.assertTrue("postfix" in [p.name for p in l])
- # FIXME: this is failing currently, create a better (artificial)
- # testcase for this feature
- # this is a not virtual (transitional) package provided by another
- #l = cache.get_providing_packages("git-core")
- #self.assertEqual(l, [])
- # now inlcude nonvirtual packages in the search
- l = cache.get_providing_packages("git-core",
- include_nonvirtual=True)
- self.assertEqual([p.name for p in l], ["git"])
self.assertTrue("mail-transport-agent" in cache["postfix"].candidate.provides)
def test_low_level_pkg_provides(self):
+ apt.apt_pkg.config.set("Apt::architecture", "i386")
+ # create highlevel cache and get the lowlevel one from it
+ highlevel_cache = apt.Cache(rootdir="./data/test-provides")
# low level cache provides list of the pkg
- cache = apt_pkg.Cache(progress=None)
+ cache = highlevel_cache._cache
l = cache["mail-transport-agent"].provides_list
# arbitrary number, just needs to be higher enough
self.assertTrue(len(l), 5)
@@ -84,8 +89,6 @@ class TestAptCache(unittest.TestCase):
def test_dpkg_journal_dirty(self):
- # backup old value
- old_status = apt_pkg.config.find_file("Dir::State::status")
# create tmp env
tmpdir = tempfile.mkdtemp()
dpkg_dir = os.path.join(tmpdir,"var","lib","dpkg")
@@ -102,8 +105,6 @@ class TestAptCache(unittest.TestCase):
# that is a dirty journal
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)
def test_apt_update(self):
rootdir = "./data/tmp"