a
    zeq                     @   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re  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                   @   s   e Zd ZdS )IntSubclassN__name__
__module____qualname__ r   r   #/usr/lib/python3.9/test/test_int.pyr      s   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   sF	  |  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 ]l\}}dD ]^}dD ]T}|| | }|}|dkr|tur| }z|  t|| W q ty   Y q0 qqqt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 ]R 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 rxq\| 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   s   | ]}| v V  qd S Nr   .0ZchZlitr   r   	<genexpr>       z0IntTestCases.test_underscores.<locals>.<genexpr>z.eEjJr   _r   c                 3   s   | ]}| v V  qd S rU   r   rV   rX   r   r   rY      rZ   Z1_00r   r	   Z0_100r   s   1_00Z_100z+_100Z1__00Z100_)	r   anyrD   rE   evalreplacer   rK   rG   rM   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)assertIsrE   r_   r   r   r   test_small_ints   s    zIntTestCases.test_small_intsc                 C   s   |  t d d S )Nr   rD   rE   r_   r   r   r   test_no_args   s    zIntTestCases.test_no_argsc                 C   s   |  tdddd | td tdd W d    n1 s@0    Y  | td tddd W d    n1 sx0    Y  | jttd	d | jttd
d d S )Nr   r"   baser'   zkeyword argumentg333333?)rS   )rS   rf   r   r   )rD   rE   assertRaisesRegexrL   rK   r_   r   r   r   test_keyword_args   s    (*zIntTestCases.test_keyword_argsc                 C   sR  |  tddd | t tdd W d   n1 s<0    Y  | t tdd W d   n1 sp0    Y  | t tdd W d   n1 s0    Y  | t$ tdddd	  d
 W d   n1 s0    Y  | t  tddd	 d
 W d   n1 s0    Y  tddD ]}|  td|d
d q2dS )z9Testing the supported limits of the int() base parameter.r   r(   r   r   N%   isr"      re   )rD   rE   rK   rG   rangerM   rf   r   r   r   test_int_base_limits  s    (((20z!IntTestCases.test_int_base_limitsc                 C   sl   |  t tdd W d   n1 s*0    Y  |  t tdd W d   n1 s^0    Y  dS )z2Not integer types are not valid bases; issue16772.r   g      @Ng      @)rK   rL   rE   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 ]8}| t td| W d    q&1 sT0    Y  q&| td|dd	d
 | td|dd	d | td|dd	d d S )Nc                   @   s   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)rM   rp   r   r   r   __init__  s    zBIntTestCases.test_int_base_indexable.<locals>.MyIndexable.__init__c                 S   s   | j S rU   ro   r_   r   r   r   	__index__  s    zCIntTestCases.test_int_base_indexable.<locals>.MyIndexable.__index__N)r   r   r   rq   rr   r   r   r   r   MyIndexable  s   rs   r"   r   r   ri   Z43Z101re   r(   r   e   rB   i  )objectrK   rG   rE   rD   )rM   rs   rf   r   r   r   test_int_base_indexable  s    *z$IntTestCases.test_int_base_indexablec              
      sn  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yj   Y n0 |fdd |D ]}|d}| t| | 	t
|d t|t ttfr| 	t
|dd n<d}| t| t
|d W d    n1 s0    Y  | td t
|d W d    n1 s>0    Y  W d    q1 s^0    Y  qd S )Nc                   @   s   e Zd ZdS )z<IntTestCases.test_non_numeric_input_types.<locals>.CustomStrNr   r   r   r   r   	CustomStr.  rZ   rw   c                   @   s   e Zd ZdS )z>IntTestCases.test_non_numeric_input_types.<locals>.CustomBytesNr   r   r   r   r   CustomBytes/  rZ   rx   c                   @   s   e Zd ZdS )zBIntTestCases.test_non_numeric_input_types.<locals>.CustomByteArrayNr   r   r   r   r   CustomByteArray0  rZ   ry   c                    s    |   S rU   )decodeb)rw   r   r   <lambda>5  rZ   z;IntTestCases.test_non_numeric_input_types.<locals>.<lambda>r   arrayc                    s
    d| S )NBr   r{   r~   r   r   r}   ?  rZ   s   100r   r"   r'   zcan't convert non-stringzinvalid literals   AAAAAAAAAAAAAAAA)strbytes	bytearray
memoryviewr   ImportErrorappendsubTesttyperD   rE   
isinstancerg   rL   rG   )rM   rx   ry   Z	factoriesfrS   msgr   )rw   r   r   test_non_numeric_input_types+  s4    
*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   r5      123 s   123 s   123As   1234)rD   rE   r   r_   r   r   r   test_int_memoryviewN  s
    z IntTestCases.test_int_memoryviewc                 C   s   |  ttd d S )Nz1.2)rK   rG   rE   r_   r   r   r   test_string_floatU  s    zIntTestCases.test_string_floatc                    sb  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 s0    Y  t|fD ]N}	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 n6 ty } z| t|d W Y d }~nd }~0 0 | d||	ff  G dd d|	 G  fd d!d!|}|  t t|  W d    n1 sN0    Y  q
