ó v®¸Qc@€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„ZRS(cC€stjjtƒdS(N(tsystpathtappendt FIXER_DIR(tself((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pytsetUp$scC€stjjƒdS(N(R R tpop(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(Rt assertFalseR%RR (RR((s1/sys/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((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      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__(((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyRDvst FileInputFixcB€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(t FixPreorder( 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Šs cC€s^|jt|jddgƒ|jtj|jddgƒ|jtj|jddgƒdS(NRtnot_heret no_fixer_clst bad_order(t assertRaisest ImportErrorRRt 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 ssdef f(): pass (Rtrefactor_stringtassertNotEqualtstrR0(RRtinputttree((s1/sys/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(s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyt print_output©s(RERFRx((Rw(s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyRq§ssdef parrot(): pass sdef cheese(): pass s( 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†}|ƒ}|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(s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyt read_fileÃsRR(ttempfiletmkdtempt addCleanuptshutiltrmtreetcopytosR tjointbasenametchmodRt log_debugt refactor_fileR0RRl( RR…RRtmock_log_debugtactually_writettmpdirR†t old_contentsRt new_contents((R…s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pytcheck_file_refactoring¹s$!    cC€s)tjjtdƒ}|j|tƒdS(Nsparrot_example.py(RR RŽR R˜Ry(RR…((s1/sys/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(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(( RR RŽR R˜RR.tsepRtassertRegexpMatchesR(RR…Rt 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ˆRtmkdirR RŽR‚tcloset refactor_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(RR RŽ(RR¯RoR~((Rs1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_refactor_dirîs    cC€s&tjjtdƒ}|j|ƒdS(Nsdifferent_encoding.py(RR RŽt TEST_DATA_DIRR˜(RR®((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyttest_file_encodingscC€sAtjjtdƒ}|j|ƒ}|j|jtjƒƒdS(Nsbom.py( RR RŽ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(RtlinesepR RŽ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 ss& >>> def parrot(): ... return 43 (Rtrefactor_docstringR0Rl(RRtdoctout((s1/sys/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À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 RR¶toperatorR{R‡RŠtunittesttwarningstlib2to3RRRt lib2to3.pgen2RR7RR RŽtdirnamet__file__R³R R R/RyRRÇtTestCaseR (((s1/sys/lib/python2.7/lib2to3/tests/test_refactor.pyts*         !