
    <e@                     .   d Z 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
mZmZmZ  G d dej                  Z G d dej                  Z G d	 d
e          Z G d de          Z G d dej                  Zedk    r ej                     dS dS )z Tests for the unicodedata module.

    Written by Marc-Andre Lemburg (mal@lemburg.com).

    (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.

    N)HTTPException)open_urlresourcerequires_resourcescript_helpercpython_onlycheck_disallow_instantiationResourceDeniedc                   :    e Zd ZdZ ed          d             ZdS )UnicodeMethodsTest(4739770dd4d0e5f1b1677accfc3552ed3c8ef326cpuc                 B   t          j                    }t          t          j        dz             D ]}t          |          }d|                                         d|                                         d|                                         d|	                                         d|
                                         d|                                         d|                                         d|                                         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z                                   |dz                                   |dz                                   |dz                                   g}|                    d                    |                              dd	                     |                                }|                     || j                   d S )
N   01abc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results         ,/usr/lib/python3.11/test/test_unicodedata.pytest_method_checksumz'UnicodeMethodsTest.test_method_checksum   s   LNNs~)** %	E %	EAq66D T\\^^$T\\^^$T^^%%&T\\^^$T\\^^$T^^%%&T\\^^$T\\^^$T\\^^$ dUl++--.dUl++--.dUl--//0dUl++--.dUl++--.dUl--//0dUl++--.dUl++--.dUl++--. 





 $$&&$$&&$$&&$$&&A"DF HHRWWT]]))'?CCDDDD!677777    N)__name__
