
    dafD                     (   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  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(                          yy)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_instantiationc                   ,    e Zd ZdZ ed      d        Zy)UnicodeMethodsTest(e708c31c0d51f758adf475cb7201cf80917362becpuc                    t        j                         }t        t        j                  dz         D ]  }t        |      }d|j                            d|j                            d|j                            d|j                            d|j                            d|j                            d|j                            d|j                            d|j                            d|dz   j                            d|dz   j                            d|dz   j                            d|dz   j                            d|dz   j                            d|dz   j                            d|dz   j                            d|dz   j                            d|dz   j                            |j                         |j!                         |j#                         |dz   j                         |dz   j!                         |dz   j#                         |dz   j#                         g}|j%                  dj'                  |      j)                  dd	              |j+                         }| j-                  || j.                         y )
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         0/root/Python-3.12.4/Lib/test/test_unicodedata.pytest_method_checksumz'UnicodeMethodsTest.test_method_checksum   s&   LLNs~~)* %	EAq6D T\\^$T\\^$T^^%&T\\^$T\\^$T^^%&T\\^$T\\^$T\\^$ dUl++-.dUl++-.dUl--/0dUl++-.dUl++-.dUl--/0dUl++-.dUl++-.dUl++-. 





 $$&$$&$$&$$&A"DF HHRWWT]))'?CDK%	EL !6!67    N)__name__
__module____qualname__r-   r   r5    r6   r4   r
   r
      s"     Bu)8 )8r6   r
   c                       e Zd ZeZy)UnicodeDatabaseTestN)r7   r8   r9   unicodedatadbr:   r6   r4   r<   r<   C   s    	Br6   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 Zy)UnicodeFunctionsTest(26ff0d31c14194b4606a5b3a81ac36df3a14e331r   c                    g }t        j                         }t        t        j                  dz         D ]q  }t        |      }t        | j                  j                  |d      d      t        | j                  j                  |d      d      t        | j                  j                  |d      d      | j                  j                  |      | j                  j                  |      | j                  j                  |      t        | j                  j                  |            t        | j                  j!                  |            t#        j$                  |      | j                  j'                  |d      g
}|j)                  dj+                  |      j-                  d             t |j/                         }| j1                  || j2                         y )Nr   z.12gr   ascii)r   r   r   r   r   r   formatr>   digitnumericdecimalcategorybidirectionaldecompositionstrmirrored	combiningr=   east_asian_widthnamer(   r)   r*   r+   r,   r-   )r.   r2   r/   r0   r1   r3   s         r4   test_function_checksumz+UnicodeFunctionsTest.test_function_checksumL   sT   LLNs~~)* 	4Aq6D tww}}T2.7twwtR0&9twwtR0&9  &%%d+%%d+DGG$$T*+DGG%%d+,,,T2T2&D HHRWWT]))'23	4  !6!67r6   c                     t        t        j                  dz         D ]W  }t        |      }| j                  j                  |d       x}s-| j                  | j                  j                  |      |       Y y )Nr   )r   r   r   r   r>   rP   r,   lookup)r.   r0   r1   looked_names       r4   test_name_inverse_lookupz-UnicodeFunctionsTest.test_name_inverse_lookupd   sa    s~~)* 	DAq6D"ggll466{6  !<dC	Dr6   c                    | j                  | j                  j                  dd       d        | j                  | j                  j                  d      d       | j                  | j                  j                  dd       d        | j                  | j                  j                  d      d       | j                  | j                  j                  dd       d        | j                  | j                  j                  d      d       | j                  t        | j                  j                         | j                  t        | j                  j                  d	       | j                  t
        | j                  j                  d
       y NA9	      ⅛   ⑨   𠀀u   𝟽   xxx)r,   r>   rF   assertRaises	TypeError
