o
    e                     @   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rle  dS dS )z3Tests for generating code from a non-annotated ast.    )absolute_import)division)print_functionN)with_metaclass)codegen)
test_utilsz../testdatac              	   C   sd   t | d#}z	t|  W n ty   Y W d    dS w W d    dS 1 s+w   Y  dS )NrFT)openastparsereadSyntaxError)filepathf r   GD:\Projects\ConvertPro\env\Lib\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}t |D ]+\}}}	|	D ]#}
|
dr<t j||
}tt| d|||||
d d  < qqt	
| |||S )Nc                    s    fdd}|S )Nc                    sV   t  d}| }W d    n1 sw   Y  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   $   d}t |}| dt| d S )Nzexec foo in barzexec(foo, bar)
r5   r9   r   r   r   test_exec_node_defaultN      
z%AutoFormatTest.test_exec_node_defaultZ
bytes_nodec                 C   r;   )Nzb'foo'zb'foo'
r5   r9   r   r   r   
test_bytesT   r=   zAutoFormatTest.test_bytesc                 C   sV   dD ]&}d| d }t |}|jtdj | t||d | d  qd S )N)z  z    	z	def a():
zb
z
def c(): dz	def c():
zd
)r7   r   bodyextendr
   r6   r   r   )r   indentr   r   r   r   r   test_default_indentationZ   s   
z'AutoFormatTest.test_default_indentationN)
r1   r2   r3   __doc__r:   r   Zrequires_featuresr<   r>   rC   r   r   r   r   r4   F   s    

r4   c                  C   s   t  } | t t | S )N)r$   Z	TestSuiteZaddTestsZ	makeSuiter4   )resultr   r   r   suitec   s   rF   __main__)rD   
__future__r   r   r   r
   Zos.pathr   r$   sixr   r7   Z
pasta.baser   r   r   realpathr    dirname__file__r!   r   r%   r   ZTestCaser4   rF   r1   mainr   r   r   r   <module>   s*   	