%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/jinja2/testsuite/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib/python3.7/site-packages/jinja2/testsuite/__pycache__/api.cpython-37.pyc

B

��R�(�@s�dZddlZddlZddlZddlZddlmZddlmZddl	m
Z
mZmZm
Z
mZmZmZmZmZddlmZe
�ZGdd�de�ZGd	d
�d
e�ZGdd�de�ZGd
d�de�Zdd�ZdS)z�
    jinja2.testsuite.api
    ~~~~~~~~~~~~~~~~~~~~

    Tests the public API and related stuff.

    :copyright: (c) 2010 by the Jinja Team.
    :license: BSD, see LICENSE for more details.
�N)�
JinjaTestCase)�next)	�Environment�	Undefined�DebugUndefined�StrictUndefined�UndefinedError�meta�is_undefined�Template�
DictLoader)�Cyclerc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ExtendedAPITestCasecCs�ddlm}xzt�|�fD]j}|�d�}|jddid�dks@t�|�d�}|jddid�dksbt�|�d	�}|jddid�d
kst�qWdS)Nr)�SandboxedEnvironmentz{{ foo.items()|list }}�items�*)�fooz[('items', 42)]z{{ foo|attr("items")()|list }}z{{ foo["items"] }}Z42)Zjinja2.sandboxrr�from_string�render�AssertionError)�selfr�env�tmpl�r�E/opt/alt/python37/lib/python3.7/site-packages/jinja2/testsuite/api.py�test_item_and_attributes


z+ExtendedAPITestCase.test_item_and_attributecCsNdd�}t|d�}|�d�}|jdd�dks0t�|�d�}|��d	ksJt�dS)
NcSs|dkrd}|S)N�r)�valuerrr�finalize_none_empty*sz?ExtendedAPITestCase.test_finalizer.<locals>.finalize_none_empty)Zfinalizez,{% for item in seq %}|{{ item }}{% endfor %})N�r)�seqz||1|fooz<{{ none }}>z<>)rrrr)rrrrrrr�test_finalizer)s


z"ExtendedAPITestCase.test_finalizercCsld}t|�}x.||D]"}|j|ks(t�t|�|kst�qWt|�|jdksRt�|��|jdksht�dS)N)r��r"r)r
Zcurrentrr�reset)rr�c�itemrrr�test_cycler4szExtendedAPITestCase.test_cyclercCsft�d�}|�dkst�|dd�dks*t�tjddd�}t|��sFt�t�d�}|dd�dksbt�dS)Nrr)rF)Zundefined_to_nonez42 + foo�T)rZcompile_expressionrr
)r�exprZexpr2rrr�test_expressions?s

z$ExtendedAPITestCase.test_expressionscCsXtd�}t�|�|kst�t�|g�|ks.t�t�|g�|ksBt�t�|�|ksTt�dS)NZContent)rr�get_templaterZselect_templateZget_or_select_template)r�trrr�test_template_passthroughIs
z-ExtendedAPITestCase.test_template_passthroughcCs|dd�}t|tddd��d�}|�d�}|jdd�dks<t�|�d	�}|jdd�d
ksZt�|�d�}|jdd�dksxt�dS)NcSs|dksd|krdS|�d�S)N�.Fz.html)�endswith)�namerrr�select_autoescapeQszIExtendedAPITestCase.test_autoescape_autoselect.<locals>.select_autoescapez	{{ foo }})ztest.txtz	test.html)Z
autoescape�loaderztest.txtz<foo>)rz	test.htmlz&lt;foo&gt;)rrr+rrr)rr1rr,rrr�test_autoescape_autoselectPs


z.ExtendedAPITestCase.test_autoescape_autoselectN)	�__name__�
__module__�__qualname__rr!r'r*r-r3rrrrrs
rc@s$eZdZdd�Zdd�Zdd�ZdS)�MetaTestCasecCsTt�d�}t�|�}|tdg�ks&t�t�d�}t�|�}|tdddg�ksPt�dS)Nz!{% set foo = 42 %}{{ bar + foo }}Zbarz�{% set foo = 42 %}{{ bar + foo }}{% macro meh(x) %}{{ x }}{% endmacro %}{% for item in seq %}{{ muh(item) + meh(seq) }}{% endfor %}r Zmuh)r�parser	Zfind_undeclared_variables�setr)r�ast�xrrr�test_find_undeclared_variablesds



z+MetaTestCase.test_find_undeclared_variablescCstt�d�}t�|�}t|�dks$t�t|�dks4t�t|�gksDt�t�d�}t�|�}t|�ddddgkspt�dS)Nz/{% extends "layout.html" %}{% include helper %}zlayout.htmlzx{% extends "layout.html" %}{% from "test.html" import a, b as c %}{% import "meh.html" as meh %}{% include "muh.html" %}z	test.htmlzmeh.htmlzmuh.html)rr8r	�find_referenced_templatesrr�list)rr:�irrr� test_find_refererenced_templatesos



z-MetaTestCase.test_find_refererenced_templatescCs�t�d�}t�|�}t|�ddgks(t�t�d�}t�|�}t|�ddgksPt�t�d�}t�|�}t|�dddgkszt�t�d�}t�|�}t|�dddgks�t�dS)Nz&{% include ["foo.html", "bar.html"] %}zfoo.htmlzbar.htmlz&{% include ("foo.html", "bar.html") %}z+{% include ["foo.html", "bar.html", foo] %}z+{% include ("foo.html", "bar.html", foo) %})rr8r	r=r>r)rr:r?rrr�test_find_included_templates}s







