o
    HXhHq                     @   s   d dl Z 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G dd dejZG dd deZedkrle  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   7/opt/python-3.10.19/usr/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#  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vsignprefix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   rW   rX   r   rY   r[   r   r   r\      r]   Z1_00r   r	   Z0_100r   s   1_00Z_100z+_100Z1__00Z100_)	r   anyrF   rG   evalreplacer   rM   rI   rO   r   r[   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)assertIsrG   rb   r   r   r   test_small_ints   s   zIntTestCases.test_small_intsc                 C   s   |  t d d S )Nr   rF   rG   rb   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?)rU   )rU   rj   r   r   )rF   rG   assertRaisesRegexrN   rM   rb   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$      ri   )rF   rG   rM   rI   rangerO   rj   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      @)rM   rN   rG   rb   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    n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 rX   value)rO   ru   r   r   r   __init__  s   
zBIntTestCases.test_int_base_indexable.<locals>.MyIndexable.__init__c                 S   s   | j S rX   rt   rb   r   r   r   	__index__     zCIntTestCases.test_int_base_indexable.<locals>.MyIndexable.__index__N)r   r   r   rv   rw   r   r   r   r   MyIndexable      ry   r$   r   r   rm   Z43Z101ri   r*   r   e   rD   i  )objectrM   rI   rG   rF   )rO   ry   rj   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    n1 sw   Y  qAd S )Nc                   @   r   )z<IntTestCases.test_non_numeric_input_types.<locals>.CustomStrNr   r   r   r   r   	CustomStr.      r~   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   CustomByteArray0  r   r   c                    s    |   S rX   )decodeb)r~   r   r   <lambda>5  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appendsubTesttyperF   rG   
isinstancerk   rN   rI   )rO   r   r   Z	factoriesfrU   msgr   )r~   r   r   test_non_numeric_input_types+  sB   
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   r7      123 s   123 s   123As   1234)rF   rG   r   rb   r   r   r   test_int_memoryviewN  s
    z IntTestCases.test_int_memoryviewc                 C   s   |  ttd d S )Nz1.2)rM   rI   rG   rb   r   r   r   test_string_floatU  rh   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    n	1 s$w   Y  qq:d S )"Nc                   @   r   )z>IntTestCases.test_intconversion.<locals>.ClassicMissingMethodsNr   r   r   r   r   ClassicMissingMethodsZ  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   rb   r   r   r   __int__c     z5IntTestCases.test_intconversion.<locals>.Foo0.__int__Nr   r   r   r   r   r   r   r   Foo0b      r   r   c                   @   r   )z0IntTestCases.test_intconversion.<locals>.ClassicNr   r   r   r   r   Classich  r   r   c                   @   rs   )z:IntTestCases.test_intconversion.<locals>.IntOverridesTruncc                 S   r   r   r   rb   r   r   r   r   l  r   zBIntTestCases.test_intconversion.<locals>.IntOverridesTrunc.__int__c                 S   r   )Nir   rb   r   r   r   	__trunc__n  r   zDIntTestCases.test_intconversion.<locals>.IntOverridesTrunc.__trunc__N)r   r   r   r   r   r   r   r   r   IntOverridesTrunck  rz   r   c                   @   r   )z2IntTestCases.test_intconversion.<locals>.JustTruncc                 S   r   r   r   rb   r   r   r   r   s  r   z<IntTestCases.test_intconversion.<locals>.JustTrunc.__trunc__Nr   r   r   r   r   r   r   r   	JustTruncr  r   r   c                   @   r   )z9IntTestCases.test_intconversion.<locals>.ExceptionalTruncc                 S   s   dd  d S )Nr   r   r   rb   r   r   r   r   x  s   zCIntTestCases.test_intconversion.<locals>.ExceptionalTrunc.__trunc__Nr   r   r   r   r   ExceptionalTruncw  r   r   c                   @   r   )z.IntTestCases.test_intconversion.<locals>.Indexc                 S   r   r   r   rb   r   r   r   rw     r   z8IntTestCases.test_intconversion.<locals>.Index.__index__Nr   r   r   rw   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 rX   r   rb   r   r   r   r     rx   zEIntTestCases.test_intconversion.<locals>.TruncReturnsNonInt.__trunc__Nr   r   r   r   r   TruncReturnsNonInt      r   c                   @   r   )z0IntTestCases.test_intconversion.<locals>.Intablec                 S   r   r   r   rb   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   rX   r   rb   r   r   r   r     rx   zGIntTestCases.test_intconversion.<locals>.TruncReturnsNonIndex.__trunc__Nr   r   r   r   r   TruncReturnsNonIndex  r   r   c                       r   )z4IntTestCases.test_intconversion.<locals>.NonIntegralc                    r   rX   r   rb   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   rX   r   rb   r   r   r   r     rx   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   rb   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   rX   r   rb   r   r   r   r     rx   zEIntTestCases.test_intconversion.<locals>.TruncReturnsBadInt.__trunc__Nr   r   r   r   r   TruncReturnsBadInt  r   r   )rM   rN   rG   r|   rF   ZeroDivisionErrorr   Zfail)rO   r   r   r   r   rj   r   r   r   Ztrunc_result_baser   r   r   er   r   )r   r   r   r   r   test_intconversionX  sX   
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   rb   r   r   r   rw     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   rb   r   r   r   rw     r   zEIntTestCases.test_int_subclass_with_index.<locals>.BadIndex.__index__Nr   r   r   r   r   BadIndex  r   r   r,   r   )rG   rF   )rO   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   rb   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   rb   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   )rG   rF   rM   rN   )rO   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   rb   r   r   r   rw     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   rb   r   r   r   rw     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   rb   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   rb   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   rX   r   rb   r   r   r   r     rx   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   rX   r   rb   r   r   r   r     rx   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   rb   r   r   r   r     r   zUIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsIntSubclass.__trunc__Nr   r   r   r   r   TruncReturnsIntSubclass  r   r   r   r   )	rG   ZassertWarnsDeprecationWarningrF   rd   r   rM   rN   r   )	rO   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   )rM   rI   rG   rF   	exceptionargs)rP   rj   cmrb   r   r   check  s   


