%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/twisted/test/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/twisted/test/__pycache__/test_defgen.cpython-312.pyc

�

Ϫ�f4��"�dZddlZddlmZmZmZddlmZmZm	Z	m
Z
mZddlm
Z
ddlmZddlmZd�Zd	�ZGd
�de�ZGd�d
�Zd�ZGd�deej2�ZGd�deej2�ZGd�dej8�Zy)zI
Tests for L{twisted.internet.defer.deferredGenerator} and related APIs.
�N)�defer�reactor�task)�Deferred�deferredGenerator�inlineCallbacks�returnValue�waitForDeferred)�runWithWarningsSuppressed)�unittest)�suppressc�\�t�}tjd|jd�|S)Nr�hi)rr�	callLater�callback��ds �:/usr/lib/python3/dist-packages/twisted/test/test_defgen.py�getThingrs$���
�A����a����T�*��H�c�R��t���fd�}tjd|��S)Nc�:���jtd��y)N�OMG)�errback�ZeroDivisionErrorrs�r�CRAPzgetOwie.<locals>.CRAP s���	�	�	�#�E�*�+rr)rrr)rrs @r�getOwiers&����
�A�,����a����Hrc��eZdZy)�TerminalExceptionN)�__name__�
__module__�__qualname__�rrrr+s��rrc�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�BaseDefgenTestsa
    This class sets up a bunch of test cases which will test both
    deferredGenerator and inlineCallbacks based generators. The subclasses
    DeferredGeneratorTests and InlineCallbacksTests each provide the actual
    generator implementations tested.
    c�V�|j�j|jd�S)z�
        Test that a normal deferredGenerator works.  Tests yielding a
        deferred which callbacks, as well as a deferred errbacks. Also
        ensures returning a final value works.
        �WOOSH)�
_genBasics�addCallback�assertEqual��selfs r�
testBasicszBaseDefgenTests.testBasics7s$����� �,�,�T�-=�-=�w�G�Grc�J�|j|j�t�S)zp
        Ensure that a buggy generator properly signals a Failure
        condition on result deferred.
        )�
assertFailure�	_genBuggyrr+s r�	testBuggyzBaseDefgenTests.testBuggy@s��
�!�!�$�.�.�"2�4E�F�Frc�V�|j�j|jd�S)z9Test that a generator which never yields results in None.N)�_genNothingr)r*r+s r�testNothingzBaseDefgenTests.testNothingGs&�����!�-�-�d�.>�.>��E�Erc�V�|j�j|jd�S)z�
        Create a Deferred Generator which yields a Deferred which fails and
        handles the exception which results.  Assert that the Deferred
        Generator does not errback its Deferred.
        N)�_genHandledTerminalFailurer)r*r+s r�testHandledTerminalFailurez*BaseDefgenTests.testHandledTerminalFailureLs&���.�.�0�<�<�T�=M�=M�t�T�Trc��tj�}|j|�}|jt	d��|j|jd�S)z~
        Just like testHandledTerminalFailure, only with a Deferred which fires
        asynchronously with an error.
        �Handled Terminal FailureN)rr�_genHandledTerminalAsyncFailurerrr)r*)r,r�deferredGeneratorResultDeferreds   r�testHandledTerminalAsyncFailurez/BaseDefgenTests.testHandledTerminalAsyncFailureTsM��

�N�N���*.�*N�*N�q�*Q�'�	�	�	�#�$>�?�@�.�:�:�4�;K�;K�T�R�Rrc�V�|j�j|jd�S)zj
        Make sure we don't blow the stack when yielding immediately
        available deferreds.
        r)�_genStackUsager)r*r+s r�testStackUsagezBaseDefgenTests.testStackUsage^s&��
�"�"�$�0�0��1A�1A�1�E�Erc�V�|j�j|jd�S)zg
        Make sure we don't blow the stack when yielding immediately
        available values.
        r)�_genStackUsage2r)r*r+s r�testStackUsage2zBaseDefgenTests.testStackUsage2es&��
�#�#�%�1�1�$�2B�2B�A�F�FrN)r r!r"�__doc__r-r1r4r7r<r?rBr#rrr%r%/s1���H�G�F�
U�S�F�Grr%c�:�ttd��gt|�S)z�
    Calls L{deferredGenerator} while suppressing the deprecation warning.

    @param f: Function to call
    @return: Return value of function.
    z7twisted.internet.defer.deferredGenerator was deprecated��message)r�SUPPRESSr)�fs r�deprecatedDeferredGeneratorrIms)��%��T�
