ó |G_Tc@€sTdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z mZmZddlmZddlmZejjejjeƒdƒZejjed ƒZejjeƒze jd ƒZWdejjƒXe jd ƒZd e 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„Z d„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((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pytsetUp$scC€stjjƒdS(N(R R tpop(R((s7/usr/local/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((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pytcheck_instances*scC€stj|||ƒS(N(RtRefactoringTool(RtoptionsRtexplicit((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pytrt/scC€sI|jitd6ƒ}|j|jtjƒ|j|jjtjƒdS(Ntprint_function(RtTruetassertIstgrammarRt!python_grammar_no_print_statementtdriver(RR((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyttest_print_function_option2scC€sF|jƒ}|j|jƒ|jitd6ƒ}|j|jƒdS(Ntwrite_unchanged_files(Rt assertFalseR%Rt assertTrue(RR((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyt!test_write_unchanged_files_option8s 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_packaget assertEqual(Rtcontentst non_prefixedtprefixedt full_namestname((s7/usr/local/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(R9(R9R:(R9sprint_function(sprint_functionR9(sprint_function(R9sprint_function(R9R;(R9sprint_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 frozensetR1(Rtruntfstemptytinptinvalid((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyttest_detect_future_featuresHsR      c C€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__(((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyREvst FileInputFixcB€seZdZRS(sfile_input< any * >(RFRGtPATTERN(((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyRHyst SimpleFixcB€seZdZRS(s'name'(RFRGRI(((s7/usr/local/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((s7/usr/local/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(t FixPreorder( tmyfixes.fix_firstRYtmyfixes.fix_lastRZtmyfixes.fix_parrotR[tmyfixes.fix_preorderR\Rt get_fixersR(RRYRZR[R\Rtpretpost((s7/usr/local/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 assertRaisest ImportErrorRRt FixerError(R((s7/usr/local/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 ssdef f(): pass (Rtrefactor_stringtassertNotEqualtstrR1(RRtinputttree((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyttest_refactor_string›s c€sdtjf‡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(s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyt print_output©s(RFRGRy((Rx(s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyRr§ssdef parrot(): pass sdef cheese(): pass s( RRt_DEFAULT_FIXERSR tstdintStringIOtrefactor_stdinR/R1(RRrRtsavetexpected((Rxs7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyttest_refactor_stdin¥s    c €sÿtjddƒ}|jtj|ƒtjˆ|ƒtjj|tjj ˆƒƒ‰tj ˆdƒ‡fd†}|ƒ}|j d|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(s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyt read_fileÃsRR(ttempfiletmkdtempt addCleanuptshutiltrmtreetcopytosR tjointbasenametchmodRt log_debugt refactor_fileR1RRm( RR†RRtmock_log_debugtactually_writettmpdirR‡t old_contentsRt new_contents((R†s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pytcheck_file_refactoring¹s$!    cC€s)tjjtdƒ}|j|tƒdS(Nsparrot_example.py(RŽR RR R™Rz(RR†((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyttest_refactor_fileÖsc €sÁtjjtdƒ}g‰‡fd†}|j|dd ditd6d|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(s7/usr/local/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ŽR RR R™RR/tsepRtassertRegexpMatchesR(RR†Ržt message_regextmessage((Rs7/usr/local/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(s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pytmock_refactor_fileðsRs2to3-test_refactorta_dirtwb(RRR“RRˆR‰RŽtmkdirR RRƒtcloset refactor_dirR‹RŒR1(t structureRR¦t save_funcRtdirtfnR (R(R¥s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pytcheckïs    &  tnothingshi.pys.dumbs .after.pys notpy.npytsappyR§sstuff.py(RŽR R(RR°RpR((Rs7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyttest_refactor_dirîs    cC€s&tjjtdƒ}|j|ƒdS(Nsdifferent_encoding.py(RŽR Rt TEST_DATA_DIRR™(RR¯((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyttest_file_encodingscC€s(tjjtdƒ}|j|ƒ}dS(Nsfalse_encoding.py(RŽR RR´R™(RR¯R((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyttest_false_file_encodingscC€sAtjjtdƒ}|j|ƒ}|j|jtjƒƒdS(Nsbom.py( RŽR RR´R™R't startswithtcodecstBOM_UTF8(RR¯R((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyttest_bomscC€s[tj}dt_z8tjjtdƒ}tjdƒ}|j||ƒWd|t_XdS(Ns scrlf.pys lib2to3.fixes(RŽtlinesepR RR´RR0R™(Rtold_sepR¯RW((s7/usr/local/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 ss& >>> def parrot(): ... return 43 (Rtrefactor_docstringR1Rm(RRtdoctout((s7/usr/local/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ÿÿÿÿ(t FixExplicitRsmyfixes.fix_explicitiRsexplicit fixer not loaded(tmyfixes.fix_explicitRÂRR1tlent post_orderRR(RRÂRtfix((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyt test_explicit6sN(RFRGRRRtNoneRzRR$R(R7RDRXRdRkRqR€t _2TO3_FIXERSRR™RšR£R³RµR¶RºR½RÁRÇ(((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyR "s2      -          (!t__doc__t __future__RR RŽR¸toperatorR|RˆR‹tunittesttwarningstlib2to3RRRt lib2to3.pgen2RR8RR Rtdirnamet__file__R´R R R0RzRRÉtTestCaseR (((s7/usr/local/lib/python2.7/lib2to3/tests/test_refactor.pyts*         !