a
    ,=ic                     @   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re  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D}zt|  W n  ty>   Y W d    dS 0 W d    n1 sT0    Y  dS )NrFT)openastparsereadSyntaxError)filepathf r   h/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/pasta/base/codegen_test.py_is_syntax_valid"   s    2r   c                   @   s   e Zd Zdd ZdS )AutoFormatTestMetac                 C   s   dd }d}t jtd}t |D ]V\}}}	|	D ]F}
|
dr2t j||
}tt| d|||||
d d  < q2q$t	
| |||S )Nc                    s    fdd}|S )Nc                    sV   t  d}| }W d    n1 s(0    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   s$   d}t |}| dt| d S )Nzexec foo in barzexec(foo, bar)
r5   r9   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'
r5   r9   r   r   r   
test_bytesT   s    
zAutoFormatTest.test_bytesc                 C   sV   dD ]L}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<   rA   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    rD   __main__)rB   
__future__r   r   r   r
   os.pathr   r$   sixr   r7   Z
pasta.baser   r   r   realpathr    dirname__file__r!   r   r%   r   ZTestCaser4   rD   r1   mainr   r   r   r   <module>   s&   	