CasperSecurity

Current Path : /lib/python3/dist-packages/twisted/trial/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/twisted/trial/__pycache__/_asynctest.cpython-310.pyc

o

�b@7�@s�UdZddlZddlZddlmZddlmZddlmZm	Z	ddl
mZddlm
Z
mZddlmZmZmZgZeded	<ee
j�Gd
d�de��ZdS)zP
Things likely to be used by writers of unit tests.

Maintainer: Jonathan Lange
�N)�List)�implementer)�defer�utils)�failure)�itrial�util)�FailTest�SkipTest�SynchronousTestCase�_wait_is_runningcs�eZdZdZd/�fdd�	Zdd�ZeZdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zejdd��Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Z�fd'd(�Zd)d*�Zd+d,�Zefd-d.�Z�ZS)0�TestCasea=
    A unit test. The atom of the unit testing universe.

    This class extends L{SynchronousTestCase} which extends C{unittest.TestCase}
    from the standard library. The main feature is the ability to return
    C{Deferred}s from tests and fixture methods and to have the suite wait for
    those C{Deferred}s to fire.  Also provides new assertions such as
    L{assertFailure}.

    @ivar timeout: A real number of seconds. If set, the test will
    raise an error if it takes longer than C{timeout} seconds.
    If not set, util.DEFAULT_TIMEOUT_DURATION is used.
    �runTestcst��|�dS)a�
        Construct an asynchronous test case for C{methodName}.

        @param methodName: The name of a method on C{self}. This method should
        be a unit test. That is, it should be a short method that calls some of
        the assert* methods. If C{methodName} is unspecified,
        L{SynchronousTestCase.runTest} will be used as the test method. This is
        mostly useful for testing Trial.
        N)�super�__init__)�self�
methodName��	__class__��:/usr/lib/python3/dist-packages/twisted/trial/_asynctest.pyr-s
zTestCase.__init__cs&�fdd�}��fdd�}|�||�S)z�
        Fail if C{deferred} does not errback with one of C{expectedFailures}.
        Returns the original Deferred with callbacks added. You will need
        to return this Deferred from your test case.
        cs��d|����)Nz$did not catch an error, instead got )�failureException)�ignore�rrr�_cb@s�z#TestCase.assertFailure.<locals>._cbcs*|j��r|jSd��t|��}��|��)Nz
Expected: {!r}
Got:
{})�check�value�format�strr)r�output��expectedFailuresrrr�_ebEs
�
z#TestCase.assertFailure.<locals>._eb)�addCallbacks)r�deferredr!rr"rr r�
assertFailure9s	zTestCase.assertFailurecs�ddlm����������fdd�}t�|tjtd��}t���}t	�
|�r4td�|��}t
�|�St
�tj���|�}���||��|��fdd��|S)	Nr��reactorcs�t���d��d��d��}t�|�}z|�|�WdStjyJ���d�_���}|durA|�	|�rA��
�||�YdS���|�YdSw)Nz (z) still running at z secsT)r�TimeoutErrorr�Failure�errback�AlreadyCalledError�crash�	_timedOut�getTodo�expected�addExpectedFailure�addError)�d�e�f�todo)rr'�resultr�timeoutrr�	onTimeoutWs�
�z TestCase._run.<locals>.onTimeout��categoryz9{!r} is a generator function and therefore will never runcs���r���p	|S�N)�active�cancel)�x)�callrr�<lambda>|szTestCase._run.<locals>.<lambda>)�twisted.internetr'�
getTimeoutr�suppressWarningsr�suppress�DeprecationWarning�getattr�inspect�isgeneratorfunction�	TypeErrorrr�fail�
maybeDeferred�runWithWarningsSuppressed�_getSuppress�	callLater�addBoth)rrr6r8�method�excr2r)r?rr'r6rr7r�_runRs(�

��
�z
TestCase._runcOs|j|i|��Sr;)�run)r�args�kwargsrrr�__call__szTestCase.__call__cCs*|�d|�}|j|j|j|f|fd�|S)N�setUp��callbackArgs�errbackArgs)rRr#�deferTestMethod�
_ebDeferSetUp�r�ignoredr6r2rrr�
deferSetUp�s�zTestCase.deferSetUpcCsN|�t�r|�||�|j|j��n|�||�|�t�r!|��|�	d|�Sr;)
rr
�addSkip�_getSkipReasonrWrr1�KeyboardInterrupt�stop�deferRunCleanups�rrr6rrrr\�s