__module____qualname__r.   r   r6    r7   r5   r   r      sB         Bu)8 )8 )8 )8 )8r7   r   c                       e Zd ZeZdS )UnicodeDatabaseTestN)r8   r9   r:   unicodedatadbr;   r7   r5   r=   r=   D   s        	BBBr7   r=   c                       e Zd ZdZ ed          d             Z ed          d             Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd ZdS )UnicodeFunctionsTest(98d602e1f69d5c5bb8a5910c40bbbad4e18e8370r   c                    g }t          j                    }t          t          j        dz             D ]^}t          |          }t          | j                            |d          d          t          | j        	                    |d          d          t          | j        
                    |d          d          | j                            |          | j                            |          | j                            |          t          | j                            |                    t          | j                            |                    g}|                    d                    |                              d                     `|                                }|                     || j                   d S )Nr   z.12gr   ascii)r   r   r   r   r   r   formatr?   digitnumericdecimalcategorybidirectionaldecompositionstrmirrored	combiningr)   r*   r+   r,   r-   r.   )r/   r3   r0   r1   r2   r4   s         r5   test_function_checksumz+UnicodeFunctionsTest.test_function_checksumM   se   LNNs~)** 	4 	4Aq66D tw}}T2..77twtR00&99twtR00&99  &&%%d++%%d++DG$$T**++DG%%d++,,
D HHRWWT]]))'223333!677777r7   c                     t          t          j        dz             D ]\}t          |          }| j                            |d           x}r.|                     | j                            |          |           ]d S )Nr   )r   r   r   r   r?   namer-   lookup)r/   r1   r2   looked_names       r5   test_name_inverse_lookupz-UnicodeFunctionsTest.test_name_inverse_lookupc   s|    s~)** 	D 	DAq66D"gll4666{ D  !<!<dCCC	D 	Dr7   c                    |                      | 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-   r?   rG   assertRaises	TypeError
ValueErrorr/   s    r5   
test_digitzUnicodeFunctionsTest.test_digitj   s8   sD114888s++Q///x66===x00!444|T::DAAA|44a888)TW]333)TW]D999*dgmS99999r7   c                 p   |                      | 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 )NrX   rY   rZ   r[   g      ?r\   g      "@u   ꘧g      @r]      𐄪i(#  r_   r`   )r-   r?   rH   ra   rb   rc   rd   s    r5   test_numericz!UnicodeFunctionsTest.test_numericv   sZ   T22D999--q11122E:::22C88822C888t<<dCCC66===)TW_555)TW_d;;;*dgos;;;;;r7   c                    |                      | 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 rW   )r-   r?   rI   ra   rb   rc   rd   s    r5   test_decimalz!UnicodeFunctionsTest.test_decimal   s:   T22D999--q111488$???488$???t<<dCCC66:::)TW_555)TW_d;;;*dgos;;;;;r7   c                 h   |                      | 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   ￾CnaLlrX   Lur]   Lorg   Nor_   )r-   r?   rJ   ra   rb   rd   s    r5   test_categoryz"UnicodeFunctionsTest.test_category   s    ))(33T:::))#..555))#..555)),77>>>)),77>>>)TW%5666)TW%5t<<<<<r7   c                    |                      | j                            d          d           |                      | j                            d          d           |                      | j                            d          d           |                      | j                            d          d           |                     t          | j        j                   |                     t          | j        j        d           d S )	Nrl   r    WSrX   Lr]   r_   )r-   r?   rK   ra   rb   rd   s    r5   test_bidirectionalz'UnicodeFunctionsTest.test_bidirectional   s    ..x88"===..s33T:::..s33S999..|<<cBBB)TW%:;;;)TW%:DAAAAAr7   c                 T   |                      | j                            d          d           |                      | j                            d          d           |                     t          | j        j                   |                     t          | j        j        d           d S )Nrl   r      ¼z<fraction> 0031 2044 0034r_   )r-   r?   rL   ra   rb   rd   s    r5   test_decompositionz'UnicodeFunctionsTest.test_decomposition   s    ..x88<<<..x88:UVVV)TW%:;;;)TW%:DAAAAAr7   c                    |                      | j                            d          d           |                      | j                            d          d           |                      | j                            d          d           |                      | j                            d          d           |                     t          | j        j                   |                     t          | j        j        d           d S )Nrl   r   rn   u   ∁r   r]   r_   )r-   r?   rN   ra   rb   rd   s    r5   test_mirroredz"UnicodeFunctionsTest.test_mirrored   s    ))(33Q777))#..222))(33Q777)),77;;;)TW%5666)TW%5t<<<<<r7   c                    |                      | j                            d          d           |                      | j                            d          d           |                      | j                            d          d           |                      | j                            d          d           |                     t          | j        j                   |                     t          | j        j        d           d S )Nrl   r   rn   u   ⃡   r]   r_   )r-   r?   rO   ra   rb   rd   s    r5   test_combiningz#UnicodeFunctionsTest.test_combining   s    **844a888**3//333**844c:::**<88!<<<)TW%6777)TW%6=====r7   c                 r    d}|D ]1}|                      | j                            d|          |           2d S )N)u   େ̀ାu   ᄀ̀ᅡu   Li̍t-sṳ́u.   मार्क ज़ुकेरबर्गu'   किर्गिज़स्तानNFCr-   r?   	normalize)r/   composedtexts      r5   	test_pr29zUnicodeFunctionsTest.test_pr29   sS    8  	C 	CDTW..ud;;TBBBB	C 	Cr7   c                 l    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   r   )r/   rn   bs      r5   test_issue10254z$UnicodeFunctionsTest.test_issue10254   s:    '$**5!44a88888r7   c                 8   d}d}d}d}d}d}|                      | j                            d|          |           |                      | j                            d|          |           |                      | j                            d|          |           d S )Nu	   ᄀᅶᆨu	   기ᆧu   기ᆧu	   기ᇃu   기ᇃr   r   )r/   u1176_str_au1176_str_bu11a7_str_au11a7_str_bu11c3_str_au11c3_str_bs          r5   test_issue29456z$UnicodeFunctionsTest.test_issue29456   s    ***$*$**5+>>LLL**5+>>LLL**5+>>LLLLLr7   c                    | 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   raNru   Nau   좔Wu   ｦHu   ？Fu   ‐rX   r]   )r?   east_asian_widthra   rb   	bytearrayr-   )r/   eaws     r5   test_east_asian_widthz*UnicodeFunctionsTest.test_east_asian_width   sJ   g&)S$///)S)++666)S"---)S$///Vc***Vd+++X,,,X,,,X,,,X,,,\**C00000r7   c                     |                      | j        j                            d          d           |                      | j                            d          d           d S )Nu   ⌚r   r   )r-   r?   	ucd_3_2_0r   rd   s    r5   !test_east_asian_width_9_0_changesz6UnicodeFunctionsTest.test_east_asian_width_9_0_changes   sW    *;;HEEsKKK11(;;SAAAAAr7   N)r8   r9   r:   r.   r   rP   rU   re   rh   rj   rs   rx   r{   r}   r   r   r   r   r   r   r;   r7   r5   rA   rA   G   s@        Bu8 8 8* uD D D
: 
: 
:< < <
< 
< 
<= = =B B BB B B= = => > >
C 
C 
C9 9 9
M 
M 
M1 1 1B B B B Br7   rA   c                   T    e Zd Zed             Zd Zd Zd Zd Zd Z	d Z
d Zd	 Zd
S )UnicodeMiscTestc                 :    t          | t          j                   d S N)r   r>   UCDrd   s    r5   test_disallow_instantiationz+UnicodeMiscTest.test_disallow_instantiation   s     	%T;?;;;;;r7   c                     d}t          j        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)rE   )r   assert_python_failureassertInerrdecode)r/   coder4   errors       r5   #test_failed_import_during_compilingz3UnicodeMiscTest.test_failed_import_during_compiling   sN    /
 4T4@@.eVZ..w7788888r7   c                 &   d}t          d          D ]e}t          |          }| j                            |d          }|dk    r3|                     || j                            |                     |dz  }f|                     |dk               d S Nr      rD   r   
   )r   r   r?   rI   r-   rH   