ValueErrorr.   s    r4   
test_digitzUnicodeFunctionsTest.test_digitk   s   sD148s+Q/x6=x0!4|T:DA|4a8)TWW]]3)TWW]]D9*dggmmS9r6   c                 b   | j                  | j                  j                  dd       d        | j                  | j                  j                  d      d       | j                  | j                  j                  d      d       | j                  | j                  j                  d      d       | j                  | j                  j                  d      d	       | j                  | j                  j                  d
d       d        | j                  | j                  j                  d      d       | j                  t        | j                  j                         | j                  t        | j                  j                  d       | j                  t
        | j                  j                  d       y )NrX   rY   rZ   r[   g      ?r\   g      "@u   ꘧g      @r]      𐄪i(#  r_   r`   )r,   r>   rG   ra   rb   rc   rd   s    r4   test_numericz!UnicodeFunctionsTest.test_numericw   s   T2D9-q12E:2C82C8t<dC6=)TWW__5)TWW__d;*dggoos;r6   c                    | j                  | j                  j                  dd       d        | j                  | j                  j                  d      d       | j                  | j                  j                  dd       d        | j                  | j                  j                  dd       d        | j                  | j                  j                  dd       d        | j                  | j                  j                  d      d       | j                  t        | j                  j                         | j                  t        | j                  j                  d	       | j                  t
        | j                  j                  d
       y rW   )r,   r>   rH   ra   rb   rc   rd   s    r4   test_decimalz!UnicodeFunctionsTest.test_decimal   s   T2D9-q148$?48$?t<dC6:)TWW__5)TWW__d;*dggoos;r6   c                 \   | j                  | j                  j                  d      d       | j                  | j                  j                  d      d       | j                  | j                  j                  d      d       | j                  | j                  j                  d      d       | j                  | j                  j                  d	      d
       | j                  t        | j                  j                         | j                  t        | j                  j                  d       y )N   ￾CnaLlrX   Lur]   Lorg   Nor_   )r,   r>   rI   ra   rb   rd   s    r4   test_categoryz"UnicodeFunctionsTest.test_category   s    ))(3T:))#.5))#.5)),7>)),7>)TWW%5%56)TWW%5%5t<r6   c                    | j                  | j                  j                  d      d       | j                  | j                  j                  d      d       | j                  | j                  j                  d      d       | j                  | j                  j                  d      d       | j                  t        | j                  j                         | j                  t        | j                  j                  d       y )	Nrl   r    WSrX   Lr]   r_   )r,   r>   rJ   ra   rb   rd   s    r4   test_bidirectionalz'UnicodeFunctionsTest.test_bidirectional   s    ..x8"=..s3T:..s3S9..|<cB)TWW%:%:;)TWW%:%:DAr6   c                 Z   | j                  | j                  j                  d      d       | j                  | j                  j                  d      d       | j                  t        | j                  j                         | j                  t        | j                  j                  d       y )Nrl   r      ¼z<fraction> 0031 2044 0034r_   )r,   r>   rK   ra   rb   rd   s    r4   test_decompositionz'UnicodeFunctionsTest.test_decomposition   sw    ..x8<..x8:UV)TWW%:%:;)TWW%:%:DAr6   c                    | j                  | j                  j                  d      d       | j                  | j                  j                  d      d       | j                  | j                  j                  d      d       | j                  | j                  j                  d      d       | j                  t        | j                  j                         | j                  t        | j                  j                  d       y )Nrl   r   rn   u   ∁r   r]   r_   )r,   r>   rM   ra   rb   rd   s    r4   test_mirroredz"UnicodeFunctionsTest.test_mirrored   s    ))(3Q7))#.2))(3Q7)),7;)TWW%5%56)TWW%5%5t<r6   c                    | j                  | j                  j                  d      d       | j                  | j                  j                  d      d       | j                  | j                  j                  d      d       | j                  | j                  j                  d      d       | j                  t        | j                  j                         | j                  t        | j                  j                  d       y )Nrl   r   rn   u   ⃡   r]   r_   )r,   r>   rN   ra   rb   rd   s    r4   test_combiningz#UnicodeFunctionsTest.test_combining   s    **84a8**3/3**84c:**<8!<)TWW%6%67)TWW%6%6=r6   c                 n    d}|D ].  }| j                  | j                  j                  d|      |       0 y )N)u   େ̀ାu   ᄀ̀ᅡu   Li̍t-sṳ́u.   मार्क ज़ुकेरबर्गu'   किर्गिज़स्तानNFCr,   r>   	normalize)r.   composedtexts      r4   	test_pr29zUnicodeFunctionsTest.test_pr29   s=    8  	CDTWW..ud;TB	Cr6   c                 d    d}d}| j                  | j                  j                  d|      |       y )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      r4   test_issue10254z$UnicodeFunctionsTest.test_issue10254   s-    '$**5!4a8r6   c                 $   d}d}d}d}d}d}| j                  | j                  j                  d|      |       | j                  | j                  j                  d|      |       | j                  | j                  j                  d|      |       y )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          r4   test_issue29456z$UnicodeFunctionsTest.test_issue29456   s    ***$*$**5+>L**5+>L**5+>Lr6   c                 H   | j                   j                  }| j                  t        |d       | j                  t        |t	                      | j                  t        |d       | j                  t        |d       | j                   |d      d       | j                   |d      d       | j                   |d      d	       | j                   |d
      d       | j                   |d      d       | j                   |d      d       | j                   |d      d	       y )N   ar   raNru   Nau   좔Wu   ｦHu   ？Fu   ‐rX   r]   )r>   rO   ra   rb   	bytearrayr,   )r.   eaws     r4   test_east_asian_widthz*UnicodeFunctionsTest.test_east_asian_width   s    gg&&)S$/)S)+6)S"-)S$/Vc*Vd+X,X,X,X,\*C0r6   c                    | j                   j                  }dD ]F  }| j                   ||      d       | j                  | j                   j	                  |d       d        H dD ]F  }| j                   ||      d       | j                  | j                   j	                  |d       d        H dD ]F  }| j                   ||      d       | j                  | j                   j	                  |d       d        H y )Nu   ԰໏჆⃼꫊𐞽𑗲r   u   﩮﫚𪛠𯨠𱍋𿿽r   u   󰀀󿿮􀀀􏿰rX   )r>   rO   r,   assertIsrP   )r.   r   r1   s      r4    test_east_asian_width_unassignedz5UnicodeFunctionsTest.test_east_asian_width_unassigned   s    gg&&H 	:DSY,MM$'',,tT2D9	:
 K 	:DSY,MM$'',,tT2D9	:
 K 	:DSY,MM$'',,tT2D9	:r6   c                     | j                  | j                  j                  j                  d      d       | j                  | j                  j                  d      d       y )Nu   ⌚r   r   )r,   r>   	ucd_3_2_0rO   rd   s    r4   !test_east_asian_width_9_0_changesz6UnicodeFunctionsTest.test_east_asian_width_9_0_changes   sF    **;;HEsK11(;SAr6   N)r7   r8   r9   r-   r   rQ   rU   re   rh   rj   rs   rx   r{   r}   r   r   r   r   r   r   r   r:   r6   r4   r@   r@   F   s     Bu8 8. uD D