qtd S )"Nc                   @   s   e Zd ZdS )z>IntTestCases.test_intconversion.<locals>.ClassicMissingMethodsNr   r   r   r   r   ClassicMissingMethodsZ  s   r   c                   @   s   e Zd ZdS )z7IntTestCases.test_intconversion.<locals>.MissingMethodsNr   r   r   r   r   MissingMethods^  s   r   c                   @   s   e Zd Zdd ZdS )z-IntTestCases.test_intconversion.<locals>.Foo0c                 S   s   dS N*   r   r_   r   r   r   __int__c  s    z5IntTestCases.test_intconversion.<locals>.Foo0.__int__Nr   r   r   r   r   r   r   r   Foo0b  s   r   r   c                   @   s   e Zd ZdS )z0IntTestCases.test_intconversion.<locals>.ClassicNr   r   r   r   r   Classich  s   r   c                   @   s   e Zd Zdd Zdd ZdS )z:IntTestCases.test_intconversion.<locals>.IntOverridesTruncc                 S   s   dS r   r   r_   r   r   r   r   l  s    zBIntTestCases.test_intconversion.<locals>.IntOverridesTrunc.__int__c                 S   s   dS )Nir   r_   r   r   r   	__trunc__n  s    zDIntTestCases.test_intconversion.<locals>.IntOverridesTrunc.__trunc__N)r   r   r   r   r   r   r   r   r   IntOverridesTrunck  s   r   c                   @   s   e Zd Zdd ZdS )z2IntTestCases.test_intconversion.<locals>.JustTruncc                 S   s   dS r   r   r_   r   r   r   r   s  s    z<IntTestCases.test_intconversion.<locals>.JustTrunc.__trunc__Nr   r   r   r   r   r   r   r   	JustTruncr  s   r   c                   @   s   e Zd Zdd ZdS )z9IntTestCases.test_intconversion.<locals>.ExceptionalTruncc                 S   s   dd  d S )Nr   r   r   r_   r   r   r   r   x  s    zCIntTestCases.test_intconversion.<locals>.ExceptionalTrunc.__trunc__Nr   r   r   r   r   ExceptionalTruncw  s   r   c                   @   s   e Zd Zdd ZdS )z.IntTestCases.test_intconversion.<locals>.Indexc                 S   s   dS r   r   r_   r   r   r   rr     s    z8IntTestCases.test_intconversion.<locals>.Index.__index__Nr   r   r   rr   r   r   r   r   Index~  s   r   c                       s   e Zd Z fddZdS )z;IntTestCases.test_intconversion.<locals>.TruncReturnsNonIntc                    s     S rU   r   r_   r   r   r   r     s    zEIntTestCases.test_intconversion.<locals>.TruncReturnsNonInt.__trunc__Nr   r   r   r   r   TruncReturnsNonInt  s   r   c                   @   s   e Zd Zdd ZdS )z0IntTestCases.test_intconversion.<locals>.Intablec                 S   s   dS r   r   r_   r   r   r   r     s    z8IntTestCases.test_intconversion.<locals>.Intable.__int__Nr   r   r   r   r   Intable  s   r   c                       s   e Zd Z fddZdS )z=IntTestCases.test_intconversion.<locals>.TruncReturnsNonIndexc                    s     S rU   r   r_   r   r   r   r     s    zGIntTestCases.test_intconversion.<locals>.TruncReturnsNonIndex.__trunc__Nr   r   r   r   r   TruncReturnsNonIndex  s   r   c                       s   e Zd Z fddZdS )z4IntTestCases.test_intconversion.<locals>.NonIntegralc                    s     S rU   r   r_   NonIntegralr   r   r     s    z>IntTestCases.test_intconversion.<locals>.NonIntegral.__trunc__Nr   r   r   r   r   r     s   r   c                       s   e Zd Z fddZdS )z@IntTestCases.test_intconversion.<locals>.TruncReturnsNonIntegralc                    s     S rU   r   r_   r   r   r   r     s    zJIntTestCases.test_intconversion.<locals>.TruncReturnsNonIntegral.__trunc__Nr   r   r   r   r   TruncReturnsNonIntegral  s   r   z2__trunc__ returned non-Integral (type NonIntegral)z!Failed to raise TypeError with %sc                   @   s   e Zd Zdd ZdS )z/IntTestCases.test_intconversion.<locals>.BadIntc                 S   s   dS Ng      E@r   r_   r   r   r   r     s    z7IntTestCases.test_intconversion.<locals>.BadInt.__int__Nr   r   r   r   r   BadInt  s   r   c                       s   e Zd Z fddZdS )z;IntTestCases.test_intconversion.<locals>.TruncReturnsBadIntc                    s     S rU   r   r_   r   r   r   r     s    zEIntTestCases.test_intconversion.<locals>.TruncReturnsBadInt.__trunc__Nr   r   r   r   r   TruncReturnsBadInt  s   r   )rK   rL   rE   ru   rD   ZeroDivisionErrorr   Zfail)rM   r   r   r   r   rf   r   r   r   Ztrunc_result_baser   r   r   er   r   )r   r   r   r   r   test_intconversionX  sJ    (
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                   @   s   e Zd Zdd ZdS )z:IntTestCases.test_int_subclass_with_index.<locals>.MyIndexc                 S   s   dS r   r   r_   r   r   r   rr     s    zDIntTestCases.test_int_subclass_with_index.<locals>.MyIndex.__index__Nr   r   r   r   r   MyIndex  s   r   c                   @   s   e Zd Zdd ZdS )z;IntTestCases.test_int_subclass_with_index.<locals>.BadIndexc                 S   s   dS r   r   r_   r   r   r   rr     s    zEIntTestCases.test_int_subclass_with_index.<locals>.BadIndex.__index__Nr   r   r   r   r   BadIndex  s   r   r*   r   )rE   rD   )rM   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                   @   s   e Zd Zdd ZdS )z6IntTestCases.test_int_subclass_with_int.<locals>.MyIntc                 S   s   dS r   r   r_   r   r   r   r     s    z>IntTestCases.test_int_subclass_with_int.<locals>.MyInt.__int__Nr   r   r   r   r   MyInt  s   r   c                   @   s   e Zd Zdd ZdS )z7IntTestCases.test_int_subclass_with_int.<locals>.BadIntc                 S   s   dS r   r   r_   r   r   r   r     s    z?IntTestCases.test_int_subclass_with_int.<locals>.BadInt.__int__Nr   r   r   r   r   r     s   r   r*   r   )rE   rD   rK   rL   )rM   r   r   r   r   r   r   test_int_subclass_with_int  s    z'IntTestCases.test_int_subclass_with_intc           	         s  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 s0    Y  | |d | t|t  | }t |}| |d | t|t   }| t t |}W d    n1 s0    Y  | |d | t|t  | }| t t |}W d    n1 sr0    Y  | |d | t|t  | }| t t |}W d    n1 s0    Y  | |d | t|t  | }| t t |}W d    n1 s0    Y  | |d | t|t  | }t |}| |d | t|t  t|}| |d | t|t d S )Nc                   @   s   e Zd Zdd ZdS )z<IntTestCases.test_int_returns_int_subclass.<locals>.BadIndexc                 S   s   dS NTr   r_   r   r   r   rr     s    zFIntTestCases.test_int_returns_int_subclass.<locals>.BadIndex.__index__Nr   r   r   r   r   r     s   r   c                   @   s   e Zd Zdd ZdS )z=IntTestCases.test_int_returns_int_subclass.<locals>.BadIndex2c                 S   s   dS r   r   r_   r   r   r   rr     s    zGIntTestCases.test_int_returns_int_subclass.<locals>.BadIndex2.__index__Nr   r   r   r   r   	BadIndex2  s   r   c                   @   s   e Zd Zdd ZdS )z:IntTestCases.test_int_returns_int_subclass.<locals>.BadIntc                 S   s   dS r   r   r_   r   r   r   r     s    zBIntTestCases.test_int_returns_int_subclass.<locals>.BadInt.__int__Nr   r   r   r   r   r     s   r   c                   @   s   e Zd Zdd ZdS )z;IntTestCases.test_int_returns_int_subclass.<locals>.BadInt2c                 S   s   dS r   r   r_   r   r   r   r     s    zCIntTestCases.test_int_returns_int_subclass.<locals>.BadInt2.__int__Nr   r   r   r   r   BadInt2  s   r   c                       s   e Zd Z fddZdS )zHIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsBadIndexc                    s     S rU   r   r_   r   r   r   r     s    zRIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsBadIndex.__trunc__Nr   r   r   r   r   TruncReturnsBadIndex  s   r   c                       s   e Zd Z fddZdS )zFIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsBadIntc                    s     S rU   r   r_   r   r   r   r     s    zPIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsBadInt.__trunc__Nr   r   r   r   r   r     s   r   c                   @   s   e Zd Zdd ZdS )zKIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsIntSubclassc                 S   s   dS r   r   r_   r   r   r   r     s    zUIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsIntSubclass.__trunc__Nr   r   r   r   r   TruncReturnsIntSubclass  s   r   r   r   )rE   ZassertWarnsDeprecationWarningrD   ra   r   r   )	rM   r   r   r   r   r   Zbad_intnZgood_intr   )r   r   r   test_int_returns_int_subclass  sV    &((((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 sH0    Y   |jjd d|d u rndn|| f  d S )Nzint(%r, %r))r   r   z*invalid literal for int() with base %d: %rr   )rK   rG   rE   rD   	exceptionargs)rN   rf   cmr_   r   r   check  s    

