B
    u9a)                @   s  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dlmZ d dlmZmZmZmZmZ d dlmZ d dlmZmZ yd dl Z d dl!Z!W n e"k
r
   d Z Z!Y nX G dd dZ#G d	d
 d
Z$G dd d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e)dddfe*d e(fgZ+dddddddd!e(fdd"e(fe&ej'ej'fde(fd#e(fde(fde(fde(fde(fe)dddfe*d e(fgZ,G d$d% d%Z-G d&d' d'Z.d(d) Z/d*d+ Z0G d,d- d-ej1Z2G d.d/ d/ej1Z3e4e d0G d1d2 d2ej1Z5G d3d4 d4ej1Z6G d5d6 d6ej1Z7G d7d8 d8ej1Z8d9d: Z9e:d;kre;  dS )<    N)	ExitStack)neg)EnvironmentVarGuardTESTFNcheck_warnings	swap_attrunlink)assert_python_ok)	MagicMockpatchc               @   s$   e Zd Zdd Zdd Zdd ZdS )Squaresc             C   s   || _ g | _d S )N)maxsofar)selfr    r   "/usr/lib/python3.7/test_builtin.py__init__"   s    zSquares.__init__c             C   s
   t | jS )N)lenr   )r   r   r   r   __len__&       zSquares.__len__c             C   sV   d|  kr| j k sn tt| j}x$||krJ| j||  |d7 }q(W | j| S )Nr      )r   
IndexErrorr   r   append)r   inr   r   r   __getitem__(   s     

zSquares.__getitem__N)__name__
__module____qualname__r   r   r   r   r   r   r   r       s   r   c               @   s$   e Zd Zdd Zdd Zdd ZdS )
StrSquaresc             C   s   || _ g | _d S )N)r   r   )r   r   r   r   r   r   2   s    zStrSquares.__init__c             C   s
   t | jS )N)r   r   )r   r   r   r   r   6   s    zStrSquares.__len__c             C   sZ   d|  kr| j k sn tt| j}x(||krN| jt||  |d7 }q(W | j| S )Nr   r   )r   r   r   r   r   str)r   r   r   r   r   r   r   9   s    

zStrSquares.__getitem__N)r   r   r   r   r   r   r   r   r   r   r   0   s   r   c               @   s   e Zd Zdd ZdS )	BitBucketc             C   s   d S )Nr   )r   liner   r   r   writeC   s    zBitBucket.writeN)r   r   r   r#   r   r   r   r   r!   B   s   r!   )0r   )1r   )9	   )10
   )Z99c   )Z100d   )Z314i:  )z 314i:  )z314 i:  )z  		  314  		  i:  z  1x)z  1  r   z  1    z  		  s   \u0663\u0661\u0664 zraw-unicode-escapei:  i   z 314z  		  314  		  z  1  c               @   s   e Zd Zdd ZdS )TestFailingBoolc             C   s   t d S )N)RuntimeError)r   r   r   r   __bool__s   s    zTestFailingBool.__bool__N)r   r   r   r0   r   r   r   r   r.   r   s   r.   c               @   s   e Zd Zdd ZdS )TestFailingIterc             C   s   t d S )N)r/   )r   r   r   r   __iter__w   s    zTestFailingIter.__iter__N)r   r   r   r2   r   r   r   r   r1   v   s   r1   c             C   s   t | t dkS )Nd)ord)argr   r   r   filter_charz   s    r6   c             C   s   t t| d S )Nr   )chrr4   )r5   r   r   r   map_char}   s    r8   c               @   sH  e Z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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/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(e)*e+j,j-dMdNdO Z.dPdQ Z/dRdS Z0dTdU Z1dVdW Z2dXdY Z3dZd[ Z4e56 7d\oe58 7d]Z9e:d^d^kZ;e)*e9oe;d_d`da Z<dbdc Z=ddde Z>dfdg Z?dhdi Z@eAdjdk ZBeAdldm ZCG dndo doeDZEdpdq ZFdrds ZGdtdu ZHdvdw ZIdxdy ZJdzd{ ZKd|d} ZLd~S )BuiltinTestc             C   s   |}t ||}t |}| t|t| | t|| t |}yt| W n tk
rh   d S X t ||}t |}| t||dd   d S )Nr   )pickledumpsloadsassertEqualtypelistnextStopIteration)r   itseqprotoZitorgr3   r   r   r   check_iter_pickle   s    


zBuiltinTest.check_iter_picklec             C   s   t d t d t d t dd t ddd | tt d | tt dd	d
d | tt d | jtt ddd | tt d d S )NsysZtimestring)namer   )rH   levelZspamspamr            r,   zstring )
__import__assertRaisesImportError	TypeError
ValueErrorModuleNotFoundError)r   r   r   r   test_import   s    
zBuiltinTest.test_importc             C   s   |  tdd |  tdd |  tdd | ttj d dk |  tdd |  tdd |  tdd | ttd |  td	d |  td
d | tt | ttd  G dd dt}|  t| d d S )Nr   i  i.r   g        gQ	@gQ	aTFc               @   s   e Zd Zdd ZdS )z&BuiltinTest.test_abs.<locals>.AbsClassc             S   s   dS )Nr   )r   r   r   r   __abs__   s    z.BuiltinTest.test_abs.<locals>.AbsClass.__abs__N)r   r   r   rV   r   r   r   r   AbsClass   s   rW   rU   )r=   abs
assertTruerF   maxsizerN   rP   object)r   rW   r   r   r   test_abs   s    zBuiltinTest.test_absc             C   s   |  tdddgd |  tdd dgd | ttdt dg | ttt  | ttd | tt | ttdddgg  |  tg d |  tdt gd dd	g}|  td
d |D d ddd	g}|  tdd |D d d S )NrJ   rL      TFr)   r   2   <   c             s   s   | ]}|d kV  qdS )*   Nr   ).0xr   r   r   	<genexpr>   s    z'BuiltinTest.test_all.<locals>.<genexpr>(   c             s   s   | ]}|d kV  qdS )r`   Nr   )ra   rb   r   r   r   rc      s    )r=   allrN   r/   r.   r1   rP   )r   Sr   r   r   test_all   s    
zBuiltinTest.test_allc             C   s   |  td d d gd |  td dd gd | ttd t dg | ttt  | ttd | tt | ttdddgg  |  tg d |  tdt gd dd	d
g}|  tdd |D d ddd
g}|  tdd |D d d S )NFrL   Tr]   r)   rJ   r   rd   r_      c             s   s   | ]}|d kV  qdS )r`   Nr   )ra   rb   r   r   r   rc      s    z'BuiltinTest.test_any.<locals>.<genexpr>   c             s   s   | ]}|d kV  qdS )r`   Nr   )ra   rb   r   r   r   rc      s    )r=   anyrN   r/   r.   r1   rP   )r   rf   r   r   r   test_any   s    

zBuiltinTest.test_anyc                s    tdd   tdd   tdd   tg d   ti d g }||   t|d	 i }||d<   t|d
  fdd}|d |d |d |d |d |d |d |d |d |d   tdd d}  t|d d S )Nr,   z''r   r$   r   z()z[]z{}z[[...]]z
{0: {...}}c                s     t| t|  d S )N)r=   asciirepr)s)r   r   r   
_check_uni   s    z*BuiltinTest.test_ascii.<locals>._check_uni'"z"' z
	 .   u   ῿u   𒿿u   u   u   𝄡z'\U0001d121'u   ' "
	 abcdé𒿿𝄡xxx.z:'\'\x00"\n\r\t abcd\x85\xe9\U00012fff\ud800\U0001d121xxx.')r=   rl   r   )r   rT   ro   rn   r   )r   r   
test_ascii   s4    

