B
    u9ah%  ã               @   s”   d dl Z d dlZd dlmZ d dlmZ d dlmZ yd dlm	Z	m
Z
mZ W n  ek
rl   d Z	 Z
ZY nX G dd„ de jƒZed	kre  ¡  dS )
é    N)Úsupport)ÚHTTPException)Úcheck_version)ÚINT_MAXÚPY_SSIZE_T_MAXÚUINT_MAXl   ÿÿÿÿ c               @   s®   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zeje eek d¡ejed dd d!d"d#„ ƒƒƒZd$S )%ÚUnicodeNamesTestc             C   s   t d| ƒ}|  ||¡ |S )Nz"\N{%s}")ÚevalÚassertEqual)ÚselfÚnameÚcodeZres© r   ú/usr/lib/python3.7/test_ucn.pyÚcheckletter   s    zUnicodeNamesTest.checkletterc                sf   dddddddddd	d
dddddddddddddddg}d}ˆ   d ‡ fdd„t||ƒD ƒ¡|¡ d S )NzLATIN CAPITAL LETTER TzLATIN SMALL LETTER HzLATIN SMALL LETTER EZSPACEzLATIN SMALL LETTER RzLATIN CAPITAL LETTER EzLATIN SMALL LETTER DzLATIN SMALL LETTER fzLATIN CAPITAL LeTtEr ozLATIN SMaLl LETTER xzLATIN SMALL LETTER AzLATIN SMALL LETTER TZSpAcEzLATIN SMALL LETTER SzLATIN small LETTER ezLATIN SMALL LETTER Pz	FULL STOPzThe rEd fOx ate the sheep.Ú c                s   g | ]}ˆ j |Ž ‘qS r   )r   )Ú.0Úargs)r   r   r   ú
<listcomp>A   s    z1UnicodeNamesTest.test_general.<locals>.<listcomp>)r
   ÚjoinÚzip)r   ÚcharsÚstringr   )r   r   Útest_general    s<    zUnicodeNamesTest.test_generalc             C   sT   xNd  ttttdƒtdƒƒƒ¡D ],}d| ¡  }t |¡}|  t 	|¡|¡ q W d S )Nr   ÚaÚzzLATIN SMALL LETTER %s)
r   ÚmapÚchrÚrangeÚordÚupperÚunicodedataÚlookupr
   r   )r   Úcharr   r   r   r   r   Útest_ascii_lettersE   s    $
z#UnicodeNamesTest.test_ascii_lettersc             C   s°   |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   d	d
¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |  ttjd¡ d S )NzHANGUL SYLLABLE GAu   ê°€zHANGUL SYLLABLE GGWEOSSu   ê¿¨zHANGUL SYLLABLE DOLSu   ëzHANGUL SYLLABLE RYANu   ëž¸zHANGUL SYLLABLE MWIKu   ë® zHANGUL SYLLABLE BBWAEMu   ë¾ˆzHANGUL SYLLABLE SSEOLu   ì°zHANGUL SYLLABLE YIu   ì˜zHANGUL SYLLABLE JJYOSSu   ì­€zHANGUL SYLLABLE KYEOLSu   ì¼¨zHANGUL SYLLABLE PANu   íŒzHANGUL SYLLABLE HWEOKu   í›¸zHANGUL SYLLABLE HIHu   íž£u   íž¤)r   ÚassertRaisesÚ
ValueErrorr!   r   )r   r   r   r   Útest_hangul_syllablesK   s    z&UnicodeNamesTest.test_hangul_syllablesc             C   s|   |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   d	d
¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd¡ d S )NzCJK UNIFIED IDEOGRAPH-3400u   ã€zCJK UNIFIED IDEOGRAPH-4DB5u   ä¶µzCJK UNIFIED IDEOGRAPH-4E00u   ä¸€zCJK UNIFIED IDEOGRAPH-9FCBu   é¿‹zCJK UNIFIED IDEOGRAPH-20000u   ð €€zCJK UNIFIED IDEOGRAPH-2A6D6u   ðª›–zCJK UNIFIED IDEOGRAPH-2A700u   ðªœ€zCJK UNIFIED IDEOGRAPH-2B734u   ð«œ´zCJK UNIFIED IDEOGRAPH-2B740u   ð«€zCJK UNIFIED IDEOGRAPH-2B81Du   ð« )r   )r   r   r   r   Útest_cjk_unified_ideographs\   s    z,UnicodeNamesTest.test_cjk_unified_ideographsc             C   sD   x>t dƒD ]2}t|ƒ}t |d ¡}|d k	r
|  t |¡|¡ q
W d S )Ni   )r   r   r!   r   r
   r"   )r   r   r#   r   r   r   r   Útest_bmp_charactersh   s
    z$UnicodeNamesTest.test_bmp_charactersc             C   s4   |   dd¡ |   dd¡ |   dd¡ |   dd¡ d S )	NzPILCROW SIGNõ   Â¶zREPLACEMENT CHARACTERu   ï¿½z)HALFWIDTH KATAKANA SEMI-VOICED SOUND MARKu   ï¾ŸzFULLWIDTH LATIN SMALL LETTER Au   ï½)r   )r   r   r   r   Útest_misc_symbolso   s    z"UnicodeNamesTest.test_misc_symbolsc             C   s”   ddddddddd	d
