diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2010-07-28 11:09:00 +0200 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2010-07-28 11:09:00 +0200 |
| commit | cee5d33d44130ce8ceb7b563f7b97f2bf9a3ca5c (patch) | |
| tree | 8157a049457a566f6ac5b2e665cba01629aadd58 /tests | |
| parent | 3b4330920da718d2dbb2a4a94577c07eaa58a8c5 (diff) | |
| parent | d642c9ea22f5705acfcba79493f48293626771c3 (diff) | |
| download | python-apt-cee5d33d44130ce8ceb7b563f7b97f2bf9a3ca5c.tar.gz | |
merged from the debian-sid bzr branch
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/data/fake-packages/Packages | 21 | ||||
| -rw-r--r-- | tests/data/fake-packages/Packages.gz | bin | 0 -> 555 bytes | |||
| -rw-r--r-- | tests/data/test_debs/gdebi-test1.deb | bin | 0 -> 934 bytes | |||
| -rw-r--r-- | tests/data/test_debs/gdebi-test10.deb | bin | 0 -> 614 bytes | |||
| -rw-r--r-- | tests/data/test_debs/gdebi-test2.deb | bin | 0 -> 554 bytes | |||
| -rw-r--r-- | tests/data/test_debs/gdebi-test3.deb | bin | 0 -> 570 bytes | |||
| -rw-r--r-- | tests/data/test_debs/gdebi-test4.deb | bin | 0 -> 2306 bytes | |||
| -rw-r--r-- | tests/data/test_debs/gdebi-test5.deb | bin | 0 -> 2306 bytes | |||
| -rw-r--r-- | tests/data/test_debs/gdebi-test6.deb | bin | 0 -> 600 bytes | |||
| -rw-r--r-- | tests/data/test_debs/gdebi-test7.deb | bin | 0 -> 578 bytes | |||
| -rw-r--r-- | tests/data/test_debs/gdebi-test8.deb | bin | 0 -> 598 bytes | |||
| -rw-r--r-- | tests/data/test_debs/gdebi-test9.deb | bin | 0 -> 586 bytes | |||
| -rw-r--r-- | tests/data/test_debs/var/lib/dpkg/status | 53 | ||||
| -rw-r--r-- | tests/test_all.py | 32 | ||||
| -rw-r--r-- | tests/test_apt_cache.py | 53 | ||||
| -rw-r--r-- | tests/test_aptsources.py | 4 | ||||
| -rw-r--r-- | tests/test_debfile.py | 66 | ||||
| -rw-r--r-- | tests/test_progress.py | 47 |
18 files changed, 262 insertions, 14 deletions
diff --git a/tests/data/fake-packages/Packages b/tests/data/fake-packages/Packages new file mode 100644 index 00000000..9fbab957 --- /dev/null +++ b/tests/data/fake-packages/Packages @@ -0,0 +1,21 @@ +Package: 2vcard +Priority: optional +Section: universe/utils +Installed-Size: 108 +Maintainer: Arvind Autar <Autar022@planet.nl> +Architecture: amd64 +Version: 0.5-1ubuntu1 +Filename: pool/universe/2/2vcard/2vcard_0.5-1ubuntu1_amd64.deb +Size: 14164 +MD5sum: 105ea91f0a75417d0f9e8e9624513b2a +SHA1: d55beee01c08efc33cd131e106330dca72ee14be +SHA256: 4a72edaf87cdb826e5508b85311fcf0bec9b7e019a55740ded7feb1b9e197f11 +Description: A little perl script to convert an adressbook to VCARD file format + 2vcard is a little perl script that you can use to convert the popular vcard + file format. Currently 2vcard can only convert adressbooks and alias files from + the following formats: abook,eudora,juno,ldif,mutt,mh and pine. + . + The VCARD format is used by gnomecard, for example, which is turn is used by + the balsa email client. +Bugs: mailto:ubuntu-users@lists.ubuntu.com +Origin: Ubuntu diff --git a/tests/data/fake-packages/Packages.gz b/tests/data/fake-packages/Packages.gz Binary files differnew file mode 100644 index 00000000..506bc8d4 --- /dev/null +++ b/tests/data/fake-packages/Packages.gz diff --git a/tests/data/test_debs/gdebi-test1.deb b/tests/data/test_debs/gdebi-test1.deb Binary files differnew file mode 100644 index 00000000..ea9991ac --- /dev/null +++ b/tests/data/test_debs/gdebi-test1.deb diff --git a/tests/data/test_debs/gdebi-test10.deb b/tests/data/test_debs/gdebi-test10.deb Binary files differnew file mode 100644 index 00000000..ca43ace6 --- /dev/null +++ b/tests/data/test_debs/gdebi-test10.deb diff --git a/tests/data/test_debs/gdebi-test2.deb b/tests/data/test_debs/gdebi-test2.deb Binary files differnew file mode 100644 index 00000000..307ac689 --- /dev/null +++ b/tests/data/test_debs/gdebi-test2.deb diff --git a/tests/data/test_debs/gdebi-test3.deb b/tests/data/test_debs/gdebi-test3.deb Binary files differnew file mode 100644 index 00000000..436b9258 --- /dev/null +++ b/tests/data/test_debs/gdebi-test3.deb diff --git a/tests/data/test_debs/gdebi-test4.deb b/tests/data/test_debs/gdebi-test4.deb Binary files differnew file mode 100644 index 00000000..9eb92d1b --- /dev/null +++ b/tests/data/test_debs/gdebi-test4.deb diff --git a/tests/data/test_debs/gdebi-test5.deb b/tests/data/test_debs/gdebi-test5.deb Binary files differnew file mode 100644 index 00000000..0c98c03f --- /dev/null +++ b/tests/data/test_debs/gdebi-test5.deb diff --git a/tests/data/test_debs/gdebi-test6.deb b/tests/data/test_debs/gdebi-test6.deb Binary files differnew file mode 100644 index 00000000..8ceacadc --- /dev/null +++ b/tests/data/test_debs/gdebi-test6.deb diff --git a/tests/data/test_debs/gdebi-test7.deb b/tests/data/test_debs/gdebi-test7.deb Binary files differnew file mode 100644 index 00000000..c0414990 --- /dev/null +++ b/tests/data/test_debs/gdebi-test7.deb diff --git a/tests/data/test_debs/gdebi-test8.deb b/tests/data/test_debs/gdebi-test8.deb Binary files differnew file mode 100644 index 00000000..439f8ca7 --- /dev/null +++ b/tests/data/test_debs/gdebi-test8.deb diff --git a/tests/data/test_debs/gdebi-test9.deb b/tests/data/test_debs/gdebi-test9.deb Binary files differnew file mode 100644 index 00000000..9901d906 --- /dev/null +++ b/tests/data/test_debs/gdebi-test9.deb diff --git a/tests/data/test_debs/var/lib/dpkg/status b/tests/data/test_debs/var/lib/dpkg/status new file mode 100644 index 00000000..f0c48151 --- /dev/null +++ b/tests/data/test_debs/var/lib/dpkg/status @@ -0,0 +1,53 @@ +Package: apt +Status: install ok installed +Priority: important +Section: admin +Installed-Size: 5456 +Maintainer: APT Development Team <deity@lists.debian.org> +Architecture: i386 +Version: 0.7.25.3 +Replaces: libapt-pkg-dev (<< 0.3.7), libapt-pkg-doc (<< 0.3.7) +Provides: libapt-pkg-libc6.10-6-4.8 +Description: Advanced front-end for dpkg + This is Debian's next generation front-end for the dpkg package manager. + It provides the apt-get utility and APT dselect method that provides a + simpler, safer way to install and upgrade packages. + . + APT features complete installation ordering, multiple source capability + and several other unique features, see the Users Guide in apt-doc. + +Package: postfix +Status: install ok installed +Priority: extra +Section: mail +Installed-Size: 3488 +Maintainer: LaMont Jones <lamont@debian.org> +Architecture: i386 +Version: 2.7.0-1 +Replaces: mail-transport-agent, postfix-tls +Provides: default-mta, mail-transport-agent, postfix-tls +Recommends: python +Conflicts: libnss-db (<< 2.2-3), mail-transport-agent, postfix-tls, smail +Description: High-performance mail transport agent + Postfix is Wietse Venema's mail transport agent that started life as an + alternative to the widely-used Sendmail program. Postfix attempts to + be fast, easy to administer, and secure, while at the same time being + sendmail compatible enough to not upset existing users. Thus, the outside + has a sendmail-ish flavor, but the inside is completely different. + +Package: debconf +Status: install ok installed +Priority: important +Section: admin +Installed-Size: 924 +Maintainer: Debconf Developers <debconf-devel@lists.alioth.debian.org> +Architecture: all +Version: 1.5.28 +Replaces: debconf-tiny +Provides: debconf-2.0 +Recommends: apt-utils (>= 0.5.1) +Conflicts: apt (<< 0.3.12.1), cdebconf (<< 0.96), debconf-tiny, debconf-utils (<< 1.3.22), dialog (<< 0.9b-20020814-1), menu (<= 2.1.3-1), whiptail (<< 0.51.4-11), whiptail-utf8 (<= 0.50.17-13) +Description: Debian configuration management system + Debconf is a configuration management system for debian packages. Packages + use Debconf to ask questions when they are installed. +Python-Version: 2.6, 3.1 diff --git a/tests/test_all.py b/tests/test_all.py index d561a9ae..d6370747 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -9,21 +9,29 @@ import os import unittest import sys -if __name__ == '__main__': - sys.stderr.write("[tests] Running on %s\n" % sys.version.replace("\n", "")) - os.chdir(os.path.dirname(__file__)) +def get_library_dir(): # Find the path to the built apt_pkg and apt_inst extensions - if os.path.exists("../build"): - from distutils.util import get_platform - from distutils.sysconfig import get_python_version - # Set the path to the build directory. - plat_specifier = ".%s-%s" % (get_platform(), get_python_version()) - if sys.version_info[0] >= 3 or sys.version_info[1] >= 6: - library_dir = "../build/lib%s%s" % (plat_specifier, + if not os.path.exists("../build"): + return None + from distutils.util import get_platform + from distutils.sysconfig import get_python_version + # Set the path to the build directory. + plat_specifier = ".%s-%s" % (get_platform(), get_python_version()) + if sys.version_info[0] >= 3 or sys.version_info[1] >= 6: + library_dir = "../build/lib%s%s" % (plat_specifier, (sys.pydebug and "-pydebug" or "")) - else: - library_dir = "../build/lib%s%s" % ((sys.pydebug and "_d" or ""), + else: + library_dir = "../build/lib%s%s" % ((sys.pydebug and "_d" or ""), plat_specifier) + return os.path.abspath(library_dir) + +if __name__ == '__main__': + sys.stderr.write("[tests] Running on %s\n" % sys.version.replace("\n", "")) + dirname = os.path.dirname(__file__) + if dirname: + os.chdir(dirname) + library_dir = get_library_dir() + if library_dir: sys.path.insert(0, os.path.abspath(library_dir)) for path in os.listdir('.'): diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index fdcf482d..a43e92d2 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -6,9 +6,15 @@ # 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 os +import tempfile import unittest +import sys +sys.path.insert(0, "..") + import apt +import apt_pkg class TestAptCache(unittest.TestCase): @@ -30,5 +36,52 @@ class TestAptCache(unittest.TestCase): self.assertTrue(isinstance(dep.relation, str)) self.assertTrue(dep.pre_depend in (True, False)) + # accessing record should take a reasonable time; in + # particular, when using compressed indexes, it should not use + # tons of seek operations + r = pkg.candidate.record + self.assertEqual(r['Package'], pkg.name) + self.assert_('Version' in r) + self.assert_(len(r['Description']) > 0) + self.assert_(str(r).startswith('Package: %s\n' % pkg.name)) + + def test_get_provided_packages(self): + cache = apt.Cache() + # a true virtual pkg + l = cache.get_providing_packages("mail-transport-agent") + self.assertTrue(len(l) > 0) + # this is a not virtual (transitional) package provided by another + l = cache.get_providing_packages("scrollkeeper") + self.assertEqual(l, []) + # now inlcude nonvirtual packages in the search (rarian-compat + # provides scrollkeeper) + l = cache.get_providing_packages("scrollkeeper", + include_nonvirtual=True) + self.assertTrue(len(l), 1) + + + 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") + os.makedirs(os.path.join(dpkg_dir,"updates")) + open(os.path.join(dpkg_dir,"status"), "w") + 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") + self.assertFalse(cache.dpkg_journal_dirty) + # that is a dirty journal + open(os.path.join(dpkg_dir,"updates","000"), "w") + self.assertTrue(cache.dpkg_journal_dirty) + # reset config value + apt_pkg.config.set("Dir::State::status", old_status) + + if __name__ == "__main__": unittest.main() diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py index 767f5244..3ef20f64 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -98,7 +98,7 @@ class TestAptSources(unittest.TestCase): apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" "sources.list.testDistribution") sources = aptsources.sourceslist.SourcesList(True, self.templates) - distro = aptsources.distro.get_distro() + distro = aptsources.distro.get_distro(id="Ubuntu") distro.get_sources(sources) # test if all suits of the current distro were detected correctly dist_templates = set() @@ -111,7 +111,7 @@ class TestAptSources(unittest.TestCase): apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" "sources.list.testDistribution") sources = aptsources.sourceslist.SourcesList(True, self.templates) - distro = aptsources.distro.get_distro() + distro = aptsources.distro.get_distro(id="Ubuntu") distro.get_sources(sources) # test if all suits of the current distro were detected correctly dist_templates = set() diff --git a/tests/test_debfile.py b/tests/test_debfile.py new file mode 100644 index 00000000..bb9fd62c --- /dev/null +++ b/tests/test_debfile.py @@ -0,0 +1,66 @@ +#!/usr/bin/python +# +# Copyright (C) 2010 Michael Vogt <mvo@ubuntu.com> +# +# 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 DebPackage in apt.debfile.""" +import os +import logging +import unittest + +from test_all import get_library_dir +import sys +sys.path.insert(0, get_library_dir()) +import apt_pkg +import apt.debfile + +class TestDebfilee(unittest.TestCase): + """ test the apt cache """ + + TEST_DEBS = [ + # conflicts with apt + ('gdebi-test1.deb', False), + # impossible dependency + ('gdebi-test2.deb', False), + # or-group (impossible-dependency|apt) + ('gdebi-test3.deb', True), + # Conflicts: apt (<= 0.1) + ('gdebi-test4.deb', True), + # Conflicts: apt (>= 0.1) + ('gdebi-test5.deb', False), + # invalid unicode in descr + ('gdebi-test6.deb', True), + # provides/conflicts against "foobarbaz" + ('gdebi-test7.deb', True), + # provides/conflicts/replaces against "mail-transport-agent" + # (should fails if mail-transport-agent is installed) + ('gdebi-test8.deb', False), + # provides/conflicts against real pkg + ('gdebi-test9.deb', True), + # provides debconf-tiny and the real debconf conflicts with + ('gdebi-test10.deb', False), + ] + + def setUp(self): + apt_pkg.init_config() + apt_pkg.config.set("APT::Architecture","i386") + apt_pkg.config.set("Dir::State::status", + "./data/test_debs/var/lib/dpkg/status") + apt_pkg.init_system() + self.cache = apt.Cache() + + def testDebFile(self): + deb = apt.debfile.DebPackage(cache=self.cache) + for (filename, expected_res) in self.TEST_DEBS: + logging.debug("testing %s, expecting %s" % (filename, expected_res)) + deb.open(os.path.join("data", "test_debs", filename)) + res = deb.check() + self.assertEqual(res, expected_res, + "Unexpected result for package '%s' (got %s wanted %s)\n%s" % ( + filename, res, expected_res, deb._failure_string)) + +if __name__ == "__main__": + #logging.basicConfig(level=logging.DEBUG) + unittest.main() diff --git a/tests/test_progress.py b/tests/test_progress.py new file mode 100644 index 00000000..ffab5bc0 --- /dev/null +++ b/tests/test_progress.py @@ -0,0 +1,47 @@ +#!/usr/bin/python +# +# Copyright (C) 2010 Michael Vogt <mvo@ubuntu.com> +# +# 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.progress""" +import unittest + +import apt +import apt_pkg +import os + +class TestAcquireProgress(apt.progress.base.AcquireProgress): + def pulse(self, owner): + self.pulsed = True + # there should be a return value here, either (True,False) + # but often this is forgoten (and causes odd error messages) + # so the lib supports it. we test the lack of support value here + +class TestProgress(unittest.TestCase): + + def setUp(self): + basedir = os.path.abspath(os.path.dirname(__file__)) + # setup apt_pkg config + apt_pkg.init() + apt_pkg.config.set("APT::Architecture", "amd64") + apt_pkg.config.set("Dir::Etc", basedir) + apt_pkg.config.set("Dir::Etc::sourceparts", "/xxx") + # setup lists dir + if not os.path.exists("./tmp/partial"): + os.makedirs("./tmp/partial") + 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) + apt_pkg.config.set("Dir::Etc::sourcelist", "fetch_sources.list") + + def test_acquire_progress(self): + progress = TestAcquireProgress() + cache = apt.Cache() + res = cache.update(progress) + self.assertTrue(progress.pulsed) + +if __name__ == "__main__": + unittest.main() |
