o
    gR                     @   s   d dl Z d dlZd dlmZ d dlmZmZ dddddd	d
dddee je jfde	fdde	fde	fde	fde	fde	fgZ
G dd deZG dd dejZedkrWe  dS dS )    N)support)VALID_UNDERSCORE_LITERALSINVALID_UNDERSCORE_LITERALS)0r   )1   )9	   )10
   )Z99c   )100d   )Z314:  )z 314r   )z314 r   )z  		  314  		  r   z  1x)z  1  r   z  1      		  u   Ȁc                   @      e Zd ZdS )IntSubclassN__name__
__module____qualname__ r   r   C/Users/admin/.pyenv/versions/3.10.0/lib/python3.10/test/test_int.pyr          r   c                   @   s   e Zd Zdd Zdd Zej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!d" Zd#S )$IntTestCasesc                 C   sB	  |  tdd |  tdd |  tdd |  tdd |  tdd |  tdd |  td	d |  td
d |  tdd |  tdd |  tddd tD ]4\}}dD ]-}dD ](}|| | }|}|dkrz|turz| }z
|  t|| W qe ty   Y qew qaq[tdtj }t|}|  |d tj  | |t |  t|dd  tjd  td}| |t td}| |t dtj }|  |d? |d  td}| |t | t	tdd |  tddd |  tddd | ttdd | ttdd | ttdd  | ttdd | ttd!d | ttd!d |  td"dd# |  td$dd# |  td%d&d# |  td'd(d# |  td)d*d# |  td+d,d# |  td-d d# |  td.d/d# |  td0d1d# |  td2d3d# |  td4dd# |  td5d6d# |  td7d8d# |  td9d:d# |  td;dd# |  td<d=d# |  td>d?d# |  td@dAd# |  tdBdCd# |  tdDdEd# |  tdFdGd# |  tdHdId# |  tdJdKd# |  tdLdMd# |  tdNdOd# |  tdPdQd# |  tdRdSd# |  tdTdUd# |  tdVdWd# |  tdXdYd# |  tdZd[d# |  td\d]d# |  td^d_d# |  td`dad# |  tdbdcd# |  tdddd |  tdddd |  tdedd |  tddd |  tddd |  tdfdd& |  tdgdd |  tdhdd |  tdidd& |  tdjdk |  tdjd1dk |  tddd |  tdd d |  tdfdd& |  tdldd |  tdmd d |  tdndd& | ttdod | ttdpd | ttdqd | ttdrd | ttdsd  | ttdtd  | ttdud  | ttdvd  | ttdwd | ttdxd | ttdyd | ttdzd |  td{dd| |  td}dd| |  td~d&d| |  tdd(d| |  tdd*d| |  tdd,d| |  tdd d| |  tdd/d| |  tdd1d| |  tdd3d| |  tddd| |  tdd6d| |  tdd8d| |  tdd:d| |  tddd| |  tdd=d| |  tdd?d| |  tddAd| |  tddCd| |  tddEd| |  tddGd| |  tddId| |  tddKd| |  tddMd| |  tddOd| |  tddQd| |  tddSd| |  tddUd| |  tddWd| |  tddYd| |  tdd[d| |  tdd]d| |  tdd_d| |  tddad| |  tddcd| d S )Nr   gQ	@   gQ	g333333@g333333g      @g      z-3z -3 u    -3 r
      )r   +-)r   r   	r   r!   r   g}Ô%ITg}Ô%I   AX  111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111   Z0o123r   S   Z0x123i#  Z0xZ0o   Z0bZ!100000000000000000000000000000000l        Z102002022201221111211Z10000000000000000   Z32244002423141   Z1550104015504   Z211301422354   Z40000000000Z12068657454r	   Z