zBuiltinTest.test_asciic             C   s4   t j d }| t|t | | t jd  d S )Nr   )rF   rZ   rY   
isinstanceintr=   )r   rb   r   r   r   test_neg   s    zBuiltinTest.test_negc             C   s>  |  tt | td |  tt |  tdd  | tt dd }|  t| G dd d}|  t| | }|  t|j | t| d |_| t| dd |_| t| |`| t| G d	d
 d
t}| }|  t| d |_|  t| G dd d|}| }|  t| d S )NrT   c             S   s   | | S )Nr   )rb   yr   r   r   <lambda>  r   z+BuiltinTest.test_callable.<locals>.<lambda>c               S   s   d S )Nr   r   r   r   r   f  r   z$BuiltinTest.test_callable.<locals>.fc               @   s   e Zd Zdd ZdS )z%BuiltinTest.test_callable.<locals>.C1c             S   s   d S )Nr   )r   r   r   r   meth  r   z*BuiltinTest.test_callable.<locals>.C1.methN)r   r   r   r{   r   r   r   r   C1  s   r|   c             S   s   dS )Nr   r   )r   r   r   r   ry     r   c               @   s   e Zd Zdd ZdS )z%BuiltinTest.test_callable.<locals>.C2c             S   s   d S )Nr   )r   r   r   r   __call__  r   z.BuiltinTest.test_callable.<locals>.C2.__call__N)r   r   r   r}   r   r   r   r   C2  s   r~   c               @   s   e Zd ZdS )z%BuiltinTest.test_callable.<locals>.C3N)r   r   r   r   r   r   r   C3  s    r   )rY   callabler   assertFalse__builtins__r{   r}   r[   )r   rz   r|   cr~   Zc2r   Zc3r   r   r   test_callable   s4    
zBuiltinTest.test_callablec             C   s:  |  tdd |  tdd |  tdd |  tdd | ttd	 |  ttjtd
dd | tt |  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td | ttd  | t	tftd! d S )"N    r-   A   Aa   rT         ÿi   z
\U0010ffffrl   zunicode-escapei  u   ￿i   u   𐀀i  u   𐀁i u   󿿾i u   󿿿i   u   􀀀i  u   􀀁i u   􏿾i u   􏿿i   l        )
r=   r7   rN   rQ   rF   
maxunicoder    encoderP   OverflowError)r   r   r   r   test_chr  s(    zBuiltinTest.test_chrc             C   s   |  ttd  d S )NZcmp)rY   hasattrbuiltins)r   r   r   r   test_cmp5  s    zBuiltinTest.test_cmpc          
   C   s  t ddd d}t |d dd t dddd t d	d
ddd t ddddd t tddd | tt  | tt ddd | tt dddd | tt td	dd | jtt dddddd
d t ddd | tt td	dd | tt tddd d}dd }dd |jd d fd!d"d#g}x|D ]|^}}g }|t |d$d|d% t	
|}|t |d$d|d% x6|D ].}	i }
t|	|
 |
d  }| |t| qjW q"W d S )&Nz	print(1)
r,   execs   ﻿s	   print(1)
pass?)sourcefilenamemoder   Ztmpr$   eval)dont_inheritr   r   r   r   )r   r   s   textrH   z
print(42)
z<string>ZbadmodeZsingler   rz   )r   r   r   u   print("å")
za = 1ZbadaJ  def f():
        """doc"""
        debug_enabled = False
        if __debug__:
            debug_enabled = True
        try:
            assert False
        except AssertionError:
            return (True, f.__doc__, debug_enabled, __debug__)
        else:
            return (False, f.__doc__, debug_enabled, __debug__)
        c               S   s   d S )Nr   r   r   r   r   rz   X  r   z#BuiltinTest.test_compile.<locals>.fr   F)r   TdocTT)r   Fr   FF)rJ   FNFFz<test>)optimize)compile
memoryviewrN   rP   rQ   r7   r    __doc__r   astparser   r=   tuple)r   bomZcodestrrz   valuesZoptvalexpectedZcodeobjsZtreecodensrvr   r   r   test_compile8  s@    



zBuiltinTest.test_compilec             C   s    dt _tt d | tt d S )Nr   spam)rF   r   delattrrN   rP   )r   r   r   r   test_delattri  s    
zBuiltinTest.test_delattrc          	   C   s  |  ttdd d}| dt  | dtt G dd dtj}|d}|  tt| | dtt | d	tt G d
d dt	}| }| dt| G dd dt	}| }| dt| G dd dt	}| }| dt| | dt| G dd dt	}| }| 
t|dddgk G dd dt	}t| }| |t | 
|dddgk G dd dt	}| }|  tt| ytW n(   | ttt d d Y nX | tg  tg  d S )Nr`   r   	local_varexitc               @   s   e Zd ZdZdS )z!BuiltinTest.test_dir.<locals>.Foo   N)r   r   r   __dict__r   r   r   r   Fooz  s   r   foostrip__mro__c               @   s   e Zd Zdd ZdS )z!BuiltinTest.test_dir.<locals>.Fooc             S   s   d| _ d| _d| _d S )N   r   r'   )rb   rx   z)r   r   r   r   r     s    z*BuiltinTest.test_dir.<locals>.Foo.__init__N)r   r   r   r   r   r   r   r   r     s   rx   c               @   s   e Zd Zg ZdS )z!BuiltinTest.test_dir.<locals>.FooN)r   r   r   	__slots__r   r   r   r   r     s   __repr__c               @   s   e Zd ZddgZdd ZdS )z!BuiltinTest.test_dir.<locals>.Foo	__class__r   c             S   s
   d| _ d S )NZwow)bar)r   r   r   r   r     s    z*BuiltinTest.test_dir.<locals>.Foo.__init__N)r   r   r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd Zdd ZdS )z!BuiltinTest.test_dir.<locals>.Fooc             S   s
   dddgS )Nkangaroor   )r   r   r   r   __dir__  s    z)BuiltinTest.test_dir.<locals>.Foo.__dir__N)r   r   r   r   r   r   r   r   r     s   r   r   r   c               @   s   e Zd Zdd ZdS )z!BuiltinTest.test_dir.<locals>.Fooc             S   s   dS )N)br   rT   r   )r   r   r   r   r     s    z)BuiltinTest.test_dir.<locals>.Foo.__dir__N)r   r   r   r   r   r   r   r   r     s   rT   r   r   c               @   s   e Zd Zdd ZdS )z!BuiltinTest.test_dir.<locals>.Fooc             S   s   dS )Nr   r   )r   r   r   r   r     s    z)BuiltinTest.test_dir.<locals>.Foo.__dir__N)r   r   r   r   r   r   r   r   r     s   rJ   rL   )rN   rP   dirassertInrF   types
ModuleTyper    assertNotInr[   rY   ZassertIsInstancer?   r   r=   r   exc_infosortedr   )r   r   r   rz   Zresr   r   r   test_dirn  sD    
"zBuiltinTest.test_dirc             C   s   |  tddd |  tddd |  tddd |  tddd |  ttj d	 d
tjd	 df xDdD ]<\}}}t||}| |d |d  | |d	 |d	  qrW | tt d S )N   r   )r      i)rJ   i)r   r   )r   rU   r   r   r   ))g      
@g      ?)g      @g      ?)g      
g      ?)g      g      ?)g      
@g      )g      g      )g      
g      )g      @g      п)r=   divmodrF   rZ   assertAlmostEqualrN   rP   )r   ZnumZdenomZ
exp_resultresultr   r   r   test_divmod  s    $
zBuiltinTest.test_divmodc             C   s  |  tdd |  tdd ddd}ddd}|  td	|d |  td	||d |  td
||d |  td||d ddd}ddd}d}|  t|d ||d |  td|d | tt | ttd | tt|d d d  G dd d}| ttdi |  d S )Nz1+1rJ   z 1+1
r   )rT   r      i,  )r   r   rT   r   r   s   ﻿   au   "å"   år   c               @   s   e Zd Zdd ZdS )z BuiltinTest.test_eval.<locals>.Xc             S   s   t d S )N)rQ   )r   keyr   r   r   r     s    z,BuiltinTest.test_eval.<locals>.X.__getitem__N)r   r   r   r   r   r   r   r   X  s   r   r   )r=   r   rN   rP   SyntaxErrorrQ   )r   globalslocalsr   r   r   r   r   	test_eval  s$    



zBuiltinTest.test_evalc       
      C   s  G dd d}| }t  }| td||d | ttd|| | td||td | td||| | td	||| | ttd| G d