dg}xt|D ]l\}}|   |t|ƒ¡ t t|ƒ¡}|  ||¡ |  t |¡t |¡¡ |  t¡ tj	 |¡ W d Q R X q W d S )N)zLATIN CAPITAL LETTER GHAi¢  )zLATIN SMALL LETTER GHAi£  )zKANNADA LETTER LLLAiÞ  )zLAO LETTER FO FONi  )zLAO LETTER FO FAYiŸ  )zLAO LETTER ROi£  )zLAO LETTER LOi¥  )z#TIBETAN MARK BKA- SHOG GI MGO RGYANiÐ  )zYI SYLLABLE ITERATION MARKi   )z=PRESENTATION FORM FOR VERTICAL RIGHT WHITE LENTICULAR BRACKETiþ  )z4BYZANTINE MUSICAL SYMBOL FTHORA SKLIRON CHROMA VASISiÅÐ )
r   r   r!   r   ZassertNotEqualr
   r"   r%   ÚKeyErrorÚ	ucd_3_2_0)r   ÚaliasesÚaliasZ	codepointr   r   r   r   Útest_aliasesu   s&    zUnicodeNamesTest.test_aliasesc          
   C   sN   xHt ddƒD ]:}|  t¡}t t|ƒ¡ W d Q R X |  t|jƒd¡ qW d S )Ni   i  zno such name)	r   r%   r&   r!   r   r   r
   ÚstrÚ	exception)r   ÚcpÚcmr   r   r   Útest_aliases_names_in_pua_range   s    z0UnicodeNamesTest.test_aliases_names_in_pua_rangec          
   C   sN   xHt ddƒD ]:}|  t¡}t t|ƒ¡ W d Q R X |  t|jƒd¡ qW d S )Ni  iÿ zno such name)	r   r%   r&   r!   r   r   r
   r1   r2   )r   r3   r4   r   r   r   Ú'test_named_sequences_names_in_pua_range–   s    z8UnicodeNamesTest.test_named_sequences_names_in_pua_rangec          
   C   sz   dddddg}xf|D ]^\}}|   t |¡|¡ |  t¡ |  |d ¡ W d Q R X |  t¡ tj |¡ W d Q R X qW d S )N)zLATIN SMALL LETTER R WITH TILDEu   rÌƒ)zTAMIL SYLLABLE SAIu   à®¸à¯ˆ)zTAMIL SYLLABLE MOOu   à®®à¯‹)zTAMIL SYLLABLE NNOOu   à®£à¯‹)zTAMIL CONSONANT KSSu   à®•à¯à®·à¯)r
   r!   r"   r%   ÚSyntaxErrorr   r,   r-   )r   Ú	sequencesÚseqnameÚ
codepointsr   r   r   Útest_named_sequences_sample   s    z,UnicodeNamesTest.test_named_sequences_samplec          
   C   sø   dt j }ytj|dtd}W n& ttfk
rD   |  d| ¡ Y nX |  |j	¡ x |D ]˜}| 
¡ }|rX| d¡rtqX| d¡\}}d dd	„ | ¡ D ƒ¡}|  t  |¡|¡ |  t¡ |  |d ¡ W d Q R X |  t¡ t j |¡ W d Q R X qXW d S )
Nz7http://www.pythontest.net/unicode/%s/NamedSequences.txtzutf-8)ÚencodingZcheckzCould not retrieve ú#ú;r   c             s   s   | ]}t t|d ƒƒV  qdS )é   N)r   Úint)r   r3   r   r   r   ú	<genexpr>¼   s    z=UnicodeNamesTest.test_named_sequences_full.<locals>.<genexpr>)r!   Úunidata_versionr   Zopen_urlresourcer   ÚOSErrorr   ZskipTestZ
addCleanupÚcloseÚstripÚ
startswithÚsplitr   r
   r"   r%   r7   r   r,   r-   )r   ZurlZtestdataÚliner9   r:   r   r   r   Útest_named_sequences_full­   s&    
z*UnicodeNamesTest.test_named_sequences_fullc             C   s@   |   ttj¡ |   ttjd¡ |   ttj¡ |   ttjd¡ d S )NZxxÚunknown)r%   Ú	TypeErrorr!   r   r"   r,   )r   r   r   r   Útest_errorsÃ   s    zUnicodeNamesTest.test_errorsc             C   sZ   |   ttddd¡ |   tttddd  dƒdd¡ |   ttddd¡ |   ttd	dd¡ d S )
Ns   \N{blah}zunicode-escapeÚstrictz\N{%s}Úxi † Úasciis   \N{SPACEs   \NSPACE)r%   ÚUnicodeErrorr1   Úbytes)r   r   r   r   Útest_strict_error_handlingÉ   s    z+UnicodeNamesTest.test_strict_error_handlingzneeds UINT_MAX < SIZE_MAXé   é   F)ÚsizeZmemuseZdry_runc             C   sF   ddt d   d }|  t|ƒtdƒt d  ¡ |  td|jd¡ d S )Ns   \N{SPACEó   xrS   ó   }s	   \N{SPACE}zunknown Unicode character namezunicode-escape)r   r
   ÚlenZassertRaisesRegexrP   Údecode)r   rU   rN   r   r   r   Útest_issue16335ß   s
    z UnicodeNamesTest.test_issue16335N)Ú__name__Ú
__module__Ú__qualname__r   r   r$   r'   r(   r)   r+   r0   r5   r6   r;   rI   rL   rR   r   Zcpython_onlyÚunittestZ
skipUnlessr   r   Z
bigmemtestr   rZ   r   r   r   r   r      s"   %r   Ú__main__)r^   r!   Ztestr   Zhttp.clientr   Ztest.test_normalizationr   Z	_testcapir   r   r   ÚImportErrorZTestCaser   r[   Úmainr   r   r   r   Ú<module>
   s    W