4294967296r   Z
1904440554   Z	9ba461594Z	535a79889   Z	2ca5b7464   Z	1a20dcd81   Z	100000000Za7ffda91   Z704he7g4   Z4f5aff66   Z3723ai4g   Z281d55i4   Z1fj8b184   Z1606k7ic   Zmb994ag   Zhek2mgl   Zdnchbnm   Zb28jpdm   Z8pfgih4   Z76beigg   Z5qmcpqg   Z4q0jto4   Z4000000    Z3aokq94!   Z2qhxjli"   Z2br45qb#   Z1z141z4$   z 0o123  Z000Z0b100z	 0O123   z 0X123  z 0B100 Z0123{   Z0X123Z0O123Z0B100Z0b2Z0b02Z0B2Z0B02Z0o8Z0o08Z0O8Z0O08Z0xgZ0x0gZ0XgZ0X0gZ!100000000000000000000000000000001l       Z102002022201221111212Z10000000000000001Z32244002423142Z1550104015505Z211301422355Z40000000001Z12068657455Z
4294967297Z
1904440555Z	9ba461595Z	535a7988aZ	2ca5b7465Z	1a20dcd82Z	100000001Za7ffda92Z704he7g5Z4f5aff67Z3723ai4hZ281d55i5Z1fj8b185Z1606k7idZmb994ahZhek2mgmZdnchbnnZb28jpdnZ8pfgih5Z76beighZ5qmcpqhZ4q0jto5Z4000001Z3aokq95Z2qhxjljZ2br45qcZ1z141z5)
assertEqualintL
ValueErrorreprsysmaxsizeZassertIsInstanceassertRaises	TypeError)selfsvZsignprefixZssZvvxr   r   r   
test_basic"   s$  
zIntTestCases.test_basicc              	      s   t D ]) t fdddD rq| t dt  | t dt ddd qtD ] t fdddD r<q.| tt d q.| tdd	d
 | tdd | tdd | ttd | ttd | ttd | ttd d S )Nc                 3       | ]}| v V  qd S Nr   .0ZchZlitr   r   	<genexpr>       z0IntTestCases.test_underscores.<locals>.<genexpr>z.eEjJr   _r   c                 3   rT   rU   r   rV   rX   r   r   rY      rZ   Z1_00r   r	   Z0_100r   s   1_00Z_100z+_100Z1__00Z100_)	r   anyrE   rF   evalreplacer   rL   rH   rN   r   rX   r   test_underscores   s    "zIntTestCases.test_underscoresc                 C   sD   |  tdd |  tdd |  tdd |  tdd d S )Nr
   r   z-1r#   s   10s   -1)assertIsrF   r_   r   r   r   test_small_ints   s   zIntTestCases.test_small_intsc                 C   s   |  t d d S )Nr   rE   rF   r_   r   r   r   test_no_args      zIntTestCases.test_no_argsc                 C   s   |  tdddd | td tdd W d    n1 s w   Y  | td tddd W d    n1 s<w   Y  | jttd	d | jttd
d d S )Nr   r$   baser(   zkeyword argumentg333333?)rR   )rR   rg   r   r   )rE   rF   assertRaisesRegexrM   rL   r_   r   r   r   test_keyword_args   s   zIntTestCases.test_keyword_argsc                 C   sN  |  tddd | t tdd W d   n1 sw   Y  | t tdd W d   n1 s8w   Y  | t tdd W d   n1 sRw   Y  | t tdddd	  d
 W d   n1 sqw   Y  | t tddd	 d
 W d   n1 sw   Y  tddD ]}|  td|d
d qdS )z9Testing the supported limits of the int() base parameter.r   r)   r   r   N%   isr$      rf   )rE   rF   rL   rH   range)rN   rg   r   r   r   test_int_base_limits  s&   z!IntTestCases.test_int_base_limitsc                 C   sn   |  t tdd W d   n1 sw   Y  |  t tdd W d   dS 1 s0w   Y  dS )z2Not integer types are not valid bases; issue16772.r   g      @Ng      @)rL   rM   rF   r_   r   r   r   test_int_base_bad_types  s   "z$IntTestCases.test_int_base_bad_typesc              	   C   s   G dd dt }dd dd  ddfD ]}| t td| W d    q1 s*w   Y  q| td|dd	d
 | td|dd	d | td|dd	d d S )Nc                   @      e Zd Zdd Zdd ZdS )z9IntTestCases.test_int_base_indexable.<locals>.MyIndexablec                 S   s
   || _ d S rU   value)rN   rq   r   r   r   __init__  s   
zBIntTestCases.test_int_base_indexable.<locals>.MyIndexable.__init__c                 S   s   | j S rU   rp   r_   r   r   r   	__index__     zCIntTestCases.test_int_base_indexable.<locals>.MyIndexable.__index__N)r   r   r   rr   rs   r   r   r   r   MyIndexable      ru   r$   r   r   rj   Z43Z101rf   r)   r   e   rC   i  )objectrL   rH   rF   rE   )rN   ru   rg   r   r   r   test_int_base_indexable  s   z$IntTestCases.test_int_base_indexablec              
      sh  G dd dt  G dd dt}G dd dt}tt fdd||tg}zd	d
