diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2010-07-02 16:46:35 +0200 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2010-07-02 16:46:35 +0200 |
| commit | 465b19e6ae3c6daeee0841d38ac93e0c19991c13 (patch) | |
| tree | fe7105c64632ccc9dc22520b6d70a18d5342c97b /tests | |
| parent | 5a6c646ceffab7ce58106eccdccf884b6d332d58 (diff) | |
| parent | dd86db9ddb22b43867b5b4dc211f4440dec7aa6a (diff) | |
| download | python-apt-465b19e6ae3c6daeee0841d38ac93e0c19991c13.tar.gz | |
* merged lp:~kiwinote/python-apt/merge-gdebi-changes, this port the
DebPackage class fixes from gdebi into python-apt so that gdebi can
use the class from python-apt directly
* apt/debfile.py:
- check if the debfiles provides are in conflict with the systems
packages
* tests/test_debs/*.deb, tests/test_debfile.py:
- add automatic test based on the test debs from gdebi
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/test_apt_cache.py | 22 | ||||
| -rw-r--r-- | tests/test_debfile.py | 56 | ||||
| -rw-r--r-- | tests/test_debs/gdebi-test1.deb | bin | 0 -> 934 bytes | |||
| -rw-r--r-- | tests/test_debs/gdebi-test10.deb | bin | 0 -> 614 bytes | |||
| -rw-r--r-- | tests/test_debs/gdebi-test2.deb | bin | 0 -> 554 bytes | |||
| -rw-r--r-- | tests/test_debs/gdebi-test3.deb | bin | 0 -> 570 bytes | |||
| -rw-r--r-- | tests/test_debs/gdebi-test4.deb | bin | 0 -> 2306 bytes | |||
| -rw-r--r-- | tests/test_debs/gdebi-test5.deb | bin | 0 -> 2306 bytes | |||
| -rw-r--r-- | tests/test_debs/gdebi-test6.deb | bin | 0 -> 4312 bytes | |||
| -rw-r--r-- | tests/test_debs/gdebi-test7.deb | bin | 0 -> 578 bytes | |||
| -rw-r--r-- | tests/test_debs/gdebi-test8.deb | bin | 0 -> 598 bytes | |||
| -rw-r--r-- | tests/test_debs/gdebi-test9.deb | bin | 0 -> 586 bytes | |||
| -rw-r--r-- | tests/test_progress.py | 44 |
15 files changed, 141 insertions, 2 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/test_apt_cache.py b/tests/test_apt_cache.py index b27ed778..653a0f48 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -6,12 +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 -import os -import tempfile class TestAptCache(unittest.TestCase): @@ -42,6 +45,21 @@ class TestAptCache(unittest.TestCase): 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") diff --git a/tests/test_debfile.py b/tests/test_debfile.py new file mode 100644 index 00000000..02e25117 --- /dev/null +++ b/tests/test_debfile.py @@ -0,0 +1,56 @@ +#!/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 + +import sys +sys.path.insert(0, "..") + +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 testDebFile(self): + deb = apt.debfile.DebPackage() + for (filename, expected_res) in self.TEST_DEBS: + logging.debug("testing %s, expecting %s" % (filename, expected_res)) + deb.open(os.path.join("test_debs", filename)) + res = deb.check() + self.assertEqual(res, expected_res) + +if __name__ == "__main__": + #logging.basicConfig(level=logging.DEBUG) + unittest.main() diff --git a/tests/test_debs/gdebi-test1.deb b/tests/test_debs/gdebi-test1.deb Binary files differnew file mode 100644 index 00000000..ea9991ac --- /dev/null +++ b/tests/test_debs/gdebi-test1.deb diff --git a/tests/test_debs/gdebi-test10.deb b/tests/test_debs/gdebi-test10.deb Binary files differnew file mode 100644 index 00000000..ca43ace6 --- /dev/null +++ b/tests/test_debs/gdebi-test10.deb diff --git a/tests/test_debs/gdebi-test2.deb b/tests/test_debs/gdebi-test2.deb Binary files differnew file mode 100644 index 00000000..307ac689 --- /dev/null +++ b/tests/test_debs/gdebi-test2.deb diff --git a/tests/test_debs/gdebi-test3.deb b/tests/test_debs/gdebi-test3.deb Binary files differnew file mode 100644 index 00000000..436b9258 --- /dev/null +++ b/tests/test_debs/gdebi-test3.deb diff --git a/tests/test_debs/gdebi-test4.deb b/tests/test_debs/gdebi-test4.deb Binary files differnew file mode 100644 index 00000000..9eb92d1b --- /dev/null +++ b/tests/test_debs/gdebi-test4.deb diff --git a/tests/test_debs/gdebi-test5.deb b/tests/test_debs/gdebi-test5.deb Binary files differnew file mode 100644 index 00000000..0c98c03f --- /dev/null +++ b/tests/test_debs/gdebi-test5.deb diff --git a/tests/test_debs/gdebi-test6.deb b/tests/test_debs/gdebi-test6.deb Binary files differnew file mode 100644 index 00000000..32fd1800 --- /dev/null +++ b/tests/test_debs/gdebi-test6.deb diff --git a/tests/test_debs/gdebi-test7.deb b/tests/test_debs/gdebi-test7.deb Binary files differnew file mode 100644 index 00000000..c0414990 --- /dev/null +++ b/tests/test_debs/gdebi-test7.deb diff --git a/tests/test_debs/gdebi-test8.deb b/tests/test_debs/gdebi-test8.deb Binary files differnew file mode 100644 index 00000000..439f8ca7 --- /dev/null +++ b/tests/test_debs/gdebi-test8.deb diff --git a/tests/test_debs/gdebi-test9.deb b/tests/test_debs/gdebi-test9.deb Binary files differnew file mode 100644 index 00000000..9901d906 --- /dev/null +++ b/tests/test_debs/gdebi-test9.deb diff --git a/tests/test_progress.py b/tests/test_progress.py new file mode 100644 index 00000000..2ab8ce5e --- /dev/null +++ b/tests/test_progress.py @@ -0,0 +1,44 @@ +#!/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 + +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() |
