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   (