a 9êdg×Rã@s dZddlmZddlmZmZddlmZddlm Z m Z m Z m Z ddl mZddd „ZGd d „d ejƒZGd d „d ejƒZGdd„dejƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„dejƒZGdd„dejƒZGdd„dejƒZGdd„dejƒZdS) z' Test suite for the code in fixer_util é)Úsupporté)ÚNodeÚLeaf)Ú fixer_util)ÚAttrÚNameÚCallÚComma)ÚtokencCs,t |¡}t|ƒD]}|jd}qd|_|S)Nr)rZ parse_stringÚrangeÚchildrenÚparent)ÚcodeÚ strip_levelsZtreeÚi©rú3/usr/local/lib/python3.9/lib2to3/tests/test_util.pyÚparse s    rc@seZdZdd„ZdS)Ú MacroTestCasecCs0t|ttfƒrttjj|ƒ}| t|ƒ|¡dS©N) Ú isinstanceÚtupleÚlistrrZsymsZ simple_stmtÚ assertEqualÚstr)ÚselfÚnodeÚstringrrrÚ assertStrszMacroTestCase.assertStrN)Ú__name__Ú __module__Ú __qualname__rrrrrrsrc@s$eZdZdd„Zdd„Zdd„ZdS)Ú Test_is_tuplecCst t|dd¡S©Né©r)rÚis_tupler©rrrrrr'szTest_is_tuple.is_tuplecCsT| | d¡¡| | d¡¡| | d¡¡| | d¡¡| | d¡¡dS)Nz(a, b)z (a, (b, c))z((a, (b, c)),)z(a,)z())Ú assertTruer'©rrrrÚ test_valid s zTest_is_tuple.test_validcCs$| | d¡¡| | d¡¡dS)Nz(a)z('foo') % (b, c))Ú assertFalser'r*rrrÚ test_invalid'szTest_is_tuple.test_invalidN)r r!r"r'r+r-rrrrr#sr#c@s$eZdZdd„Zdd„Zdd„ZdS)Ú Test_is_listcCst t|dd¡Sr$)rÚis_listrr(rrrr/-szTest_is_list.is_listcCsT| | d¡¡| | d¡¡| | d¡¡| | d¡¡| | d¡¡dS)Nz[]z[a]z[a, b]z [a, [b, c]]z[[a, [b, c]],])r)r/r*rrrr+0s zTest_is_list.test_validcCs| | d¡¡dS)Nz[]+[])r,r/r*rrrr-7szTest_is_list.test_invalidN)r r!r"r/r+r-rrrrr.,sr.c@seZdZdd„Zdd„ZdS)Ú Test_AttrcCs@tddd}| ttdƒtdƒƒd¡| t|tdƒƒd¡dS)Nzfoo()r%r&ÚaÚbúa.bzfoo().b)rrrr)rÚcallrrrÚtest<s zTest_Attr.testcCs&ttdƒtdƒƒ}| t|ƒt¡dS)Nr1r2)rrrÚtyper)rÚattrrrrÚ test_returnsBszTest_Attr.test_returnsN)r r!r"r5r8rrrrr0;sr0c@seZdZdd„ZdS)Ú Test_NamecCs8| tdƒd¡| tdƒd¡| tdddd¡dS)Nr1z foo.foo().barr2©ÚprefixZba)rrr*rrrr5HszTest_Name.testN)r r!r"r5rrrrr9Gsr9c@seZdZddd„Zdd„ZdS)Ú Test_CallNcCsFg}t|tƒr6|D]}| |¡| tƒ¡q| ¡tt|ƒ||ƒS)zHelp the next test)rrÚappendr Úpopr r)rÚnameÚargsr;r ÚargrrrÚ_CallOs  zTest_Call._Callc CsÌdttjdƒttjdƒttjdƒgttjdƒttjdƒttjdƒttjdƒgttjdƒttjdddgg}| | d ¡d ¡| | d|d¡d ¡| | d |d¡d ¡| |jd|dddd¡dS)Nrr%éér2Újú r:ÚAzA()zb(1,2,3)za.b().cza.b().c(1,3,2,4)Údz d(b, j))rr ÚNUMBERÚSTRINGrrB)rZkidsrrrr5Ys ÿÿûzTest_Call.test)NN)r r!r"rBr5rrrrr<Ns r<c@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) ÚTest_does_tree_importcCs<t ||¡}|r|S|jD]}| ||¡}|r|SqdSr)rÚ find_bindingr Ú_find_bind_rec)rr?rÚcÚchildrrrrMhs    z$Test_does_tree_import._find_bind_reccCs"t|ƒ}| d|¡}t |||¡S)NÚstart)rrMrÚdoes_tree_import)rÚpackager?rrrrrrQqs z&Test_does_tree_import.does_tree_importcCs¬d}|D]J\}}}| |||d|¡}| |¡| |||d|¡}| |¡qd}|D]J\}}}| |||d|¡}| |¡| |||d|¡}| |¡q\dS)N))r1r1úfrom a import b)úa.dr1úfrom a.d import b)zd.ar1úfrom d.a import b)Nr1úimport b)Nr1úimport b, c, dÚ ))r1r1úfrom a import a)Úxr1úfrom x import a)r[r1úfrom x import b, c, a, d)úx.br1úfrom x.b import a)r^r1úfrom x.b import b, c, a, d)Nr1úimport a)Nr1úimport b, c, a, d)rQr,r))rrZ failing_testsrRr?Úimport_ÚnZ passing_testsrrrÚtry_withws   zTest_does_tree_import.try_withcCs| d¡dS)Nzdef foo(): bar.baz() start=3)rer*rrrÚtest_in_functionsz&Test_does_tree_import.test_in_functionN)r r!r"rMrQrerfrrrrrKgs rKc@sÖeZdZd4dd„Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„ZdS)5ÚTest_find_bindingNcCst |t|ƒ|¡Sr)rrLr)rr?rrRrrrrL”szTest_find_binding.find_bindingcCsp| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡dS)Nr1za = bz a = [b, c, d]z a = foo()za = foo().foo.foo[6][foo]zfoo = azfoo = (a, b, c)©r)rLr,r*rrrÚtest_simple_assignment—s z(Test_find_binding.test_simple_assignmentcCsp| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡dS)Nr1z(a,) = bz(a, b, c) = [b, c, d]z(c, (d, a), b) = foo()z(a, b) = foo().foo[6][foo]z(foo, b) = (b, a)z(foo, (b, c)) = (a, b, c)rhr*rrrÚtest_tuple_assignmentŸs z'Test_find_binding.test_tuple_assignmentcCsp| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡dS)Nr1z[a] = bz[a, b, c] = [b, c, d]z[c, [d, a], b] = foo()z[a, b] = foo().foo[a][foo]z[foo, b] = (b, a)z[foo, [b, c]] = (a, b, c)rhr*rrrÚtest_list_assignment§s z&Test_find_binding.test_list_assignmentcCsL| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡dS)Nr1z foo.a = 5z foo[a] = 5z foo(a) = 5z foo(a, b) = 5©r,rLr*rrrÚtest_invalid_assignments¯sz*Test_find_binding.test_invalid_assignmentscCsL| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡dS)Nr1rarbrWrXrhr*rrrÚtest_simple_importµsz$Test_find_binding.test_simple_importcCs”| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd ¡¡dS) Nr1r\rZr]r_r`rSrUrVrhr*rrrÚtest_from_import»sz"Test_find_binding.test_from_importcCsL| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡dS)Nr1z import b as azimport b as a, c, a as f, dú import a as fzimport b, c as f, d as erhr*rrrÚtest_import_asÅsz Test_find_binding.test_import_ascCs‚| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡dS) Nr1úfrom x import b as aúfrom x import g as a, d as búfrom x.b import t as aúfrom x.b import g as a, dúfrom a import b as tzfrom a.d import b as tzfrom d.a import b as trhr*rrrÚtest_from_import_asËsz%Test_find_binding.test_from_import_ascCsP| | dd¡¡| | dd¡¡| | ddd¡¡| | ddd¡¡dS)Nr2rWrXrNrhr*rrrÚtest_simple_import_with_packageÔsz1Test_find_binding.test_simple_import_with_packagecCsà| | ddd¡¡| | ddd¡¡| | ddd¡¡| | ddd¡¡| | ddd¡¡| | dd d¡¡| | dd d¡¡| | dd d¡¡| | dd d ¡¡| | ddd ¡¡| | ddd¡¡dS)Nr1r\r[rZzfrom x import *r]r_r^zfrom x.b import *r`rSrUrTrVzfrom x.y import *r3rhr*rrrÚtest_from_import_with_packageÚsz/Test_find_binding.test_from_import_with_packagecCs@| | ddd¡¡| | ddd¡¡| | ddd¡¡dS)Nr1zimport b.c as azb.crpÚfrlr*rrrÚtest_import_as_with_packageçsz-Test_find_binding.test_import_as_with_packagecCs| | ddd¡¡| | ddd¡¡| | ddd¡¡| | ddd¡¡| | ddd¡¡| | ddd ¡¡| | ddd ¡¡dS) Nr1rrr[rsrtr^rurvr2Útrlr*rrrÚ test_from_import_as_with_packageìsz2Test_find_binding.test_from_import_as_with_packagecCs˜| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡d }| | d|¡¡dS) Nr1z def a(): passzdef a(b, c, d): passzdef a(): b = 7zdef d(b, (c, a), e): passzdef d(a=7): passzdef d(a): passzdef d(): a = 7zG def d(): def a(): passrh©rÚsrrrÚtest_function_deføsz#Test_find_binding.test_function_defcCsÎ| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd ¡¡| | dd ¡¡| | dd ¡¡d }| | d|¡¡dS) Nr1z class a: passzclass a(): passzclass a(b): passzclass a(b, c=8): passz class d: passzclass d(a): passzclass d(b, a=7): passzclass d(b, *a): passzclass d(b, **a): passzclass d: a = 7zK class d(): class a(): passrhr~rrrÚtest_class_defsz Test_find_binding.test_class_defcCs‚| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡| | dd¡¡dS) Nr1zfor a in r: passzfor a, b in r: passzfor (a, b) in r: passzfor c, (a,) in r: passzfor c, (a, b) in r: passzfor c in r: a = czfor c in a: passrhr*rrrÚtest_forszTest_find_binding.test_forcCs´d}| | d|¡¡d}| | d|¡¡d}| | d|¡¡d}| | d|¡¡d}| | d|¡¡d}| | d|¡¡d}| | d|¡¡d }| | d|¡¡dS) NzM for b in r: for a in b: passr1zP for b in r: for a, c in b: passzR for b in r: for (a, c) in b: passzP for b in r: for (a,) in b: passzU for b in r: for c, (a, d) in b: passzN for b in r: for c in b: a = 7zN for b in r: for c in b: d = azN for b in r: for c in a: d = 7rhr~rrrÚtest_for_nested"s z!Test_find_binding.test_for_nestedcCs(| | dd¡¡| | dd¡¡dS)Nr1zif b in r: a = czif a in r: d = erhr*rrrÚtest_ifSszTest_find_binding.test_ifcCs0d}| | d|¡¡d}| | d|¡¡dS)NzL if b in r: if c in d: a = cr1zL if b in r: if c in d: c = arhr~rrrÚtest_if_nestedWsz Test_find_binding.test_if_nestedcCs(| | dd¡¡| | dd¡¡dS)Nr1zwhile b in r: a = czwhile a in r: d = erhr*rrrÚ test_whiledszTest_find_binding.test_whilecCs0d}| | d|¡¡d}| | d|¡¡dS)NzR while b in r: while c in d: a = cr1zR while b in r: while c in d: c = arhr~rrrÚtest_while_nestedhsz#Test_find_binding.test_while_nestedcCs\d}| | d|¡¡d}| | d|¡¡d}| | d|¡¡d}| | d|¡¡dS)NzQ try: a = 6 except: b = 8r1zQ try: b = 8 except: a = 6zƒ try: b = 8 except KeyError: pass except: a = 6úQ try: b = 8 except: b = 6rhr~rrrÚtest_try_exceptusz!Test_find_binding.test_try_exceptcCsžd}| | d|¡¡d}| | d|¡¡d}| | d|¡¡d}| | d|¡¡d}| | d|¡¡d}| | d|¡¡d}| | d|¡¡dS) Nz› try: try: a = 6 except: pass except: b = 8r1z› try: b = 8 except: try: a = 6 except: passz› try: b = 8 except: try: pass except: a = 6zÕ try: try: b = 8 except KeyError: pass except: a = 6 except: passzÕ try: pass except: try: b = 8 except KeyError: pass except: a = 6rˆa try: try: b = 8 except: c = d except: try: b = 6 except: t = 8 except: o = yrhr~rrrÚtest_try_except_nested”s   z(Test_find_binding.test_try_except_nestedcCs\d}| | d|¡¡d}| | d|¡¡d}| | d|¡¡d}| | d|¡¡dS)Nz| try: c = 6 except: b = 8 finally: a = 9r1zR try: b = 8 finally: a = 6zR try: b = 8 finally: b = 6z| try: b = 8 except: b = 9 finally: b = 6rhr~rrrÚtest_try_except_finallyász)Test_find_binding.test_try_except_finallycCsFd}| | d|¡¡d}| | d|¡¡d}| | d|¡¡dS)Nzú try: c = 6 except: b = 8 finally: try: a = 9 except: b = 9 finally: c = 9r1z try: b = 8 finally: try: pass finally: a = 6zž try: b = 8 finally: try: b = 6 finally: b = 7rhr~rrrÚtest_try_except_finally_nesteds  z0Test_find_binding.test_try_except_finally_nested)N)r r!r"rLrirjrkrmrnrorqrwrxryr{r}r€rr‚rƒr„r…r†r‡r‰rŠr‹rŒrrrrrg“s2      1  M!rgc@s4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) ÚTest_touch_importcCs*tdƒ}t dd|¡| t|ƒd¡dS)Nz"""foo""" bar()Úfooz"""foo""" import foo bar() ©rrZ touch_importrr©rrrrrÚtest_after_docstring'sz&Test_touch_import.test_after_docstringcCs*tdƒ}t dd|¡| t|ƒd¡dS)Nz"""foo""" import bar bar()rŽz'"""foo""" import bar import foo bar() rrrrrÚtest_after_imports,sz$Test_touch_import.test_after_importscCs*tdƒ}t dd|¡| t|ƒd¡dS)Núbar()rŽzimport foo bar() rrrrrÚtest_beginning1sz Test_touch_import.test_beginningcCs*tdƒ}t dd|¡| t|ƒd¡dS)Nr“ZhtmlÚescapezfrom html import escape bar() rrrrrro6sz"Test_touch_import.test_from_importcCs*tdƒ}t dd|¡| t|ƒd¡dS)Nr“Zcgizimport cgi bar() rrrrrÚtest_name_import;sz"Test_touch_import.test_name_importN)r r!r"r‘r’r”ror–rrrrr%s rc@seZdZdd„Zdd„ZdS)ÚTest_find_indentationcCs:tj}tdƒ}| ||ƒd¡tdƒ}| ||ƒd¡dS)Nznode()Ú)rÚfind_indentationrr©rÚfirrrrÚ test_nothingBs z"Test_find_indentation.test_nothingcCsntj}tdƒ}| ||ƒd¡| ||jdjdjdƒd¡tdƒ}| ||jdjdjdƒd¡dS)Nzdef f(): x()r˜rrDr%z zdef f(): x() y())rr™rrr ršrrrÚ test_simpleIs "z!Test_find_indentation.test_simpleN)r r!r"rœrrrrrr—@sr—N)r)Ú__doc__r˜rZlib2to3.pytreerrZlib2to3rZlib2to3.fixer_utilrrr r Z lib2to3.pgen2r rZTestCaserr#r.r0r9r<rKrgrr—rrrrÚs&     ,