lm W n	 ty5   Y n
w |fdd |D ]p}|d}| t|[ | 	t
|d t|t ttfri| 	t
|dd nd}| t| t
|d W d    n1 sw   Y  | td t
|d W d    n1 sw   Y  W d    qA1 sw   Y  qAd S )Nc                   @   r   )z<IntTestCases.test_non_numeric_input_types.<locals>.CustomStrNr   r   r   r   r   	CustomStr-      rz   c                   @   r   )z>IntTestCases.test_non_numeric_input_types.<locals>.CustomBytesNr   r   r   r   r   CustomBytes.  r{   r|   c                   @   r   )zBIntTestCases.test_non_numeric_input_types.<locals>.CustomByteArrayNr   r   r   r   r   CustomByteArray/  r{   r}   c                    s    |   S rU   )decodeb)rz   r   r   <lambda>4  r{   z;IntTestCases.test_non_numeric_input_types.<locals>.<lambda>r   arrayc                    s
    d| S )NBr   r   r   r   r   r   >  s   
 s   100r   r$   r(   zcan't convert non-stringzinvalid literals   AAAAAAAAAAAAAAAA)strbytes	bytearray
memoryviewr   ImportErrorappendZsubTesttyperE   rF   
isinstancerh   rM   rH   )rN   r|   r}   Z	factoriesfrR   msgr   )rz   r   r   test_non_numeric_input_types*  s@   
z)IntTestCases.test_non_numeric_input_typesc                 C   s   |  ttddd d |  ttddd d |  ttddd d |  ttddd d |  ttddd d d S )	Ns   123r   r   r6      123 s   123 s   123As   1234)rE   rF   r   r_   r   r   r   test_int_memoryviewM  s
    z IntTestCases.test_int_memoryviewc                 C   s   |  ttd d S )Nz1.2)rL   rH   rF   r_   r   r   r   test_string_floatT  re   zIntTestCases.test_string_floatc                    sZ  G dd d}|  tt|  G dd dt}|  tt|  G dd d}| t| d G dd	 d	}t|fD ]}G d
