[Python-modules-commits] [python-urllib3] 06/15: Import python-urllib3_1.22.orig.tar.gz

Ondrej Novy onovy at debian.org
Mon Dec 11 22:11:42 UTC 2017


This is an automated email from the git hooks/post-receive script.

onovy pushed a commit to branch master
in repository python-urllib3.

commit f42e59e953528206c93c29f8da8ca03463e3fcfc
Author: Ondřej Nový <onovy at debian.org>
Date:   Mon Dec 11 21:53:32 2017 +0100

    Import python-urllib3_1.22.orig.tar.gz
---
 CHANGES.rst                                     |  17 +
 CONTRIBUTORS.txt                                |   3 +
 PKG-INFO                                        |  27 +-
 dev-requirements.txt                            |   3 +
 docs/requirements.txt                           |   1 +
 dummyserver/handlers.py                         |   3 +
 setup.cfg                                       |   2 +-
 setup.py                                        |   9 +
 test/appengine/__init__.py                      |  71 ---
 test/appengine/app.yaml                         |  11 -
 test/appengine/conftest.py                      |  72 +++
 test/appengine/nose.cfg                         |   4 -
 test/appengine/requirements.txt                 |   1 -
 test/{contrib => appengine}/test_gae_manager.py |  97 ++--
 test/appengine/test_urlfetch.py                 |  54 ++-
 test/contrib/test_socks.py                      |   3 +
 test/test_collections.py                        | 348 +++++++-------
 test/test_compatibility.py                      |  25 +-
 test/test_connection.py                         |  26 +-
 test/test_connectionpool.py                     | 452 +++++++++---------
 test/test_exceptions.py                         |  67 +--
 test/test_fields.py                             |  42 +-
 test/test_filepost.py                           |  90 ++--
 test/test_proxymanager.py                       |  68 ++-
 test/test_queue_monkeypatch.py                  |  24 +-
 test/test_response.py                           | 311 ++++++------
 test/test_retry.py                              | 171 +++----
 test/test_util.py                               | 604 +++++++++++-------------
 test/with_dummyserver/test_connectionpool.py    |  58 +++
 test/with_dummyserver/test_https.py             |  61 ++-
 test/with_dummyserver/test_poolmanager.py       |   1 +
 test/with_dummyserver/test_proxy_poolmanager.py |  17 +-
 test/with_dummyserver/test_socketlevel.py       | 140 +++++-
 urllib3.egg-info/PKG-INFO                       |  27 +-
 urllib3.egg-info/SOURCES.txt                    |   6 +-
 urllib3/__init__.py                             |   2 +-
 urllib3/_collections.py                         |   9 +-
 urllib3/connectionpool.py                       |  58 ++-
 urllib3/contrib/_securetransport/bindings.py    |   3 +
 urllib3/contrib/pyopenssl.py                    |  11 +-
 urllib3/contrib/securetransport.py              |   3 +
 urllib3/response.py                             |   4 +
 urllib3/util/ssl_.py                            |   6 +-
 43 files changed, 1600 insertions(+), 1412 deletions(-)

diff --git a/CHANGES.rst b/CHANGES.rst
index 917d9ad..25ff7e2 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,23 @@
 Changes
 =======
 
