From 3bf9c3fe4d19ed4d985dc8b7747a737699f46a7e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 31 Dec 2013 23:25:13 +0100 Subject: make test_pep8.py pass --- tests/test_auth.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'tests/test_auth.py') diff --git a/tests/test_auth.py b/tests/test_auth.py index bc353427..a9cfe736 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -15,6 +15,8 @@ import unittest if sys.version_info[0] > 2: from http.server import HTTPServer from http.server import SimpleHTTPRequestHandler as HTTPRequestHandler + HTTPServer # pyflakes + HTTPRequestHandler # pyflakes else: from BaseHTTPServer import HTTPServer from SimpleHTTPServer import SimpleHTTPRequestHandler as HTTPRequestHandler @@ -22,6 +24,7 @@ else: if sys.version_info[0] == 2 and sys.version_info[1] == 6: from unittest2 import TestCase + TestCase # pyflakes else: from unittest import TestCase @@ -215,7 +218,8 @@ class TestAuthKeys(TestCase): def test_add_key_from_keyserver_too_short(self): """Ensure that short keyids are not imported""" with self.assertRaises(apt.auth.AptKeyError): - apt.auth.add_key_from_keyserver("46925553", "hkp://localhost:19191") + apt.auth.add_key_from_keyserver( + "46925553", "hkp://localhost:19191") def test_add_key_from_server_mitm(self): """Verify that the key fingerprint is verified after download""" @@ -227,7 +231,8 @@ class TestAuthKeys(TestCase): "0101010178F7FE5C3E65D8AF8B48AD6246925553", "hkp://localhost:%d" % self.keyserver_port) self.assertTrue( - str(cm.exception).startswith("Fingerprints do not match"), cm.exception) + str(cm.exception).startswith("Fingerprints do not match"), + cm.exception) def testAddKeyFromServer(self): """Install a GnuPG key from a remote server.""" @@ -236,7 +241,7 @@ class TestAuthKeys(TestCase): with self._discard_stderr(): apt.auth.add_key_from_keyserver( - "0xa1bD8E9D78F7FE5C3E65D8AF8B48AD6246925553", + "0xa1bD8E9D78F7FE5C3E65D8AF8B48AD6246925553", "hkp://localhost:%d" % self.keyserver_port) ret = apt.auth.list_keys() -- cgit v1.2.3 From f6c94dbe9cbfa645b19832842183e248f940f829 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 6 Jan 2014 12:36:29 +0100 Subject: tests: Remove checks for Python older than 2.7 This simplifies the test code a tiny bit. --- tests/test_all.py | 11 +++-------- tests/test_auth.py | 9 +-------- tests/test_size_to_str.py | 9 +-------- 3 files changed, 5 insertions(+), 24 deletions(-) (limited to 'tests/test_auth.py') diff --git a/tests/test_all.py b/tests/test_all.py index 180712f9..6eebb0cf 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -10,8 +10,7 @@ import unittest.runner import unittest import sys -# workaround for py3.2 that apparently does not have this anymore -# it has "abiflags" +# Python 3 only provides abiflags since 3.2 if not hasattr(sys, "pydebug"): if sys.abiflags.startswith("d"): sys.pydebug = True @@ -27,12 +26,8 @@ def get_library_dir(): 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 ""), - plat_specifier) + library_dir = "../build/lib%s%s" % (plat_specifier, + (sys.pydebug and "-pydebug" or "")) return os.path.abspath(library_dir) diff --git a/tests/test_auth.py b/tests/test_auth.py index a9cfe736..dafbdc31 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -22,13 +22,6 @@ else: from SimpleHTTPServer import SimpleHTTPRequestHandler as HTTPRequestHandler -if sys.version_info[0] == 2 and sys.version_info[1] == 6: - from unittest2 import TestCase - TestCase # pyflakes -else: - from unittest import TestCase - - import apt_pkg import apt.auth @@ -118,7 +111,7 @@ DHcut3Yey8o= -----END PGP PUBLIC KEY BLOCK-----""" -class TestAuthKeys(TestCase): +class TestAuthKeys(unittest.TestCase): """Test handling of keys for signed repositories.""" diff --git a/tests/test_size_to_str.py b/tests/test_size_to_str.py index 1d0e9232..ba1e45b3 100644 --- a/tests/test_size_to_str.py +++ b/tests/test_size_to_str.py @@ -2,19 +2,12 @@ __author__ = "Barry Warsaw , James Hunt, Michael Vogt" -import sys import unittest import apt_pkg -if sys.version_info[0] == 2 and sys.version_info[1] == 6: - from unittest2 import TestCase - TestCase # pyflakes -else: - from unittest import TestCase - -class SizeToStrTestCase(TestCase): +class SizeToStrTestCase(unittest.TestCase): """Test apt_pkg.size_to_str""" DATA = { -- cgit v1.2.3 From db910e38e65586c7ab7875edbe2b7f21e03d5450 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 22 Mar 2014 18:34:33 +0100 Subject: tests: Drop some more Python 2.6 cruft We do not support Python 2.6 anymore, so we can get rid of this. --- tests/test_apt_cache.py | 8 +------- tests/test_auth.py | 12 ------------ 2 files changed, 1 insertion(+), 19 deletions(-) (limited to 'tests/test_auth.py') diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index ee4fc50b..4df5e27d 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -16,12 +16,6 @@ import sys import tempfile import unittest -if sys.version_info[0] == 2 and sys.version_info[1] == 6: - from unittest2 import TestCase - TestCase # pyflakes -else: - from unittest import TestCase - from test_all import get_library_dir libdir = get_library_dir() @@ -51,7 +45,7 @@ def get_open_file_descriptors(): return set(map(int, fds)) -class TestAptCache(TestCase): +class TestAptCache(unittest.TestCase): """ test the apt cache """ def setUp(self): diff --git a/tests/test_auth.py b/tests/test_auth.py index dafbdc31..790ed380 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -115,18 +115,6 @@ class TestAuthKeys(unittest.TestCase): """Test handling of keys for signed repositories.""" - if sys.version_info[0] == 2 and sys.version_info[1] < 7: - def addCleanup(self, function, *args, **kwds): - try: - self.cleanup.append(lambda: function(*args, **kwds)) - except AttributeError: - self.cleanup = [lambda: function(*args, **kwds)] - - def tearDown(self): - for f in self.cleanup: - f() - self.cleanup = [] - def setUp(self): # reset any config manipulations done in the individual tests apt_pkg.init_config() -- cgit v1.2.3 From 470da5754d0c97a883b76a7e263a678df83156e0 Mon Sep 17 00:00:00 2001 From: Mauricio Faria de Oliveira Date: Thu, 28 Aug 2014 14:44:10 -0700 Subject: tests/test_auth.py: update for gnupg 1.4.18 The test 'test_add_key_from_server_mitm' needs updating for gnupg 1.4.18 which fail differently/earlier when 'fingerprints do not match' since commit 'Screen keyserver responses' (5230304349490f31aa64ee2b69a8a2bc06bf7816) With that change gnupg actually checks itself(!) if the key that the server send matches the key that the user asked for. Closes: #755342 --- apt/auth.py | 6 ++++++ tests/test_auth.py | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'tests/test_auth.py') diff --git a/apt/auth.py b/apt/auth.py index 6fe7c01a..b8089d0c 100644 --- a/apt/auth.py +++ b/apt/auth.py @@ -154,6 +154,12 @@ def _add_key_from_keyserver(keyid, keyserver, tmp_keyring_dir): if res != 0: raise AptKeyError("recv from '%s' failed for '%s'" % ( keyserver, keyid)) + # FIXME: + # - with gnupg 1.4.18 the downloaded key is actually checked(!), + # i.e. gnupg will not import anything that the server sends + # into the keyring, so the below checks are now redundant *if* + # gnupg 1.4.18 is used + # now export again using the long key id (to ensure that there is # really only this one key in our keyring) and not someone MITM us tmp_export_keyring = os.path.join(tmp_keyring_dir, "export-keyring.gpg") diff --git a/tests/test_auth.py b/tests/test_auth.py index 790ed380..67377363 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -212,7 +212,10 @@ class TestAuthKeys(unittest.TestCase): "0101010178F7FE5C3E65D8AF8B48AD6246925553", "hkp://localhost:%d" % self.keyserver_port) self.assertTrue( - str(cm.exception).startswith("Fingerprints do not match"), + str(cm.exception).startswith( + "recv from 'hkp://localhost:%d' failed for '%s'" % ( + self.keyserver_port, + "0101010178F7FE5C3E65D8AF8B48AD6246925553")), cm.exception) def testAddKeyFromServer(self): -- cgit v1.2.3