FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-74902: Avoid hitting unicode.org for test data by zware · Pull Request #144195 · python/cpython · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
56 changes: 23 additions & 33 deletions Lib/test/test_unicodedata.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -956,11 +976,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(" ")]
Expand All @@ -970,17 +985,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)
Expand Down Expand Up @@ -1077,25 +1082,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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

So, it is not in auxiliary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It is not; since we only have three files in there (up from two before adding this one), the extra directory seemed unnecessary. Easy enough to add back if you want it, though.

testdata = download_test_data_file(TESTDATAFILE)

with testdata:
self.run_grapheme_break_tests(testdata)
Expand Down
Loading

Back | FazBrowse Home | New Git URL