U W½g†ã@sÊddlmZddlmZddlmZGdd„deƒZddd„Zd d „Zd d „Zd d„Z ee ƒZ dd„Z dd„Z ee ƒZ dd„Z ee ƒZ dd„ZeeƒZdd„ZeeƒZdd„ZeeƒZGdd„deƒZdS)é)Úgreenleté)ÚTestCase)Úfails_leakcheckc@s<eZdZdZdd„Zdd„Zdd„Zdd „Zd d „ZeZ dS) ÚgenletNcOs||_||_d|_dS©N)ÚargsÚkwdsÚchild)Úselfrr ©r úT/opt/hc_python/lib64/python3.8/site-packages/greenlet/tests/test_generator_nested.pyÚ__init__szgenlet.__init__cCs|j\}||j|jŽdSr)Úfnrr )r rr r r Úrun sz genlet.runcCs|Srr ©r r r r Ú__iter__szgenlet.__iter__cCs ||_dSr)r )r r r r r Ú set_childszgenlet.set_childcCsP|jr.|j}|jr$|}|j}d|_q | ¡}nt ¡|_| ¡}|rH|St‚dSr)r ÚswitchrÚ getcurrentÚparentÚ StopIteration)r r ÚtmpÚresultr r r Ú__next__s  zgenlet.__next__) Ú__name__Ú __module__Ú __qualname__rrrrrrÚnextr r r r rsrcCsTt ¡}|dkrFt|tƒs"tdƒ‚|dkr6|j |¡|j}|d8}q| |¡dS)Nrzyield outside a genletr)rrÚ isinstancerÚ RuntimeErrorrrr)ÚvalueÚlevelÚgr r r ÚYield-s   r$csG‡fdd„dtƒ}|S)NcseZdZ”fZdS)zGenlet..TheGenletN)rrrrr ©Úfuncr r Ú TheGenlet<sr')r)r&r'r r%r ÚGenlet;sr(ccs&t|ƒD]}| |d¡|VqdS©Nr)ÚrangeÚappend©ÚnÚseenÚir r r Úg1Cs r0cCs(t|ƒD]}| |d¡t|ƒqdSr))r*r+r$r,r r r Úg2Is r1cCs t|ƒdSr©r$)r/r r r ÚnestedQsr3cCs(t|ƒD]}| |d¡t|ƒqdSr))r*r+r3r,r r r Úg3Us r4cCs2|dkr dSt|dƒD] }t|ƒqt|ƒdS)Nrr)Úaxr$©r-Úiir r r Úa\s  r8csPt|ƒdkrD|D]0‰‡fdd„t‡fdd„|DƒƒDƒ}|st‚qnt|ƒdS)Nrcsg|]}tˆg|ƒ‘qSr r2)Ú.0Úp©Úer r Ú iszperms..csg|]}|ˆkr|‘qSr r )r9Úxr;r r r=is)ÚlenÚpermsÚAssertionErrorr$)Úlr>r r;r r@es  $ r@cCs*td|ƒD]}t|ƒt||dƒq dS)Nré)r*r$r6r r r Úgr1psrDcCst|ƒD]}| |¡qdSr)rDr+)r-r.r7r r r Úgr2xs rEc@s8eZdZdd„Zedd„ƒZdd„Zdd„Zd d „Zd S) ÚNestedGeneratorTestsc Cs>g}td|ƒD]}| |¡q| |ddddddddg¡dS)NérrCééé é)rEr+Ú assertEqual©r r.r7r r r Útest_layered_genlets€s z)NestedGeneratorTests.test_layered_genletsc Cstttdƒƒƒ}t|ƒ}| t|ƒd¡| ddddg|¡| ddddg|¡g}ttttdƒƒƒtttdƒƒƒƒD]}| |¡qv| |ddddgdddgfddddgdddgfddddgdddgfddddgdddgfddddgdddgfddddgdddgfg¡dS)NrHérrrCrI)r@Úlistr*rLr?ZassertInÚzipr+)r Z gen_permsÚ permutationsÚresr7r r r Útest_permutations†s"& (þþz&NestedGeneratorTests.test_permutationscCsdtttfD]T}g}tdƒD]}|d|ƒD]}| |¡q(q| |dddddddddddg ¡q dS)NrIrGrrrCrH)r0r1r4r*r+rL)r r#r.Ú_Újr r r Útest_genlet_simple—s  z'NestedGeneratorTests.test_genlet_simplecCs&z tdƒWntk r YnXdS)Né )r$r rr r r Útest_genlet_badŸs z$NestedGeneratorTests.test_genlet_badcCs g}tdƒD]}| |¡q dS)NrG)r5r+rMr r r Útest_nested_genlets¥s z(NestedGeneratorTests.test_nested_genletsN) rrrrNrrTrWrYrZr r r r rFs  rFN)r)rÚrZ leakcheckrrr$r(r0r1r3r4r8r5r@rDrErFr r r r Ús(   '