https://github.com/python/cpython/commit/7d447ac4e0d00910af72b74d6716ac3b1b3bfc0a
commit: 7d447ac4e0d00910af72b74d6716ac3b1b3bfc0a
branch: 3.12
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: vstinner <vstin...@python.org>
date: 2025-03-28T15:12:59Z
summary:

[3.12] gh-131807: fix ResourceWarning in test_ucn.py (GH-131808) (#131846)

gh-131807: fix ResourceWarning in test_ucn.py (GH-131808)
(cherry picked from commit adb67ed7e465410829ac0b1f903ec5678e0e51cc)

Co-authored-by: Thomas Grainger <tagr...@gmail.com>
Co-authored-by: Victor Stinner <vstin...@python.org>

files:
M Lib/test/test_ucn.py

diff --git a/Lib/test/test_ucn.py b/Lib/test/test_ucn.py
index cbfd5af2bb751c..0e2c25aaff2fe9 100644
--- a/Lib/test/test_ucn.py
+++ b/Lib/test/test_ucn.py
@@ -10,6 +10,7 @@
 import ast
 import unittest
 import unicodedata
+import urllib.error
 
 from test import support
 from http.client import HTTPException
@@ -181,20 +182,23 @@ def check_version(testfile):
         try:
             testdata = support.open_urlresource(url, encoding="utf-8",
                                                 check=check_version)
-        except (OSError, HTTPException):
-            self.skipTest("Could not retrieve " + url)
-        self.addCleanup(testdata.close)
-        for line in testdata:
-            line = line.strip()
-            if not line or line.startswith('#'):
-                continue
-            seqname, codepoints = line.split(';')
-            codepoints = ''.join(chr(int(cp, 16)) for cp in codepoints.split())
-            self.assertEqual(unicodedata.lookup(seqname), codepoints)
-            with self.assertRaises(SyntaxError):
-                self.checkletter(seqname, None)
-            with self.assertRaises(KeyError):
-                unicodedata.ucd_3_2_0.lookup(seqname)
+        except urllib.error.HTTPError as exc:
+            exc.close()
+            self.skipTest(f"Could not retrieve {url}: {exc!r}")
+        except (OSError, HTTPException) as exc:
+            self.skipTest(f"Could not retrieve {url}: {exc!r}")
+        with testdata:
+            for line in testdata:
+                line = line.strip()
+                if not line or line.startswith('#'):
+                    continue
+                seqname, codepoints = line.split(';')
+                codepoints = ''.join(chr(int(cp, 16)) for cp in 
codepoints.split())
+                self.assertEqual(unicodedata.lookup(seqname), codepoints)
+                with self.assertRaises(SyntaxError):
+                    self.checkletter(seqname, None)
+                with self.assertRaises(KeyError):
+                    unicodedata.ucd_3_2_0.lookup(seqname)
 
     def test_errors(self):
         self.assertRaises(TypeError, unicodedata.name)

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to