Skip to content
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
24 changes: 24 additions & 0 deletions Lib/test/test_urllib.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,25 @@ def test_redirect_limit_independent(self):
finally:
self.unfakehttp()

def test_http_error_attribute_values(self):
hdrs = {
"Authorization": "Bearer foobar",
"Accept": "application/json"
}
err = urllib.error.HTTPError("http://something", 404, "foo", hdrs, None)
self.assertEqual(err.filename, "http://something")
self.assertEqual(err.code, 404)
self.assertEqual(err.msg, "foo")
self.assertEqual(err.reason, "foo")
self.assertEqual(err.hdrs, hdrs)
self.assertEqual(err.headers, hdrs)
err.close()

def test_http_error_default_fp(self):
err = urllib.error.HTTPError("http://something", 404, "foo", {}, None)
self.assertIsInstance(err.fp, io.BytesIO)
err.close()

def test_empty_socket(self):
# urlopen() raises OSError if the underlying socket does not send any
# data. (#1680230)
Expand Down Expand Up @@ -513,6 +532,11 @@ def test_ftp_nonexisting(self):
self.assertFalse(e.exception.filename)
self.assertTrue(e.exception.reason)

def test_url_error_stringified(self):
reason = 'sixseven'
err = urllib.error.URLError(reason)
self.assertEqual(str(err), f'<urlopen error {reason}>')


class urlopen_DataTests(unittest.TestCase):
"""Test urlopen() opening a data URL."""
Expand Down
Loading