Skip to content

Commit

Permalink
fix env in test_urllib
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Jan 11, 2025
1 parent f0490ab commit be71a81
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions Lib/test/test_urllib.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,11 @@ def test_read_bogus(self):
Content-Type: text/html; charset=iso-8859-1
''', mock_close=True)
try:
self.assertRaises(OSError, urllib.request.urlopen, "http://python.org/")
with self.assertRaises(OSError) as exc_info:
with urllib.request.urlopen("http://python.org/"):
pass
with exc_info.exception:
pass
finally:
self.unfakehttp()

Expand All @@ -434,8 +438,11 @@ def test_invalid_redirect(self):
''', mock_close=True)
try:
msg = "Redirection to url 'file:"
with self.assertRaisesRegex(urllib.error.HTTPError, msg):
urllib.request.urlopen("http://python.org/")
with self.assertRaisesRegex(urllib.error.HTTPError, msg) as exc_info:
with urllib.request.urlopen("http://python.org/"):
pass
with exc_info.exception:
pass
finally:
self.unfakehttp()

Expand All @@ -448,8 +455,11 @@ def test_redirect_limit_independent(self):
Connection: close
''', mock_close=True)
try:
self.assertRaises(urllib.error.HTTPError, urllib.request.urlopen,
"http://something")
with self.assertRaises(urllib.error.HTTPError) as exc_info:
with urllib.request.urlopen("http://something"):
pass
with exc_info.exception:
pass
finally:
self.unfakehttp()

Expand Down Expand Up @@ -529,10 +539,10 @@ def setUp(self):
"QOjdAAAAAXNSR0IArs4c6QAAAA9JREFUCNdj%0AYGBg%2BP//PwAGAQL%2BCm8 "
"vHgAAAABJRU5ErkJggg%3D%3D%0A%20")

self.text_url_resp = urllib.request.urlopen(self.text_url)
self.text_url_base64_resp = urllib.request.urlopen(
self.text_url_base64)
self.image_url_resp = urllib.request.urlopen(self.image_url)
self.text_url_resp = self.enterContext(urllib.request.urlopen(self.text_url))
self.text_url_base64_resp = self.enterContext(urllib.request.urlopen(
self.text_url_base64))
self.image_url_resp = self.enterContext(urllib.request.urlopen(self.image_url))

def test_interface(self):
# Make sure object returned by urlopen() has the specified methods
Expand Down

0 comments on commit be71a81

Please sign in to comment.