o
    ¯b¸  ã                   @   sŒ  d Z ddlmZ ddlmZmZmZ ddlmZmZ G dd„ de	ƒZ
G dd„ dƒZG d	d
„ d
eejƒZG dd„ deejƒZG dd„ dƒZG dd„ deejƒZG dd„ deejƒZG dd„ dƒZG dd„ deejƒZG dd„ deejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZedd ƒG d!d"„ d"ejƒƒZG d#d$„ d$ejƒZG d%d&„ d&ejƒZG d'd(„ d(ejƒZG d)d*„ d*ejƒZd+d,„ Zd-S ).a  
Definitions of test cases with various interesting error-related behaviors, to
be used by test modules to exercise different features of trial's test runner.

See the L{twisted.trial.test.test_tests} module docstring for details about how
this code is arranged.
é    )ÚskipIf)ÚdeferÚprotocolÚreactor)ÚunittestÚutilc                   @   ó   e Zd ZdS )ÚFoolishErrorN©Ú__name__Ú
__module__Ú__qualname__© r   r   ú>/usr/lib/python3/dist-packages/twisted/trial/test/erroneous.pyr	      ó    r	   c                   @   ó   e Zd Zdd„ Zdd„ ZdS )ÚFailureInSetUpMixinc                 C   ó   t dƒ‚)NzI am a broken setUp method©r	   ©Úselfr   r   r   ÚsetUp   ó   zFailureInSetUpMixin.setUpc                 C   ó   d S ©Nr   r   r   r   r   Ú	test_noop   ó   zFailureInSetUpMixin.test_noopN)r   r   r   r   r   r   r   r   r   r      ó    r   c                   @   r   )ÚSynchronousTestFailureInSetUpNr
   r   r   r   r   r       r   r   c                   @   r   )ÚAsynchronousTestFailureInSetUpNr
   r   r   r   r   r   $   r   r   c                   @   r   )ÚFailureInTearDownMixinc                 C   r   )NzI am a broken tearDown methodr   r   r   r   r   ÚtearDown)   r   zFailureInTearDownMixin.tearDownc                 C   r   r   r   r   r   r   r   r   ,   r   z FailureInTearDownMixin.test_noopN)r   r   r   r!   r   r   r   r   r   r    (   r   r    c                   @   r   )Ú SynchronousTestFailureInTearDownNr
   r   r   r   r   r"   0   ó    r"   c                   @   r   )Ú!AsynchronousTestFailureInTearDownNr
   r   r   r   r   r$   6   r   r$   c                   @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )ÚFailureButTearDownRunsMixinz7
    A test fails, but its L{tearDown} still runs.
    Fc                 C   s
   d| _ d S ©NT)ÚtornDownr   r   r   r   r!   A   ó   
z$FailureButTearDownRunsMixin.tearDownc                 C   r   )z$
        A test that fails.
        zI am a broken testr   r   r   r   r   Ú
test_failsD   ó   z&FailureButTearDownRunsMixin.test_failsN)r   r   r   Ú__doc__r'   r!   r)   r   r   r   r   r%   :   s
    r%   c                   @   r   )Ú%SynchronousTestFailureButTearDownRunsNr
   r   r   r   r   r,   K   r#   r,   c                   @   r   )Ú&AsynchronousTestFailureButTearDownRunsNr
   r   r   r   r   r-   Q   r#   r-   c                   @   ó$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTestRegularFailc                 C   ó   |   d¡ d S )NúI fail©Úfailr   r   r   r   Ú	test_failX   ó   zTestRegularFail.test_failc                 C   s   |   ¡  d S r   )Ú
