��Qc@�sTdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl
Z
ddlZddlm
Z
mZmZddlmZddlmZejjejje�d�Zejjed �Zejje�ze
jd
�ZWdejj�Xe
jd�Zde
jfd
��YZ dS(s
Unit tests for refactor.py.
i�(twith_statementN(trefactortpygramt
fixer_base(ttokeni(tsupporttdatatfixerstmyfixess
lib2to3.fixestTestRefactoringToolcB�s�eZd�Zd�Zd�Zdedd�Zd�Zd�Z d�Z
d�Zd�Zd �Z
d
�Zd�Zd�Zedded
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(cC�stjjt�dS(N(tsystpathtappendt FIXER_DIR(tself((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pytsetUp$scC�stjj�dS(N(R
Rtpop(R((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttearDown'scC�sJxCt||�D]2\}}t||�s|jd||�qqWdS(Ns%s are not instances of %s(tzipt
isinstancetfail(Rt instancestclassestinsttcls((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pytcheck_instances*scC�stj|||�S(N(RtRefactoringTool(RtoptionsRtexplicit((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pytrt/scC�sO|jitd6�}|j|jtjk�|j|jjtjk�dS(Ntprint_function(RtTruet
assertTruetgrammarRt!python_grammar_no_print_statementtdriver(RR((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_print_function_option2scC�sF|j�}|j|j�|jitd6�}|j|j�dS(Ntwrite_unchanged_files(RtassertFalseR%RR (RR((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyt!test_write_unchanged_files_option8scC�s�dddddg}tjd�}tjdt�}tjd�}|j|g|D]}d|^qU�|j||�|j|g|D]}d|^q��dS( NRtfirsttlasttparrottpreorderRtfix_smyfixes.fix_(Rtget_all_fix_namestFalsetget_fixers_from_packagetassertEqual(Rtcontentstnon_prefixedtprefixedt
full_namestname((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_fixer_loading_helpers>s' cC�stj}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||�|�dS((Nts%from __future__ import print_functionRs!from __future__ import generatorst
generatorss*from __future__ import generators, featuretfeatures1from __future__ import generators, print_functions1from __future__ import print_function, generatorss(from __future__ import (print_function,)s3from __future__ import (generators, print_function)s2from __future__ import (generators, nested_scopes)t
nested_scopessGfrom __future__ import generators
from __future__ import print_functiontfromsfrom 4sfrom xsfrom x 5s from x ims
from x importsfrom 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_functions3class x: pass
from __future__ import print_function(sprint_function(R8(R8R9(R8sprint_function(sprint_functionR8(sprint_function(R8sprint_function(R8R:(R8sprint_function(R;sfrom 4sfrom xsfrom x 5s from x ims
from x importsfrom x import 4(sprint_function(sprint_function(sprint_function(Rt_detect_future_featurest frozensetR0(Rtruntfstemptytinptinvalid((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_detect_future_featuresHsR
cC�sdtjfd��Y}dtjfd��Y}dtjfd��Y}|ig�}|ig�}|ig�}tj|||g�}|jtjj�}|j|||g�|jt j
�} |j| ||g�x'|j�D]}
|j|
|g�q�S(NtNoneFixcB�seZRS((t__name__t
__module__(((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyRDvstFileInputFixcB�seZdZRS(sfile_input< any * >(RERFtPATTERN(((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyRGyst SimpleFixcB�seZdZRS(s'name'(RERFRH(((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyRI|s(RtBaseFixRt_get_headnode_dictRRtpython_symbolst
file_inputR0RtNAMEt
itervalues(RRDRGRItno_headt with_headtsimpletdt top_fixest
name_fixestfixes((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_get_headnode_dictuscC�s�ddlm}ddlm}ddlm}ddlm}|j�}|j �\}}|j
||g�|j
||||g�dS(Ni�(tFixFirst(tFixLast(t FixParrot(tFixPreorder(tmyfixes.fix_firstRXtmyfixes.fix_lastRYtmyfixes.fix_parrotRZtmyfixes.fix_preorderR[Rt
get_fixersR(RRXRYRZR[Rtpretpost((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_fixer_loading�scC�s^|jt|jddg�|jtj|jddg�|jtj|jddg�dS(NRtnot_heretno_fixer_clst bad_order(tassertRaisestImportErrorRRt
FixerError(R((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_naughty_fixers�scC�sl|j�}d}|j|d�}|jt|�|�d}|j|d�}|jt|�|�dS(Nsdef parrot(): pass
s<test>sdef f(): pass
(Rtrefactor_stringtassertNotEqualtstrR0(RRtinputttree((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_refactor_string�sc�s�dtjf�fd��Y}g�|t�}tj}tjd�t_z|j�Wd|t_Xdddtg}|j�|�dS(NtMyRTc�seZ�fd�ZRS(c�s�j||||g�dS(N(textend(Rtold_texttnew_texttfilenametequal(tresults(s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pytprint_output�s(RERFRx((Rw(s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyRq�ssdef parrot(): pass
sdef cheese(): pass
s<stdin>( RRt_DEFAULT_FIXERSR
tstdintStringIOtrefactor_stdinR.R0(RRqRtsavetexpected((Rws1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_refactor_stdin�s
c�s�tjdd�}|jtj|�tj�|�tjj|tjj ����tj
�d��fd�}|�}|jd|d|�} |r�|| _n| j
��|j||��|s�dS| j
�t�|�}
|j||
�|
S(Ntprefixs2to3-test_refactori�c�s&t�d��}|j�SWdQXdS(Ntrb(topentread(tfp(t test_file(s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyt read_file�sRR(ttempfiletmkdtempt
addCleanuptshutiltrmtreetcopytosRtjointbasenametchmodRt log_debugt
refactor_fileR0RRl(RR�RRtmock_log_debugtactually_writettmpdirR�told_contentsRtnew_contents((R�s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pytcheck_file_refactoring�s$!
cC�s)tjjtd�}|j|t�dS(Nsparrot_example.py(R�RR�R
R�Ry(RR�((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_refactor_file�sc
�s�tjjtd�}g��fd�}|j|ddditd6d|dt�dtjtjj|�f}xE�D]&}d |kr||j ||�Pq|q|W|j
d
|�f�dS(Nsparrot_example.pyc�s�j||�dS(N(R(tmsgtargs(tdebug_messages(s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pytrecording_log_debug�sRRR%R�R�sNot writing changes to .*%s%ssNot writing changess%r not matched in %r((R�RR�R
R�RR.tsepR�tassertRegexpMatchesR(RR�R�t
message_regextmessage((R�s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyt'test_refactor_file_write_unchanged_file�s
c�sv�fd�}|gg�ddddddg}dg}|||�dtjjdd �g}|||�dS(
Nc�s��fd�}tjj}|tj_�j�}g�tjdd�}z`tjtjj |d��x0|D](}t
tjj ||�d�j�qqW|j|�Wd|tj_t
j|�X�j�g|D]}tjj ||�^q��dS(Nc�s�j|�dS(N(R(RtfR�(tgot(s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pytmock_refactor_file�sR�s2to3-test_refactorta_dirtwb(RRR�RR�R�R�tmkdirRR�R�tclosetrefactor_dirR�R�R0(t structureR~R�t save_funcRtdirtfnR(R(R�s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pytcheck�s
& tnothingshi.pys.dumbs .after.pys notpy.npytsappyR�sstuff.py(R�RR�(RR�RoR~((Rs1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_refactor_dir�s
cC�s&tjjtd�}|j|�dS(Nsdifferent_encoding.py(R�RR�t
TEST_DATA_DIRR�(RR�((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_file_encodingscC�sAtjjtd�}|j|�}|j|jtj��dS(Nsbom.py( R�RR�R�R�R t
startswithtcodecstBOM_UTF8(RR�R((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_bomscC�s[tj}dt_z8tjjtd�}tjd�}|j||�Wd|t_XdS(Ns
scrlf.pys
lib2to3.fixes(R�tlinesepRR�R�RR/R�(Rtold_sepR�RV((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_crlf_newliness cC�s`|j�}d}|j|d�}|j||�d}|j|d�}|j||�dS(Ns
>>> example()
42
s<test>s&
>>> def parrot():
... return 43
(Rtrefactor_docstringR0Rl(RRtdoctout((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_refactor_docstring!scC�s�ddlm}|jddg�}|jt|j�d�|jddg�}x1|jD]}t||�r]Pq]q]W|jd�dS(Ni�(tFixExplicitRsmyfixes.fix_explicitiRsexplicit fixer not loaded(tmyfixes.fix_explicitR�RR0tlent
post_orderRR(RR�Rtfix((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyt
test_explicit2sN(RERFRRRtNoneRyRR$R'R6RCRWRcRjRpRt_2TO3_FIXERSRR�R�R�R�R�R�R�R�R�(((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyR "s0
-
(!t__doc__t
__future__RR
R�R�toperatorR{R�R�tunittesttwarningstlib2to3RRRt
lib2to3.pgen2RR7RRR�tdirnamet__file__R�R
RR/RyRR�tTestCaseR (((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyt<module>s*!
|