(z.IntTestCases.test_error_message.<locals>.check   ½u   123½z  123 456  z123 r   z123  245r2   r   z123 245r   s   123u   123)Nr   )rM   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_issue316197  s    zIntTestCases.test_issue31619N)r   r   r   rT   r`   r   Zcpython_onlyrb   rd   rh   rm   rn   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r   !   s&    8

#VH!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setUprI   get_int_max_str_digits_previous_limitset_int_max_str_digitsr_   	__class__r   r   r   C  s    

zIntStrDigitLimitsTests.setUpc                    s   t | j t   d S rU   )rI   r   r   r   tearDownr_   r   r   r   r   H  s    zIntStrDigitLimitsTests.tearDownc                 C   s   |  t d | t d td6 | t d | dd }t| W d    n1 sf0    Y  |  t d d S )Nr   i N  r   )	ZassertGreaterrI   r   
assertLessr   adjust_int_max_str_digitsrD   	int_classr   )rM   ir   r   r   test_disabled_limitL  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   rI   r   rD   lenr   )rM   r   	maxdigitsr   r   r   test_max_str_digits_edge_casesU  s    z5IntStrDigitLimitsTests.test_max_str_digits_edge_casesNc                 C   sN   |  t0 |d u r | | n| || W d    n1 s@0    Y  d S rU   )rK   rG   r   )rM   r   rf   r   r   r   r   a  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    n1 s0    Y  d S )Nr   r   r   r   r   r   )rI   r   r   rK   rG   r   )rM   r   r   r   r   r   test_max_str_digitsh  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 sv0    Y  | | }| 	t
|| |d
k rtd| dttd| R | t}| }t| W d	   n1 s0    Y  | | }	W d	   n1 s 0    Y  | dt|j | |	|d  tddd  dd}
| t}| }t|
 W d	   n1 s0    Y  | | }| dt|j | ||d  d	S )?Regression test: ensure we fail before performing O(N**2) work.iP  r   r%   ci  r   re   i1 N      ?"slow" conversion took only 	 seconds.gףp=
?
conversionr"   i  )rI   r   timeprocess_time	monotonicrE   r   r   r   rD   r   unittestSkipTestrK   rG   assertInr   assertLessEqualr   )rM   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_strv  s<    
&

&*(
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 sh0    Y  | | }|dk rt	d| dt|d	 R | 
t}| }t| W d   n1 s0    Y  | | }W d   n1 s0    Y  | d
t|j | ||d  dd }	| 
t}| }t|	 W d   n1 s`0    Y  | | }
| d
t|j | |
|d  dS )r   順 r   iD
 8Nr   r   r   r   r   r"   7iO )rI   r   r   r   r   r   r   rE   r   r   rK   rG   r   r   r   r   )rM   r   r   r   Zhuger   r   r   r   Z
