ó
v®¸Qc           @€  sT  d  Z  d d l m 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 m Z m Z d d l m Z d d l m Z e j j e j j e ƒ d ƒ Z e j j e d	 ƒ Z e j j e ƒ z e j d
 ƒ Z Wd e j j ƒ  Xe j d ƒ Z d e
 j f d „  ƒ  YZ  d S(   s   
Unit tests for refactor.py.
iÿÿÿÿ(   t   with_statementN(   t   refactort   pygramt
   fixer_base(   t   tokeni   (   t   supportt   datat   fixerst   myfixess   lib2to3.fixest   TestRefactoringToolc           B€  sã   e  Z d  „  Z d „  Z d „  Z d e d d „ Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z e d d e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C€  s   t  j j t ƒ d  S(   N(   t   syst   patht   appendt	   FIXER_DIR(   t   self(    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   setUp$   s    c         C€  s   t  j j ƒ  d  S(   N(   R
   R   t   pop(   R   (    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   tearDown'   s    c         C€  sJ   xC t  | | ƒ D]2 \ } } t | | ƒ s |  j d | | ƒ q q Wd  S(   Ns   %s are not instances of %s(   t   zipt
   isinstancet   fail(   R   t	   instancest   classest   instt   cls(    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   check_instances*   s    c         C€  s   t  j | | | ƒ S(   N(   R   t   RefactoringTool(   R   t   optionsR   t   explicit(    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   rt/   s    c         C€  sO   |  j  i t d 6ƒ } |  j | j t j k ƒ |  j | j j t j k ƒ d  S(   Nt   print_function(   R   t   Truet
   assertTruet   grammarR   t!   python_grammar_no_print_statementt   driver(   R   R   (    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   test_print_function_option2   s    c         C€  sF   |  j  ƒ  } |  j | j ƒ |  j  i t d 6ƒ } |  j | j ƒ d  S(   Nt   write_unchanged_files(   R   t   assertFalseR%   R   R    (   R   R   (    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt!   test_write_unchanged_files_option8   s    c         C€  s§   d d d d d g } t  j d ƒ } t  j d t ƒ } t  j d ƒ } |  j | g  | D] } d | ^ qU ƒ |  j | | ƒ |  j | g  | D] } d | ^ qŒ ƒ d  S(	   NR   t   firstt   lastt   parrott   preorderR   t   fix_s   myfixes.fix_(   R   t   get_all_fix_namest   Falset   get_fixers_from_packaget   assertEqual(   R   t   contentst   non_prefixedt   prefixedt
   full_namest   name(    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   test_fixer_loading_helpers>   s    '	c         C€  s  t  j } t } | ƒ  } |  j | d ƒ | ƒ |  j | d ƒ | d ƒ ƒ |  j | d ƒ | d ƒ ƒ |  j | d ƒ | d ƒ ƒ d } |  j | | ƒ | d ƒ ƒ d	 } |  j | | ƒ | d ƒ ƒ d
 } |  j | | ƒ | d  ƒ ƒ d } |  j | | ƒ | d! ƒ ƒ d } |  j | | ƒ | d" ƒ ƒ d } |  j | | ƒ | d# ƒ ƒ d$ } x$ | D] } |  j | | ƒ | ƒ q[Wd } |  j | | ƒ | d% ƒ ƒ d } |  j | | ƒ | ƒ d } |  j | | ƒ | d& ƒ ƒ d } |  j | | ƒ | d' ƒ ƒ d } |  j | | ƒ | ƒ d  S((   Nt    s%   from __future__ import print_functionR   s!   from __future__ import generatorst
   generatorss*   from __future__ import generators, featuret   features1   from __future__ import generators, print_functions1   from __future__ import print_function, generatorss(   from __future__ import (print_function,)s3   from __future__ import (generators, print_function)s2   from __future__ import (generators, nested_scopes)t   nested_scopessG   from __future__ import generators
from __future__ import print_functiont   froms   from 4s   from xs   from x 5s	   from x ims   from x imports   from x import 4s1   'docstring'
from __future__ import print_functions9   'docstring'
'somng'
from __future__ import print_functions/   # comment
from __future__ import print_functions5   # comment
'doc'
from __future__ import print_functions3   class x: pass
from __future__ import print_function(   s   print_function(   R8   (   R8   R9   (   R8   s   print_function(   s   print_functionR8   (   s   print_function(   R8   s   print_function(   R8   R:   (   R8   s   print_function(   R;   s   from 4s   from xs   from x 5s	   from x ims   from x imports   from x import 4(   s   print_function(   s   print_function(   s   print_function(   R   t   _detect_future_featurest	   frozensetR0   (   R   t   runt   fst   emptyt   inpt   invalid(    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   test_detect_future_featuresH   sR    		      c         C€  s  d t  j f d „  ƒ  Y} d t  j f d „  ƒ  Y} d t  j f d „  ƒ  Y} | i  g  ƒ } | i  g  ƒ } | i  g  ƒ } t j | | | g ƒ } | j t j j ƒ } |  j | | | g ƒ | j t	 j
 ƒ }	 |  j |	 | | g ƒ x' | j ƒ  D] }
 |  j |
 | g ƒ qð Wd  S(   Nt   NoneFixc           B€  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyRD   v   s   t   FileInputFixc           B€  s   e  Z d  Z RS(   s   file_input< any * >(   RE   RF   t   PATTERN(    (    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyRG   y   s   t	   SimpleFixc           B€  s   e  Z d  Z RS(   s   'name'(   RE   RF   RH   (    (    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyRI   |   s   (   R   t   BaseFixR   t   _get_headnode_dictR   R   t   python_symbolst
   file_inputR0   R   t   NAMEt
   itervalues(   R   RD   RG   RI   t   no_headt	   with_headt   simplet   dt	   top_fixest
   name_fixest   fixes(    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   test_get_headnode_dictu   s    c         C€  sŽ   d d l  m } d d l m } d d l m } d d l m } |  j ƒ  } | j	 ƒ  \ } } |  j
 | | g ƒ |  j
 | | | | g ƒ d  S(   Niÿÿÿÿ(   t   FixFirst(   t   FixLast(   t	   FixParrot(   t   FixPreorder(   t   myfixes.fix_firstRX   t   myfixes.fix_lastRY   t   myfixes.fix_parrotRZ   t   myfixes.fix_preorderR[   R   t
   get_fixersR   (   R   RX   RY   RZ   R[   R   t   pret   post(    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   test_fixer_loadingŠ   s    c         C€  s^   |  j  t |  j d d g ƒ|  j  t j |  j d d g ƒ|  j  t j |  j d d g ƒd  S(   NR   t   not_heret   no_fixer_clst	   bad_order(   t   assertRaisest   ImportErrorR   R   t
   FixerError(   R   (    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   test_naughty_fixers–   s    c         C€  sl   |  j  ƒ  } d } | j | d ƒ } |  j t | ƒ | ƒ d } | j | d ƒ } |  j t | ƒ | ƒ d  S(   Ns   def parrot(): pass

s   <test>s   def f(): pass

(   R   t   refactor_stringt   assertNotEqualt   strR0   (   R   R   t   inputt   tree(    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   test_refactor_string›   s    c         €  s   d t  j f ‡  f d †  ƒ  Y} g  ‰  | t ƒ } t j } t j d ƒ t _ z | j ƒ  Wd  | t _ Xd d d t g } |  j ˆ  | ƒ d  S(   Nt   MyRTc           €  s   e  Z ‡  f d  †  Z RS(   c         €  s   ˆ  j  | | | | g ƒ d  S(   N(   t   extend(   R   t   old_textt   new_textt   filenamet   equal(   t   results(    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   print_output©   s    (   RE   RF   Rx   (    (   Rw   (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyRq   §   s   s   def parrot(): pass

s   def cheese(): pass

s   <stdin>(	   R   R   t   _DEFAULT_FIXERSR
   t   stdint   StringIOt   refactor_stdinR.   R0   (   R   Rq   R   t   savet   expected(    (   Rw   s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   test_refactor_stdin¥   s    	
c         €  sÿ   t  j d d ƒ } |  j t j | ƒ t j ˆ  | ƒ t j j | t j j	 ˆ  ƒ ƒ ‰  t j
 ˆ  d ƒ ‡  f d †  } | ƒ  } |  j d | d | ƒ }	 | r¨ | |	 _ n  |	 j ˆ  ƒ |  j | | ƒ  ƒ | sÒ d  S|	 j ˆ  t ƒ | ƒ  }
 |  j | |
 ƒ |
 S(   Nt   prefixs   2to3-test_refactori¤  c          €  s&   t  ˆ  d ƒ  }  |  j ƒ  SWd  QXd  S(   Nt   rb(   t   opent   read(   t   fp(   t	   test_file(    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt	   read_fileÃ   s    R   R   (   t   tempfilet   mkdtempt
   addCleanupt   shutilt   rmtreet   copyt   osR   t   joint   basenamet   chmodR   t	   log_debugt   refactor_fileR0   R   Rl   (   R   R…   R   R   t   mock_log_debugt   actually_writet   tmpdirR†   t   old_contentsR   t   new_contents(    (   R…   s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   check_file_refactoring¹   s$    !		c         C€  s)   t  j j t d ƒ } |  j | t ƒ d  S(   Ns   parrot_example.py(   R   R   RŽ   R   R˜   Ry   (   R   R…   (    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   test_refactor_fileÖ   s    c      
   €  sÁ   t  j j t d ƒ } g  ‰  ‡  f d †  } |  j | d d d i t d 6d | d t ƒd t  j t  j j | ƒ f } xE ˆ  D]& } d	 | k r| |  j	 | | ƒ Pq| q| W|  j
 d
 | ˆ  f ƒ d  S(   Ns   parrot_example.pyc         €  s   ˆ  j  |  | ƒ d  S(   N(   R   (   t   msgt   args(   t   debug_messages(    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   recording_log_debugÝ   s    R   R   R%   R“   R”   s   Not writing changes to .*%s%ss   Not writing changess   %r not matched in %r(    (   R   R   RŽ   R   R˜   R   R.   t   sepR   t   assertRegexpMatchesR   (   R   R…   R   t   message_regext   message(    (   Rœ   s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt'   test_refactor_file_write_unchanged_fileÚ   s    c         €  sv   ‡  f d †  } | g  g  ƒ d d d d d d g } d g } | | | ƒ d t  j j d d	 ƒ g } | | | ƒ d  S(
   Nc         €  sþ   ‡  f d †  } t  j j } | t  j _ ˆ j ƒ  } g  ‰  t j d d ƒ } z` t j t j j	 | d ƒ ƒ x0 |  D]( } t
 t j j	 | | ƒ d ƒ j ƒ  qq W| j | ƒ Wd  | t  j _ t j | ƒ Xˆ j ˆ  g  | D] } t j j	 | | ƒ ^ qØ ƒ d  S(   Nc         €  s   ˆ  j  | ƒ d  S(   N(   R   (   R   t   fR›   (   t   got(    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   mock_refactor_fileð   s    R€   s   2to3-test_refactort   a_dirt   wb(   R   R   R’   R   R‡   Rˆ   R   t   mkdirR   RŽ   R‚   t   closet   refactor_dirRŠ   R‹   R0   (   t	   structureR~   R¥   t	   save_funcR   t   dirt   fnR   (   R   (   R¤   s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   checkï   s    &	t   nothings   hi.pys   .dumbs	   .after.pys	   notpy.npyt   sappyR¦   s   stuff.py(   R   R   RŽ   (   R   R¯   Ro   R~   (    (   R   s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   test_refactor_dirî   s    		c         C€  s&   t  j j t d ƒ } |  j | ƒ d  S(   Ns   different_encoding.py(   R   R   RŽ   t   TEST_DATA_DIRR˜   (   R   R®   (    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   test_file_encoding  s    c         C€  sA   t  j j t d ƒ } |  j | ƒ } |  j | j t j ƒ ƒ d  S(   Ns   bom.py(	   R   R   RŽ   R³   R˜   R    t
   startswitht   codecst   BOM_UTF8(   R   R®   R   (    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   test_bom  s    c         C€  s[   t  j } d t  _ z8 t  j j t d ƒ } t j d ƒ } |  j | | ƒ Wd  | t  _ Xd  S(   Ns   
s   crlf.pys   lib2to3.fixes(   R   t   linesepR   RŽ   R³   R   R/   R˜   (   R   t   old_sepR®   RV   (    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   test_crlf_newlines  s    		c         C€  s`   |  j  ƒ  } d } | j | d ƒ } |  j | | ƒ d } | j | d ƒ } |  j | | ƒ d  S(   Ns   
>>> example()
42
s   <test>s&   
>>> def parrot():
...      return 43
(   R   t   refactor_docstringR0   Rl   (   R   R   t   doct   out(    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   test_refactor_docstring!  s    c         C€  s‹   d d l  m } |  j d d g ƒ } |  j t | j ƒ d ƒ |  j d d g ƒ } x1 | j D] } t | | ƒ r] Pq] q] W|  j d ƒ d  S(   Niÿÿÿÿ(   t   FixExplicitR   s   myfixes.fix_expliciti    R   s   explicit fixer not loaded(   t   myfixes.fix_explicitRÀ   R   R0   t   lent
   post_orderR   R   (   R   RÀ   R   t   fix(    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   test_explicit2  s    N(   RE   RF   R   R   R   t   NoneRy   R   R$   R'   R6   RC   RW   Rc   Rj   Rp   R   t   _2TO3_FIXERSR   R˜   R™   R¢   R²   R´   R¸   R»   R¿   RÅ   (    (    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyR	   "   s0   						
	-				
				 			
	(!   t   __doc__t
   __future__R    R
   R   R¶   t   operatorR{   R‡   RŠ   t   unittestt   warningst   lib2to3R   R   R   t   lib2to3.pgen2R   R7   R   R   RŽ   t   dirnamet   __file__R³   R   R   R/   Ry   R   RÇ   t   TestCaseR	   (    (    (    s1   /sys/lib/python2.7/lib2to3/tests/test_refactor.pyt   <module>   s*   !