o
    9»BiÁ*  ã                   @  s¬   d Z ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
mZmZ ddlm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ƒZG dd„ deƒZ[dS )z0
Tests for returning Deferreds from a TestCase.
é    )ÚannotationsN)Údefer)ÚFailure)ÚreporterÚunittestÚutil)Údetestsc                   @  sH   e Zd Zddd„Zddd	„Zdd
d„Zddd„Zddd„Zddd„ZdS )Ú
SetUpTestsÚklassútype[pyunit.TestCase]Úreturnú,tuple[reporter.TestResult, pyunit.TestSuite]c                 C  ó"   t  ¡ }t ¡ }| |¡}||fS ©N©ÚpyunitÚ
TestLoaderr   Ú
TestResultÚloadTestsFromTestCase©Úselfr
   ÚloaderÚrÚs© r   ú`/var/www/html/Trade-python/venv/lib/python3.10/site-packages/twisted/trial/test/test_deferred.pyÚ
_loadSuite   ó   
zSetUpTests._loadSuiteÚNonec                 C  s8   |   tj¡\}}||ƒ |  | ¡ ¡ |  |jd¡ d S )Né   )r   r   ÚDeferredSetUpOKÚ
assertTrueÚwasSuccessfulÚassertEqualÚtestsRun©r   ÚresultÚsuiter   r   r   Útest_success   s   zSetUpTests.test_successc                 C  óx   |   tjj¡ |  tj¡\}}||ƒ |   | ¡ ¡ |  |jd¡ |  t|j	ƒd¡ |  t|j
ƒd¡ |   tjj¡ d S ©Nr   r   )ÚassertFalser   ÚDeferredSetUpFailÚ
testCalledr   r"   r#   r$   ÚlenÚfailuresÚerrorsr%   r   r   r   Ú	test_fail    ó   zSetUpTests.test_failc                 C  r)   r*   )r+   r   ÚDeferredSetUpCallbackFailr-   r   r"   r#   r$   r.   r/   r0   r%   r   r   r   Útest_callbackFail*   r2   zSetUpTests.test_callbackFailc                 C  r)   r*   )r+   r   ÚDeferredSetUpErrorr-   r   r"   r#   r$   r.   r/   r0   r%   r   r   r   Ú
test_error4   r2   zSetUpTests.test_errorc                 C  sŠ   |   tjj¡ |  tj¡\}}||ƒ |  | ¡ ¡ |  |jd¡ |  t	|j
ƒd¡ |  t	|jƒd¡ |  t	|jƒd¡ |   tjj¡ d S r*   )r+   r   ÚDeferredSetUpSkipr-   r   r!   r"   r#   r$   r.   r/   r0   Úskipsr%   r   r   r   Ú	test_skip>   s   zSetUpTests.test_skipN©r
   r   r   r   ©r   r   )	Ú__name__Ú
__module__Ú__qualname__r   r(   r1   r4   r6   r9   r   r   r   r   r	      s    







r	   c                   @  s4   e Zd Zddd„Zddd„Zdd
d„Zddd„ZdS )ÚNeverFireTestsr   r   c                 C  s   t j| _dt _d S )Ngš™™™™™¹?)r   ÚDEFAULT_TIMEOUT_DURATIONÚ_oldTimeout©r   r   r   r   ÚsetUpK   s   
zNeverFireTests.setUpc                 C  s   | j t_d S r   )rA   r   r@   rB   r   r   r   ÚtearDownO   s   zNeverFireTests.tearDownr
   r   r   c                 C  r   r   r   r   r   r   r   r   R   r   zNeverFireTests._loadSuitec                 C  s¬   |   tjj¡ |  tj¡\}}||ƒ |   | ¡ ¡ |  |jd¡ |  t|j	ƒd¡ |  t|j
ƒd¡ |   tjj¡ t|j
d d tƒsFJ ‚|  |j
d d  tj¡¡ d S r*   )r+   r   ÚDeferredSetUpNeverFirer-   r   r"   r#   r$   r.   r/   r0   Ú
isinstancer   r!   Úcheckr   ÚTimeoutErrorr%   r   r   r   Ú
test_setUpZ   s    zNeverFireTests.test_setUpNr;   r:   )r<   r=   r>   rC   rD   r   rI   r   r   r   r   r?   J   s
    


r?   c                   @  s    e Zd Zddd„Zddd	„Zd
S )Ú
TestTesterÚnameÚstrr   úpyunit.TestCasec                 C  s   t dƒ‚)Nzmust override me)ÚNotImplementedError©r   rK   r   r   r   ÚgetTesth   s   zTestTester.getTestúreporter.TestResultc                 C  s   t  ¡ }|  |¡ |¡ |S r   )r   r   rP   Úrun)r   rK   r&   r   r   r   ÚrunTestk   s   zTestTester.runTestN)rK   rL   r   rM   )rK   rL   r   rQ   )r<   r=   r>   rP   rS   r   r   r   r   rJ   g   s    
rJ   c                   @  sf   e Zd Zddd„Zddd	„Zdd
d„Zddd„Zddd„Zddd„Zddd„Z	ddd„Z
ddd„ZdS )ÚDeferredTestsrK   rL   r   údetests.DeferredTestsc                 C  ó
   t  |¡S r   )r   rT   rO   r   r   r   rP   r   ó   
zDeferredTests.getTestr   c                 C  ó*   |   d¡}|  | ¡ ¡ |  |jd¡ d S ©NÚ	test_passr   ©rS   r!   r"   r#   r$   ©r   r&   r   r   r   rZ   u   ó   
zDeferredTests.test_passc                 C  s8   |   d¡}|  | ¡ ¡ |  |jd¡ |  tjj¡ dS )zQ
        The body of a L{defer.inlineCallbacks} decorated test gets run.
        Útest_passInlineCallbacksr   N)rS   r!   r"   r#   r$   r   rT   Útouchedr\   r   r   r   r^   z   s   
z&DeferredTests.test_passInlineCallbacksc                 C  ó<   |   d¡}|  | ¡ ¡ |  |jd¡ |  t|jƒd¡ d S )Nr1   r   ©rS   r+   r"   r#   r$   r.   r/   r\   r   r   r   r1   ƒ   ó   
zDeferredTests.test_failc                 C  r`   )NÚtest_failureInCallbackr   ra   r\   r   r   r   rc   ‰   rb   z$DeferredTests.test_failureInCallbackc                 C  r`   )NÚtest_errorInCallbackr   )rS   r+   r"   r#   r$   r.   r0   r\   r   r   r   rd      rb   z"DeferredTests.test_errorInCallbackc                 C  sJ   |   d¡}|  | ¡ ¡ |  |jd¡ |  t|jƒd¡ |  tj	j
¡ d S ©Nr9   r   )rS   r!   r"   r#   r$   r.   r8   r+   r   rT   r_   r\   r   r   r   r9   •   s
   
zDeferredTests.test_skipc                 C  s`   |   d¡}|  | ¡ ¡ |  |jd¡ |  t|jƒd¡ |  t|jƒd¡ |  t|jƒd¡ d S )NÚtest_expectedFailurer   r   )	rS   r!   r"   r#   r$   r.   r0   r/   ÚexpectedFailuresr\   r   r   r   Ú	test_todoœ   s   
zDeferredTests.test_todoc                 C  s.   |   d¡}|  |jd¡ |  | ¡ |j¡ d S )NÚtest_threadr   )rS   r#   r$   r!   r"   r0   r\   r   r   r   ri   ¤   s   
zDeferredTests.test_threadN)rK   rL   r   rU   r;   )r<   r=   r>   rP   rZ   r^   r1   rc   rd   r9   rh   ri   r   r   r   r   rT   q   s    



	



