summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2010-09-07 13:26:35 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2010-09-07 13:26:35 +0200
commit6c5feb6111db81f4e7ec871275daa736a6fc793c (patch)
tree47d06e08e7236be2d700e28af0e2aad4ccb562d9 /tests
parent33bbf9482fe486aab915768fc74609d303c1e1f9 (diff)
parentb390a866fc3af9e7050148f11fb558fd52a8a703 (diff)
downloadpython-apt-6c5feb6111db81f4e7ec871275daa736a6fc793c.tar.gz
* merged patch from Samuel Lidén Borell to fix crash if there utf8
in the control file (LP: #624290) and add test * apt/cache.py: - add "sources_list" parameter to cache.update() to force updating a single sources.list entry only * debian/control: - add missing build-depends on python-debian (needed to run the tests for apt.debfile.DebPackage() * apt/debfile: - don't fail if we conflict with the pkgs we are reinstalling
Diffstat (limited to 'tests')
-rw-r--r--tests/data/test-repo/Packages.gzbin0 -> 675 bytes
-rw-r--r--tests/data/test-repo2/Packages.gzbin0 -> 675 bytes
-rw-r--r--tests/data/test_debs/utf8-package_1.0-1_all.debbin0 -> 1150 bytes
-rw-r--r--tests/test_apt_cache.py64
-rw-r--r--tests/test_debfile.py7
5 files changed, 70 insertions, 1 deletions
diff --git a/tests/data/test-repo/Packages.gz b/tests/data/test-repo/Packages.gz
new file mode 100644
index 00000000..81daf2bb
--- /dev/null
+++ b/tests/data/test-repo/Packages.gz
Binary files differ
diff --git a/tests/data/test-repo2/Packages.gz b/tests/data/test-repo2/Packages.gz
new file mode 100644
index 00000000..81daf2bb
--- /dev/null
+++ b/tests/data/test-repo2/Packages.gz
Binary files differ
diff --git a/tests/data/test_debs/utf8-package_1.0-1_all.deb b/tests/data/test_debs/utf8-package_1.0-1_all.deb
new file mode 100644
index 00000000..e0339c2e
--- /dev/null
+++ b/tests/data/test_debs/utf8-package_1.0-1_all.deb
Binary files differ
diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py
index d6a2cbd4..83d30ff3 100644
--- a/tests/test_apt_cache.py
+++ b/tests/test_apt_cache.py
@@ -17,7 +17,7 @@ sys.path.insert(0, get_library_dir())
import apt
import apt_pkg
-
+import shutil
class TestAptCache(unittest.TestCase):
""" test the apt cache """
@@ -98,7 +98,69 @@ class TestAptCache(unittest.TestCase):
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"
+ shutil.rmtree(rootdir)
+ try:
+ os.makedirs(os.path.join(rootdir, "var/lib/apt/lists/partial"))
+ except OSError, e:
+ pass
+ state_dir = os.path.join(rootdir, "var/lib/apt")
+ lists_dir = os.path.join(rootdir, "var/lib/apt/lists")
+ apt_pkg.config.set("dir::state", state_dir)
+ # set a local sources.list that does not need the network
+ base_sources = os.path.abspath(os.path.join(rootdir, "sources.list"))
+ apt_pkg.config.set("dir::etc::sourcelist", base_sources)
+ 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()
+
+ # 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()
+ self.assertTrue(os.path.exists(sources_list))
+ # write marker to ensure listcleaner is not run
+ open("./data/tmp/var/lib/apt/lists/marker", "w")
+
+ # update a single sources.list
+ cache = apt.Cache()
+ cache.update(sources_list=sources_list)
+ # verify we just got the excpected package file
+ needle_packages = [f for f in os.listdir(lists_dir)
+ if f.endswith("tests_data_test-repo_Packages")]
+ self.assertEqual(len(needle_packages), 1)
+ # verify that we *only* got the Packages file from a single source
+ all_packages = [f for f in os.listdir(lists_dir)
+ if f.endswith("_Packages")]
+ self.assertEqual(needle_packages, all_packages)
+ # verify that the listcleaner was not run and the marker file is
+ # still there
+ self.assertTrue("marker" in os.listdir(lists_dir))
+ # now run update again (without the "normal" sources.list that
+ # contains test-repo2 and verify that we got the normal sources.list
+ cache.update()
+ needle_packages = [f for f in os.listdir(lists_dir)
+ if f.endswith("tests_data_test-repo2_Packages")]
+ self.assertEqual(len(needle_packages), 1)
+ all_packages = [f for f in os.listdir(lists_dir)
+ if f.endswith("_Packages")]
+ self.assertEqual(needle_packages, all_packages)
+
+ # and another update with a single source only
+ cache = apt.Cache()
+ cache.update(sources_list=sources_list)
+ all_packages = [f for f in os.listdir(lists_dir)
+ if f.endswith("_Packages")]
+ self.assertEqual(len(all_packages), 2)
if __name__ == "__main__":
unittest.main()
diff --git a/tests/test_debfile.py b/tests/test_debfile.py
index 42cda6f6..571c2ec9 100644
--- a/tests/test_debfile.py
+++ b/tests/test_debfile.py
@@ -1,4 +1,5 @@
#!/usr/bin/python
+# -*- coding: utf-8 -*-
#
# Copyright (C) 2010 Michael Vogt <mvo@ubuntu.com>
#
@@ -77,6 +78,12 @@ class TestDebfilee(unittest.TestCase):
"Unexpected result for package '%s' (got %s wanted %s)\n%s" % (
filename, res, expected_res, deb._failure_string))
+ def test_utf8_sections(self):
+ deb = apt.debfile.DebPackage(cache=self.cache)
+ deb.open(os.path.join("data","test_debs","utf8-package_1.0-1_all.deb"))
+ self.assertEqual(deb["Maintainer"],
+ "Samuel Lidén Borell <samuel@slbdata.se>")
+
def testContent(self):
# normal
deb = apt.debfile.DebPackage(cache=self.cache)