ó
v®¸Qc           @   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 Z d  d l	 m
 Z
 e j j e j j e ƒ d ƒ Z e j j e d ƒ Z d e j f d „  ƒ  YZ e d k rð e j
 ƒ  n  d S(   iÿÿÿÿN(   t   maint   datas   py2_test_grammar.pyt   TestMainc           B   sq   e  Z e e j d  ƒ s' d
 d „ Z n  d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z RS(   t   assertNotRegexc         C   s]   d d  l  } t | d ƒ s- | j | ƒ } n  | j | ƒ rY |  j d | j | f ƒ n  d  S(   Niÿÿÿÿt   searchs   regexp %s MATCHED text %r(   t   ret   hasattrt   compileR   t   failt   pattern(   t   selft   textt   regexpt   msgR   (    (    s-   /sys/lib/python2.7/lib2to3/tests/test_main.pyR      s
    c         C   s   d  |  _ d  S(   N(   t   Nonet   temp_dir(   R
   (    (    s-   /sys/lib/python2.7/lib2to3/tests/test_main.pyt   setUp   s    c         C   s*   t  j j 2|  j r& t j |  j ƒ n  d  S(   N(   t   loggingt   roott   handlersR   t   shutilt   rmtree(   R
   (    (    s-   /sys/lib/python2.7/lib2to3/tests/test_main.pyt   tearDown"   s    
	c         C   sm   t  j } t  j } t  j } | t  _ | t  _ | t  _ z t j d | ƒ SWd  | t  _ | t  _ | t  _ Xd  S(   Ns   lib2to3.fixes(   t   syst   stdint   stdoutt   stderrR    (   R
   t   argst
   in_capturet   out_capturet   err_capturet
   save_stdint   save_stdoutt   save_stderr(    (    s-   /sys/lib/python2.7/lib2to3/tests/test_main.pyt   run_2to3_capture(   s    								c         C   s£   t  j  d ƒ } t  j  ƒ  } t j d ƒ | ƒ } t  j  ƒ  } |  j d g | | | ƒ } |  j | d ƒ | j ƒ  } |  j d | k ƒ |  j d | j ƒ  k ƒ d  S(   Nu   print 'nothing'
print u'Ã¼ber'
t   asciit   -i    s   -print 'nothing's9   WARNING: couldn't encode <stdin>'s diff for your terminal(   t   StringIOt   codecst	   getwriterR"   t   assertEqualt   getvaluet
   assertTrue(   R
   t   input_streamt   outt   out_enct   errt   rett   output(    (    s-   /sys/lib/python2.7/lib2to3/tests/test_main.pyt   test_unencodable_diff6   s    	c         C   sD  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 QX|  j	 j d ƒ d S(   s5   Setup a test source tree and output destination tree.t   python2_projectt   python3_projects   __init__.pyt   ws
   trivial.pys#   print 'I need a simple conversion.'N(   t   tempfilet   mkdtempR   t   ost   patht   joint   py2_src_dirt   py3_dest_dirt   mkdirt   setup_filest   opent   closet   appendR   t   copyt   PY2_TEST_MODULEt   basenamet   trivial_py2_filet   init_py2_filet   write(   R
   t   trivial(    (    s-   /sys/lib/python2.7/lib2to3/tests/test_main.pyt   setup_test_source_treesB   s    	%c      	      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 †  |  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(   s9   2to3 a single directory with a new output dir and suffix.t   TESTs   -ns   --add-suffixs   --write-unchanged-filess
   --no-diffss   --output-dirt    i    s    implies -w.s6   Output in %r will mirror the input directory %r layoutc         3   s   |  ] } | ˆ  Vq d  S(   N(    (   t   .0t   name(   t   suffix(    s-   /sys/lib/python2.7/lib2to3/tests/test_main.pys	   <genexpr>f   s    s   Writing converted %s to %ss   No changes to .*/__init__\.pyt   /s   No changes to .*/trivial\.pyN(   RH   R%   R"   R;   R:   R(   R)   t   assertInt   setR=   R7   t   listdirR8   R9   R   t   escapet   sept   assertRegexpMatchest   replaceR   (   R
   R,   R.   R/   R   RL   RS   (    (   RM   s-   /sys/lib/python2.7/lib2to3/tests/test_main.pyt+   test_filename_changing_on_output_single_dirU   s4    
"	(c         C   sà   |  j  ƒ  t j ƒ  } |  j |  j g } t 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(   s6   2to3 two files in one directory with a new output dir.c         s   s!   |  ] } t  j j | ƒ Vq d  S(   N(   R7   R8   RC   (   RK   RL   (    (    s-   /sys/lib/python2.7/lib2to3/tests/test_main.pys	   <genexpr>w   s    s   -ns   -ws   --write-unchanged-filess
   --no-diffss   --output-dirRJ   i    s6   Output in %r will mirror the input directory %r layoutN(   RH   R%   RD   RE   RP   R"   R;   R(   R)   RO   R:   R7   RQ   (   R
   R.   t	   py2_filest   expected_filesR/   R   (    (    s-   /sys/lib/python2.7/lib2to3/tests/test_main.pyt*   test_filename_changing_on_output_two_filesr   s    
	c         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(	   s)   2to3 a single file with a new output dir.s   -ns   -ws
   --no-diffss   --output-dirRJ   i    s6   Output in %r will mirror the input directory %r layoutN(   RH   R%   R"   R;   RD   R(   R)   RO   R:   RP   R7   R8   RC   RQ   (   R
   R.   R/   R   (    (    s-   /sys/lib/python2.7/lib2to3/tests/test_main.pyt,   test_filename_changing_on_output_single_fileƒ   s    
	!N(   t   __name__t
   __module__R   t   unittestt   TestCaseR   R   R   R   R"   R1   RH   RV   RY   RZ   (    (    (    s-   /sys/lib/python2.7/lib2to3/tests/test_main.pyR      s   							t   __main__(   R   R&   R   R7   R   R   R%   R5   R]   t   lib2to3R    R8   R9   t   dirnamet   __file__t   TEST_DATA_DIRRB   R^   R   R[   (    (    (    s-   /sys/lib/python2.7/lib2to3/tests/test_main.pyt   <module>   s   !€