a
    äze‰>  ã                   @   sª   d dl Z d dlmZ d dlZd dlZd dlZd dlmZmZm	Z	 G dd„ dej
ƒZG dd„ dej
ƒZG dd	„ d	eƒZG d
d„ deƒZG dd„ dej
ƒZedkr¦e ¡  dS )é    N)ÚHTTPException)Úopen_urlresourceÚrequires_resourceÚscript_helperc                   @   s    e Zd ZdZedƒdd„ ƒZdS )ÚUnicodeMethodsTestZ(fbdf8106a3c7c242086b0a9efa03ad4d30d5b85dÚcpuc                 C   sn  t  ¡ }ttjd ƒD ]:}t|ƒ}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|d  ¡  | ¡ | ¡ | ¡ |d  ¡ |d  ¡ |d  ¡ |d  ¡ g}| d |¡ dd	¡¡ q| ¡ }|  || j¡ d S )
Né   Z01ÚabcZ123z 	ÚABCÚ úutf-8Úsurrogatepass)ÚhashlibÚsha1ÚrangeÚsysÚ
maxunicodeÚchrÚisalnumÚisalphaÚ	isdecimalÚisdigitÚislowerÚ	isnumericÚisspaceÚistitleÚisupperÚlowerÚupperÚtitleÚupdateÚjoinÚencodeÚ	hexdigestÚassertEqualÚexpectedchecksum)ÚselfÚhÚiÚcharÚdataÚresult© r,   ú+/usr/lib/python3.9/test/test_unicodedata.pyÚtest_method_checksum   s@    












à#z'UnicodeMethodsTest.test_method_checksumN)Ú__name__Ú
__module__Ú__qualname__r%   r   r.   r,   r,   r,   r-   r      s   r   c                   @   s   e Zd ZeZdS )ÚUnicodeDatabaseTestN)r/   r0   r1   ÚunicodedataÚdbr,   r,   r,   r-   r2   B   s   r2   c                   @   sˆ   e Zd ZdZedƒ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dS ) ÚUnicodeFunctionsTestZ(d1e37a2854df60ac607b47b51189b9bf1b54bfdbr   c                 C   sÌ   g }t  ¡ }ttjd ƒD ]–}t|ƒ}t| j |d¡dƒt| j 	|d¡dƒt| j 
|d¡dƒ| j |¡| j |¡| j |¡t| j |¡ƒt| j |¡ƒg}| d |¡ d¡¡ q| ¡ }|  || j¡ d S )Nr   éÿÿÿÿz.12gr   Úascii)r   r   r   r   r   r   Úformatr4   ÚdigitÚnumericÚdecimalÚcategoryÚbidirectionalÚdecompositionÚstrÚmirroredÚ	combiningr    r!   r"   r#   r$   r%   )r&   r*   r'   r(   r)   r+   r,   r,   r-   Útest_function_checksumK   s     


