Skip to content

Commit 624ef6f

Browse files
zsaladinAjobK
andauthored
[3.13] urllib: Add tests for HTTP errors to complete coverage (GH-154102) (#155921)
Co-authored-by: Ajob Kustra <ajob.edward.kustra@cern.ch>
1 parent 6d13dc5 commit 624ef6f

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Lib/test/test_urllib.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,25 @@ def test_redirect_limit_independent(self):
514514
finally:
515515
self.unfakehttp()
516516

517+
def test_http_error_attribute_values(self):
518+
hdrs = {
519+
"Authorization": "Bearer foobar",
520+
"Accept": "application/json"
521+
}
522+
err = urllib.error.HTTPError("http://something", 404, "foo", hdrs, None)
523+
self.assertEqual(err.filename, "http://something")
524+
self.assertEqual(err.code, 404)
525+
self.assertEqual(err.msg, "foo")
526+
self.assertEqual(err.reason, "foo")
527+
self.assertEqual(err.hdrs, hdrs)
528+
self.assertEqual(err.headers, hdrs)
529+
err.close()
530+
531+
def test_http_error_default_fp(self):
532+
err = urllib.error.HTTPError("http://something", 404, "foo", {}, None)
533+
self.assertIsInstance(err.fp, io.BytesIO)
534+
err.close()
535+
517536
def test_empty_socket(self):
518537
# urlopen() raises OSError if the underlying socket does not send any
519538
# data. (#1680230)
@@ -566,6 +585,11 @@ def test_ftp_cache_pruning(self):
566585
finally:
567586
self.unfakeftp()
568587

588+
def test_url_error_stringified(self):
589+
reason = 'sixseven'
590+
err = urllib.error.URLError(reason)
591+
self.assertEqual(str(err), f'<urlopen error {reason}>')
592+
569593
def test_userpass_inurl(self):
570594
self.fakehttp(b"HTTP/1.0 200 OK\r\n\r\nHello!")
571595
try:

0 commit comments

Comments
 (0)