summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2012-12-11 15:32:02 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2012-12-11 15:32:02 +0100
commit610c1592a0118483651e66d12eea51df0624ebc1 (patch)
treef4ce184c0418eccd47bcde40df1063a4430c6f88
parent2ad969f628aee2948a12f8c3ba03572646ac4c5f (diff)
parentc7eb97c2fc8e2f4d3a7e41ac615382657eb95d49 (diff)
downloadpython-apt-610c1592a0118483651e66d12eea51df0624ebc1.tar.gz
merged test-fixes from ubuntu (mostly for dep8)
-rw-r--r--aptsources/distinfo.py3
-rw-r--r--aptsources/distro.py4
-rw-r--r--aptsources/sourceslist.py2
-rw-r--r--data/templates/Ubuntu.info.in6
-rw-r--r--debian/changelog35
-rw-r--r--tests/test_all.py13
-rw-r--r--tests/test_apt_cache.py14
-rw-r--r--tests/test_aptsources.py3
-rw-r--r--tests/test_auth.py67
-rw-r--r--tests/test_debfile.py4
-rw-r--r--tests/test_debfile_multiarch.py10
-rw-r--r--tests/test_lp659438.py6
-rw-r--r--tests/test_progress.py2
-rw-r--r--tests/test_tagfile.py4
14 files changed, 141 insertions, 32 deletions
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..1c9daa27 100644
--- a/aptsources/distro.py
+++ b/aptsources/distro.py
@@ -163,7 +163,7 @@ class Distribution(object):
fname = "/usr/share/xml/iso-codes/iso_3166.xml"
if os.path.exists(fname):
et = ElementTree(file=fname)
- it = et.getiterator('iso_3166_entry')
+ it = et.iter('iso_3166_entry')
for elm in it:
try:
descr = elm.attrib["common_name"]
@@ -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/data/templates/Ubuntu.info.in b/data/templates/Ubuntu.info.in
index a3fc1bec..567456b3 100644
--- a/data/templates/Ubuntu.info.in
+++ b/data/templates/Ubuntu.info.in
@@ -30,14 +30,14 @@ ParentSuite: raring
RepositoryType: deb-src
BaseURI: http://archive.ubuntu.com/ubuntu/
MatchURI: archive.ubuntu.com/ubuntu|ports.ubuntu.com/ubuntu-ports
-_Description: Ubuntu 12.04 'Precise Pangolin'
+_Description: Ubuntu 13.04 'Raring Ringtail'
Suite: raring
RepositoryType: deb
MatchName: .*
BaseURI: cdrom:\[Ubuntu.*13.04
MatchURI: cdrom:\[Ubuntu.*13.04
-_Description: Cdrom with Ubuntu 12.04 'Raring Ringtail'
+_Description: Cdrom with Ubuntu 13.04 'Raring Ringtail'
Available: False
Component: main
_CompDescription: Officially supported
@@ -129,7 +129,7 @@ BaseURI-i386: http://archive.ubuntu.com/ubuntu
MatchURI-i386: archive.ubuntu.com/ubuntu
MirrorsFile-amd64: Ubuntu.mirrors
MirrorsFile-i386: Ubuntu.mirrors
-_Description: Ubuntu 12.04 'Precise Pangolin'
+_Description: Ubuntu 12.10 'Quantal Quetzal'
Component: main
_CompDescription: Officially supported
_CompDescriptionLong: Canonical-supported free and open-source software
diff --git a/debian/changelog b/debian/changelog
index 2db49743..a7292ef3 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -14,7 +14,42 @@ python-apt (0.8.9~exp1) UNRELEASED; urgency=low
[ Jason Conti ]
* lp:~jconti/python-apt/closeable-cache:
- add apt.Cache.close() method
+
+ [ Martin Pitt ]
+ * 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.
+ * 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)
+ [ Colin Watson ]
+ * 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.
+ * 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.
+ * 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.
+ * tests/test_aptsources.py:
+ - Clean up file object in test_enable_component.
+ * tests/test_lp659438.py:
+ - Add an Architecture: line to the test Packages file so that apt
+ doesn't get upset with it.
+ * data/templates/Ubuntu.info.in:
+ - Fix descriptions of quantal and raring.
+
-- Michael Vogt <mvo@debian.org> Mon, 15 Oct 2012 10:03:21 +0200
python-apt (0.8.8.2) UNRELEASED; urgency=low
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)
diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py
index 7e2ead2d..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
@@ -34,7 +36,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 +44,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))
@@ -57,6 +59,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:
@@ -120,7 +124,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")
@@ -133,7 +137,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_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")
diff --git a/tests/test_auth.py b/tests/test_auth.py
index 2b524d28..bc353427 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -1,5 +1,10 @@
#!/usr/bin/env python
+from __future__ import print_function
+
+import contextlib
+import errno
+import itertools
import os
import shutil
import sys
@@ -152,6 +157,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,20 +222,22 @@ 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:%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."""
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:%d" % self.keyserver_port)
ret = apt.auth.list_keys()
self.assertEqual(len(ret), 1)
@@ -228,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()
@@ -236,15 +260,39 @@ 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()
+
+ # 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)
@@ -255,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()
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 7c02a32a..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
@@ -23,7 +25,8 @@ 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")
+ # 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 +40,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.warn("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(
diff --git a/tests/test_lp659438.py b/tests/test_lp659438.py
index d3bdd910..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)
@@ -48,8 +50,8 @@ class RegressionTestCase(unittest.TestCase):
Status: install reinstreq half-installed
Priority: optional
Section: admin
-Architecture: all
-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:
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()
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