ó ÈÏRc@sdZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z m Z mZmZmZmZmZddlmZe ƒZdefd„ƒYZd efd „ƒYZd efd „ƒYZd efd„ƒYZd„ZdS(s¾ jinja2.testsuite.api ~~~~~~~~~~~~~~~~~~~~ Tests the public API and related stuff. :copyright: (c) 2010 by the Jinja Team. :license: BSD, see LICENSE for more details. iÿÿÿÿN(t JinjaTestCase(tnext( t Environmentt UndefinedtDebugUndefinedtStrictUndefinedtUndefinedErrortmetat is_undefinedtTemplatet DictLoader(tCyclertExtendedAPITestCasecBs>eZd„Zd„Zd„Zd„Zd„Zd„ZRS(cCsÍddlm}x¶tƒ|ƒfD]¢}|jdƒ}|jdidd6ƒdks]t‚|jdƒ}|jdidd6ƒdks‘t‚|jd ƒ}|jdidd6ƒd ks#t‚q#WdS( Niÿÿÿÿ(tSandboxedEnvironments{{ foo.items()|list }}tfooi*titemss[('items', 42)]s{{ foo|attr("items")()|list }}s{{ foo["items"] }}t42(tjinja2.sandboxR Rt from_stringtrendertAssertionError(tselfR tenvttmpl((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_item_and_attributes%%cCspd„}td|ƒ}|jdƒ}|jdd ƒdksEt‚|jdƒ}|jƒd kslt‚dS( NcSs|dkrd}n|S(Nu(tNone(tvalue((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pytfinalize_none_empty*s  tfinalizes,{% for item in seq %}|{{ item }}{% endfor %}tseqiRs||1|foos <{{ none }}>s<>(Nisfoo(RRRRR(RRRR((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_finalizer)s  cCs–d}t|Œ}x?||D]3}|j|ks8t‚t|ƒ|kst‚qWt|ƒ|jdksst‚|jƒ|jdks’t‚dS(Niii(iii(R tcurrentRRtreset(RRtctitem((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyt test_cycler4s   cCs—tjdƒ}|ƒdks$t‚|ddƒdks?t‚tjddtƒ}t|ƒƒsit‚tjdƒ}|ddƒdks“t‚dS(NRi*tundefined_to_nones42 + fooiT(Rtcompile_expressionRRtFalseR(Rtexprtexpr2((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_expressions?scCs‚tdƒ}tj|ƒ|ks't‚tj|gƒ|ksEt‚tj|gƒ|ksct‚tj|ƒ|ks~t‚dS(NtContent(R Rt get_templateRtselect_templatetget_or_select_template(Rtt((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_template_passthroughIs  cCs½d„}td|dtidd6dd6ƒƒ}|jdƒ}|jddƒdks_t‚|jdƒ}|jddƒd ksŒt‚|jdƒ}|jddƒdks¹t‚dS( NcSs)|dksd|krtS|jdƒS(Nt.s.html(RR&tendswith(tname((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pytselect_autoescapeQst autoescapetloaders {{ foo }}stest.txts test.htmlRss <foo>(RR R+RRR(RR3RR.((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_autoescape_autoselectPs  (t__name__t __module__RRR#R)R/R6(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyR s  t MetaTestCasecBs#eZd„Zd„Zd„ZRS(cCs|tjdƒ}tj|ƒ}|tdgƒks9t‚tjdƒ}tj|ƒ}|tdddgƒksxt‚dS(Ns!{% set foo = 42 %}{{ bar + foo }}tbarsƒ{% set foo = 42 %}{{ bar + foo }}{% macro meh(x) %}{{ x }}{% endmacro %}{% for item in seq %}{{ muh(item) + meh(seq) }}{% endfor %}Rtmuh(RtparseRtfind_undeclared_variablestsetR(Rtasttx((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_find_undeclared_variablesds cCs¬tjdƒ}tj|ƒ}t|ƒdks6t‚t|ƒdksNt‚t|ƒgksft‚tjdƒ}tj|ƒ}t|ƒddddgks¨t‚dS(Ns/{% extends "layout.html" %}{% include helper %}s layout.htmlsx{% extends "layout.html" %}{% from "test.html" import a, b as c %}{% import "meh.html" as meh %}{% include "muh.html" %}s test.htmlsmeh.htmlsmuh.html(RR<Rtfind_referenced_templatesRRRtlist(RR?ti((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyt test_find_refererenced_templatesoscCsútjdƒ}tj|ƒ}t|ƒddgks<t‚tjdƒ}tj|ƒ}t|ƒddgksxt‚tjdƒ}tj|ƒ}t|ƒdddgks·t‚tjdƒ}tj|ƒ}t|ƒdddgksöt‚dS(Ns&{% include ["foo.html", "bar.html"] %}sfoo.htmlsbar.htmls&{% include ("foo.html", "bar.html") %}s+{% include ["foo.html", "bar.html", foo] %}s+{% include ("foo.html", "bar.html", foo) %}(RR<RRBRCRR(RR?RD((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_find_included_templates}s!(R7R8RARERF(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyR9bs tStreamingTestCasecBs,eZd„Zd„Zd„Zd„ZRS(cCsµtjdƒ}|jdttdƒƒƒ}|jt|ƒdƒ|jt|ƒdƒ|jt|ƒdƒ|jt|ƒdƒ|jt|ƒdƒ|jt|ƒd ƒdS( NsQRis(RRtstreamRCtranget assert_equalR(RRRH((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_basic_streaming‘scCsmtjdƒ}|jdttdƒƒƒ}|jddƒ|jt|ƒdƒ|jt|ƒdƒdS(NsQRitsizeiu (RRRHRCRItenable_bufferingRJR(RRRH((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_buffered_streamingœs cCsetjdƒ}|jƒ}|j s+t‚|jdƒ|jsGt‚|jƒ|j sat‚dS(Nti(RRRHtbufferedRRMtdisable_buffering(RRRH((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_streaming_behavior¤s   cCsœtjƒ}z{tjdƒ}|jƒ}|jtjj|dƒdƒt tjj|dƒdƒ}|j |j ƒdƒWdQXWdt j |ƒXdS(Nu✓sdump.txtsutf-8trbs✓(ttempfiletmkdtempRRRHtdumptostpathtjointopent assertEqualtreadtshutiltrmtree(RttmpRRHtf((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_dump_stream­s  ! (R7R8RKRNRRRa(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyRGs  tUndefinedTestCasecBsPeZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z RS(cCs\d„}tdƒ}|jd|ƒdks3t‚tdƒ}|jt|jd|ƒdS(NcSs tƒ‚dS(N(t StopIteration(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest¼ssA{{ test() }}BRdtABsA{{ test().missingattribute }}B(R RRt assert_raisesR(RRdR.((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_stopiteration_is_undefined»s    cCs;ytdƒjWntk r$nXts7tdƒ‚dS(NtFoosExpected actual attribute error(Rt__dict__tAttributeErrorR&R(R((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyt%test_undefined_and_special_attributesÃs  cCsÐtdtƒ}|j|jdƒjƒdƒ|jt|jdƒjƒ|j|jdƒjƒdƒ|j|jdƒjƒdƒ|j|jd ƒjd d ƒd ƒ|j|jd ƒjƒdƒdS(Nt undefineds {{ missing }}us{{ missing.attribute }}s{{ missing|list }}s[]s{{ missing is not defined }}tTrues{{ foo.missing }}Ri*ROs{{ not missing }}(RRRJRRRfR(RR((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_default_undefinedËs %cCsÐtdtƒ}|j|jdƒjƒdƒ|jt|jdƒjƒ|j|jdƒjƒdƒ|j|jdƒjƒdƒ|j|jdƒjd d ƒd ƒ|j|jd ƒjƒdƒdS( NRls {{ missing }}s{{ missing.attribute }}s{{ missing|list }}s[]s{{ missing is not defined }}Rms{{ foo.missing }}Ri*u,{{ no such element: int object['missing'] }}s{{ not missing }}(RRRJRRRfR(RR((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_debug_undefinedÕs cCsãtdtƒ}|jt|jdƒjƒ|jt|jdƒjƒ|jt|jdƒjƒ|j|jdƒjƒdƒ|jt|jdƒjdd ƒ|jt|jd ƒjƒ|j|jd ƒjƒd ƒdS( NRls {{ missing }}s{{ missing.attribute }}s{{ missing|list }}s{{ missing is not defined }}Rms{{ foo.missing }}Ri*s{{ not missing }}s&{{ missing|default("default", true) }}tdefault(RRRfRRRRJ(RR((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_strict_undefinedàs"cCs)tdƒ}|jt|jddƒdS(Ns{{ var[42].foo }}tvari(R RfRR(RR.((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_indexing_gives_undefinedês cCs[ytƒjddƒƒWn(tk rD}|jdksWt‚nXtsWtdƒ‚dS(Ntsplits'None' has no attribute 'split'sexpected exception(RtgetattrRRtmessageRR&(Rte((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_none_gives_proper_errorîs cCs[ytddddƒƒWn(tk rD}|jdksWt‚nXtsWtdƒ‚dS(Ntobji*R2tuppers%'int object' has no attribute 'upper'sexpected exception(RRRvRR&(RRw((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_object_reprös ( R7R8RgRkRnRoRqRsRxR{(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyRb¹s    cCshtjƒ}|jtjtƒƒ|jtjtƒƒ|jtjtƒƒ|jtjtƒƒ|S(N(tunittestt TestSuitetaddTestt makeSuiteR R9RGRb(tsuite((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyR€ÿs  (t__doc__R|RWRTR]tjinja2.testsuiteRtjinja2._compatRtjinja2RRRRRRRR R t jinja2.utilsR RR R9RGRbR€(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyt s    @ G-*F