rT   c                   @  sŽ   e Zd Zd$dd„Zd%dd„Zd&dd„Zd&dd„Zd&dd„Zd&dd„Zd&dd„Z	d&dd„Z
d&dd„Zd&dd„Zd&dd„Zd&dd „Zd&d!d"„Zd#S )'ÚTimeoutTestsrK   rL   r   údetests.TimeoutTestsc                 C  rV   r   )r   rj   rO   r   r   r   rP   «   rW   zTimeoutTests.getTestÚerrorr   ÚexpectedMessager   c                 C  s.   |   | tj¡tj¡ |  ||jjd ¡ d S )Nr   )r#   rG   r   rH   ÚassertInÚvalueÚargs)r   rl   rm   r   r   r   Ú_wasTimeout®   s   zTimeoutTests._wasTimeoutc                 C  rX   rY   r[   r\   r   r   r   rZ   ²   r]   zTimeoutTests.test_passc                 C  rX   )NÚtest_passDefaultr   r[   r\   r   r   r   rr   ·   r]   zTimeoutTests.test_passDefaultc                 C  ój   |   d¡}|  | ¡ ¡ |  |jd¡ |  t|jƒd¡ t|jd d tƒs(J ‚|  	|jd d d¡ d S )NÚtest_timeoutr   r   z((test_timeout) still running at 0.1 secs©
rS   r+   r"   r#   r$   r.   r0   rF   r   rq   r\   r   r   r   rt   ¼   ó   
ÿzTimeoutTests.test_timeoutc                 C  rs   )NÚtest_timeoutZeror   r   z,(test_timeoutZero) still running at 0.0 secsru   r\   r   r   r   rw   Æ   rv   zTimeoutTests.test_timeoutZeroc                 C  s*   |   d¡}|  | ¡ ¡ |  |jd¡ dS )z[
        See L{twisted.trial.test.detests.TimeoutTests.test_addCleanupPassDefault}
        Útest_addCleanupPassDefaultr   Nr[   r\   r   r   r   rx   Ð   s   
z'TimeoutTests.test_addCleanupPassDefaultc                 C  sj   |   d¡}|  | ¡ ¡ |  |jd¡ |  t|jƒd¡ t|jd d tƒs(J ‚|  	|jd d d¡ dS )zÍ
        See L{twisted.trial.test.detests.TimeoutTests.test_addCleanupTimeout}

        TODO: current test does not mock reactor and thus the test spends real time
        until the timeout fires.
        Útest_addCleanupTimeoutr   r   z4(cleanup function cleanup) still running at 0.1 secsNru   r\   r   r   r   ry   Ø   s   
ÿz#TimeoutTests.test_addCleanupTimeoutc                 C  r`   re   )rS   r!   r"   r#   r$   r.   r8   r\   r   r   r   r9   è   rb   zTimeoutTests.test_skipc                 C  rs   )Nrf   r   r   z0(test_expectedFailure) still running at 0.1 secs)
rS   r!   r"   r#   r$   r.   rg   rF   r   rq   r\   r   r   r   rh   î   s   
þzTimeoutTests.test_todoc                 C  sJ   |   d¡}|  | ¡ ¡ |  |jd¡ tjjd usJ ‚|  tjjd¡ d S )NÚtest_errorPropagationr   z1(test_errorPropagation) still running at 0.1 secs)	rS   r+   r"   r#   r$   r   rj   ÚtimedOutrq   r\   r   r   r   rz   ù   s   
þz"TimeoutTests.test_errorPropagationc                 C  sj   t  ¡ }| tj¡}t ¡ }| |¡ |  t	|j
ƒd¡ t|j
d d tƒs(J ‚|  |j
d d d¡ d S )Nr   r   z&(testMethod) still running at 0.2 secs)r   r   r   r   ÚTestClassTimeoutAttributer   r   rR   r#   r.   r0   rF   r   rq   )r   r   r'   r&   r   r   r   Útest_classTimeout  s   
zTimeoutTests.test_classTimeoutc                 C  st   ddl m} | d|j¡}|  d¡}| ¡ r| ¡  |  | ¡ ¡ t	|j
d d tƒs-J ‚|  |j
d d d¡ d S )Nr   )Úreactoré   Útest_calledButNeverCallbackr   z7(test_calledButNeverCallback) still running at 0.1 secs)Útwisted.internetr~   Ú	callLaterÚcrashrS   ÚactiveÚcancelr+   r"   rF   r0   r   rq   )r   r~   Úcallr&   r   r   r   Ú&test_callbackReturnsNonCallingDeferred  s   
þz3TimeoutTests.test_callbackReturnsNonCallingDeferredN)rK   rL   r   rk   )rl   r   rm   rL   r   r   r;   )r<   r=   r>   rP   rq   rZ   rr   rt   rw   rx   ry   r9   rh   rz   r}   r‡   r   r   r   r   rj   ª   s    














	rj   )Ú__doc__Ú
__future__r   r   r   r   r   Útwisted.python.failurer   Útwisted.trialr   r   Útwisted.trial.testr   ÚTestCaser	   r?   rJ   rT   rj   r   r   r   r   Ú<module>   s   9
9t