o
    ¯bf  ã                   @   sˆ   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ d	d
„ ZG dd„ deƒZdd„ Zg d¢ZdS )z0
General helpers for L{twisted.web} unit tests.
é    )ÚType)ÚDeferredÚsucceed)ÚSynchronousTestCase)Úserver)ÚflattenString)ÚFlattenerError)ÚFlattenablec                 C   s\   |   |¡}t|tƒr| |¡ | ¡  td ƒS |tju r'|jr#td ƒS | 	¡ S t
d|›�ƒ‚)NzUnexpected return value: )ÚrenderÚ
isinstanceÚbytesÚwriteÚfinishr   r   ÚNOT_DONE_YETÚfinishedÚnotifyFinishÚ
ValueError)ÚresourceÚrequestÚresult© r   ú8/usr/lib/python3/dist-packages/twisted/web/test/_util.pyÚ_render   s   



r   c                   @   sZ   e Zd ZdZdededee fdd„Zdededefdd„Zded	e	e
 dd
fdd„Zd
S )ÚFlattenTestCasezH
    A test case that assists with testing L{twisted.web._flatten}.
    ÚrootÚtargetÚreturnc                    s0   dt dt f‡ ‡fdd„}td|ƒ}| |¡ |S )zS
        Assert that a root element, when flattened, is equal to a string.
        r   r   c                    s   ˆ   | ˆ¡S )N)ÚassertEqual)r   ©Úselfr   r   r   Úcheck,   s   z/FlattenTestCase.assertFlattensTo.<locals>.checkN)r   r   ÚaddCallback)r   r   r   r    Údr   r   r   ÚassertFlattensTo'   s   

z FlattenTestCase.assertFlattensToc                 C   s   |   |  ||¡¡S )aÖ  
        Assert that a root element, when flattened, is equal to a string, and
        performs no asynchronus Deferred anything.

        This version is more convenient in tests which wish to make multiple
        assertions about flattening, since it can be called multiple times
        without having to add multiple callbacks.

        @return: the result of rendering L{root}, which should be equivalent to
            L{target}.
        @rtype: L{bytes}
        )ÚsuccessResultOfr#   )r   r   r   r   r   r   ÚassertFlattensImmediately3   s   z)FlattenTestCase.assertFlattensImmediatelyÚexnNc                 C   s(   |   |  |d¡t¡}|  |jj|¡ dS )zQ
        Assert flattening a root element raises a particular exception.
        ó    N)ÚfailureResultOfr#   r   ÚassertIsInstanceÚvalueÚ
_exception)r   r   r&   Úfailurer   r   r   ÚassertFlatteningRaisesB   s   z&FlattenTestCase.assertFlatteningRaises)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r#   r%   r   Ú	Exceptionr-   r   r   r   r   r   "   s
    r   c                 C   s   |   | ¡ t¡ dS )zõ
    Assert that C{fileObj} is a temporary file on the filesystem.

    @param case: A C{TestCase} instance to use to make the assertion.

    @raise: C{case.failureException} if C{fileObj} is not a temporary file on
        the filesystem.
    N)r)   ÚfilenoÚint)ÚcaseÚfileObjr   r   r   ÚassertIsFilesystemTemporaryJ   s   r7   )r   r   r7   N)r1   Útypingr   Útwisted.internet.deferr   r   Útwisted.trial.unittestr   Útwisted.webr   Útwisted.web._flattenr   Útwisted.web.errorr   Útwisted.web.templater	   r   r   r7   Ú__all__r   r   r   r   Ú<module>   s   (