÷z+UnicodeFunctionsTest.test_function_checksumc                 C   s¶   |   | j dd ¡d ¡ |   | j d¡d¡ |   | j dd ¡d ¡ |   | j d¡d¡ |   | j dd ¡d ¡ |   | j d¡d¡ |  t| jj¡ |  t| jjd	¡ |  t| jjd
¡ d S ©NÚAÚ9é	   õ   â…›õ   â‘¨õ   ð €€u   ðŸ½é   ÚxxÚx)r$   r4   r9   ÚassertRaisesÚ	TypeErrorÚ
ValueError©r&   r,   r,   r-   Ú
test_digita   s    zUnicodeFunctionsTest.test_digitc                 C   sÈ   |   | j dd ¡d ¡ |   | j d¡d¡ |   | j d¡d¡ |   | j d¡d¡ |   | j d¡d	¡ |   | j d
d ¡d ¡ |   | j d¡d¡ |  t| jj¡ |  t| jjd¡ |  t| jjd¡ d S )NrD   rE   rF   rG   g      À?rH   g      "@u   ê˜§g      @rI   õ   ð„ªi(#  rK   rL   )r$   r4   r:   rM   rN   rO   rP   r,   r,   r-   Útest_numericm   s    z!UnicodeFunctionsTest.test_numericc                 C   s¸   |   | j dd ¡d ¡ |   | j d¡d¡ |   | j dd ¡d ¡ |   | j dd ¡d ¡ |   | j dd ¡d ¡ |   | j d¡d¡ |  t| jj¡ |  t| jjd	¡ |  t| jjd
¡ d S rC   )r$   r4   r;   rM   rN   rO   rP   r,   r,   r-   Útest_decimalz   s    z!UnicodeFunctionsTest.test_decimalc                 C   sŠ   |   | j d¡d¡ |   | j d¡d¡ |   | j d¡d¡ |   | j d¡d¡ |   | j d	¡d
¡ |  t| jj¡ |  t| jjd¡ d S )Nõ   ï¿¾ZCnÚaZLlrD   ZLurI   ZLorR   ZNorK   )r$   r4   r<   rM   rN   rP   r,   r,   r-   Útest_category†   s    z"UnicodeFunctionsTest.test_categoryc                 C   sv   |   | j d¡d¡ |   | j d¡d¡ |   | j d¡d¡ |   | j d¡d¡ |  t| jj¡ |  t| jjd¡ d S )	NrU   r   ú ZWSrD   ÚLrI   rK   )r$   r4   r=   rM   rN   rP   r,   r,   r-   Útest_bidirectional   s    z'UnicodeFunctionsTest.test_bidirectionalc                 C   sN   |   | j d¡d¡ |   | j d¡d¡ |  t| jj¡ |  t| jjd¡ d S )NrU   r   õ   Â¼z<fraction> 0031 2044 0034rK   )r$   r4   r>   rM   rN   rP   r,   r,   r-   Útest_decomposition™   s    z'UnicodeFunctionsTest.test_decompositionc                 C   sv   |   | j d¡d¡ |   | j d¡d¡ |   | j d¡d¡ |   | j d¡d¡ |  t| jj¡ |  t| jjd¡ d S )NrU   r   rV   u   âˆr   rI   rK   )r$   r4   r@   rM   rN   rP   r,   r,   r-   Útest_mirrored    s    z"UnicodeFunctionsTest.test_mirroredc                 C   sv   |   | j d¡d¡ |   | j d¡d¡ |   | j d¡d¡ |   | j d¡d¡ |  t| jj¡ |  t| jjd¡ d S )NrU   r   rV   u   âƒ¡éæ   rI   rK   )r$   r4   rA   rM   rN   rP   r,   r,   r-   Útest_combining©   s    z#UnicodeFunctionsTest.test_combiningc                 C   s(   d}|D ]}|   | j d|¡|¡ qd S )N)u   à­‡Ì€à¬¾u   á„€Ì€á…¡u   LiÌt-sá¹³Ìu.   à¤®à¤¾à¤°à¥à¤• à¤œà¤¼à¥à¤•à¥‡à¤°à¤¬à¤°à¥à¤—u'   à¤•à¤¿à¤°à¥à¤—à¤¿à¤œà¤¼à¤¸à¥à¤¤à¤¾à¤¨ÚNFC©r$   r4   Ú	normalize)r&   ZcomposedÚtextr,   r,   r-   Ú	test_pr29²   s    zUnicodeFunctionsTest.test_pr29c                 C   s"   d}d}|   | j d|¡|¡ d S )Nu?   CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ§u>   CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸CÌ¸Ã‡r`   ra   )r&   rV   Úbr,   r,   r-   Útest_issue10254¾   s    z$UnicodeFunctionsTest.test_issue10254c                 C   s^   d}d}d}d}d}d}|   | j d|¡|¡ |   | j d|¡|¡ |   | j d|¡|¡ d S )Nu	   á„€á…¶á†¨u	   á„€á…µá†§u   ê¸°á†§u	   á„€á…µá‡ƒu   ê¸°á‡ƒr`   ra   )r&   Zu1176_str_aZu1176_str_bZu11a7_str_aZu11a7_str_bZu11c3_str_aZu11c3_str_br,   r,   r-   Útest_issue29456Ä   s    z$UnicodeFunctionsTest.test_issue29456c                 C   s¶   | j j}|  t|d¡ |  t|tƒ ¡ |  t|d¡ |  t|d¡ |  |dƒd¡ |  |dƒd¡ |  |dƒd	¡ |  |d
ƒd¡ |  |dƒd¡ |  |dƒd¡ |  |dƒd	¡ d S )Nó   ar   ZraúÚNrX   ZNau   ì¢”ÚWu   ï½¦ÚHu   ï¼ŸÚFu   â€rD   rI   )r4   Úeast_asian_widthrM   rN   Ú	bytearrayr$   )r&   Zeawr,   r,   r-   Útest_east_asian_widthÐ   s    z*UnicodeFunctionsTest.test_east_asian_widthc                 C   s.   |   | jj d¡d¡ |   | j d¡d¡ d S )Nu   âŒšrj   rk   )r$   r4   Ú	ucd_3_2_0rn   rP   r,   r,   r-   Ú!test_east_asian_width_9_0_changesÞ   s    z6UnicodeFunctionsTest.test_east_asian_width_9_0_changesN)r/   r0   r1   r%   r   rB   rQ   rS   rT   rW   rZ   r\   r]   r_   rd   rf   rg   rp   rr   r,   r,   r,   r-   r5   E   s    

			r5   c                   @   sL   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S )ÚUnicodeMiscTestc                 C   s,   d}t  d|¡}d}|  ||j d¡¡ d S )NzGimport sys;sys.modules['unicodedata'] = None;eval("'\\N{SOFT HYPHEN}'")z-czUSyntaxError: (unicode error) \N escapes not supported (can't load unicodedata module)r7   )r   Zassert_python_failureZassertInÚerrÚdecode)r&   Úcoder+   Úerrorr,   r,   r-   Ú#test_failed_import_during_compilingä   s    z3UnicodeMiscTest.test_failed_import_during_compilingc                 C   s^   d}t dƒD ]>}t|ƒ}| j |d¡}|dkr|  || j |¡¡ |d7 }q|  |dk¡ d S ©Nr   é   r6   r   é
   )r   r   r4   r;   r$   r:   Ú