extra_huger   r   r   r   +test_denial_of_service_prevented_str_to_int  s:    
&

&((
zBIntStrDigitLimitsTests.test_denial_of_service_prevented_str_to_intc              	   C   sr   t  }dD ]`}| j|d@ | d|d  | |dk s>J | dd | W d   q1 sb0    Y  qdS )z-The limit does not apply to power of 2 bases.)r"   r'   r&   r   r>   re   r   r   r   N)rI   r   r   r   )rM   r   rf   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)rI   r   r   r   )rM   r   ZtriplesrN   Zs_r   r   r   test_underscores_ignored  s    

z/IntStrDigitLimitsTests.test_underscores_ignoredc                 C   sh   | j }t }d| }||}|d| }||ks8J |d| }| |ksTJ t| t| d S )N5r   r   )r   rI   r   r   )rM   r   
max_digitsrN   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    ql1 sP0    Y  n|dk rlt| | t }|| d| W d    n1 s0    Y  d S )N2r   r   )r   rI   r   rK   rG   r   )rM   rf   r   r   rN   r   r   r   r   r   _other_base_helper  s    
(z)IntStrDigitLimitsTests._other_base_helperc                 C   sx   d}| j |d | | W d    n1 s00    Y  d}| j |d | | W d    n1 sj0    Y  d S )Nr   re   rB   )r   r   rl   r   r   r   test_int_from_other_bases  s    (z0IntStrDigitLimitsTests.test_int_from_other_bases)N)r   r   r   rE   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__)rI   r   r   testr   Ztest.test_grammarr   r   rH   rJ   rG   rF   rE   r   ZTestCaser   r   r   r   mainr   r   r   r   <module>   sD       " B