From 44c2dafdd59c98f629b812f6e741c14073908eb2 Mon Sep 17 00:00:00 2001 From: Jason Conti Date: Fri, 12 Oct 2012 14:14:34 -0400 Subject: * tests/test_apt_cache.py: - Add test to verify all files are closed after calling apt.Cache.close() --- tests/test_apt_cache.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index 448aed75..63ce46bc 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -19,6 +19,7 @@ import apt import apt_pkg import shutil import glob +import os import logging def if_sources_list_is_readable(f): @@ -29,6 +30,14 @@ def if_sources_list_is_readable(f): logging.warn("skipping '%s' because sources.list is not readable" % f) return wrapper +def get_open_file_descriptors(): + try: + fds = os.listdir("/proc/self/fd") + except OSError: + logging.warn("failed to list /proc/self/fd") + return set([]) + return set(map(int, fds)) + class TestAptCache(unittest.TestCase): """ test the apt cache """ @@ -70,6 +79,16 @@ class TestAptCache(unittest.TestCase): self.assertTrue(len(r['Description']) > 0) self.assertTrue(str(r).startswith('Package: %s\n' % pkg.shortname)) + @if_sources_list_is_readable + def test_closeable_cache(self): + fd_0 = get_open_file_descriptors() + cache = apt.Cache() + opened_fd = get_open_file_descriptors().difference(fd_0) + cache.close() + fd_1 = get_open_file_descriptors() + unclosed_fd = opened_fd.intersection(fd_1) + self.assertEqual(unclosed_fd, set()) + def test_get_provided_packages(self): apt.apt_pkg.config.set("Apt::architecture", "i386") cache = apt.Cache(rootdir="./data/test-provides/") -- cgit v1.2.3 From 7a7722a91bd80572daf5d5f7f377b7b189e533bf Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 15 Oct 2012 11:17:34 +0200 Subject: add changelog for lp:~jconti/python-apt/closeable-cache and add new test "test_cache_close_download_fails" --- debian/changelog | 5 +++++ tests/test_apt_cache.py | 30 +++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/debian/changelog b/debian/changelog index 1cb722b6..0e8ca556 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,11 +1,16 @@ python-apt (0.8.8.1) UNRELEASED; urgency=low + [ Michael Vogt ] * python/tag.cc: - make TagSecString_FromStringAndSize, TagSecString_FromString static, thanks to jcristau * python/cache.cc: - add "Codename" to PackageFile object * add dep8 style autopkgtest support + + [ Jason Conti ] + * lp:~jconti/python-apt/closeable-cache: + - add apt.Cache.close() method -- Michael Vogt Mon, 15 Oct 2012 10:03:21 +0200 diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index fc429cf3..c850cec2 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -16,6 +16,12 @@ import sys import tempfile import unittest +if sys.version_info[0] == 2 and sys.version_info[1] == 6: + from unittest2 import TestCase +else: + from unittest import TestCase + + from test_all import get_library_dir sys.path.insert(0, get_library_dir()) @@ -41,7 +47,7 @@ def get_open_file_descriptors(): return set(map(int, fds)) -class TestAptCache(unittest.TestCase): +class TestAptCache(TestCase): """ test the apt cache """ def setUp(self): @@ -80,18 +86,28 @@ class TestAptCache(unittest.TestCase): self.assertEqual(r['Package'], pkg.shortname) self.assertTrue('Version' in r) self.assertTrue(len(r['Description']) > 0) - self.assertTrue(str(r).startswith('Package: %s\n' % pkg.shortname)) + self.assertTrue( + str(r).startswith('Package: %s\n' % pkg.shortname)) @if_sources_list_is_readable - def test_closeable_cache(self): - fd_0 = get_open_file_descriptors() + def test_cache_close_leak_fd(self): + fds_before_open = get_open_file_descriptors() cache = apt.Cache() - opened_fd = get_open_file_descriptors().difference(fd_0) + opened_fd = get_open_file_descriptors().difference(fds_before_open) cache.close() - fd_1 = get_open_file_descriptors() - unclosed_fd = opened_fd.intersection(fd_1) + fds_after_close = get_open_file_descriptors() + unclosed_fd = opened_fd.intersection(fds_after_close) + self.assertEqual(fds_before_open, fds_after_close) self.assertEqual(unclosed_fd, set()) + @if_sources_list_is_readable + def test_cache_close_download_fails(self): + cache = apt.Cache() + self.assertEqual(cache.required_download, 0) + cache.close() + with self.assertRaises(apt.cache.CacheClosedException): + cache.required_download + def test_get_provided_packages(self): apt.apt_pkg.config.set("Apt::architecture", "i386") cache = apt.Cache(rootdir="./data/test-provides/") -- cgit v1.2.3 From 3a7246ab8faa36eb270f28e6b47e1608e587365a Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 15 Oct 2012 11:27:49 +0200 Subject: close cache on (re)open --- apt/cache.py | 2 ++ tests/test_apt_cache.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'tests') diff --git a/apt/cache.py b/apt/cache.py index adc936ef..beebde8a 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -142,6 +142,8 @@ class Cache(object): """ if progress is None: progress = apt.progress.base.OpProgress() + # close old cache on (re)open + self.close() self.op_progress = progress self._run_callbacks("cache_pre_open") diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index c850cec2..22c4e871 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -100,6 +100,23 @@ class TestAptCache(TestCase): self.assertEqual(fds_before_open, fds_after_close) self.assertEqual(unclosed_fd, set()) + def test_cache_open_twice_leaks_fds(self): + cache = apt.Cache() + fds_before_open = get_open_file_descriptors() + cache.open() + fds_after_open_twice = get_open_file_descriptors() + self.assertEqual(fds_before_open, fds_after_open_twice) + + @if_sources_list_is_readable + def test_cache_delete_leasks_fds(self): + fds_before_open = get_open_file_descriptors() + cache = apt.Cache() + del cache + import gc + gc.collect() + fds_after_delete = get_open_file_descriptors() + self.assertEqual(fds_before_open, fds_after_delete) + @if_sources_list_is_readable def test_cache_close_download_fails(self): cache = apt.Cache() -- cgit v1.2.3 From 870bf6095484206655f58753a12430da4569645c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 17 Oct 2012 14:44:03 +0200 Subject: tests/test_apt_cache.py: delete test_cache_delete_leasks_fds() as its not reliable --- tests/test_apt_cache.py | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'tests') diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index 22c4e871..7e2ead2d 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -107,16 +107,6 @@ class TestAptCache(TestCase): fds_after_open_twice = get_open_file_descriptors() self.assertEqual(fds_before_open, fds_after_open_twice) - @if_sources_list_is_readable - def test_cache_delete_leasks_fds(self): - fds_before_open = get_open_file_descriptors() - cache = apt.Cache() - del cache - import gc - gc.collect() - fds_after_delete = get_open_file_descriptors() - self.assertEqual(fds_before_open, fds_after_delete) - @if_sources_list_is_readable def test_cache_close_download_fails(self): cache = apt.Cache() -- cgit v1.2.3 From 4e9e2c06c3016703b0e90b2435e672e8774bfedd Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 8 Nov 2012 15:03:12 +0000 Subject: * tests/test_lp659438.py: - Add an Architecture: line to the test Packages file so that apt doesn't get upset with it. --- debian/changelog | 8 ++++++++ tests/test_lp659438.py | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/debian/changelog b/debian/changelog index 7879fef8..efcae83b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +python-apt (0.8.8ubuntu3) UNRELEASED; urgency=low + + * tests/test_lp659438.py: + - Add an Architecture: line to the test Packages file so that apt + doesn't get upset with it. + + -- Colin Watson Thu, 08 Nov 2012 15:02:21 +0000 + python-apt (0.8.8ubuntu2) raring; urgency=low * data/templates/Ubuntu.info.in: diff --git a/tests/test_lp659438.py b/tests/test_lp659438.py index 4564f0f6..da8cfa8e 100644 --- a/tests/test_lp659438.py +++ b/tests/test_lp659438.py @@ -48,7 +48,8 @@ class RegressionTestCase(unittest.TestCase): Status: install reinstreq half-installed Priority: optional Section: admin -Version: 3.6.9+build1+nobinonly-0ubuntu1""") +Version: 3.6.9+build1+nobinonly-0ubuntu1 +Architecture: all""") sources_list_path = apt_pkg.config.find_file("Dir::Etc::sourcelist") repo_path = os.path.abspath("./data/test-repo") with open(sources_list_path, "w") as sources_list: -- cgit v1.2.3 From b1c7cc0732f19431e8365e0dc3f812130dca0bdb Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 19 Nov 2012 11:58:29 +0000 Subject: * tests/test_apt_cache.py, tests/test_lp659438.py, tests/test_progress.py: - Clear out APT::Update::Post-Invoke and APT::Update::Post-Invoke-Success in tests that call cache.update to avoid pollution from the host system. --- debian/changelog | 9 +++++++++ tests/test_apt_cache.py | 2 ++ tests/test_lp659438.py | 2 ++ tests/test_progress.py | 2 ++ 4 files changed, 15 insertions(+) (limited to 'tests') diff --git a/debian/changelog b/debian/changelog index ec17d70a..e503456f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +python-apt (0.8.8ubuntu4) UNRELEASED; urgency=low + + * tests/test_apt_cache.py, tests/test_lp659438.py, tests/test_progress.py: + - Clear out APT::Update::Post-Invoke and + APT::Update::Post-Invoke-Success in tests that call cache.update to + avoid pollution from the host system. + + -- Colin Watson Mon, 19 Nov 2012 11:57:28 +0000 + python-apt (0.8.8ubuntu3) raring; urgency=low * tests/test_lp659438.py: diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index 7e2ead2d..3cf89c07 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -57,6 +57,8 @@ class TestAptCache(TestCase): self._cnf = {} for item in apt_pkg.config.keys(): self._cnf[item] = apt_pkg.config.find(item) + apt_pkg.config.clear("APT::Update::Post-Invoke") + apt_pkg.config.clear("APT::Update::Post-Invoke-Success") def tearDown(self): for item in self._cnf: diff --git a/tests/test_lp659438.py b/tests/test_lp659438.py index da8cfa8e..b9a837b4 100644 --- a/tests/test_lp659438.py +++ b/tests/test_lp659438.py @@ -39,6 +39,8 @@ class RegressionTestCase(unittest.TestCase): def setUp(self): apt_pkg.init_config() + apt_pkg.config.clear("APT::Update::Post-Invoke") + apt_pkg.config.clear("APT::Update::Post-Invoke-Success") self.chroot_path = chroot_path = tempfile.mkdtemp() # Create a damaged status file self.cache = apt.cache.Cache(rootdir=chroot_path) diff --git a/tests/test_progress.py b/tests/test_progress.py index 3b6285d6..b7bba02f 100644 --- a/tests/test_progress.py +++ b/tests/test_progress.py @@ -37,6 +37,8 @@ class TestProgress(unittest.TestCase): with open("fetch_sources.list","w") as fobj: fobj.write(deb_line) apt_pkg.config.set("Dir::Etc::sourcelist", "fetch_sources.list") + apt_pkg.config.clear("APT::Update::Post-Invoke") + apt_pkg.config.clear("APT::Update::Post-Invoke-Success") def test_acquire_progress(self): progress = TestAcquireProgress() -- cgit v1.2.3 From 024b5fda24482226d1ee2eafb297285ebd13e5fa Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 19 Nov 2012 12:37:18 +0000 Subject: * tests/test_auth.py: - Discard stderr from gpg. --- debian/changelog | 2 ++ tests/test_auth.py | 30 ++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/debian/changelog b/debian/changelog index e503456f..1be049b4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,8 @@ python-apt (0.8.8ubuntu4) UNRELEASED; urgency=low - Clear out APT::Update::Post-Invoke and APT::Update::Post-Invoke-Success in tests that call cache.update to avoid pollution from the host system. + * tests/test_auth.py: + - Discard stderr from gpg. -- Colin Watson Mon, 19 Nov 2012 11:57:28 +0000 diff --git a/tests/test_auth.py b/tests/test_auth.py index 2b524d28..183752ba 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +import contextlib import os import shutil import sys @@ -152,6 +153,21 @@ class TestAuthKeys(TestCase): for item in cnf: apt_pkg.config.set(item, cnf[item]) + @contextlib.contextmanager + def _discard_stderr(self): + stderr_fd = sys.stderr.fileno() + stderr_save = os.dup(stderr_fd) + try: + devnull = os.open('/dev/null', os.O_WRONLY) + try: + os.dup2(devnull, stderr_fd) + yield + finally: + os.close(devnull) + finally: + os.dup2(stderr_save, stderr_fd) + os.close(stderr_save) + def testAddAndExportKey(self): """Add an example key.""" apt.auth.add_key(WHEEZY_KEY) @@ -202,9 +218,10 @@ class TestAuthKeys(TestCase): self._start_keyserver() self.addCleanup(self._stop_keyserver) with self.assertRaises(apt.auth.AptKeyError) as cm: - apt.auth.add_key_from_keyserver( - "0101010178F7FE5C3E65D8AF8B48AD6246925553", - "hkp://localhost:19191") + with self._discard_stderr(): + apt.auth.add_key_from_keyserver( + "0101010178F7FE5C3E65D8AF8B48AD6246925553", + "hkp://localhost:19191") self.assertTrue( str(cm.exception).startswith("Fingerprints do not match")) @@ -213,9 +230,10 @@ class TestAuthKeys(TestCase): self._start_keyserver() self.addCleanup(self._stop_keyserver) - apt.auth.add_key_from_keyserver( - "0xa1bD8E9D78F7FE5C3E65D8AF8B48AD6246925553", - "hkp://localhost:19191") + with self._discard_stderr(): + apt.auth.add_key_from_keyserver( + "0xa1bD8E9D78F7FE5C3E65D8AF8B48AD6246925553", + "hkp://localhost:19191") ret = apt.auth.list_keys() self.assertEqual(len(ret), 1) -- cgit v1.2.3 From 386f2f98ac0860d3d34c60127232703fb0122001 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 19 Nov 2012 13:00:55 +0000 Subject: Try successive keyserver ports if 19191 is already in use. --- debian/changelog | 1 + tests/test_auth.py | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/debian/changelog b/debian/changelog index 1be049b4..39685bef 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,7 @@ python-apt (0.8.8ubuntu4) UNRELEASED; urgency=low avoid pollution from the host system. * tests/test_auth.py: - Discard stderr from gpg. + - Try successive keyserver ports if 19191 is already in use. -- Colin Watson Mon, 19 Nov 2012 11:57:28 +0000 diff --git a/tests/test_auth.py b/tests/test_auth.py index 183752ba..be7f41a6 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -1,6 +1,10 @@ #!/usr/bin/env python +from __future__ import print_function + import contextlib +import errno +import itertools import os import shutil import sys @@ -221,7 +225,7 @@ class TestAuthKeys(TestCase): with self._discard_stderr(): apt.auth.add_key_from_keyserver( "0101010178F7FE5C3E65D8AF8B48AD6246925553", - "hkp://localhost:19191") + "hkp://localhost:%d" % self.keyserver_port) self.assertTrue( str(cm.exception).startswith("Fingerprints do not match")) @@ -233,7 +237,7 @@ class TestAuthKeys(TestCase): with self._discard_stderr(): apt.auth.add_key_from_keyserver( "0xa1bD8E9D78F7FE5C3E65D8AF8B48AD6246925553", - "hkp://localhost:19191") + "hkp://localhost:%d" % self.keyserver_port) ret = apt.auth.list_keys() self.assertEqual(len(ret), 1) @@ -246,6 +250,8 @@ class TestAuthKeys(TestCase): def _start_keyserver(self): """Start a fake keyserver on http://localhost:19191 + If port 19191 is unavailable, try successive ports until one is. + Store the port actually in use in self.keyserver_port. Thanks pitti. """ dir = tempfile.mkdtemp() @@ -254,15 +260,31 @@ class TestAuthKeys(TestCase): with open(os.path.join(dir, "pks", "lookup"), "w") as key_file: key_file.write(WHEEZY_KEY) + keyserver_pipe = os.pipe() self.keyserver_pid = os.fork() if self.keyserver_pid == 0: + os.close(keyserver_pipe[0]) # quiesce server log os.dup2(os.open('/dev/null', os.O_WRONLY), sys.stderr.fileno()) os.chdir(dir) - httpd = HTTPServer(('localhost', 19191), HTTPRequestHandler) + for port in itertools.count(19191): + try: + httpd = HTTPServer(('localhost', port), HTTPRequestHandler) + break + except IOError as e: + if e.errno != errno.EADDRINUSE: + raise + keyserver_write = os.fdopen(keyserver_pipe[1], 'w') + print(port, file=keyserver_write) + keyserver_write.close() httpd.serve_forever() os._exit(0) + os.close(keyserver_pipe[1]) + keyserver_read = os.fdopen(keyserver_pipe[0]) + self.keyserver_port = int(keyserver_read.readline()) + keyserver_read.close() + # wait a bit until server is ready time.sleep(0.5) -- cgit v1.2.3 From a0ecfe1c745e07c41c85b80d747b19179341531d Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 19 Nov 2012 13:22:42 +0000 Subject: * aptsources/distinfo.py, aptsources/distro.py, aptsources/sourceslist.py, tests/test_apt_cache.py, tests/test_debfile_multiarch.py: - Use logging.warning rather than the deprecated logging.warn. --- aptsources/distinfo.py | 3 ++- aptsources/distro.py | 2 +- aptsources/sourceslist.py | 2 +- debian/changelog | 3 +++ tests/test_apt_cache.py | 8 ++++---- tests/test_debfile_multiarch.py | 4 ++-- 6 files changed, 13 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/aptsources/distinfo.py b/aptsources/distinfo.py index e0ee915d..d80721e5 100644 --- a/aptsources/distinfo.py +++ b/aptsources/distinfo.py @@ -172,7 +172,8 @@ class DistInfo(object): stdout=PIPE).communicate()[0].strip() except OSError as exc: if exc.errno != errno.ENOENT: - logging.warn('lsb_release failed, using defaults:' % exc) + logging.warning( + 'lsb_release failed, using defaults:' % exc) dist = "Debian" self.dist = dist diff --git a/aptsources/distro.py b/aptsources/distro.py index ca87a919..82fd67ba 100644 --- a/aptsources/distro.py +++ b/aptsources/distro.py @@ -465,7 +465,7 @@ def _lsb_release(): result.update(l.split(":\t") for l in out.split("\n") if ':\t' in l) except OSError as exc: if exc.errno != errno.ENOENT: - logging.warn('lsb_release failed, using defaults:' % exc) + logging.warning('lsb_release failed, using defaults:' % exc) return result diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py index 40902d84..f5a86ecb 100644 --- a/aptsources/sourceslist.py +++ b/aptsources/sourceslist.py @@ -375,7 +375,7 @@ class SourcesList(object): source = SourceEntry(line, file) self.list.append(source) except: - logging.warn("could not open file '%s'\n" % file) + logging.warning("could not open file '%s'\n" % file) def save(self): """ save the current sources """ diff --git a/debian/changelog b/debian/changelog index 39685bef..d9083659 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +7,9 @@ python-apt (0.8.8ubuntu4) UNRELEASED; urgency=low * tests/test_auth.py: - Discard stderr from gpg. - Try successive keyserver ports if 19191 is already in use. + * aptsources/distinfo.py, aptsources/distro.py, aptsources/sourceslist.py, + tests/test_apt_cache.py, tests/test_debfile_multiarch.py: + - Use logging.warning rather than the deprecated logging.warn. -- Colin Watson Mon, 19 Nov 2012 11:57:28 +0000 diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index 3cf89c07..fe90eb8a 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -34,7 +34,7 @@ def if_sources_list_is_readable(f): if os.access("/etc/apt/sources.list", os.R_OK): f(*args, **kwargs) else: - logging.warn("skipping '%s' because sources.list is not readable" % f) + logging.warning("skipping '%s' because sources.list is not readable" % f) return wrapper @@ -42,7 +42,7 @@ def get_open_file_descriptors(): try: fds = os.listdir("/proc/self/fd") except OSError: - logging.warn("failed to list /proc/self/fd") + logging.warning("failed to list /proc/self/fd") return set([]) return set(map(int, fds)) @@ -122,7 +122,7 @@ class TestAptCache(TestCase): cache = apt.Cache(rootdir="./data/test-provides/") cache.open() if len(cache) == 0: - logging.warn("skipping test_get_provided_packages, cache empty?!?") + logging.warning("skipping test_get_provided_packages, cache empty?!?") return # a true virtual pkg l = cache.get_providing_packages("mail-transport-agent") @@ -135,7 +135,7 @@ class TestAptCache(TestCase): # create highlevel cache and get the lowlevel one from it highlevel_cache = apt.Cache(rootdir="./data/test-provides") if len(highlevel_cache) == 0: - logging.warn("skipping test_log_level_pkg_provides, cache empty?!?") + logging.warning("skipping test_log_level_pkg_provides, cache empty?!?") return # low level cache provides list of the pkg cache = highlevel_cache._cache diff --git a/tests/test_debfile_multiarch.py b/tests/test_debfile_multiarch.py index 7c02a32a..8da070aa 100644 --- a/tests/test_debfile_multiarch.py +++ b/tests/test_debfile_multiarch.py @@ -23,7 +23,7 @@ class TestDebfileMultiarch(unittest.TestCase): def test_multiarch_deb_check(self): if apt_pkg.get_architectures() != ["amd64", "i386"]: - logging.warn("skipping test because running on a non-multiarch system") + logging.warning("skipping test because running on a non-multiarch system") return deb = apt.debfile.DebPackage( "./data/test_debs/multiarch-test1_i386.deb") @@ -37,7 +37,7 @@ class TestDebfileMultiarch(unittest.TestCase): # use "lib3ds-1-3" as a test to see if non-multiach lib conflicts work canary = "lib3ds-1-3" if not canary in cache: - logging.warn("skipping test because %s is missing" % canary) + logging.warning("skipping test because %s is missing" % canary) return cache[canary].mark_install() deb = apt.debfile.DebPackage( -- cgit v1.2.3 From 116aa6eec9cf830d81c45ff257f16d7472e5314b Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 19 Nov 2012 13:25:49 +0000 Subject: * tests/test_debfile_multiarch.py: - Don't log warnings when skipping tests; the resulting stderr output causes autopkgtest to fail. --- debian/changelog | 3 +++ tests/test_debfile_multiarch.py | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/debian/changelog b/debian/changelog index d9083659..25125971 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,9 @@ python-apt (0.8.8ubuntu4) UNRELEASED; urgency=low * aptsources/distinfo.py, aptsources/distro.py, aptsources/sourceslist.py, tests/test_apt_cache.py, tests/test_debfile_multiarch.py: - Use logging.warning rather than the deprecated logging.warn. + * tests/test_debfile_multiarch.py: + - Don't log warnings when skipping tests; the resulting stderr output + causes autopkgtest to fail. -- Colin Watson Mon, 19 Nov 2012 11:57:28 +0000 diff --git a/tests/test_debfile_multiarch.py b/tests/test_debfile_multiarch.py index 8da070aa..5e6d0b9a 100644 --- a/tests/test_debfile_multiarch.py +++ b/tests/test_debfile_multiarch.py @@ -23,7 +23,8 @@ class TestDebfileMultiarch(unittest.TestCase): def test_multiarch_deb_check(self): if apt_pkg.get_architectures() != ["amd64", "i386"]: - logging.warning("skipping test because running on a non-multiarch system") + # TODO: use unittest.skip + #logging.warning("skipping test because running on a non-multiarch system") return deb = apt.debfile.DebPackage( "./data/test_debs/multiarch-test1_i386.deb") @@ -37,7 +38,8 @@ class TestDebfileMultiarch(unittest.TestCase): # use "lib3ds-1-3" as a test to see if non-multiach lib conflicts work canary = "lib3ds-1-3" if not canary in cache: - logging.warning("skipping test because %s is missing" % canary) + # TODO: use unittest.skip + #logging.warning("skipping test because %s is missing" % canary) return cache[canary].mark_install() deb = apt.debfile.DebPackage( -- cgit v1.2.3 From b8ea5404dd387aa9f414a44113610d395777b778 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 19 Nov 2012 14:15:23 +0000 Subject: * tests/test_all.py: - Write general test status output to stdout, not stderr. --- debian/changelog | 2 ++ tests/test_all.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/debian/changelog b/debian/changelog index 25125971..2fbfc3b4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,6 +13,8 @@ python-apt (0.8.8ubuntu4) UNRELEASED; urgency=low * tests/test_debfile_multiarch.py: - Don't log warnings when skipping tests; the resulting stderr output causes autopkgtest to fail. + * tests/test_all.py: + - Write general test status output to stdout, not stderr. -- Colin Watson Mon, 19 Nov 2012 11:57:28 +0000 diff --git a/tests/test_all.py b/tests/test_all.py index 0f548781..0eccfa91 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -33,17 +33,22 @@ def get_library_dir(): plat_specifier) return os.path.abspath(library_dir) +class MyTestRunner(unittest.runner.TextTestRunner): + def __init__(self, *args, **kwargs): + kwargs["stream"] = sys.stdout + super(MyTestRunner, self).__init__(*args, **kwargs) + if __name__ == '__main__': if not os.access("/etc/apt/sources.list", os.R_OK): - sys.stderr.write("[tests] Skipping because sources.list is not readable\n") + sys.stdout.write("[tests] Skipping because sources.list is not readable\n") sys.exit(0) - sys.stderr.write("[tests] Running on %s\n" % sys.version.replace("\n", "")) + sys.stdout.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() - sys.stderr.write("Using library_dir: '%s'" % library_dir) + sys.stdout.write("Using library_dir: '%s'" % library_dir) if library_dir: sys.path.insert(0, os.path.abspath(library_dir)) @@ -51,4 +56,4 @@ if __name__ == '__main__': if path.endswith('.py') and os.path.isfile(path): exec('from %s import *' % path[:-3]) - unittest.main() + unittest.main(testRunner=MyTestRunner) -- cgit v1.2.3 From 178bf6c4cbde8a3f66a1b8f018d7a950125eee84 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 19 Nov 2012 14:16:39 +0000 Subject: * tests/test_aptsources.py: - Clean up file object in test_enable_component. --- debian/changelog | 2 ++ tests/test_aptsources.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/debian/changelog b/debian/changelog index 2fbfc3b4..02e99916 100644 --- a/debian/changelog +++ b/debian/changelog @@ -15,6 +15,8 @@ python-apt (0.8.8ubuntu4) UNRELEASED; urgency=low causes autopkgtest to fail. * tests/test_all.py: - Write general test status output to stdout, not stderr. + * tests/test_aptsources.py: + - Clean up file object in test_enable_component. -- Colin Watson Mon, 19 Nov 2012 11:57:28 +0000 diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py index 41cfabb3..75dd91c1 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -164,7 +164,8 @@ class TestAptSources(unittest.TestCase): from subprocess import Popen, PIPE target = "./data/aptsources/sources.list.enable_comps" line = "deb http://archive.ubuntu.com/ubuntu lucid main\n" - open(target, "w").write(line) + with open(target, "w") as target_file: + target_file.write(line) apt_pkg.config.set("Dir::Etc::sourcelist", target) sources = aptsources.sourceslist.SourcesList(True, self.templates) distro = aptsources.distro.get_distro(id="Ubuntu") -- cgit v1.2.3 From 7fd512f22177d4745843d8d282cbb8a964915a21 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 20 Nov 2012 09:44:23 +0100 Subject: tests/*.py: Do not prepend None to sys.path, Python 3.3 redeems that with an unintelligible crash. --- debian/changelog | 7 +++++++ tests/test_apt_cache.py | 4 +++- tests/test_debfile.py | 4 +++- tests/test_debfile_multiarch.py | 4 +++- tests/test_tagfile.py | 4 +++- 5 files changed, 19 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/debian/changelog b/debian/changelog index 4a7a0485..6bfacedf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +python-apt (0.8.8ubuntu5) UNRELEASED; urgency=low + + * tests/*.py: Do not prepend None to sys.path, Python 3.3 redeems that with + an unintelligible crash. + + -- Martin Pitt Tue, 20 Nov 2012 09:43:36 +0100 + python-apt (0.8.8ubuntu4) raring; urgency=low * tests/test_apt_cache.py, tests/test_lp659438.py, tests/test_progress.py: diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index fe90eb8a..21dfeb98 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -23,7 +23,9 @@ else: from test_all import get_library_dir -sys.path.insert(0, get_library_dir()) +libdir = get_library_dir() +if libdir: + sys.path.insert(0, libdir) import apt import apt_pkg diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 04a6b65a..75c46966 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -13,7 +13,9 @@ import unittest from test_all import get_library_dir import sys -sys.path.insert(0, get_library_dir()) +libdir = get_library_dir() +if libdir: + sys.path.insert(0, libdir) import apt_pkg import apt.debfile diff --git a/tests/test_debfile_multiarch.py b/tests/test_debfile_multiarch.py index 5e6d0b9a..bbf62016 100644 --- a/tests/test_debfile_multiarch.py +++ b/tests/test_debfile_multiarch.py @@ -13,7 +13,9 @@ import unittest from test_all import get_library_dir import sys -sys.path.insert(0, get_library_dir()) +libdir = get_library_dir() +if libdir: + sys.path.insert(0, libdir) import apt import apt_pkg import apt.debfile diff --git a/tests/test_tagfile.py b/tests/test_tagfile.py index 33197e6a..f26f851b 100644 --- a/tests/test_tagfile.py +++ b/tests/test_tagfile.py @@ -21,7 +21,9 @@ import tempfile import unittest from test_all import get_library_dir -sys.path.insert(0, get_library_dir()) +libdir = get_library_dir() +if libdir: + sys.path.insert(0, libdir) import apt_pkg -- cgit v1.2.3 From 5b224ace5811c2cc9a1f5506072f04abbd7dc242 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 20 Nov 2012 09:52:18 +0100 Subject: tests/test_auth.py: In test_add_key_from_server_mitm(), show the exception if it does not match the expectation, so that this becomes possible to debug. --- debian/changelog | 3 +++ tests/test_auth.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/debian/changelog b/debian/changelog index 6bfacedf..cce0d623 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,9 @@ python-apt (0.8.8ubuntu5) UNRELEASED; urgency=low * tests/*.py: Do not prepend None to sys.path, Python 3.3 redeems that with an unintelligible crash. + * tests/test_auth.py: In test_add_key_from_server_mitm(), show the exception + if it does not match the expectation, so that this becomes possible to + debug. -- Martin Pitt Tue, 20 Nov 2012 09:43:36 +0100 diff --git a/tests/test_auth.py b/tests/test_auth.py index be7f41a6..7fb8160b 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -227,7 +227,7 @@ class TestAuthKeys(TestCase): "0101010178F7FE5C3E65D8AF8B48AD6246925553", "hkp://localhost:%d" % self.keyserver_port) self.assertTrue( - str(cm.exception).startswith("Fingerprints do not match")) + str(cm.exception).startswith("Fingerprints do not match"), cm.exception) def testAddKeyFromServer(self): """Install a GnuPG key from a remote server.""" -- cgit v1.2.3 From d07479422c5930856ebb5ff362e176bd5c64441a Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 20 Nov 2012 11:41:48 +0100 Subject: tests/test_auth.py: Temporarily disable $http_proxy for the tests, as gnupg does not get along with proxies (LP #789049) --- debian/changelog | 2 ++ tests/test_auth.py | 11 +++++++++++ 2 files changed, 13 insertions(+) (limited to 'tests') diff --git a/debian/changelog b/debian/changelog index cad5c31c..e934f203 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +7,8 @@ python-apt (0.8.8ubuntu5) UNRELEASED; urgency=low debug. * aptsources/distro.py: Replace the deprecated getiterator() ElementTree method with iter(), to avoid raising a PendingDeprecationWarning. + * tests/test_auth.py: Temporarily disable $http_proxy for the tests, as + gnupg does not get along with proxies (LP #789049) -- Martin Pitt Tue, 20 Nov 2012 09:43:36 +0100 diff --git a/tests/test_auth.py b/tests/test_auth.py index 7fb8160b..bc353427 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -285,6 +285,14 @@ class TestAuthKeys(TestCase): self.keyserver_port = int(keyserver_read.readline()) keyserver_read.close() + # temporarily disable proxy, as gnupg does not get along with that + # (LP #789049) + self.orig_proxy = os.environ.get('http_proxy') + try: + del os.environ['http_proxy'] + except KeyError: + pass + # wait a bit until server is ready time.sleep(0.5) @@ -295,6 +303,9 @@ class TestAuthKeys(TestCase): os.kill(self.keyserver_pid, 15) os.wait() + # restore proxy + if self.orig_proxy is not None: + os.environ['http_proxy'] = self.orig_proxy if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From 6c4a6388831e4c9a158f626b94634bddad819592 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 13 Mar 2013 18:36:17 +0100 Subject: python2.6 compat fixes --- aptsources/distro.py | 4 ++++ tests/test_all.py | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/aptsources/distro.py b/aptsources/distro.py index 1c9daa27..108a3012 100644 --- a/aptsources/distro.py +++ b/aptsources/distro.py @@ -163,6 +163,10 @@ class Distribution(object): fname = "/usr/share/xml/iso-codes/iso_3166.xml" if os.path.exists(fname): et = ElementTree(file=fname) + # python2.6 compat, the next two lines can get removed + # once we do not use py2.6 anymore + if getattr(et, "iter", None) is None: + et.iter = et.getiterator it = et.iter('iso_3166_entry') for elm in it: try: diff --git a/tests/test_all.py b/tests/test_all.py index 0eccfa91..25774617 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -6,9 +6,16 @@ # notice and this notice are preserved. """Run all available unit tests.""" import os -import unittest import sys +try: + import unittest.runner + import unittest +except ImportError: + # py2.6 compat + import unittest2 as unittest + + # workaround for py3.2 that apparently does not have this anymore # it has "abiflags" if not hasattr(sys, "pydebug"): -- cgit v1.2.3