<s> """<STR_LIT>""" <EOL> import unittest <EOL> import unicodedata <EOL> import _testcapi <EOL> from test import support <EOL> from http . client import HTTPException <EOL> from test . test_normalization import check_version <EOL> class UnicodeNamesTest ( unittest . TestCase ) : <EOL> def checkletter ( self , name , code ) : <EOL> res = eval ( r'<STR_LIT>' % name ) <EOL> self . assertEqual ( res , code ) <EOL> return res <EOL> def test_general ( self ) : <EOL> chars = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> string = "<STR_LIT>" <EOL> self . assertEqual ( <EOL> "<STR_LIT>" . join ( [ self . checkletter ( * args ) for args in zip ( chars , string ) ] ) , <EOL> string <EOL> ) <EOL> def test_ascii_letters ( self ) : <EOL> for char in "<STR_LIT>" . join ( map ( chr , range ( ord ( "<STR_LIT:a>" ) , ord ( "<STR_LIT:z>" ) ) ) ) : <EOL> name = "<STR_LIT>" % char . upper ( ) <EOL> code = unicodedata . lookup ( name ) <EOL> self . assertEqual ( unicodedata . name ( code ) , name ) <EOL> def test_hangul_syllables ( self ) : <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertRaises ( ValueError , unicodedata . name , "<STR_LIT>" ) <EOL> def test_cjk_unified_ideographs ( self ) : <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def test_bmp_characters ( self ) : <EOL> for code in range ( <NUM_LIT> ) : <EOL> char = chr ( code ) <EOL> name = unicodedata . name ( char , None ) <EOL> if name is not None : <EOL> self . assertEqual ( unicodedata . lookup ( name ) , char ) <EOL> def test_misc_symbols ( self ) : <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . checkletter ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def test_aliases ( self ) : <EOL> aliases = [ <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) <EOL> ] <EOL> for alias , codepoint in aliases : <EOL> self . checkletter ( alias , chr ( codepoint ) ) <EOL> name = unicodedata . name ( chr ( codepoint ) ) <EOL> self . assertNotEqual ( name , alias ) <EOL> self . assertEqual ( unicodedata . lookup ( alias ) , <EOL> unicodedata . lookup ( name ) ) <EOL> with self . assertRaises ( KeyError ) : <EOL> unicodedata . ucd_3_2_0 . lookup ( alias ) <EOL> def test_aliases_names_in_pua_range ( self ) : <EOL> for cp in range ( <NUM_LIT> , <NUM_LIT> ) : <EOL> with self . assertRaises ( ValueError ) as cm : <EOL> unicodedata . name ( chr ( cp ) ) <EOL> self . assertEqual ( str ( cm . exception ) , '<STR_LIT>' ) <EOL> def test_named_sequences_names_in_pua_range ( self ) : <EOL> for cp in range ( <NUM_LIT> , <NUM_LIT> ) : <EOL> with self . assertRaises ( ValueError ) as cm : <EOL> unicodedata . name ( chr ( cp ) ) <EOL> self . assertEqual ( str ( cm . exception ) , '<STR_LIT>' ) <EOL> def test_named_sequences_sample ( self ) : <EOL> sequences = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> for seqname , codepoints in sequences : <EOL> self . assertEqual ( unicodedata . lookup ( seqname ) , codepoints ) <EOL> with self . assertRaises ( SyntaxError ) : <EOL> self . checkletter ( seqname , None ) <EOL> with self . assertRaises ( KeyError ) : <EOL> unicodedata . ucd_3_2_0 . lookup ( seqname ) <EOL> def test_named_sequences_full ( self ) : <EOL> url = ( "<STR_LIT>" % <EOL> unicodedata . unidata_version ) <EOL> try : <EOL> testdata = support . open_urlresource ( url , encoding = "<STR_LIT:utf-8>" , <EOL> check = check_version ) <EOL> except ( IOError , HTTPException ) : <EOL> self . skipTest ( "<STR_LIT>" + url ) <EOL> self . addCleanup ( testdata . close ) <EOL> for line in testdata : <EOL> line = line . strip ( ) <EOL> if not line or line . startswith ( '<STR_LIT:#>' ) : <EOL> continue <EOL> seqname , codepoints = line . split ( '<STR_LIT:;>' ) <EOL> codepoints = '<STR_LIT>' . join ( chr ( int ( cp , <NUM_LIT:16> ) ) for cp in codepoints . split ( ) ) <EOL> self . assertEqual ( unicodedata . lookup ( seqname ) , codepoints ) <EOL> with self . assertRaises ( SyntaxError ) : <EOL> self . checkletter ( seqname , None ) <EOL> with self . assertRaises ( KeyError ) : <EOL> unicodedata . ucd_3_2_0 . lookup ( seqname ) <EOL> def test_errors ( self ) : <EOL> self . assertRaises ( TypeError , unicodedata . name ) <EOL> self . assertRaises ( TypeError , unicodedata . name , '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , unicodedata . lookup ) <EOL> self . assertRaises ( KeyError , unicodedata . lookup , '<STR_LIT>' ) <EOL> def test_strict_error_handling ( self ) : <EOL> self . assertRaises ( <EOL> UnicodeError , <EOL> str , b"<STR_LIT>" , '<STR_LIT>' , '<STR_LIT:strict>' <EOL> ) <EOL> self . assertRaises ( <EOL> UnicodeError , <EOL> str , bytes ( "<STR_LIT>" % ( "<STR_LIT:x>" * <NUM_LIT> ) , "<STR_LIT:ascii>" ) , '<STR_LIT>' , '<STR_LIT:strict>' <EOL> ) <EOL> self . assertRaises ( <EOL> UnicodeError , <EOL> str , b"<STR_LIT>" , '<STR_LIT>' , '<STR_LIT:strict>' <EOL> ) <EOL> self . assertRaises ( <EOL> UnicodeError , <EOL> str , b"<STR_LIT>" , '<STR_LIT>' , '<STR_LIT:strict>' <EOL> ) <EOL> @ unittest . skipUnless ( _testcapi . INT_MAX < _testcapi . PY_SSIZE_T_MAX , <EOL> "<STR_LIT>" ) <EOL> @ support . bigmemtest ( size = _testcapi . UINT_MAX + <NUM_LIT:1> , <EOL> memuse = <NUM_LIT:2> + <NUM_LIT:1> , dry_run = False ) <EOL> def test_issue16335 ( self , size ) : <EOL> x = b'<STR_LIT>' + b'<STR_LIT:x>' * ( _testcapi . UINT_MAX + <NUM_LIT:1> ) + b'<STR_LIT:}>' <EOL> self . assertEqual ( len ( x ) , len ( b'<STR_LIT>' ) + <EOL> ( _testcapi . UINT_MAX + <NUM_LIT:1> ) ) <EOL> self . assertRaisesRegex ( UnicodeError , <EOL> '<STR_LIT>' , <EOL> x . decode , '<STR_LIT>' <EOL> ) <EOL> def test_main ( ) : <EOL> support . run_unittest ( UnicodeNamesTest ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
