U
    T‚gT  ã                   @   sf   d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	m
Z
mZ e
e
edœdd„ZG d	d
„ d
eƒZdS )zW
Tests for L{twisted.web._stan} portion of the L{twisted.web.template}
implementation.
é    N)ÚNoReturn)ÚTestCase)ÚCDATAÚCharRefÚCommentÚFlattenableÚTag)ÚaÚkwÚreturnc                  O   s   t dƒ| |ŽS )z(
    Produce a new tag for testing.
    Úhello)r   )r	   r
   © r   ú>/tmp/pip-unpacked-wheel-1_7di8ic/twisted/web/test/test_stan.pyÚproto   s    r   c                   @   s¸   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„Zddœdd„Zddœdd„Z	ddœdd„Z
ddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd„ZdS )ÚTagTestsz
    Tests for L{Tag}.
    N©r   c                 C   s*   t dd�}|  |jd¡ |  |ji ¡ dS )zŠ
        Setting an attribute named C{render} will change the C{render} instance
        variable instead of adding an attribute.
        Z
myRenderer©ÚrenderN)r   ÚassertEqualr   Ú
attributes©ÚselfÚtagr   r   r   Útest_renderAttribute   s    
zTagTests.test_renderAttributec              	   C   s8   |   t¡�}tdd� W 5 Q R X |  |jjd d¡ dS )z‚
        Attempting to set an attribute named C{render} to something other than
        a string will raise L{TypeError}.
        éS   r   r   z0Value for "render" attribute must be str, got 83N)ÚassertRaisesÚ	TypeErrorr   r   Ú	exceptionÚargs)r   Úer   r   r   Útest_renderAttributeNonString&   s    
 ÿz&TagTests.test_renderAttributeNonStringc                 C   s   t ƒ }|  ||jdd�¡ dS )z0
        L{Tag.fillSlots} returns self.
        Útest)r!   N)r   ÚassertIdenticalÚ	fillSlotsr   r   r   r   Útest_fillSlots1   s    zTagTests.test_fillSlotsc                 C   sò   dg}t d|ddd�}|jdd� d|_d	|_d
|_|jdd�}|  |jd d¡ |  |j|j¡ |  |j	d|g¡ |  |j	|j	¡ |  
|j	d |¡ |  |j|j¡ |  |j|j¡ |  |jd¡ |  |jd	¡ |  |jd
¡ |  |jd¡ dS )z´
        L{Tag.clone} copies all attributes and children of a tag, including its
        render attribute.  If the shallow flag is C{False}, that's where it
        stops.
        ú
inner listúHow are youÚworldÚaSampleMethod©r   r   Úbar©Zfooúfoo/baré   é   F)Údeepr   é   N©r   r#   ÚfilenameZ
lineNumberZcolumnNumberÚcloner   r   ZassertNotIdenticalÚchildrenr"   ZslotDatar   )r   Ú	innerListr   r3   r   r   r   Útest_cloneShallow8   s$    zTagTests.test_cloneShallowc                 C   s  t dƒ}dg}t d||ddd�}|jdd� d	|_d
|_d|_| ¡ }|  |jd d¡ |  |j|j¡ |  |j	|j	¡ |  
|j	d |¡ |  |j	d |¡ |  
|j	d |¡ |  |j	d |¡ |  |j|j¡ |  |j|j¡ |  |jd	¡ |  |jd
¡ |  |jd¡ |  |jd¡ dS )zø
        L{Tag.clone} copies all attributes and children of a tag, including its
        render attribute.  In its normal operating mode (where the deep flag is
        C{True}, as is the default), it will clone all sub-lists and sub-tags.
        Úinnerr%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r   r0   é   Nr1   )r   ZinnerTagr5   r   r3   r   r   r   Útest_cloneDeepQ   s6        ÿzTagTests.test_cloneDeepc                 C   s6   t dd„ tdƒD ƒƒ}|  tdtjtj j|j	¡ dS )zì
        Cloning a tag containing a generator is unsafe. To avoid breaking
        programs that only flatten the clone or only flatten the original,
        we deprecate old behavior rather than making it an error immediately.
        c                 s   s   | ]}t |ƒV  qd S ©N)Ústr)Ú.0Únr   r   r   Ú	<genexpr>y   s     z:TagTests.test_cloneGeneratorDeprecation.<locals>.<genexpr>é
   z´Cloning a Tag which contains a generator is unsafe, since the generator can be consumed only once; this is deprecated since Twisted 21.7.0 and will raise an exception in the futureN)
