o
    ¯bø	  ã                   @   sF   d Z ddlZddlmZ ddlmZ ddlmZ G dd„ dejƒZ	dS )zL
Tests for async assertions provided by C{twisted.trial.unittest.TestCase}.
é    N)Údefer)Úfailure)Úunittestc                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚAsynchronousAssertionsTestszp
    Tests for L{TestCase}'s asynchronous extensions to L{SynchronousTestCase}.
    That is, assertFailure.
    c                 C   s   t  dd„ ¡}|  |t¡S )Nc                   S   ó   dd S ©Né   r   © r	   r	   r	   úI/usr/lib/python3/dist-packages/twisted/trial/test/test_asyncassertions.pyÚ<lambda>   ó    z@AsynchronousAssertionsTests.test_assertFailure.<locals>.<lambda>)r   ÚmaybeDeferredÚassertFailureÚZeroDivisionError©ÚselfÚdr	   r	   r
   Útest_assertFailure   s   z.AsynchronousAssertionsTests.test_assertFailurec                    s:   t  dd„ ¡}ˆ  |t¡ | ‡ fdd„‡ fdd„¡ |S )Nc                   S   r   r   r	   r	   r	   r	   r
   r      r   zOAsynchronousAssertionsTests.test_assertFailure_wrongException.<locals>.<lambda>c                    ó
   ˆ   d¡S ©NzShould have failed©Úfail©Úx©r   r	   r
   r      ó   
 c                    ó   |   ˆ j¡S ©N©ÚtrapÚfailureExceptionr   r   r	   r
   r      ó    )r   r   r   ÚOverflowErrorÚaddCallbacksr   r	   r   r
   Ú!test_assertFailure_wrongException   s   

þz=AsynchronousAssertionsTests.test_assertFailure_wrongExceptionc                    s6   t  d ¡}ˆ  |t¡ | ‡ fdd„‡ fdd„¡ |S )Nc                    r   r   r   r   r   r	   r
   r   '   r   zLAsynchronousAssertionsTests.test_assertFailure_noException.<locals>.<lambda>c                    r   r   r   r   r   r	   r
   r   (   r!   )r   Úsucceedr   r   r#   r   r	   r   r
   Útest_assertFailure_noException#   s   


þz:AsynchronousAssertionsTests.test_assertFailure_noExceptionc                 C   sP   zdd  W n t y   t ¡ }t |¡}Y nw |  |t¡}| | j|¡ |S )zŠ
        In the case of assertFailure failing, check that we get lots of
        information about the exception that was raised.
        r   r   )	r   r   ÚFailurer   r   r   ÚRuntimeErrorÚ
addErrbackÚ
_checkInfo)r   Úfr   r	   r	   r
   Útest_assertFailure_moreInfo,   s   þz7AsynchronousAssertionsTests.test_assertFailure_moreInfoc                 C   s<   |  | j¡sJ ‚| ¡ }|  | ¡ |¡ |  | ¡ |¡ d S r   )Úcheckr    ÚgetErrorMessageÚassertInÚgetBriefTraceback)r   ÚassertionFailurer+   Úoutputr	   r	   r
   r*   :   s   z&AsynchronousAssertionsTests._checkInfoc                    sV   G dd„ dt ƒ‰ G ‡ fdd„dtjƒ}|dƒ}t ¡ }| |¡ |  dt|jƒ¡ dS )zJ
        A single wrong assertFailure should fail the whole test.
        c                   @   s   e Zd ZdS )zMAsynchronousAssertionsTests.test_assertFailure_masked.<locals>.ExampleFailureN)Ú__name__Ú
__module__Ú__qualname__r	   r	   r	   r
   ÚExampleFailureE   s    r6   c                       s   e Zd Z” Zdd„ ZdS )zAAsynchronousAssertionsTests.test_assertFailure_masked.<locals>.TCc                 S   s*   t  dd„ ¡}|  |t¡ |  |t¡ |S )Nc                   S   r   r   r	   r	   r	   r	   r
   r   L   r   zfAsynchronousAssertionsTests.test_assertFailure_masked.<locals>.TC.test_assertFailure.<locals>.<lambda>)r   r   r   r"   r   r   r	   r	   r
   r   K   s   zTAsynchronousAssertionsTests.test_assertFailure_masked.<locals>.TC.test_assertFailureN)r3   r4   r5   r    r   r	   ©r6   r	   r
   ÚTCH   s    r8   r   r   N)	Ú	Exceptionr   ÚTestCaseÚpyunitÚ
TestResultÚrunÚassertEqualÚlenÚfailures)r   r8   ÚtestÚresultr	   r7   r
   Útest_assertFailure_masked@   s   	
z5AsynchronousAssertionsTests.test_assertFailure_maskedN)
r3   r4   r5   Ú__doc__r   r$   r&   r,   r*   rC   r	   r	   r	   r
   r      s    		r   )
rD   r   r;   Útwisted.internetr   Útwisted.pythonr   Útwisted.trialr:   r   r	   r	   r	   r
   Ú<module>   s   