�	
�
	�	��rc��eZdZed��Zed��Zed��Zed��Zed��Zd�Z	ee	�Z	d�Z
ee
�Z
d�Zed	�
�gZ
y)�DeferredGeneratorTestsc#�8K�tt��}|��|j�}|j|d�tt	��}|��	|j�d��y#t
$r%}|jt
|�d�Yd}~�.d}~wwxYw�w�Nrrr')r
r�	getResultr*rr�str)r,�x�ow�es    rr(z!DeferredGeneratorTests._genBasics�s������H�J�'����
�K�K�M������D�!�
�W�Y�
'����	,��L�L�N��
���!�	,����S��V�U�+�+��	,�s0�AB�A)�$B�)	B�2B�
B�B�Bc#�@K�tt����ddzy�w�N�r)r
rr+s rr0z DeferredGeneratorTests._genBuggy�s�����h�j�)�)�	�Q��s�c#�K�y�w�Nr#r+s rr3z"DeferredGeneratorTests._genNothing�s	�������c#�K�ttjtd���}|��	|j	�y#t$rYywxYw�w�Nr9)r
r�failrrN�r,rPs  rr6z1DeferredGeneratorTests._genHandledTerminalFailure�sD�����E�J�J�'8�9S�'T�U�V����	�
�K�K�M�� �	��	�s'�,A�A�A�	A�	A�A�Ac#�jK�t|�}|��	|j�y#t$rYywxYw�wrW)r
rNr)r,rrPs   rr:z6DeferredGeneratorTests._genHandledTerminalAsyncFailure�s4�����A�����	�
�K�K�M�� �	��	�s�3�$�3�	0�3�0�3c#�K�td�D]4}ttjd��}|��|j	�}�6d��y�w�Ni�rUr)�ranger
r�succeedrNr\s  rr>z%DeferredGeneratorTests._genStackUsage�sC�����t��	�A���
�
�a� 0�1�A��G����
�A�		�
��s�AA
c#�<K�td�D]}d���d��y�wr_)r`r\s  rrAz&DeferredGeneratorTests._genStackUsage2�s%�����t��	�A��G�	���s�c�T�d�}t|�}|j|�t�S)zZ
        Ensure that yielding a Deferred directly is trapped as an
        error.
        c3�$K�t���y�wrW�rr#rr�_genDeferredzADeferredGeneratorTests.testDeferredYielding.<locals>._genDeferred�s�����*��s�)rIr/�	TypeError)r,rfs  r�testDeferredYieldingz+DeferredGeneratorTests.testDeferredYielding�s(��	�3�<�@���!�!�,�.�)�<�<rz5twisted.internet.defer.waitForDeferred was deprecatedrEN)r r!r"rIr(r0r3r6r:r>rArhrGr
