@@ -30,6 +30,26 @@ def iterallchars():
3030 maxunicode = 0xffff if quicktest else sys .maxunicode
3131 return map (chr , range (maxunicode + 1 ))
3232
33+
34+ def check_version (testfile ):
35+ hdr = testfile .readline ()
36+ return unicodedata .unidata_version in hdr
37+
38+
39+ def download_test_data_file (filename ):
40+ TESTDATAURL = f"http://www.pythontest.net/unicode/{ unicodedata .unidata_version } /{ filename } "
41+
42+ try :
43+ return open_urlresource (TESTDATAURL , encoding = "utf-8" , check = check_version )
44+ except PermissionError :
45+ raise unittest .SkipTest (
46+ f"Permission error when downloading { TESTDATAURL } "
47+ f"into the test data directory"
48+ )
49+ except (OSError , HTTPException ) as exc :
50+ raise unittest .SkipTest (f"Failed to download { TESTDATAURL } : { exc } " )
51+
52+
3353class UnicodeMethodsTest (unittest .TestCase ):
3454
3555 # update this, if the database changes
@@ -979,11 +999,6 @@ def test_segment_object(self):
979999
9801000
9811001class NormalizationTest (unittest .TestCase ):
982- @staticmethod
983- def check_version (testfile ):
984- hdr = testfile .readline ()
985- return unicodedata .unidata_version in hdr
986-
9871002 @staticmethod
9881003 def unistr (data ):
9891004 data = [int (x , 16 ) for x in data .split (" " )]
@@ -993,17 +1008,7 @@ def unistr(data):
9931008 @requires_resource ('cpu' )
9941009 def test_normalization (self ):
9951010 TESTDATAFILE = "NormalizationTest.txt"
996- TESTDATAURL = f"http://www.pythontest.net/unicode/{ unicodedata .unidata_version } /{ TESTDATAFILE } "
997-
998- # Hit the exception early
999- try :
1000- testdata = open_urlresource (TESTDATAURL , encoding = "utf-8" ,
1001- check = self .check_version )
1002- except PermissionError :
1003- self .skipTest (f"Permission error when downloading { TESTDATAURL } "
1004- f"into the test data directory" )
1005- except (OSError , HTTPException ) as exc :
1006- self .skipTest (f"Failed to download { TESTDATAURL } : { exc } " )
1011+ testdata = download_test_data_file (TESTDATAFILE )
10071012
10081013 with testdata :
10091014 self .run_normalization_tests (testdata , unicodedata )
@@ -1100,25 +1105,10 @@ class MyStr(str):
11001105
11011106
11021107class GraphemeBreakTest (unittest .TestCase ):
1103- @staticmethod
1104- def check_version (testfile ):
1105- hdr = testfile .readline ()
1106- return unicodedata .unidata_version in hdr
1107-
11081108 @requires_resource ('network' )
11091109 def test_grapheme_break (self ):
1110- TESTDATAFILE = "auxiliary/GraphemeBreakTest.txt"
1111- TESTDATAURL = f"https://www.unicode.org/Public/{ unicodedata .unidata_version } /ucd/{ TESTDATAFILE } "
1112-
1113- # Hit the exception early
1114- try :
1115- testdata = open_urlresource (TESTDATAURL , encoding = "utf-8" ,
1116- check = self .check_version )
1117- except PermissionError :
1118- self .skipTest (f"Permission error when downloading { TESTDATAURL } "
1119- f"into the test data directory" )
1120- except (OSError , HTTPException ) as exc :
1121- self .skipTest (f"Failed to download { TESTDATAURL } : { exc } " )
1110+ TESTDATAFILE = "GraphemeBreakTest.txt"
1111+ testdata = download_test_data_file (TESTDATAFILE )
11221112
11231113 with testdata :
11241114 self .run_grapheme_break_tests (testdata )
0 commit comments