+1.22 (2017-07-20)
+-----------------
+
+* Fixed missing brackets in ``HTTP CONNECT`` when connecting to IPv6 address via
+  IPv6 proxy. (Issue #1222)
+
+* Made the connection pool retry on ``SSLError``.  The original ``SSLError``
+  is available on ``MaxRetryError.reason``. (Issue #1112)
+
+* Drain and release connection before recursing on retry/redirect.  Fixes
+  deadlocks with a blocking connectionpool. (Issue #1167)
+
+* Fixed compatibility for cookiejar. (Issue #1229)
+
+* pyopenssl: Use vendored version of ``six``. (Issue #1231)
+
+
 1.21.1 (2017-05-02)
 -------------------
 
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index cdd19fa..6f8c254 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -230,5 +230,8 @@ In chronological order:
 * Tuukka Mustonen <tuukka.mustonen at gmail.com>
   * Add counter for status_forcelist retries.
 
+* Erik Rose <erik at mozilla.com>
+  * Bugfix to pyopenssl vendoring
+
 * [Your name or handle] <[email or website]>
   * [Brief summary of your changes]
diff --git a/PKG-INFO b/PKG-INFO
index e6ba1c5..ec0cfb9 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: urllib3
-Version: 1.21.1
+Version: 1.22
 Summary: HTTP library with thread-safe connection pooling, file post, and more.
 Home-page: https://urllib3.readthedocs.io/
 Author: Andrey Petrov
@@ -102,6 +102,23 @@ Description: urllib3
         Changes
         =======
         
+        1.22 (2017-07-20)
+        -----------------
+        
+        * Fixed missing brackets in ``HTTP CONNECT`` when connecting to IPv6 address via
+          IPv6 proxy. (Issue #1222)
+        
+        * Made the connection pool retry on ``SSLError``.  The original ``SSLError``
+          is available on ``MaxRetryError.reason``. (Issue #1112)
+        
+        * Drain and release connection before recursing on retry/redirect.  Fixes
+          deadlocks with a blocking connectionpool. (Issue #1167)
+        
+        * Fixed compatibility for cookiejar. (Issue #1229)
+        
+        * pyopenssl: Use vendored version of ``six``. (Issue #1231)
+        
+        
         1.21.1 (2017-05-02)
         -------------------
         
@@ -991,6 +1008,14 @@ Classifier: License :: OSI Approved :: MIT License
 Classifier: Operating System :: OS Independent
 Classifier: Programming Language :: Python
 Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
 Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
+Classifier: Programming Language :: Python :: Implementation :: CPython
+Classifier: Programming Language :: Python :: Implementation :: PyPy
 Classifier: Topic :: Internet :: WWW/HTTP
 Classifier: Topic :: Software Development :: Libraries
diff --git a/dev-requirements.txt b/dev-requirements.txt
index d241d9d..70938ff 100644
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -9,3 +9,6 @@ tornado==4.2.1
 PySocks==1.5.6
 pkginfo>=1.0,!=1.3.0
 psutil==4.3.1
+pytest-cov==2.5.1
+pytest==3.1.0
+gcp-devrel-py-tools==0.0.7
diff --git a/docs/requirements.txt b/docs/requirements.txt
index 05b104a..45d80de 100644
--- a/docs/requirements.txt
+++ b/docs/requirements.txt
@@ -2,3 +2,4 @@
 ndg-httpsclient
 sphinx
 alabaster
+requests>=2.0,<2.16
diff --git a/dummyserver/handlers.py b/dummyserver/handlers.py
index 44f5cda..a943b83 100644
--- a/dummyserver/handlers.py
+++ b/dummyserver/handlers.py
@@ -165,6 +165,9 @@ class TestingApp(RequestHandler):
         headers = [('Location', target)]
         return Response(status=status, headers=headers)
 
+    def not_found(self, request):
+        return Response('Not found', status='404 Not Found')
+
     def multi_redirect(self, request):
         "Performs a redirect chain based on ``redirect_codes``"
         codes = request.params.get('redirect_codes', '200').decode('utf-8')
diff --git a/setup.cfg b/setup.cfg
index e585a59..b3b22f9 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -8,7 +8,7 @@ cover-erase = true
 exclude = ./docs/conf.py,./urllib3/packages/*
 max-line-length = 99
 
-[wheel]
+[bdist_wheel]
 universal = 1
 
 [metadata]
diff --git a/setup.py b/setup.py
index fbff594..35e02aa 100644
--- a/setup.py
+++ b/setup.py
@@ -30,7 +30,15 @@ setup(name='urllib3',
           'Operating System :: OS Independent',
           'Programming Language :: Python',
           'Programming Language :: Python :: 2',
+          'Programming Language :: Python :: 2.6',
+          'Programming Language :: Python :: 2.7',
           'Programming Language :: Python :: 3',
+          'Programming Language :: Python :: 3.3',
+          'Programming Language :: Python :: 3.4',
+          'Programming Language :: Python :: 3.5',
+          'Programming Language :: Python :: 3.6',
+          'Programming Language :: Python :: Implementation :: CPython',
+          'Programming Language :: Python :: Implementation :: PyPy',
           'Topic :: Internet :: WWW/HTTP',
           'Topic :: Software Development :: Libraries',
       ],
@@ -48,6 +56,7 @@ setup(name='urllib3',
       tests_require=[
           # These are a less-specific subset of dev-requirements.txt, for the
           # convenience of distro package maintainers.
+          'pytest',
           'nose',
           'mock',
           'tornado',
diff --git a/test/appengine/__init__.py b/test/appengine/__init__.py
index 917544d..e69de29 100644
--- a/test/appengine/__init__.py
+++ b/test/appengine/__init__.py
@@ -1,71 +0,0 @@
-import os
-import sys
-import unittest
-from nose.plugins.skip import SkipTest
-
-
-def activate_sandbox():
-    """
-    Enables parts of the GAE sandbox that are relevant.
-
-    Inserts the stub module import hook which causes the usage of appengine-specific
-    httplib, httplib2, socket, etc.
-    """
-    from google.appengine.tools.devappserver2.python import sandbox
-
-    for name in list(sys.modules):
-        if name in sandbox.dist27.MODULE_OVERRIDES:
-            del sys.modules[name]
-    sys.meta_path.insert(0, sandbox.StubModuleImportHook())
-    sys.path_importer_cache = {}
-
-
-def deactivate_sandbox():
-    from google.appengine.tools.devappserver2.python import sandbox
-
-    sys.meta_path = [
-        x for x in sys.meta_path if not isinstance(x, sandbox.StubModuleImportHook)]
-    sys.path_importer_cache = {}
-
-    # Delete any instances of sandboxed modules.
-    for name in list(sys.modules):
-        if name in sandbox.dist27.MODULE_OVERRIDES:
-            del sys.modules[name]
-
-
-class AppEngineSandboxTest(unittest.TestCase):
-
-    @classmethod
-    def setUpClass(cls):
-
-        if sys.version_info[:2] != (2, 7):
-            raise SkipTest("App Engine only tests on py2.7")
-
-        if 'APPLICATION_ID' not in os.environ:
-            raise SkipTest("NoseGAE plugin not used.")
-
-        try:
-            activate_sandbox()
-        except ImportError:
-            raise SkipTest("App Engine SDK not available.")
-
-    @classmethod
-    def tearDownClass(self):
-        try:
-            deactivate_sandbox()
-        except ImportError:
-            pass
-
-
-class MockResponse(object):
-    def __init__(self, content, status_code, content_was_truncated, final_url, headers):
-        import httplib
-        from StringIO import StringIO
-
-        self.content = content
-        self.status_code = status_code
-        self.content_was_truncated = content_was_truncated
-        self.final_url = final_url
-        self.header_msg = httplib.HTTPMessage(StringIO(''.join(
-            ["%s: %s\n" % (k, v) for k, v in headers.iteritems()] + ["\n"])))
-        self.headers = self.header_msg.items()
diff --git a/test/appengine/app.yaml b/test/appengine/app.yaml
deleted file mode 100644
index 907c57f..0000000
--- a/test/appengine/app.yaml
+++ /dev/null
@@ -1,11 +0,0 @@
-# dummy app.yaml for nosegae
-
-api_version: 1
-runtime: python27
-threadsafe: true
-
-handlers:
-- url: /
-  static_files: README.md
-  upload: README.md
-  mime_type: text/plain
diff --git a/test/appengine/conftest.py b/test/appengine/conftest.py
new file mode 100644
index 0000000..a0e3a04
--- /dev/null
+++ b/test/appengine/conftest.py
@@ -0,0 +1,72 @@
+# Copyright 2015 Google Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import sys
+
+# Import py.test hooks and fixtures for App Engine
+from gcp_devrel.testing.appengine import (
+    pytest_configure,
+    pytest_runtest_call,
+    testbed
+)
+import pytest
+import six
+
+
+__all__ = [
+    'pytest_configure',
+    'pytest_runtest_call',
+    'pytest_ignore_collect',
+    'testbed',
+    'sandbox',
+]
+
+
+ at pytest.fixture
+def sandbox(testbed):
+    """
+    Enables parts of the GAE sandbox that are relevant.
+    Inserts the stub module import hook which causes the usage of
+    appengine-specific httplib, httplib2, socket, etc.
+    """
+    from google.appengine.tools.devappserver2.python import sandbox
+
+    for name in list(sys.modules):
+        if name in sandbox.dist27.MODULE_OVERRIDES:
+            del sys.modules[name]
+    sys.meta_path.insert(0, sandbox.StubModuleImportHook())
+    sys.path_importer_cache = {}
+
+    yield testbed
+
+    sys.meta_path = [
+        x for x in sys.meta_path
+        if not isinstance(x, sandbox.StubModuleImportHook)]
+    sys.path_importer_cache = {}
+
+    # Delete any instances of sandboxed modules.
+    for name in list(sys.modules):
+        if name in sandbox.dist27.MODULE_OVERRIDES:
+            del sys.modules[name]
+
+
+def pytest_ignore_collect(path, config):
+    """Skip App Engine tests in python 3 or if no SDK is available."""
+    if 'appengine' in str(path):
+        if six.PY3:
+            return True
+        if not os.environ.get('GAE_SDK_PATH'):
+            return True
+    return False
diff --git a/test/appengine/nose.cfg b/test/appengine/nose.cfg
deleted file mode 100644
index 8d8b3f1..0000000
--- a/test/appengine/nose.cfg
+++ /dev/null
@@ -1,4 +0,0 @@
-[nosetests]
-cover-min-percentage=0
-with-gae=1
-gae-application=test/appengine/app.yaml
diff --git a/test/appengine/requirements.txt b/test/appengine/requirements.txt
deleted file mode 100644
index b6d79e0..0000000
--- a/test/appengine/requirements.txt
+++ /dev/null
@@ -1 +0,0 @@
-NoseGAE==0.5.7
diff --git a/test/contrib/test_gae_manager.py b/test/appengine/test_gae_manager.py
similarity index 69%
rename from test/contrib/test_gae_manager.py
rename to test/appengine/test_gae_manager.py
index 685c4ab..95838ef 100644
--- a/test/contrib/test_gae_manager.py
+++ b/test/appengine/test_gae_manager.py
@@ -1,29 +1,12 @@
-import unittest
+import dummyserver.testcase
+import pytest
 
-from dummyserver.testcase import HTTPSDummyServerTestCase
-from nose.plugins.skip import SkipTest
+from urllib3.contrib import appengine
+import urllib3.exceptions
+import urllib3.util.url
+import urllib3.util.retry
 
-try:
-    from google.appengine.api import urlfetch
-    (urlfetch)
-except ImportError:
-    raise SkipTest("App Engine SDK not available.")
-
-from urllib3.contrib.appengine import AppEngineManager, AppEnginePlatformError
-from urllib3.exceptions import (
-    TimeoutError,
-    ProtocolError,
-    SSLError)
-from urllib3.util.url import Url
-from urllib3.util.retry import Retry, RequestHistory
-
-from test.with_dummyserver.test_connectionpool import (
-    TestConnectionPool, TestRetry, TestRetryAfter)
-
-
-# Prevent nose from running these test.
-TestConnectionPool.__test__ = False
-TestRetry.__test__ = False
+from test.with_dummyserver import test_connectionpool
 
 
 # This class is used so we can re-use the tests from the connection pool.
@@ -44,7 +27,7 @@ class MockPool(object):
         return self.manager.urlopen(method, url, *args, **kwargs)
 
     def _absolute_url(self, path):
-        return Url(
+        return urllib3.util.url.Url(
             scheme=self.scheme,
             host=self.host,
             port=self.port,
@@ -54,14 +37,11 @@ class MockPool(object):
 # Note that this doesn't run in the sandbox, it only runs with the URLFetch
 # API stub enabled. There's no need to enable the sandbox as we know for a fact
 # that URLFetch is used by the connection manager.
-class TestGAEConnectionManager(TestConnectionPool):
-    __test__ = True
-
-    # Magic class variable that tells NoseGAE to enable the URLFetch stub.
-    nosegae_urlfetch = True
+ at pytest.mark.usefixtures('testbed')
+class TestGAEConnectionManager(test_connectionpool.TestConnectionPool):
 
     def setUp(self):
-        self.manager = AppEngineManager()
+        self.manager = appengine.AppEngineManager()
         self.pool = MockPool(self.host, self.port, self.manager)
 
     # Tests specific to AppEngineManager
@@ -69,7 +49,7 @@ class TestGAEConnectionManager(TestConnectionPool):
     def test_exceptions(self):
         # DeadlineExceededError -> TimeoutError
         self.assertRaises(
-            TimeoutError,
+            urllib3.exceptions.TimeoutError,
             self.pool.request,
             'GET',
             '/sleep?seconds=0.005',
@@ -77,21 +57,21 @@ class TestGAEConnectionManager(TestConnectionPool):
 
         # InvalidURLError -> ProtocolError
         self.assertRaises(
-            ProtocolError,
+            urllib3.exceptions.ProtocolError,
             self.manager.request,
             'GET',
             'ftp://invalid/url')
 
         # DownloadError -> ProtocolError
         self.assertRaises(
-            ProtocolError,
+            urllib3.exceptions.ProtocolError,
             self.manager.request,
             'GET',
             'http://0.0.0.0')
 
         # ResponseTooLargeError -> AppEnginePlatformError
         self.assertRaises(
-            AppEnginePlatformError,
+            appengine.AppEnginePlatformError,
             self.pool.request,
             'GET',
             '/nbytes?length=33554433')  # One byte over 32 megabtyes.
@@ -100,7 +80,7 @@ class TestGAEConnectionManager(TestConnectionPool):
         # which maps to a AppEnginePlatformError.
         body = b'1' * 10485761  # One byte over 10 megabytes.
         self.assertRaises(
-            AppEnginePlatformError,
+            appengine.AppEnginePlatformError,
             self.manager.request,
             'POST',
             '/',
@@ -139,11 +119,12 @@ class TestGAEConnectionManager(TestConnectionPool):
     test_dns_error = None
 
 
-class TestGAEConnectionManagerWithSSL(HTTPSDummyServerTestCase):
-    nosegae_urlfetch = True
+ at pytest.mark.usefixtures('testbed')
+class TestGAEConnectionManagerWithSSL(
+        dummyserver.testcase.HTTPSDummyServerTestCase):
 
     def setUp(self):
-        self.manager = AppEngineManager()
+        self.manager = appengine.AppEngineManager()
         self.pool = MockPool(self.host, self.port, self.manager, 'https')
 
     def test_exceptions(self):
@@ -151,25 +132,22 @@ class TestGAEConnectionManagerWithSSL(HTTPSDummyServerTestCase):
         # SSLError is raised with dummyserver because URLFetch doesn't allow
         # self-signed certs.
         self.assertRaises(
-            SSLError,
+            urllib3.exceptions.SSLError,
             self.pool.request,
             'GET',
             '/')
 
 
-class TestGAERetry(TestRetry):
-    __test__ = True
-
-    # Magic class variable that tells NoseGAE to enable the URLFetch stub.
-    nosegae_urlfetch = True
+ at pytest.mark.usefixtures('testbed')
+class TestGAERetry(test_connectionpool.TestRetry):
 
     def setUp(self):
-        self.manager = AppEngineManager()
+        self.manager = appengine.AppEngineManager()
         self.pool = MockPool(self.host, self.port, self.manager)
 
     def test_default_method_whitelist_retried(self):
         """ urllib3 should retry methods in the default method whitelist """
-        retry = Retry(total=1, status_forcelist=[418])
+        retry = urllib3.util.retry.Retry(total=1, status_forcelist=[418])
         # Use HEAD instead of OPTIONS, as URLFetch doesn't support OPTIONS
         resp = self.pool.request(
             'HEAD', '/successful_retry',
@@ -179,16 +157,18 @@ class TestGAERetry(TestRetry):
 
     def test_retry_return_in_response(self):
         headers = {'test-name': 'test_retry_return_in_response'}
-        retry = Retry(total=2, status_forcelist=[418])
+        retry = urllib3.util.retry.Retry(total=2, status_forcelist=[418])
         resp = self.pool.request('GET', '/successful_retry',
                                  headers=headers, retries=retry)
         self.assertEqual(resp.status, 200)
         self.assertEqual(resp.retries.total, 1)
         # URLFetch use absolute urls.
-        self.assertEqual(resp.retries.history,
-                         (RequestHistory('GET',
-                                         self.pool._absolute_url('/successful_retry'),
-                                         None, 418, None),))
+        self.assertEqual(
+            resp.retries.history,
+            (urllib3.util.retry.RequestHistory(
+                'GET',
+                self.pool._absolute_url('/successful_retry'),
+                None, 418, None),))
 
     # test_max_retry = None
     # test_disabled_retry = None
@@ -197,17 +177,10 @@ class TestGAERetry(TestRetry):
     test_multi_redirect_history = None
 
 
-class TestGAERetryAfter(TestRetryAfter):
-    __test__ = True
-
-    # Magic class variable that tells NoseGAE to enable the URLFetch stub.
-    nosegae_urlfetch = True
+ at pytest.mark.usefixtures('testbed')
+class TestGAERetryAfter(test_connectionpool.TestRetryAfter):
 
     def setUp(self):
         # Disable urlfetch which doesn't respect Retry-After header.
-        self.manager = AppEngineManager(urlfetch_retries=False)
+        self.manager = appengine.AppEngineManager(urlfetch_retries=False)
         self.pool = MockPool(self.host, self.port, self.manager)
-
-
-if __name__ == '__main__':
-    unittest.main()
diff --git a/test/appengine/test_urlfetch.py b/test/appengine/test_urlfetch.py
index 3f72023..9971d8e 100644
--- a/test/appengine/test_urlfetch.py
+++ b/test/appengine/test_urlfetch.py
@@ -1,49 +1,73 @@
-from . import AppEngineSandboxTest, MockResponse
+"""These tests ensure that when running in App Engine standard with the
+App Engine sandbox enabled that urllib3 appropriately uses the App
+Engine-patched version of httplib to make requests."""
+
+import httplib
+import StringIO
+import unittest
 
 from mock import patch
-from nose.plugins.skip import SkipTest
+import pytest
+
 from ..test_no_ssl import TestWithoutSSL
 
 
-class TestHTTP(AppEngineSandboxTest, TestWithoutSSL):
-    nosegae_urlfetch = True
+class MockResponse(object):
+    def __init__(self, content, status_code, content_was_truncated, final_url,
+                 headers):
+
+        self.content = content
+        self.status_code = status_code
+        self.content_was_truncated = content_was_truncated
+        self.final_url = final_url
+        self.header_msg = httplib.HTTPMessage(StringIO.StringIO(''.join(
+            ["%s: %s\n" % (k, v) for k, v in headers.iteritems()] + ["\n"])))
+        self.headers = headers
+
 
+ at pytest.mark.usefixtures('sandbox')
+class TestHTTP(TestWithoutSSL):
     def test_urlfetch_called_with_http(self):
-        """
-        Check that URLFetch is used to fetch non-https resources
-        """
+        """Check that URLFetch is used to fetch non-https resources."""
         resp = MockResponse(
             'OK',
             200,
             False,
             'http://www.google.com',
             {'content-type': 'text/plain'})
-        with patch('google.appengine.api.urlfetch.fetch', return_value=resp) as fetchmock:
+        fetch_patch = patch(
+            'google.appengine.api.urlfetch.fetch', return_value=resp
+        )
+        with fetch_patch as fetch_mock:
             import urllib3
             pool = urllib3.HTTPConnectionPool('www.google.com', '80')
             r = pool.request('GET', '/')
             self.assertEqual(r.status, 200, r.data)
-            self.assertEqual(fetchmock.call_count, 1)
-
+            self.assertEqual(fetch_mock.call_count, 1)
 
-class TestHTTPS(AppEngineSandboxTest):
-    nosegae_urlfetch = True
 
+ at pytest.mark.usefixtures('sandbox')
+class TestHTTPS(unittest.TestCase):
+    @pytest.mark.xfail(
+        reason='This is not yet supported by urlfetch, presence of the ssl '
+               'module will bypass urlfetch.')
     def test_urlfetch_called_with_https(self):
         """
         Check that URLFetch is used when fetching https resources
         """
-        raise SkipTest()  # Skipped for now because it fails.
         resp = MockResponse(
             'OK',
             200,
             False,
             'https://www.google.com',
             {'content-type': 'text/plain'})
-        with patch('google.appengine.api.urlfetch.fetch', return_value=resp) as fetchmock:
+        fetch_patch = patch(
+            'google.appengine.api.urlfetch.fetch', return_value=resp
+        )
+        with fetch_patch as fetch_mock:
             import urllib3
             pool = urllib3.HTTPSConnectionPool('www.google.com', '443')
             pool.ConnectionCls = urllib3.connection.UnverifiedHTTPSConnection
             r = pool.request('GET', '/')
             self.assertEqual(r.status, 200, r.data)
-            self.assertEqual(fetchmock.call_count, 1)
+            self.assertEqual(fetch_mock.call_count, 1)
diff --git a/test/contrib/test_socks.py b/test/contrib/test_socks.py
index da55343..d5c8274 100644
--- a/test/contrib/test_socks.py
+++ b/test/contrib/test_socks.py
@@ -255,6 +255,7 @@ class TestSocks5Proxy(IPV4SocketDummyServerTestCase):
         self._start_server(request_handler)
         proxy_url = "socks5://%s:%s" % (self.host, self.port)
         pm = socks.SOCKSProxyManager(proxy_url)
+        self.addCleanup(pm.clear)
         response = pm.request('GET', 'http://localhost')
 
         self.assertEqual(response.status, 200)
@@ -511,6 +512,7 @@ class TestSOCKS4Proxy(IPV4SocketDummyServerTestCase):
         self._start_server(request_handler)
         proxy_url = "socks4://%s:%s" % (self.host, self.port)
         pm = socks.SOCKSProxyManager(proxy_url)
+        self.addCleanup(pm.clear)
         response = pm.request('GET', 'http://localhost')
 
         self.assertEqual(response.status, 200)
@@ -664,6 +666,7 @@ class TestSOCKSWithTLS(IPV4SocketDummyServerTestCase):
                         b'Content-Length: 0\r\n'
                         b'\r\n')
             tls.close()
+            sock.close()
 
         self._start_server(request_handler)
         proxy_url = "socks5h://%s:%s" % (self.host, self.port)
diff --git a/test/test_collections.py b/test/test_collections.py
index ce9c8ae..98c202b 100644
--- a/test/test_collections.py
+++ b/test/test_collections.py
@@ -1,32 +1,30 @@
-import unittest
-
 from urllib3._collections import (
     HTTPHeaderDict,
     RecentlyUsedContainer as Container
 )
-from nose.plugins.skip import SkipTest
+import pytest
 
 from urllib3.packages import six
 xrange = six.moves.xrange
 
 
-class TestLRUContainer(unittest.TestCase):
+class TestLRUContainer(object):
     def test_maxsize(self):
         d = Container(5)
 
         for i in xrange(5):
             d[i] = str(i)
 
-        self.assertEqual(len(d), 5)
+        assert len(d) == 5
 
         for i in xrange(5):
-            self.assertEqual(d[i], str(i))
+            assert d[i] == str(i)
 
         d[i+1] = str(i+1)
 
-        self.assertEqual(len(d), 5)
-        self.assertFalse(0 in d)
-        self.assertTrue(i+1 in d)
+        assert len(d) == 5
+        assert 0 not in d
+        assert (i + 1) in d
 
     def test_expire(self):
         d = Container(5)
@@ -41,7 +39,7 @@ class TestLRUContainer(unittest.TestCase):
         d[5] = '5'
 
         # Check state
-        self.assertEqual(list(d.keys()), [2, 3, 4, 0, 5])
+        assert list(d.keys()) == [2, 3, 4, 0, 5]
 
     def test_same_key(self):
         d = Container(5)
@@ -49,8 +47,8 @@ class TestLRUContainer(unittest.TestCase):
         for i in xrange(10):
             d['foo'] = i
 
-        self.assertEqual(list(d.keys()), ['foo'])
-        self.assertEqual(len(d), 1)
+        assert list(d.keys()) == ['foo']
+        assert len(d) == 1
 
     def test_access_ordering(self):
         d = Container(5)
@@ -59,13 +57,13 @@ class TestLRUContainer(unittest.TestCase):
             d[i] = True
 
         # Keys should be ordered by access time
-        self.assertEqual(list(d.keys()), [5, 6, 7, 8, 9])
+        assert list(d.keys()) == [5, 6, 7, 8, 9]
 
         new_order = [7, 8, 6, 9, 5]
         for k in new_order:
             d[k]
 
-        self.assertEqual(list(d.keys()), new_order)
+        assert list(d.keys()) == new_order
 
     def test_delete(self):
         d = Container(5)
@@ -74,10 +72,10 @@ class TestLRUContainer(unittest.TestCase):
             d[i] = True
 
         del d[0]
-        self.assertFalse(0 in d)
+        assert 0 not in d
 
         d.pop(1)
-        self.assertFalse(1 in d)
+        assert 1 not in d
 
         d.pop(1, None)
 
@@ -88,15 +86,16 @@ class TestLRUContainer(unittest.TestCase):
             d[i] = True
 
         r = d.get(4)
-        self.assertEqual(r, True)
+        assert r is True
 
         r = d.get(5)
-        self.assertEqual(r, None)
+        assert r is None
 
         r = d.get(5, 42)
-        self.assertEqual(r, 42)
+        assert r == 42
 
-        self.assertRaises(KeyError, lambda: d[5])
+        with pytest.raises(KeyError):
+            d[5]
 
     def test_disposal(self):
         evicted_items = []
@@ -108,23 +107,24 @@ class TestLRUContainer(unittest.TestCase):
         d = Container(5, dispose_func=dispose_func)
         for i in xrange(5):
             d[i] = i
-        self.assertEqual(list(d.keys()), list(xrange(5)))
-        self.assertEqual(evicted_items, [])  # Nothing disposed
+        assert list(d.keys()) == list(xrange(5))
+        assert evicted_items == []  # Nothing disposed
 
         d[5] = 5
-        self.assertEqual(list(d.keys()), list(xrange(1, 6)))
-        self.assertEqual(evicted_items, [0])
+        assert list(d.keys()) == list(xrange(1, 6))
+        assert evicted_items == [0]
 
         del d[1]
-        self.assertEqual(evicted_items, [0, 1])
+        assert evicted_items == [0, 1]
 
         d.clear()
-        self.assertEqual(evicted_items, [0, 1, 2, 3, 4, 5])
+        assert evicted_items == [0, 1, 2, 3, 4, 5]
 
     def test_iter(self):
         d = Container()
 
-        self.assertRaises(NotImplementedError, d.__iter__)
+        with pytest.raises(NotImplementedError):
+            d.__iter__()
 
 
 class NonMappingHeaderContainer(object):
@@ -139,185 +139,193 @@ class NonMappingHeaderContainer(object):
         return self._data[key]
 
 
-class TestHTTPHeaderDict(unittest.TestCase):
-    def setUp(self):
-        self.d = HTTPHeaderDict(Cookie='foo')
-        self.d.add('cookie', 'bar')
+ at pytest.fixture()
+def d():
+    header_dict = HTTPHeaderDict(Cookie='foo')
+    header_dict.add('cookie', 'bar')
+    return header_dict
+
 
+class TestHTTPHeaderDict(object):
     def test_create_from_kwargs(self):
         h = HTTPHeaderDict(ab=1, cd=2, ef=3, gh=4)
-        self.assertEqual(len(h), 4)
-        self.assertTrue('ab' in h)
+        assert len(h) == 4
+        assert 'ab' in h
 
     def test_create_from_dict(self):
         h = HTTPHeaderDict(dict(ab=1, cd=2, ef=3, gh=4))
-        self.assertEqual(len(h), 4)
-        self.assertTrue('ab' in h)
+        assert len(h) == 4
+        assert 'ab' in h
 
     def test_create_from_iterator(self):
         teststr = 'urllib3ontherocks'
         h = HTTPHeaderDict((c, c*5) for c in teststr)
-        self.assertEqual(len(h), len(set(teststr)))
+        assert len(h) == len(set(teststr))
 
     def test_create_from_list(self):
         headers = [('ab', 'A'), ('cd', 'B'), ('cookie', 'C'), ('cookie', 'D'), ('cookie', 'E')]
         h = HTTPHeaderDict(headers)
-        self.assertEqual(len(h), 3)
-        self.assertTrue('ab' in h)
+        assert len(h) == 3
+        assert 'ab' in h
         clist = h.getlist('cookie')
-        self.assertEqual(len(clist), 3)
-        self.assertEqual(clist[0], 'C')
-        self.assertEqual(clist[-1], 'E')
+        assert len(clist) == 3
+        assert clist[0] == 'C'
+        assert clist[-1] == 'E'
 
     def test_create_from_headerdict(self):
         headers = [('ab', 'A'), ('cd', 'B'), ('cookie', 'C'), ('cookie', 'D'), ('cookie', 'E')]
         org = HTTPHeaderDict(headers)
         h = HTTPHeaderDict(org)
-        self.assertEqual(len(h), 3)
-        self.assertTrue('ab' in h)
+        assert len(h) == 3
+        assert 'ab' in h
         clist = h.getlist('cookie')
-        self.assertEqual(len(clist), 3)
-        self.assertEqual(clist[0], 'C')
-        self.assertEqual(clist[-1], 'E')
-        self.assertFalse(h is org)
-        self.assertEqual(h, org)
-
-    def test_setitem(self):
-        self.d['Cookie'] = 'foo'
-        self.assertEqual(self.d['cookie'], 'foo')
-        self.d['cookie'] = 'with, comma'
-        self.assertEqual(self.d.getlist('cookie'), ['with, comma'])
-
-    def test_update(self):
-        self.d.update(dict(Cookie='foo'))
-        self.assertEqual(self.d['cookie'], 'foo')
-        self.d.update(dict(cookie='with, comma'))
-        self.assertEqual(self.d.getlist('cookie'), ['with, comma'])
-
-    def test_delitem(self):
-        del self.d['cookie']
-        self.assertFalse('cookie' in self.d)
-        self.assertFalse('COOKIE' in self.d)
-
-    def test_add_well_known_multiheader(self):
-        self.d.add('COOKIE', 'asdf')
-        self.assertEqual(self.d.getlist('cookie'), ['foo', 'bar', 'asdf'])
-        self.assertEqual(self.d['cookie'], 'foo, bar, asdf')
-
-    def test_add_comma_separated_multiheader(self):
-        self.d.add('bar', 'foo')
-        self.d.add('BAR', 'bar')
-        self.d.add('Bar', 'asdf')
-        self.assertEqual(self.d.getlist('bar'), ['foo', 'bar', 'asdf'])
-        self.assertEqual(self.d['bar'], 'foo, bar, asdf')
-
-    def test_extend_from_list(self):
-        self.d.extend([('set-cookie', '100'), ('set-cookie', '200'), ('set-cookie', '300')])
-        self.assertEqual(self.d['set-cookie'], '100, 200, 300')
-
-    def test_extend_from_dict(self):
-        self.d.extend(dict(cookie='asdf'), b='100')
-        self.assertEqual(self.d['cookie'], 'foo, bar, asdf')
-        self.assertEqual(self.d['b'], '100')
-        self.d.add('cookie', 'with, comma')
-        self.assertEqual(self.d.getlist('cookie'), ['foo', 'bar', 'asdf', 'with, comma'])
-
-    def test_extend_from_container(self):
+        assert len(clist) == 3
+        assert clist[0] == 'C'
+        assert clist[-1] == 'E'
+        assert h is not org
+        assert h == org
+
+    def test_setitem(self, d):
+        d['Cookie'] = 'foo'
+        assert d['cookie'] == 'foo'
+        d['cookie'] = 'with, comma'
+        assert d.getlist('cookie') == ['with, comma']
+
+    def test_update(self, d):
+        d.update(dict(Cookie='foo'))
... 4114 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-urllib3.git



More information about the Python-modules-commits mailing list