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(cCs^ddlm}xGt|fD]3}|jd}|jd}|jd}q#WdS(Ni(tSandboxedEnvironments{{ foo.items()|list }}s{{ foo|attr("items")()|list }}s{{ foo["items"] }}(tjinja2.sandboxR Rt from_string(tselfR tenvttmpl((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_item_and_attributes cCs:d}td|}|jd}|jd}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 %}s <{{ none }}>(RR(RRRR((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_finalizer)s  cCs?d}t|}x||D]}qWt||jdS(Niii(iii(R Rtreset(Rtitemstctitem((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyt test_cycler4s   cCs7tjd}tjddt}tjd}dS(Ntfootundefined_to_nones42 + foo(Rtcompile_expressiontFalse(Rtexprtexpr2((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_expressions?scCstd}dS(NtContent(R (Rtt((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_template_passthroughIs cCscd}td|dtidd6dd6}|jd}|jd}|jd}dS(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.html(RR t get_templateR(RR+RR&((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_autoescape_autoselectPs  (t__name__t __module__RRRR$R'R/(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyR s  t MetaTestCasecBs#eZdZdZdZRS(cCs@tjd}tj|}tjd}tj|}dS(Ns!{% set foo = 42 %}{{ bar + foo }}s{% set foo = 42 %}{{ bar + foo }}{% macro meh(x) %}{{ x }}{% endmacro %}{% for item in seq %}{{ muh(item) + meh(seq) }}{% endfor %}(RtparseRtfind_undeclared_variables(Rtasttx((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_find_undeclared_variablesds cCs@tjd}tj|}tjd}tj|}dS(Ns/{% extends "layout.html" %}{% include helper %}sx{% extends "layout.html" %}{% from "test.html" import a, b as c %}{% import "meh.html" as meh %}{% include "muh.html" %}(RR3Rtfind_referenced_templates(RR5ti((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyt test_find_refererenced_templatesos cCs|tjd}tj|}tjd}tj|}tjd}tj|}tjd}tj|}dS(Ns&{% include ["foo.html", "bar.html"] %}s&{% include ("foo.html", "bar.html") %}s+{% include ["foo.html", "bar.html", foo] %}s+{% include ("foo.html", "bar.html", foo) %}(RR3RR8(RR5R9((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_find_included_templates}s(R0R1R7R:R;(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyR2bs tStreamingTestCasecBs,eZdZdZdZdZRS(cCstjd}|jdttd}|jt|d|jt|d|jt|d|jt|d|jt|d|jt|d dS( NsQtseqis(RRtstreamtlisttranget assert_equalR(RRR>((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_basic_streamingscCsmtjd}|jdttd}|jdd|jt|d|jt|ddS(NsQR=itsizeiu (RRR>R?R@tenable_bufferingRAR(RRR>((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_buffered_streamings cCs6tjd}|j}|jd|jdS(Nti(RRR>RDtdisable_buffering(RRR>((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✓(ttempfiletmkdtempRRR>tdumptostpathtjointopent assertEqualtreadtshutiltrmtree(RttmpRR>tf((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_dump_streams  ! (R0R1RBRERHRW(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyR<s  tUndefinedTestCasecBsPeZdZdZdZdZdZdZdZdZ RS(cCs>d}td}td}|jt|jd|dS(NcSs tdS(N(t StopIteration(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttestssA{{ test() }}BsA{{ test().missingattribute }}BRZ(R t assert_raisesRtrender(RRZR&((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_stopiteration_is_undefineds   cCs)ytdjWntk r$nXdS(NtFoo(Rt__dict__tAttributeError(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*RFs{{ not missing }}(RRRARR\R[R(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( NRbs {{ missing }}s{{ missing.attribute }}s{{ missing|list }}s[]s{{ missing is not defined }}Rcs{{ foo.missing }}Ri*u,{{ no such element: int object['missing'] }}s{{ not missing }}(RRRARR\R[R(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( NRbs {{ missing }}s{{ missing.attribute }}s{{ missing|list }}s{{ missing is not defined }}Rcs{{ foo.missing }}Ri*s{{ not missing }}s&{{ missing|default("default", true) }}tdefault(RRR[RRR\RA(RR((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_strict_undefineds"cCs)td}|jt|jdddS(Ns{{ var[42].foo }}tvari(R R[RR\(RR&((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_indexing_gives_undefineds cCs4ytjddWntk r/}nXdS(Ntsplit(RtgetattrRR(Rte((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_none_gives_proper_errors cCs4ytddddWntk r/}nXdS(Ntobji*R*tupper(RR(RRl((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_object_reprs ( R0R1R]RaRdReRgRiRmRp(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyRXs    cCshtj}|jtjt|jtjt|jtjt|jtjt|S(N(tunittestt TestSuitetaddTestt makeSuiteR R2R<RX(tsuite((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyRus  (t__doc__RqRMRJRStjinja2.testsuiteRtjinja2._compatRtjinja2RRRRRRRR R t jinja2.utilsR RR R2R<RXRu(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyt s    @ G-*F