d d}| }| ttd|| G dd dt}| }| td||d | ttd|| | td||td | td||| | td	||| td|| td|t	  G dd d}| }d|d< d|d< d|d< | |d d G dd d}	| ttdt  |	  d S )Nc               @   s   e Zd Zdd Zdd ZdS )z(BuiltinTest.test_general_eval.<locals>.Mc             S   s   |dkrdS t d S )NrT   r   )KeyError)r   r   r   r   r   r     s    z4BuiltinTest.test_general_eval.<locals>.M.__getitem__c             S   s   t dS )Nxyz)r?   )r   r   r   r   keys  s    z-BuiltinTest.test_general_eval.<locals>.M.keysN)r   r   r   r   r   r   r   r   r   M  s   r   rT   r   r   zdir()r   z	globals()zlocals()c               @   s   e Zd ZdS )z(BuiltinTest.test_general_eval.<locals>.AN)r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd Zdd Zdd ZdS )z(BuiltinTest.test_general_eval.<locals>.Dc             S   s   |dkrdS t | |S )NrT   r   )dictr   )r   r   r   r   r   r      s    z4BuiltinTest.test_general_eval.<locals>.D.__getitem__c             S   s   t dS )Nr   )r?   )r   r   r   r   r     s    z-BuiltinTest.test_general_eval.<locals>.D.keysN)r   r   r   r   r   r   r   r   r   D  s   r   z[locals() for i in (2,3)]c               @   s    e Zd Zi Zdd Zdd ZdS )z2BuiltinTest.test_general_eval.<locals>.SpreadSheetc             S   s   || j |< d S )N)_cells)r   r   Zformular   r   r   __setitem__  s    z>BuiltinTest.test_general_eval.<locals>.SpreadSheet.__setitem__c             S   s   t | j| t | S )N)r   r   r   )r   r   r   r   r   r     s    z>BuiltinTest.test_general_eval.<locals>.SpreadSheet.__getitem__N)r   r   r   r   r   r   r   r   r   r   SpreadSheet  s   r   5Za1za1*6Za2za2*7a3   c               @   s   e Zd Zdd Zdd ZdS )z(BuiltinTest.test_general_eval.<locals>.Cc             S   s   t |d S )N)r   )r   itemr   r   r   r   #  s    z4BuiltinTest.test_general_eval.<locals>.C.__getitem__c             S   s   dS )Nr   r   )r   r   r   r   r   %  s    z-BuiltinTest.test_general_eval.<locals>.C.keysN)r   r   r   r   r   r   r   r   r   C"  s   r   )
r   r=   r   rN   	NameErrorr?   rP   r   collectionsUserDict)
r   r   mgr   r   r3   r   ssr   r   r   r   test_general_eval  s:    	zBuiltinTest.test_general_evalc          	   C   s   i }t d| d|kr|d= | |ddi t d| d|krD|d= | |ddi i }i }t " tjddd	d
 t d|| W d Q R X d|kr|d= d|kr|d= | ||fddiddif d S )Nzz = 1r   r   r   zz = 1+1rJ   ignorezglobal statementz<string>)modulezglobal a; a = 1; b = 2rT   r   )r   r=   r   warningsfilterwarnings)r   r   lr   r   r   	test_exec)  s(    

zBuiltinTest.test_execc                s   t ddd}| tdt|di i | tt|ddi t ddd}| tdt|di i G d	d
 d
t G  fdddt}tt	t
jr|t	j}n|t	}t ddd}|  t|d|i |i }t ddd}|  t|| d S )Nzprint('Hello World!')r,   r   zname 'print' is not definedr   {   zclass A: passz__build_class__ not foundc               @   s   e Zd ZdS )z7BuiltinTest.test_exec_globals.<locals>.frozendict_errorN)r   r   r   r   r   r   r   frozendict_errorO  s   r   c                   s   e Zd Z fddZdS )z1BuiltinTest.test_exec_globals.<locals>.frozendictc                s    dd S )Nzfrozendict is readonlyr   )r   r   value)r   r   r   r   S  s    z=BuiltinTest.test_exec_globals.<locals>.frozendict.__setitem__N)r   r   r   r   r   )r   r   r   
frozendictR  s   r   z1__builtins__['superglobal']=2; print(superglobal)Ztestzx=1)r   assertRaisesRegexr   r   rN   rP   	Exceptionr   ru   r   r   r   r   )r   r   r   Zfrozen_builtins	namespacer   )r   r   test_exec_globalsA  s(    zBuiltinTest.test_exec_globalsc             C   s@   t j}d t _z&ytd W n tk
r.   Y nX W d |t _X d S )NrT   )rF   stdoutr   r   )r   
savestdoutr   r   r   test_exec_redirectede  s    
z BuiltinTest.test_exec_redirectedc             C   s  |  ttdd dtd |  ttd ddg dgdd d	d
gdddgd	g |  ttdd ddd	d
dgdd	dg |  ttd tdddd	ddddddg	 |  ttdd tddd	dddg dd }t|td | tt G dd dt}| tttdd |  dd }| ttt|td |  ttd dddg |  ttd d d!ddg | tttd"d d S )#Nc             S   s   d|   kodkS   S )NrT   r   r   )r   r   r   r   ry   q  r   z)BuiltinTest.test_filter.<locals>.<lambda>zHello WorldZelloorldr   ZhellorK   r,   r'   r   c             S   s   | dkS )Nr   r   )rb   r   r   r   ry   s  r   rJ   r)   rL         $   1   @   Q   c             S   s   | d S )NrJ   r   )rb   r   r   r   ry   u  r   c             S   s   dS )Nr   r   )r   r   r   r   identityv  s    z)BuiltinTest.test_filter.<locals>.identityr   c               @   s   e Zd Zdd ZdS )z'BuiltinTest.test_filter.<locals>.BadSeqc             S   s   |dk rdS t d S )NrL   r`   )rQ   )r   indexr   r   r   r   {  s    z3BuiltinTest.test_filter.<locals>.BadSeq.__getitem__N)r   r   r   r   r   r   r   r   BadSeqz  s   r  c             S   s   | S )Nr   )rb   r   r   r   ry     r   c               S   s   d S )Nr   r   r   r   r   badfunc  s    z(BuiltinTest.test_filter.<locals>.badfunc)r   rJ   c             S   s   | dkS )NrK   r   )rb   r   r   r   ry     r   )r   rJ   rK   rL   r`   )	r=   r?   filterr   rN   rP   r[   rQ   range)r   r  r  r  r   r   r   test_filterp  s    2*,(zBuiltinTest.test_filterc             C   sB   x<t tjd D ]*}ttd}ttd}| |t|| qW d S )Nr   Z
abcdeabcde)r
  r:   HIGHEST_PROTOCOLr	  r6   rE   r?   )r   rD   f1f2r   r   r   test_filter_pickle  s    

zBuiltinTest.test_filter_picklec             C   sn   |  ttdtjk | tttd | tttdd | tt | tttttj | ttdd d S )Nr   r   r   u   픞)	rY   getattrrF   r   rN   rP   AttributeErrorr7   r   )r   r   r   r   test_getattr  s    zBuiltinTest.test_getattrc             C   s   |  ttd | tttd | tt | dttttj G dd d}| tt| d G dd d}| t	t| d d S )	Nr   r   Fc               @   s   e Zd Zdd ZdS )z#BuiltinTest.test_hasattr.<locals>.Ac             S   s   t d S )N)
SystemExit)r   whatr   r   r   __getattr__  s    z/BuiltinTest.test_hasattr.<locals>.A.__getattr__N)r   r   r   r  r   r   r   r   r     s   r   r   c               @   s   e Zd Zdd ZdS )z#BuiltinTest.test_hasattr.<locals>.Bc             S   s   t d S )N)rQ   )r   r  r   r   r   r    s    z/BuiltinTest.test_hasattr.<locals>.B.__getattr__N)r   r   r   r  r   r   r   r   B  s   r  )
rY   r   rF   rN   rP   r=   r7   r   r  rQ   )r   r   r  r   r   r   test_hasattr  s    zBuiltinTest.test_hasattrc             C   s   t d  | t dt d | t dt d t d | t dt d t d dd }| tt g  | tt i  G dd	 d	}| tt | t G d
d dt}| t |dt d d S )Nr   g      ?r   s   spam)r   r   rJ   rK   c               S   s   d S )Nr   r   r   r   r   rz     r   z BuiltinTest.test_hash.<locals>.fc               @   s   e Zd Zdd ZdS )z BuiltinTest.test_hash.<locals>.Xc             S   s   dd S )NrJ   r+   r   )r   r   r   r   __hash__  s    z)BuiltinTest.test_hash.<locals>.X.__hash__N)r   r   r   r  r   r   r   r   r     s   r   c               @   s   e Zd Zdd ZdS )z BuiltinTest.test_hash.<locals>.Zc             S   s   | S )Nr   )r   r   r   r   r    s    z)BuiltinTest.test_hash.<locals>.Z.__hash__N)r   r   r   r  r   r   r   r   Z  s   r  r`   )hashr=   rN   rP   r>   rv   )r   rz   r   r  r   r   r   	test_hash  s    zBuiltinTest.test_hashc             C   s2   |  tdd |  tdd | tti  d S )Nr   Z0x10iz-0x10)r=   hexrN   rP   )r   r   r   r   test_hex  s    zBuiltinTest.test_hexc             C   sL   t d  t d t d t d t d t ddddg t dddd d S )	Nr   g      ?r   )r   r   rJ   rK   r   rJ   rK   )r   Zeggsham)id)r   r   r   r   test_id  s    zBuiltinTest.test_idc             C   sr   |  tt |  ttdd dddgdg}xB|D ]:}t|}| t|d | t|d |  tt| q0W d S )Nr`   )r%   2r%   r!  Z12)rN   rP   iterr=   r@   rA   )r   Zlistsr   r   r   r   r   	test_iter  s    
zBuiltinTest.test_iterc             C   s   G dd d}G dd d|}G dd d}| }| }| }|  t|| |  t|| |  t||  |  t||  |  td|  | tt|d | tt d S )Nc               @   s   e Zd ZdS )z&BuiltinTest.test_isinstance.<locals>.CN)r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd ZdS )z&BuiltinTest.test_isinstance.<locals>.DN)r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd ZdS )z&BuiltinTest.test_isinstance.<locals>.EN)r   r   r   r   r   r   r   E  s   r$  r   )rY   ru   rN   rP   )r   r   r   r$  r   r3   er   r   r   test_isinstance  s    zBuiltinTest.test_isinstancec             C   s   G dd d}G dd d|}G dd d}| }| }| }|  t|| |  t|| |  t||  | ttd| | tt|d | tt d S )Nc               @   s   e Zd ZdS )z&BuiltinTest.test_issubclass.<locals>.CN)r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd ZdS )z&BuiltinTest.test_issubclass.<locals>.DN)r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd ZdS )z&BuiltinTest.test_issubclass.<locals>.EN)r   r   r   r   r   r   r   r$    s   r$  r   )rY   
issubclassrN   rP   )r   r   r   r$  r   r3   r%  r   r   r   test_issubclass  s    zBuiltinTest.test_issubclassc             C   sF  |  tdd |  tdd |  tdd |  tddddgd |  ti d |  tddd	d G d
d d}| tt|  G dd d}| tt|  G dd d}| tt|  G dd d}| tt|  G dd d}| tt|  G dd d}| tt|  G dd dt}| tt|  d S )N123rK   r   r   )r   rJ   rK   rL   rL   r   rJ   )rT   r   c               @   s   e Zd Zdd ZdS )z$BuiltinTest.test_len.<locals>.BadSeqc             S   s   t d S )N)rQ   )r   r   r   r   r     s    z,BuiltinTest.test_len.<locals>.BadSeq.__len__N)r   r   r   r   r   r   r   r   r    s   r  c               @   s   e Zd Zdd ZdS )z(BuiltinTest.test_len.<locals>.InvalidLenc             S   s   d S )Nr   )r   r   r   r   r     s    z0BuiltinTest.test_len.<locals>.InvalidLen.__len__N)r   r   r   r   r   r   r   r   
InvalidLen  s   r*  c               @   s   e Zd Zdd ZdS )z&BuiltinTest.test_len.<locals>.FloatLenc             S   s   dS )Ng      @r   )r   r   r   r   r   
  s    z.BuiltinTest.test_len.<locals>.FloatLen.__len__N)r   r   r   r   r   r   r   r   FloatLen	  s   r+  c               @   s   e Zd Zdd ZdS )z)BuiltinTest.test_len.<locals>.NegativeLenc             S   s   dS )Nir   )r   r   r   r   r     s    z1BuiltinTest.test_len.<locals>.NegativeLen.__len__N)r   r   r   r   r   r   r   r   NegativeLen  s   r,  c               @   s   e Zd Zdd ZdS )z%BuiltinTest.test_len.<locals>.HugeLenc             S   s
   t jd S )Nr   )rF   rZ   )r   r   r   r   r     s    z-BuiltinTest.test_len.<locals>.HugeLen.__len__N)r   r   r   r   r   r   r   r   HugeLen  s   r-  c               @   s   e Zd Zdd ZdS )z-BuiltinTest.test_len.<locals>.HugeNegativeLenc             S   s   t j d S )Nr)   )rF   rZ   )r   r   r   r   r     s    z5BuiltinTest.test_len.<locals>.HugeNegativeLen.__len__N)r   r   r   r   r   r   r   r   HugeNegativeLen  s   r.  c               @   s   e Zd ZdS )z)BuiltinTest.test_len.<locals>.NoLenMethodN)r   r   r   r   r   r   r   NoLenMethod  s    r/  )r=   r   rN   rQ   rP   r   r[   )r   r  r*  r+  r,  r-  r.  r/  r   r   r   test_len  s(    zBuiltinTest.test_lenc                s  |  ttdd tdddddg yddlm  W n tk
rR   dd	  Y nX |  tt fd
dddgddggddgddgg |  ttdd dddgdddgdddg dd }|  tt|dddgdddg |  tt|dddgdddgdddg |  tt|dddgdddgdddgdddg |  ttttdddddddddddg
 d d! }|  tt|tdtdddg | 	t
t | 	t
td"d d# G d$d% d%}| 	tttd&d |  d'd( }| 	ttt|td d S ))Nc             S   s   | |  S )Nr   )rb   r   r   r   ry     r   z&BuiltinTest.test_map.<locals>.<lambda>r   rL   r'   r   )sqrtc             S   s
   t | dS )Ng      ?)pow)rb   r   r   r   r1  $  s    z"BuiltinTest.test_map.<locals>.sqrtc                s   t t | S )N)r?   map)rb   )r1  r   r   ry   '  r   r   r  g      @g       @g      "@g      @c             S   s   | | S )Nr   )rb   rx   r   r   r   ry   +  r   rK   rJ   r)   r]   c              W   s   d}x| D ]}|| }q
W |S )Nr   r   )vZaccur   r   r   r   plus/  s    
 z"BuiltinTest.test_map.<locals>.plusr   r   r      r   r  r  r  c             S   s"   | d kr|S |d kr| S t | |S )N)r   )rT   r   r   r   r   MaxC  s
    z!BuiltinTest.test_map.<locals>.Maxc             S   s   | S )Nr   )rb   r   r   r   ry   N  r   r`   c               @   s   e Zd Zdd ZdS )z$BuiltinTest.test_map.<locals>.BadSeqc             s   s   t d V  d S )N)rQ   )r   r   r   r   r2   P  s    z-BuiltinTest.test_map.<locals>.BadSeq.__iter__N)r   r   r   r2   r   r   r   r   r  O  s   r  c             S   s   | S )Nr   )rb   r   r   r   ry   S  r   c             S   s   t d S )N)r/   )rb   r   r   r   r  T  s    z%BuiltinTest.test_map.<locals>.badfunc)r=   r?   r3  r
  Zmathr1  rO   rv   r   rN   rP   rQ   r/   )r   r5  r7  r  r  r   )r1  r   test_map  sH     "
zBuiltinTest.test_mapc             C   sB   x<t tjd D ]*}ttd}ttd}| |t|| qW d S )Nr   zIs this the real life?)r
  r:   r  r3  r8   rE   r?   )r   rD   Zm1Zm2r   r   r   test_map_pickleX  s    

zBuiltinTest.test_map_picklec          	   C   s
  |  tdd |  tdddd |  tdd |  tddddddgd |  tdddd |  tdddd |  td	ddd | tt | ttd
 | ttd G dd d}| tt|  x>dD ]6}yt|t  W n tk
r   Y qX | | qW |  tdtdd |  tdtdd |  tddtdd |  tdd dd  |  tdd dd |  tdd dd |  tddtdd |  tddtdd dd t	dD }t
dd |D }|j}|  t||dtt||dd  d S )N1231233r   rJ   rK   )r   rJ   rK   r   rJ   rK   g      @g       @g      ?r`   r   c               @   s   e Zd Zdd ZdS )z$BuiltinTest.test_max.<locals>.BadSeqc             S   s   t d S )N)rQ   )r   r  r   r   r   r   l  s    z0BuiltinTest.test_max.<locals>.BadSeq.__getitem__N)r   r   r   r   r   r   r   r   r  k  s   r  )zmax(key=int)zmax(default=None)zmax(1, 2, default=None)zmax(default=None, key=int)zmax(1, key=int)zmax(1, 2, keystone=int)zmax(1, 2, key=int, abc=int)zmax(1, 2, key=1))r   )r   )r   rJ   )default)r<  r   c             S   s   g | ]}t d qS )r   )random	randrange)ra   r   r   r   r   
<listcomp>  s    z(BuiltinTest.test_max.<locals>.<listcomp>r+   c             s   s   | ]}|t d fV  qdS )r^   N)r=  r>  )ra   elemr   r   r   rc     s    z'BuiltinTest.test_max.<locals>.<genexpr>r   )r=   r   rN   rP   rQ   r   r   failr   r
  r   r   r   reversed)r   r  stmtdatar   rz   r   r   r   test_max^  s@    	zBuiltinTest.test_maxc          	   C   s  |  tdd |  tdddd |  tdd |  tddddddgd |  tdddd |  tdddd |  td	ddd	 | tt | ttd
 | ttd G dd d}| tt|  x>dD ]6}yt|t  W n tk
