]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-99352: Ensure HTTPSConnection is available before exercising https tests. (...
authorSenthil Kumaran <senthil@python.org>
Wed, 26 Apr 2023 01:02:27 +0000 (19:02 -0600)
committerGitHub <noreply@github.com>
Wed, 26 Apr 2023 01:02:27 +0000 (18:02 -0700)
gh-99352: Ensure HTTPSConnection is available before exercising https
tests.

This will fix the buildbot issue mentioned in

https://github.com/python/cpython/pull/99353

Lib/test/test_urllib2.py

index b7c6f6dd8f1b99b38ddf250d28bdd65474615785..99c9e24994732fac0891d2120212d732b780c189 100644 (file)
@@ -524,16 +524,17 @@ class MockHTTPHandlerRedirect(urllib.request.BaseHandler):
             return MockResponse(200, "OK", msg, "", req.get_full_url())
 
 
-class MockHTTPSHandler(urllib.request.HTTPSHandler):
-    # Useful for testing the Proxy-Authorization request by verifying the
-    # properties of httpcon
+if hasattr(http.client, 'HTTPSConnection'):
+    class MockHTTPSHandler(urllib.request.HTTPSHandler):
+        # Useful for testing the Proxy-Authorization request by verifying the
+        # properties of httpcon
 
-    def __init__(self, debuglevel=None, context=None, check_hostname=None):
-        super(MockHTTPSHandler, self).__init__(debuglevel, context, check_hostname)
-        self.httpconn = MockHTTPClass()
+        def __init__(self, debuglevel=None, context=None, check_hostname=None):
+            super(MockHTTPSHandler, self).__init__(debuglevel, context, check_hostname)
+            self.httpconn = MockHTTPClass()
 
-    def https_open(self, req):
-        return self.do_open(self.httpconn, req)
+        def https_open(self, req):
+            return self.do_open(self.httpconn, req)
 
 
 class MockHTTPHandlerCheckAuth(urllib.request.BaseHandler):
@@ -1075,6 +1076,7 @@ class HandlerTests(unittest.TestCase):
         o.open("http://www.example.com")
         self.assertEqual(h._debuglevel, 5)
 
+    @unittest.skipUnless(hasattr(http.client, 'HTTPSConnection'), 'HTTPSConnection required for HTTPS tests.')
     def test_https_handler_global_debuglevel(self):
         with mock.patch.object(http.client.HTTPSConnection, 'debuglevel', 7):
             o = OpenerDirector()
@@ -1083,6 +1085,7 @@ class HandlerTests(unittest.TestCase):
             o.open("https://www.example.com")
             self.assertEqual(h._debuglevel, 7)
 
+    @unittest.skipUnless(hasattr(http.client, 'HTTPSConnection'), 'HTTPSConnection required for HTTPS tests.')
     def test_https_handler_local_debuglevel(self):
         o = OpenerDirector()
         h = MockHTTPSHandler(debuglevel=4)
@@ -1456,6 +1459,7 @@ class HandlerTests(unittest.TestCase):
         self.assertEqual([(handlers[0], "https_open")],
                          [tup[0:2] for tup in o.calls])
 
+    @unittest.skipUnless(hasattr(http.client, 'HTTPSConnection'), 'HTTPSConnection required for HTTPS tests.')
     def test_proxy_https_proxy_authorization(self):
         o = OpenerDirector()
         ph = urllib.request.ProxyHandler(dict(https='proxy.example.com:3128'))