:<
<=BB=>
C9
M1:"Br6   r@   c                   b    e Zd Zed        Zd Zd Zd Zd Zd Z	 e
d      d        Zd	 Zd
 Zy)UnicodeMiscTestc                 8    t        | t        j                         y N)r   r=   UCDrd   s    r4   test_disallow_instantiationz+UnicodeMiscTest.test_disallow_instantiation   s     	%T;??;r6   c                     d}t        j                  d|      }d}| j                  ||j                  j	                  d             y )NzGimport sys;sys.modules['unicodedata'] = None;eval("'\\N{SOFT HYPHEN}'")z-czUSyntaxError: (unicode error) \N escapes not supported (can't load unicodedata module)rD   )r   assert_python_failureassertInerrdecode)r.   coder3   errors       r4   #test_failed_import_during_compilingz3UnicodeMiscTest.test_failed_import_during_compiling  sA    /
 44T4@.eVZZ..w78r6   c                 
   d}t        d      D ]_  }t        |      }| j                  j                  |d      }|dk7  s0| j	                  || j                  j                  |             |dz  }a | j                  |dk\         y Nr      rC   r   
   )r   r   r>   rH   r,   rG   
assertTruer.   countr0   cdecs        r4   test_decimal_numeric_consistentz/UnicodeMiscTest.test_decimal_numeric_consistent  sx     w 	AAA''//!R(Cby  dggooa&89
	 	$r6   c                 
   d}t        d      D ]_  }t        |      }| j                  j                  |d      }|dk7  s0| j	                  || j                  j                  |             |dz  }a | j                  |dk\         y r   )r   r   r>   rF   r,   rG   r   r   s        r4   test_digit_numeric_consistentz-UnicodeMiscTest.test_digit_numeric_consistent!  sx     w 	AAA''--2&Cby  dggooa&89
	 	$r6   c                 Z    | j                  | j                  j                  d      d       y )NzGOTHIC LETTER FAIHUu   𐍆)r,   r>   rS   rd   s    r4   test_bug_1704793z UnicodeMiscTest.test_bug_1704793.  s     (=>Mr6   c                 p   dd l }| j                   |j                  d             | j                  |j                  j                  d              | j                  dj	                         dk(         | j                  dj	                         dk(         | j                  dj	                         dk(         y )Nr   u   ༺rn   rX      ᵹu   Ᵹ.)r=   r   rM   r   r&   )r.   r=   s     r4   test_ucd_510zUnicodeMiscTest.test_ucd_5101  s    ,,,X67K11::8DDE 			S()((23		S()r6   r   c           
      b   | j                  dj                         d       | j                  t        t        j                  dz         D cg c]S  }dt        |      j                         t        |      j                         z   t        |      j                         z   v r|U c}dg       y c c}w )Nr   r    r   )r,   r%   r   r   r   r   r&   r'   )r.   r   s     r4   test_bug_5828zUnicodeMiscTest.test_bug_5828<  s    )84 !12SV\\^CFLLN:3q6<<>II  C	
s   
AB,c                     | j                  dj                         d       | j                  dj                         d       | j                  dj                         d       y )Nu   Ǆu   ǅu   ǆ)r,   r'   rd   s    r4   test_bug_4971zUnicodeMiscTest.test_bug_4971H  sG    )84)84)84r6   c                     t        d      D ]a  }t        |      dz   j                         }|dv r | j                  t	        |      dd|z         C| j                  t	        |      dd|z         c y )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.   r0   liness      r4   test_linebreak_7643z#UnicodeMiscTest.test_linebreak_7643N  sz    w 	JAVc\--/E 7 7  UQ!@1!DF   UQ!Dq!HJ	Jr6   N)r7   r8   r9   r   r   r   r   r   r   r   r   r   r   r   r:   r6   r4   r   r      sR    < <9 %%N	* u	
 	
5	Jr6   r   c                   p    e Zd Zed        Zed        Z ed       ed      d               Zd Zd Z	d Z
y	)
NormalizationTestc                 F    | j                         }t        j                  |v S r   )readliner=   unidata_version)testfilehdrs     r4   check_versionzNormalizationTest.check_versionZ  s!    !**c11r6   c                     | j                  d      D cg c]  }t        |d       } }dj                  | D cg c]  }t        |       c}      S c c}w c c}w )Nru      r   )splitintr)   r   )r2   r`   s     r4   unistrzNormalizationTest.unistr_  sI    $(JJsO4qAr
44ww-1A-.. 5-s
   AAnetworkr   c                 Z   d}dt         j                   d| }	 t        |d| j                        }5  | j                  |       d d d        y # t        $ r | j                  d| d       Y =t        t        f$ r!}| j                  d| d	|        Y d }~gd }~ww xY w# 1 sw Y   y xY w)
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        r4   test_normalizationz$NormalizationTest.test_normalizationd  s     /:;;V;V:WWXYeXfg	F'g.2.@.@BH  	3((2	3 	3  	;MM>{m L9 : ;' 	FMM/}BseDEE	F	3 	3s(   A B!B/B=BB!B*c                    d }i }d }d }d }d }|D ]  }d|v r|j                  d      d   }|j                         }|s/|j                  d      r|j                         d   }T|j                  d      d d	 D 	cg c]  }	| j                  |	       c}	\  }
}}}}| j	                  | ||
      cxk(  xr  ||      cxk(  xr  ||      k(  nc |       | j	                  | ||      cxk(  xr  ||      k(  nc |       | j	                  | ||
      cxk(  xr  ||      cxk(  xr  ||      k(  nc |       | j	                  | ||      cxk(  xr  ||      k(  nc |       | j	                  | ||
      cxk(  xr5  ||      cxk(  xr'  ||      cxk(  xr  ||      cxk(  xr  ||      k(  nc |       | j	                  | ||
      cxk(  xr5  ||      cxk(  xr'  ||      cxk(  xr  ||      cxk(  xr  ||      k(  nc |       | j	                  t        j                  d
|             | j	                  t        j                  d
|             | j	                  t        j                  d|             | j	                  t        j                  d|             | j	                  t        j                  d|             | j	                  t        j                  d|             |dk(  sd||
<    t        t        j                  dz         D ]Z  }t        |      }||v r| j	                  | ||      cxk(  xr'  ||      cxk(  xr  ||      cxk(  xr  ||      k(  nc |       \ y c c}	w )Nc                 .    t        j                  d|       S )Nr   r=   r   rL   s    r4   r   z6NormalizationTest.run_normalization_tests.<locals>.NFC{      ((44r6   c                 .    t        j                  d|       S )NNFKCr   r   s    r4   r   z7NormalizationTest.run_normalization_tests.<locals>.NFKC~      ((55r6   c                 .    t        j                  d|       S )NNFDr   r   s    r4   r   z6NormalizationTest.run_normalization_tests.<locals>.NFD  r   r6   c                 .    t        j                  d|       S )NNFKDr   r   s    r4   r   z7NormalizationTest.run_normalization_tests.<locals>.NFKD  r   r6   #r   z@Part;rC   r   r   r   r   z@Part1r   )r   strip
startswithr   r   r=   is_normalizedr   r   r   r   )r.   r   part
part1_datar   r   r   r   liner`   c1c2c3c4c5r   Xs                    r4   r   z)NormalizationTest.run_normalization_testsw  s   
	5	6	5	6  "	#Dd{zz#q)::<Dw'zz|A6:jjocr6JKdkk!nKNBr"R OOB3r7Bs2wB3r7BDIOOB3r76s2w6=OOB3r7Bs2wB3r7BDIOOB3r76s2w6=OOB$r( =d2h = H=(,R=48H= " OOB$r( =d2h = H=(,R=48H= " OOK55eR@AOOK55eR@AOOK55eR@AOOK55eR@AOOK55fbABOOK55fbAB x!"
2E"	#J s~~a'( 	LAAAJOOAQG3q6GT!WGQGK		L9 Ls   =M=c                     | j                  t        t        j                         | j                  t        t        j                  dd       | j                  t        j                  dd      d       y )Nunknownr_   r   r   )ra   rb   r=   r   rc   r,   rd   s    r4   test_edge_casesz!NormalizationTest.test_edge_cases  sO    )[%:%:;*k&;&;YM..vr:B?r6   c                 0    t        j                  dd       y )Nr   u   한글r   rd   s    r4   test_bug_834676z!NormalizationTest.test_bug_834676  s    e^4r6   N)r7   r8   r9   staticmethodr   r   r   r   r   r  r  r:   r6   r4   r   r   Y  s`    2 2 / / y!u3  "3"9Lv@
5r6   r   __main__)__doc__r   http.clientr   r   r=   unittesttest.supportr   r   r   r   r   TestCaser
   r<   r@   r   r   r7   mainr:   r6   r4   <module>r     s     % 
  F F/8** /8b(++ uB. uBnZJ) ZJx`5)) `5F zHMMO r6   