zTestCase._ebDeferSetUpcCsH|�|j|�}|j|j|j|f|fd�|�|j|�|�|j|�|S)NrX)rR�_testMethodNamer#�_cbDeferTestMethod�_ebDeferTestMethodrOrd�
deferTearDownr]rrrr[�s�zTestCase.deferTestMethodcCs*|��dur|�||���|Sd|_|S)NT)r.�addUnexpectedSuccess�_passed)rr^r6rrrrg�s
�zTestCase._cbDeferTestMethodcCs�|��}|dur|�|�r|�|||�dS|�|jt�r%|�||�dS|�t�r6|�||�|�	�dS|�t
�rL|�||�t
||j�|j��dS|�||�dSr;)r.r/r0rrr	�
addFailurerbr1rcr
r`rarFrfr)rr4r6r5rrrrh�s

�zTestCase._ebDeferTestMethodcCs|�d|�}|�|j|�|S)N�tearDown)rR�
addErrback�_ebDeferTearDownr]rrrri�szTestCase.deferTearDowncCs(|�||�|�t�r|��d|_dS�NF)r1rrbrcrkrerrrro�s

zTestCase._ebDeferTearDownc	csv�g}|jddd�D]\}}}z
||i|��VWqty*|�t���Yqw|D]}|�||�d|_q-dS)zf
        Run any scheduled cleanups and report errors (if any) to the result.
        object.
        N���F)�	_cleanups�	Exception�appendrr)r1rk)rr^r6�failures�funcrTrUr4rrrrd�s���zTestCase.deferRunCleanupscCs�zt�||���}|sd|_Wnty#|�|t���d|_Ynw|j�	�D]}|�||�d|_q)|�
�|��|jrG|�|�dSdSrp)
r�_Janitor�postCaseCleanuprk�
BaseExceptionr1rr)�	_observer�	getErrors�flushLoggedErrors�_removeObserver�
addSuccess)rr6�clean�errorrrr�_cleanUp�s"�
��zTestCase._cleanUpcCs<zt�||���WdSty|�|t���YdSwr;)rrw�postClassCleanupryr1rr))rr6rrr�
_classCleanUp�s
�zTestCase._classCleanUpcs��fdd�}|S)z�
        Create a method which wraps the reactor method C{name}. The new
        method issues a deprecation warning and calls the original.
        cs,tjd��fdtd��j�|i|��S)Nz{reactor.%s cannot be used inside unit tests. In the future, using %s will fail the test and may crash or hang the test run.�)�
stacklevelr:)�warnings�warnrE�_reactorMethods)�a�kw��namerrr�_�s��z&TestCase._makeReactorMethod.<locals>._r)rr�r�rr�r�_makeReactorMethod�s
zTestCase._makeReactorMethodcCs6i|_dD]}t||�|j|<t|||�|��qdS)z�
        Deprecate C{iterate}, C{crash} and C{stop} on C{reactor}. That is,
        each method is wrapped in a function that issues a deprecation
        warning, then calls the original.

        @param reactor: The Twisted reactor.
        )r,�iteratercN)r�rF�setattrr�)rr'r�rrr�_deprecateReactor�s
�zTestCase._deprecateReactorcCs*|j��D]
\}}t|||�qi|_dS)z�
        Restore the deprecated reactor methods. Undoes what
        L{_deprecateReactor} did.

        @param reactor: The Twisted reactor.
        N)r��itemsr�)rr'r�rPrrr�_undeprecateReactor	s
zTestCase._undeprecateReactorc	Cs�ddlm}|�|�d|_z+|�d|�}z|�|�W|�|�|�|�n|�|�|�|�wW|�|�dS|�|�w)z�
        Really run C{setUp}, the test method, and C{tearDown}.  Any of these may
        return L{defer.Deferred}s. After they complete, do some reactor cleanup.

        @param result: A L{TestResult} object.
        rr&FN)	rAr'r�r-r_�_waitr�r�r�)rr6r'r2rrr�_runFixturesAndTests


�zTestCase._runFixturesAndTestcst�j|g|�Ri|��S)a	
        Extend the base cleanup feature with support for cleanup functions which
        return Deferreds.

        If the function C{f} returns a Deferred, C{TestCase} will wait until the
        Deferred has fired before proceeding to the next function.
        )r�
addCleanup)rr4rTrUrrrr�)szTestCase.addCleanupcCs|��Sr;)rMrrrr�getSuppress3szTestCase.getSuppressc	CsHt�|jdtj�}zt|�WSttfy#tjdt	d�tjYSw)ae
        Returns the timeout value set on this test. Checks on the instance
        first, then the class, then the module, then packages. As soon as it
        finds something with a C{timeout} attribute, returns that. Returns
        L{util.DEFAULT_TIMEOUT_DURATION} if it cannot find anything. See
        L{TestCase} docstring for more details.
        r7z)'timeout' attribute needs to be a number.r9)
r�acquireAttribute�_parents�DEFAULT_TIMEOUT_DURATION�float�
ValueErrorrIr�r�rE)rr7rrrrB6s
�
�
�zTestCase.getTimeoutcs�|rtd��ddlm�g��fdd�}��fdd�}t�|tjdtd	��}�fd
d�}t�|tjdtd	��}|�d�z5|�	|��rMWd�|�
�dS|�	|�|�_z���W�`n�`w�sf|j
roWd�|�
�dSt��d�|�
�w)
zATake a Deferred that only ever callbacks. Block until it happens.z_wait is not reentrantrr&cs�dur��|�dSdSr;)rt)�any)�resultsrrrtVs�zTestCase._wait.<locals>.appendcs�dur
���dSdSr;�r,)�ign�r'r�rrr,Zs�zTestCase._wait.<locals>.crashzreactor\.crash cannot be used.*)�messager:cs���dSr;r�rr&rrrceszTestCase._wait.<locals>.stopN)�RuntimeErrorrAr'rrCrrDrErtrO�poprcrSr-rb)rr2�runningrtr,rcrr�rr�MsL����


�

�
zTestCase._wait)r)�__name__�
__module__�__qualname__�__doc__rr%�failUnlessFailurerRrVr_r\r[rgrhriror�inlineCallbacksrdr�r�r�r�r�r�r�r�rBrr��
__classcell__rrrrr
s4-
	


r
)r�rGr��typingr�zope.interfacerrArr�twisted.pythonr�
twisted.trialrr�twisted.trial._synctestr	r
rr�__annotations__�	ITestCaser
rrrr�<module>s
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY