U
    
W[
  ã                   @   sV   d Z ddlmZm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}.
é    )ÚdivisionÚabsolute_importN)Úfailure)Údefer)Ú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   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   s   dd S r   r
   r
   r
   r
   r   r      r   zOAsynchronousAssertionsTests.test_assertFailure_wrongException.<locals>.<lambda>c                    s
   ˆ   d¡S ©NzShould have failed©Úfail©Úx©r   r
   r   r      r   c                    s   |   ˆ j¡S ©N©ZtrapÚfailureExceptionr   r   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                    s
   ˆ   d¡S r   r   r   r   r
   r   r   &   r   zLAsynchronousAssertionsTests.test_assertFailure_noException.<locals>.<lambda>c                    s   |   ˆ j¡S r   r   r   r   r
   r   r   '   r   )r   Zsucceedr   r   r   r   r
   r   r   Útest_assertFailure_noException#   s    

ÿz:AsynchronousAssertionsTests.test_assertFailure_noExceptionc                 C   sR   zdd  W n& t k
r2   t ¡ }t |¡}Y nX |  |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   ZFailurer   r   r   ÚRuntimeErrorZ
addErrbackÚ
_checkInfo)r   Úfr   r
   r
   r   Útest_assertFailure_moreInfo+   s    z7AsynchronousAssertionsTests.test_assertFailure_moreInfoc                 C   s<   |  | j¡st‚| ¡ }|  | ¡ |¡ |  | ¡ |¡ d S r   )Zcheckr   ÚAssertionErrorZgetErrorMessageZassertInZgetBriefTraceback)r   Z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   r+   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   s   dd S r   r
   r
   r
   r
   r   r   K   r   zfAsynchronousAssertionsTests.test_assertFailure_masked.<locals>.TC.test_assertFailure.<locals>.<lambda>)r   r   r   r   r   r   r
   r
   r   r   J   s    zTAsynchronousAssertionsTests.test_assertFailure_masked.<locals>.TC.test_assertFailureN)r(   r)   r*   r   r   r
   ©r+   r
   r   ÚTCH   s   r-   r   r	   N)	Ú	Exceptionr   ÚTestCaseÚpyunitZ
TestResultÚrunZassertEqualÚlenZfailures)r   r-   ZtestÚresultr
   r,   r   Útest_assertFailure_maskedA   s    
z5AsynchronousAssertionsTests.test_assertFailure_maskedN)
r(   r)   r*   Ú__doc__r   r    r!   r%   r#   r4   r
   r
   r
   r   r      s   r   )r5   Z
__future__r   r   r   r0   Ztwisted.pythonr   Ztwisted.internetr   Ztwisted.trialr/   r   r
   r
   r
   r   Ú<module>   s   