B
    u9a@M                 @   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re  dS )    N)support)VALID_UNDERSCORE_LITERALSINVALID_UNDERSCORE_LITERALS)0r   )1   )9	   )10
   )Z99c   )100d   )Z314i:  )z 314i:  )z314 i:  )z  		  314  		  i:  z  1x)z  1  r   z  1    z  		  u   Ȁc               @   s   e Zd ZdS )IntSubclassN)__name__
__module____qualname__ r   r   /usr/lib/python3.7/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!S )"IntTestCasesc             C   sT	  |  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 x~tD ]v\}}xldD ]d}x^dD ]V}|| | }|}|dkr|tk	r| }y|  t|| W q tk
r$   Y qX qW qW qW 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 )Ni:  gQ	@   gQ	g333333@g333333g      @g      z-3z -3 u    -3 r
      )r   +-)r   r   	z  		  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   xZt D ]R t fdddD r"q| t dt  | t dt ddd qW x4tD ], t fdddD r~qb| tt d qbW | 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   | ]}| kV  qd S )Nr   ).0ch)litr   r   	<genexpr>   s    z0IntTestCases.test_underscores.<locals>.<genexpr>z.eEjJr   _r   c             3   s   | ]}| kV  qd S )Nr   )rR   rS   )rT   r   r   rU      s    Z1_00r   r	   Z0_100r   s   1_00Z_100z+_100Z1__00Z100_)	r   anyrA   rB   evalreplacer   rH   rD   )rJ   r   )rT   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)assertIsrB   )rJ   r   r   r   test_small_ints   s    zIntTestCases.test_small_intsc             C   s   |  t d d S )Nr   )rA   rB   )rJ   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 Q R X | td tddd W d Q R X | jttd	d | jttd
d d S )Nr   r   )baser$   zkeyword argumentg333333?)rP   )rP   r^   r   r   )rA   rB   assertRaisesRegexrI   rH   )rJ   r   r   r   test_keyword_args   s    zIntTestCases.test_keyword_argsc          	   C   s   |  tddd | t tdd W dQ R X | t tdd W dQ R X | t tdd W dQ R X | t tdddd	  d
 W dQ R X | t tddd	 d
 W dQ R X x&tddD ]}|  td|d
d qW dS )z9Testing the supported limits of the int() base parameter.r   r%   r   r   N%   isr      )r^   )rA   rB   rH   rD   range)rJ   r^   r   r   r   test_int_base_limits  s    z!IntTestCases.test_int_base_limitsc          	   C   sD   |  t tdd W dQ R X |  t tdd W dQ R X dS )z2Not integer types are not valid bases; issue16772.r   g      @Ng      @)rH   rI   rB   )rJ   r   r   r   test_int_base_bad_types  s    z$IntTestCases.test_int_base_bad_typesc          
   C   s   G dd dt }x>dd dd  ddfD ]$}| t td| W d Q R X q(W | 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 )N)value)rJ   rf   r   r   r   __init__  s    zBIntTestCases.test_int_base_indexable.<locals>.MyIndexable.__init__c             S   s   | j S )N)rf   )rJ   r   r   r   	__index__  s    zCIntTestCases.test_int_base_indexable.<locals>.MyIndexable.__index__N)r   r   r   rg   rh   r   r   r   r   MyIndexable  s   ri   r   r   r   ra   Z43Z101)r^   r%   r   e   r?   i  )objectrH   rD   rB   rA   )rJ   ri   r^   r   r   r   test_int_base_indexable  s    z$IntTestCases.test_int_base_indexablec                s2  G dd dt  G dd dt}G dd dt}tt fdd||tg}yd	d