z)MetaTestCase.test_find_included_templatesN)r4r5r6r<r@rArrrrr7bsr7c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�StreamingTestCasecCs�t�d�}|jttd��d�}|�t|�d�|�t|�d�|�t|�d�|�t|�d�|�t|�d�|�t|�d	�dS)
NzQ<ul>{% for item in seq %}<li>{{ loop.index }} - {{ item }}</li>{%- endfor %}</ul>�)r z<ul>z<li>1 - 0</li>z<li>2 - 1</li>z<li>3 - 2</li>z<li>4 - 3</li>z</ul>)rr�streamr>�range�assert_equalr)rrrDrrr�test_basic_streaming�s
z&StreamingTestCase.test_basic_streamingcCsNt�d�}|jttd��d�}|jdd�|�t|�d�|�t|�d�dS)NzQ<ul>{% for item in seq %}<li>{{ loop.index }} - {{ item }}</li>{%- endfor %}</ul>rC)r r#)�sizez <ul><li>1 - 0</li><li>2 - 1</li>z!<li>3 - 2</li><li>4 - 3</li></ul>)rrrDr>rE�enable_bufferingrFr)rrrDrrr�test_buffered_streaming�s

z)StreamingTestCase.test_buffered_streamingcCsFt�d�}|��}|jrt�|�d�|js0t�|��|jrBt�dS)Nr�)rrrDZbufferedrrIZdisable_buffering)rrrDrrr�test_streaming_behavior�s



z)StreamingTestCase.test_streaming_behaviorc	Csvt��}z\t�d�}|��}|�tj�|d�d�t	tj�|d�d��}|�
|��d�WdQRXWdt�
|�XdS)Nu✓zdump.txtzutf-8�rbs✓)�tempfileZmkdtemprrrD�dump�os�path�join�openZassertEqual�read�shutilZrmtree)rZtmprrD�frrr�test_dump_stream�s
z"StreamingTestCase.test_dump_streamN)r4r5r6rGrJrLrWrrrrrB�s	rBc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�UndefinedTestCasecCsBdd�}td�}|j|d�dks$t�td�}|jt|j|d�dS)NcSs
t��dS)N)�
StopIterationrrrr�test�sz?UndefinedTestCase.test_stopiteration_is_undefined.<locals>.testzA{{ test() }}B)rZZABzA{{ test().missingattribute }}B)rrr�
assert_raisesr)rrZr,rrr�test_stopiteration_is_undefined�s
z1UndefinedTestCase.test_stopiteration_is_undefinedcCs4ytd�jWntk
r"YnXds0td��dS)NZFooFzExpected actual attribute error)r�__dict__�AttributeErrorr)rrrr�%test_undefined_and_special_attributes�s
z7UndefinedTestCase.test_undefined_and_special_attributescCs�ttd�}|�|�d���d�|�t|�d�j�|�|�d���d�|�|�d���d�|�|�d	�jd
d�d�|�|�d���d�dS)
N)�	undefinedz
{{ missing }}rz{{ missing.attribute }}z{{ missing|list }}z[]z{{ missing is not defined }}�Truez{{ foo.missing }}r)rz{{ not missing }})rrrFrrr[r)rrrrr�test_default_undefined�s
z(UndefinedTestCase.test_default_undefinedcCs�ttd�}|�|�d���d�|�t|�d�j�|�|�d���d�|�|�d���d�|�|�d�jd	d
�d�|�|�d���d�dS)
N)r`z
{{ missing }}z{{ missing.attribute }}z{{ missing|list }}z[]z{{ missing is not defined }}raz{{ foo.missing }}r)rz,{{ no such element: int object['missing'] }}z{{ not missing }})rrrFrrr[r)rrrrr�test_debug_undefined�s
z&UndefinedTestCase.test_debug_undefinedcCs�ttd�}|�t|�d�j�|�t|�d�j�|�t|�d�j�|�|�d���d�|jt|�d�jdd	�|�t|�d
�j�|�|�d���d�dS)
N)r`z
{{ missing }}z{{ missing.attribute }}z{{ missing|list }}z{{ missing is not defined }}raz{{ foo.missing }}r)rz{{ not missing }}z&{{ missing|default("default", true) }}�default)rrr[rrrrF)rrrrr�test_strict_undefined�s
z'UndefinedTestCase.test_strict_undefinedcCstd�}|jt|jdd�dS)Nz{{ var[42].foo }}r)�var)rr[rr)rr,rrr�test_indexing_gives_undefined�sz/UndefinedTestCase.test_indexing_gives_undefinedc
CsVyt��dd��Wn0tk
rD}z|jdks4t�Wdd}~XYnXdsRtd��dS)N�splitz'None' has no attribute 'split'Fzexpected exception)r�getattrr�messager)r�errr�test_none_gives_proper_error�s
 z.UndefinedTestCase.test_none_gives_proper_errorc
CsTytddd��Wn0tk
rB}z|jdks2t�Wdd}~XYnXdsPtd��dS)Nr�upper)�objr0z%'int object' has no attribute 'upper'Fzexpected exception)rrrjr)rrkrrr�test_object_repr�s
 z"UndefinedTestCase.test_object_reprN)r4r5r6r\r_rbrcrergrlrorrrrrX�s

rXcCsLt��}|�t�t��|�t�t��|�t�t��|�t�t��|S)N)�unittestZ	TestSuiteZaddTestZ	makeSuiterr7rBrX)�suiterrrrq�srq)�__doc__rprPrNrUZjinja2.testsuiterZjinja2._compatrZjinja2rrrrrr	r
rrZjinja2.utilsr
rrr7rBrXrqrrrr�<module>
s,G-*F

Zerion Mini Shell 1.0