Current File : //opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyc
�
��#ec@�s`dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZmZmZddlmZddlmZejjejje�d�Zejjed	�Zejje�zejd
�ZWdejj�Xejd�Zdej fd
��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�Zd	�Z
d
�Zd�Zd�Zedded
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(cC�stjjt�dS(N(tsystpathtappendt	FIXER_DIR(tself((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pytsetUp%scC�stjj�dS(N(R
Rtpop(R((s;/opt/RZpython2/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((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pytcheck_instances+scC�stj|||�S(N(RtRefactoringTool(RtoptionsRtexplicit((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pytrt0scC�sI|jitd6�}|j|jtj�|j|jjtj�dS(Ntprint_function(RtTruetassertIstgrammarRt!python_grammar_no_print_statementtdriver(RR((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyttest_print_function_option3scC�sF|j�}|j|j�|jitd6�}|j|j�dS(Ntwrite_unchanged_files(RtassertFalseR%Rt
assertTrue(RR((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyt!test_write_unchanged_files_option9scC�s�dddddg}tjd�}tjdt�}tjd�}|j|g|D]}d|^qU�|j||�|j|g|D]}d|^q��dS(	NRtfirsttlasttparrottpreorderRtfix_smyfixes.fix_(Rtget_all_fix_namestFalsetget_fixers_from_packagetassertEqual(Rtcontentstnon_prefixedtprefixedt
full_namestname((s;/opt/RZpython2/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(R(R9(R9R:(R9R(RR9(R(R9R(R9R;(R9R(R<sfrom 4sfrom xsfrom x 5s	from x ims
from x importsfrom x import 4(R(R(R(Rt_detect_future_featurest	frozensetR1(Rtruntfstemptytinptinvalid((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyttest_detect_future_featuresIsR		



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�WdS(NtNoneFixcB�seZRS((t__name__t
__module__(((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyREwstFileInputFixcB�seZdZRS(sfile_input< any * >(RFRGtPATTERN(((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyRHzst	SimpleFixcB�seZdZRS(s'name'(RFRGRI(((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyRJ}s(RtBaseFixRt_get_headnode_dictRRtpython_symbolst
file_inputR1RtNAMEt
itervalues(RRERHRJtno_headt	with_headtsimpletdt	top_fixest
name_fixestfixes((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyttest_get_headnode_dictvscC�s�ddlm}ddlm}ddlm}ddlm}|j�}|j	�\}}|j
||g�|j
||||g�dS(Ni����(tFixFirst(tFixLast(t	FixParrot(tFixPreorder(tmyfixes.fix_firstRYtmyfixes.fix_lastRZtmyfixes.fix_parrotR[tmyfixes.fix_preorderR\Rt
get_fixersR(RRYRZR[R\Rtpretpost((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyttest_fixer_loading�scC�s^|jt|jddg�|jtj|jddg�|jtj|jddg�dS(NRtnot_heretno_fixer_clst	bad_order(tassertRaisestImportErrorRRt
FixerError(R((s;/opt/RZpython2/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_stringtassertNotEqualtstrR1(RRtinputttree((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyttest_refactor_string�sc�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(s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pytprint_output�s(RFRGRy((Rx(s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyRr�ssdef parrot(): pass

sdef cheese(): pass

s<stdin>(	RRt_DEFAULT_FIXERSR
tstdintStringIOtrefactor_stdinR/R1(RRrRtsavetexpected((Rxs;/opt/RZpython2/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(s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyt	read_file�sRR(ttempfiletmkdtempt
addCleanuptshutiltrmtreetcopytosRtjointbasenametchmodRt	log_debugt
refactor_fileR1RRm(RR�RRtmock_log_debugtactually_writettmpdirR�told_contentsRtnew_contents((R�s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pytcheck_file_refactoring�s$!	
	cC�s)tjjtd�}|j|t�dS(Nsparrot_example.py(R�RR�R
R�Rz(RR�((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyttest_refactor_file�sc
�s�tjjtd�}g��fd�}|j|ddditd6d|dt�dtjtj	tjj
|��}xE�D]&}d	|kr�|j||�Pq�q�W|jd
|�f�dS(Nsparrot_example.pyc�s�j||�dS(N(R(tmsgtargs(tdebug_messages(s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pytrecording_log_debug�sRRR%R�R�sNot writing changes to .*%ssNot writing changess%r not matched in %r((
R�RR�R
R�RR/tretescapetsepR�tassertRegexpMatchesR(RR�R�t
message_regextmessage((R�s;/opt/RZpython2/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(s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pytmock_refactor_file�sR�s2to3-test_refactorta_dirtwb(RRR�RR�R�R�tmkdirRR�R�tclosetrefactor_dirR�R�R1(t	structureRR�t	save_funcRtdirtfnR(R(R�s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pytcheck�s
&	tnothingshi.pys.dumbs	.after.pys	notpy.npytsappyR�sstuff.py(R�RR�(RR�RpR((Rs;/opt/RZpython2/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�((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyttest_file_encodingscC�s(tjjtd�}|j|�}dS(Nsfalse_encoding.py(R�RR�R�R�(RR�R((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyttest_false_file_encodingscC�sAtjjtd�}|j|�}|j|jtj��dS(Nsbom.py(	R�RR�R�R�R't
startswithtcodecstBOM_UTF8(RR�R((s;/opt/RZpython2/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�RR0R�(Rtold_sepR�RW((s;/opt/RZpython2/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_docstringR1Rm(RRtdoctout((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyttest_refactor_docstring&scC�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�RR1tlent
post_orderRR(RR�Rtfix((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyt
test_explicit7sN(RFRGRRRtNoneRzRR$R(R7RDRXRdRkRqR�t_2TO3_FIXERSRR�R�R�R�R�R�R�R�R�R�(((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyR	#s2						
	-				
				 				
	("t__doc__t
__future__RR
R�R�toperatorR�R|R�R�tunittesttwarningstlib2to3RRRt
lib2to3.pgen2RR8RRR�tdirnamet__file__R�R
RR0RzRR�tTestCaseR	(((s;/opt/RZpython2/lib/python2.7/lib2to3/tests/test_refactor.pyt<module>s,!