z.IntTestCases.test_error_message.<locals>.check   ½u   123½z  123 456  z123 r   z123  245r4   r   z123 245r   s   123u   123rX   r   )rO   r   r   rb   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2Drf   rb   r   r   r   test_issue316194  s   zIntTestCases.test_issue31619N)r   r   r   rV   rc   r   Zcpython_onlyre   rg   rl   rq   rr   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   !   s(     8

#VE!r   c                       s   e Zd ZeZ fddZ fddZdd Zdd Z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  ZS )IntStrDigitLimitsTestsc                    s"   t    t | _td d S )Ni   )supersetUprK   get_int_max_str_digits_previous_limitset_int_max_str_digitsrb   	__class__r   r   r   @  s   

zIntStrDigitLimitsTests.setUpc                    s   t | j t   d S rX   )rK   r   r   r   tearDownrb   r   r   r   r   E  s   zIntStrDigitLimitsTests.tearDownc                 C   s   |  t d | t d td | t d | dd }t| W d    n1 s3w   Y  |  t d d S )Nr   i N  r   )	ZassertGreaterrK   r   
assertLessr   adjust_int_max_str_digitsrF   	int_classr   )rO   ir   r   r   test_disabled_limitI  s   
z*IntStrDigitLimitsTests.test_disabled_limitc                 C   sz   | j }t }|d|  |dd|   |d| d  |dd|   |dd|   | ttd|d  | dS )z&Ignore the +/- sign and space padding.r   r   r    r!   r   r   N)r   rK   r   rF   lenr   )rO   r   	maxdigitsr   r   r   test_max_str_digits_edge_casesR  s    z5IntStrDigitLimitsTests.test_max_str_digits_edge_casesNc                 C   s`   |  t! |d u r| | n| || W d    d S W d    d S 1 s)w   Y  d S rX   )rM   rI   r   )rO   r   rj   r   r   r   r   ^  s   "zIntStrDigitLimitsTests.checkc                 C   s   t  }| d|d   | dd|d    | d|d  d  | dd|d    | dd|d    | d|d   d| }| t t| W d    d S 1 s[w   Y  d S )Nr   r   r   r    r!   r   )rK   r   r   rM   rI   r   )rO   r   r   r   r   r   test_max_str_digitse  s   
"z*IntStrDigitLimitsTests.test_max_str_digitsc              	   C   s  t  }|dk sJ |tj}| dkrtj}tddd  dd}d}t| | }t|}W d	   n1 s;w   Y  | | }| 	t
|| |d
k rZtd| dttd| ) | t}| }t| W d	   n1 s{w   Y  | | }	W d	   n1 sw   Y  | dt|j | |	|d  tddd  dd}
| t}| }t|
 W d	   n1 sw   Y  | | }| dt|j | ||d  d	S )?Regression test: ensure we fail before performing O(N**2) work.iP  r   r'   ci  r   ri   i1 N      ?"slow" conversion took only 	 seconds.gףp=
?
conversionr$   i  )rK   r   timeprocess_time	monotonicrG   r   r   r   rF   r   unittestSkipTestrM   rI   assertInr   assertLessEqualr   )rO   r   get_timeZhuge_intdigitsstartZhuge_decimalseconds_to_converterrseconds_to_fail_hugeZextra_huge_intseconds_to_fail_extra_huger   r   r   +test_denial_of_service_prevented_int_to_strs  sD   






zBIntStrDigitLimitsTests.test_denial_of_service_prevented_int_to_strc              	   C   s  t  }|dk sJ |tj}| dkrtj}d}d| }t| | }t| W d   n1 s4w   Y  | | }|dk rKt	d| dt|d	 ) | 
t}| }t| W d   n1 sjw   Y  | | }W d   n1 s~w   Y  | d
t|j | ||d  dd }	| 
t}| }t|	 W d   n1 sw   Y  | | }
| d
t|j | |
|d  dS )r   順 r   iD
 8Nr   r   r   r   r   r$   7iO )rK   r   r   r   r   r   r   rG   r   r   rM   rI   r   r   r   r   )rO   r   r   r   Zhuger   r   r   r   Z
extra_huger   r   r   r   +test_denial_of_service_prevented_str_to_int  sB   






zBIntStrDigitLimitsTests.test_denial_of_service_prevented_str_to_intc              	   C   sr   t  }dD ]0}| j|d  | d|d  | |dk sJ | dd | W d   n1 s1w   Y  qdS )z-The limit does not apply to power of 2 bases.)r$   r)   r(   r   r@   ri   r   r   r   N)rK   r   r   r   )rO   r   rj   r   r   r   !test_power_of_two_bases_unlimited  s   z8IntStrDigitLimitsTests.test_power_of_two_bases_unlimitedc                 C   sX   t  }|d }d| }d| }| | | | | | d | | d d S )Nr   Z111Z1_11Z_111)rK   r   r   r   )rO   r   ZtriplesrP   Zs_r   r   r   test_underscores_ignored  s   

z/IntStrDigitLimitsTests.test_underscores_ignoredc                 C   sh   | j }t }d| }||}|d| }||ksJ |d| }| |ks*J t| t| d S )N5r    r!   )r   rK   r   r   )rO   r   
max_digitsrP   r   Zpos_iZneg_ir   r   r   test_sign_not_counted  s   z,IntStrDigitLimitsTests.test_sign_not_countedc                 C   s   | j }t }d| }|||}|dkr.| t t| W d    n1 s(w   Y  n|dk r6t| | t}|| d| W d    d S 1 sOw   Y  d S )N2r   r   )r   rK   r   rM   rI   r   )rO   rj   r   r  rP   r   r   r   r   r   _other_base_helper  s   

"z)IntStrDigitLimitsTests._other_base_helperc                 C   sz   d}| j |d | | W d    n1 sw   Y  d}| j |d | | W d    d S 1 s6w   Y  d S )Nr   ri   rD   )r   r  rp   r   r   r   test_int_from_other_bases  s   "z0IntStrDigitLimitsTests.test_int_from_other_basesrX   )r   r   r   rG   r   r   r   r   r   r   r   r   r   r   r   r  r  r  __classcell__r   r   r   r   r   <  s    	
+(
r   c                   @   s   e Zd ZeZdS )IntSubclassStrDigitLimitsTestsN)r   r   r   r   r   r   r   r   r   r    s    r  __main__)rK   r   r   testr   Ztest.test_grammarr   r   rJ   rL   rI   rH   rG   r   ZTestCaser   r   r  r   mainr   r   r   r   <module>   sH         B