o !ÔbŽã@sÄddlZddlZddlZddlZddlmZddlZddlmZddl m Z ddl m Z m Z mZmZmZddlmZmZmZGdd„dejƒZGd d „d ejƒZd d „Zed kr`ejd ddSdS)éN)Úmkstemp)ÚMarkup)ÚContext)Ú ExpressionÚSuiteÚ UndefinedÚUndefinedErrorÚ UNDEFINED)ÚBytesIOÚ IS_PYTHON2Ú wrapped_bytesc@sneZdZdd„Zdd„Zdd„Zdd„Zd d „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;„Zdd?„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[„Z/d\d]„Z0d^d_„Z1d`da„Z2dbdc„Z3ddde„Z4e5j6dfkrÙdgdh„Z7didj„Z8dkdl„Z9dmdn„Z:dodp„Z;dqdr„Zdwdx„Z?dydz„Z@d{d|„ZAd}d~„ZBdd€„ZCdd‚„ZDdƒd„„ZEd…d†„ZFd‡dˆ„ZGd‰dŠ„ZHd‹dŒ„ZIddŽ„ZJdd„ZKd‘d’„ZLd“d”„ZMd•d–„ZNd—S)˜ÚExpressionTestCasecCs,tdƒ}| |tdƒ¡| |tdƒ¡dS©Nzx,yzy, x)rÚ assertEqualÚassertNotEqual©ÚselfÚexpr©rúz+1z+xÚxr;r'rrrÚtest_unaryop_posnóz#ExpressionTestCase.test_unaryop_poscCó4| dtdƒ i¡¡| dtdƒ ddi¡¡dS)Néÿÿÿÿz-1z-xrBr>r;r'rrrÚtest_unaryop_negrrDz#ExpressionTestCase.test_unaryop_negcCrE)NFznot Trueznot xrBTr;r'rrrÚtest_unaryop_notvrDz#ExpressionTestCase.test_unaryop_notcCrE)Néþÿÿÿz~1z~xrBr>r;r'rrrÚtest_unaryop_invzrDz#ExpressionTestCase.test_unaryop_invcCó6| dtdƒ i¡¡| dtdƒ dddœ¡¡dS)Nr?z2 + 1zx + yrr>©rBÚyr;r'rrrÚtest_binop_add~ó z!ExpressionTestCase.test_binop_addcCs6| dtdƒ i¡¡| dtdƒ dddœ¡¡dS)Nr>ú2 - 1úx - yrLr;r'rrrÚtest_binop_sub‚rOz!ExpressionTestCase.test_binop_subcCó6| dtdƒ i¡¡| dtdƒ dddœ¡¡dS)Nr>rPrQrrLr;r'rrrrR†rOcCó6| dtdƒ i¡¡| dtdƒ dddœ¡¡dS)Néz2 * 2zx * yrrLr;r'rrrÚtest_binop_mulŠrOz!ExpressionTestCase.test_binop_mulcCrT)NrUz2 ** 2zx ** yrrLr;r'rrrÚtest_binop_powŽrOz!ExpressionTestCase.test_binop_powcCrS)Nrz4 / 2zx / yrUrLr;r'rrrÚtest_binop_div’rOz!ExpressionTestCase.test_binop_divcCrK)Nr>z3 // 2zx // yr?rrLr;r'rrrÚtest_binop_floordiv–rOz&ExpressionTestCase.test_binop_floordivcCrK)Nr>z3 % 2zx % yr?rrLr;r'rrrÚtest_binop_modšrOz!ExpressionTestCase.test_binop_modcCrS)Nrz1 & 0zx & yr>rLr;r'rrrÚtest_binop_andžrOz!ExpressionTestCase.test_binop_andcCó6| dtdƒ i¡¡| dtdƒ dddœ¡¡dS)Nr>z1 | 0zx | yrrLr;r'rrrÚ test_binop_or¢rOz ExpressionTestCase.test_binop_orcCr\)Nr>z1 ^ 0zx ^ yrrLr;r'rrrÚtest_binop_xor¦rOz!ExpressionTestCase.test_binop_xorcCrK)NTz1 in (1, 2, 3)zx in yr>r=rLr;r'rrrÚtest_binop_containsªóÿz&ExpressionTestCase.test_binop_containscCrK)NTz4 not in (1, 2, 3)z x not in yrUr=rLr;r'rrrÚtest_binop_not_contains¯r`z*ExpressionTestCase.test_binop_not_containscCsh| dtdƒ i¡¡| dtdƒ dddœ¡¡| dtdƒ i¡¡| dtdƒ dddœ¡¡dS) NTz1 is 1zx is yr>rLFz1 is 2rr;r'rrrÚ test_binop_is´s z ExpressionTestCase.test_binop_iscCsh| dtdƒ i¡¡| dtdƒ dddœ¡¡| dtdƒ i¡¡| dtdƒ dddœ¡¡dS) NTz 1 is not 2z x is not yr>rrLFz 1 is not 1r;r'rrrÚtest_binop_is_notºs ÿÿz$ExpressionTestCase.test_binop_is_notcCrS)NFzTrue and Falsezx and yTrLr;r'rrrÚtest_boolop_andÂr`z"ExpressionTestCase.test_boolop_andcCr\)NTz True or Falsezx or yFrLr;r'rrrÚtest_boolop_orÇr`z!ExpressionTestCase.test_boolop_orcCrT)NTz1 == 1zx == yr>rLr;r'rrrÚtest_compare_eqÌrOz"ExpressionTestCase.test_compare_eqcCsv| dtdƒ i¡¡| dtdƒ dddœ¡¡tjdkr9| dtdƒ i¡¡| dtdƒ dddœ¡¡dSdS) NFz1 != 1zx != yr>rLÚ3z1 <> 1zx <> y)rrrÚsysÚversionr'rrrÚtest_compare_neÐs   þz"ExpressionTestCase.test_compare_necCrK)NTrzx < yr>rrLr;r'rrrÚtest_compare_lt×rOz"ExpressionTestCase.test_compare_ltcCrT)NTz1 <= 1zx <= yr>rLr;r'rrrÚtest_compare_leÛrOz"ExpressionTestCase.test_compare_lecCrK)NTz2 > 1zx > yrr>rLr;r'rrrÚtest_compare_gtßrOz"ExpressionTestCase.test_compare_gtcCrT)NTz1 >= 1zx >= yr>rLr;r'rrrÚtest_compare_geãrOz"ExpressionTestCase.test_compare_gecCrK)NTz 1 != 3 == 3z x != y == yr>r?rLr;r'rrrÚtest_compare_multiçr`z%ExpressionTestCase.test_compare_multicCsf| dtdƒ ddd„i¡¡ddi}| dtdƒ |¡¡ddtdƒii}| dtd ƒ |¡¡dS) Nr0zfoo()r%cSódS)Nr0rrrrrÚíóz7ExpressionTestCase.test_call_function..r$ÚBARz foo.upper()z len(foo.bar))rrrÚrange©rÚdatarrrÚtest_call_functionìs z%ExpressionTestCase.test_call_functioncCs$| dtdƒ dd„ddœ¡¡dS)Nr0z foo(x=bar)cSó|S©Nr©rBrrrrqôrrz7ExpressionTestCase.test_call_keywords..©r%r$r;r'rrrÚtest_call_keywordsósÿz%ExpressionTestCase.test_call_keywordscCs&| dtdƒ dd„dgdœ¡¡dS)Nr0z foo(*bar)cSrxryrrzrrrrqørrz8ExpressionTestCase.test_call_star_args..r{r;r'rrrÚtest_call_star_args÷sÿz&ExpressionTestCase.test_call_star_argscCs0dd„}tdƒ}| d| |ddidœ¡¡dS)NcSrxryrrzrrrr%üóz4ExpressionTestCase.test_call_dstar_args..fooz foo(**bar)r0rBr{©rrr)rr%rrrrÚtest_call_dstar_argsûs z'ExpressionTestCase.test_call_dstar_argscCs2dtdƒi}tdƒ}| ddgt| |¡ƒ¡dS)NÚitemsézfilter(lambda x: x > 2, items)r?rU)rtrrÚlistr©rrvrrrrÚ test_lambdas zExpressionTestCase.test_lambdacCs8tsdSdddgi}tdƒ}| dgt| |¡ƒ¡dS)Nr©r>r)rr>z#filter(lambda (x, y): x > y, items))r rrrƒrr„rrrÚtest_lambda_tuple_args  z(ExpressionTestCase.test_lambda_tuple_argc CóÒtdƒ}| ddg| dtdƒi¡¡tdƒ}| gd¢| dtdƒi¡¡tdƒ}| gd ¢| tdƒd d œ¡¡td ƒ}| gd ¢| dtd ƒtdƒgi¡¡tdƒ}| gd¢| ddgddgdœ¡¡dS)Nz[n for n in numbers if n < 2]rr>Únumbersr‚z+[(i, n + 1) for i, n in enumerate(numbers)]©)rr>r†)rr?)r?rU)rUr‚z[offset + n for n in numbers]©rr?rUr‚ér©r‰Úoffsetz&[n for group in groups for n in group]©rr>rr>rÚgroupsr?z[(a, b) for a in x for b in y]©)Úx0Úy0)r’Úy1)Úx1r“)r•r”r’r•r“r”rL©rrrrtrrrrÚtest_list_comprehensionó$ ÿ ÿ ÿ ÿz*ExpressionTestCase.test_list_comprehensioncCó8dddœdddœg}tdƒ}| dg| d|i¡¡dS)NÚar>©Únamer:Úbrz&[i.name for i in items if i.value > 1]rr©rrrrrrÚ$test_list_comprehension_with_getattr"óz7ExpressionTestCase.test_list_comprehension_with_getattrcCr™)Nršr>r›rrz,[i['name'] for i in items if i['value'] > 1]rrržrrrÚ$test_list_comprehension_with_getitem'r z7ExpressionTestCase.test_list_comprehension_with_getitemc Crˆ)Nz!list(n for n in numbers if n < 2)rr>r‰r‚z/list((i, n + 1) for i, n in enumerate(numbers))rŠz!list(offset + n for n in numbers)r‹rrz*list(n for group in groups for n in group)rrr?z"list((a, b) for a in x for b in y)r‘r’r•r“r”rLr–rrrrÚtest_generator_expression,r˜z,ExpressionTestCase.test_generator_expressioncCr™)Nršr>r›rrz*list(i.name for i in items if i.value > 1)rrržrrrÚ&test_generator_expression_with_getattr@r z9ExpressionTestCase.test_generator_expression_with_getattrcCr™)Nršr>r›rrz0list(i['name'] for i in items if i['value'] > 1)rrržrrrÚ&test_generator_expression_with_getitemEr z9ExpressionTestCase.test_generator_expression_with_getitem)rr‚cCs8tdƒ}| d| ddi¡¡| d| ddi¡¡dS)Nz'T' if foo else 'F'ÚTr%TÚFFrrrrrÚtest_conditional_expressionKsz.ExpressionTestCase.test_conditional_expressionc Cs.tdƒ}| ddg| dttdƒƒi¡¡dS)Nz numbers[0:2]rr>r‰r‚©rrrrƒrtrrrrÚ test_slicePs&zExpressionTestCase.test_slicecCs6tdƒ}| ttdƒƒdddœ¡}| ddg|¡dS)Nznumbers[start:end]r‚rr©r‰ÚstartÚendr>©rrrƒrtr©rrÚresrrrÚtest_slice_with_varsTsz'ExpressionTestCase.test_slice_with_varscCó2tdƒ}| dttdƒƒi¡}| gd¢|¡dS)Nz numbers[:]r‰r‚©rr>rr?rUr­r®rrrÚtest_slice_copyYóz"ExpressionTestCase.test_slice_copycCs4tdƒ}| ttdƒƒddœ¡}| gd¢|¡dS)Nznumbers[::stride]r‚r©r‰Ústride©rrrUr­r®rrrÚtest_slice_stride^sz$ExpressionTestCase.test_slice_stridec Cs,tdƒ}| dg| dttdƒƒi¡¡dS)Nz numbers[-1:]rUr‰r‚r¨rrrrÚtest_slice_negative_startcs$z,ExpressionTestCase.test_slice_negative_startcCr±)Nz numbers[:-1]r‰r‚©rr>rr?r­r®rrrÚtest_slice_negative_endgr´z*ExpressionTestCase.test_slice_negative_endcCs.tdƒ}| dttdƒƒi¡}| |d¡dS)Nz numbers[1]r‰r‚r>r­r®rrrÚtest_slice_constantlsz&ExpressionTestCase.test_slice_constantcCs8dd„}tdƒ}| ttdƒƒ|dœ¡}| |d¡dS)NcSrp©NrrrrrrÚfrr~z-ExpressionTestCase.test_slice_call..fz numbers[f()]r‚©r‰r¾rr­)rr¾rr¯rrrÚtest_slice_callqsz"ExpressionTestCase.test_slice_callcCs0tdƒ}| ttdƒƒddœ¡}| |d¡dS)Nz numbers[v]r‚r©r‰Úvr­r®rrrÚtest_slice_namexsz"ExpressionTestCase.test_slice_namecCs@Gdd„dƒ}tdƒ}| ttdƒƒ|ƒdœ¡}| |d¡dS)Nc@óeZdZdd„ZdS)z.ValueHoldercSó d|_dS©Nr?©r:r'rrrÚ__init__ó zEExpressionTestCase.test_slice_attribute..ValueHolder.__init__N©Ú__name__Ú __module__Ú __qualname__rÈrrrrÚ ValueHolder~ó rÎznumbers[obj.value]r‚©r‰Úobjr?r­)rrÎrr¯rrrÚtest_slice_attribute}sz'ExpressionTestCase.test_slice_attributecCsHtddddd}| i¡}t|tƒsJ‚| d|j¡|jtus"J‚dS)NÚnothingú index.htmlé2Úlenient©ÚfilenameÚlinenoÚlookup)rrÚ isinstancerrÚ_nameÚ_ownerr )rrÚretvalrrrÚtest_access_undefined…sÿ z(ExpressionTestCase.test_access_undefinedcCóbGdd„dtƒ}|ƒ}tddddd}| d|i¡}t|tƒs!J‚| d |j¡|j|us/J‚dS) Nc@rÄ)z.SomethingcSrp©Nz rr'rrrÚ__repr__r~zEExpressionTestCase.test_getattr_undefined..Something.__repr__N©rËrÌrÍrârrrrÚ SomethingŽrÏräú something.nilrÔrÕrÖr×Ú somethingÚnil©ÚobjectrrrÛrrrÜrÝ©rrärærrÞrrrÚtest_getattr_undefinedóÿz)ExpressionTestCase.test_getattr_undefinedcCsHGdd„dtƒ}| ttdƒjd|ƒi¡| ttdƒjd|ƒi¡dS)Nc@s,eZdZdd„ZeeƒZdd„ZeeƒZdS)z.SomethingcSót‚ry©ÚNotImplementedErrorr'rrrÚprop_a›r~zCExpressionTestCase.test_getattr_exception..Something.prop_acSríry)ÚAttributeErrorr'rrrÚprop_bžr~zCExpressionTestCase.test_getattr_exception..Something.prop_bN)rËrÌrÍrðÚpropertyròrrrrräšs  räzs.prop_aÚszs.prop_b)réÚ assertRaisesrïrrrñ©rrärrrÚtest_getattr_exception™sÿÿz)ExpressionTestCase.test_getattr_exceptioncCrà) Nc@rÄ)zCExpressionTestCase.test_getitem_undefined_string..SomethingcSrprárr'rrrrâ¨r~zLExpressionTestCase.test_getitem_undefined_string..Something.__repr__Nrãrrrrrä§rÏräúsomething["nil"]rÔrÕrÖr×rærçrèrêrrrÚtest_getitem_undefined_string¦rìz0ExpressionTestCase.test_getitem_undefined_stringcCs.Gdd„dtƒ}| ttdƒjd|ƒi¡dS)Nc@rÄ)z.SomethingcSríryrî)rr9rrrÚ __getitem__´r~zHExpressionTestCase.test_getitem_exception..Something.__getitem__N)rËrÌrÍrúrrrrrä³rÏräzs["foo"]rô)rérõrïrrrörrrÚtest_getitem_exception²sÿz)ExpressionTestCase.test_getitem_exceptionc CsÔtddddd}z | i¡| d¡WdStyi}zHt ¡\}}}|j}g}|jr7|j}| |¡|js,| dt |ƒ¡| d|d j j j ¡| d|d j j j ¡| d|d j¡WYd}~dSd}~ww) NrÓrÔrÕÚstrictr×úExpected UndefinedErrorz"nothing" not definedzéýÿÿÿ)rrÚfailrrhÚexc_infoÚtb_nextÚappendrÚstrÚtb_frameÚf_codeÚco_nameÚ co_filenameÚ tb_lineno)rrÚeÚexc_typeÚ exc_valueÚ exc_tracebackÚframeÚframesrrrÚtest_error_access_undefined¹s0ÿ  þ ÿ ÿ €ôz.ExpressionTestCase.test_error_access_undefinedc CóÜGdd„dtƒ}tddddd}z| d|ƒi¡| d ¡WdStym}zA| d t|ƒ¡t ¡\}}}d }|j }|j rO|j }|j j } | j |krLn|j s?| d ¡| d| j ¡| d|j¡WYd}~dSd}~ww) Nc@rÄ)zBExpressionTestCase.test_error_getattr_undefined..SomethingcSrprárr'rrrrâÏr~zKExpressionTestCase.test_error_getattr_undefined..Something.__repr__NrãrrrrräÎrÏrärårÔrÕrür×rærýú% has no member named "nil"zú'never found the frame I was looking for©rérrrÿrrrrhrrrrrrr© rrärr r r r Ú search_stringr r rrrÚtest_error_getattr_undefinedÍó.ÿ ü €óz/ExpressionTestCase.test_error_getattr_undefinedc Cr) Nc@rÄ)zIExpressionTestCase.test_error_getitem_undefined_string..SomethingcSrprárr'rrrrâçr~zRExpressionTestCase.test_error_getitem_undefined_string..Something.__repr__NrãrrrrräærÏrärørÔrÕrür×rærýrzrrrrrrÚ#test_error_getitem_undefined_stringårz6ExpressionTestCase.test_error_getitem_undefined_stringcCó(tddid}| dtdƒ |¡¡dS)NÚsomeÚthing)Údictz dict['some']©rrrrrurrrÚ!test_getitem_with_constant_stringýóz4ExpressionTestCase.test_getitem_with_constant_stringcCsˆtddddddœd}| dtdƒ |¡¡| dtd ƒ |¡¡| dtd ƒ |¡¡| dtd ƒ |¡¡| dtd ƒ |¡¡dS) Nr$ÚbazÚquoxÚquoooxÚfoobar)Tg@Nr0sfoo©Úvaluesz values[True]z values[2.5]z values[42]zvalues[b"foo"]z values[None]rrurrrÚtest_getitem_with_simple_indexs ûz1ExpressionTestCase.test_getitem_with_simple_indexcCs>tgd¢d}| dtdƒ |¡¡| dtdƒ |¡¡dS)Nr=)rr>zitems[0]r?z items[-1]rrurrrÚtest_array_indicessz%ExpressionTestCase.test_array_indicescCsbGdd„dtƒ}|ƒddœ}| dtdƒ |¡¡| dtdƒ |¡¡| dtdƒ |¡¡dS) Nc@seZdZdZdS)zCExpressionTestCase.test_item_access_for_attributes..MyClassÚBarN)rËrÌrÍÚmyattrrrrrÚMyClasssr*r))Úminer9r(z mine.myattrzmine["myattr"]z mine[key])rérrr)rr*rvrrrÚtest_item_access_for_attributess  z2ExpressionTestCase.test_item_access_for_attributescCr)Nr%r$r$zvalues[str("foo")]rrurrrÚtest_function_in_item_accessrz/ExpressionTestCase.test_function_in_item_accessN)OrËrÌrÍrrr#r(r)r-r/r8r<r@rArCrGrHrJrNrRrVrWrXrYrZr[r]r^r_rarbrcrdrerfrjrkrlrmrnrorwr|r}r€r…r‡r—rŸr¡r¢r£r¤rhÚ version_infor§r©r°r³r¸r¹r»r¼rÀrÃrÒrßrër÷rùrûrrrrr&r'r,r-rrrrr sš        r c@sºeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z e s6dd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Zd7d8„Zd9d:„Z d;d<„Z!d=d>„Z"d?d@„Z#dAdB„Z$dCdD„Z%dEdF„Z&dGdH„Z'dIdJ„Z(dKdL„Z)dMdN„Z*dOdP„Z+dQdR„Z,e-j.dSkr³dTdU„Z/dVdW„Z0dXdY„Z1dZd[„Z2d\d]„Z3d^d_„Z4d`da„Z5dbdc„Z6ddde„Z7dfdg„Z8dhdi„Z9djS)kÚ SuiteTestCasecCsbtdƒ}tƒ}t ||d¡| d¡t |¡}i}| |¡| d|d¡|j|jks/J‚dS)Núfoo = 42rrr0r%) rr rrrrÚexecuterr )rÚsuiter!r"rvrrrr##s   zSuiteTestCase.test_picklecCs.tdƒ}ddi}| |¡| d|d¡dS)Nzdata = [] bar = foo r%r0r$©rr1r©rr2rvrrrÚtest_internal_shadowing.s z%SuiteTestCase.test_internal_shadowingcCó*tdƒ}i}| |¡| d|d¡dS)Nr0r0r%r3r4rrrÚ test_assign;s zSuiteTestCase.test_assigncCs8tdƒ}i}| |¡d|vsJ‚| d|dƒ¡dS)Nzdef donothing(): passÚ donothingr3r4rrrÚtest_defAs   zSuiteTestCase.test_defcCs<tdƒ}ddi}| |¡d|vsJ‚| d|dƒ¡dS)Nz2 def donothing(): if True: return foo r%r$r8r3r4rrrÚ!test_def_with_multiple_statementsHs   z/SuiteTestCase.test_def_with_multiple_statementscCó.tdƒ}i}| |¡| ddg|d¡dS)Nzl values = [] def add(value): if value not in values: values.append(value) add('foo') add('bar') r%r$r%r3r4rrrÚtest_def_using_nonlocalSó z%SuiteTestCase.test_def_using_nonlocalcCó:tdƒ}i}| |¡| d|d¡| d|d¡dS)NzY def difference(v1, v2=10): return v1 - v2 x = difference(20, 19) y = difference(20) r>rBé rMr3r4rrrÚtest_def_some_defaults`ó  z$SuiteTestCase.test_def_some_defaultscCsJtdƒ}i}| |¡| d|d¡| d|d¡| d|d¡dS)Nzn def difference(v1=100, v2=10): return v1 - v2 x = difference(20, 19) y = difference(20) z = difference() r>rBr?rMéZÚzr3r4rrrÚtest_def_all_defaultsls  z#SuiteTestCase.test_def_all_defaultscCr6)Nzj def mysum(*others): rv = 0 for n in others: rv = rv + n return rv x = mysum(1, 2, 3) rŒrBr3r4rrrÚtest_def_varargzs zSuiteTestCase.test_def_varargcCs2tdƒ}i}| |¡| ddgt|dƒ¡dS)Nz^ def smash(**kw): return [''.join(i) for i in kw.items()] x = smash(foo='abc', bar='def') ÚbardefÚfooabcrB)rr1rÚsortedr4rrrÚtest_def_kwargs‡s zSuiteTestCase.test_def_kwargscCr6)Nz8 def kwonly(*args, k): return k x = kwonly(k="foo") r%rBr3r4rrrÚtest_def_kwonlyarg’ó z SuiteTestCase.test_def_kwonlyargcCr>)NzK def kwonly(*args, k="bar"): return k x = kwonly(k="foo") y = kwonly() r%rBr$rMr3r4rrrÚtest_def_kwonlyarg_with_defaultœrAz-SuiteTestCase.test_def_kwonlyarg_with_defaultcCr;)Nz­ def doit(): values = [] def add(value): if value not in values: values.append(value) add('foo') add('bar') return values x = doit() r%r$rBr3r4rrrÚtest_def_nested¨s zSuiteTestCase.test_def_nestedcCr6)Nzl def lower(fun): return lambda: fun().lower() @lower def say_hi(): return 'Hi!' result = say_hi() zhi!Úresultr3r4rrrÚtest_def_with_decorator¸s z%SuiteTestCase.test_def_with_decoratorcCs&tdƒ}i}| |¡d|vsJ‚dS)Nzfoo = 42 del foo r%©rr1r4rrrÚ test_deleteÇs zSuiteTestCase.test_deletecCó&tdƒ}i}| |¡d|vsJ‚dS)Nzclass plain(object): passÚplainrPr4rrrÚ test_classÏó zSuiteTestCase.test_classcCs.tdƒ}i}| |¡| dt|dƒ¡dS)Nz def create(): class Foobar(object): def __str__(self): return 'foobar' return Foobar() x = create() r#rB)rr1rrr4rrrÚtest_class_in_defÕr=zSuiteTestCase.test_class_in_defcCrR)Nz7class plain(object): def donothing(): pass rSrPr4rrrÚtest_class_with_methodsâs z%SuiteTestCase.test_class_with_methodscCrR)Nzfrom itertools import repeatÚrepeatrPr4rrrÚ test_importërUzSuiteTestCase.test_importcCs(tdƒ}tƒ}| |¡d|vsJ‚dS)Nzfrom itertools import *rX)rrr1r4rrrÚtest_import_starñs zSuiteTestCase.test_import_starcCsBtdƒ}tƒ}| |¡d|vsJ‚| gd¢t|dƒƒ¡dS)NzDdef fun(): from itertools import repeat return repeat(1, 3) rX)r>r>r>Úfun)rrr1rrƒr4rrrÚtest_import_in_def÷s   z SuiteTestCase.test_import_in_defcCs.tdƒ}i}| |¡| gd¢|d¡dS)Nz-x = [] for i in range(3): x.append(i**2) )rr>rUrBr3r4rrrÚtest_fors zSuiteTestCase.test_forcCs8tdƒ}i}| |¡d|vsJ‚| d|dƒ¡dS)NzVdef loop(): for i in range(10): if i == 5: break return i Úloopr‚r3r4rrrÚtest_for_in_def s   zSuiteTestCase.test_for_in_defcCó.tdƒ}ddi}| |¡| d|d¡dS)Nzif foo == 42: x = True r%r0TrBr3r4rrrÚtest_ifs zSuiteTestCase.test_ifcCstdƒ}| t|ji¡dS)Nzraise NotImplementedError)rrõrïr1©rr2rrrÚ test_raiseszSuiteTestCase.test_raisecCó*tdƒ}i}| |¡| d|d¡dS)NzXtry: import somemod except ImportError: somemod = None else: somemod.dosth()Úsomemodr3r4rrrÚtest_try_except"s zSuiteTestCase.test_try_exceptcCrd)Nz%try: x = 2 finally: x = None rBr3r4rrrÚ test_finally-rKzSuiteTestCase.test_finallycCr`)Nz>x = 0 while x < 5: x += step if x == 4: break ÚsteprrUrBr3r4rrrÚtest_while_break7s zSuiteTestCase.test_while_breakcCó2tdƒ}ddi}| d|i¡| d|d¡dS)Nz d['k'] += 42Úkr>Údé+r3©rr2rlrrrÚ#test_augmented_attribute_assignmentBóz1SuiteTestCase.test_augmented_attribute_assignmentcCstdƒ i¡dS)Nzx = 1; x += 42; assert x == 43rPr'rrrÚtest_local_augmented_assignHsz)SuiteTestCase.test_local_augmented_assigncCó&i}tdƒ |¡| d|d¡dS)Nz6def foo(): i = 1 i += 1 return i x = foo()rrBr3©rrlrrrÚtest_augmented_assign_in_defKsz*SuiteTestCase.test_augmented_assign_in_defcCrr)NzQdef foo(): i = 0 for n in range(5): i += n return i x = foo()r?rBr3rsrrrÚ$test_augmented_assign_in_loop_in_defTsz2SuiteTestCase.test_augmented_assign_in_loop_in_defcCrj)Nz)[d['k']] = 'foo',; assert d['k'] == 'foo'rkr$rlr%r3rnrrrÚtest_assign_in_list^rpz!SuiteTestCase.test_assign_in_listcCstdƒ}| dddii¡dS)Nz&x = 1; exec(d['k']); assert x == 42, xrlrkzx = 42rPrbrrrÚ test_execdr*zSuiteTestCase.test_execcCstdƒ}| ddi¡dS)Nz) def f(): return v assert f() == 42 rÂr0rPrbrrrÚ test_returnhszSuiteTestCase.test_returncCs2tdƒ}dii}| |¡| d|dd¡dS)Nzd['k'] = 'foo'rlr%rkr3r4rrrÚtest_assign_to_dict_itemqs z&SuiteTestCase.test_assign_to_dict_itemcCsBGdd„dtƒ}|ƒ}tdƒ}d|i}| |¡| d|j¡dS)Nc@s eZdZdS)z9SuiteTestCase.test_assign_to_attribute..SomethingN)rËrÌrÍrrrrräxs räzobj.attr = 'foo'rÑr%)rérr1rÚattr)rrärær2rvrrrÚtest_assign_to_attributews  z&SuiteTestCase.test_assign_to_attributecCs<Gdd„dtƒ}|ƒ}tdƒ d|i¡| t|dƒ¡dS)Nc@rÄ)z-SuiteTestCase.test_delattr..SomethingcSrÅ)Nr%)rzr'rrrrÈrÉz6SuiteTestCase.test_delattr..Something.__init__NrÊrrrrrä€rÏräz del obj.attrrÑrz)rérr1Ú assertFalseÚhasattr)rrärÑrrrÚ test_delattrszSuiteTestCase.test_delattrcCs*ddi}tdƒ d|i¡| d|¡dS)Nrkr%z del d['k']rl)rr1Ú assertNotInrsrrrÚ test_delitem‡szSuiteTestCase.test_delitemc Cs~tƒ\}}t |d¡}z-| d¡| d¡| ¡d|i}tdƒ}| |¡| ddg|d¡Wt  |¡dSt  |¡w) NÚwzfoo bar rÚpathz{from __future__ import with_statement lines = [] with open(path) as file: for line in file: lines.append(line) úfoo zbar Úlines© rÚosÚfdopenÚwriterÚcloserr1rÚremove©rÚfdr‚r¾rlr2rrrÚtest_with_statementŒs     z!SuiteTestCase.test_with_statementcCs.i}tdƒ}| |¡| gd¢|d¡dS)Na  results = [] def counter(maximum): i = 0 while i < maximum: val = (yield i) if val is not None: i = val else: i += 1 it = counter(5) results.append(next(it)) results.append(it.send(3)) results.append(next(it)) )rr?rUÚresultsr3)rrlr2rrrÚtest_yield_expression s z#SuiteTestCase.test_yield_expression)r?r?c Cs~tƒ\}}t |d¡}z-| d¡| d¡| ¡d|i}tdƒ}| |¡| ddg|d¡Wt  |¡dSt  |¡w)Nrrƒrr‚zÄfrom __future__ import with_statement lines = [] with open(path) as file1, open(path) as file2: for line in file1: lines.append(line) for line in file2: lines.append(line) r„r…r‹rrrÚ'test_with_statement_with_multiple_itemsµs     z5SuiteTestCase.test_with_statement_with_multiple_itemscCs6tdƒ}dgd¢i}| |¡| ddg|d¡dS)Nzx = numbers[0:2]r‰rºrr>rBr3r4rrrr©Ëó  zSuiteTestCase.test_slicecCs:tdƒ}gd¢dddœ}| |¡| ddg|d¡dS)Nzx = numbers[start:end]rºrrrªr>rBr3r4rrrr°Ñs z"SuiteTestCase.test_slice_with_varscCs6tdƒ}dgd¢i}| |¡| gd¢|d¡dS)Nzx = numbers[:]r‰rºrBr3r4rrrr³×r‘zSuiteTestCase.test_slice_copycCó8tdƒ}gd¢ddœ}| |¡| gd¢|d¡dS)Nzx = numbers[::stride]r²rrµr·rBr3r4rrrr¸Ýó zSuiteTestCase.test_slice_stridecCs6tdƒ}gd¢ddœ}| |¡| dg|d¡dS)Nzx = numbers[-1:]r²rrµrUrBr3r4rrrr¹ãs z'SuiteTestCase.test_slice_negative_startcCr’)Nzx = numbers[:-1]r²rrµrºrBr3r4rrrr»ér“z%SuiteTestCase.test_slice_negative_endcCs2tdƒ}dgd¢i}| |¡| d|d¡dS)Nzx = numbers[1]r‰r²r>rBr3r4rrrr¼ïs  z!SuiteTestCase.test_slice_constantcCs<dd„}tdƒ}gd¢|dœ}| |¡| d|d¡dS)NcSrpr½rrrrrr¾ör~z(SuiteTestCase.test_slice_call..fzx = numbers[f()]r²r¿rrBr3)rr¾r2rvrrrrÀõs  zSuiteTestCase.test_slice_callcCs4tdƒ}gd¢ddœ}| |¡| d|d¡dS)Nzx = numbers[v]r²rrÁrBr3r4rrrrÃýs zSuiteTestCase.test_slice_namecCsDGdd„dƒ}tdƒ}gd¢|ƒdœ}| |¡| d|d¡dS)Nc@rÄ)z7SuiteTestCase.test_slice_attribute..ValueHoldercSrÅrÆrÇr'rrrrÈrÉz@SuiteTestCase.test_slice_attribute..ValueHolder.__init__NrÊrrrrrÎrÏrÎzx = numbers[obj.value]r²rÐr?rBr3)rrÎr2rvrrrrÒs  z"SuiteTestCase.test_slice_attributeN):rËrÌrÍr#r5r7r9r:r<r@rDrErIr rJrLrMrOrQrTrVrWrYrZr\r]r_rarcrfrgrirorqrtrurvrwrxryr{r~r€rrrhr.rr©r°r³r¸r¹r»r¼rÀrÃrÒrrrrr/!sn                      r/cCsBt ¡}| t tj¡¡| t td¡¡| t t d¡¡|S)NÚtest) ÚunittestÚ TestSuiteÚaddTestÚdoctestÚ DocTestSuiterrÌÚ makeSuiter r/)r2rrrr2 s r2Ú__main__)Ú defaultTest)r˜r†rrhÚtempfilerr•Ú genshi.corerÚgenshi.template.baserÚgenshi.template.evalrrrrr Ú genshi.compatr r r ÚTestCaser r/r2rËÚmainrrrrÚs.     oÿ