https://github.com/python/cpython/commit/624ef6f7349c3116cd6be18998ccd97b4778867d
commit: 624ef6f7349c3116cd6be18998ccd97b4778867d
branch: 3.13
author: Daehee Kim <[email protected]>
committer: hugovk <[email protected]>
date: 2026-08-17T09:55:18+03:00
summary:

[3.13] urllib: Add tests for HTTP errors to complete coverage (GH-154102) 
(#155921)

Co-authored-by: Ajob Kustra <[email protected]>

files:
M Lib/test/test_urllib.py

diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index bfcabeeae5c05e..c6a3157698d3ad 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -514,6 +514,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)
@@ -566,6 +585,11 @@ def test_ftp_cache_pruning(self):
         finally:
             self.unfakeftp()
 
+    def test_url_error_stringified(self):
+        reason = 'sixseven'
+        err = urllib.error.URLError(reason)
+        self.assertEqual(str(err), f'<urlopen error {reason}>')
+
     def test_userpass_inurl(self):
         self.fakehttp(b"HTTP/1.0 200 OK\r\n\r\nHello!")
         try:

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to