a 9êdgàã@sºdZddlZddlmZddlmZddlmZmZddl m Z Gdd„de j ƒZ Gd d „d e ƒZ Gd d „d e ƒZGd d„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd „d e ƒZGd!d"„d"e ƒZGd#d$„d$e ƒZGd%d&„d&e ƒZGd'd(„d(e ƒZGd)d*„d*e ƒZGd+d,„d,e ƒZGd-d.„d.e ƒZGd/d0„d0e ƒZ Gd1d2„d2e ƒZ!Gd3d4„d4ƒZ"Gd5d6„d6e e"ƒZ#Gd7d8„d8e e"ƒZ$Gd9d:„d:e e"ƒZ%Gd;d<„d„d>e ƒZ'Gd?d@„d@e ƒZ(GdAdB„dBe ƒZ)GdCdD„dDe ƒZ*GdEdF„dFe ƒZ+GdGdH„dHe ƒZ,GdIdJ„dJe ƒZ-GdKdL„dLe ƒZ.GdMdN„dNe ƒZ/GdOdP„dPe ƒZ0GdQdR„dRe ƒZ1GdSdT„dTe ƒZ2GdUdV„dVe ƒZ3GdWdX„dXe ƒZ4GdYdZ„dZe ƒZ5Gd[d\„d\e ƒZ6Gd]d^„d^e ƒZ7Gd_d`„d`e ƒZ8Gdadb„dbe ƒZ9Gdcdd„dde ƒZ:Gdedf„dfe ƒZ;Gdgdh„dhe ƒZGdmdn„dne ƒZ?Gdodp„dpe ƒZ@Gdqdr„dre ƒZAGdsdt„dte ƒZBdS)uz" Test suite for the fixer modules éN)Úchain)Ú itemgetter)ÚpygramÚ fixer_util)Úsupportc@sLeZdZddd„Zdd„Zddd „Zdd d „Zd d „Zddd„Zdd„Z dS)Ú FixerTestCaseNÚlib2to3cCsP|dur|jg}t |||¡|_g|_d|_t|jj|jjƒD] }|j|_ q>dS)Nz) ÚfixerrÚget_refactorerÚrefactorÚ fixer_logÚfilenamerZ pre_orderZ post_orderÚlog)ÚselfZfix_listZ fixer_pkgÚoptionsr ©rú5/usr/local/lib/python3.9/lib2to3/tests/test_fixers.pyÚsetUpsÿzFixerTestCase.setUpcCs8t |¡}t |¡}|j ||j¡}| |t|ƒ¡|S©N)rZreformatr Zrefactor_stringr Ú assertEqualÚstr)rÚbeforeÚafterÚtreerrrÚ_checks   zFixerTestCase._checkFcCs.| ||¡}| |j¡|s*| |jg¡dSr)rÚ assertTrueÚ was_changedrr )rrrÚignore_warningsrrrrÚcheck#s  zFixerTestCase.checkcCs4| ||¡}| |d |j¡¡|s0| |j¡dS)NÚ)rZassertInÚjoinr rr)rrrÚmessageÚ unchangedrrrrÚwarns)s zFixerTestCase.warnscCs|j|||dddS)NT©r"©r#)rrr!rrrÚwarns_unchanged/szFixerTestCase.warns_unchangedcCs"| ||¡|s| |jg¡dSr)rrr )rrrrrrr"2s zFixerTestCase.unchangedcGs–|jg}| |¡t d|¡}| ¡\}}d|j}|rN|djj |¡rNdS|rl|djj |¡rl|sldS| dd  dd„||Dƒ¡|f¡dS)NrZfix_éÿÿÿÿz5Fixer run order (%s) is incorrect; %s should be last.ú, cSsg|] }|jj‘qSr)Ú __class__Ú __module__)Ú.0ÚxrrrÚ Dóz3FixerTestCase.assert_runs_after..) r Úextendrr Z get_fixersr)r*ÚendswithZfailr )rÚnamesÚfixesÚrÚpreZpostÚnrrrÚassert_runs_after7s    ÿzFixerTestCase.assert_runs_after)NrN)F)F)F) Ú__name__r*Ú __qualname__rrrr#r&r"r6rrrrr s    rc@s(eZdZdZdd„Zdd„Zdd„ZdS) ÚTest_neÚnecCsd}d}| ||¡dS)Nzif x <> y: passzif x != y: pass©r©rÚbÚarrrÚ test_basicIszTest_ne.test_basiccCsd}d}| ||¡dS)Nzif x<>y: passzif x!=y: passr;r<rrrÚtest_no_spacesQszTest_ne.test_no_spacescCsd}d}| ||¡dS)Nzif x<>y<>z: passzif x!=y!=z: passr;r<rrrÚ test_chainedYszTest_ne.test_chainedN)r7r*r8r r?r@rArrrrr9Fsr9c@sheZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„ZdS)Ú Test_has_keyZhas_keycCsd}d}| ||¡dS)Nz$x = d.has_key("x") or d.has_key("y")zx = "x" in d or "y" in dr;r<rrrÚtest_1dszTest_has_key.test_1cCsd}d}| ||¡dS)Nzx = a.b.c.d.has_key("x") ** 3zx = ("x" in a.b.c.d) ** 3r;r<rrrÚtest_2iszTest_has_key.test_2cCsd}d}| ||¡dS)Nz!x = a.b.has_key(1 + 2).__repr__()zx = (1 + 2 in a.b).__repr__()r;r<rrrÚtest_3nszTest_has_key.test_3cCsd}d}| ||¡dS)Nz,x = a.b.has_key(1 + 2).__repr__() ** -3 ** 4z(x = (1 + 2 in a.b).__repr__() ** -3 ** 4r;r<rrrÚtest_4sszTest_has_key.test_4cCsd}d}| ||¡dS)Nzx = a.has_key(f or g)zx = (f or g) in ar;r<rrrÚtest_5xszTest_has_key.test_5cCsd}d}| ||¡dS)Nzx = a + b.has_key(c)zx = a + (c in b)r;r<rrrÚtest_6}szTest_has_key.test_6cCsd}d}| ||¡dS)Nzx = a.has_key(lambda: 12)zx = (lambda: 12) in ar;r<rrrÚtest_7‚szTest_has_key.test_7cCsd}d}| ||¡dS)Nzx = a.has_key(a for a in b)zx = (a for a in b) in ar;r<rrrÚtest_8‡szTest_has_key.test_8cCsd}d}| ||¡dS)Nzif not a.has_key(b): passzif b not in a: passr;r<rrrÚtest_9ŒszTest_has_key.test_9cCsd}d}| ||¡dS)Nz$if not a.has_key(b).__repr__(): passz if not (b in a).__repr__(): passr;r<rrrÚtest_10‘szTest_has_key.test_10cCsd}d}| ||¡dS)Nzif not a.has_key(b) ** 2: passzif not (b in a) ** 2: passr;r<rrrÚtest_11–szTest_has_key.test_11N)r7r*r8r rCrDrErFrGrHrIrJrKrLrMrrrrrBasrBc@sàeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„Zd6S)7Ú Test_applyZapplycCsd}d}| ||¡dS)Nzx = apply(f, g + h)z x = f(*g + h)r;r<rrrrCžszTest_apply.test_1cCsd}d}| ||¡dS)Nzy = apply(f, g, h)zy = f(*g, **h)r;r<rrrrD£szTest_apply.test_2cCsd}d}| ||¡dS)Nz z = apply(fs[0], g or h, h or g)zz = fs[0](*g or h, **h or g)r;r<rrrrE¨szTest_apply.test_3cCsd}d}| ||¡dS)Nzapply(f, (x, y) + t)zf(*(x, y) + t)r;r<rrrrF­szTest_apply.test_4cCsd}d}| ||¡dS)Nzapply(f, args,)úf(*args)r;r<rrrrG²szTest_apply.test_5cCsd}d}| ||¡dS)Nzapply(f, args, kwds,)úf(*args, **kwds)r;r<rrrrH·szTest_apply.test_6cCsd}d}| ||¡dS)Nzx = apply(f+g, args)zx = (f+g)(*args)r;r<rrrÚtest_complex_1¾szTest_apply.test_complex_1cCsd}d}| ||¡dS)Nzx = apply(f*g, args)zx = (f*g)(*args)r;r<rrrÚtest_complex_2ÃszTest_apply.test_complex_2cCsd}d}| ||¡dS)Nzx = apply(f**g, args)zx = (f**g)(*args)r;r<rrrÚtest_complex_3ÈszTest_apply.test_complex_3cCsd}d}| ||¡dS)Nzx = apply(f.g, args)zx = f.g(*args)r;r<rrrÚtest_dotted_nameÏszTest_apply.test_dotted_namecCsd}d}| ||¡dS)Nzx = apply(f[x], args)zx = f[x](*args)r;r<rrrÚtest_subscriptÔszTest_apply.test_subscriptcCsd}d}| ||¡dS)Nzx = apply(f(), args)zx = f()(*args)r;r<rrrÚ test_callÙszTest_apply.test_callcCsd}d}| ||¡dS)Nz"x = apply(a.b.c.d.e.f, args, kwds)zx = a.b.c.d.e.f(*args, **kwds)r;r<rrrÚ test_extremeßszTest_apply.test_extremecCsd}d}| ||¡dS)Nz1apply( # foo f, # bar args)rOr;r<rrrÚtest_weird_commentsåszTest_apply.test_weird_commentscCsd}| |¡dS)Nzapply()r$©rÚsrrrÚtest_unchanged_1îszTest_apply.test_unchanged_1cCsd}| |¡dS)Nzapply(f)r$rYrrrÚtest_unchanged_2òszTest_apply.test_unchanged_2cCsd}| |¡dS)Nz apply(f,)r$rYrrrÚtest_unchanged_3öszTest_apply.test_unchanged_3cCsd}| |¡dS)Nzapply(f, args, kwds, extras)r$rYrrrÚtest_unchanged_4úszTest_apply.test_unchanged_4cCsd}| |¡dS)Nzapply(f, *args, **kwds)r$rYrrrÚtest_unchanged_5þszTest_apply.test_unchanged_5cCsd}| |¡dS)Nzapply(f, *args)r$rYrrrÚtest_unchanged_6szTest_apply.test_unchanged_6cCsd}| |¡dS)Nzapply(f, **kwds)r$rYrrrÚtest_unchanged_6bszTest_apply.test_unchanged_6bcCsd}| |¡dS)Nz#apply(func=f, args=args, kwds=kwds)r$rYrrrÚtest_unchanged_7 szTest_apply.test_unchanged_7cCsd}| |¡dS)Nzapply(f, args=args, kwds=kwds)r$rYrrrÚtest_unchanged_8szTest_apply.test_unchanged_8cCsd}| |¡dS)Nzapply(f, args, kwds=kwds)r$rYrrrÚtest_unchanged_9szTest_apply.test_unchanged_9cCsd}d}| ||¡dS)Nzapply( f, args, kwds)rPr;©rr>r=rrrÚ test_space_1szTest_apply.test_space_1cCsd}d}| ||¡dS)Nzapply( f ,args,kwds )rPr;rerrrÚ test_space_2szTest_apply.test_space_2N)r7r*r8r rCrDrErFrGrHrQrRrSrTrUrVrWrXr[r\r]r^r_r`rarbrcrdrfrgrrrrrN›s6 rNc@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) Ú Test_reloadÚreloadcCsd}d}| ||¡dS)Nz reload(a)z$import importlib importlib.reload(a)r;r<rrrÚtest#szTest_reload.testcCs,d}d}| ||¡d}d}| ||¡dS)Nzreload( a ) # commentz0import importlib importlib.reload( a ) # commentzreload( a ) # commentz1import importlib importlib.reload( a ) # commentr;r<rrrÚ test_comment(s  zTest_reload.test_commentcCs@d}d}| ||¡d}d}| ||¡d}d}| ||¡dS)Nz reload( a )z&import importlib importlib.reload( a )z reload( a)z%import importlib importlib.reload( a)z reload(a )z%import importlib importlib.reload(a )r;r<rrrÚ test_space2s  zTest_reload.test_spacecCs‚d}| |¡d}| |¡d}| |¡d}| |¡d}| |¡d}| |¡d}| |¡d}| |¡d }| |¡dS) Nz reload(a=1)z reload(f, g)z reload(f, *h)zreload(f, *h, **i)zreload(f, **i)zreload(*h, **i)z reload(*h)z reload(**i)zreload()r$rYrrrÚtest_unchanged?s$        zTest_reload.test_unchangedN)r7r*r8r rjrkrlrmrrrrrh s   rhc@s(eZdZdZdd„Zdd„Zdd„ZdS) Ú Test_internÚinterncCs@d}d}| ||¡d}d}| ||¡d}d}| ||¡dS)Nzx = intern( a )z"import sys x = sys.intern( a )z%y = intern("b" # test )z4import sys y = sys.intern("b" # test )zz = intern(a+b+c.d, )z&import sys z = sys.intern(a+b+c.d, )r;r<rrrÚtest_prefix_preservation^s  z$Test_intern.test_prefix_preservationcCs@d}d}| ||¡d}d}| ||¡d}d}| ||¡dS)Nz x = intern(a)zimport sys x = sys.intern(a)zz = intern(a+b+c.d,)z#import sys z = sys.intern(a+b+c.d,)z"intern("y%s" % 5).replace("y", "")z1import sys sys.intern("y%s" % 5).replace("y", "")r;r<rrrrjms  zTest_intern.testcCsJd}| |¡d}| |¡d}| |¡d}| |¡d}| |¡dS)Nz intern(a=1)z intern(f, g)z intern(*h)z intern(**i)zintern()r$rYrrrrm|s    zTest_intern.test_unchangedN)r7r*r8r rprjrmrrrrrn[srnc@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) Ú Test_reduceÚreducecCsd}d}| ||¡dS)Nzreduce(a, b, c)z,from functools import reduce reduce(a, b, c)r;r<rrrÚtest_simple_callszTest_reduce.test_simple_callcCsd}d}| ||¡dS)Nzdef x(arg): reduce(sum, [])z8from functools import reduce def x(arg): reduce(sum, [])r;r<rrrÚ test_bug_7253”szTest_reduce.test_bug_7253cCsd}d}| ||¡dS)Nzreduce(lambda x, y: x + y, seq)z>sys.stderr, 1, 2, 3zprint(1, 2, 3, file=sys.stderr)r;r<rrrÚ!test_vargs_without_trailing_commaûsz,Test_print.test_vargs_without_trailing_commacCsd}d}| ||¡dS)Nzprint >>sys.stderr, 1, 2,z%print(1, 2, end=' ', file=sys.stderr)r;r<rrrÚtest_with_trailing_commasz#Test_print.test_with_trailing_commacCsd}d}| ||¡dS)Nzprint >>sys.stderr, 1+1zprint(1+1, file=sys.stderr)r;r<rrrÚtest_no_trailing_commasz!Test_print.test_no_trailing_commacCsd}d}| ||¡dS)Nzprint >> sys.stderrzprint(file=sys.stderr)r;r<rrrÚtest_spaces_before_file sz"Test_print.test_spaces_before_filecCs&d}| |¡d}d}| ||¡dS)NzrrrÚtest_with_future_print_functions  z*Test_print.test_with_future_print_functionN)r7r*r8r rprzr|rCrDrErFrGr}r~rr€rr‚rƒr„r†rrrrrv¯s$ rvc@s`eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dS)Ú Test_execÚexeccCsd}d}| ||¡dS)Nz exec code in ns1, ns2z exec(code, ns1, ns2)r;r<rrrrpsz"Test_exec.test_prefix_preservationcCsd}d}| ||¡dS)Nz exec codeú exec(code)r;r<rrrr?!szTest_exec.test_basiccCsd}d}| ||¡dS)Nzexec code in nsúexec(code, ns)r;r<rrrÚtest_with_globals&szTest_exec.test_with_globalscCsd}d}| ||¡dS)Nzexec code in ns1, ns2úexec(code, ns1, ns2)r;r<rrrÚtest_with_globals_locals+sz"Test_exec.test_with_globals_localscCsd}d}| ||¡dS)Nzexec (a.b()) in nszexec((a.b()), ns)r;r<rrrrQ0szTest_exec.test_complex_1cCsd}d}| ||¡dS)Nzexec a.b() + c in nszexec(a.b() + c, ns)r;r<rrrrR5szTest_exec.test_complex_2cCsd}| |¡dS)Nr‰r$rYrrrr[<szTest_exec.test_unchanged_1cCsd}| |¡dS)Nz exec (code)r$rYrrrr\@szTest_exec.test_unchanged_2cCsd}| |¡dS)NrŠr$rYrrrr]DszTest_exec.test_unchanged_3cCsd}| |¡dS)NrŒr$rYrrrr^HszTest_exec.test_unchanged_4N)r7r*r8r rpr?r‹rrQrRr[r\r]r^rrrrr‡sr‡c@sHeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dS)Ú Test_reprÚreprcCsd}d}| ||¡dS)Nz x = `1 + 2`zx = repr(1 + 2)r;r<rrrrpOsz"Test_repr.test_prefix_preservationcCsd}d}| ||¡dS)Nz x = `1 + 2`zx = repr(1 + 2)r;r<rrrÚ test_simple_1TszTest_repr.test_simple_1cCsd}d}| ||¡dS)Nzy = `x`z y = repr(x)r;r<rrrÚ test_simple_2YszTest_repr.test_simple_2cCsd}d}| ||¡dS)Nzz = `y`.__repr__()zz = repr(y).__repr__()r;r<rrrÚ test_complex^szTest_repr.test_complexcCsd}d}| ||¡dS)Nz x = `1, 2, 3`zx = repr((1, 2, 3))r;r<rrrr}cszTest_repr.test_tuplecCsd}d}| ||¡dS)Nz x = `1 + `2``zx = repr(1 + repr(2))r;r<rrrÚ test_nestedhszTest_repr.test_nestedcCsd}d}| ||¡dS)Nzx = `1, 2 + `3, 4``zx = repr((1, 2 + repr((3, 4))))r;r<rrrÚtest_nested_tuplesmszTest_repr.test_nested_tuplesN) r7r*r8r rprr‘r’r}r“r”rrrrrŽLsrŽc@seZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"S)#Ú Test_exceptÚexceptcCsd}d}| ||¡dS)Nzq try: pass except (RuntimeError, ImportError), e: passzs try: pass except (RuntimeError, ImportError) as e: passr;r<rrrrpusz$Test_except.test_prefix_preservationcCsd}d}| ||¡dS)NzV try: pass except Foo, e: passúX try: pass except Foo as e: passr;r<rrrÚ test_simple‚szTest_except.test_simplecCsd}d}| ||¡dS)NzU try: pass except Foo,e: passr—r;r<rrrÚ"test_simple_no_space_before_targetsz.Test_except.test_simple_no_space_before_targetcCsd}d}| ||¡dS)NzÈ def foo(): try: pass except Exception, (f, e): pass except ImportError, e: passa  def foo(): try: pass except Exception as xxx_todo_changeme: (f, e) = xxx_todo_changeme.args pass except ImportError as e: passr;r<rrrÚtest_tuple_unpackœs  zTest_except.test_tuple_unpackcCsd}d}| ||¡dS)Nzn try: pass except (RuntimeError, ImportError), e: passzp try: pass except (RuntimeError, ImportError) as e: passr;r<rrrÚtest_multi_class±szTest_except.test_multi_classcCsd}d}| ||¡dS)Nza try: pass except Exception, [a, b]: passzž try: pass except Exception as xxx_todo_changeme: [a, b] = xxx_todo_changeme.args passr;r<rrrÚtest_list_unpack¿szTest_except.test_list_unpackcCsd}d}| ||¡dS)Nz_ try: pass except Exception, d[5]: passz— try: pass except Exception as xxx_todo_changeme: d[5] = xxx_todo_changeme passr;r<rrrÚtest_weird_target_1ÎszTest_except.test_weird_target_1cCsd}d}| ||¡dS)Nz` try: pass except Exception, a.foo: passz˜ try: pass except Exception as xxx_todo_changeme: a.foo = xxx_todo_changeme passr;r<rrrÚtest_weird_target_2ÝszTest_except.test_weird_target_2cCsd}d}| ||¡dS)Nzb try: pass except Exception, a().foo: passzš try: pass except Exception as xxx_todo_changeme: a().foo = xxx_todo_changeme passr;r<rrrÚtest_weird_target_3ìszTest_except.test_weird_target_3cCsd}d}| ||¡dS)Nz… try: pass except Exception, a: pass except: passz‡ try: pass except Exception as a: pass except: passr;r<rrrÚtest_bare_exceptûszTest_except.test_bare_exceptcCsd}d}| ||¡dS)NzÖ try: pass except Exception, a: pass except: pass else: pass finally: passzØ try: pass except Exception as a: pass except: pass else: pass finally: passr;r<rrrÚ!test_bare_except_and_else_finally s  z-Test_except.test_bare_except_and_else_finallycCsd}d}| ||¡dS)Nz» try: pass except TypeError, b: pass except Exception, a: pass except: passz¿ try: pass except TypeError as b: pass except Exception as a: pass except: passr;r<rrrÚ+test_multi_fixed_excepts_before_bare_except's  z7Test_except.test_multi_fixed_excepts_before_bare_exceptcCsTd}d}| ||¡d}d}| ||¡d}d}| ||¡d}d}| ||¡dS) Nzd try: raise TypeError except TypeError, e: pass zf try: raise TypeError except TypeError as e: pass zd try: raise TypeError except TypeError, e: pass zf try: raise TypeError except TypeError as e: pass zT try: raise TypeError except TypeError, e: pass zV try: raise TypeError except TypeError as e: pass z try: raise TypeError except TypeError, e: pass else: function() finally: done() z try: raise TypeError except TypeError as e: pass else: function() finally: done() r;r<rrrÚtest_one_line_suites=s   z Test_except.test_one_line_suitescCsd}| |¡dS)NzO try: pass except: passr$rYrrrr[mszTest_except.test_unchanged_1cCsd}| |¡dS)NzY try: pass except Exception: passr$rYrrrr\uszTest_except.test_unchanged_2cCsd}| |¡dS)Nzg try: pass except (Exception, SystemExit): passr$rYrrrr]}szTest_except.test_unchanged_3N)r7r*r8r rpr˜r™ršr›rœrržrŸr r¡r¢r£r[r\r]rrrrr•rs"   0r•c@s˜eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$S)%Ú Test_raiseÚraisecCsd}d}| ||¡dS)Nzraise Exception, 5úraise Exception(5)r;r<rrrr?ˆszTest_raise.test_basiccCs,d}d}| ||¡d}d}| ||¡dS)Nzraise Exception,5r¦zraise Exception, 5zraise Exception(5)r;r<rrrrps  z#Test_raise.test_prefix_preservationcCs@d}d}| ||¡d}d}| ||¡d}d}| ||¡dS)Nzraise Exception, 5 # foozraise Exception(5) # foozraise E, (5, 6) % (a, b) # foozraise E((5, 6) % (a, b)) # fooz:def foo(): raise Exception, 5, 6 # foozIdef foo(): raise Exception(5).with_traceback(6) # foor;r<rrrÚtest_with_comments–s  zTest_raise.test_with_commentscCsd}d}| ||¡dS)Nzraise Exception(5), None, tbz%raise Exception(5).with_traceback(tb)r;r<rrrÚtest_None_value¥szTest_raise.test_None_valuecCsd}d}| ||¡dS)Nzraise Exception, (5, 6, 7)zraise Exception(5, 6, 7)r;r<rrrÚtest_tuple_valueªszTest_raise.test_tuple_valuecCsd}d}| ||¡dS)Nzraise E, (5, 6) % (a, b)zraise E((5, 6) % (a, b))r;r<rrrÚtest_tuple_detection¯szTest_raise.test_tuple_detectioncCsd}d}| ||¡dS)Nzraise (((E1, E2), E3), E4), Vú raise E1(V)r;r<rrrÚtest_tuple_exc_1´szTest_raise.test_tuple_exc_1cCsd}d}| ||¡dS)Nzraise (E1, (E2, E3), E4), Vr«r;r<rrrÚtest_tuple_exc_2¹szTest_raise.test_tuple_exc_2cCsd}| |d¡dS)Nz raise 'foo'ú+Python 3 does not support string exceptions©r&rYrrrÚtest_string_excÀszTest_raise.test_string_exccCsd}| |d¡dS)Nzraise "foo", 5r®r¯rYrrrÚtest_string_exc_valÄszTest_raise.test_string_exc_valcCsd}| |d¡dS)Nzraise "foo", 5, 6r®r¯rYrrrÚtest_string_exc_val_tbÈsz!Test_raise.test_string_exc_val_tbcCsd}d}| ||¡dS)Nz4def foo(): raise Exception, 5, 6úCdef foo(): raise Exception(5).with_traceback(6)r;r<rrrÚ test_tb_1ÎszTest_raise.test_tb_1cCsd}d}| ||¡dS)Nzhdef foo(): a = 5 raise Exception, 5, 6 b = 6úwdef foo(): a = 5 raise Exception(5).with_traceback(6) b = 6r;r<rrrÚ test_tb_2ÕszTest_raise.test_tb_2cCsd}d}| ||¡dS)Nz2def foo(): raise Exception,5,6r³r;r<rrrÚ test_tb_3àszTest_raise.test_tb_3cCsd}d}| ||¡dS)Nzfdef foo(): a = 5 raise Exception,5,6 b = 6rµr;r<rrrÚ test_tb_4çszTest_raise.test_tb_4cCsd}d}| ||¡dS)Nzd?„Z"d@dA„Z#dBdC„Z$dDdE„Z%dFdG„Z&dHS)IÚ Test_dictÚdictcCs|d}d}| ||¡d}d}| ||¡d}d}| ||¡d}d}| ||¡d }d }| ||¡d }d}| ||¡dS) Nzif d. keys ( ) : passz if list(d. keys ( )) : passzif d. items ( ) : passz!if list(d. items ( )) : passzif d. iterkeys ( ) : passzif iter(d. keys ( )) : passz"[i for i in d. iterkeys( ) ]z[i for i in d. keys( ) ]zif d. viewkeys ( ) : passzif d. keys ( ) : passz"[i for i in d. viewkeys( ) ]r;r<rrrrpôs$     z"Test_dict.test_prefix_preservationcCs|d}d}| ||¡d}d}| ||¡d}d}| ||¡d}d}| ||¡d}d}| ||¡d }d}| ||¡dS) Nzd.keys() # foozlist(d.keys()) # foozd.items() # foozlist(d.items()) # foozd.iterkeys() # fooziter(d.keys()) # fooz/[i for i in d.iterkeys() # foo ]z+[i for i in d.keys() # foo ]zd.viewitems() # foor;r<rrrÚtest_trailing_comment s$     zTest_dict.test_trailing_commentcCsFtjD]:}d|}| |¡d|}| |¡d|}| |¡qdS)Nzs = %s(d.keys())zs = %s(d.values())zs = %s(d.items())©rZconsuming_callsr")rÚwrapperrZrrrrm*s   zTest_dict.test_unchangedcCs,d}d}| ||¡d}d}| ||¡dS)Núd.keys()úlist(d.keys())za[0].foo().keys()zlist(a[0].foo().keys())r;r<rrrÚtest_015s  zTest_dict.test_01cCsd}d}| ||¡dS)Nú d.items()zlist(d.items())r;r<rrrÚtest_02>szTest_dict.test_02cCsd}d}| ||¡dS)Nú d.values()zlist(d.values())r;r<rrrÚtest_03CszTest_dict.test_03cCsd}d}| ||¡dS)Nz d.iterkeys()úiter(d.keys())r;r<rrrÚtest_04HszTest_dict.test_04cCsd}d}| ||¡dS)Nz d.iteritems()ziter(d.items())r;r<rrrÚtest_05MszTest_dict.test_05cCsd}d}| ||¡dS)Nzd.itervalues()ziter(d.values())r;r<rrrÚtest_06RszTest_dict.test_06cCsd}| |¡dS)Nr×r$rYrrrÚtest_07WszTest_dict.test_07cCsd}| |¡dS)Núsorted(d.keys())r$rYrrrÚtest_08[szTest_dict.test_08cCsd}d}| ||¡dS)NrÝziter(list(d.keys()))r;r<rrrÚtest_09_szTest_dict.test_09cCsd}d}| ||¡dS)Nz foo(d.keys())zfoo(list(d.keys()))r;r<rrrrLdszTest_dict.test_10cCsd}d}| ||¡dS)Núfor i in d.keys(): print iz for i in list(d.keys()): print ir;r<rrrrMiszTest_dict.test_11cCsd}d}| ||¡dS)Nzfor i in d.iterkeys(): print irår;r<rrrÚtest_12nszTest_dict.test_12cCsd}d}| ||¡dS)Nú[i for i in d.keys()]z for i in list(d.keys())]r;r<rrrÚtest_13sszTest_dict.test_13cCsd}d}| ||¡dS)Nz[i for i in d.iterkeys()]rçr;r<rrrÚtest_14xszTest_dict.test_14cCsd}d}| ||¡dS)Nú(i for i in d.keys())z(i for i in list(d.keys()))r;r<rrrÚtest_15}szTest_dict.test_15cCsd}d}| ||¡dS)Nz(i for i in d.iterkeys())rêr;r<rrrÚtest_16‚szTest_dict.test_16cCsd}d}| ||¡dS)Nziter(d.iterkeys())rÝr;r<rrrÚtest_17‡szTest_dict.test_17cCsd}d}| ||¡dS)Nzlist(d.iterkeys())r×r;r<rrrÚtest_18ŒszTest_dict.test_18cCsd}d}| ||¡dS)Nzsorted(d.iterkeys())râr;r<rrrÚtest_19‘szTest_dict.test_19cCsd}d}| ||¡dS)Nzfoo(d.iterkeys())zfoo(iter(d.keys()))r;r<rrrÚtest_20–szTest_dict.test_20cCsd}d}| ||¡dS)Nzprint h.iterkeys().next()zprint iter(h.keys()).next()r;r<rrrÚtest_21›szTest_dict.test_21cCsd}d}| ||¡dS)Nzprint h.keys()[0]zprint list(h.keys())[0]r;r<rrrÚtest_22 szTest_dict.test_22cCsd}d}| ||¡dS)Nzprint list(h.iterkeys().next())z!print list(iter(h.keys()).next())r;r<rrrÚtest_23¥szTest_dict.test_23cCsd}d}| ||¡dS)Nzfor x in h.keys()[0]: print xz#for x in list(h.keys())[0]: print xr;r<rrrÚtest_24ªszTest_dict.test_24cCsd}d}| ||¡dS)Nz d.viewkeys()rÖr;r<rrrÚtest_25¯szTest_dict.test_25cCsd}d}| ||¡dS)Nz d.viewitems()rÙr;r<rrrÚtest_26´szTest_dict.test_26cCsd}d}| ||¡dS)Nzd.viewvalues()rÛr;r<rrrÚtest_27¹szTest_dict.test_27cCsd}d}| ||¡dS)Nz[i for i in d.viewkeys()]rçr;r<rrrÚtest_28¾szTest_dict.test_28cCsd}d}| ||¡dS)Nz(i for i in d.viewkeys())rêr;r<rrrÚtest_29ÃszTest_dict.test_29cCsd}d}| ||¡dS)Nziter(d.viewkeys())rÝr;r<rrrÚtest_30ÈszTest_dict.test_30cCsd}d}| ||¡dS)Nzlist(d.viewkeys())r×r;r<rrrÚtest_31ÍszTest_dict.test_31cCsd}d}| ||¡dS)Nzsorted(d.viewkeys())râr;r<rrrÚtest_32ÒszTest_dict.test_32N)'r7r*r8r rprÓrmrØrÚrÜrÞrßràrárãrärLrMrærèrérërìrírîrïrðrñròrórôrõrör÷rørùrúrûrürrrrrÑñsH  rÑc@sXeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dS)Ú Test_xrangeÚxrangecCs@d}d}| ||¡d}d}| ||¡d}d}| ||¡dS)Nzx = xrange( 10 )zx = range( 10 )zx = xrange( 1 , 10 )zx = range( 1 , 10 )zx = xrange( 0 , 10 , 2 )zx = range( 0 , 10 , 2 )r;r<rrrrpÚs  z$Test_xrange.test_prefix_preservationcCsd}d}| ||¡dS)Nzx = xrange(10)z x = range(10)r;r<rrrÚtest_single_argçszTest_xrange.test_single_argcCsd}d}| ||¡dS)Nzx = xrange(1, 10)zx = range(1, 10)r;r<rrrÚ test_two_argsìszTest_xrange.test_two_argscCsd}d}| ||¡dS)Nzx = xrange(0, 10, 2)zx = range(0, 10, 2)r;r<rrrÚtest_three_argsñszTest_xrange.test_three_argscCshd}d}| ||¡d}d}| ||¡d}d}| ||¡d}d}| ||¡d }d }| ||¡dS) Nzx = range(10, 3, 9)zx = list(range(10, 3, 9))zx = foo(range(10, 3, 9))zx = foo(list(range(10, 3, 9)))zx = range(10, 3, 9) + [4]zx = list(range(10, 3, 9)) + [4]zx = range(10)[::-1]zx = list(range(10))[::-1]zx = range(10) [3]zx = list(range(10)) [3]r;r<rrrÚtest_wrap_in_listös    zTest_xrange.test_wrap_in_listcCs,d}d}| ||¡d}d}| ||¡dS)Nzfor i in xrange(10): j=izfor i in range(10): j=iz[i for i in xrange(10)]ú[i for i in range(10)]r;r<rrrÚtest_xrange_in_for s  zTest_xrange.test_xrange_in_forcCs| d¡| d¡dS)Nzfor i in range(10): passrr$rÐrrrÚtest_range_in_fors zTest_xrange.test_range_in_forcCs| d¡dS)Nzx in range(10, 3, 9)r$rÐrrrÚtest_in_contains_testsz!Test_xrange.test_in_contains_testcCstjD]}| d|¡qdS)Nza = %s(range(10))rÔ)rÚcallrrrÚtest_in_consuming_contexts z%Test_xrange.test_in_consuming_contextN) r7r*r8r rprÿrrrrrrrrrrrrý×s  rýcs$eZdZ‡fdd„Zdd„Z‡ZS)ÚTest_xrange_with_reducecstt|ƒ ddg¡dS)Nrþrr)Úsuperr rrЩr)rrr!szTest_xrange_with_reduce.setUpcCsd}d}| ||¡dS)Nzreduce(x, xrange(5))z0from functools import reduce reduce(x, range(5))r;r<rrrÚtest_double_transform$sz-Test_xrange_with_reduce.test_double_transform)r7r*r8rr Ú __classcell__rrr rr s r c@sPeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dS)ÚTest_raw_inputZ raw_inputcCs,d}d}| ||¡d}d}| ||¡dS)Nzx = raw_input( )zx = input( )zx = raw_input( '' )úx = input( '' )r;r<rrrrp-s  z'Test_raw_input.test_prefix_preservationcCsd}d}| ||¡dS)Nzx = raw_input()ú x = input()r;r<rrrrC6szTest_raw_input.test_1cCsd}d}| ||¡dS)Nzx = raw_input('')ú x = input('')r;r<rrrrD;szTest_raw_input.test_2cCsd}d}| ||¡dS)Nzx = raw_input('prompt')úx = input('prompt')r;r<rrrrE@szTest_raw_input.test_3cCsd}d}| ||¡dS)Nzx = raw_input(foo(a) + 6)zx = input(foo(a) + 6)r;r<rrrrFEszTest_raw_input.test_4cCsd}d}| ||¡dS)Nzx = raw_input(invite).split()zx = input(invite).split()r;r<rrrrGJszTest_raw_input.test_5cCsd}d}| ||¡dS)Nz x = raw_input(invite) . split ()zx = input(invite) . split ()r;r<rrrrHOszTest_raw_input.test_6cCsd}d}| ||¡dS)Nzx = int(raw_input())zx = int(input())r;r<rrrrJTszTest_raw_input.test_8N) r7r*r8r rprCrDrErFrGrHrJrrrrr*s rc@s(eZdZdZgd¢Zdd„Zdd„ZdS)ÚTest_funcattrsZ funcattrs)ZclosureÚdocÚnameÚdefaultsÚcodeÚglobalsrÒcCsH|jD]<}d|}d|}| ||¡d|}d|}| ||¡qdS)Nz a.func_%súa.__%s__zself.foo.func_%s.foo_barúself.foo.__%s__.foo_bar©Úattrsr©rÚattrr=r>rrrrj^s  zTest_funcattrs.testcCsF|jD]:}d|}| |¡d|}| |¡d|}| |¡qdS)Nzfoo(func_%s + 5)ú f(foo.__%s__)úf(foo.__%s__.foo)©rr"©rrrZrrrrmhs   zTest_funcattrs.test_unchangedN©r7r*r8r rrjrmrrrrrYs rc@s(eZdZdZdd„Zdd„Zdd„ZdS) ÚTest_xreadlinesZ xreadlinescCs@d}d}| ||¡d}d}| ||¡d}d}| ||¡dS)Nzfor x in f.xreadlines(): passzfor x in f: passz!for x in foo().xreadlines(): passzfor x in foo(): passz'for x in (5 + foo()).xreadlines(): passzfor x in (5 + foo()): passr;r<rrrrVvs  zTest_xreadlines.test_callcCs@d}d}| ||¡d}d}| ||¡d}d}| ||¡dS)Nzfoo(f.xreadlines + 5)zfoo(f.__iter__ + 5)zfoo(f().xreadlines + 5)zfoo(f().__iter__ + 5)zfoo((5 + f()).xreadlines + 5)zfoo((5 + f()).__iter__ + 5)r;r<rrrÚ test_attr_refƒs  zTest_xreadlines.test_attr_refcCs<d}| |¡d}| |¡d}| |¡d}| |¡dS)Nzfor x in f.xreadlines(5): passz for x in f.xreadlines(k=5): passz$for x in f.xreadlines(*k, **v): passzfoo(xreadlines)r$rYrrrrms   zTest_xreadlines.test_unchangedN)r7r*r8r rVr%rmrrrrr$ss  r$c@s<eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd S)ÚImportsFixerTestscCsP|j ¡D]@\}}d|}d|}| ||¡d|}d|}| ||¡q dS)Nú import %szimport foo, %s, bar©ÚmodulesÚitemsr©rÚoldÚnewr=r>rrrÚtest_import_module s z$ImportsFixerTests.test_import_modulecCsl|j ¡D]\\}}d|}d|}| ||¡d|}d|}| ||¡d|}d|}| ||¡q dS)Nzfrom %s import foozfrom %s import foo, barzfrom %s import (yes, no)r(r+rrrÚtest_import_fromªs  z"ImportsFixerTests.test_import_fromcCsP|j ¡D]@\}}d|}d|}| ||¡d|}d|}| ||¡q dS)Nzimport %s as foo_barr(r+rrrÚtest_import_module_as¸s z'ImportsFixerTests.test_import_module_ascCs4|j ¡D]$\}}d|}d|}| ||¡q dS)Nzfrom %s import foo as barr(r+rrrÚtest_import_from_asÂsz%ImportsFixerTests.test_import_from_ascCs4|j ¡D]$\}}d|}d|}| ||¡q dS)Núfrom %s import *r(r+rrrÚ test_starÈszImportsFixerTests.test_starcCsÀ|j ¡D]°\}}d||f}d||f}| ||¡d||f}d||f}| ||¡d|f}| |¡d|||f}d|||f}| ||¡d||f}d||f}| ||¡q dS)NzG import %s foo(%s.bar) zJ from %s import x %s = 23 zJ def f(): %s.method() zJ import %s %s.bar(%s.foo) z@ import %s x.%s )r)r*rr")rr,r-r=r>rZrrrÚtest_import_module_usageÎsBýý ýý ý ýý ýýz*ImportsFixerTests.test_import_module_usageN) r7r*r8r.r/r0r1r3r4rrrrr&žs   r&c@s,eZdZdZddlmZdd„Zdd„ZdS) Ú Test_importsÚimportsé©ÚMAPPINGcCsd}d}| ||¡dS)Nzimport urlparse, cStringIOzimport urllib.parse, ior;r<rrrÚtest_multiple_importssz"Test_imports.test_multiple_importscCsd}d}| ||¡dS)Nzv import copy_reg as bar, HTMLParser as foo, urlparse s = urlparse.spam(bar.foo()) z~ import copyreg as bar, html.parser as foo, urllib.parse s = urllib.parse.spam(bar.foo()) r;r<rrrÚtest_multiple_imports_as sz%Test_imports.test_multiple_imports_asN) r7r*r8r Úfixes.fix_importsr9r)r:r;rrrrr5s r5c@seZdZdZddlmZdS)Ú Test_imports2Úimports2r7r8N)r7r*r8r Úfixes.fix_imports2r9r)rrrrr=sr=cs$eZdZ‡fdd„Zdd„Z‡ZS)ÚTest_imports_fixer_ordercsRtt|ƒ ddg¡ddlm}| ¡|_ddlm}dD]}|||j|<q:dS)Nr6r>r7r8)ÚdbhashÚdumbdbmÚdbmÚgdbm)r r@rr?r9Úcopyr)r<)rZmapping2Zmapping1Úkeyr rrrs    zTest_imports_fixer_order.setUpcCsdD]}||_| d¡qdS)N)r6r>Úimport)r r6)rZfixrrrÚ$test_after_local_imports_refactoring$sz=Test_imports_fixer_order.test_after_local_imports_refactoring)r7r*r8rrHr rrr rr@s r@c@s\eZdZdZddlmZdd„Zdd„Zdd „Z d d „Z d d „Z dd„Z dd„Z dd„ZdS)Ú Test_urllibÚurllibr7r8cCsD|j ¡D]4\}}d|}dd ttdƒ|ƒ¡}| ||¡q dS)Nr'r(r)r)r*r Úmaprr)rr,Úchangesr=r>rrrr..szTest_urllib.test_import_modulec Csî|j ¡D]Þ\}}g}|D]š\}}|D]D}| |¡d||f}d||f}| ||¡d|} | | ¡q&d|d |¡f}d|d |¡f}| ||¡dd |¡} | | ¡qd|d |¡f}d dd„|Dƒ¡}| ||¡q dS)Núfrom %s import %súfrom foo import %sr(Ú cSs"g|]\}}d|d |¡f‘qS)rMr()r )r+r-Úmembersrrrr-Jsÿz0Test_urllib.test_import_from..)r)r*Úappendrr"r ) rr,rLZ all_membersr-rPÚmemberr=r>rZrrrr/4s(         ÿzTest_urllib.test_import_fromcCs$|jD]}d|}| |d¡qdS)Nzimport %s as fooz#This module is now multiple modules©r)r&©rr,rZrrrr0Ns z!Test_urllib.test_import_module_ascCs||j ¡D]l\}}|D]^\}}|D]P}d||f}d||f}| ||¡d|||f}d|||f}| ||¡q"qq dS)Núfrom %s import %s as foo_barzfrom %s import %s as blah, %sr()rr,rLr-rPrRr=r>rrrr1Ss    zTest_urllib.test_import_from_ascCs$|jD]}d|}| |d¡qdS)Nr2zCannot handle star importsrSrTrrrr3^s zTest_urllib.test_starcCs,d}d}| ||¡d}d}| ||¡dS)Nz6 def foo(): from urllib import urlencode, urlopen zZ def foo(): from urllib.parse import urlencode from urllib.request import urlopen zB def foo(): other() from urllib import urlencode, urlopen zf def foo(): other() from urllib.parse import urlencode from urllib.request import urlopen r;r<rrrÚ test_indentedcs  zTest_urllib.test_indentedcCsd}d}| ||¡dS)Nzfrom urllib import getproxiesz%from urllib.request import getproxiesr;r<rrrÚtest_single_import|szTest_urllib.test_single_importc Cs¢|j ¡D]’\}}|D]„\}}|D]v}d dd„|j|Dƒ¡}d|||f}d|||f}| ||¡d|||||f}d|||||f}| ||¡q"qq dS)Nr(cSsg|] \}}|‘qSrr)r+r5Zmemsrrrr-†r.z8Test_urllib.test_import_module_usage..z^ import %s foo(%s.%s) z` import %s %s.%s(%s.%s) )r)r*r r) rr,rLr-rPrRZ new_importr=r>rrrr4‚s(  ÿýý  ý ýz$Test_urllib.test_import_module_usageN)r7r*r8r Zfixes.fix_urllibr9r)r.r/r0r1r3rVrWr4rrrrrI*s  rIc@sHeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dS)Ú Test_inputÚinputcCs,d}d}| ||¡d}d}| ||¡dS)Nzx = input( )zx = eval(input( ))rzx = eval(input( '' ))r;r<rrrrpŸs  z#Test_input.test_prefix_preservationcCsd}d}| ||¡dS)Nzx = input() # foozx = eval(input()) # foor;r<rrrrÓ¨sz Test_input.test_trailing_commentcCs.d}| |¡d}| |¡d}| |¡dS)Núx = eval(input())úx = eval(input(''))úx = eval(input(foo(5) + 9))r$rYrrrrz­s   zTest_input.test_idempotencycCsd}d}| ||¡dS)NrrZr;r<rrrrC·szTest_input.test_1cCsd}d}| ||¡dS)Nrr[r;r<rrrrD¼szTest_input.test_2cCsd}d}| ||¡dS)Nrzx = eval(input('prompt'))r;r<rrrrEÁszTest_input.test_3cCsd}d}| ||¡dS)Nzx = input(foo(5) + 9)r\r;r<rrrrFÆszTest_input.test_4N) r7r*r8r rprÓrzrCrDrErFrrrrrXœs  rXc@s°eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*S)+ÚTest_tuple_paramsZ tuple_paramscCsd}| |¡dS)Nzdef foo(): passr$rYrrrr[Îsz"Test_tuple_params.test_unchanged_1cCsd}| |¡dS)Nzdef foo(a, b, c): passr$rYrrrr\Òsz"Test_tuple_params.test_unchanged_2cCsd}| |¡dS)Nzdef foo(a=3, b=4, c=5): passr$rYrrrr]Ösz"Test_tuple_params.test_unchanged_3cCsd}d}| ||¡dS)Nz8 def foo(((a, b), c)): x = 5zn def foo(xxx_todo_changeme): ((a, b), c) = xxx_todo_changeme x = 5r;r<rrrrCÚszTest_tuple_params.test_1cCsd}d}| ||¡dS)Nz; def foo(((a, b), c), d): x = 5zq def foo(xxx_todo_changeme, d): ((a, b), c) = xxx_todo_changeme x = 5r;r<rrrrDåszTest_tuple_params.test_2cCsd}d}| ||¡dS)Nz@ def foo(((a, b), c), d) -> e: x = 5zv def foo(xxx_todo_changeme, d) -> e: ((a, b), c) = xxx_todo_changeme x = 5r;r<rrrrEðszTest_tuple_params.test_3cCsd}d}| ||¡dS)Nz/ def foo(((a, b), c)): x = 5; y = 7zV def foo(xxx_todo_changeme): ((a, b), c) = xxx_todo_changeme; x = 5; y = 7r;r<rrrÚtest_semicolonûsz Test_tuple_params.test_semicoloncCsd}d}| ||¡dS)NzE def foo(((a, b), c), d, e=5) -> z: x = 5z{ def foo(xxx_todo_changeme, d, e=5) -> z: ((a, b), c) = xxx_todo_changeme x = 5r;r<rrrÚ test_keywordsszTest_tuple_params.test_keywordscCsd}d}| ||¡dS)NzR def foo(((a, b), c), d, *vargs, **kwargs) -> z: x = 5zˆ def foo(xxx_todo_changeme, d, *vargs, **kwargs) -> z: ((a, b), c) = xxx_todo_changeme x = 5r;r<rrrÚ test_varargsszTest_tuple_params.test_varargscCsd}d}| ||¡dS)NzH def foo(((a, b), c), (d, e, f)) -> z: x = 5z¶ def foo(xxx_todo_changeme, xxx_todo_changeme1) -> z: ((a, b), c) = xxx_todo_changeme (d, e, f) = xxx_todo_changeme1 x = 5r;r<rrrÚ test_multi_1szTest_tuple_params.test_multi_1cCsd}d}| ||¡dS)NzQ def foo(x, ((a, b), c), d, (e, f, g), y) -> z: x = 5z¿ def foo(x, xxx_todo_changeme, d, xxx_todo_changeme1, y) -> z: ((a, b), c) = xxx_todo_changeme (e, f, g) = xxx_todo_changeme1 x = 5r;r<rrrÚ test_multi_2%szTest_tuple_params.test_multi_2cCsd}d}| ||¡dS)Nzj def foo(((a, b), c), (d, e, f)) -> z: "foo foo foo foo" x = 5zØ def foo(xxx_todo_changeme, xxx_todo_changeme1) -> z: "foo foo foo foo" ((a, b), c) = xxx_todo_changeme (d, e, f) = xxx_todo_changeme1 x = 5r;r<rrrÚtest_docstring1sz Test_tuple_params.test_docstringcCsd}| |¡dS)Núlambda x: x + 5r$rYrrrÚtest_lambda_no_change?sz'Test_tuple_params.test_lambda_no_changecCsTd}d}| ||¡d}d}| ||¡d}d}| ||¡d}d}| ||¡dS)Nzlambda (x): x + 5rdzlambda(x): x + 5zlambda ((((x)))): x + 5zlambda((((x)))): x + 5r;r<rrrÚtest_lambda_parens_single_argCs   z/Test_tuple_params.test_lambda_parens_single_argcCsTd}d}| ||¡d}d}| ||¡d}d}| ||¡d}d}| ||¡dS)Nzlambda (x, y): x + f(y)zlambda x_y: x_y[0] + f(x_y[1])zlambda(x, y): x + f(y)zlambda (((x, y))): x + f(y)zlambda(((x, y))): x + f(y)r;r<rrrÚtest_lambda_simpleTs   z$Test_tuple_params.test_lambda_simplecCs,d}d}| ||¡d}d}| ||¡dS)Nzlambda (x,): x + f(x)zlambda x1: x1[0] + f(x1[0])zlambda (((x,))): x + f(x)r;r<rrrÚtest_lambda_one_tuplees  z'Test_tuple_params.test_lambda_one_tuplecCsd}d}| ||¡dS)Nzlambda (x, y): x + x + f(x) + xz0lambda x_y: x_y[0] + x_y[0] + f(x_y[0]) + x_y[0]r;r<rrrÚtest_lambda_simple_multi_usensz.Test_tuple_params.test_lambda_simple_multi_usecCsd}d}| ||¡dS)Nzlambda (x, y): y + xzlambda x_y: x_y[1] + x_y[0]r;r<rrrÚtest_lambda_simple_reversessz,Test_tuple_params.test_lambda_simple_reversecCs,d}d}| ||¡d}d}| ||¡dS)Nzlambda (x, (y, z)): x + y + zz2lambda x_y_z: x_y_z[0] + x_y_z[1][0] + x_y_z[1][1]z!lambda (((x, (y, z)))): x + y + zr;r<rrrÚtest_lambda_nestedxs  z$Test_tuple_params.test_lambda_nestedcCsd}d}| ||¡dS)Nz lambda (x, (y, z)): x + y + f(y)z5lambda x_y_z: x_y_z[0] + x_y_z[1][0] + f(x_y_z[1][0])r;r<rrrÚtest_lambda_nested_multi_usesz.Test_tuple_params.test_lambda_nested_multi_useN)r7r*r8r r[r\r]rCrDrEr^r_r`rarbrcrerfrgrhrirjrkrlrrrrr]Ës*         r]c@s(eZdZdZgd¢Zdd„Zdd„ZdS)ÚTest_methodattrsZ methodattrs)ÚfuncrÚclasscCsd|jD]X}d|}|dkr d}nd|}| ||¡d|}|dkrJd}nd|}| ||¡qdS)Nza.im_%sroza.__self__.__class__rzself.foo.im_%s.foo_barz#self.foo.__self__.__class__.foo_barrrrrrrrj‹s  zTest_methodattrs.testcCsF|jD]:}d|}| |¡d|}| |¡d|}| |¡qdS)Nzfoo(im_%s + 5)rr r!r"rrrrm›s   zTest_methodattrs.test_unchangedNr#rrrrrm†srmc@sxeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„Zd6d7„Zd8d9„Zd:d;„Z dd?„Z"d@dA„Z#dBdC„Z$dDdE„Z%dFdG„Z&dHdI„Z'dJdK„Z(dLdM„Z)dNdO„Z*dPdQ„Z+dRdS„Z,dTdU„Z-dVdW„Z.dXdY„Z/dZd[„Z0d\S)]Ú Test_nextÚnextcCsd}d}| ||¡dS)Nz it.next()znext(it)r;r<rrrrC©szTest_next.test_1cCsd}d}| ||¡dS)Nza.b.c.d.next()z next(a.b.c.d)r;r<rrrrD®szTest_next.test_2cCsd}d}| ||¡dS)Nz(a + b).next()z next((a + b))r;r<rrrrE³szTest_next.test_3cCsd}d}| ||¡dS)Nz a().next()z next(a())r;r<rrrrF¸szTest_next.test_4cCsd}d}| ||¡dS)Nza().next() + bz next(a()) + br;r<rrrrG½szTest_next.test_5cCsd}d}| ||¡dS)Nzc( a().next() + b)zc( next(a()) + b)r;r<rrrrHÂszTest_next.test_6cCsd}d}| ||¡dS)NzU for a in b: foo(a) a.next() zT for a in b: foo(a) next(a) r;r<rrrÚtest_prefix_preservation_1Çsz$Test_next.test_prefix_preservation_1cCsd}d}| ||¡dS)Nzq for a in b: foo(a) # abc # def a.next() zp for a in b: foo(a) # abc # def next(a) r;r<rrrÚtest_prefix_preservation_2Ôsz$Test_next.test_prefix_preservation_2cCsd}d}|j||dddS)Nzj next = 5 for a in b: foo(a) a.next() zn next = 5 for a in b: foo(a) a.__next__() T©rr;r<rrrÚtest_prefix_preservation_3ãsz$Test_next.test_prefix_preservation_3cCsd}d}|j||dddS)Nz† next = 5 for a in b: foo(a) # abc # def a.next() zŠ next = 5 for a in b: foo(a) # abc # def a.__next__() Trtr;r<rrrÚtest_prefix_preservation_4òsz$Test_next.test_prefix_preservation_4cCsd}d}|j||dddS)Nzz next = 5 for a in b: foo(foo(a), # abc a.next()) z~ next = 5 for a in b: foo(foo(a), # abc a.__next__()) Trtr;r<rrrÚtest_prefix_preservation_5 sz$Test_next.test_prefix_preservation_5cCsd}d}| ||¡dS)Nze for a in b: foo(foo(a), # abc a.next()) zd for a in b: foo(foo(a), # abc next(a)) r;r<rrrÚtest_prefix_preservation_6 sz$Test_next.test_prefix_preservation_6cCsd}d}| ||¡dS)Nz[ class A: def next(self): pass z_ class A: def __next__(self): pass r;r<rrrÚ test_method_1 szTest_next.test_method_1cCsd}d}| ||¡dS)Nzc class A(object): def next(self): pass zg class A(object): def __next__(self): pass r;r<rrrÚ test_method_2, szTest_next.test_method_2cCsd}d}| ||¡dS)NzX class A: def next(x): pass z\ class A: def __next__(x): pass r;r<rrrÚ test_method_39 szTest_next.test_method_3cCsd}d}| ||¡dS)Nzí class A: def __init__(self, foo): self.foo = foo def next(self): pass def __iter__(self): return self zñ class A: def __init__(self, foo): self.foo = foo def __next__(self): pass def __iter__(self): return self r;r<rrrÚ test_method_4F s  zTest_next.test_method_4cCsd}| |¡dS)Nza class A: def next(self, a, b): pass r$rYrrrÚtest_method_unchanged_ szTest_next.test_method_unchangedcCsd}| |d¡dS)Nzy next = foo class A: def next(self, a, b): pass ú)Calls to builtin next() possibly shadowedr¯rYrrrÚtest_shadowing_assign_simpleg sz&Test_next.test_shadowing_assign_simplecCsd}| |d¡dS)Nz~ (next, a) = foo class A: def next(self, a, b): pass r~r¯rYrrrÚtest_shadowing_assign_tuple_1q sz'Test_next.test_shadowing_assign_tuple_1cCsd}| |d¡dS)Nz‹ (a, (b, (next, c)), a) = foo class A: def next(self, a, b): pass r~r¯rYrrrÚtest_shadowing_assign_tuple_2{ sz'Test_next.test_shadowing_assign_tuple_2cCsd}| |d¡dS)Nz~ [next, a] = foo class A: def next(self, a, b): pass r~r¯rYrrrÚtest_shadowing_assign_list_1… sz&Test_next.test_shadowing_assign_list_1cCsd}| |d¡dS)Nz‹ [a, [b, [next, c]], a] = foo class A: def next(self, a, b): pass r~r¯rYrrrÚtest_shadowing_assign_list_2 sz&Test_next.test_shadowing_assign_list_2cCsd}| |d¡dS)Nz  def foo(): __builtin__.next = foo class A: def next(self, a, b): pass r~r¯rYrrrÚtest_builtin_assign™ szTest_next.test_builtin_assigncCsd}| |d¡dS)Nz¥ def foo(): (a, __builtin__.next) = foo class A: def next(self, a, b): pass r~r¯rYrrrÚtest_builtin_assign_in_tuple¤ sz&Test_next.test_builtin_assign_in_tuplecCsd}| |d¡dS)Nz¥ def foo(): [a, __builtin__.next] = foo class A: def next(self, a, b): pass r~r¯rYrrrÚtest_builtin_assign_in_list¯ sz%Test_next.test_builtin_assign_in_listcCsd}| |¡dS)Nz– def foo(): A.next = foo class A: def next(self, a, b): pass r$rYrrrÚtest_assign_to_nextº szTest_next.test_assign_to_nextcCsd}| |¡dS)Nz› def foo(): (a, A.next) = foo class A: def next(self, a, b): pass r$rYrrrÚtest_assign_to_next_in_tupleÅ sz&Test_next.test_assign_to_next_in_tuplecCsd}| |¡dS)Nz› def foo(): [a, A.next] = foo class A: def next(self, a, b): pass r$rYrrrÚtest_assign_to_next_in_listÐ sz%Test_next.test_assign_to_next_in_listcCsd}| |d¡dS)Nz… import foo.bar as next class A: def next(self, a, b): pass r~r¯rYrrrÚtest_shadowing_import_1Û sz!Test_next.test_shadowing_import_1cCsd}| |d¡dS)NzŠ import bar, bar.foo as next class A: def next(self, a, b): pass r~r¯rYrrrÚtest_shadowing_import_2å sz!Test_next.test_shadowing_import_2cCsd}| |d¡dS)Nz import bar, bar.foo as next, baz class A: def next(self, a, b): pass r~r¯rYrrrÚtest_shadowing_import_3ï sz!Test_next.test_shadowing_import_3cCsd}| |d¡dS)Nz from x import next class A: def next(self, a, b): pass r~r¯rYrrrÚtest_shadowing_import_from_1ù sz&Test_next.test_shadowing_import_from_1cCsd}| |d¡dS)Nzƒ from x.a import next class A: def next(self, a, b): pass r~r¯rYrrrÚtest_shadowing_import_from_2 sz&Test_next.test_shadowing_import_from_2cCsd}| |d¡dS)Nz‡ from x import a, next, b class A: def next(self, a, b): pass r~r¯rYrrrÚtest_shadowing_import_from_3 sz&Test_next.test_shadowing_import_from_3cCsd}| |d¡dS)Nz‰ from x.a import a, next, b class A: def next(self, a, b): pass r~r¯rYrrrÚtest_shadowing_import_from_4 sz&Test_next.test_shadowing_import_from_4cCsd}| |d¡dS)Nz def next(a): pass class A: def next(self, a, b): pass r~r¯rYrrrÚtest_shadowing_funcdef_1! sz"Test_next.test_shadowing_funcdef_1cCsd}d}| ||d¡dS)Nz¡ def next(a): pass class A: def next(self): pass it.next() z© def next(a): pass class A: def __next__(self): pass it.__next__() r~r%r<rrrÚtest_shadowing_funcdef_2, s  z"Test_next.test_shadowing_funcdef_2cCsd}| |d¡dS)NzW def f(): global next next = 5 r~r¯rYrrrÚtest_shadowing_global_1C sz!Test_next.test_shadowing_global_1cCsd}| |d¡dS)Nz] def f(): global a, next, b next = 5 r~r¯rYrrrÚtest_shadowing_global_2K sz!Test_next.test_shadowing_global_2cCsd}| |d¡dS)Nze for next in it(): pass b = 5 c = 6 r~r¯rYrrrÚtest_shadowing_for_simpleS sz#Test_next.test_shadowing_for_simplecCsd}| |d¡dS)Nzh for next, b in it(): pass b = 5 c = 6 r~r¯rYrrrÚtest_shadowing_for_tuple_1] sz$Test_next.test_shadowing_for_tuple_1cCsd}| |d¡dS)Nzp for a, (next, c), b in it(): pass b = 5 c = 6 r~r¯rYrrrÚtest_shadowing_for_tuple_2g sz$Test_next.test_shadowing_for_tuple_2cCsd}d}| ||¡dS)Nzgnext = g.nextzgnext = g.__next__r;r<rrrÚtest_noncall_access_1q szTest_next.test_noncall_access_1cCsd}d}| ||¡dS)Nz f(g.next + 5)zf(g.__next__ + 5)r;r<rrrÚtest_noncall_access_2v szTest_next.test_noncall_access_2cCsd}d}| ||¡dS)Nzf(g().next + 5)zf(g().__next__ + 5)r;r<rrrÚtest_noncall_access_3{ szTest_next.test_noncall_access_3N)1r7r*r8r rCrDrErFrGrHrrrsrurvrwrxryrzr{r|r}rr€rr‚rƒr„r…r†r‡rˆr‰rŠr‹rŒrrŽrrr‘r’r“r”r•r–r—r˜r™ršrrrrrp¦s\                           rpc@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) Ú Test_nonzeroÚnonzerocCsd}d}| ||¡dS)Nzb class A: def __nonzero__(self): pass z_ class A: def __bool__(self): pass r;r<rrrrCƒ szTest_nonzero.test_1cCsd}d}| ||¡dS)Nzj class A(object): def __nonzero__(self): pass úg class A(object): def __bool__(self): pass r;r<rrrrD szTest_nonzero.test_2cCsd}| |¡dS)Nrr$rYrrrr[ szTest_nonzero.test_unchanged_1cCsd}| |¡dS)Nzm class A(object): def __nonzero__(self, a): pass r$rYrrrr\¥ szTest_nonzero.test_unchanged_2cCsd}| |¡dS)NzE def __nonzero__(self): pass r$rYrrrÚtest_unchanged_func­ sz Test_nonzero.test_unchanged_funcN) r7r*r8r rCrDr[r\ržrrrrr›€ s   r›c@sxeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„ZdS)ÚTest_numliteralsZ numliteralscCsd}d}| ||¡dS)NZ0755Ú0o755r;r<rrrÚ test_octal_1· szTest_numliterals.test_octal_1cCsd}d}| ||¡dS)Nza = 12Lúa = 12r;r<rrrÚtest_long_int_1¼ sz Test_numliterals.test_long_int_1cCsd}d}| ||¡dS)Nza = 12lr¢r;r<rrrÚtest_long_int_2Á sz Test_numliterals.test_long_int_2cCsd}d}| ||¡dS)Nz b = 0x12lzb = 0x12r;r<rrrÚ test_long_hexÆ szTest_numliterals.test_long_hexcCs,d}d}| ||¡d}d}| ||¡dS)Nz b = 0x12Lz b = 0x12zb = 0755 # spamzb = 0o755 # spamr;r<rrrÚtest_comments_and_spacingË s  z*Test_numliterals.test_comments_and_spacingcCsd}| |¡dS)NÚ5r$rYrrrÚtest_unchanged_intÔ sz#Test_numliterals.test_unchanged_intcCsd}| |¡dS)Nz5.0r$rYrrrÚtest_unchanged_floatØ sz%Test_numliterals.test_unchanged_floatcCsd}| |¡dS)Nr r$rYrrrÚtest_unchanged_octalÜ sz%Test_numliterals.test_unchanged_octalcCsd}| |¡dS)NZ0xABCr$rYrrrÚtest_unchanged_hexà sz#Test_numliterals.test_unchanged_hexcCsd}| |¡dS)Nz5.0e10r$rYrrrÚtest_unchanged_expä sz#Test_numliterals.test_unchanged_expcCsd}| |¡dS)Nz5 + 4jr$rYrrrÚtest_unchanged_complex_intè sz+Test_numliterals.test_unchanged_complex_intcCsd}| |¡dS)Nz 5.4 + 4.9jr$rYrrrÚtest_unchanged_complex_floatì sz-Test_numliterals.test_unchanged_complex_floatcCs d}| |¡d}| |¡dS)NZ4jz4.4jr$rYrrrÚtest_unchanged_complex_bareð s z,Test_numliterals.test_unchanged_complex_bareN)r7r*r8r r¡r£r¤r¥r¦r¨r©rªr«r¬r­r®r¯rrrrrŸ´ s rŸc@s8eZdZdZddiZdd„Zdd„Zdd „Zd d „Zd S) Ú Test_renamesÚrenamesÚsys)ZmaxintÚmaxsizecCsVt|j ¡ƒD]B\}\}}d||f}d||f}| ||¡d|}| |¡qdS)NrMrN)Úlistr)r*rr")rÚmodr,r-r=r>rZrrrr/ü s    zTest_renames.test_import_fromcCsDt|j ¡ƒD]0\}\}}d||f}d||f}| ||¡qdS)NrU©r´r)r*r©rrµr,r-r=r>rrrr1 s  z Test_renames.test_import_from_ascCsLt|j ¡ƒD]8\}\}}d||||f}d||||f}| ||¡qdS)NzJ import %s foo(%s, %s.%s) r¶r·rrrr4 s ý ýz%Test_renames.test_import_module_usagecCsLt|j ¡ƒD]8\}\}}d||||f}d||||f}| ||¡qdS)NzO from %s import %s foo(%s, %s) r¶r·rrrÚXXX_test_from_import_usage s ý ýz'Test_renames.XXX_test_from_import_usageN) r7r*r8r r)r/r1r4r¸rrrrr°ö s   r°c@s`eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dS)Ú Test_unicodeÚunicodecCs@d}d}| ||¡d}d}| ||¡d}d}| ||¡dS)Nz unicode( x)zstr( x)z unicode(x )z str(x )z u'h'z 'h'r;r<rrrÚtest_whitespace' s  zTest_unicode.test_whitespacecCsd}d}| ||¡dS)Nzunicode(x, y, z)z str(x, y, z)r;r<rrrÚtest_unicode_call4 szTest_unicode.test_unicode_callcCsd}d}| ||¡dS)Nz unichr(u'h')zchr('h')r;r<rrrÚ test_unichr9 szTest_unicode.test_unichrcCsd}d}| ||¡dS)Nzu"x"z"x"r;r<rrrÚtest_unicode_literal_1> sz#Test_unicode.test_unicode_literal_1cCsd}d}| ||¡dS)Nzur'x'zr'x'r;r<rrrÚtest_unicode_literal_2C sz#Test_unicode.test_unicode_literal_2cCsd}d}| ||¡dS)Nz UR'''x''' z R'''x''' r;r<rrrÚtest_unicode_literal_3H sz#Test_unicode.test_unicode_literal_3cCs,d}d}| ||¡d}d}| ||¡dS)Nú'\\\u20ac\U0001d121\\u20ac'z'\\\\u20ac\\U0001d121\\u20ac'úr'\\\u20ac\U0001d121\\u20ac'r;r<rrrÚtest_native_literal_escape_uM s  z)Test_unicode.test_native_literal_escape_ucCs,d}d}| ||¡d}d}| ||¡dS)Nzb'\\\u20ac\U0001d121\\u20ac'zbr'\\\u20ac\U0001d121\\u20ac'r;r<rrrÚtest_bytes_literal_escape_uV s  z(Test_unicode.test_bytes_literal_escape_ucCs,d}d}| ||¡d}d}| ||¡dS)Nzu'\\\u20ac\U0001d121\\u20ac'rÁzur'\\\u20ac\U0001d121\\u20ac'rÂr;r<rrrÚtest_unicode_literal_escape_u_ s  z*Test_unicode.test_unicode_literal_escape_ucCs@d}|d}|d}| ||¡|d}|d}| ||¡dS)Nz(from __future__ import unicode_literals rÁrÂr;)rÚfr=r>rrrÚ$test_native_unicode_literal_escape_uh s z1Test_unicode.test_native_unicode_literal_escape_uN)r7r*r8r r»r¼r½r¾r¿rÀrÃrÄrÅrÇrrrrr¹$ s    r¹c@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) Ú Test_filterÚfiltercCs,d}d}| ||¡d}d}| ||¡dS)Nz#x = filter( foo, 'abc' )z)x = list(filter( foo, 'abc' ))zx = filter( None , 'abc' )z x = [_f for _f in 'abc' if _f]r;r<rrrrpv s  z$Test_filter.test_prefix_preservationcCshd}d}| ||¡d}d}| ||¡d}d}| ||¡d}d}| ||¡d}d }| ||¡dS) Nzx = filter(None, 'abc')zx = [_f for _f in 'abc' if _f]zx = len(filter(f, 'abc'))zx = len(list(filter(f, 'abc')))z)x = filter(lambda x: x%2 == 0, range(10))z&x = [x for x in range(10) if x%2 == 0]z+x = filter(lambda (x): x%2 == 0, range(10))z5filter(lambda x: True if x > 2 else False, [1, 2, 3])z4[x for x in [1, 2, 3] if (True if x > 2 else False)]r;r<rrrÚtest_filter_basic s    zTest_filter.test_filter_basiccCsTd}d}| ||¡d}d}| ||¡d}d}| ||¡d}d}| ||¡dS)Nzx = filter(None, 'abc')[0]z!x = [_f for _f in 'abc' if _f][0]zx = len(filter(f, 'abc')[0])z"x = len(list(filter(f, 'abc'))[0])z,x = filter(lambda x: x%2 == 0, range(10))[0]z)x = [x for x in range(10) if x%2 == 0][0]z.x = filter(lambda (x): x%2 == 0, range(10))[0]r;r<rrrÚtest_filter_trailers– s   z Test_filter.test_filter_trailerscCsd}| |¡d}| |¡d}| |¡d}| |¡d}| |¡d}| |¡d}| |¡d}| |¡d }| |¡d }| |¡d }| |¡d }| |¡d }| |¡d}| |¡d}| |¡d}| |¡d}| |¡d}| |¡d}| |¡dS)Nzb.join(filter(f, 'abc'))z#(a + foo(5)).join(filter(f, 'abc'))ziter(filter(f, 'abc'))zlist(filter(f, 'abc'))zlist(filter(f, 'abc'))[0]zset(filter(f, 'abc'))zset(filter(f, 'abc')).pop()ztuple(filter(f, 'abc'))zany(filter(f, 'abc'))zall(filter(f, 'abc'))zsum(filter(f, 'abc'))zsorted(filter(f, 'abc'))z"sorted(filter(f, 'abc'), key=blah)z%sorted(filter(f, 'abc'), key=blah)[0]zenumerate(filter(f, 'abc'))z$enumerate(filter(f, 'abc'), start=1)zfor i in filter(f, 'abc'): passz[x for x in filter(f, 'abc')]z(x for x in filter(f, 'abc'))r$©rr>rrrÚtest_filter_nochange¨ sL                  z Test_filter.test_filter_nochangecCs4d}| |¡d}d}| ||¡d}| |¡dS)Nz:from future_builtins import spam, filter; filter(f, 'ham')z6from future_builtins import spam; x = filter(f, 'abc')zrrrÚcheckallZs zTest_itertools.checkallcCsd}d}| ||¡dS)Nzitertools.izip(a, b)z zip(a, b)r;r<rrrÚtest_0dszTest_itertools.test_0cCsd}d}| ||¡dS)Nz%s(f, a)©r r<rrrrCkszTest_itertools.test_1cCs,d}d}| ||¡d}d}| ||¡dS)Nzitertools.ifilterfalse(a, b)zitertools.filterfalse(a, b)zitertools.izip_longest(a, b)zitertools.zip_longest(a, b)r;r<rrrÚtest_qualifiedps  zTest_itertools.test_qualifiedcCs,d}d}| ||¡d}d}| ||¡dS)Nzifilterfalse(a, b)zfilterfalse(a, b)zizip_longest(a, b)zzip_longest(a, b)r;r<rrrrDys  zTest_itertools.test_2cCsd}d}| ||¡dS)Nz %s(f, a)rr<rrrrf‚szTest_itertools.test_space_1cCs,d}d}| ||¡d}d}| ||¡dS)Nz itertools.ifilterfalse(a, b)z itertools.filterfalse(a, b)z itertools.izip_longest(a, b)z itertools.zip_longest(a, b)r;r<rrrrg‡s  zTest_itertools.test_space_2cCs| ddd¡dS)NrKrÕrÉrrÐrrrr szTest_itertools.test_run_orderN) r7r*r8r r rrCrrDrfrgr rrrrr Ws    r c@sHeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dS)ÚTest_itertools_importsZitertools_importscCs@d}d}| ||¡d}d}| ||¡d}d}| ||¡dS)Nz%from itertools import imap, izip, fooúfrom itertools import fooz*from itertools import bar, imap, izip, foozfrom itertools import bar, fooz'from itertools import chain, imap, izipzfrom itertools import chainr;r<rrrÚ test_reduced—s  z#Test_itertools_imports.test_reducedcCsd}d}| ||¡dS)Nz%#foo from itertools import imap, izipz#foo r;r<rrrÚ test_comments¤sz$Test_itertools_imports.test_commentscCs,d}d}| ||¡d}d}| ||¡dS)Nz from itertools import imap, iziprzfrom itertools import izipr;r<rrrÚ test_none©s  z Test_itertools_imports.test_nonecCsbd}d}| ||¡d}d}| ||¡d}d}| ||¡d}d}| ||¡d}| |¡dS)Nz-from itertools import izip, bar as bang, imapz!from itertools import bar as bangz-from itertools import izip as _zip, imap, barzfrom itertools import barz"from itertools import imap as _maprz0from itertools import imap as _map, izip as _zip)rr")rr=r>rZrrrÚtest_import_as²s    z%Test_itertools_imports.test_import_ascCsndD]d}d|f}d|f}| ||¡d|f}d|f}| ||¡d|f}d|f}| ||¡qdS)N)Ú filterfalseÚ zip_longestzfrom itertools import i%szfrom itertools import %sz$from itertools import imap, i%s, foozfrom itertools import %s, fooz#from itertools import bar, i%s, fooz"from itertools import bar, %s, foor;)rrr=r>rrrÚtest_ifilter_and_zip_longestÆs        z3Test_itertools_imports.test_ifilter_and_zip_longestcCsd}| |¡dS)Nzfrom itertools import *r$rYrrrÚtest_import_starÔsz'Test_itertools_imports.test_import_starcCsd}| |¡dS)Nrr$rYrrrrmÙsz%Test_itertools_imports.test_unchangedN) r7r*r8r rrrrrrrmrrrrr”s  rcs´eZdZdZ‡fdd„Zdd„Z‡fdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Z‡ZS)(Ú Test_importrGcsDttˆƒ ¡gˆ_tƒˆ_dˆ_‡fdd„}ddlm}||_ dS)NTcsˆj |¡ˆjp|ˆjvSr)Ú files_checkedrQÚ always_existsÚ present_files©rrÐrrÚ fake_existsès z&Test_import.setUp..fake_existsr©Ú fix_import) r rrrÚsetrrÚ lib2to3.fixesr"Úexists)rr r"r rÐrrás  zTest_import.setUpcCsddlm}tjj|_dS)Nrr!)r$r"ÚosÚpathr%)rr"rrrÚtearDownïs zTest_import.tearDowncs2d|_tt|ƒ ||¡d|_tt|ƒ |¡dS)NTF)rr rrr"r<r rrÚ check_bothószTest_import.check_bothcs¸dd„}d|_tdgƒ|_dtjjdddd f}|d ƒd |d ƒf}|D]n‰g|_ˆ|_| d ¡tj  ˆ¡r|tj  ˆ¡d‰nd‰t‡fdd„|Dƒƒ}|  d¡|  t|jƒ|¡qDdS)NcSstjj | d¡¡S)Nú/)r&r'Úpathsepr Úsplit)r'rrrÚpúsz)Test_import.test_files_checked..pFú __init__.pyz.pyz.pycz.soz.slz.pydz /spam/eggs.pyzni.pyz../../shrubbery.pyz import jamz/jamZjamc3s|]}ˆ|VqdSrr)r+ÚextrrrÚ r.z1Test_import.test_files_checked..) rr#rr&r'Úseprr r"ÚdirnameÚaddr)rr-Zexpected_extensionsZ names_to_testZexpected_checksrrrÚtest_files_checkedùs    zTest_import.test_files_checkedcCs$d}d|_tdgƒ|_| |¡dS)Nú import barFúbar.py©rr#rr"rYrrrÚtest_not_in_packages zTest_import.test_not_in_packagecCs&d}d|_tddgƒ|_| |¡dS)Nz1from __future__ import absolute_import import barFr.r6r7rYrrrÚ!test_with_absolute_import_enabledsz-Test_import.test_with_absolute_import_enabledcCs,d}d}d|_tddgƒ|_| ||¡dS)Nr5úfrom . import barFr.r6)rr#rrr<rrrÚtest_in_packages zTest_import.test_in_packagecCs4d}d}d|_tddtjjgƒ|_| ||¡dS)Nr5r:Fr.Zbar)rr#r&r'r1rrr<rrrÚtest_import_from_package$s z$Test_import.test_import_from_packagecCsd}| |¡dS)Nr:r$rYrrrÚtest_already_relative_import+sz(Test_import.test_already_relative_importcCsd}d}| ||¡dS)Nzimport bar # Foozfrom . import bar # Foor;r<rrrÚtest_comments_and_indent/sz$Test_import.test_comments_and_indentcCs@d}d}| ||¡d}d}| ||¡d}d}| ||¡dS)Nzfrom foo import bar, bazzfrom .foo import bar, bazzfrom foo import barzfrom .foo import barzfrom foo import (bar, baz)zfrom .foo import (bar, baz)©r)r<rrrÚ test_from4s  zTest_import.test_fromcCsd}d}| ||¡dS)Nzfrom green.eggs import hamzfrom .green.eggs import hamr?r<rrrÚtest_dotted_fromAszTest_import.test_dotted_fromcCsd}d}| ||¡dS)Nz"from green.eggs import ham as spamz#from .green.eggs import ham as spamr?r<rrrÚ test_from_asFszTest_import.test_from_ascCsTd}d}| ||¡d}d}| ||¡d}d}| ||¡d}d}| ||¡dS) Nz import foozfrom . import fooúimport foo, barzfrom . import foo, barzimport foo, bar, xzfrom . import foo, bar, xzimport x, y, zzfrom . import x, y, zr?r<rrrÚ test_importKs   zTest_import.test_importcCs,d}d}| ||¡d}d}| ||¡dS)Nzimport foo as xzfrom . import foo as xzimport a as b, b as c, c as dz$from . import a as b, b as c, c as dr?r<rrrr\s  zTest_import.test_import_ascCs(d|_tddgƒ|_d}| |d¡dS)NFzfoo.pyr.rCz#absolute and local imports together)rr#rr&rYrrrÚtest_local_and_absoluteesz#Test_import.test_local_and_absolutecCsd}d}| ||¡dS)Nzimport foo.barzfrom . import foo.barr?r<rrrÚtest_dotted_importlszTest_import.test_dotted_importcCsd}d}| ||¡dS)Nzimport foo.bar as bangzfrom . import foo.bar as bangr?r<rrrÚtest_dotted_import_asqsz!Test_import.test_dotted_import_ascCsd}d}| ||¡dS)Nz1 # prefix import foo.bar z8 # prefix from . import foo.bar r?r<rrrÚ test_prefixvszTest_import.test_prefix)r7r*r8r rr(r)r4r8r9r;r<r=r>r@rArBrDrrErFrGrHr rrr rrÞs(    rc@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) ÚTest_set_literalZ set_literalcCs°d}d}| ||¡d}d}| ||¡d}d}| ||¡d}| ||¡d}d}| ||¡d }| ||¡d }d }| ||¡d }d }| ||¡d}d}| ||¡dS)Nzset([1, 2, 3])z {1, 2, 3}zset((1, 2, 3))z set((1,))ú{1}zset([1])z set((a, b))z{a, b}z set([a, b])zset((a*234, f(args=23)))z{a*234, f(args=23)}zset([a*23, f(23)])z {a*23, f(23)}zset([a-234**23])z {a-234**23}r;r<rrrr?†s2        zTest_set_literal.test_basiccCsTd}d}| ||¡d}d}| ||¡d}d}| ||¡d}d}| ||¡dS) Nzset([x for x in y])z{x for x in y}zset([x for x in y if x == m])z{x for x in y if x == m}zset([x for x in y for a in b])z{x for x in y for a in b}zset([f(x) - 23 for x in y])z{f(x) - 23 for x in y}r;r<rrrÚtest_listcomps©s   zTest_set_literal.test_listcompscCsd}d}| ||¡d}d}| ||¡d}d}| ||¡d}d}| ||¡d }d }| ||¡d }d }| ||¡d }d}| ||¡dS)Nz set( [1, 2])z{1, 2}z set([1 , 2])z{1 , 2}z set([ 1 ])z{ 1 }z set( [1] )rJzset([ 1, 2 ])z { 1, 2 }zset([x for x in y ])z{x for x in y }zimport collections.abc isinstance(x, collections.abc.Sequence)r;r<rrrÚtest_operator_isSequenceTypeUsz*Test_operator.test_operator_isSequenceTypecCsd}d}| ||¡dS)Nzoperator.isMappingType(x)z=import collections.abc isinstance(x, collections.abc.Mapping)r;r<rrrÚtest_operator_isMappingTypeZsz)Test_operator.test_operator_isMappingTypecCsd}d}| ||¡dS)Nzoperator.isNumberType(x)z,import numbers isinstance(x, numbers.Number)r;r<rrrÚtest_operator_isNumberType_sz(Test_operator.test_operator_isNumberTypecCs@d}d}| ||¡d}d}| ||¡d}d}| ||¡dS)Nzoperator.repeat(x, n)zoperator.mul(x, n)zoperator .repeat(x, n)zoperator .mul(x, n)zoperator. repeat(x, n)zoperator. mul(x, n)r;r<rrrÚtest_operator_repeatds  z"Test_operator.test_operator_repeatcCs@d}d}| ||¡d}d}| ||¡d}d}| ||¡dS)Nzoperator.irepeat(x, n)zoperator.imul(x, n)zoperator .irepeat(x, n)zoperator .imul(x, n)zoperator. irepeat(x, n)zoperator. imul(x, n)r;r<rrrÚtest_operator_irepeatqs  z#Test_operator.test_operator_irepeatcCsd}d}| ||¡dS)Nz isCallable(x)z"You should use 'callable(x)' here.r¯©rrZÚtrrrÚtest_bare_isCallable~sz"Test_operator.test_bare_isCallablecCsd}d}| ||¡dS)NzsequenceIncludes(x, y)z.You should use 'operator.contains(x, y)' here.r¯r`rrrÚtest_bare_sequenceIncludesƒsz(Test_operator.test_bare_sequenceIncludescCsd}d}| ||¡dS)NzisSequenceType(z)z>You should use 'isinstance(z, collections.abc.Sequence)' here.r¯r`rrrÚ!test_bare_operator_isSequenceTypeˆsz/Test_operator.test_bare_operator_isSequenceTypecCsd}d}| ||¡dS)NzisMappingType(x)z=You should use 'isinstance(x, collections.abc.Mapping)' here.r¯r`rrrÚ test_bare_operator_isMappingTypesz.Test_operator.test_bare_operator_isMappingTypecCsd}d}| ||¡dS)NzisNumberType(y)z4You should use 'isinstance(y, numbers.Number)' here.r¯r`rrrÚtest_bare_operator_isNumberType’sz-Test_operator.test_bare_operator_isNumberTypecCsd}d}| ||¡dS)Nz repeat(x, n)z)You should use 'operator.mul(x, n)' here.r¯r`rrrÚtest_bare_operator_repeat—sz'Test_operator.test_bare_operator_repeatcCsd}d}| ||¡dS)Nzirepeat(y, 187)z,You should use 'operator.imul(y, 187)' here.r¯r`rrrÚtest_bare_operator_irepeatœsz(Test_operator.test_bare_operator_irepeatN)r7r*r8r rYrZr[r\r]r^r_rbrcrdrerfrgrhrrrrrW?s   rWc@sHeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dS)Ú Test_exitfuncZexitfunccCsd}d}| ||¡dS)NzI import sys sys.exitfunc = my_atexit ze import sys import atexit atexit.register(my_atexit) r;r<rrrr˜¦szTest_exitfunc.test_simplecCsd}d}| ||¡dS)NzO import sys, crumbs sys.exitfunc = my_func zY import sys, crumbs, atexit atexit.register(my_func) r;r<rrrÚtest_names_import²szTest_exitfunc.test_names_importcCsd}d}| ||¡dS)Nzh import sys sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression z„ import sys import atexit atexit.register(do(d)/a()+complex(f=23, g=23)*expression) r;r<rrrÚtest_complex_expression½sz%Test_exitfunc.test_complex_expressioncCs,d}d}| ||¡d}d}| ||¡dS)NzN import sys # Foo sys.exitfunc = f # Blah zj import sys import atexit # Foo atexit.register(f) # Blah zo import apples, sys, crumbs, larry # Pleasant comments sys.exitfunc = func zy import apples, sys, crumbs, larry, atexit # Pleasant comments atexit.register(func) r;r<rrrrÉs  zTest_exitfunc.test_commentscCsd}d}| ||¡dS)Nz] import sys def f(): sys.exitfunc = func zz import sys import atexit def f(): atexit.register(func) r;r<rrrÚtest_in_a_functionßsz Test_exitfunc.test_in_a_functioncCsd}d}d}| |||¡dS)Nzsys.exitfunc = fzatexit.register(f)zKCan't find sys import; Please add an atexit import at the top of your file.r%)rr=r>ÚmsgrrrÚtest_no_sys_importísz Test_exitfunc.test_no_sys_importcCsd}| |¡dS)Nzf(sys.exitfunc)r$rYrrrrmõszTest_exitfunc.test_unchangedN) r7r*r8r r˜rjrkrrlrnrmrrrrri¢s   ric@s(eZdZdZdd„Zdd„Zdd„ZdS) Ú Test_assertsZassertscCs&gd¢}|D]\}}| ||¡q dS)N) )zself.assert_(True)úself.assertTrue(True))zself.assertEquals(2, 2)úself.assertEqual(2, 2))zself.assertNotEquals(2, 3)úself.assertNotEqual(2, 3))zself.assertAlmostEquals(2, 3)úself.assertAlmostEqual(2, 3))z self.assertNotAlmostEquals(2, 8)úself.assertNotAlmostEqual(2, 8))zself.failUnlessEqual(2, 2)rq)zself.failIfEqual(2, 3)rr)z self.failUnlessAlmostEqual(2, 3)rs)zself.failIfAlmostEqual(2, 8)rt)zself.failUnless(True)rp)zself.failUnlessRaises(foo)zself.assertRaises(foo))zself.failIf(False)zself.assertFalse(False)r;)rZtestsr=r>rrrÚtest_deprecated_namesþs z"Test_asserts.test_deprecated_namescCsd}d}| ||¡d}d}| ||¡d}d}| ||¡d}d}| ||¡d }d }| ||¡d }d }| ||¡d }d}| ||¡dS)Nzeq = self.assertEqualszeq = self.assertEqualz#self.assertEquals(2, 3, msg="fail")z"self.assertEqual(2, 3, msg="fail")z)self.assertEquals(2, 3, msg="fail") # fooz(self.assertEqual(2, 3, msg="fail") # foozself.assertEquals (2, 3)zself.assertEqual (2, 3)z self.assertEquals (2, 3)z self.assertEqual (2, 3)z0with self.failUnlessRaises(Explosion): explode()z,with self.assertRaises(Explosion): explode()z6with self.failUnlessRaises(Explosion) as cm: explode()z2with self.assertRaises(Explosion) as cm: explode()r;r<rrrÚ test_variantss*      zTest_asserts.test_variantscCs| d¡| d¡dS)Nzself.assertEqualsOnSaturdayz!self.assertEqualsOnSaturday(3, 5)r$rÐrrrrm's zTest_asserts.test_unchangedN)r7r*r8r rurvrmrrrrroúsro)CÚ__doc__r&r rrXrrrrZ lib2to3.testsrZTestCaserr9rBrNrhrnrqrvr‡rŽr•r¤r»rÈrÊrÍrÑrýr rrr$r&r5r=r@rIrXr]rmrpr›rŸr°r¹rÈrÏrÔrÙrÚrßrþrrr rrrIrLrMrPrSrWrirorrrrÚs   9:;1#j3&}.&gH /+br/< ]4B.Oh|P Z =J%":&=cX