o
    o^                     @   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   7lib/python3.10/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)selfZ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__)ZmcsnamebasesZ	inst_dictr   Ztest_method_prefixZ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)
r1   r5   r   r   r   test_exec_node_defaultN      
z%AutoFormatTest.test_exec_node_defaultZ
bytes_nodec                 C   r7   )Nzb'foo'zb'foo'
r1   r5   r   r   r   
test_bytesT   r9   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
)r3   r   bodyextendr
   r2   r   r   )r   indentr   r   r   r   r   test_default_indentationZ   s   
z'AutoFormatTest.test_default_indentationN)
r-   r.   r/   __doc__r6   r   Zrequires_featuresr8   r:   r?   r   r   r   r   r0   F   s    

r0   c                  C   s   t  } | t t | S )N)r#   Z	TestSuiteZaddTestsZ	makeSuiter0   )resultr   r   r   suitec   s   rB   __main__)r@   Z
__future__r   r   r   r
   Zos.pathr   r#   Zsixr   r3   Z
pasta.baser   r   r   realpathr   dirname__file__r    r   r$   r   ZTestCaser0   rB   r-   mainr   r   r   r   <module>   s*   	