From 6c0d651721fabc9ac34a35b2c3a33ae27d84adf5 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Mon, 24 Apr 2023 22:25:01 -0700 Subject: [PATCH 1/3] Ensure HTTPSConnection is available before exercising https tests. --- Lib/test/test_urllib2.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index b7c6f6dd8f1b99..0f684a3257ebb9 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -524,6 +524,7 @@ def http_open(self, req): return MockResponse(200, "OK", msg, "", req.get_full_url()) +@unittest.skipUnless(hasattr(http.client, 'HTTPSConnection'), 'HTTPSConnection required for HTTPS tests.') class MockHTTPSHandler(urllib.request.HTTPSHandler): # Useful for testing the Proxy-Authorization request by verifying the # properties of httpcon @@ -1075,6 +1076,7 @@ def test_http_handler_local_debuglevel(self): 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 @@ def test_https_handler_global_debuglevel(self): 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) From b2f2437cafd8d9515584f3a352326e247a1d8b1f Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Tue, 25 Apr 2023 05:21:10 -0700 Subject: [PATCH 2/3] Check for HTTPSConnection. --- Lib/test/test_urllib2.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 0f684a3257ebb9..389ddf5a918623 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -524,17 +524,17 @@ def http_open(self, req): return MockResponse(200, "OK", msg, "", req.get_full_url()) -@unittest.skipUnless(hasattr(http.client, 'HTTPSConnection'), 'HTTPSConnection required for HTTPS tests.') -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): From abddef6ca5682a9adc2b5a00883d72dc4a6e09c8 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Tue, 25 Apr 2023 06:45:38 -0700 Subject: [PATCH 3/3] Another test requiring HTTPS. --- Lib/test/test_urllib2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 389ddf5a918623..99c9e24994732f 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1459,6 +1459,7 @@ def test_proxy_https(self): 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'))