o
!b( @ s d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZm Z m
Z
mZ G dd dejZ
G dd dejZG dd d ejZG d
d dejZG dd
d
ejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZdd Zedkrejdd dS dS ) N)
IS_PYTHON2)
directivesMarkupTemplateTextTemplateTemplateRuntimeErrorTemplateSyntaxErrorc @ s( e Zd ZdZdd Zdd Zdd ZdS ) AttrsDirectiveTestCasez,Tests for the `py:attrs` template directive.c C s8 t d}ddiddig}| d|j|djdd dS ) zM
Verify that the directive has access to the loop variables.
zt
id z;
itemsNencodingr assertEqualgeneraterender)selftmplr
r B/usr/lib/python3/dist-packages/genshi/template/tests/directives.pytest_combined_with_loop s
z.AttrsDirectiveTestCase.test_combined_with_loopc C $ t d}| d| jdd dS )}
Verify that an attribute value that evaluates to `None` removes an
existing attribute of that name.
zu
z2
Nr r r r r r r test_update_existing_attr' z0AttrsDirectiveTestCase.test_update_existing_attrc C r )r zt
z&
Nr r r r r r test_remove_existing_attr3 r z0AttrsDirectiveTestCase.test_remove_existing_attrN)__name__
__module____qualname____doc__r r r r r r r r s
r c @ sx e Zd ZdZdd Zdd Zdd Zdd Zd
d Zdd
Z dd Z
dd Zdd Zdd Z
dd Zdd Zdd ZdS )ChooseDirectiveTestCasezoTests for the `py:choose` template directive and the complementary
directives `py:when` and `py:otherwise`.c C r )zd
Verify that, if multiple `py:when` bodies match, only the first is
output.
z
1
2
3
z-
1
Nr r r r r r test_multiple_true_whensD z0ChooseDirectiveTestCase.test_multiple_true_whensc C $ t d}| d| jd d d S )Nz
hidden
hello
z1
hello
r r r r r r test_otherwiseR z&ChooseDirectiveTestCase.test_otherwisec C r )z?
Verify that `py:choose` blocks can be nested:
z
zw
Nr r r r r r test_nesting[ z$ChooseDirectiveTestCase.test_nestingc C r )z.
Verify more complex nesting.
z
x
Nr r r r r r test_complex_nestingo r* z,ChooseDirectiveTestCase.test_complex_nestingc C r )z>
Verify more complex nesting using otherwise.
a
r+ Nr r r r r r test_complex_nesting_otherwise r* z6ChooseDirectiveTestCase.test_complex_nesting_otherwisec C r )zs
Verify that a when directive with a strip directive actually strips of
the outer element.
z
foo
z1
foo
Nr r r r r r test_when_with_strip r% z,ChooseDirectiveTestCase.test_when_with_stripc C t d}| tt| dS )zq
Verify that a `when` directive outside of a `choose` directive is
reported as an error.
zZ
Nr assertRaisesr strr r r r r test_when_outside_choose z0ChooseDirectiveTestCase.test_when_outside_choosec C r/ )zw
Verify that an `otherwise` directive outside of a `choose` directive is
reported as an error.
z]
Nr0 r r r r test_otherwise_outside_choose r4 z5ChooseDirectiveTestCase.test_otherwise_outside_choosec C r/ )zw
Verify that an `when` directive that doesn't have a `test` attribute
is reported as an error.
z
Nr0 r r r r test_when_without_test s z.ChooseDirectiveTestCase.test_when_without_testc C ( t d}| d|jddjdd dS )z
Verify that an `when` directive that doesn't have a `test` attribute
works as expected as long as the parent `choose` directive has a test
expression.
z
$
foo
YeahfooNr r r r r r ,test_when_without_test_but_with_choose_value s zDChooseDirectiveTestCase.test_when_without_test_but_with_choose_valuec C r )zf
Verify that an `otherwise` directive can be used without a `test`
attribute.
z
r8 Nr r r r r r test_otherwise_without_test r% z3ChooseDirectiveTestCase.test_otherwise_without_testc C r )K
Verify that the directive can also be used as an element.
z
1
2
3
z"
1
Nr r r r r r test_as_element s z'ChooseDirectiveTestCase.test_as_elementc C r )Q
Verify that the directive works as expected in a text template.
z#choose
#when 1 == 1
1
#end
#when 2 == 2
2
#end
#when 3 == 3
3
#end
#endz 1
Nr r r r r r r r r test_in_text_template s z-ChooseDirectiveTestCase.test_in_text_templateN)r r r! r" r$ r' r) r, r- r. r3 r5 r6 r<