
mYl                 @   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 j e j j e  d  Z e j j e d  Z Gd d   d e j  Z e d k r e j
   d S)    N)maindatazpy2_test_grammar.pyc               @   sp   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   J/build/mts/release/bora-5583004/publish/lin64/lib64/python3.5/test_main.pysetUp   s    zTestMain.setUpc             C   s0   t  j j d  d   =|  j r, t j |  j  d  S)N)loggingroothandlersr   shutilrmtree)r   r   r   r   tearDown   s    	zTestMain.tearDownc             C   sm   t  j } t  j } t  j } | t  _ | t  _ | t  _ z t j d |  SWd  | t  _ | t  _ | t  _ Xd  S)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   s   t  j d  } t  j   } t j d  |  } t  j   } |  j d g | | |  } |  j | d  | j   j d  } |  j	 d |  |  j	 d | j    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   sE  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   } | j d  Wd QRX|  j	 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  |  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 |  j f |  |  j t	   f d d   |  j
 D  t	 t j |  j    xS |  j
 D]H } |  j d t j j |  j |  t j j |  j |    f |  q Wt j t j  } |  j | d j d |   |  j | d j d |   d S)z92to3 a single directory with a new output dir and suffix.ZTESTz-nz--add-suffixz--write-unchanged-filesz
--no-diffsz--output-dir r   z implies -w.z6Output in %r will mirror the input directory %r layoutc             3   s   |  ] } |   Vq d  S)Nr   ).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)r9   r   r   r   r-   r,   r   r   r    setr/   r)   listdirr*   r+   reescapesepZassertRegexreplaceZassertNotRegex)r   r!   r"   r#   r   r<   rD   r   )r=   r   +test_filename_changing_on_output_single_dirK   s4    
%	(z4TestMain.test_filename_changing_on_output_single_dirc             C   s   |  j    t j   } |  j |  j g } t d d   | D  } |  j d d d d d |  j g | t j d  t j   |  } |  j | d	  | j	   } |  j
 d
 |  j |  j f |  |  j | t t j |  j    d S)z62to3 two files in one directory with a new output dir.c             s   s!   |  ] } t  j j |  Vq d  S)N)r)   r*   r5   )r;   r<   r   r   r   r>   m   s    zFTestMain.test_filename_changing_on_output_two_files.<locals>.<genexpr>z-nz-wz--write-unchanged-filesz
--no-diffsz--output-dirr:   r   z6Output in %r will mirror the input directory %r layoutN)r9   r   r   r6   r7   r@   r   r-   r   r   r    r,   r)   rA   )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   |  j    t j   } |  j d d d d |  j |  j g t j d  t j   |  } |  j | d  | j   } |  j d |  j |  j	 f |  |  j t
 t j j |  j  g  t
 t j |  j    d S)	z)2to3 a single file with a new output dir.z-nz-wz
--no-diffsz--output-dirr:   r   z6Output in %r will mirror the input directory %r layoutN)r9   r   r   r   r-   r6   r   r   r    r,   r@   r)   r*   r5   rA   )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%   r9   rF   rG   rH   r   r   r   r   r      s   r   __main__)r   r   r
   r)   rB   r   r   r'   ZunittestZlib2to3r   r*   r+   dirname__file__ZTEST_DATA_DIRr4   ZTestCaser   rI   r   r   r   r   <module>   s   !w