U
     T‚gÁ  ã                   @   sº  d Z ddlmZ ddlmZmZmZ ddlmZ ddl	mZm
Z
 G dd„ deƒ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!G d0d1„ d1ejƒZ"d2S )3aJ  
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.

Some of these tests are also used by L{twisted.trial._dist.test}.
é    )ÚskipIf)ÚdeferÚprotocolÚreactor)Ú
deferLater)ÚunittestÚutilc                   @   s   e Zd ZdS )ÚFoolishErrorN©Ú__name__Ú
__module__Ú__qualname__© r   r   ú@/tmp/pip-unpacked-wheel-1_7di8ic/twisted/trial/test/erroneous.pyr	      s   r	   c                   @   s(   e Zd ZdZeddœdd„Zdd„ ZdS )Ú
LargeErrorzj
    An exception which has a string representation of at least a specified
    number of characters.
    N)ÚminSizeÚreturnc                 C   s   t  | ¡ || _d S ©N)Ú	ExceptionÚ__init__r   )Úselfr   r   r   r   r   !   s    
zLargeError.__init__c                 C   s   d| j  }d|› d�S )NÚxzLargeError<I fail: ú>)r   )r   Zlarger   r   r   Ú__str__%   s    
zLargeError.__str__)r   r   r   Ú__doc__Úintr   r   r   r   r   r   r      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	   ©r   r   r   r   ÚsetUp+   s    zFailureInSetUpMixin.setUpc                 C   s   d S r   r   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!   2   s   r!   c                   @   s   e Zd ZdS )ÚAsynchronousTestFailureInSetUpNr
   r   r   r   r   r"   6   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    >   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%   B   s   r%   c                   @   s   e Zd ZdS )Ú!AsynchronousTestFailureInTearDownNr
   r   r   r   r   r&   H   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$   S   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_failsV   s    z&FailureButTearDownRunsMixin.test_failsN)r   r   r   r   r)   r$   r*   r   r   r   r   r'   L   s   r'   c                   @   s   e Zd ZdS )Ú%SynchronousTestFailureButTearDownRunsNr
   r   r   r   r   r+   ]   s   r+   c                   @   s   e Zd ZdS )Ú&AsynchronousTestFailureButTearDownRunsNr
   r   r   r   r   r,   c   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_failj   s    zTestRegularFail.test_failc                 C   s   |   ¡  d S r   )Ú
subroutiner   r   r   r   Útest_subfailm   s    zTestRegularFail.test_subfailc                 C   s   |   d¡ d S )NzI fail insider/   r   r   r   r   r2   p   s    zTestRegularFail.subroutineN)r   r   r   r1   r3   r2   r   r   r   r   r-   i   s   r-   c                   @   sf   e Zd ZdZdZejd dœdd„Zejd dœdd„Zddœd	d
„Z	ddœdd„Z
ddœdd„ZdS )ÚTestAsynchronousFailz?
    Test failures for L{unittest.TestCase} based classes.
    r.   N)r   c                 C   s   t td| jdƒS )zW
        A test which fails in the callback of the returned L{defer.Deferred}.
        r   zI fail later©r   r   r0   r   r   r   r   r1   {   s    zTestAsynchronousFail.test_failc                 C   s   t td| jddd  ƒS )zw
        A test which fails in the callback of the returned L{defer.Deferred}
        with a very long string.
        r   zI fail later: r   é   r5   r   r   r   r   Útest_failGreaterThan64k�   s    z,TestAsynchronousFail.test_failGreaterThan64kc                 C   s   t | jƒ‚dS )zA
        A test which raises an exception synchronously.
        N)r   Útextr   r   r   r   Útest_exceptionˆ   s    z#TestAsynchronousFail.test_exceptionc                 C   s   t dƒ‚dS )zk
        A test which raises an exception with a long string representation
        synchronously.
        r6   N)r   r   r   r   r   Útest_exceptionGreaterThan64kŽ   s    z1TestAsynchronousFail.test_exceptionGreaterThan64kc                 C   s   t dd ƒ‚dS )z‡
        A test which synchronously raises an exception with a long string
        representation including non-ascii content.
        u   â˜ƒi €  N)r   r   r   r   r   Ú#test_exceptionGreaterThan64kEncoded•   s    	z8TestAsynchronousFail.test_exceptionGreaterThan64kEncoded)r   r   r   r   r8   r   ÚDeferredr1   r7   r9   r:   r;   r   r   r   r   r4   t   s   r4   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   r?   r@   r   r   r   r   r=   ¡   s   r=   Tzskipping this testc                   @   s   e Zd ZdS )ÚTestSkipTestCaseNr
   r   r   r   r   rA   ²   s   rA   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ƒ‚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{®Gáz„?z/Deliberate failure to mask the hidden exceptionN)r   Ú	callLaterrE   Ziterater0   r   r   r   r   ÚtestHiddenException½   s    
zDelayedCall.testHiddenExceptionz!reactor\.iterate cannot be used.*)ÚmessageÚcategoryN)	r   r   r   rD   rE   rG   r   ÚsuppressÚDeprecationWarningr   r   r   r   rB   ·   s    ÿÿrB   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   rF   )r   rN   r   r   r   Útest_leftoverPendingCallsÕ   s    z-ReactorCleanupTests.test_leftoverPendingCallsN)r   r   r   rO   r   r   r   r   rL   Ô   s   rL   c                   @   s   e Zd Zdd„ ZdS )ÚSocketOpenTestc                 C   s    t  ¡ }t j|_ t d|¡ d S )Nr   )r   ZFactoryÚProtocolr   Z	listenTCP)r   Úfr   r   r   Útest_socketsLeftOpenÝ   s    z#SocketOpenTest.test_socketsLeftOpenN)r   r   r   rS   r   r   r   r   rP   Ü   s   rP   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<   )r   Údr   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   rU   rW   rX   r   r   r   r   rT   ã   s   rT   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    rY   c                   @   s&   e Zd ZU dZdZeed< dd„ ZdS )ÚEventuallyFailingTestCasez>
    A test suite that fails after it is run a few times.
    r   Únc                 C   s&   |  j d7  _ | j dkr"|  d¡ dS )zK
        Run successfully a few times and then fail forever after.
        r>   é   zeventually failingN)r[   r0   r   r   r   r   Útest_itÿ   s    
z!EventuallyFailingTestCase.test_itN)r   r   r   r   r[   r   Ú__annotations__r]   r   r   r   r   rZ   ø   s   
rZ   N)#r   r   r   Ztwisted.internetr   r   r   Ztwisted.internet.taskr   Ztwisted.trialr   r   r	   r   r   ZSynchronousTestCaser!   ZTestCaser"   r#   r%   r&   r'   r+   r,   r-   r4   r=   rA   rB   rL   rP   rT   rY   rZ   r   r   r   r   Ú<module>   sF   
 ÿ
 ÿ
 ÿ-