lm W n tk
rl   Y nX |fdd x|D ]}|d}| t| | 	t
|d t|t ttfr| 	t
|dd n&d}| t| t
|d W d Q R X | td t
|d W d Q R X W d Q R X qW d S )Nc               @   s   e Zd ZdS )z<IntTestCases.test_non_numeric_input_types.<locals>.CustomStrN)r   r   r   r   r   r   r   	CustomStr-  s    rm   c               @   s   e Zd ZdS )z>IntTestCases.test_non_numeric_input_types.<locals>.CustomBytesN)r   r   r   r   r   r   r   CustomBytes.  s    rn   c               @   s   e Zd ZdS )zBIntTestCases.test_non_numeric_input_types.<locals>.CustomByteArrayN)r   r   r   r   r   r   r   CustomByteArray/  s    ro   c                s    |   S )N)decode)b)rm   r   r   <lambda>4      z;IntTestCases.test_non_numeric_input_types.<locals>.<lambda>r   )arrayc                s
    d| S )NBr   )rq   )rt   r   r   rr   >  rs   s   100r   r   r$   zcan't convert non-stringzinvalid literals   AAAAAAAAAAAAAAAA)strbytes	bytearray
memoryviewrt   ImportErrorappendZsubTesttyperA   rB   
isinstancer_   rI   rD   )rJ   rn   ro   Z	factoriesfrP   msgr   )rm   rt   r   test_non_numeric_input_types*  s2    

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   r2   s   123 s   123 s   123As   1234)rA   rB   ry   )rJ   r   r   r   test_int_memoryviewM  s
    z IntTestCases.test_int_memoryviewc             C   s   |  ttd d S )Nz1.2)rH   rD   rB   )rJ   r   r   r   test_string_floatT  s    zIntTestCases.test_string_floatc                s  G dd d}|  tt|  G dd dt}|  tt|  G dd d}| t| d G dd	 d	}xt|fD ]}G d
d d|}| t| d G dd d|}| t| d G dd d|}|  t t|  W d Q R X x
t|fD ]}	G dd d|	G fddd|}
| t|
 d G fddd|	G fddd|}yt|  W n4 tk
