o
    JAfl                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
 ejejedZejedZG dd dejZedkrOe
  dS dS )    N)maindatazpy2_test_grammar.pyc                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )TestMainc                 C   s
   d | _ d S N)temp_dirself r	   ./usr/lib/python3.10/lib2to3/tests/test_main.pysetUp   s   
zTestMain.setUpc                 C   s(   t jjd d = | jrt| j d S d S r   )loggingroothandlersr   shutilrmtreer   r	   r	   r
   tearDown   s   zTestMain.tearDownc                 C   sZ   t j}t j}t j}|t _|t _|t _ztd|W |t _|t _|t _S |t _|t _|t _w )Nzlib2to3.fixes)sysstdinstdoutstderrr   )r   argsZ
in_captureZout_captureZerr_captureZ
save_stdinZsave_stdoutZsave_stderrr	   r	   r
   run_2to3_capture   s   zTestMain.run_2to3_capturec                 C   st   t d}t  }td|}t  }| dg|||}| |d | d}| 	d| | 	d|  d S )Nu   print 'nothing'
print u'über'
ascii-r   z-print 'nothing'z9WARNING: couldn't encode <stdin>'s diff for your terminal)
ioStringIOBytesIOcodecs	getwriterr   assertEqualgetvaluedecodeassertIn)r   Zinput_streamoutZout_encerrretoutputr	   r	   r
   test_unencodable_diff,   s   
zTestMain.test_unencodable_diffc                 C   s   t  | _tj| jd| _tj| jd| _t| j t| j g | _	t
tj| jdd  | j	d tt| j | j	tjt tj| jd| _tj| jd| _t
| jd}|d W d   n1 srw   Y  | j	d dS )z5Setup a test source tree and output destination tree.Zpython2_projectZpython3_projectz__init__.pywz
trivial.pyz#print 'I need a simple conversion.'N)tempfilemkdtempr   ospathjoinpy2_src_dirpy3_dest_dirmkdirsetup_filesopencloseappendr   copyPY2_TEST_MODULEbasenametrivial_py2_fileinit_py2_filewrite)r   Ztrivialr	   r	   r
   setup_test_source_trees8   s    
z TestMain.setup_test_source_treesc              
      s  |    t }t }d | dd ddd| j| jgtd||}| |d | }| d	| | d
| j| jf | | t	 fdd| j
D t	t| j | j
D ]}| dtj| j|tj| j|  f | qXttj}| |dd| | |dd| dS )z92to3 a single directory with a new output dir and suffix.ZTEST-nz--add-suffix--write-unchanged-files
--no-diffs--output-dir r   z implies -w.6Output in %r will mirror the input directory %r layoutc                 3   s    | ]}|  V  qd S r   r	   .0namesuffixr	   r
   	<genexpr>\   s    zGTestMain.test_filename_changing_on_output_single_dir.<locals>.<genexpr>zWriting converted %s to %szNo changes to .*/__init__\.py/zNo changes to .*/trivial\.pyN)r;   r   r   r   r/   r.   r   r    r"   setr1   r+   listdirr,   r-   reescapesepZassertRegexreplaceZassertNotRegex)r   r#   r$   r%   r   rD   rM   r	   rE   r
   +test_filename_changing_on_output_single_dirK   sJ   
z4TestMain.test_filename_changing_on_output_single_dirc                 C   s   |    t }| j| jg}tdd |D }| ddddd| jg| tdt |}| |d	 |	 }| 
d
| j| jf | | |tt| j dS )z62to3 two files in one directory with a new output dir.c                 s   s    | ]	}t j|V  qd S r   )r+   r,   r7   rB   r	   r	   r
   rG   m   s    zFTestMain.test_filename_changing_on_output_two_files.<locals>.<genexpr>r<   -wr=   r>   r?   r@   r   rA   N)r;   r   r   r8   r9   rI   r   r/   r   r    r"   r.   r+   rJ   )r   r$   Z	py2_filesZexpected_filesr%   r   r	   r	   r
   *test_filename_changing_on_output_two_filesh   s*   z3TestMain.test_filename_changing_on_output_two_filesc                 C   s   |    t }| dddd| j| jgtdt |}| |d | }| d| j| j	f | | t
tj| jgt
t| j dS )	z)2to3 a single file with a new output dir.r<   rP   r>   r?   r@   r   rA   N)r;   r   r   r   r/   r8   r   r    r"   r.   rI   r+   r,   r7   rJ   )r   r$   r%   r   r	   r	   r
   ,test_filename_changing_on_output_single_filey   s&   z5TestMain.test_filename_changing_on_output_single_fileN)__name__
__module____qualname__r   r   r   r'   r;   rO   rQ   rR   r	   r	   r	   r
   r      s    r   __main__)r   r   r   r+   rK   r   r   r)   ZunittestZlib2to3r   r,   r-   dirname__file__ZTEST_DATA_DIRr6   ZTestCaser   rS   r	   r	   r	   r
   <module>   s    w