%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�8����UdZddlZddlZddlmZmZddlmZddlmZddl	m
Z
mZddlm
Z
ddlmZmZdd	lmZmZmZed
�ZgZeded<eej0�Gd�d
e��Zy)zP
Things likely to be used by writers of unit tests.

Maintainer: Jonathan Lange
�N)�Callable�List)�implementer)�	ParamSpec)�defer�utils)�failure)�itrial�util)�FailTest�SkipTest�SynchronousTestCase�_P�_wait_is_runningc���eZdZdZd�fd�	Zd�ZeZd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zej"d
��Zd�Zd�Zd�Zd�Zd�Zd�Zdeeefdej8dej:ddf�fd�Zd�Zd�Z e!fd�Z"�xZ#S)�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.
    c�$��t�|�|�y)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__s  ��:/usr/lib/python3/dist-packages/twisted/trial/_asynctest.pyrzTestCase.__init__1s���	����$�c�@����fd�}��fd�}|j||�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.
        c�,���jd|����)Nz$did not catch an error, instead got )�failureException)�ignorers �r�_cbz#TestCase.assertFailure.<locals>._cbDs ����'�'�6�v�j�A��
rc���|j��r|jSdj�t|��}�j	|��)Nz
Expected: {!r}
Got:
{})�check�value�format�strr)r	�output�expectedFailuresrs  ��r�_ebz#TestCase.assertFailure.<locals>._ebIsH����w�}�}�.�/��}�}�$�5�<�<�$�c�'�l����+�+�F�3�3r)�addCallbacks)r�deferredr&rr's` `  r�
assertFailurezTestCase.assertFailure=s"���	�
	4��$�$�S�#�.�.rc�������	�ddlm��j��	�����	fd�}tj|tjt���}t���}tj|�r/tdj|��}tj|�Stjtj �j#�|�}�j%�	||��|j'�fd��|S)Nr��reactorc���tj��d��d��d��}tj|�}	|j	|�y#tj
