B
    u9a~                 @   sj   d Z ddlZddlmZ ddlmZmZ ddlZerDddlZdd Z	G dd dej
Zed	krfe  dS )
z/
   Test cases for codeop.py
   Nick Mathewson
    N)	is_jython)compile_commandPyCF_DONT_IMPLY_DEDENTc             C   s,   x&|   D ]\}}t|dr
d| |< q
W | S )N__call__T)itemshasattr)dnv r   !/usr/lib/python3.7/test_codeop.pyunify_callables   s    
r   c               @   sJ   e Zd ZdddZdddZdddZd	d
 Zdd Zdd Zdd Z	dS )CodeopTestssinglec       	      C   s   t rt|d|}| | |dkrhi i  }}tj}t t_z t|| tt|dd| W d|t_X n,|dkrddi}dt	||i}dt	||i}| 
t|t| n"t|d|t}| 
t|d|| dS )z(succeed iff str is a valid piece of codez<input>r   Nevala   value)r   r   
assertTruesysstdoutioStringIOexeccompiler   assertEqualr   r   )	selfstrsymbolcoder   rZsaved_stdoutZctxZexpectedr   r   r   assertValid   s$    




zCodeopTests.assertValidc             C   s   |  t||dd dS )z5succeed iff str is the start of a valid piece of code)r   N)r   r   )r   r   r   r   r   r   assertIncomplete-   s    zCodeopTests.assertIncomplete   c             C   s\   yt ||d | d W n< tk
r8   | | Y n  tk
rV   | |  Y nX dS )z8succeed iff str is the start of an invalid piece of code)r   z$No exception raised for invalid codeN)r   ZfailSyntaxErrorr   OverflowError)r   r   r   Z	is_syntaxr   r   r   assertInvalid1   s    zCodeopTests.assertInvalidc             C   s  | j }ts@| tdtdddt | tdtdddt n|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 |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 )'N passz<input>r   
za = 1z
a = 1za = 1
za = 1

z	

a = 1

zdef x():
  pass
zif 1:
 pass
z

if 1: pass
z

if 1: pass

zdef x():

 pass
zdef x():
  pass
  
zdef x():
  pass
 
zpass
z3**3
zif 9==3:
   pass
else:
   pass
z(if 1:
 pass
 if 1:
  pass
 else:
  pass
z#a
#b
a = 3
z#a

   
a=3
za=3

z
a = 9+ \
3z3**3r   z(lambda z: 
 z**3)z9+ \
3z9+ \
3
z

a**3z
 
a**3z
#a
#b
a**3z

if 1: a=1

z#a

   
a=3

z1def f():
 try: pass
 finally: [x for x in (1,2)]
zdef f():
 pass
#foo
z@a.b.c
def f():
 pass
)r!   r   r   r   r   r   )r   avr   r   r   
test_valid;   s^    












zCodeopTests.test_validc             C   sH  | j }|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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- |d. |d/ |d0 |d1 |d2 |d3 |d4 |d5 |d6 |d7 |d8 |d9 |d: |d; |d< |d= |d> |d? |d@ |dA |dB |dC |dD |dE |dF |dG |dH |dI |dJ |d |dK |dL |dM |d |dN |dO |dP |dQ |dR |dS |dT |dU |dV |dW |dX |dY |dZ |d[ |d\ |d] |d^ |d_ |d` |da |db |dc |dd d S )eNz(a **z(a,b,z(a,b,(za = (za = {zb + {zif 9==3:
   pass
else:zif 9==3:
   pass
else:
zif 9==3:
   pass
else:
   passzif 1:zif 1:
z if 1:
 pass
 if 1:
  pass
 else:z!if 1:
 pass
 if 1:
  pass
 else:
z'if 1:
 pass
 if 1:
  pass
 else:
  passzdef x():z	def x():
z
def x():

zdef x():
  passzdef x():
  pass
 zdef x():
  pass
  z

def x():
  passza = 9+ \za = 'a\z	a = '''xyr'   r   r)   (z(


z(9+z9+ \zlambda z: \z!if True:
 if True:
  if True:   
z@a(z@a(bz@a(b,z@a(b,cz@a(b,c,zfrom a import (zfrom a import (bzfrom a import (b,zfrom a import (b,czfrom a import (b,c,[z[az[a,z[a,bz[a,b,{z{az{a:z{a:bz{a:b,z{a:b,cz{a:b,c:z{a:b,c:dz	{a:b,c:d,za(za(bza(b,za(b,cza(b,c,za[za[bza[b,za[b:za[b:cza[b:c:za[b:c:dzdef a(zdef a(bzdef a(b,z	def a(b,cz
def a(b,c,z(az(a,z(a,bzif a:
 pass
elif b:zif a:
 pass
elif b:
 pass
else:zwhile a:zwhile a:
 pass
else:zfor a in b:zfor a in b:
 pass
else:ztry:ztry:
 pass
except:ztry:
 pass
finally:z!try:
 pass
except:
 pass
finally:zwith a:zwith a as b:zclass a:zclass a(z	class a(bz
class a(b,z
class a():z[x forz[x for x inz[x for x in (z(x forz(x for x inz(x for x in ()r"   )r   air   r   r   test_incomplete}   s    






zCodeopTests.test_incompletec             C   s   | j }|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d |d |d |d |d |d |d |d d S )Nza bza @za b @za ** @za = za = 9 +zdef x():

pass
z

 if 1: pass

passz	a = 9+ \
za = 'a\ za = 'a\
za = 1r   za = (]z())z[}z9+z	lambda z:z
return 2.3zif (a == 1 and b = 2): passzdel 1zdel (1,)zdel [1]zdel '1'z"[i for i in range(10)] = (1, 2, 3))r&   )r   r/   r   r   r   test_invalid   s6    







zCodeopTests.test_invalidc             C   s@   |  tddjtdddj | tddjtdddj d S )Nza = 1
abcr   def)r   r   co_filenamer   ZassertNotEqual)r   r   r   r   test_filename#  s    zCodeopTests.test_filenameN)r   )r   )r   r#   )
__name__
__module____qualname__r!   r"   r&   r+   r0   r2   r6   r   r   r   r   r      s   



B &r   __main__)__doc__ZunittestZtest.supportr   Zcodeopr   r   r   r   r   ZTestCaser   r7   mainr   r   r   r   <module>   s     