Skip to content

gh-99352: Ensure HTTPSConnection is available before exercising https tests. #103828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions Lib/test/test_urllib2.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,16 +524,17 @@ def http_open(self, req):
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):
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -1456,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'))
Expand Down