mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
[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 adb67ed7e4)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
d4ddc03e56
commit
7d447ac4e0
1 changed files with 18 additions and 14 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue