mirror of
https://github.com/python/cpython.git
synced 2026-05-09 20:10:56 +00:00
gh-74902: Avoid hitting unicode.org for test data (GH-144195)
Use our own pythontest.net instead.
This commit is contained in:
parent
a4665b5067
commit
9efe82503d
1 changed files with 23 additions and 33 deletions
|
|
@ -30,6 +30,26 @@ def iterallchars():
|
|||
maxunicode = 0xffff if quicktest else sys.maxunicode
|
||||
return map(chr, range(maxunicode + 1))
|
||||
|
||||
|
||||
def check_version(testfile):
|
||||
hdr = testfile.readline()
|
||||
return unicodedata.unidata_version in hdr
|
||||
|
||||
|
||||
def download_test_data_file(filename):
|
||||
TESTDATAURL = f"http://www.pythontest.net/unicode/{unicodedata.unidata_version}/{filename}"
|
||||
|
||||
try:
|
||||
return open_urlresource(TESTDATAURL, encoding="utf-8", check=check_version)
|
||||
except PermissionError:
|
||||
raise unittest.SkipTest(
|
||||
f"Permission error when downloading {TESTDATAURL} "
|
||||
f"into the test data directory"
|
||||
)
|
||||
except (OSError, HTTPException) as exc:
|
||||
raise unittest.SkipTest(f"Failed to download {TESTDATAURL}: {exc}")
|
||||
|
||||
|
||||
class UnicodeMethodsTest(unittest.TestCase):
|
||||
|
||||
# update this, if the database changes
|
||||
|
|
@ -979,11 +999,6 @@ def test_segment_object(self):
|
|||
|
||||
|
||||
class NormalizationTest(unittest.TestCase):
|
||||
@staticmethod
|
||||
def check_version(testfile):
|
||||
hdr = testfile.readline()
|
||||
return unicodedata.unidata_version in hdr
|
||||
|
||||
@staticmethod
|
||||
def unistr(data):
|
||||
data = [int(x, 16) for x in data.split(" ")]
|
||||
|
|
@ -993,17 +1008,7 @@ def unistr(data):
|
|||
@requires_resource('cpu')
|
||||
def test_normalization(self):
|
||||
TESTDATAFILE = "NormalizationTest.txt"
|
||||
TESTDATAURL = f"http://www.pythontest.net/unicode/{unicodedata.unidata_version}/{TESTDATAFILE}"
|
||||
|
||||
# Hit the exception early
|
||||
try:
|
||||
testdata = open_urlresource(TESTDATAURL, encoding="utf-8",
|
||||
check=self.check_version)
|
||||
except PermissionError:
|
||||
self.skipTest(f"Permission error when downloading {TESTDATAURL} "
|
||||
f"into the test data directory")
|
||||
except (OSError, HTTPException) as exc:
|
||||
self.skipTest(f"Failed to download {TESTDATAURL}: {exc}")
|
||||
testdata = download_test_data_file(TESTDATAFILE)
|
||||
|
||||
with testdata:
|
||||
self.run_normalization_tests(testdata, unicodedata)
|
||||
|
|
@ -1100,25 +1105,10 @@ class MyStr(str):
|
|||
|
||||
|
||||
class GraphemeBreakTest(unittest.TestCase):
|
||||
@staticmethod
|
||||
def check_version(testfile):
|
||||
hdr = testfile.readline()
|
||||
return unicodedata.unidata_version in hdr
|
||||
|
||||
@requires_resource('network')
|
||||
def test_grapheme_break(self):
|
||||
TESTDATAFILE = "auxiliary/GraphemeBreakTest.txt"
|
||||
TESTDATAURL = f"https://www.unicode.org/Public/{unicodedata.unidata_version}/ucd/{TESTDATAFILE}"
|
||||
|
||||
# Hit the exception early
|
||||
try:
|
||||
testdata = open_urlresource(TESTDATAURL, encoding="utf-8",
|
||||
check=self.check_version)
|
||||
except PermissionError:
|
||||
self.skipTest(f"Permission error when downloading {TESTDATAURL} "
|
||||
f"into the test data directory")
|
||||
except (OSError, HTTPException) as exc:
|
||||
self.skipTest(f"Failed to download {TESTDATAURL}: {exc}")
|
||||
TESTDATAFILE = "GraphemeBreakTest.txt"
|
||||
testdata = download_test_data_file(TESTDATAFILE)
|
||||
|
||||
with testdata:
|
||||
self.run_grapheme_break_tests(testdata)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue