B
    ­»ˆdñ  ã               @   sØ   d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddl	m
Z
 ddlZddlmZ ddlmZ ej ej ej ej¡d	¡¡Zd
d„ ZG dd„ deƒZG dd„ de
eejƒƒZdd„ ZedkrÔe ¡  dS )z3Tests for generating code from a non-annotated ast.é    )Úabsolute_import)Údivision)Úprint_functionN)Úwith_metaclass)Úcodegen)Ú
test_utilsz../testdatac          	   C   sB   t | dƒ.}yt | ¡ ¡ W n tk
r2   dS X W d Q R X dS )NÚrFT)ÚopenÚastÚparseÚreadÚSyntaxError)ÚfilepathÚf© r   úI/var/www/html/venv/lib/python3.7/site-packages/pasta/base/codegen_test.pyÚ_is_syntax_valid"   s    r   c               @   s   e Zd Zdd„ ZdS )ÚAutoFormatTestMetac             C   s”   dd„ }d}t j td¡}xht  |¡D ]Z\}}}	xN|	D ]F}
|
 d¡r6t j ||
¡}t t|ƒ d¡||ƒƒ|||
d d…  < q6W q&W t	 
| |||¡S )Nc                s   ‡ fdd„}|S )Nc          	      sB   t ˆ dƒ}| ¡ }W d Q R X t |¡}t |¡}|  ||¡ d S )Nr   )r	   r   r
   r   r   Úto_strZassertMultiLineEqual)ÚselfÚhandleÚsrcÚtZauto_formatted)Ú
input_filer   r   Útest0   s
    

zLAutoFormatTestMeta.__new__.<locals>.auto_format_test_generator.<locals>.testr   )r   r   r   )r   r   Úauto_format_test_generator/   s    z>AutoFormatTestMeta.__new__.<locals>.auto_format_test_generatorZtest_auto_format_r   z.inz3Test contains syntax not supported by this version.éýÿÿÿ)ÚosÚpathÚjoinÚTESTDATA_DIRÚwalkÚendswithÚunittestZskipIfr   ÚtypeÚ__new__)ÚmcsÚnameÚbasesÚ	inst_dictr   Ztest_method_prefixÚdata_dirÚdirpathÚ_ÚfilesÚfilenameÚ	full_pathr   r   r   r%   -   s    


"zAutoFormatTestMeta.__new__N)Ú__name__Ú
__module__Ú__qualname__r%   r   r   r   r   r   +   s   r   c               @   sD   e Zd ZdZdd„ Ze d¡dd„ ƒZe d¡dd	„ ƒZd
d„ Z	dS )ÚAutoFormatTestz:Tests that code without formatting info is printed neatly.c             C   s$   d}t  |¡}|  |t |¡¡ d S )Nz1from a import b
import c, d
from ..e import f, g
)r
   r   ÚassertEqualÚpastaÚdump)r   r   r   r   r   r   Útest_importsI   s    
zAutoFormatTest.test_importsZ	exec_nodec             C   s$   d}t  |¡}|  dt |¡¡ d S )Nzexec foo in barzexec(foo, bar)
)r
   r   r4   r5   r6   )r   r   r   r   r   r   Útest_exec_node_defaultN   s    
z%AutoFormatTest.test_exec_node_defaultZ
bytes_nodec             C   s$   d}t  |¡}|  dt |¡¡ d S )Nzb'foo'zb'foo'
)r
   r   r4   r5   r6   )r   r   r   r   r   r   Ú
test_bytesT   s    
zAutoFormatTest.test_bytesc             C   sZ   xTdD ]L}d| d }t  |¡}|j t d¡j¡ |  t |¡|d | d ¡ qW d S )N)z  z    ú	z	def a():
zb
z
def c(): dz	def c():
zd
)r5   r   ÚbodyÚextendr
   r4   r   r   )r   Úindentr   r   r   r   r   Útest_default_indentationZ   s    

z'AutoFormatTest.test_default_indentationN)
r0   r1   r2   Ú__doc__r7   r   Zrequires_featuresr8   r9   r>   r   r   r   r   r3   F   s
   r3   c              C   s   t  ¡ } |  t  t¡¡ | S )N)r#   Z	TestSuiteZaddTestsZ	makeSuiter3   )Úresultr   r   r   Úsuitec   s    rA   Ú__main__)r?   Ú
__future__r   r   r   r
   Úos.pathr   r#   Úsixr   r5   Z
pasta.baser   r   r   Úrealpathr   ÚdirnameÚ__file__r    r   r$   r   ZTestCaser3   rA   r0   Úmainr   r   r   r   Ú<module>   s$   	