a  zeR@s dZddlmZddlmZmZddlmZddlm Z m Z m Z m Z ddl mZddd ZGd d d ejZGd d d ejZGdddejZGdddeZGdddeZGdddeZGdddejZGdddejZGdddejZGdddejZdS) z' Test suite for the code in fixer_util )support)NodeLeaf) fixer_util)AttrNameCallComma)tokencCs,t|}t|D]}|jd}qd|_|S)Nr)rZ parse_stringrangechildrenparent)code strip_levelsZtreeirK/opt/bitninja-python-dojo/embedded/lib/python3.9/lib2to3/tests/test_util.pyparse s    rc@seZdZddZdS) MacroTestCasecCs0t|ttfrttjj|}|t||dSN) isinstancetuplelistrrZsymsZ simple_stmt assertEqualstr)selfnodestringrrr assertStrszMacroTestCase.assertStrN)__name__ __module__ __qualname__rrrrrrsrc@s$eZdZddZddZddZdS) Test_is_tuplecCstt|ddSNr)ris_tuplerrrrrrr'szTest_is_tuple.is_tuplecCsT||d||d||d||d||ddS)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||ddS)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$eZdZddZddZddZdS) Test_is_listcCstt|ddSr$)ris_listrr(rrrr/-szTest_is_list.is_listcCsT||d||d||d||d||ddS)Nz[]z[a]z[a, b]z [a, [b, c]]z[[a, [b, c]],])r)r/r*rrrr+0s zTest_is_list.test_validcCs||ddS)Nz[]+[])r,r/r*rrrr-7szTest_is_list.test_invalidN)r r!r"r/r+r-rrrrr.,sr.c@seZdZddZddZdS) Test_AttrcCs@tddd}|ttdtdd|t|tdddS)Nzfoo()r%r&aba.bzfoo().b)rrrr)rcallrrrtest<s zTest_Attr.testcCs&ttdtd}|t|tdS)Nr1r2)rrrtyper)rattrrrr test_returnsBszTest_Attr.test_returnsN)r r!r"r5r8rrrrr0;sr0c@seZdZddZdS) Test_NamecCs8|tdd|tdd|tdddddS)Nr1z foo.foo().barr2prefixZba)rrr*rrrr5HszTest_Name.testN)r r!r"r5rrrrr9Gsr9c@seZdZdddZddZdS) Test_CallNcCsFg}t|tr6|D]}|||tq|tt|||S)zHelp the next test)rrappendr popr r)rnameargsr;r argrrr_CallOs  zTest_Call._Callc Csdttjdttjdttjdgttjdttjdttjdttjdgttjdttjdddgg}||d d ||d|dd ||d |dd ||jd|dddddS)Nrr%r2j r:AzA()zb(1,2,3)za.b().cza.b().c(1,3,2,4)dz d(b, j))rr NUMBERSTRINGrrB)rZkidsrrrr5Ys zTest_Call.test)NN)r r!r"rBr5rrrrr<Ns r<c@s,eZdZddZddZddZddZd S) Test_does_tree_importcCs<t||}|r|S|jD]}|||}|r|SqdSr)r find_bindingr _find_bind_rec)rr?rcchildrrrrMhs    z$Test_does_tree_import._find_bind_reccCs"t|}|d|}t|||S)Nstart)rrMrdoes_tree_import)rpackager?rrrrrrQqs z&Test_does_tree_import.does_tree_importcCsd}|D]J\}}}||||d|}||||||d|}||qd}|D]J\}}}||||d|}||||||d|}||q\dS)N))r1r1from a import b)a.dr1from a.d import b)zd.ar1from d.a import b)Nr1import b)Nr1import b, c, d ))r1r1from a import a)xr1from x import a)r[r1from x import b, c, a, d)x.br1from x.b import a)r^r1from x.b import b, c, a, d)Nr1import a)Nr1import b, c, a, d)rQr,r))rrZ failing_testsrRr?import_nZ passing_testsrrrtry_withws   zTest_does_tree_import.try_withcCs|ddS)Nzdef foo(): bar.baz() start=3)rer*rrrtest_in_functionsz&Test_does_tree_import.test_in_functionN)r r!r"rMrQrerfrrrrrKgs rKc@seZdZd4ddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3ZdS)5Test_find_bindingNcCst|t||Sr)rrLr)rr?rrRrrrrLszTest_find_binding.find_bindingcCsp||dd||dd||dd||dd||dd||dddS)Nr1za = bz a = [b, c, d]z a = foo()za = foo().foo.foo[6][foo]zfoo = azfoo = (a, b, c)r)rLr,r*rrrtest_simple_assignments z(Test_find_binding.test_simple_assignmentcCsp||dd||dd||dd||dd||dd||dddS)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*rrrtest_tuple_assignments z'Test_find_binding.test_tuple_assignmentcCsp||dd||dd||dd||dd||dd||dddS)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*rrrtest_list_assignments z&Test_find_binding.test_list_assignmentcCsL||dd||dd||dd||dddS)Nr1z foo.a = 5z foo[a] = 5z foo(a) = 5z foo(a, b) = 5r,rLr*rrrtest_invalid_assignmentssz*Test_find_binding.test_invalid_assignmentscCsL||dd||dd||dd||dddS)Nr1rarbrWrXrhr*rrrtest_simple_importsz$Test_find_binding.test_simple_importcCs||dd||dd||dd||dd||dd||dd||dd||dd dS) Nr1r\rZr]r_r`rSrUrVrhr*rrrtest_from_importsz"Test_find_binding.test_from_importcCsL||dd||dd||dd||dddS)Nr1z import b as azimport b as a, c, a as f, d import a as fzimport b, c as f, d as erhr*rrrtest_import_assz Test_find_binding.test_import_ascCs||dd||dd||dd||dd||dd||dd||dddS) Nr1from x import b as afrom x import g as a, d as bfrom x.b import t as afrom x.b import g as a, dfrom a import b as tzfrom a.d import b as tzfrom d.a import b as trhr*rrrtest_from_import_assz%Test_find_binding.test_from_import_ascCsP||dd||dd||ddd||ddddS)Nr2rWrXrNrhr*rrrtest_simple_import_with_packagesz1Test_find_binding.test_simple_import_with_packagecCs||ddd||ddd||ddd||ddd||ddd||dd d||dd d||dd d||dd d ||ddd ||ddddS)Nr1r\r[rZzfrom x import *r]r_r^zfrom x.b import *r`rSrUrTrVzfrom x.y import *r3rhr*rrrtest_from_import_with_packagesz/Test_find_binding.test_from_import_with_packagecCs@||ddd||ddd||ddddS)Nr1zimport b.c as azb.crpfrlr*rrrtest_import_as_with_packagesz-Test_find_binding.test_import_as_with_packagecCs||ddd||ddd||ddd||ddd||ddd||ddd ||ddd dS) Nr1rrr[rsrtr^rurvr2trlr*rrr test_from_import_as_with_packagesz2Test_find_binding.test_from_import_as_with_packagecCs||dd||dd||dd||dd||dd||dd||ddd }||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(): passrhrsrrrtest_function_defsz#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~rrrtest_class_defsz Test_find_binding.test_class_defcCs||dd||dd||dd||dd||dd||dd||dddS) 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*rrrtest_forszTest_find_binding.test_forcCsd}||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~rrrtest_for_nested"s z!Test_find_binding.test_for_nestedcCs(||dd||dddS)Nr1zif b in r: a = czif a in r: d = erhr*rrrtest_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~rrrtest_if_nestedWsz Test_find_binding.test_if_nestedcCs(||dd||dddS)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~rrrtest_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 = 6Q try: b = 8 except: b = 6rhr~rrrtest_try_exceptusz!Test_find_binding.test_try_exceptcCsd}||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 = 6ra try: try: b = 8 except: c = d except: try: b = 6 except: t = 8 except: o = yrhr~rrrtest_try_except_nesteds   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~rrrtest_try_except_finallysz)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~rrrtest_try_except_finally_nesteds  z0Test_find_binding.test_try_except_finally_nested)N)r r!r"rLrirjrkrmrnrorqrwrxryr{r}rrrrrrrrrrrrrrrrrgs2      1  M!rgc@s4eZdZddZddZddZddZd d Zd S) Test_touch_importcCs*td}tdd||t|ddS)Nz"""foo""" bar()fooz"""foo""" import foo bar() rrZ touch_importrrrrrrrtest_after_docstring'sz&Test_touch_import.test_after_docstringcCs*td}tdd||t|ddS)Nz"""foo""" import bar bar()rz'"""foo""" import bar import foo bar() rrrrrtest_after_imports,sz$Test_touch_import.test_after_importscCs*td}tdd||t|ddS)Nbar()rzimport foo bar() rrrrrtest_beginning1sz Test_touch_import.test_beginningcCs*td}tdd||t|ddS)NrZhtmlescapezfrom html import escape bar() rrrrrro6sz"Test_touch_import.test_from_importcCs*td}tdd||t|ddS)NrZcgizimport cgi bar() rrrrrtest_name_import;sz"Test_touch_import.test_name_importN)r r!r"rrrrorrrrrr%s rc@seZdZddZddZdS)Test_find_indentationcCs:tj}td}|||dtd}|||ddS)Nznode())rfind_indentationrrrfirrrr test_nothingBs z"Test_find_indentation.test_nothingcCsntj}td}|||d|||jdjdjddtd}|||jdjdjdddS)Nzdef f(): x()rrrDr%z zdef f(): x() y())rrrrr rrrr test_simpleIs "z!Test_find_indentation.test_simpleN)r r!r"rrrrrrr@srN)r)__doc__rrZlib2to3.pytreerrZlib2to3rZlib2to3.fixer_utilrrr r Z lib2to3.pgen2r rZTestCaserr#r.r0r9r<rKrgrrrrrrs&     ,