U
    
W[                     @   s  d Z ddlmZmZ ddlmZmZ ddlmZm	Z	m
Z
 G dd deZG dd deZG d	d
 d
eejZG dd deejZG dd deZG dd deejZG dd deejZG dd de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G dd  d ejZd!e_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.
    )divisionabsolute_import)unittestutil)reactorprotocoldeferc                   @   s   e Zd ZdS )FoolishErrorN__name__
__module____qualname__ r   r   >/usr/lib/python3/dist-packages/twisted/trial/test/erroneous.pyr	      s   r	   c                   @   s   e Zd Zdd Zdd ZdS )FailureInSetUpMixinc                 C   s   t dd S )NzI am a broken setUp methodr	   selfr   r   r   setUp   s    zFailureInSetUpMixin.setUpc                 C   s   d S Nr   r   r   r   r   	test_noop   s    zFailureInSetUpMixin.test_noopN)r   r   r   r   r   r   r   r   r   r      s   r   c                   @   s   e Zd ZdS )SynchronousTestFailureInSetUpNr
   r   r   r   r   r   !   s   r   c                   @   s   e Zd ZdS )AsynchronousTestFailureInSetUpNr
   r   r   r   r   r   '   s   r   c                   @   s   e Zd Zdd Zdd ZdS )FailureInTearDownMixinc                 C   s   t dd S )NzI am a broken tearDown methodr   r   r   r   r   tearDown.   s    zFailureInTearDownMixin.tearDownc                 C   s   d S r   r   r   r   r   r   r   1   s    z FailureInTearDownMixin.test_noopN)r   r   r   r   r   r   r   r   r   r   -   s   r   c                   @   s   e Zd ZdS ) SynchronousTestFailureInTearDownNr
   r   r   r   r   r   6   s   r   c                   @   s   e Zd ZdS )!AsynchronousTestFailureInTearDownNr
   r   r   r   r   r   <   s   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   H   s    z$FailureButTearDownRunsMixin.tearDownc                 C   s   t ddS )z$
        A test that fails.
        zI am a broken testNr   r   r   r   r   
test_failsL   s    z&FailureButTearDownRunsMixin.test_failsN)r   r   r   __doc__r   r   r    r   r   r   r   r   B   s   r   c                   @   s   e Zd ZdS )%SynchronousTestFailureButTearDownRunsNr
   r   r   r   r   r"   T   s   r"   c                   @   s   e Zd ZdS )&AsynchronousTestFailureButTearDownRunsNr
   r   r   r   r   r#   Z   s   r#   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestRegularFailc                 C   s   |  d d S )NI failfailr   r   r   r   	test_failb   s    zTestRegularFail.test_failc                 C   s   |    d S r   )
subroutiner   r   r   r   test_subfailf   s    zTestRegularFail.test_subfailc                 C   s   |  d d S )NzI fail insider&   r   r   r   r   r)   j   s    zTestRegularFail.subroutineN)r   r   r   r(   r*   r)   r   r   r   r   r$   `   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   DeferredZaddCallback_laterr   	callLatercallbackr   dr   r   r   r(   t   s    zTestAsynchronousFail.test_failc                 C   s   |  d d S )NzI fail laterr&   )r   resr   r   r   r-   ~   s    zTestAsynchronousFail._laterc                 C   s   t ddS )zA
        A test which raises an exception synchronously.
        r%   N)	Exceptionr   r   r   r   test_exception   s    z#TestAsynchronousFail.test_exceptionN)r   r   r   r!   r(   r-   r4   r   r   r   r   r+   o   s   
r+   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!   r7   r8   r   r   r   r   r5      s   r5   c                   @   s   e Zd ZdS )TestSkipTestCaseNr
   r   r   r   r   r9      s   r9   zskipping this testc                   @   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d S r   )RuntimeErrorhiddenExceptionMsgr   r   r   r   go   s    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{Gz?z/Deliberate failure to mask the hidden exceptionN)r   r.   r=   Ziterater'   r   r   r   r   testHiddenException   s    
zDelayedCall.testHiddenExceptionz!reactor\.iterate cannot be used.*)messagecategoryN)	r   r   r   r<   r=   r>   r   suppressDeprecationWarningr   r   r   r   r:      s   r:   c                   @   s   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   _   s    z8ReactorCleanupTests.test_leftoverPendingCalls.<locals>._g     @)r   r.   )r   rE   r   r   r   test_leftoverPendingCalls   s    z-ReactorCleanupTests.test_leftoverPendingCallsN)r   r   r   rF   r   r   r   r   rC      s   rC   c                   @   s   e Zd Zdd ZdS )SocketOpenTestc                 C   s    t  }t j|_ td| d S )Nr   )r   ZFactoryZProtocolr   Z	listenTCP)r   fr   r   r   test_socketsLeftOpen   s    z#SocketOpenTest.test_socketsLeftOpenN)r   r   r   rI   r   r   r   r   rG      s   rG   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TimingOutDeferredc                 C   s   d S r   r   r   r   r   r   
test_alpha   s    zTimingOutDeferred.test_alphac                 C   s   d| _ t }|S r   )ZmethodCalledr   r,   r0   r   r   r   test_deferredThatNeverFires   s    z-TimingOutDeferred.test_deferredThatNeverFiresc                 C   s   d S r   r   r   r   r   r   
test_omega   s    zTimingOutDeferred.test_omegaN)r   r   r   rK   rL   rM   r   r   r   r   rJ      s   rJ   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    rN   N)#r!   Z
__future__r   r   Ztwisted.trialr   r   Ztwisted.internetr   r   r   r3   r	   objectr   ZSynchronousTestCaser   ZTestCaser   r   r   r   r   r"   r#   r$   r+   r5   r9   skipr:   rC   rG   rJ   rN   r   r   r   r   <module>   sR   	
 
 	
 
 
 
 