o
    ¯bT  ã                   @   sj   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 de
de
def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ƒ| i |¤ŽS )z(
    Produce a new tag for testing.
    Úhello)r   )r	   r
   © r   ú</usr/lib/python3/dist-packages/twisted/web/test/test_stan.pyÚproto   s   r   c                   @   sˆ   e Zd ZdZddd„Zddd„Zddd	„Zdd
d„Zddd„Zddd„Z	ddd„Z
ddd„Zddd„Zddd„Zddd„Zddd„ZdS )ÚTagTestsz
    Tests for L{Tag}.
    r   Nc                 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.
        Ú
myRenderer©ÚrenderN)r   ÚassertEqualr   Ú
attributes©ÚselfÚtagr   r   r   Útest_renderAttribute   s   
zTagTests.test_renderAttributec                 C   sL   |   t¡�}tdd� W d  ƒ n1 sw   Y  |  |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   Nr   z0Value for "render" attribute must be str, got 83)Ú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©Úfooúfoo/baré   é   F)Údeepr   é   N©r   r#   ÚfilenameÚ
lineNumberÚcolumnNumberÚcloner   r   ÚassertNotIdenticalÚchildrenr"   ÚslotDatar   )r   Ú	innerListr   r6   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   r1   é   Nr2   )r   ÚinnerTagr:   r   r6   r   r   r   Útest_cloneDeepQ   s.   
ÿ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__r6   r   r   r   r   Útest_cloneGeneratorDeprecations   s   ùz'TagTests.test_cloneGeneratorDeprecationc                 C   sV   dt fdd„}|ƒ }td|dƒ}z|  tdtjtj j|j	¡ W | 
¡  dS | 
¡  w )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 ‚r@   )ÚNotImplementedErrorr   r   r   r   Ú	asyncFunc‹   s   €z:TagTests.test_cloneCoroutineDeprecation.<locals>.asyncFuncÚ123Ú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   rG   rH   rI   rJ   r   rK   rL   r6   Úclose)r   rO   Ú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 arer8   Úcoolzthis-attribute)ÚandSoIsrV   N)r   Úclearr   r8   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   ó   |   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±   ó   zTagTests.test_commentReprPy3c                 C   r]   )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   r^   r   r_   r   r   r   Útest_cdataReprPy3¸   ra   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   r^   r   )r   Úsnowmanr   r   r   Útest_charrefRepr¿   s   zTagTests.test_charrefRepr)r   N)Ú__name__rK   Ú__qualname__Ú__doc__r   r    r$   r;   r?   rM   rT   rX   r\   r`   rb   re   r   r   r   r   r      s    

	



"






r   )rh   rI   Útypingr   Útwisted.trial.unittestr   Útwisted.web.templater   r   r   r   r   r   r   r   r   r   r   Ú<module>   s   