@@ -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
@@ -956,11 +976,6 @@ def test_segment_object(self):
956976
957977
958978class NormalizationTest (unittest .TestCase ):
959- @staticmethod
960- def check_version (testfile ):
961- hdr = testfile .readline ()
962- return unicodedata .unidata_version in hdr
963-
964979 @staticmethod
965980 def unistr (data ):
966981 data = [int (x , 16 ) for x in data .split (" " )]
@@ -970,17 +985,7 @@ def unistr(data):
970985 @requires_resource ('cpu' )
971986 def test_normalization (self ):
972987 TESTDATAFILE = "NormalizationTest.txt"
973- TESTDATAURL = f"http://www.pythontest.net/unicode/{ unicodedata .unidata_version } /{ TESTDATAFILE } "
974-
975- # Hit the exception early
976- try :
977- testdata = open_urlresource (TESTDATAURL , encoding = "utf-8" ,
978- check = self .check_version )
979- except PermissionError :
980- self .skipTest (f"Permission error when downloading { TESTDATAURL } "
981- f"into the test data directory" )
982- except (OSError , HTTPException ) as exc :
983- self .skipTest (f"Failed to download { TESTDATAURL } : { exc } " )
988+ testdata = download_test_data_file (TESTDATAFILE )
984989
985990 with testdata :
986991 self .run_normalization_tests (testdata , unicodedata )
@@ -1077,25 +1082,10 @@ class MyStr(str):
10771082
10781083
10791084class GraphemeBreakTest (unittest .TestCase ):
1080- @staticmethod
1081- def check_version (testfile ):
1082- hdr = testfile .readline ()
1083- return unicodedata .unidata_version in hdr
1084-
10851085 @requires_resource ('network' )
10861086 def test_grapheme_break (self ):
1087- TESTDATAFILE = "auxiliary/GraphemeBreakTest.txt"
1088- TESTDATAURL = f"https://www.unicode.org/Public/{ unicodedata .unidata_version } /ucd/{ TESTDATAFILE } "
1089-
1090- # Hit the exception early
1091- try :
1092- testdata = open_urlresource (TESTDATAURL , encoding = "utf-8" ,
1093- check = self .check_version )
1094- except PermissionError :
1095- self .skipTest (f"Permission error when downloading { TESTDATAURL } "
1096- f"into the test data directory" )
1097- except (OSError , HTTPException ) as exc :
1098- self .skipTest (f"Failed to download { TESTDATAURL } : { exc } " )
1087+ TESTDATAFILE = "GraphemeBreakTest.txt"
1088+ testdata = download_test_data_file (TESTDATAFILE )
10991089
11001090 with testdata :
11011091 self .run_grapheme_break_tests (testdata )
0 commit comments