d d|}| t| d G dd d|}| t| d G dd d|}|  t t|  W d    n1 s{w   Y  t|fD ]}	G dd d|	G fddd|}
| t|
 d G dd d|	G fddd|}| t|
 d G fddd|	G fddd|}zt|  W n ty } z| t|d W Y d }~nd }~ww | d||	ff  G dd d|	 G  fd d!d!|}|  t t|  W d    q1 s$w   Y  qq:d S )"Nc                   @   r   )z>IntTestCases.test_intconversion.<locals>.ClassicMissingMethodsNr   r   r   r   r   ClassicMissingMethodsY  r   r   c                   @   r   )z7IntTestCases.test_intconversion.<locals>.MissingMethodsNr   r   r   r   r   MissingMethods]  r   r   c                   @      e Zd Zdd ZdS )z-IntTestCases.test_intconversion.<locals>.Foo0c                 S      dS N*   r   r_   r   r   r   __int__b     z5IntTestCases.test_intconversion.<locals>.Foo0.__int__Nr   r   r   r   r   r   r   r   Foo0a      r   r   c                   @   r   )z0IntTestCases.test_intconversion.<locals>.ClassicNr   r   r   r   r   Classicg  r   r   c                   @   ro   )z:IntTestCases.test_intconversion.<locals>.IntOverridesTruncc                 S   r   r   r   r_   r   r   r   r   k  r   zBIntTestCases.test_intconversion.<locals>.IntOverridesTrunc.__int__c                 S   r   )Nir   r_   r   r   r   	__trunc__m  r   zDIntTestCases.test_intconversion.<locals>.IntOverridesTrunc.__trunc__N)r   r   r   r   r   r   r   r   r   IntOverridesTruncj  rv   r   c                   @   r   )z2IntTestCases.test_intconversion.<locals>.JustTruncc                 S   r   r   r   r_   r   r   r   r   r  r   z<IntTestCases.test_intconversion.<locals>.JustTrunc.__trunc__Nr   r   r   r   r   r   r   r   	JustTruncq  r   r   c                   @   r   )z9IntTestCases.test_intconversion.<locals>.ExceptionalTruncc                 S   s   dd  d S )Nr   r   r   r_   r   r   r   r   w  s   zCIntTestCases.test_intconversion.<locals>.ExceptionalTrunc.__trunc__Nr   r   r   r   r   ExceptionalTruncv  r   r   c                   @   r   )z.IntTestCases.test_intconversion.<locals>.Indexc                 S   r   r   r   r_   r   r   r   rs   ~  r   z8IntTestCases.test_intconversion.<locals>.Index.__index__Nr   r   r   rs   r   r   r   r   Index}  r   r   c                          e Zd Z fddZdS )z;IntTestCases.test_intconversion.<locals>.TruncReturnsNonIntc                         S rU   r   r_   r   r   r   r     rt   zEIntTestCases.test_intconversion.<locals>.TruncReturnsNonInt.__trunc__Nr   r   r   r   r   TruncReturnsNonInt      r   c                   @   r   )z0IntTestCases.test_intconversion.<locals>.Intablec                 S   r   r   r   r_   r   r   r   r     r   z8IntTestCases.test_intconversion.<locals>.Intable.__int__Nr   r   r   r   r   Intable  r   r   c                       r   )z=IntTestCases.test_intconversion.<locals>.TruncReturnsNonIndexc                    r   rU   r   r_   r   r   r   r     rt   zGIntTestCases.test_intconversion.<locals>.TruncReturnsNonIndex.__trunc__Nr   r   r   r   r   TruncReturnsNonIndex  r   r   c                       r   )z4IntTestCases.test_intconversion.<locals>.NonIntegralc                    r   rU   r   r_   NonIntegralr   r   r     s   z>IntTestCases.test_intconversion.<locals>.NonIntegral.__trunc__Nr   r   r   r   r   r     r   r   c                       r   )z@IntTestCases.test_intconversion.<locals>.TruncReturnsNonIntegralc                    r   rU   r   r_   r   r   r   r     rt   zJIntTestCases.test_intconversion.<locals>.TruncReturnsNonIntegral.__trunc__Nr   r   r   r   r   TruncReturnsNonIntegral  r   r   z2__trunc__ returned non-Integral (type NonIntegral)z!Failed to raise TypeError with %sc                   @   r   )z/IntTestCases.test_intconversion.<locals>.BadIntc                 S   r   Ng      E@r   r_   r   r   r   r     r   z7IntTestCases.test_intconversion.<locals>.BadInt.__int__Nr   r   r   r   r   BadInt  r   r   c                       r   )z;IntTestCases.test_intconversion.<locals>.TruncReturnsBadIntc                    r   rU   r   r_   r   r   r   r     rt   zEIntTestCases.test_intconversion.<locals>.TruncReturnsBadInt.__trunc__Nr   r   r   r   r   TruncReturnsBadInt  r   r   )rL   rM   rF   rx   rE   ZeroDivisionErrorr   Zfail)rN   r   r   r   r   rg   r   r   r   Ztrunc_result_baser   r   r   er   r   )r   r   r   r   r   test_intconversionW  sV   
 zIntTestCases.test_intconversionc                 C   sZ   G dd dt }G dd dt }|d}| |d | t |d | t | d d S )Nc                   @   r   )z:IntTestCases.test_int_subclass_with_index.<locals>.MyIndexc                 S   r   r   r   r_   r   r   r   rs     r   zDIntTestCases.test_int_subclass_with_index.<locals>.MyIndex.__index__Nr   r   r   r   r   MyIndex  r   r   c                   @   r   )z;IntTestCases.test_int_subclass_with_index.<locals>.BadIndexc                 S   r   r   r   r_   r   r   r   rs     r   zEIntTestCases.test_int_subclass_with_index.<locals>.BadIndex.__index__Nr   r   r   r   r   BadIndex  r   r   r+   r   )rF   rE   )rN   r   r   my_intr   r   r   test_int_subclass_with_index  s   z)IntTestCases.test_int_subclass_with_indexc                 C   sj   G dd dt }G dd dt }|d}| |d | t |d |d}| |d | tt | d S )Nc                   @   r   )z6IntTestCases.test_int_subclass_with_int.<locals>.MyIntc                 S   r   r   r   r_   r   r   r   r     r   z>IntTestCases.test_int_subclass_with_int.<locals>.MyInt.__int__Nr   r   r   r   r   MyInt  r   r   c                   @   r   )z7IntTestCases.test_int_subclass_with_int.<locals>.BadIntc                 S   r   r   r   r_   r   r   r   r     r   z?IntTestCases.test_int_subclass_with_int.<locals>.BadInt.__int__Nr   r   r   r   r   r     r   r   r+   r   )rF   rE   rL   rM   )rN   r   r   r   r   r   r   test_int_subclass_with_int  s   z'IntTestCases.test_int_subclass_with_intc           	         sN  G dd d G dd dt }G dd dG dd dt }G  fd	d
