Rc@sdZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z m Z mZmZmZmZmZddlmZe ZdefdYZd efd YZd efd YZd efdYZdZdS(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. iN(t JinjaTestCase(tnext( t Environmentt UndefinedtDebugUndefinedtStrictUndefinedtUndefinedErrortmetat is_undefinedtTemplatet DictLoader(tCyclertExtendedAPITestCasecBs>eZdZdZdZdZdZdZRS(cCsddlm}xt|fD]}|jd}|jdidd6dks]t|jd}|jdidd6dkst|jd }|jdidd6d ks#tq#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}|jd ksltdS( 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  cCsd}t|}x?||D]3}|j|ks8tt||kstqWt||jdksst|j|jdkstdS(Niii(iii(R tcurrentRRtreset(RRtctitem((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyt test_cycler4s   cCstjd}|dks$t|dddks?ttjddt}t|sittjd}|dddkstdS(NRi*tundefined_to_nones42 + fooiT(Rtcompile_expressionRRtFalseR(Rtexprtexpr2((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_expressions?scCstd}tj||ks'ttj|g|ksEttj|g|kscttj||ks~tdS(NtContent(R Rt get_templateRtselect_templatetget_or_select_template(Rtt((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_template_passthroughIs  cCsd}td|dtidd6dd6}|jd}|jdddks_t|jd}|jddd kst|jd}|jdddkstdS( NcSs)|dksd|krtS|jdS(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#eZdZdZdZRS(cCs|tjd}tj|}|tdgks9ttjd}tj|}|tdddgksxtdS(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 cCstjd}tj|}t|dks6tt|dksNtt|gksfttjd}tj|}t|ddddgkstdS(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_templatesoscCstjd}tj|}t|ddgks<ttjd}tj|}t|ddgksxttjd}tj|}t|dddgksttjd}tj|}t|dddgkstdS(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,eZdZdZdZdZRS(cCstjd}|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_streamingscCsmtjd}|jdttd}|jdd|jt|d|jt|ddS(NsQRitsizeiu (RRRHRCRItenable_bufferingRJR(RRRH((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_buffered_streamings cCsetjd}|j}|j s+t|jd|jsGt|j|j satdS(Nti(RRRHtbufferedRRMtdisable_buffering(RRRH((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_streaming_behaviors   cCstj}z{tjd}|j}|jtjj|ddt tjj|dd}|j |j dWdQXWdt j |XdS(Nu✓sdump.txtsutf-8trbs✓(ttempfiletmkdtempRRRHtdumptostpathtjointopent assertEqualtreadtshutiltrmtree(RttmpRRHtf((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_dump_streams  ! (R7R8RKRNRRRa(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyRGs  tUndefinedTestCasecBsPeZdZdZdZdZdZdZdZdZ RS(cCs\d}td}|jd|dks3ttd}|jt|jd|dS(NcSs tdS(N(t StopIteration(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttestssA{{ test() }}BRdtABsA{{ test().missingattribute }}B(R RRt assert_raisesR(RRdR.((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_stopiteration_is_undefineds    cCs;ytdjWntk r$nXts7tddS(NtFoosExpected actual attribute error(Rt__dict__tAttributeErrorR&R(R((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyt%test_undefined_and_special_attributess  cCstdt}|j|jdjd|jt|jdj|j|jdjd|j|jdjd|j|jd jd d d |j|jd jddS(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_undefineds %cCstdt}|j|jdjd|jt|jdj|j|jdjd|j|jdjd|j|jdjd d d |j|jd jddS( 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_undefineds cCstdt}|jt|jdj|jt|jdj|jt|jdj|j|jdjd|jt|jdjdd |jt|jd j|j|jd jd 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_undefineds"cCs)td}|jt|jdddS(Ns{{ var[42].foo }}tvari(R RfRR(RR.((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_indexing_gives_undefineds cCs[ytjddWn(tk rD}|jdksWtnXtsWtddS(Ntsplits'None' has no attribute 'split'sexpected exception(RtgetattrRRtmessageRR&(Rte((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_none_gives_proper_errors cCs[ytddddWn(tk rD}|jdksWtnXtsWtddS(Ntobji*R2tuppers%'int object' has no attribute 'upper'sexpected exception(RRRvRR&(RRw((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_object_reprs ( R7R8RgRkRnRoRqRsRxR{(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyRbs    cCshtj}|jtjt|jtjt|jtjt|jtjt|S(N(tunittestt TestSuitetaddTestt makeSuiteR R9RGRb(tsuite((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyRs  (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