subroutiner   r   r   r   Útest_subfail[   ó   zTestRegularFail.test_subfailc                 C   r0   )NzI fail insider2   r   r   r   r   r6   ^   r5   zTestRegularFail.subroutineN)r   r   r   r4   r7   r6   r   r   r   r   r/   W   s    r/   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚTestAsynchronousFailz?
    Test failures for L{unittest.TestCase} based classes.
    c                 C   s(   t  ¡ }| | j¡ t d|jd¡ |S )zW
        A test which fails in the callback of the returned L{defer.Deferred}.
        r   N)r   ÚDeferredÚaddCallbackÚ_laterr   Ú	callLaterÚcallback©r   Údr   r   r   r4   g   s   zTestAsynchronousFail.test_failc                 C   r0   )NzI fail laterr2   )r   Úresr   r   r   r<   p   r5   zTestAsynchronousFail._laterc                 C   r   )zA
        A test which raises an exception synchronously.
        r1   )Ú	Exceptionr   r   r   r   Útest_exceptions   r*   z#TestAsynchronousFail.test_exceptionN)r   r   r   r+   r4   r<   rC   r   r   r   r   r9   b   s
    	r9   c                   @   s   e Zd ZdZdZdd„ ZdS )Ú	ErrorTestz�
    A test case which has a L{test_foo} which will raise an error.

    @ivar ran: boolean indicating whether L{test_foo} has been run.
    Fc                 C   s   d| _ dd  dS )zJ
        Set C{self.ran} to True and raise a C{ZeroDivisionError}
        Té   r   N)Úranr   r   r   r   Útest_fooƒ   s   zErrorTest.test_fooN)r   r   r   r+   rF   rG   r   r   r   r   rD   z   s    rD   Tzskipping this testc                   @   r   )ÚTestSkipTestCaseNr
   r   r   r   r   rH   ‹   s    rH   c                   @   s2   e Zd ZdZdd„ Zdd„ Zejded�ge_dS )	ÚDelayedCallzsomething blew upc                 C   s
   t | jƒ‚r   )ÚRuntimeErrorÚhiddenExceptionMsgr   r   r   r   Úgo“   r(   zDelayedCall.goc                 C   s&   t  d| j¡ t  d¡ |  d¡ dS )a®  
        What happens if an error is raised in a DelayedCall and an error is
        also raised in the test?

        L{test_reporter.ErrorReportingTests.testHiddenException} checks that
        both errors get reported.

        Note that this behaviour is deprecated. A B{real} test would return a
        Deferred that got triggered by the callLater. This would guarantee the
        delayed call error gets reported.
        r   g{®Gáz„?z/Deliberate failure to mask the hidden exceptionN)r   r=   rL   Úiterater3   r   r   r   r   ÚtestHiddenException–   s   
zDelayedCall.testHiddenExceptionz!reactor\.iterate cannot be used.*)ÚmessageÚcategoryN)	r   r   r   rK   rL   rN   r   ÚsuppressÚDeprecationWarningr   r   r   r   rI   �   s    ÿ
ÿrI   c                   @   ó   e Zd Zdd„ ZdS )ÚReactorCleanupTestsc                 C   s   dd„ }t  d|¡ d S )Nc                   S   s   t dƒ d S )Nzfoo!)Úprintr   r   r   r   Ú_¯   r8   z8ReactorCleanupTests.test_leftoverPendingCalls.<locals>._g     ˆÃ@)r   r=   )r   rV   r   r   r   Útest_leftoverPendingCalls®   s   z-ReactorCleanupTests.test_leftoverPendingCallsN)r   r   r   rW   r   r   r   r   rT   ­   ó    rT   c                   @   rS   )ÚSocketOpenTestc                 C   s    t  ¡ }t j|_ t d|¡ d S )Nr   )r   ÚFactoryÚProtocolr   Ú	listenTCP)r   Úfr   r   r   Útest_socketsLeftOpen¶   s   z#SocketOpenTest.test_socketsLeftOpenN)r   r   r   r^   r   r   r   r   rY   µ   rX   rY   c                   @   r.   )ÚTimingOutDeferredc                 C   r   r   r   r   r   r   r   Ú
test_alpha½   r   zTimingOutDeferred.test_alphac                 C   s   d| _ t ¡ }|S r&   )ÚmethodCalledr   r:   r?   r   r   r   Útest_deferredThatNeverFiresÀ   s   z-TimingOutDeferred.test_deferredThatNeverFiresc                 C   r   r   r   r   r   r   r   Ú
test_omegaÅ   r   zTimingOutDeferred.test_omegaN)r   r   r   r`   rb   rc   r   r   r   r   r_   ¼   s    r_   c                 C   s   dS )zci will raise an unexpected exception...
    ... *CAUSE THAT'S THE KINDA GUY I AM*

    >>> 1/0
    Nr   r   r   r   r   ÚunexpectedExceptionÉ   s    rd   N)r+   r   r   Útwisted.internetr   r   r   Útwisted.trialr   rB   r	   r   ÚSynchronousTestCaser   ÚTestCaser   r    r"   r$   r%   r,   r-   r/   r9   rD   rH   rI   rT   rY   r_   rd   r   r   r   r   Ú<module>   s<   	
ÿ
ÿ
ÿ