assertTrue©r&   Úcountr(   ÚcZdecr,   r,   r-   Útest_decimal_numeric_consistentô   s    
z/UnicodeMiscTest.test_decimal_numeric_consistentc                 C   s^   d}t dƒD ]>}t|ƒ}| j |d¡}|dkr|  || j |¡¡ |d7 }q|  |dk¡ d S ry   )r   r   r4   r9   r$   r:   r|   r}   r,   r,   r-   Útest_digit_numeric_consistent  s    
z-UnicodeMiscTest.test_digit_numeric_consistentc                 C   s   |   | j d¡d¡ d S )NzGOTHIC LETTER FAIHUu   ð†)r$   r4   ÚlookuprP   r,   r,   r-   Útest_bug_1704793  s    z UnicodeMiscTest.test_bug_1704793c                 C   sf   dd l }|  | d¡¡ |  |j d¡ ¡ |  d ¡ dk¡ |  d ¡ dk¡ |  d ¡ dk¡ d S )Nr   u   à¼ºrV   rD   õ   áµ¹u   ê½Ú.)r3   r|   r@   rq   r   )r&   r3   r,   r,   r-   Útest_ucd_510  s    zUnicodeMiscTest.test_ucd_510c                 C   s6   |   d ¡ d¡ |   dd„ ttjd ƒD ƒdg¡ d S )Nr„   c                 S   s8   g | ]0}d t |ƒ ¡ t |ƒ ¡  t |ƒ ¡  v r|‘qS )ú )r   r   r   r   )Ú.0r   r,   r,   r-   Ú
<listcomp>   s   (ÿz1UnicodeMiscTest.test_bug_5828.<locals>.<listcomp>r   r   )r$   r   r   r   r   rP   r,   r,   r-   Útest_bug_5828  s    ÿûzUnicodeMiscTest.test_bug_5828c                 C   s4   |   d ¡ d¡ |   d ¡ d¡ |   d ¡ d¡ d S )Nu   Ç„u   Ç…u   Ç†)r$   r   rP   r,   r,   r-   Útest_bug_4971'  s    zUnicodeMiscTest.test_bug_4971c                 C   sX   t dƒD ]J}t|ƒd  ¡ }|dv r<|  t|ƒdd| ¡ q|  t|ƒdd| ¡ qd S )Nrz   rD   )
r{   é   é   é   é…   é   é   é   i(   i)   é   z\u%.4x should be a linebreakr   z \u%.4x should not be a linebreak)r   r   Ú
splitlinesr$   Úlen)r&   r(   Úlinesr,   r,   r-   Útest_linebreak_7643-  s    ÿÿz#UnicodeMiscTest.test_linebreak_7643N)r/   r0   r1   rx   r€   r   rƒ   r†   rŠ   r‹   r—   r,   r,   r,   r-   rs   â   s   rs   c                   @   sL   e Zd Zedd„ ƒZedd„ ƒZedƒdd„ ƒZdd	„ Zd
d„ Z	dd„ Z
dS )ÚNormalizationTestc                 C   s   |   ¡ }tj|v S )N)Úreadliner3   Úunidata_version)ZtestfileZhdrr,   r,   r-   Úcheck_version9  s    zNormalizationTest.check_versionc                 C   s(   dd„ |   d¡D ƒ} d dd„ | D ƒ¡S )Nc                 S   s   g | ]}t |d ƒ‘qS )é   )Úint©rˆ   rL   r,   r,   r-   r‰   @  ó    z,NormalizationTest.unistr.<locals>.<listcomp>rX   r   c                 S   s   g | ]}t |ƒ‘qS r,   )r   rž   r,   r,   r-   r‰   A  rŸ   )Úsplitr!   )r*   r,   r,   r-   Úunistr>  s    zNormalizationTest.unistrZnetworkc              	   C   s¦   d}dt j› d|› }zt|d| jd}W nH tyN   |  d|› d¡ Y n& ttfyr   |  d|› ¡ Y n0 | |  	|¡ W d   ƒ n1 s˜0    Y  d S )	NzNormalizationTest.txtz"http://www.pythontest.net/unicode/ú/r   )ÚencodingÚcheckz"Permission error when downloading z into the test data directoryzCould not retrieve )
r3   rš   r   r›   ÚPermissionErrorZskipTestÚOSErrorr   ZfailÚrun_normalization_tests)r&   ZTESTDATAFILEZTESTDATAURLÚtestdatar,   r,   r-   Útest_normalizationC  s    ÿ
z$NormalizationTest.test_normalizationc                    s  d }i }dd„ }dd„ }dd„ }dd„ }|D ]\}d	|v rH|  d	¡d
 }| ¡ }|sVq,| d¡rn|  ¡ d
 }q,‡ fdd„|  d¡d d… D ƒ\}	}
}}}ˆ  |
||	ƒ  koÄ||
ƒ  koÄ||ƒkn  |¡ ˆ  |||ƒ  koì||ƒkn  |¡ ˆ  |||	ƒ  ko&||
ƒ  ko&||ƒkn  |¡ ˆ  |||ƒ  koP||ƒkn  |¡ ˆ  |||	ƒ  koª||
ƒ  koª||ƒ  koª||ƒ  koª||ƒkn  |¡ ˆ  |||	ƒ  ko||
ƒ  ko||ƒ  ko||ƒ  ko||ƒkn  |¡ ˆ  t d|
¡¡ ˆ  t d|¡¡ ˆ  t d|¡¡ ˆ  t d|¡¡ ˆ  t d|¡¡ ˆ  t d|¡¡ |dkr,d||	< q,ttjd ƒD ]f}t	|ƒ}||v r´qšˆ  |||ƒ  koô||ƒ  koô||ƒ  koô||ƒkn  |¡ qšd S )Nc                 S   s   t  d| ¡S )Nr`   ©r3   rb   ©r?   r,   r,   r-   r`   Y  s    z6NormalizationTest.run_normalization_tests.<locals>.NFCc                 S   s   t  d| ¡S )NÚNFKCrª   r«   r,   r,   r-   r¬   \  s    z7NormalizationTest.run_normalization_tests.<locals>.NFKCc                 S   s   t  d| ¡S )NÚNFDrª   r«   r,   r,   r-   r­   _  s    z6NormalizationTest.run_normalization_tests.<locals>.NFDc                 S   s   t  d| ¡S )NÚNFKDrª   r«   r,   r,   r-   r®   b  s    z7NormalizationTest.run_normalization_tests.<locals>.NFKDú#r   z@Partc                    s   g | ]}ˆ   |¡‘qS r,   )r¡   rž   rP   r,   r-   r‰   n  rŸ   z=NormalizationTest.run_normalization_tests.<locals>.<listcomp>ú;r6   r`   r­   r¬   r®   z@Part1r   )
r    ÚstripÚ
startswithr|   r3   Úis_normalizedr   r   r   r   )r&   r¨   ÚpartZ
part1_datar`   r¬   r­   r®   ÚlineÚc1Úc2Zc3Zc4Zc5r   ÚXr,   rP   r-   r§   U  sf    

*6(:*&ÿ
ÿ
ÿþ&ÿ
ÿ
ÿþ

z)NormalizationTest.run_normalization_testsc                 C   s8   |   ttj¡ |   ttjdd¡ |  t dd¡d¡ d S )NÚunknownrK   r¬   r   )rM   rN   r3   rb   rO   r$   rP   r,   r,   r-   Útest_edge_cases  s    z!NormalizationTest.test_edge_casesc                 C   s   t  dd¡ d S )Nr`   u   í•œê¸€rª   rP   r,   r,   r-   Útest_bug_834676•  s    z!NormalizationTest.test_bug_834676N)r/   r0   r1   Ústaticmethodr›   r¡   r   r©   r§   rº   r»   r,   r,   r,   r-   r˜   8  s   


;r˜   Ú__main__)r   Zhttp.clientr   r   r3   ZunittestZtest.supportr   r   r   ZTestCaser   r2   r5   rs   r˜   r/   Úmainr,   r,   r,   r-   Ú<module>	   s   1 Vb