B /g^xc@sfddlmZmZddlZddlZddlTGdddejZGdddejZdd Ze d krbedS) ) run_unittestcheck_syntax_errorN)Z*c@sDeZdZddZddZddZddZd d Zd d Zd dZ dS) TokenTestscCs(d}||ddd}||dddS)Nzbackslash for line continuationrzbackslash ending comment assertEqualsselfxr ;/usr/lib64/python3.7/lib2to3/tests/data/py3_test_grammar.py testBackslashszTokenTests.testBackslashc Csr|tdtd|dd|dd|dd|dd|ttdddlm}|dkr|dd|ddk|ddk|ddkxd D]4}y t|}Wqtk r| d |YqXqWn|d kr`|d d |d dk|d dk|ddkxPdD]8}y t|}Wn$tk rV| d |YnXq"Wn| d|dS)Nrii Z0x)maxsizeil)Z 2147483648Z 0o40000000000Z 0x100000000Z"0b10000000000000000000000000000000z(OverflowError on huge integer literal %rlll)Z9223372036854775808Z0o2000000000000000000000Z0x10000000000000000ZA0b100000000000000000000000000000000000000000000000000000000000000zWeird maxsize value %r) rZtype assertRaises SyntaxErrorevalsysrassert_Z OverflowErrorfail)rrsr r r r testPlainIntegerss8            zTokenTests.testPlainIntegerscCs$d}d}d}d}d}d}d}d}dS)Nrrl?l ~l!]cllr rr r r testLongIntegersAszTokenTests.testLongIntegerscCsHd}d}d}d}d}d}d}d}d}d}d}d }d }d }d }d }d }dS)N i[lE#Wi# iw gffffff?@g?@gףp= ?Q @ BgIae Hg#;7r rr r r testUnderscoresInNumbersKs"z#TokenTests.testUnderscoresInNumberscCs0d}d}d}d}d}d}d}d}d}d}d}dS)Nrgs@gjt?rgt =gWHBgF@r rr r r testFloatsaszTokenTests.testFloatscCs*d}d}|t|dko||kd}d}|t|dkoL||koLt|dkd}d}|t|dkoz||kozt|dkd}d}|t|d ko||kd }d }|t|d ko||kd }d }|||d }|||d }|||d }|||d d }d d }|||dS)Nrz'i'z"i"zdoesn't "shrink" does itizdoes "shrink" doesn't itz2 The "quick" brown fox jumps over the 'lazy' dog. zhello \T)rlenZordr)rr yr r r testStringLiteralsos6&&     zTokenTests.testStringLiteralscCs$d}||tk|ttddS)N.z.. .)rZEllipsisrrrrr r r testEllipsisszTokenTests.testEllipsisN) __name__ __module__ __qualname__r rrrrr#r$r r r r rs $ *rc@s<eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Z d=d>Z!d?d@Z"dAdBZ#dCdDZ$dEdFZ%dGdHZ&dIdJZ'dKdLZ(dMS)N GrammarTestscCs td}dS)Nz 1, 0 or 1)rrr r r testEvalInputzGrammarTests.testEvalInputc s dd}||d|didd}dd}||jjd||jjd d d }d d }dd}dd}dd}||d|d|dd|dd||d|d|dd|dddddddddd |d|d|dd|ddd|dddddddddd |dd|ddd|dddd|dddddddddd dzdd} | | d| d | fd!did{d"d#} | d| dd| d|d$did}d%d&} | dd| ddd| d'| d~d(| dd)| dd*didd+d,} | | d| dd| d-| dd.| dd$di| fddd/dd0d1} | d| dd| ddddd2d3}|dd|ddd|dddddd4d5}||d|dd|d6|d |fd!didd7d8}|d|dd|ddddd9d:}|dd|ddd|dddd|d6|dd*didd;d<}||d|dd|ddd|dd=|fddd/dd>d?}|d|dd|ddd|dddd|d6|dd@|dd.d*diddAdB}|dd|ddd|dddd|ddddd|d6|dd@|dd(dCdiytddEdiWntk rYn X|dFdGdH}|dIdJdIdKdLdM}|dddIdN|dddIdOdP|dddIdOdQdIdNdRdS}|dddIdIdOdT|dddIdOdIdUdVdW}||dddgdddXdYdddXf|ttdZ|ttd[t d\d]dW}||j d^t it d_d`dW}||j dDt itd_dadW}||j dDtit d_dbdW}||j dDt iddcdddW}||j dedidddfdgdW}||j dddfddddddhdidW}||j dddddhdddjdkdddddddldmdndodW}||j dddddddldmdndpdq}|t d\drdW}||j d^t idfdsdW}dfdtdW }ddufdvdW }t d\fdwdW }t |dxt |dydS)NcSdSNr r r r r f1z$GrammarTests.testFuncdef..f1r cSr+r,r Z one_argumentr r r f2r.z$GrammarTests.testFuncdef..f2cSr+r,r twoZ argumentsr r r f3r.z$GrammarTests.testFuncdef..f3r/r1cSr+r,r )Zone_argr r r a1r.z$GrammarTests.testFuncdef..a1cSr+r,r )r2argsr r r a2r.z$GrammarTests.testFuncdef..a2cWr+r,r )restr r r v0r.z$GrammarTests.testFuncdef..v0cWr+r,r ar7r r r v1r.z$GrammarTests.testFuncdef..v1cWr+r,r r:br7r r r v2r.z$GrammarTests.testFuncdef..v2r rr rcSr+r,r r:r r r d01r.z%GrammarTests.testFuncdef..d01r r:cSr+r,r r:r=r r r d11r.z%GrammarTests.testFuncdef..d11r=cSr+r,r r:r=cr r r d21r.z%GrammarTests.testFuncdef..d21r rr?rr?r?rKcSr+r,r rHr r r d02r.z%GrammarTests.testFuncdef..d02r rrrHcSr+r,r rJr r r d12r.z%GrammarTests.testFuncdef..d12cSr+r,r r:r=rKdr r r d22r.z%GrammarTests.testFuncdef..d22cWr+r,r r9r r r d01vr.z&GrammarTests.testFuncdef..d01v)r rr?r@cWr+r,r r<r r r d11vr.z&GrammarTests.testFuncdef..d11vcWr+r,r r:r=rKr7r r r d21vr.z&GrammarTests.testFuncdef..d21vcWr+r,r r<r r r d02v r.z&GrammarTests.testFuncdef..d02v)rr?r@cWr+r,r rYr r r d12vr.z&GrammarTests.testFuncdef..d12v)r?r@rAcWr+r,r )r:r=rKrUr7r r r d22vr.z&GrammarTests.testFuncdef..d22vrUr sfooz/Bytes should not work as keyword argument namescS|Sr,r Zkeyr r r pos0key1-r.z*GrammarTests.testFuncdef..pos0key1idr_)k2cSs ||||fSr,r )p1p2k1rar r r pos2key2/r.z*GrammarTests.testFuncdef..pos2key2)rdi)rdra)rardc[s|||||fSr,r )rbrcrdraZkwargr r r pos2key2dict3r.z.GrammarTests.testFuncdef..pos2key2dict)ratokwarg1tokwarg2)rgrhrac_s||fSr,r )r5Zkwargsr r r f8z#GrammarTests.testFuncdef..fr r")r r?r@zf(1, *(2,3), 4)zf(1, x=2, *(3,4), x=5))returncSr+r,r r r r r ri@r.rlrmcSr+r,r rmr r r riBr.cWr+r,r rmr r r riDr.c[r+r,r rmr r r riFr.r"cSr+r,r rkr r r riHr.r")r=rKcSr+r,r rTr r r riJr.)r=rKegcWr+r,r )r:r=rKrUrorirpr r r riLr.r)iji )r=rKrorphrrkrlc _r+r,r ) r:r=rKrUrorirtrqrrrprur r r riOrjcSr^r,r rmr r r nullUr.z&GrammarTests.testFuncdef..nullcSr+r,r rmr r r riVrjcSr,r r Zclosurer r ri\r.crwr,r rmrxr r ri]r.rucrwr,r ryrxr r ri^r.crwr,r r rxr r ri_r.z f(*g(1=2))z f(**g(1=2))rGrGrGrGrGrQrQrQrGrGrQrQrGrGrGrQrQrGrQrQrGrQrQrGrmrGr@rArzrG)rZ__code__Z co_varnamesstr TypeErrorrrrrlistZ__annotations__ZintZfloatr)rr-r0r3r4r6r8r;r>rFrIrLrPrSrVrWrXrZr[r\r]r`rerfrirvr rxr testFuncdefs4                                                    zGrammarTests.testFuncdefcCsdd}||ddd}dd}||dddgdddfddfd d}||ddd d}||dd d ||dd d dt|dt|ddddd}||dd d||dd ddddS)NcSdS)Nrr r r r r gr.z*GrammarTests.testLambdef..rcSsttSr,)r:rUr r r r rir.cSsdddDS)NcSsg|] }d|kqSrRr .0r r r r jz>GrammarTests.testLambdef....)r?rr r r r r rjr.r cSr^r,r )zr r r rlr.cS|Sr,r rnr r r rlr.cSrr,r rmr r r rlr.rcS |||Sr,r )r r"rr r r rnr.rAr?rBzlambda x: x = 2zlambda (None,): NonerycSrr,r )r r"rur r r rsr.irrrGrR)rr)rZl1Zl2Zl3Zl4Zl5Zl6r r r testLambdefes   zGrammarTests.testLambdefcCsd}~dd}|dS)Nr cSs d}~dSNr r rmr r r foo~sz(GrammarTests.testSimpleStmt..foor )rr rr r r testSimpleStmt{szGrammarTests.testSimpleStmtc CsRd}d}d}}}d\}}}d}\}}}\}}}}t|dt|ddS)Nr rM)r r)r?r@z x + 1 = 1z a + 1 = b + 2r) rr r"rabcr:r=rKxyzr r r testExprStmts   zGrammarTests.testExprStmtcCs,dddg}|\}}}|||f}~~~~~dS)Nr rr?r )rrr r"rrr r r testDelStmts    zGrammarTests.testDelStmtcCr+r,r rr r r testPassStmtr*zGrammarTests.testPassStmtcCs xPqWdSr,r rr r r testBreakStmtszGrammarTests.testBreakStmtcCsd}x|rd}qqWd}x(|s@d}y wd}Wqd}YqXqW|dkrT||d}x|srd}zwZWdd}XqZW|dkr||dS)Nr rrZokz&continue failed to continue inside tryz'continue inside try called except blockzfinally block not calledr)rrqmsgr r r testContinueStmts,  zGrammarTests.testContinueStmtcsdfdd }|dS)Nr rcshd}xD|rH|d7}y$|r*|dkr*|d8}P|d8}wWqYqXqW|dksZ|dkrdddS)Nrr z1continue then break in try/except in loop broken!r)Zextra_burning_oilZcountZ big_hipporr r test_inners  z9GrammarTests.test_break_continue_loop..test_inner)r rr )rrr rr test_break_continue_loops z%GrammarTests.test_break_continue_loopcCs*dd}dd}||}t|ddS)NcSr+r,r r r r r g1r.z#GrammarTests.testReturn..g1cSrrr r r r r g2r.z#GrammarTests.testReturn..g2zclass foo:return 1r)rrrr r r r testReturns zGrammarTests.testReturncCst|ddS)Nzclass foo:yield 1rrr r r testYieldrjzGrammarTests.testYieldcCsDy tdWntk r YnXytWntk r>YnXdS)Nz just testing) RuntimeErrorZKeyboardInterruptrr r r testRaises zGrammarTests.testRaisecCsdddl}ddl}ddl}ddlm}ddlm}ddlm}m}ddlm}m}ddlm}m}dS)Nr)time)pathargv)rrrr)rrrrrr r r testImports  zGrammarTests.testImportcCr+r,r rr r r testGlobalszGrammarTests.testGlobalcsddfdd}dS)Nrcr+r,r r rkr r rir*z$GrammarTests.testNonlocal..fr )rrir rkr testNonlocalszGrammarTests.testNonlocalc Cs>yWn4tk r8}z||jddWdd}~XYnXdS)Nrr)ZAssertionErrorrr5)rror r r testAsserts $zGrammarTests.testAssertcCr+r,r rr r r testIfs zGrammarTests.testIfcCsd}d}||ddS)Nrrrrr r r testWhile&szGrammarTests.testWhilecCsx dD]}qWxdD] \}}}qWGddd}d}x|dD] }||}q>W|dkr`|dg}xd D]\}||qjW||d d d gdS) NrMr c@$eZdZddZddZddZdS)z%GrammarTests.testFor..SquarescSs||_g|_dSr,)maxsofar)rrr r r __init__;sz.GrammarTests.testFor..Squares.__init__cSs t|jSr,)r!rrr r r __len__>r.z-GrammarTests.testFor..Squares.__len__cSsVd|kr|jksntt|j}x$||krJ|j|||d}q(W|j|S)Nrr )rZ IndexErrorr!rappend)rrqnr r r __getitem__?s   z1GrammarTests.testFor..Squares.__getitem__N)r%r&r'rrrr r r r Squares:srrrizfor over growing sequence)rGrRrOr rr?)rr assertEqual)rrqrrrurrr Zresultr r r testFor5s     zGrammarTests.testForc Csy ddWntk r YnXy ddWn^tk rBYnLtk rb}zWdd}~XYn,tk r}zWdd}~XYn YnXy ddWntttfk rYnXy ddWn(tttfk r}zWdd}~XYnXzWdXdSNr r)ZZeroDivisionErrorZEOFErrorr|r)rrr r r testTryPs2    zGrammarTests.testTrycCr+r,r rr r r testSuitegs zGrammarTests.testSuitecCsdsdrdsdsdrdS)Nr Fr rr r r testTestvs  zGrammarTests.testTestcCsddk}ddkrddkrddkr ddkr(ddkr0ddkr8ddkr@ddk rHddkrPddkrXddkrdkrdkrdkrdkrdkrdkrdkrdkrdk rnndS)Nr r r rr r r testComparisonshzGrammarTests.testComparisoncCsd}d}d}dSrr rr r r testBinaryMaskOpszGrammarTests.testBinaryMaskOpscCsd}d}d}dS)Nrrr r rr r r testShiftOpsrzGrammarTests.testShiftOpscCsd}d}d}d}dS)Nr rrr rr r r testAdditiveOpszGrammarTests.testAdditiveOpscCsd}d}d}d}dS)Nr ?rgr rr r r testMultiplicativeOpsrz"GrammarTests.testMultiplicativeOpscCsd}d}d}d}d}dS)Nr rirr rr r r testUnaryOpss zGrammarTests.testUnaryOpsc Csddl}ddl}|jd}|}|jd}d}|d}|d}|dd}|dd}|dd}|dd}|dd}|dd}|dd}i}d |d <d |d <d |d <d|d<t|}|jddd|t|ddS)NrrZ01234rrAiiir rrGr?rQr@rMcSst|tr|SdS)Nr )Z isinstanceZtuplermr r r rr.z,GrammarTests.testSelectors..r_z[1, (1,), (1, 2), (1, 2, 3)])rrrZmodulesr}Zsortrr{) rrrrKr r:rrUZLr r r testSelectorss,        zGrammarTests.testSelectorscCsd}dpdpd}dpdpdddf}g}dg}dp6dp6dg}dpDdpDdddg}g}i}ddi}ddi}dpjddppdi}ddd}ddd}dddddd d }dh}ddh}ddd h}dddh}|}d }d }dS)Nr rr?oner2)rr2r@rArB)rr2threeZfourZfiveZsixrr i{r rr r r testAtomss,     zGrammarTests.testAtomsc Cs|Gddd}Gddd}Gddd|}Gddd|}Gd d d |||}Gd d d }d d}|Gddd}dS)Nc@ eZdZdS)z$GrammarTests.testClassdef..BNr%r&r'r r r r Brc@r)z%GrammarTests.testClassdef..B2Nrr r r r B2rrc@r)z%GrammarTests.testClassdef..C1Nrr r r r C1rrc@r)z%GrammarTests.testClassdef..C2Nrr r r r C2rrc@r)z$GrammarTests.testClassdef..DNrr r r r Drrc@r)z$GrammarTests.testClassdef..CcSr+r,r rr r r meth1r.z*GrammarTests.testClassdef..C.meth1cSr+r,r )rZargr r r meth2r.z*GrammarTests.testClassdef..C.meth2cSr+r,r )rr4r6r r r meth3r.z*GrammarTests.testClassdef..C.meth3N)r%r&r'rrrr r r r CsrcSr^r,r rmr r r class_decoratorr.z2GrammarTests.testClassdef..class_decoratorc@r)z$GrammarTests.testClassdef..GNrr r r r Gsrr ) rrrrrrrrrr r r testClassdefszGrammarTests.testClassdefcCs,dddg}|dd|DdddddS)Nr rr?cSsi|]}|d|qSrGr rrqr r r z rz.GrammarTests.testDictcomps..r@rMr)rnumsr r r testDictcompss zGrammarTests.testDictcompscsdddddg}dddgd d d g}d d |Ddddgdd |Ddddddgdd |Ddddgfdd |Dddddddddddd d!d"d#d$gfd%d |Dddddddd d!d#d$g d&d tdDdgddgdddgdddd'gddd(d)d*ggd+d,}||d-d-d-gfd.d/}|td0td1d2d3d4g}d5d6d7gd8d9d:d;gfdd?d@gdS)ANr rr?r@rAAppleBananaCoconutz Applez Banana z Coco nut cSsg|] }|qSr )Zstrip)rrr r r rrz.GrammarTests.testListcomps..z Coco nutcSsg|] }d|qSrOr rr r r rrrBr rsicSsg|]}|dkr|qSrRr rr r r rrcsg|]}D] }||fq qSr r rrqrstrsr r rr)r r)r r)r r)rr)rr)rr)r?r)r?r)r?r)r@r)r@r)r@r)rAr)rAr)rArcs(g|] }ddDD] }||fqqS)cSsg|]}d|kr|qS)rr )rrir r r rrz9GrammarTests.testListcomps...r rrr r rrcSsg|]}dd|qS)csfddtdDS)Ncsg|] }|qSr r rrEr r rrzKGrammarTests.testListcomps.....r rangerEr rEr rr.z7GrammarTests.testListcomps...r )rrrr r r rriii@icSsdd|DS)NcSs,g|]$}|dkrd|ko"dknqS)rrr?r rr r r r!rzDGrammarTests.testListcomps..test_in_func..r )Zlr r r test_in_func rjz0GrammarTests.testListcomps..test_in_funcFcs,dddDddgddgdd ggdS) NcSs"g|]}dd||dgDqS)cSg|]}|qSr r rr"r r r r&rzTGrammarTests.testListcomps..test_nested_front...r r rr r r r&rzIGrammarTests.testListcomps..test_nested_front..)r r?rAr rr?r@rArBrr rr r test_nested_front%sz5GrammarTests.testListcomps..test_nested_frontz"[i, s for i in nums for s in strs]z[x if y])r Boeing)rFord)r? Macdonalds)rAirliner)rEngine) Cheeseburger)r r)r r)rr)r?rcsDg|]<\}}D].\}}D] \}}||kr||kr||fqqqSr r )rZsnoZsnameZpnoZpnameZsp_snoZsp_pno)partssuppartr r r?s  )rr)rr)rr)rr)rrr)rrZspcsrrZ suppliersr r )rrrrr testListcomps sF     .      zGrammarTests.testListcompscsddtdD}|t|ddtdDyt||dWntk rZYnXdy(fddD}t||d Wntk rYnX|td dd Dd dd D|td ddDdddDddtdDddddDD}|t|tddtdD|tddtdDtddtdD|tddtdDtddtdD|tddddtdDDtddtdD|tddddddtdDDDtddtdD|tddd dd!dtdDDDtd"dtdD|td#dd$dd%dtdDDDtd&dtdD|td'dd(dd)dtdDDDd*t|d+t|d,dS)-Ncss |]}ddtdDVqdS)cSrr r rr r r rKrz6GrammarTests.testGenexps...rNrrr r r Kz+GrammarTests.testGenexps..r cSrr r rr r r rLrz,GrammarTests.testGenexps..rz&should produce StopIteration exceptionc3s|] }VqdSr,r )rrUrEr r rUrzshould produce TypeErrorcs |]}dD]}||fVq qdS)abcdNr rr r"r r r r[rrcSg|]}dD] }||fq qS)rr rr r r r[rcsr)xyNr rr r r r\rZabcSr)rr rr r r r\rcSrr r rr r r r^rcs|] }|VqdSr,r rr r r r_rcsrr,r rr r r r_rcSrr r rr r r r`rcss|]}|dVqdSrNr rr r r rbrcSsg|] }|dqSrRr rr r r rbrcss|]}|dr||VqdSrr rr r r rcrcSsg|]}|dr||qSrRr rr r r rcrcsrr,r rr r r rdrcsrr,r rr r r rdrcSrr r rr r r rdrcsrr,r rr r r rercsrr,r rr r r rercsrr,r rrr r r rercSrr r rr r r rercsrr,r rr r r rfrcSrr r rr r r rfrcsrr,r rr r r rfrcSrr r rr r r rfrcs|] }|VqdSTNr rr r r rgrcsrr,r rr r r rgrcsrrr rr r r rgrcSrr r rr r r rgrcsrrr rr r r rhrcss|]}dr|VqdS)FNr rr r r rhrcsrrr rr r r rhrrzfoo(x for x in range(10), 100)zfoo(100, x for x in range(10))) rrZnextrZ StopIterationr|r}Zsumr)rrpr=r rEr testGenexpsIs8$$"00:DDD2 zGrammarTests.testGenexpscsdddtD}d|tt|dddfddtD}dd|dd tdDt||d d tdDd dd g|td dtdDd dd g|dd dDdddg|tdddDd ddgdS)Nrcsrr,r rr r r rnrz9GrammarTests.testComprehensionSpecials..rAFc3s(|] }rtD]}||fVqqdSr,rrrqrrZtr r r rrrTcSs"g|]}tdD] }||fqqSrArrr r r rtrz:GrammarTests.testComprehensionSpecials..cSs g|]}|dr|dr|qSrNr rr r r rxrr rCcss"|]}|dr|dr|VqdS)rr?Nr rr r r ryrcSsg|] \}|qSr r rr r r r|r))r@r)rBr@rBcss|] \}|VqdSr,r rr r r r}r))rC)rD)r rDr )rrr!r})rrpr rr testComprehensionSpecialsls $z&GrammarTests.testComprehensionSpecialsc CsGdddt}|WdQRX|}WdQRX| \}}WdQRX||WdQRXWdQRX|}|}WdQRXWdQRX|}|WdQRXWdQRXdS)Nc@seZdZddZddZdS)z1GrammarTests.test_with_statement..managercSr)NrQr rr r r __enter__rjz;GrammarTests.test_with_statement..manager.__enter__cWr+r,r )rr5r r r __exit__rjz:GrammarTests.test_with_statement..manager.__exit__N)r%r&r'rrr r r r managersr)Zobject)rrr r"r r r test_with_statements    z GrammarTests.test_with_statementcCsdd}|ddddddfDdg|d dd dd dfDdg|d n|ddd |drx|ddnd d |drd odnd d |drd odnd d |d odnd d|drdp|ddndd|d p|ddn|ddd |dpd n|ddd |dnd d|dr>dnd d |dndd|d ndd |dndd|dndd|drddkndddS)NcSs tt|Sr,)Zprintr )rZretr r r _checkevalsz/GrammarTests.testIfElseExpr.._checkevalcSsg|]}|r|qSr r rr r r rrz/GrammarTests.testIfElseExpr..cSr)NTr r r r r rr.z-GrammarTests.testIfElseExpr..cSr)NFr r r r r rr.TcSsg|]}|dr|dqS)Fr rr r r rrcS |rdSdS)NFTr rmr r r rr.cSr)NTFr rmr r r rr.r rAzcheck 1rzcheck 2rBzcheck 3rr?zcheck 4zcheck 5zcheck 6FrCrsr@g@r)rrr r r testIfElseExprs$$$"zGrammarTests.testIfElseExprN))r%r&r'r)r~rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r r r r(sN 9      #?#r(cCstttdSr,)rrr(r r r r test_mainrjrZ__main__) Z test.supportrrZunittestrZTestCaserr(rr%r r r r Z s