r#rrrKrKs��� ��!�� !��!��!��!��!��!��!��!���1��@�N��2�/�B�O�=�	�S�T��HrrKc���eZdZd�Zee�Zd�Zee�Zd�Zee�Zd�Zee�Zd�Zee�Zd�Z	ee	�Z	d�Z
ee
�Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zd�Zy)�InlineCallbacksTestsc#��K�t���}|j|d�	t���td�y#t$r%}|jt	|�d�Yd}~�5d}~wwxYw�wrM)rr*rrrOr	)r,rPrRs   rr(zInlineCallbacksTests._genBasics�s^�����*�������D�!�	,��)�O�	�G���!�	,����S��V�U�+�+��	,�s+�A+�:�A+�	A(�A#�A+�#A(�(A+c#�.K�t���ddzy�wrTrer+s rr0zInlineCallbacksTests._genBuggy�s�����j��	�A��s�c#�K�y�wrWr#r+s rr3z InlineCallbacksTests._genNothing�s	�����rXc#�lK�	tjtd����y#t$rYywxYw�wrZ)rr[rr+s rr6z/InlineCallbacksTests._genHandledTerminalFailure�s2����	��*�*�.�/I�J�K�K�� �	��	�s�4� %�4�	1�4�1�4c#�4K�	|��y#t$rYywxYw�wrW)r)r,rs  rr:z4InlineCallbacksTests._genHandledTerminalAsyncFailure�s!����	��G�� �	��	�s��	��	���c#�pK�td�D]}tjd����td�y�wr_)r`rrar	r\s  rr>z#InlineCallbacksTests._genStackUsages1�����t��	#�A��-�-��"�"�	#�	�A��s�46c#�JK�td�D]}d���td�y�wr_)r`r	r\s  rrAz$InlineCallbacksTests._genStackUsage2	s'�����t��	�A��G�	�	�A��s�!#c�`�d�}t|�}|�j|jd�S)z�
        Ensure that yielding a non-deferred passes it back as the
        result of the yield expression.

        @return: A L{twisted.internet.defer.Deferred}
        @rtype: L{twisted.internet.defer.Deferred}
        c3�*K�d��td�y�w�N��r	r#rr�_testz8InlineCallbacksTests.testYieldNonDeferred.<locals>._test������G���N���ru�rr)r*)r,rws  r�testYieldNonDeferredz)InlineCallbacksTests.testYieldNonDeferreds.��	� ��&���w�"�"�4�#3�#3�Q�7�7rc�`�d�}t|�}|�j|jd�S)z9Ensure a standard python return results in a None result.c3�K�d��y�wrtr#r#rr�	_noReturnz9InlineCallbacksTests.testReturnNoValue.<locals>._noReturn's�����G����Nrz)r,r~s  r�testReturnNoValuez&InlineCallbacksTests.testReturnNoValue$s.��	�$�I�.�	��{�&�&�t�'7�'7��>�>rc�`�d�}t|�}|�j|jd�S)zEnsure that returnValue works.c3�*K�d��td�y�w)Nru�rvr#rr�_returnz5InlineCallbacksTests.testReturnValue.<locals>._return2rxryr�rz)r,r�s  r�testReturnValuez$InlineCallbacksTests.testReturnValue/s.��	�"�'�*���y�$�$�T�%5�%5�q�9�9rc	�~�d�}t|�}|jdt|jt|���y)z�
        Ensure that C{TypeError} with a message about L{inlineCallbacks} is
        raised when a non-generator returns something other than a generator.
        c��yrtr#r#rr�_noYieldz>InlineCallbacksTests.test_nonGeneratorReturn.<locals>._noYield@s��rrN�r�assertInrO�assertRaisesrg�r,r�s  r�test_nonGeneratorReturnz,InlineCallbacksTests.test_nonGeneratorReturn:s4��	�#�8�,���
�
�'��T�->�->�y�(�-S�)T�Urc	�~�d�}t|�}|jdt|jt|���y)z�
        Ensure that C{TypeError} with a message about L{inlineCallbacks} is
        raised when a non-generator calls L{returnValue}.
        c��td�yrtrvr#rrr�zCInlineCallbacksTests.test_nonGeneratorReturnValue.<locals>._noYieldMs	����NrrNr�r�s  r�test_nonGeneratorReturnValuez1InlineCallbacksTests.test_nonGeneratorReturnValueGs4��	�#�8�,���
�
�'��T�->�->�y�(�-S�)T�Urc�&���tj��t�fd���t�fd��}|�}�jd�|j	|�}|jd|�|jd|�|j
d|�y)z�
        When one inlineCallbacks calls another, the internal L{_DefGen_Return}
        flow control exception raised by calling L{defer.returnValue} doesn't
        leak into tracebacks captured in the caller.
        c3�T�K�tj�d���td�y�w)zG
            This is the inner function using returnValue.
            rz"actual-value-not-used-for-the-testN)r�
deferLaterr	��clocks�r�_returnszOInlineCallbacksTests.test_internalDefGenReturnValueDoesntLeak.<locals>._returns\s#�����
�/�/�%��+�+��<�=�s�%(c3�|�K�	����td��#t$rtj�cYSwxYw�w)Nzboom returnValue�r�	traceback�
format_exc�r�s�r�_raiseszNInlineCallbacksTests.test_internalDefGenReturnValueDoesntLeak.<locals>._raisesds=�����
.��j� �'�(:�;�;��$�
.� �+�+�-�-�
.���<��9�<�9�<r�_DefGen_Return�BDuring handling of the above exception, another exception occurredz/test_defgen.TerminalException: boom returnValueN�r�Clockr�advance�successResultOf�assertNotInr��r,r�r�tbr�r�s    @@r�(test_internalDefGenReturnValueDoesntLeakz=InlineCallbacksTests.test_internalDefGenReturnValueDoesntLeakTs�����
�
���	�	>�
�	>�
�	.�
�	.�
�I��
�
�
�a��
�
!�
!�!�
$��	
���)�2�.����P�RT�	
�	
�
�
�G��Lrc�&���tj��t�fd���t�fd��}|�}�jd�|j	|�}|jd|�|jd|�|j
d|�y)a�
        When one inlineCallbacks calls another, the internal L{StopIteration}
        flow control exception generated when the inner generator returns
        doesn't leak into tracebacks captured in the caller.

        This is similar to C{test_internalDefGenReturnValueDoesntLeak} but the
        inner function uses the "normal" return statemement rather than the
        C{returnValue} helper.
        c3�>�K�tj�d���y�w)Nrr�)rr�r�s�rr�zKInlineCallbacksTests.test_internalStopIterationDoesntLeak.<locals>._returns�s������/�/�%��+�+��s�c3�|�K�	����td��#t$rtj�cYSwxYw�w)Nzboom normal returnr�r�s�rr�zJInlineCallbacksTests.test_internalStopIterationDoesntLeak.<locals>._raises�s=�����
.��j� �'�(<�=�=��$�
.� �+�+�-�-�
.�r�r�
StopIterationr�z1test_defgen.TerminalException: boom normal returnNr�r�s    @@r�$test_internalStopIterationDoesntLeakz9InlineCallbacksTests.test_internalStopIterationDoesntLeakys�����
�
���	�	�
�	�
�	.�
�	.�
�I��
�
�
�a��
�
!�
!�!�
$��	
����"�-����P�RT�	
�	
�
�
�I�2�NrN)r r!r"r(rr0r3r6r:r>rAr{r�r�r�r�r�r�r#rrrjrj�s���	�!��,�J�� �	�*�I��"�+�.�K��"1�1K�!L���'6�6U�&V�#��%�^�4�N��&�o�6�O�8�"	?�	:�V�V�#M�J$Orrjc��eZdZdZd�Zd�Zy)�DeprecateDeferredGeneratorTestszY
    Tests that L{DeferredGeneratorTests} and L{waitForDeferred} are
    deprecated.
    c���td��}|j|jg�}|jt	|�d�|j|ddt
�|j|ddd�y)z5
        L{deferredGenerator} is deprecated.
        c3�K�d��y�wrWr#r#rr�decoratedFunctionz[DeprecateDeferredGeneratorTests.test_deferredGeneratorDeprecated.<locals>.decoratedFunction�s�����J�rrUr�categoryrFz�twisted.internet.defer.deferredGenerator was deprecated in Twisted 15.0.0; please use twisted.internet.defer.inlineCallbacks insteadN)r�
flushWarnings� test_deferredGeneratorDeprecatedr*�len�DeprecationWarning)r,r��warningss   rr�z@DeprecateDeferredGeneratorTests.test_deferredGeneratorDeprecated�s~��

�	�
�	��%�%�t�'L�'L�&M�N������X���*�����!��Z�0�2D�E�����Q�K�	�"�
=�	
rc��t�}t|�|j|jg�}|j	t|�d�|j	|ddt�|j	|ddd�y)z3
        L{waitForDeferred} is deprecated.
        rUrr�rFz�twisted.internet.defer.waitForDeferred was deprecated in Twisted 15.0.0; please use twisted.internet.defer.inlineCallbacks insteadN)rr
r��test_waitForDeferredDeprecatedr*r�r�)r,rr�s   rr�z>DeprecateDeferredGeneratorTests.test_waitForDeferredDeprecated�sy��
�J������%�%�t�'J�'J�&K�L������X���*�����!��Z�0�2D�E�����Q�K�	�"�
=�	
rN)r r!r"rCr�r�r#rrr�r��s���

�&
rr�)rCr��twisted.internetrrr�twisted.internet.deferrrrr	r
�twisted.python.utilr�
twisted.trialr�twisted.trial.utilr
rGrr�	Exceptionrr%rI�TestCaserKrj�SynchronousTestCaser�r#rr�<module>r�s�����1�1���:�"�3�
�
�	�	�	�;G�;G�|�$S�_�h�.?�.?�S�lHO�?�H�,=�,=�HO�V(
�h�&B�&B�(
r

Zerion Mini Shell 1.0