r } z| t|d W d d }~X Y nX | d||	ff  G dd d|	 G  fddd|}|  t t|  W d Q R X qW qxW d S )Nc               @   s   e Zd ZdS )z>IntTestCases.test_intconversion.<locals>.ClassicMissingMethodsN)r   r   r   r   r   r   r   ClassicMissingMethodsY  s   r   c               @   s   e Zd ZdS )z7IntTestCases.test_intconversion.<locals>.MissingMethodsN)r   r   r   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   )rJ   r   r   r   __int__b  s    z5IntTestCases.test_intconversion.<locals>.Foo0.__int__N)r   r   r   r   r   r   r   r   Foo0a  s   r   r   c               @   s   e Zd ZdS )z0IntTestCases.test_intconversion.<locals>.ClassicN)r   r   r   r   r   r   r   Classicg  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 )Nr   r   )rJ   r   r   r   r   k  s    zBIntTestCases.test_intconversion.<locals>.IntOverridesTrunc.__int__c             S   s   dS )Nir   )rJ   r   r   r   	__trunc__m  s    zDIntTestCases.test_intconversion.<locals>.IntOverridesTrunc.__trunc__N)r   r   r   r   r   r   r   r   r   IntOverridesTruncj  s   r   c               @   s   e Zd Zdd ZdS )z2IntTestCases.test_intconversion.<locals>.JustTruncc             S   s   dS )Nr   r   )rJ   r   r   r   r   r  s    z<IntTestCases.test_intconversion.<locals>.JustTrunc.__trunc__N)r   r   r   r   r   r   r   r   	JustTruncq  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   )rJ   r   r   r   r   w  s    zCIntTestCases.test_intconversion.<locals>.ExceptionalTrunc.__trunc__N)r   r   r   r   r   r   r   r   ExceptionalTruncv  s   r   c               @   s   e Zd Zdd ZdS )z1IntTestCases.test_intconversion.<locals>.Integralc             S   s   dS )Nr   r   )rJ   r   r   r   r   ~  s    z9IntTestCases.test_intconversion.<locals>.Integral.__int__N)r   r   r   r   r   r   r   r   Integral}  s   r   c                   s   e Zd Z fddZdS )z;IntTestCases.test_intconversion.<locals>.TruncReturnsNonIntc                s     S )Nr   )rJ   )r   r   r   r     s    zEIntTestCases.test_intconversion.<locals>.TruncReturnsNonInt.__trunc__N)r   r   r   r   r   )r   r   r   TruncReturnsNonInt  s   r   c                   s   e Zd Z fddZdS )z4IntTestCases.test_intconversion.<locals>.NonIntegralc                s     S )Nr   )rJ   )NonIntegralr   r   r     s    z>IntTestCases.test_intconversion.<locals>.NonIntegral.__trunc__N)r   r   r   r   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 )Nr   )rJ   )r   r   r   r     s    zJIntTestCases.test_intconversion.<locals>.TruncReturnsNonIntegral.__trunc__N)r   r   r   r   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   )rJ   r   r   r   r     s    z7IntTestCases.test_intconversion.<locals>.BadInt.__int__N)r   r   r   r   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 )Nr   )rJ   )r   r   r   r     s    zEIntTestCases.test_intconversion.<locals>.TruncReturnsBadInt.__trunc__N)r   r   r   r   r   )r   r   r   TruncReturnsBadInt  s   r   )rH   rI   rB   rk   rA   ZeroDivisionErrorrv   Zfail)rJ   r   r   r   r   r^   r   r   r   Ztrunc_result_baser   r   er   r   )r   r   r   r   test_intconversionW  s@    
zIntTestCases.test_intconversionc             C   sX   G dd dt }G dd dt }|d}| |d | t |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 )Nr   r   )rJ   r   r   r   r     s    z>IntTestCases.test_int_subclass_with_int.<locals>.MyInt.__int__N)r   r   r   r   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 )Ng      E@r   )rJ   r   r   r   r     s    z?IntTestCases.test_int_subclass_with_int.<locals>.BadInt.__int__N)r   r   r   r   r   r   r   r   r     s   r   r'   r   )rB   rA   rH   rI   )rJ   r   r   Zmy_intr   r   r   test_int_subclass_with_int  s    z'IntTestCases.test_int_subclass_with_intc          	      sP  G dd d G dd dt }G  fddd}G dd d}  }| t t |}W d Q R X | |d	 | t|t  | }| t t |}W d Q R X | |d	 | t|t  | }| t t |}W d Q R X | |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>.BadIntc             S   s   dS )NTr   )rJ   r   r   r   r     s    zBIntTestCases.test_int_returns_int_subclass.<locals>.BadInt.__int__N)r   r   r   r   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 )NTr   )rJ   r   r   r   r     s    zCIntTestCases.test_int_returns_int_subclass.<locals>.BadInt2.__int__N)r   r   r   r   r   r   r   r   BadInt2  s   r   c                   s   e Zd Z fddZdS )zFIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsBadIntc                s     S )Nr   )rJ   )r   r   r   r     s    zPIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsBadInt.__trunc__N)r   r   r   r   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 )NTr   )rJ   r   r   r   r     s    zUIntTestCases.test_int_returns_int_subclass.<locals>.TruncReturnsIntSubclass.__trunc__N)r   r   r   r   r   r   r   r   TruncReturnsIntSubclass  s   r   r   )rB   ZassertWarnsDeprecationWarningrA   r[   r|   r   )rJ   r   r   r   Zbad_intnZgood_intr   )r   r   test_int_returns_int_subclass  s4    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          	      sj    j td| |f d"}|d kr*t|  n
t| | W d Q R X  |jjd d|d krZdn|| f  d S )Nzint(%r, %r))r   r   z*invalid literal for int() with base %d: %rr   )rH   rD   rB   rA   Z	exceptionargs)rK   r^   cm)rJ   r   r   check  s    
z.IntTestCases.test_error_message.<locals>.check   ½u   123½z  123 456  z123 r   z123  245r/   r   z123 245s   123 s   123u   123)Nr   )rJ   r   r   )rJ   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2D)rA   rB   )rJ   r   r   r   test_issue31619  s
    zIntTestCases.test_issue31619N)r   r   r   rQ   rZ   r   Zcpython_onlyr\   r]   r`   rd   re   rl   r   r   r   r   r   r   r   r   r   r   r   r   r       s"    8
#M+!r   __main__)rF   ZunittestZtestr   Ztest.test_grammarr   r   rE   rG   rD   rC   rB   r   ZTestCaser   r   mainr   r   r   r   <module>   s8   
   j