@@ -98,13 +98,58 @@ def test_function_checksum(self):
9898 result = h .hexdigest ()
9999 self .assertEqual (result , self .expectedchecksum )
100100
101+ @requires_resource ('network' )
102+ def test_name (self ):
103+ TESTBASEURL = "https://www.unicode.org/Public"
104+ TESTDATAFILE = "extracted/DerivedName.txt"
105+ TESTDATAURL = f"{ TESTBASEURL } /{ unicodedata .unidata_version } /ucd/{ TESTDATAFILE } "
106+
107+ # Hit the exception early
108+ try :
109+ testdata = open_urlresource (TESTDATAURL , encoding = "utf-8" )
110+ except PermissionError :
111+ self .skipTest (f"Permission error when downloading { TESTDATAURL } "
112+ f"into the test data directory" )
113+ except (OSError , HTTPException ) as exc :
114+ self .skipTest (f"Failed to download { TESTDATAURL } : { exc } " )
115+
116+ with testdata :
117+ self .run_name_tests (testdata )
118+
119+ def run_name_tests (self , testdata ):
120+ names_ref = {}
121+
122+ def parse_cp (s ):
123+ return int (s , 16 )
124+
125+ # Parse data
126+ for line in testdata :
127+ line = line .strip ()
128+ if not line or line .startswith ("#" ):
129+ continue
130+ raw_cp , name = line .split ("; " )
131+ # Check for a range
132+ if ".." in raw_cp :
133+ cp1 , cp2 = map (parse_cp , raw_cp .split (".." ))
134+ # remove ‘*’ at the end
135+ name = name [:- 1 ]
136+ for cp in range (cp1 , cp2 + 1 ):
137+ names_ref [cp ] = f"{ name } { cp :0>4X} "
138+ else :
139+ cp = parse_cp (raw_cp )
140+ names_ref [cp ] = name
141+
142+ for cp in range (0 , 0x10ffff + 1 ):
143+ self .assertEqual (self .db .name (chr (cp ), None ), names_ref .get (cp ))
144+
101145 @requires_resource ('cpu' )
102146 def test_name_inverse_lookup (self ):
103147 for i in range (sys .maxunicode + 1 ):
104148 char = chr (i )
105149 if looked_name := self .db .name (char , None ):
106150 self .assertEqual (self .db .lookup (looked_name ), char )
107151
152+
108153 def test_digit (self ):
109154 self .assertEqual (self .db .digit ('A' , None ), None )
110155 self .assertEqual (self .db .digit ('9' ), 9 )
0 commit comments