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