|
10 | 10 | import ast
|
11 | 11 | import unittest
|
12 | 12 | import unicodedata
|
| 13 | +import urllib.error |
13 | 14 |
|
14 | 15 | from test import support
|
15 | 16 | from http.client import HTTPException
|
@@ -181,20 +182,23 @@ def check_version(testfile):
|
181 | 182 | try:
|
182 | 183 | testdata = support.open_urlresource(url, encoding="utf-8",
|
183 | 184 | check=check_version)
|
184 |
| - except (OSError, HTTPException): |
185 |
| - self.skipTest("Could not retrieve " + url) |
186 |
| - self.addCleanup(testdata.close) |
187 |
| - for line in testdata: |
188 |
| - line = line.strip() |
189 |
| - if not line or line.startswith('#'): |
190 |
| - continue |
191 |
| - seqname, codepoints = line.split(';') |
192 |
| - codepoints = ''.join(chr(int(cp, 16)) for cp in codepoints.split()) |
193 |
| - self.assertEqual(unicodedata.lookup(seqname), codepoints) |
194 |
| - with self.assertRaises(SyntaxError): |
195 |
| - self.checkletter(seqname, None) |
196 |
| - with self.assertRaises(KeyError): |
197 |
| - unicodedata.ucd_3_2_0.lookup(seqname) |
| 185 | + except urllib.error.HTTPError as exc: |
| 186 | + exc.close() |
| 187 | + self.skipTest(f"Could not retrieve {url}: {exc!r}") |
| 188 | + except (OSError, HTTPException) as exc: |
| 189 | + self.skipTest(f"Could not retrieve {url}: {exc!r}") |
| 190 | + with testdata: |
| 191 | + for line in testdata: |
| 192 | + line = line.strip() |
| 193 | + if not line or line.startswith('#'): |
| 194 | + continue |
| 195 | + seqname, codepoints = line.split(';') |
| 196 | + codepoints = ''.join(chr(int(cp, 16)) for cp in codepoints.split()) |
| 197 | + self.assertEqual(unicodedata.lookup(seqname), codepoints) |
| 198 | + with self.assertRaises(SyntaxError): |
| 199 | + self.checkletter(seqname, None) |
| 200 | + with self.assertRaises(KeyError): |
| 201 | + unicodedata.ucd_3_2_0.lookup(seqname) |
198 | 202 |
|
199 | 203 | def test_errors(self):
|
200 | 204 | self.assertRaises(TypeError, unicodedata.name)
|
|
0 commit comments