assertTruer/   countr1   cdecs        r5   test_decimal_numeric_consistentz/UnicodeMiscTest.test_decimal_numeric_consistent  s     w 	 	AAA'//!R((Cbyy  dgooa&8&8999
$$$$$r7   c                 &   d}t          d          D ]e}t          |          }| j                            |d          }|dk    r3|                     || j                            |                     |dz  }f|                     |dk               d S r   )r   r   r?   rG   r-   rH   r   r   s        r5   test_digit_numeric_consistentz-UnicodeMiscTest.test_digit_numeric_consistent  s     w 	 	AAA'--2&&Cbyy  dgooa&8&8999
$$$$$r7   c                 b    |                      | j                            d          d           d S )NzGOTHIC LETTER FAIHUu   𐍆)r-   r?   rS   rd   s    r5   test_bug_1704793z UnicodeMiscTest.test_bug_1704793  s-    (=>>MMMMMr7   c                    dd l }|                      |j        d                     |                     |j                            d                      |                     d                                dk               |                     d                                dk               |                     d                                dk               d S )Nr   u   ༺rn   rX      ᵹu   Ᵹ.)r>   r   rN   r   r'   )r/   r>   s     r5   test_ucd_510zUnicodeMiscTest.test_ucd_510  s    ,,X66777K1::8DDDEEE 			S()))(((2333		S()))))r7   c                     |                      d                                d           |                      d t          t          j        dz             D             dg           d S )Nr   c                     g | ]k}d t          |                                          t          |                                          z   t          |                                          z   v i|lS ) )r   r&   r'   r(   ).0r   s     r5   
<listcomp>z1UnicodeMiscTest.test_bug_5828.<locals>.<listcomp>.  sa       SVV\\^^CFFLLNN:3q66<<>>III IIIr7   r   r   )r-   r&   r   r   r   rd   s    r5   test_bug_5828zUnicodeMiscTest.test_bug_5828*  sv    ))8444  !122   C	
 	
 	
 	
 	
r7   c                     |                      d                                d           |                      d                                d           |                      d                                d           d S )Nu   Ǆu   ǅu   ǆ)r-   r(   rd   s    r5   test_bug_4971zUnicodeMiscTest.test_bug_49715  sh    ))8444))8444))844444r7   c                    t          d          D ]y}t          |          dz                                   }|dv r(|                     t	          |          dd|z             R|                     t	          |          dd|z             zd S )Nr   rX   )
r                        i(   i)      z\u%.4x should be a linebreakr   z \u%.4x should not be a linebreak)r   r   
splitlinesr-   len)r/   r1   liness      r5   test_linebreak_7643z#UnicodeMiscTest.test_linebreak_7643;  s    w 	J 	JAVVc\--//E 7 7 7  UQ!@1!DF F F F   UQ!Dq!HJ J J J	J 	Jr7   N)r8   r9   r:   r   r   r   r   r   r   r   r   r   r   r;   r7   r5   r   r      s        < < \<9 9 9 % % %% % %N N N	* 	* 	*	
 	
 	
5 5 5	J 	J 	J 	J 	Jr7   r   c                   t    e Zd Zed             Zed             Z ed          d             Zd Zd Z	d Z
dS )	NormalizationTestc                 F    |                                  }t          j        |v S r   )readliner>   unidata_version)testfilehdrs     r5   check_versionzNormalizationTest.check_versionG  s!    !!*c11r7   c                 ~    d |                      d          D             } d                    d | D                       S )Nc                 .    g | ]}t          |d           S )   )intr   r`   s     r5   r   z,NormalizationTest.unistr.<locals>.<listcomp>N  s     444qAr

444r7   ru   r   c                 ,    g | ]}t          |          S r;   )r   r   s     r5   r   z,NormalizationTest.unistr.<locals>.<listcomp>O  s    ---1A---r7   )splitr*   )r3   s    r5   unistrzNormalizationTest.unistrL  s@    44DJJsOO444ww-----...r7   networkc                 z   d}dt           j         d| }	 t          |d| j                  }n]# t          $ r |                     d| d           Y n8t          t          f$ r%}|                     d| d	|            Y d }~nd }~ww xY w|5  |                     |           d d d            d S # 1 swxY w Y   d S )
NzNormalizationTest.txtz"http://www.pythontest.net/unicode//r   )encodingcheckz"Permission error when downloading z into the test data directoryzFailed to download z: )	r>   r   r   r   PermissionErrorskipTestOSErrorr   run_normalization_tests)r/   TESTDATAFILETESTDATAURLtestdataexcs        r5   test_normalizationz$NormalizationTest.test_normalizationQ  sk   .g;;VggYegg	F'g.2.@B B BHH 	; 	; 	;MM :{ : : : ; ; ; ; ;' 	F 	F 	FMMDDDsDDEEEEEEEE	F  	3 	3((222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3s-   . #BB#BBB00B47B4c                     d }i }d }d }d }d }|D ]W}d|v r|                     d          d         }|                                }|s9|                    d          r|                                 d         }i fd|                     d	          d d
         D             \  }	}
}}}                     |
 ||	          cxk    o ||
          cxk    o ||          k    nc |                                | ||          cxk    o ||          k    nc |                                | ||	          cxk    o ||
          cxk    o ||          k    nc |                                | ||          cxk    o ||          k    nc |                                | ||	          cxk    o> ||
          cxk    o. ||          cxk    o ||          cxk    o ||          k    nc |                                | ||	          cxk    o> ||
          cxk    o. ||          cxk    o ||          cxk    o ||          k    nc |                                t	          j        d|
                                          t	          j        d|                                          t	          j        d|                                          t	          j        d|                                          t	          j        d|                                          t	          j        d|                     |dk    rd||	<   Yt          t          j        dz             D ]l}t          |          }||v r                     | ||          cxk    o. ||          cxk    o ||          cxk    o ||          k    nc |           md S )Nc                 ,    t          j        d|           S )Nr   r>   r   rM   s    r5   r   z6NormalizationTest.run_normalization_tests.<locals>.NFCg      (444r7   c                 ,    t          j        d|           S )NNFKCr   r   s    r5   r   z7NormalizationTest.run_normalization_tests.<locals>.NFKCj      (555r7   c                 ,    t          j        d|           S )NNFDr   r   s    r5   r   z6NormalizationTest.run_normalization_tests.<locals>.NFDm  r   r7   c                 ,    t          j        d|           S )NNFKDr   r   s    r5   r  z7NormalizationTest.run_normalization_tests.<locals>.NFKDp  r   r7   #r   z@Partc                 :    g | ]}                     |          S r;   )r   )r   r`   r/   s     r5   r   z=NormalizationTest.run_normalization_tests.<locals>.<listcomp>|  s#    KKKdkk!nnKKKr7   ;rD   r   r   r   r  z@Part1r   )
r   strip
startswithr   r>   is_normalizedr   r   r   r   )r/   r   part
part1_datar   r   r   r  linec1c2c3c4c5r   Xs   `               r5   r   z)NormalizationTest.run_normalization_testsc  s   
	5 	5 	5	6 	6 	6	5 	5 	5	6 	6 	6  "	# "	#Dd{{zz#q)::<<D w'' zz||AKKKKdjjoocrc6JKKKNBr"R OOB33r77BBBBss2wwBBBB33r77BBBBDIIIOOB33r776666ss2ww6666===OOB33r77BBBBss2wwBBBB33r77BBBBDIIIOOB33r776666ss2ww6666===OOB$$r(( = = = =dd2hh = = = = DHH= = = =(,R= = = =48DHH= = = = " " " OOB$$r(( = = = =dd2hh = = = = DHH= = = =(,R= = = =48DHH= = = = " " " OOK5eR@@AAAOOK5eR@@AAAOOK5eR@@AAAOOK5eR@@AAAOOK5fbAABBBOOK5fbAABBB x!"
2 s~a'(( 	L 	LAAAJOOAQGGGG33q66GGGGTT!WWGGGGQGGGGKKKK		L 	Lr7   c                     |                      t          t          j                   |                      t          t          j        dd           |                     t          j        dd          d           d S )Nunknownr_   r   r   )ra   rb   r>   r   rc   r-   rd   s    r5   test_edge_casesz!NormalizationTest.test_edge_cases  sa    )[%:;;;*k&;YMMM.vr::B?????r7   c                 0    t          j        dd           d S )Nr   u   한글r   rd   s    r5   test_bug_834676z!NormalizationTest.test_bug_834676  s    e^44444r7   N)r8   r9   r:   staticmethodr   r   r   r   r   r  r  r;   r7   r5   r   r   F  s        2 2 \2 / / \/ y!!3 3 "!3"9L 9L 9Lv@ @ @
5 5 5 5 5r7   r   __main__)__doc__r   http.clientr   r   r>   unittesttest.supportr   r   r   r   r   r	   TestCaser   r=   rA   r   r   r8   mainr;   r7   r5   <module>r     s     % % % % % % 



     * * * * * * * * * * * * * * * *
/8 /8 /8 /8 /8* /8 /8 /8b    (+   bB bB bB bB bB. bB bB bBHYJ YJ YJ YJ YJ) YJ YJ YJv_5 _5 _5 _5 _5) _5 _5 _5D zHMOOOOO r7   