r   Y qX | | qW |  tdtdd |  tdtdd |  tddtdd |  tdd dd  |  tdd dd |  tdd dd |  tddtdd |  tddtdd dd t	dD }t
dd |D }|j}|  t||dt||dd  d S )Nr:  r%   r   rJ   rK   )r   rJ   rK   r   rJ   rK   g      @g       @g      ?r`   r   c               @   s   e Zd Zdd ZdS )z$BuiltinTest.test_min.<locals>.BadSeqc             S   s   t d S )N)rQ   )r   r  r   r   r   r     s    z0BuiltinTest.test_min.<locals>.BadSeq.__getitem__N)r   r   r   r   r   r   r   r   r    s   r  )zmin(key=int)zmin(default=None)zmin(1, 2, default=None)zmin(default=None, key=int)zmin(1, key=int)zmin(1, 2, keystone=int)zmin(1, 2, key=int, abc=int)zmin(1, 2, key=1))r   )r   )r   rJ   )r<  )r<  r   c             S   s   g | ]}t d qS )r   )r=  r>  )ra   r   r   r   r   r?    s    z(BuiltinTest.test_min.<locals>.<listcomp>r+   c             s   s   | ]}|t d fV  qdS )r^   N)r=  r>  )ra   r@  r   r   r   rc     s    z'BuiltinTest.test_min.<locals>.<genexpr>r   )r=   minrN   rP   rQ   r   r   rA  r   r
  r   r   r   )r   r  rC  rD  r   rz   r   r   r   test_min  s@    	zBuiltinTest.test_minc             C   s   t td}| t|d | t|d | tt| | tt| | t|dd G dd dt}t | }| t|dd | tt| dd }| }| t|d | tt| | t|dd d S )	NrJ   r   r   r`   c               @   s   e Zd Zdd Zdd ZdS )z#BuiltinTest.test_next.<locals>.Iterc             S   s   | S )Nr   )r   r   r   r   r2     s    z,BuiltinTest.test_next.<locals>.Iter.__iter__c             S   s   t d S )N)rA   )r   r   r   r   __next__  s    z,BuiltinTest.test_next.<locals>.Iter.__next__N)r   r   r   r2   rH  r   r   r   r   Iter  s   rI  c               s   s
   dV  d S )Nr   r   r   r   r   r   gen  s    z"BuiltinTest.test_next.<locals>.gen)r"  r
  r=   r@   rN   rA   r[   )r   rB   rI  rJ  r   r   r   	test_next  s    
zBuiltinTest.test_nextc             C   s2   |  tdd |  tdd | ttd d S )Nr+   Z0o144iz-0o144r   )r=   octrN   rP   )r   r   r   r   test_oct  s    zBuiltinTest.test_octc          	   C   sf   t td}| tt |B |d |d |d |d |d |d W d Q R X d S )Nwz1+1
z+The quick brown fox jumps over the lazy dogz.
z
Dear John
,  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,  YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY)openr   
addCleanupr   r#   )r   fpr   r   r   write_testfile  s    





zBuiltinTest.write_testfilec          	   C   s   |    ttd}|p | |dd | | d | |dd | |dd | |dd	 | |d
d W d Q R X | ttd | ttd d S )NrrL   z1+1
z-The quick brown fox jumps over the lazy dog.
ZDearr+   z John
i,  rO  i  rP  za bs   a b)rT  rQ  r   r=   readlinereadrN   rQ   )r   rS  r   r   r   	test_open  s    
zBuiltinTest.test_openzutf-8 mode is enabledc          	   C   s   t tj}z^xdD ]}|tjkrtj|= qW |   td}ttd}| | |j	| W d Q R X W d tj
  tj| X d S )N)LC_ALLLANGLC_CTYPEFrN  )r   osenvironrT  localegetpreferredencodingrQ  r   r=   encodingclearupdate)r   Zold_environr   Zcurrent_locale_encodingrS  r   r   r   test_open_default_encoding  s    





z&BuiltinTest.test_open_default_encodingc          	   C   s0   t t}| | t|  W d Q R X d S )N)rQ  __file__r   r\  get_inheritablefileno)r   Zfileobjr   r   r   test_open_non_inheritable  s    z%BuiltinTest.test_open_non_inheritablec             C   sn  |  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ttjtj | ttd |  t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 S )#Nr-   r   r   r   rT   r         r   r          Ar         r`   i u   ￿i  u   𐀀i   u   𐀁i  u   󿿾i u   󿿿i u   􀀀i   u   􀀁i  u   􏿾i u   􏿿)r=   r4   r7   rF   r   rN   rP   )r   r   r   r   test_ord  s,    zBuiltinTest.test_ordc          
   C   s  |  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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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 xzdD ]r}xjdD ]b}xZdD ]R}t|tst|tst|tr| tt||| n| t|||d qW qW qW | tddd | tddd | ttdd
d | ttddd | tt d S ) Nr   r   rJ   r)   i   ri   i   rh   i   @r   rL   rK   ig        g      ?g       @g      @g      0Ag      Ag       g      @g       )rJ   g       @)r)   g      $@)i  g     @@g      8@r   g      ?y              ?gUUUUUU?y      ?LXz?)r=   r2  r   ru   floatrN   rP   rQ   )r   rb   rx   r   r   r   r   test_pow5  sJ    


&zBuiltinTest.test_powc             C   s  |    ttd}tj}tj}z|t_t t_| t d | t d | tdd |t_tj	  | 
tt t t_tdt_| 
ttdd tdt_| t d t t_| 
tt t`| 
ttd	 t`| 
ttd	 W d |t_|t_|	  X d S )
NrU  z1+1z,The quick brown fox jumps over the lazy dog.ztesting
z	Dear JohnzNULL r`   z    'whitespace'prompt)rT  rQ  r   rF   stdinr   r!   r=   inputcloserN   rQ   ioStringIOrP   EOFErrorr/   )r   rS  Z	savestdinr   r   r   r   
test_inputf  s6    


zBuiltinTest.test_inputc             C   s   |  tdd |  tdd |  tdd |  tg d |  ti d g }|| |  t|d	 i }||d< |  t|d
 d S )Nr,   z''r   r$   r   z()z[]z{}z[[...]]z
{0: {...}})r=   rm   r   )r   rT   r   r   r   	test_repr  s    
zBuiltinTest.test_reprc             C   s0  |  tdd |  ttdt |  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 |  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tddt |  ttddt |  ttddt |  tdd |  tdd |  tdd |  td d |  tdd |  td!d! |  td"d" |  ttdt |  ttd"dt |  ttd"dt |  ttd"dt |  tddd#d | tt G d$d% d%}G d&d' d'}|  t| d( | ttdd)d* | tt|  | }d+d, |_| tt| | tt|d d S )-Ng        g      ?g      $@g    eAg@xDg      g      $g    eg@xg?g?g333333$@g eAgg333333$g eg?g#@g33dAgg#g33dg       r   r   r   g      @r]   g      @g      ig      r   i)ZnumberZndigitsc               @   s   e Zd Zdd ZdS )z)BuiltinTest.test_round.<locals>.TestRoundc             S   s   dS )N   r   )r   r   r   r   	__round__  s    z3BuiltinTest.test_round.<locals>.TestRound.__round__N)r   r   r   r{  r   r   r   r   	TestRound  s   r|  c               @   s   e Zd ZdS )z+BuiltinTest.test_round.<locals>.TestNoRoundN)r   r   r   r   r   r   r   TestNoRound  s   r}  rz  rJ   rK   c              W   s   | S )Nr   )argsr   r   r   ry     r   z(BuiltinTest.test_round.<locals>.<lambda>)r=   roundr>   rv   ro  rN   rP   r{  )r   r|  r}  tr   r   r   
test_round  sb    
zBuiltinTest.test_roundZLinuxZalphag7y1CzItest will fail;  failure is probably due to a buggy system round functionc             C   sT   |  tdd |  tdd |  tdd |  tdd |  tdd d S )Ng7y1Cg 7y1Cg7y1Cg7y1Cg7y1C)r=   r  )r   r   r   r   test_round_large  s
    zBuiltinTest.test_round_largec             C   s\   xVddt dtddgD ]8}| t|d t| | tt|d tt| qW d S )Ni  g
ףp=J@z1234.56i@ r+   )decimalZDecimal	fractionsZFractionr=   r  r>   )r   rb   r   r   r   test_bug_27936  s    zBuiltinTest.test_bug_27936c             C   s<   t tdd | tjd | tt tdd | tt  d S )Nr   r   )setattrrF   r=   r   rN   rP   )r   r   r   r   test_setattr   s    zBuiltinTest.test_setattrc             C   s  |  tg d |  tttddd |  ttttddd |  ttdd |  tttdd |  tdgdgdggg dddg | tt | ttd	 | ttd
ddg | ttd
ddgd | ttddgd tdtdg}| tt|td | ttdgdgdgg | ttddig | ttddigd ddi G dd d}| t	t|  g }tdd tdD | |  |g  d S )Nr   rJ   r      r)   i  r   rK   r`   rT   r   r   r,   r      cr      bc               @   s   e Zd Zdd ZdS )z$BuiltinTest.test_sum.<locals>.BadSeqc             S   s   t d S )N)rQ   )r   r  r   r   r   r     s    z0BuiltinTest.test_sum.<locals>.BadSeq.__getitem__N)r   r   r   r   r   r   r   r   r    s   r  c             s   s   | ]}|gV  qd S )Nr   )ra   rb   r   r   r   rc   !  s    z'BuiltinTest.test_sum.<locals>.<genexpr>)
r=   sumr?   r
  r"  r   rN   rP   	bytearrayrQ   )r   r   r  emptyr   r   r   test_sum  s*    $zBuiltinTest.test_sumc             C   s,   |  tdtd | tdtd d S )Nr,   r)  r   )r=   r>   assertNotEqual)r   r   r   r   	test_type$  s    zBuiltinTest.test_typec               C   s   t  S )N)varsr   r   r   r   get_vars_f0*  s    zBuiltinTest.get_vars_f0c              C   s   t   d} d}t S )Nr   rJ   )r9   r  r  )rT   r   r   r   r   get_vars_f2.  s    zBuiltinTest.get_vars_f2c               @   s   e Zd Zdd ZeedZdS )zBuiltinTest.C_get_varsc             C   s   ddiS )NrT   rJ   r   )r   r   r   r   getDict6  s    zBuiltinTest.C_get_vars.getDict)fgetN)r   r   r   r  propertyr   r   r   r   r   
C_get_vars5  s   r  c             C   s   |  tt tt  |  tttttt |  |  i  |  |  ddd | ttdd | ttd |  t| 	 ddi d S )Nr   rJ   )rT   r   r`   rT   )
r=   setr  r   rF   r  r  rN   rP   r  )r   r   r   r   	test_vars:  s    zBuiltinTest.test_varsc             C   sN  d}d}dddg}|  tt||| dddg}|  tt||| d	}|  tt||| G d
d d}|  tt|| | |  tt g  |  ttg  g  | ttd  G dd d}| tt||  | tt|t  G dd d}|  tt| tdtttd G dd d}| t	tt| |  d S )N)r   rJ   rK   )rL   r   r]   )r   rL   )rJ   r   )rK   r]   rL   r   r]   )rL   r   r]   r   c               @   s   e Zd Zdd ZdS )zBuiltinTest.test_zip.<locals>.Ic             S   s   |dk s|dkrt |d S )Nr   rJ   rL   )r   )r   r   r   r   r   r   M  s     z+BuiltinTest.test_zip.<locals>.I.__getitem__N)r   r   r   r   r   r   r   r   IL  s   r  c               @   s   e Zd ZdS )zBuiltinTest.test_zip.<locals>.GN)r   r   r   r   r   r   r   GT  s   r  c               @   s   e Zd Zdd ZdS )z4BuiltinTest.test_zip.<locals>.SequenceWithoutALengthc             S   s   |dkrt n|S d S )Nr   )r   )r   r   r   r   r   r   ]  s    z@BuiltinTest.test_zip.<locals>.SequenceWithoutALength.__getitem__N)r   r   r   r   r   r   r   r   SequenceWithoutALength\  s   r  i   @c               @   s   e Zd Zdd ZdS )z$BuiltinTest.test_zip.<locals>.BadSeqc             S   s   |dkrt n|S d S )Nr   )rQ   )r   r   r   r   r   r   h  s    z0BuiltinTest.test_zip.<locals>.BadSeq.__getitem__N)r   r   r   r   r   r   r   r   r  g  s   r  )
r=   r?   ziprN   rP   r/   r1   r
  	enumeraterQ   )r   rT   r   r  r  r  r  r  r   r   r   test_zipC  s,    

zBuiltinTest.test_zipc             C   sF   d}d}dddg}x.t tjd D ]}t||}| ||| q"W d S )N)r   rJ   rK   )rL   r   r]   )r   rL   )rJ   r   )rK   r]   r   )r
  r:   r  r  rE   )r   rT   r   r  rD   Zz1r   r   r   test_zip_pickleo  s    

zBuiltinTest.test_zip_picklec          
      s    tddd dd } fdd}||    fdd	}|d
 |d |d |d |d |d |t |d  G dd d} tt| d  ttt d  ttt t  t d} |d  tt jd  tt jt   tt jd  G dd d}  t| d   t| dd   t| dd G dd d}G dd dt}xrt||gD ]d}	|	 }
  t|
t|
   t|
dt|
  	tdt
|	j  t|
d W d Q R X qW G dd dt}  td|dd  d S )!NrK   r,   r;  c              S   s\   G dd dt } G dd d| }G dd dt }G dd d|}G d	d
 d
|}| |||fS )Nc               @   s   e Zd Zdd Zdd ZdS )z7BuiltinTest.test_format.<locals>.classes_new.<locals>.Ac             S   s
   || _ d S )N)rb   )r   rb   r   r   r   r     s    z@BuiltinTest.test_format.<locals>.classes_new.<locals>.A.__init__c             S   s   t | j| S )N)r    rb   )r   format_specr   r   r   
__format__  s    zBBuiltinTest.test_format.<locals>.classes_new.<locals>.A.__format__N)r   r   r   r   r  r   r   r   r   r     s   r   c               @   s   e Zd ZdS )zBBuiltinTest.test_format.<locals>.classes_new.<locals>.DerivedFromAN)r   r   r   r   r   r   r   DerivedFromA  s   r  c               @   s   e Zd ZdS )z<BuiltinTest.test_format.<locals>.classes_new.<locals>.SimpleN)r   r   r   r   r   r   r   Simple  s    r  c               @   s   e Zd Zdd Zdd ZdS )zGBuiltinTest.test_format.<locals>.classes_new.<locals>.DerivedFromSimplec             S   s
   || _ d S )N)rb   )r   rb   r   r   r   r     s    zPBuiltinTest.test_format.<locals>.classes_new.<locals>.DerivedFromSimple.__init__c             S   s   t | j| S )N)r    rb   )r   r  r   r   r   r    s    zRBuiltinTest.test_format.<locals>.classes_new.<locals>.DerivedFromSimple.__format__N)r   r   r   r   r  r   r   r   r   DerivedFromSimple  s   r  c               @   s   e Zd ZdS )zHBuiltinTest.test_format.<locals>.classes_new.<locals>.DerivedFromSimple2N)r   r   r   r   r   r   r   DerivedFromSimple2  s    r  )r[   )r   r  r  r  r  r   r   r   classes_new~  s    z,BuiltinTest.test_format.<locals>.classes_newc                s\     t| ddd   t|ddd   t|ddd   t|d	d
d d S )NrK   specZ3specrL   Z4specr   abcZ5abcr)   ZabcdefZ10abcdef)r=   format)r   r  r  r  )r   r   r   
class_test  s
    z+BuiltinTest.test_format.<locals>.class_testc                s.     t| dt|    t| t|  d S )Nr,   )r=   r  r    )r   )r   r   r   empty_format_spec  s    z2BuiltinTest.test_format.<locals>.empty_format_specl   .@g      ?g]]^Ug]]^g;q7r*g;q7rc               @   s   e Zd Zdd ZdS )z0BuiltinTest.test_format.<locals>.BadFormatResultc             S   s   dS )Ng      ?r   )r   r  r   r   r   r    s    z;BuiltinTest.test_format.<locals>.BadFormatResult.__format__N)r   r   r   r  r   r   r   r   BadFormatResult  s   r  rL   z<object object atc               @   s   e Zd Zdd ZdS )z"BuiltinTest.test_format.<locals>.Ac             S   s
   t d|S )Nr,   )r  )r   Zfmt_strr   r   r   r    s    z-BuiltinTest.test_format.<locals>.A.__format__N)r   r   r   r  r   r   r   r   r     s   r   rn   c               @   s   e Zd ZdS )z"BuiltinTest.test_format.<locals>.BN)r   r   r   r   r   r   r   r    s   r  c               @   s   e Zd ZdS )z"BuiltinTest.test_format.<locals>.CN)r   r   r   r   r   r   r   r     s   r   z\b%s\bc               @   s   e Zd ZdS )z/BuiltinTest.test_format.<locals>.DerivedFromStrN)r   r   r   r   r   r   r   DerivedFromStr  s    r  r   r(   z
         0)r=   r  r[   rN   rP   r  rY   
startswithr    r   reescaper   )r   r  r  r  r  rb   r   r  r   clsobjr  r   )r   r   test_formatw  sJ    
zBuiltinTest.test_formatc             C   s   |  tdd |  tdd |  tdd |  tdd d	 |  tdd d d
 |  tdd  d |  tdd d  d d S )Nr   Z0b0r   Z0b1r   z-0b1rJ   r   ZD0b100000000000000000000000000000000000000000000000000000000000000000ZC0b11111111111111111111111111111111111111111111111111111111111111111zE-0b100000000000000000000000000000000000000000000000000000000000000000zD-0b11111111111111111111111111111111111111111111111111111111111111111)r=   bin)r   r   r   r   test_bin  s    zBuiltinTest.test_binc             C   s0   t d}| t|jdd | t|jdd d S )Ns   abc   1r   s   1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111)r  rN   rQ   	translaterP   )r   rb   r   r   r   test_bytearray_translate  s    z$BuiltinTest.test_bytearray_translatec             C   sP   xJd t tfD ]<}t|}| | | | t|dd | jt|ddd qW d S )Nr   rJ   )rT   r   )EllipsisNotImplementedr>   assertIsrN   rP   )r   consttpr   r   r   test_construct_singletons  s
    z%BuiltinTest.test_construct_singletonsN)Mr   r   r   rE   rS   r\   rg   rk   rt   rw   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r   r#  r&  r(  r0  r8  r9  rE  rG  rK  rM  rT  rX  unittestskipIfrF   flags	utf8_moderc  rg  rn  rp  rx  ry  r  platformsystemr  machineZlinux_alphar  Zsystem_round_bugr  r  r  r  r  staticmethodr  r  r[   r  r  r  r  r  r  r  r  r   r   r   r   r9      s   #"1ME$	
"<441%Q
		,e	r9   c               @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Ze	
ejjddd Ze	
ejjddd Ze	
ejjddd Zdd Ze	
ejjddd Zdd ZdS )TestBreakpointc             C   sH   t  | _| | jj | jt | _| jd= | jttdtj	 d S )NPYTHONBREAKPOINTbreakpointhook)
r   	resourcesrR  rt  enter_contextr   envr   rF   __breakpointhook__)r   r   r   r   setUp  s    zTestBreakpoint.setUpc          	   C   s&   t d}t  W d Q R X |  d S )Nzpdb.set_trace)r   
breakpointZassert_called_once)r   mockr   r   r   test_breakpoint  s    
zTestBreakpoint.test_breakpointc             C   s   t  }|t_t  |  d S )N)r
   rF   r  r  assert_called_once_with)r   my_breakpointhookr   r   r   'test_breakpoint_with_breakpointhook_set  s    z6TestBreakpoint.test_breakpoint_with_breakpointhook_setc          	   C   sP   t  }|t_t  |  tjt_td}t  |  W d Q R X |  d S )Nzpdb.set_trace)r
   rF   r  r  r  r  r   )r   r  r  r   r   r   )test_breakpoint_with_breakpointhook_reset  s    
z8TestBreakpoint.test_breakpoint_with_breakpointhook_resetc             C   s6   t  }|t_tdddddd |jdddddd d S )Nr   rJ   rK   rL   r   )fourfive)r
   rF   r  r  r  )r   r  r   r   r   &test_breakpoint_with_args_and_keywords  s    z5TestBreakpoint.test_breakpoint_with_args_and_keywordsc          	   C   s*   dd }|t _| jttdddddd d S )	Nc               S   s   d S )Nr   r   r   r   r   r    s    zMTestBreakpoint.test_breakpoint_with_passthru_error.<locals>.my_breakpointhookr   rJ   rK   rL   r   )r  r  )rF   r  rN   rP   r  )r   r  r   r   r   #test_breakpoint_with_passthru_error  s    z2TestBreakpoint.test_breakpoint_with_passthru_errorz-E was givenc          	   C   s4   d| j d< td}td |d W d Q R X d S )Nrv   r  zbuiltins.int7)r  r   r  r  )r   r  r   r   r   test_envar_good_path_builtin$  s    

z+TestBreakpoint.test_envar_good_path_builtinc          	   C   s0   d| j d< td}t  |  W d Q R X d S )Nzsys.exitr  )r  r   r  r  )r   r  r   r   r   test_envar_good_path_other+  s    

z)TestBreakpoint.test_envar_good_path_otherc          	   C   s0   d| j d< td}t  |  W d Q R X d S )Nr$   r  zpdb.set_trace)r  r   r  assert_not_called)r   r  r   r   r   test_envar_good_path_noop_02  s    

z*TestBreakpoint.test_envar_good_path_noop_0c          	   C   s0   d| j d< td}t  |  W d Q R X d S )Nr,   r  zpdb.set_trace)r  r   r  r  )r   r  r   r   r   !test_envar_good_path_empty_string9  s    

z0TestBreakpoint.test_envar_good_path_empty_stringc          
   C   s   xdD ]~}| j |dh || jd< | jtd}| jtdd}t  | t|j	d| d | |j
t |  W d Q R X qW d S )	N).z..z.foozfoo.z.intzint.z.foo.barz	..foo.barz/./Znosuchbuiltinznosuchmodule.nosuchcallable)envarr  zpdb.set_traceT)quietz*Ignoring unimportable $PYTHONBREAKPOINT: "rq   )subTestr  r  r  r   r   r  r=   r    messagecategoryRuntimeWarningr  )r   r  r  rN  r   r   r   test_envar_unimportable@  s    
z&TestBreakpoint.test_envar_unimportablec          	   C   s6   d| j d< td}tt_t  |  W d Q R X d S )Nzsys.exitr  )r  r   rv   rF   r  r  r  )r   r  r   r   r   #test_envar_ignored_when_hook_is_setS  s
    

z2TestBreakpoint.test_envar_ignored_when_hook_is_setN)r   r   r   r  r  r  r  r  r  r  r  rF   r  ignore_environmentr  r  r  r  r  r  r   r   r   r   r    s   r  z,the pty and signal modules must be availablec               @   s>   e Zd Zdd ZdddZdd Zdd	 Zd
d Zdd ZdS )PtyTestsc          
   C   s  t  \}}yt \}}W nL ttfk
rh } z*t | t | | d|  W d d }~X Y nX |dkrzPy6t	
d t | t|d}|| W d Q R X W n   t  Y nX W d t d X t | t || t|d2}	g }
x&|	  }|dkrP |
| qW W d Q R X t|
dkrt }xByt |d}W n tk
rf   P Y nX |spP || q>W t | |dd	}| d
t|
|f  t | t |d |
S )Nzpty.fork() raised {}r   rJ   rN  rU  r,   i  rl   r   z9got %d lines in pipe but expected 2, child output was:
%s)r\  pipeptyforkOSErrorr  rt  skipTestr  signalalarmrQ  	traceback	print_exc_exitr#   rV  r   r   r   r  rW  extenddecoderA  waitpid)r   childterminal_inputrU  rN  pidfdr%  wpipeZrpipelinesr"   Zchild_outputchunkr   r   r   	run_child`  sV    