r   ÚrangeÚassertWarnsÚDeprecationWarningÚsysÚmodulesr   Ú
__module__Ú__file__r3   r   r   r   r   Útest_cloneGeneratorDeprecations   s    ùz'TagTests.test_cloneGeneratorDeprecationc                 C   sP   t dœdd„}|ƒ }td|dƒ}z |  tdtjtj j	|j
¡ W 5 | ¡  X dS )zì
        Cloning a tag containing a coroutine is unsafe. To avoid breaking
        programs that only flatten the clone or only flatten the original,
        we deprecate old behavior rather than making it an error immediately.
        r   c                   Ó   s   t ‚d S r:   )ÚNotImplementedErrorr   r   r   r   Ú	asyncFunc‹   s    z:TagTests.test_cloneCoroutineDeprecation.<locals>.asyncFuncZ123Z789z¬Cloning a Tag which contains a coroutine is unsafe, since the coroutine can run only once; this is deprecated since Twisted 21.7.0 and will raise an exception in the futureN)r   r   ÚcloserA   rB   rC   rD   r   rE   rF   r3   )r   rI   Úcoror   r   r   r   Útest_cloneCoroutineDeprecation„   s    ù
z'TagTests.test_cloneCoroutineDeprecationc                 C   s<   t ddddd�}| ¡  |  |jg ¡ |  |jddi¡ dS )zk
        L{Tag.clear} removes all children from a tag, but leaves its attributes
        in place.
        z	these arer4   Zcoolzthis-attribute)ÚandSoIsrM   N)r   Úclearr   r4   r   r   r   r   r   Ú
test_clear�   s    zTagTests.test_clearc                 C   s.   t dƒ}|ƒ }|dd� |  |jddi¡ dS )z‰
        L{Tag.__call__} accepts Python keywords with a suffixed underscore as
        the DOM attribute of that literal suffix.
        Údivr	   )Úclass_ÚclassN)r   r   r   )r   r   r   r   r   r   Útest_suffix§   s    
zTagTests.test_suffixc                 C   s   |   ttdƒƒd¡ dS )zo
        L{Comment.__repr__} returns a value which makes it easy to see what's
        in the comment.
        zhello therezComment('hello there')N)r   Úreprr   ©r   r   r   r   Útest_commentReprPy3±   s    zTagTests.test_commentReprPy3c                 C   s   |   ttdƒƒd¡ dS )zm
        L{CDATA.__repr__} returns a value which makes it easy to see what's in
        the comment.
        z	test datazCDATA('test data')N)r   rT   r   rU   r   r   r   Útest_cdataReprPy3¸   s    zTagTests.test_cdataReprPy3c                 C   s    t dƒ}|  tt|ƒƒd¡ dS )zw
        L{CharRef.__repr__} returns a value which makes it easy to see what
        character is referred to.
        u   â˜ƒzCharRef(9731)N)Úordr   rT   r   )r   Zsnowmanr   r   r   Útest_charrefRepr¿   s    zTagTests.test_charrefRepr)Ú__name__rE   Ú__qualname__Ú__doc__r   r    r$   r6   r9   rG   rL   rO   rS   rV   rW   rY   r   r   r   r   r      s   	"

r   )r\   rC   Útypingr   Ztwisted.trial.unittestr   Ztwisted.web.templater   r   r   r   r   r   r   r   r   r   r   Ú<module>   s   