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>
   zCloning 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789zCloning 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   