8889841có ÈÏ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}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|ƒ|jƒdS(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|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.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#eZd„Zd„Zd„ZRS(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,eZd„Zd„Zd„Zd„ZRS(cCsµtjdƒ}|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_streaming‘scCsmtjdƒ}|jdttdƒƒƒ}|jddƒ|jt|ƒdƒ|jt|ƒdƒdS(NsQR=itsizeiu (RRR>R?R@tenable_bufferingRAR(RRR>((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_buffered_streamingœs cCs6tjdƒ}|jƒ}|jdƒ|jƒdS(Nti(RRR>RDtdisable_buffering(RRR>((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✓(ttempfiletmkdtempRRR>tdumptostpathtjointopent assertEqualtreadtshutiltrmtree(RttmpRR>tf((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_dump_stream­s  ! (R0R1RBRERHRW(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyR<s  tUndefinedTestCasecBsPeZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z RS(cCs>d„}tdƒ}tdƒ}|jt|jd|ƒdS(NcSs tƒ‚dS(N(t StopIteration(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest¼ssA{{ test() }}BsA{{ test().missingattribute }}BRZ(R t assert_raisesRtrender(RRZR&((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_stopiteration_is_undefined»s   cCs)ytdƒjWntk r$nXdS(NtFoo(Rt__dict__tAttributeError(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*RFs{{ not missing }}(RRRARR\R[R(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( 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_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( 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_undefinedàs"cCs)tdƒ}|jt|jddƒdS(Ns{{ var[42].foo }}tvari(R R[RR\(RR&((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_indexing_gives_undefinedês cCs4ytƒjddƒƒWntk r/}nXdS(Ntsplit(RtgetattrRR(Rte((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_none_gives_proper_errorîs cCs4ytddddƒƒWntk r/}nXdS(Ntobji*R*tupper(RR(RRl((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyttest_object_reprös ( R0R1R]RaRdReRgRiRmRp(((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyRX¹s    cCshtjƒ}|jtjtƒƒ|jtjtƒƒ|jtjtƒƒ|jtjtƒƒ|S(N(tunittestt TestSuitetaddTestt makeSuiteR R2R<RX(tsuite((s8/usr/lib/python2.7/site-packages/jinja2/testsuite/api.pyRuÿs  (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