zPtyTests.run_childNc                s   t j rt j s| d  fdd}| ||d }| |d ddh |d dkrf| d t|d	 }r|d
}n|t jj	}| 
|| d S )Nzstdin and stdout must be ttysc                sj   r4t jtj ddt_t jtj ddt_tdtj oJtj | d ttt	 | d d S )Nsurrogateescape)r`  errorsreplaceztty =)file)
ru  TextIOWrapperrF   rr  detachr   printisattyrl   rs  )r  )rq  stdio_encodingr   r   r    s    

z'PtyTests.check_input_tty.<locals>.childs   
r   z
tty = Trueztty = Falsez%standard IO in should have been a ttyr   r  )rF   rr  r  r   r  r   r   r   r  r`  r=   )r   rq  r  r	  r  r  Zinput_resultr   r   )rq  r	  r   check_input_tty  s    

zPtyTests.check_input_ttyc             C   s   |  dd d S )Nrq  s   quux)r
  )r   r   r   r   test_input_tty  s    zPtyTests.test_input_ttyc             C   s   |  ddd d S )Nu   promptés   quuxzutf-8)r
  )r   r   r   r   test_input_tty_non_ascii  s    z!PtyTests.test_input_tty_non_asciic             C   s   |  ddd d S )Nu   promptés   quuxrl   )r
  )r   r   r   r   'test_input_tty_non_ascii_unicode_errors  s    z0PtyTests.test_input_tty_non_ascii_unicode_errorsc             C   s(   dd }|  |d}d}| || d S )Nc             S   sB   t dtj | d t t_td t dttj	 | d d S )Nzstdin.isatty():)r  rq  z	captured:)