$rd�j
�d�_�j�}|�&|j|�r�j�||�Yy�j�|�YywxYw)Nz (z) still running at z secsT)r�TimeoutErrorr	�Failure�errback�AlreadyCalledError�crash�	_timedOut�getTodo�expected�addExpectedFailure�addError)	�d�e�f�todorr-�resultr�timeouts	    �����r�	onTimeoutz TestCase._run.<locals>.onTimeout[s�����"�"��(�"�Z�L�(;�G�9�E�J��A�����"�A�
-��	�	�!����+�+�

-��
�
��!%����|�|�~���#��
�
�a�(8��-�-�d�A�t�<��O�O�D�!�,�

-�s�A�A B?�*B?�>B?��categoryz9{!r} is a generator function and therefore will never runc�P���j�xr�j�xs|S�N)�active�cancel)�x�calls �r�<lambda>zTestCase._run.<locals>.<lambda>�s���D�K�K�M�;�d�k�k�m�@�q�r)�twisted.internetr-�
getTimeoutr�suppressWarningsr�suppress�DeprecationWarning�getattr�inspect�isgeneratorfunction�	TypeErrorr#r�fail�
maybeDeferred�runWithWarningsSuppressed�_getSuppress�	callLater�addBoth)
rrr=r?�method�excr9rGr-r>s
```    @@@r�_runz
TestCase._runVs����,��/�/�#��	-�	-�,�*�*��t�}�}�.@�A�
�	���z�*���&�&�v�.��K�R�R����C�
�:�:�c�?�"�����+�+�T�->�->�-@�&�
��� � ��)�Q�7��	�	�	�@�A��rc�&�|j|i|��SrC)�run)r�args�kwargss   r�__call__zTestCase.__call__�s���t�x�x��(��(�(rc��|jd|�}|j|j|j|f|f��|S)N�setUp��callbackArgs�errbackArgs)rZr(�deferTestMethod�
_ebDeferSetUp�r�ignoredr=r9s    r�
deferSetUpzTestCase.deferSetUp�sF���I�I�g�v�&��	���� � ���� ���	�		�	
��rc�0�|jt�r7|j||j|j|j
��n8|j
||�|jt�r|j�|jd|�SrC)
r!r
�addSkip�_getSkipReasonrar"r8�KeyboardInterrupt�stop�deferRunCleanups�rr	r=s   rrfzTestCase._ebDeferSetUp�sl���7�=�=��"��N�N�4��!4�!4�T�Z�Z����!O�P��O�O�D�'�*��w�}�}�.�/����
��$�$�T�6�2�2rc��|j|j|�}|j|j|j|f|f��|j|j|�|j|j|�|S)Nrb)rZ�_testMethodNamer(�_cbDeferTestMethod�_ebDeferTestMethodrWro�
deferTearDownrgs    rrezTestCase.deferTestMethod�st���I�I�d�*�*�F�3��	����#�#��#�#� ���	�		�	
�	
�	�	�$�'�'��0�	�	�	�$�$�$�f�-��rc�x�|j��"|j||j��|Sd|_|S)NT)r5�addUnexpectedSuccess�_passed)rrhr=s   rrszTestCase._cbDeferTestMethod�s9���<�<�>�%��'�'��d�l�l�n�=��� �D�L��rc	��|j�}|�%|j|�r|j|||�y|j|jt
�r|j
||�y|jt�r#|j||�|j�y|jt�rA|j||jt||j�|j��y|j||�yrC)r5r6r7r!rr�
addFailurermr8rnr
rkrlrNrrr")rr;r=r<s    rrtzTestCase._ebDeferTestMethod�s����|�|�~�����
�
�a� 0��%�%�d�A�t�4�
�W�W�T�*�*�H�
5����d�A�&�
�W�W�&�
'��O�O�D�!�$��K�K�M�
�W�W�X�
��N�N��d�)�)�'�$��8L�8L�*M�q�w�w�W�
�
�O�O�D�!�$rc�b�|jd|�}|j|j|�|S)N�tearDown)rZ�
addErrback�_ebDeferTearDownrgs    rruzTestCase.deferTearDown�s+���I�I�j�&�)��	���T�*�*�F�3��rc��|j||�|jt�r|j�d|_y�NF)r8r!rmrnrxrps   rr~zTestCase._ebDeferTearDown�s/������g�&��7�=�=�*�+��K�K�M���rc#�hK�g}t|j�dkDrB|jj�\}}}	||i|����t|j�dkDr�B|D]}|j||�d|_�y#t$r&|j	tj��Y�hwxYw�w)zf
        Run any scheduled cleanups and report errors (if any) to the result.
        object.
        rFN)	�len�	_cleanups�pop�	Exception�appendr	r0r8rx)rrhr=�failures�funcr]r^r;s        rrozTestCase.deferRunCleanups�s��������$�.�.�!�A�%�!%���!3�!3�!5��D�$��
3��D�+�F�+�+��$�.�.�!�A�%��	!�A��O�O�D�!�$� �D�L�	!���
3������� 1�2�
3�s.�9B2�
B�B2�!B2�,B/�,B2�.B/�/B2c��	tj||�j�}|sd|_|jj�D]}|j||�d|_�|j�|j�|jr|j|�yy#t$r.|j|t
j��d|_Y��wxYwr�)
r�_Janitor�postCaseCleanuprx�
BaseExceptionr8r	r0�	_observer�	getErrors�flushLoggedErrors�_removeObserver�
addSuccess)rr=�clean�errors    r�_cleanUpzTestCase._cleanUp�s���	!��M�M�$��/�?�?�A�E��$����^�^�-�-�/�	!�E��O�O�D�%�(� �D�L�	!�	
��� ������<�<����d�#����	!��O�O�D�'�/�/�"3�4� �D�L�	!�s�-B&�&4C�Cc��	tj||�j�y#t$r'|j	|tj��YywxYwrC)rr��postClassCleanupr�r8r	r0)rr=s  r�
_classCleanUpzTestCase._classCleanUp�sB��	5��M�M�$��'�8�8�:���	5��O�O�D�'�/�/�"3�4�	5�s�$'�-A�Ac������fd�}|S)z�
        Create a method which wraps the reactor method C{name}. The new
        method issues a deprecation warning and calls the original.
        c�t��tjd��d��d�dt���j�|i|��S)Nzreactor.z8 cannot be used inside unit tests. In the future, using z7 will fail the test and may crash or hang the test run.�)�
stacklevelrA)�warnings�warnrM�_reactorMethods)�a�kw�namers  ��r�_z&TestCase._makeReactorMethod.<locals>._�sB����M�M�26�t�=��+�
�.�4�'�'��-�q�7�B�7�7r�)rr�r�s`` r�_makeReactorMethodzTestCase._makeReactorMethod�s���	8��rc��i|_dD]7}t||�|j|<t|||j|���9y)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.
        )r3�iteraternN)r�rN�setattrr�)rr-r�s   r�_deprecateReactorzTestCase._deprecateReactorsK�� "���0�	B�D�)0��$�)?�D� � ��&��G�T�4�#:�#:�4�#@�A�	Brc�p�|jj�D]\}}t|||��i|_y)z�
        Restore the deprecated reactor methods. Undoes what
        L{_deprecateReactor} did.

        @param reactor: The Twisted reactor.
        N)r��itemsr�)rr-r�rXs    r�_undeprecateReactorzTestCase._undeprecateReactors:��!�0�0�6�6�8�	+�L�D�&��G�T�6�*�	+�!��rc�l�ddlm}|j|�d|_	|j	d|�}	|j|�|j
|�|j|�	|j|�y#|j
|�|j|�wxYw#|j|�wxYw)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)	rIr-r�r4ri�_waitr�r�r�)rr=r-r9s    r�_runFixturesAndTestzTestCase._runFixturesAndTests���	-����w�'����	.�����f�-�A�
+��
�
�1�
��
�
�f�%��"�"�6�*��$�$�W�-���
�
�f�%��"�"�6�*���$�$�W�-�s"�B �A9�"B �9$B�B � B3r;r]r^�returnNc�*��t�|�|g|��i|��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)rr;r]r^rs    �rr�zTestCase.addCleanup0s����w�!�!�5�d�5�f�5�5rc�"�|j�SrC)rU)rs r�getSuppresszTestCase.getSuppress<s��� � �"�"rc��tj|jdtj�}	t	|�S#t
tf$r.tjdt��tjcYSwxYw)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.
        r>z)'timeout' attribute needs to be a number.r@)
r�acquireAttribute�_parents�DEFAULT_TIMEOUT_DURATION�float�
ValueErrorrQr�r�rM)rr>s  rrJzTestCase.getTimeout?sj���'�'��M�M�9�d�&C�&C�
��
	1���>�!���I�&�	1�

�M�M�;�FX�
��0�0�0�	1�s�
<�:A9�8A9c�h���|rtd��ddlm�g��fd�}��fd�}tj|tjdt���}�fd�}tj|tjdt���}|jd	�	|j|��r	d	�|j�y	|j|�|�_	�j��`�s|jr	d	�|j�y	t��#�`wxYw#d	�|j�wxYw)
zATake a Deferred that only ever callbacks. Block until it happens.z_wait is not reentrantrr,c�.�����j|�yyrC)r�)�any�resultss �rr�zTestCase._wait.<locals>.append_s����"����s�#�#rc�,�����j�yyrC�r3)�ignr-r�s ��rr3zTestCase._wait.<locals>.crashcs����"��
�
��#rzreactor\.crash cannot be used.*)�messagerAc�&���j�yrCr�r,s�rrnzTestCase._wait.<locals>.stopns����M�M�OrN)�RuntimeErrorrIr-rrKrrLrMr�rWr�rnr\r4rm)rr9�runningr�r3rnr-r�s      @@rr�zTestCase._waitVs�����7�8�8�,���	$�	 ��&�&���M�M�:�EW�
�
��	��%�%���M�M�:�EW�
�
��	���t��$	�
�I�I�f����<�G��K�K�M�=
�I�I�e���G�L�
!����
��L��$�.�.��"�G��K�K�M�$�%�%��-�L��0�G��K�K�M�s0�D�?D�D�(D�
D�D�D�D1)�runTest)$�__name__�
__module__�__qualname__�__doc__rr*�failUnlessFailurerZr_rirfrersrtrur~r�inlineCallbacksror�r�r�r�r�r�rr�objectr]r^r�r�rJrr��
__classcell__)rs@rrr!s�����
%�/�.&��+�Z)��3�
��%� �
����!��!�"$� 5��$B�	"�.�.
6��"�f�*�%�
6�.0�g�g�
6�AC���
6�	
�
6�#�1�. 0�Grr)r�rOr��typingrr�zope.interfacerrrIrr�twisted.pythonr	�
twisted.trialr
r�twisted.trial._synctestrr
rrr�__annotations__�	ITestCaserr�rr�<module>r�sn��
���!�&��
*�"�&�K�K��t�_��!��$�t�*�!�
�V�
�
��{�"�{��{r

Zerion Mini Shell 1.0