d
}G fddd}G dd d}  }| t t |}W d    n1 sNw   Y  | |d | t|t  | }t |}| |d | t|t   }| t t |}W d    n1 sw   Y  | |d | t|t  | }| t t |}W d    n1 sw   Y  | |d | t|t  | }| t t |}W d    n1 sw   Y  | |d | t|t  | }| tt | | }t |}| |d | t|t  t|}| |d | t|t d S )Nc                   @   r   )z<IntTestCases.test_int_returns_int_subclass.<locals>.BadIndexc                 S   r   NTr   r_   r   r   r   rs     r   zFIntTestCases.test_int_returns_int_subclass.<locals>.BadIndex.__index__Nr   r   r   r   r   r     r   r   c                   @   r   )z=IntTestCases.test_int_returns_int_subclass.<locals>.BadIndex2c                 S   r   r   r   r_   r   r   r   rs     r   zGIntTestCases.test_int_returns_int_subclass.<locals>.BadIndex2.__index__Nr   r   r   r   r   	BadIndex2  r   r   c                   @   r   )z:IntTestCases.test_int_returns_int_subclass.<locals>.BadIntc                 S   r   r   r   r_   r   r   r   r     r   zBIntTestCases.test_int_returns_int_subclass.<locals>.BadInt.__int__Nr   r   r   r   r   r     r   r   c                   @   r   )z;IntTestCases.test_int_returns_int_subclass.<locals>.BadInt2c                 S   r   r   r   r_   r   r   r   r     r   zCIntTestCases.test_int_returns_int_subclass.<locals>.BadInt2.__int__Nr   r   r   r   r   BadInt2  r   r   c                       r   )zHIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsBadIndexc                    r   rU   r   r_   r   r   r   r     rt   zRIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsBadIndex.__trunc__Nr   r   r   r   r   TruncReturnsBadIndex  r   r   c                       r   )zFIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsBadIntc                    r   rU   r   r_   r   r   r   r     rt   zPIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsBadInt.__trunc__Nr   r   r   r   r   r     r   r   c                   @   r   )zKIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsIntSubclassc                 S   r   r   r   r_   r   r   r   r     r   zUIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsIntSubclass.__trunc__Nr   r   r   r   r   TruncReturnsIntSubclass  r   r   r   r   )	rF   ZassertWarnsDeprecationWarningrE   ra   r   rL   rM   r   )	rN   r   r   r   r   r   Zbad_intnZgood_intr   )r   r   r   test_int_returns_int_subclass  sX   



z*IntTestCases.test_int_returns_int_subclassc                    s   d f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 S )Nc                    s~    j td| |f d}|d u rt|  nt| | W d    n1 s$w   Y   |jjd d|d u r7dn|| f  d S )Nzint(%r, %r))r   r   z*invalid literal for int() with base %d: %rr   )rL   rH   rF   rE   	exceptionargs)rO   rg   cmr_   r   r   check  s   


z.IntTestCases.test_error_message.<locals>.check   ½u   123½z  123 456  z123 r   z123  245r3   r   z123 245r   s   123u   123rU   r   )rN   r   r   r_   r   test_error_message  s    






zIntTestCases.test_error_messagec                 C   sL   |  tddd |  tddd |  tddd	 |  td
dd d S )NZ=1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1_0_1r$   iUUUUZ1_2_3_4_5_6_7_0_1_2_3r'   iSpSZ1_2_3_4_5_6_7_8_9r   l   gF Z1_2_3_4_5_6_7r?   i2Drc   r_   r   r   r   test_issue316193  s   zIntTestCases.test_issue31619N)r   r   r   rS   r`   r   Zcpython_onlyrb   rd   ri   rm   rn   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r       s(     8

#VE!r   __main__)rJ   Zunittesttestr   Ztest.test_grammarr   r   rI   rK   rH   rG   rF   r   ZTestCaser   r   mainr   r   r   r   <module>   s@        