
    dafl                     R   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                  j                  ej                  j                  e      d      Zej                  j                  ed      Z G d dej"                        Zedk(  r ej                          yy)    N)maindatazpy2_test_grammar.pyc                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
TestMainc                     d | _         y N)temp_dirselfs    6/root/Python-3.12.4/Lib/test/test_lib2to3/test_main.pysetUpzTestMain.setUp   s	        c                     t         j                  j                  d d = | j                  r t	        j
                  | j                         y y r   )loggingroothandlersr	   shutilrmtreer
   s    r   tearDownzTestMain.tearDown   s0    LL!!!$==MM$--( r   c                 `   t         j                  }t         j                  }t         j                  }|t         _        |t         _        |t         _        	 t	        j                  d|      |t         _        |t         _        |t         _        S # |t         _        |t         _        |t         _        w xY w)Nzlib2to3.fixes)sysstdinstdoutstderrr   )r   args
in_captureout_captureerr_capture
save_stdinsave_stdoutsave_stderrs           r   run_2to3_capturezTestMain.run_2to3_capture   ss    YY
jjjj	 
 
	%99_d3"CI$CJ$CJ #CI$CJ$CJs   B
 
#B-c                    t        j                  d      }t        j                         } t        j                  d      |      }t        j                         }| j                  dg|||      }| j                  |d       |j                         j                  d      }| j                  d|       | j                  d|j                                y )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   input_streamoutout_encerrretoutputs          r   test_unencodable_diffzTestMain.test_unencodable_diff,   s    {{#FGjjl+&""7+C0kkm##SE<#Fa &&w/(&1 &'*||~	7r   c                 `   t        j                         | _        t        j                  j                  | j                  d      | _        t        j                  j                  | j                  d      | _        t        j                  | j                         t        j                  | j                         g | _	        t        t        j                  j                  | j                  d      d      j                          | j                  j                  d       t        j                  t        | j                         | j                  j                  t        j                  j!                  t                     t        j                  j                  | j                  d      | _        t        j                  j                  | j                  d      | _        t        | j"                  d      5 }|j'                  d       ddd       | j                  j                  d       y# 1 sw Y   %xY w)z5Setup a test source tree and output destination tree.python2_project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   trivials     r   setup_test_source_treesz TestMain.setup_test_source_trees8   so    ((*77<<7HIGGLL8IJ
!!"
""#RWW\\$**M:C@FFH.OT%5%56 0 0 AB "T-=-=| LWW\\$*:*:MJ$''- 	AMM?@	A-	A 	As   .H$$H-c                 0   | j                          t        j                         }t        j                         }d| j                  ddddd| j                  | j
                  gt        j                  d      ||      }| j                  |d       |j                         }| j                  d	|       | j                  d
| j                  d| j
                  d|       | j                  t        fd| j                  D              t        t        j                  | j                                     | j                  D ]m  }| j                  dt        j                  j                  | j
                  |      dt        j                  j                  | j                  |z         |       o t        j                   t        j"                        }| j%                  |dj'                  d|             | j)                  |dj'                  d|             y)z92to3 a single directory with a new output dir and suffix.TEST-nz--add-suffix--write-unchanged-files
--no-diffs--output-dir r   z implies -w.
Output in ! will mirror the input directory  layoutc              3   (   K   | ]	  }|z     y wr    ).0namesuffixs     r   	<genexpr>zGTestMain.test_filename_changing_on_output_single_dir.<locals>.<genexpr>\   s     FTT&[Fs   zWriting converted z to zNo changes to .*/__init__\.py/zNo changes to .*/trivial\.pyN)rM   r&   r'   r"   r@   r?   r+   r,   r.   setrB   r<   listdirr=   r>   reescapesepassertRegexreplaceassertNotRegex)r   r0   r2   r3   r   r[   rc   r\   s          @r   +test_filename_changing_on_output_single_dirz4TestMain.test_filename_changing_on_output_single_dirK   s   $$&kkmkkm##~v/H~""D$4$46 Bc	+
 	a nf-))4+;+;=>D	F 	FT5E5EFFRZZ(9(9:;	=$$ 	KDMMGGLL!1!148GGLL!2!2DK@BCIK	K ii8@@cJ	L7??SI	Kr   c                 F   | j                          t        j                         }| j                  | j                  g}t        d |D              }| j                  ddddd| j                  g|z   t        j                  d      t        j                         |      }| j                  |d       |j                         }| j                  d	| j                  d
| j                  d|       | j                  |t        t        j                  | j                                     y)z62to3 two files in one directory with a new output dir.c              3   Z   K   | ]#  }t         j                  j                  |       % y wr   )r<   r=   rH   )rZ   r[   s     r   r]   zFTestMain.test_filename_changing_on_output_two_files.<locals>.<genexpr>m   s     JRWW--d3Js   )+rP   -wrQ   rR   rS   rT   r   rU   rV   rW   N)rM   r&   r'   rI   rJ   r_   r"   r@   r+   r,   r.   r?   r<   r`   )r   r2   	py2_filesexpected_filesr3   r   s         r   *test_filename_changing_on_output_two_filesz3TestMain.test_filename_changing_on_output_two_filesh   s    $$&kkm**D,>,>?	J	JJ##t6~t/@/@BDMNB5 	a ))4+;+;=>D	F 	RZZ8I8I-J)KLr   c                 b   | j                          t        j                         }| j                  dddd| j                  | j
                  gt        j                  d      t        j                         |      }| j                  |d       |j                         }| j                  d| j                  d| j                  d	|       | j                  t        t        j                  j                  | j
                        g      t        t        j                  | j                                     y
)z)2to3 a single file with a new output dir.rP   rj   rR   rS   rT   r   rU   rV   rW   N)rM   r&   r'   r"   r@   rI   r+   r,   r.   r?   r_   r<   r=   rH   r`   )r   r2   r3   r   s       r   ,test_filename_changing_on_output_single_filez5TestMain.test_filename_changing_on_output_single_filey   s    $$&kkm##t\>4;L;L&&(B5 	a ))4+;+;=>D	F 	bgg..t/D/DEFGRZZ(9(9:;	=r   N)__name__
__module____qualname__r   r   r"   r5   rM   rg   rm   ro   rY   r   r   r   r      s,    )%
7.&K:M"=r   r   __main__)r)   r&   r   r<   ra   r   r   r:   unittestlib2to3r   r=   r>   dirname__file__TEST_DATA_DIRrG   TestCaser   rp   rY   r   r   <module>rz      s     	  	 	  
    RWW__X6?'',,}.CDt=x   t=n zHMMO r   