r  rF   rr  r  ru  rv  r   rs  rl   getvalue)r  r   r   r   r    s    
z3PtyTests.test_input_no_stdout_fileno.<locals>.childs   quux)zstdin.isatty(): Truezcaptured: 'prompt')r   ZassertSequenceEqual)r   r  r  r   r   r   r   test_input_no_stdout_fileno  s    z$PtyTests.test_input_no_stdout_fileno)N)	r   r   r   r   r
  r  r  r  r  r   r   r   r   r  [  s   :
r  c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )

TestSortedc             C   s   t td}|d d  }t| | |t| | || |  t| | |t|dd d | || t| | |t|dd | || d S )Nr+   c             S   s   |  S )Nr   )rb   r   r   r   ry     r   z'TestSorted.test_basic.<locals>.<lambda>)r   r   )reverse)r?   r
  r=  Zshuffler=   r   r  r  )r   rD  copyr   r   r   
test_basic  s    


zTestSorted.test_basicc          	   C   sX   t g  | t t g d W d Q R X t g d d | t t g d  W d Q R X d S )N)iterable)r   )r   rN   rP   )r   r   r   r   test_bad_arguments  s    zTestSorted.test_bad_argumentsc             C   s~   d}t ttg}x$|D ]}| t|t|| qW dt|}tttt ttj	g}x$|D ]}| t|t|| qZW d S )NZabracadabrar,   )
r?   r   r    r=   r   joinr  	frozensetr   fromkeys)r   rn   r   Tr   r   r   test_inputtypes  s    


zTestSorted.test_inputtypesc             C   s"   d  }| tt|d dd  d S )Nz,The quick Brown fox Jumped over The lazy Dogc             S   s   dS )Nr   r   )rb   rx   r   r   r   ry     r   z.TestSorted.test_baddecorator.<locals>.<lambda>)splitrN   rP   r   )r   rD  r   r   r   test_baddecorator  s    zTestSorted.test_baddecoratorN)r   r   r   r  r  r  r  r   r   r   r   r    s   
r  c               @   s   e Zd Zdd ZdS )ShutdownTestc             C   s4   d}t d|dd\}}}| ddg|   d S )Naf  if 1:
            import builtins
            import sys

            class C:
                def __del__(self):
                    print("before")
                    # Check that builtins still exist
                    len(())
                    print("after")

            c = C()
            # Make this module survive until builtins and sys are cleaned
            builtins.here = sys.modules[__name__]
            sys.here = sys.modules[__name__]
            # Create a reference loop so that this module needs to go
            # through a GC phase.
            here = sys.modules[__name__]
            z-crl   )ZPYTHONIOENCODINGZbeforeZafter)r	   r=   r  
splitlines)r   r   Zrcouterrr   r   r   test_cleanup  s    zShutdownTest.test_cleanupN)r   r   r   r!  r   r   r   r   r    s   r  c               @   sL   e Z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 )TestTypec             C   sn  t ddi }| |jd | |jd | |jt | |jtf | |jt | }| t || | |j	| G dd d}t d|t
fddd i}| |jd | |jd | |jt | |j|t
f | |jt
 | d|j | d	|j |d
}| |d
 | t || | |j	| | | d | | d | |ddd d S )Nr   r   c               @   s   e Zd Zdd ZdS )z!TestType.test_new_type.<locals>.Bc             S   s   d|  S )Nzham%dr   )r   r   r   r   r  *  s    z%TestType.test_new_type.<locals>.B.hamN)r   r   r   r  r   r   r   r   r  )  s   r  r   r   c             S   s   d|  S )Nzspam%sr   )r   r   r   r   ry   ,  r   z(TestType.test_new_type.<locals>.<lambda>r  r`   Zham42Zspam42rJ   littles   * )r>   r=   r   r   r   	__bases__r[   r  __base__r   rv   r   r   r   r  r   to_bytes)r   r   rb   r  r   r   r   r   test_new_type  s2    zTestType.test_new_typec          	   C   sN   |  t tddi dd W d Q R X |  t tddi d W d Q R X d S )NrT   r   r   )rb   )r   )rN   rP   r>   )r   r   r   r   test_type_nokwargs<  s    zTestType.test_type_nokwargsc          
   C   s  xZdD ]R}| j |d< t|di }| |j| | |j| | |jt W d Q R X qW | t tddi  W d Q R X | t tddi  W d Q R X | t tddi  W d Q R X tddi }xTdD ]L}| j |d6 ||_| |j| | |jd | |jt W d Q R X qW tddi }| t d|_W d Q R X | |jd | t d|_W d Q R X | |jd | t d|_W d Q R X | |jd d S )N)r      Äu   🐍zB.A42r,   )rH   r   zA Bu   ABrk  r   )	r  r>   r=   r   r   r   rN   rQ   rP   )r   rH   r   r   r   r   r   test_type_nameB  s:    

zTestType.test_type_namec          	   C   s   t ddddi}| |jd | |jd | |jt | t t ddddi W d Q R X | |jd d|_| |jd | |jd | t d|_W d Q R X | |jd d S )Nr   r   r   zB.C   BzD.E)r>   r=   r   r   r   rN   rP   )r   r   r   r   r   test_type_qualnamec  s    zTestType.test_type_qualnamec          	   C   s   x*dD ]"}t ddd|i}| |j| qW | t t ddddi W d Q R X t ddi }| |jd  x dD ]}||_| |j| qrW d S )N)rb   r)  u   🐍zx y   xr`   Nr   r   r   u   xy)rb   r)  u   🐍zx yu   xyr.  r`   N)r>   r=   r   rN   UnicodeEncodeError)r   r   r   r   r   r   test_type_docs  s    

zTestType.test_type_docc          	   C   s>  |  t t  W d Q R X |  t tdd W d Q R X |  t tddi d W d Q R X |  t tddi d W d Q R X |  t tdg i  W d Q R X |  t tddti  W d Q R X |  t tddi  W d Q R X |  t tdtfi  W d Q R X |  t tdttfi  W d Q R X d S )Nr   r   )r   )N)rN   rP   r>   r   MappingProxyTypeboolrv   r    )r   r   r   r   test_bad_args  s$    zTestType.test_bad_argsc          	   C   s  |  t tddddi W d Q R X |  t tdtfddi W d Q R X |  t tddddi W d Q R X |  t tddddi W d Q R X |  t tddddi W d Q R X |  t tdddd	d
 W d Q R X |  t tddddi W d Q R X |  t tddddi W d Q R X G dd d}|  t td|fddi W d Q R X |  t td|fddi W d Q R X d S )Nr   r   r   r.  rb   r,   r*  zx yr   )r   rb   )r   r   )__weakref__r4  c               @   s   e Zd ZdS )z"TestType.test_bad_slots.<locals>.BN)r   r   r   r   r   r   r   r    s   r  r   r4  )rN   rP   r>   rv   rQ   )r   r  r   r   r   test_bad_slots  s*    zTestType.test_bad_slotsc             C   sV   t ddg}|d t| }tdd|}| t|j d d ddg d S )N)rT   r   )r   rJ   rT   r   r   rJ   )r   OrderedDictmove_to_endr?   itemsr>   r=   r   )r   Zodr   r   r   r   r   test_namespace_order  s
    
zTestType.test_namespace_orderN)r   r   r   r'  r(  r+  r-  r0  r3  r5  r9  r   r   r   r   r"    s   !r"  c             C   s   ddl m} ||t |S )Nr   )DocTestSuite)Zdoctestr:  ZaddTestr   )loaderZtestspatternr:  r   r   r   
load_tests  s    r=  __main__)<r   r   r   r  r  ru  r^  r\  r:   r  r=  r  rF   r  r   r  r   
contextlibr   operatorr   Ztest.supportr   r   r   r   r   Ztest.support.script_helperr	   Zunittest.mockr
   r   r  r  rO   r   r   r!   rm   rZ   rQ   r    r7   Ztest_conv_no_signZtest_conv_signr.   r1   r6   r8   ZTestCaser9   r  Z
skipUnlessr  r  r  r"  r=  r   mainr   r   r   r   <module>   s             |i
t+" 
