o
    Óó·ih  ã                   @   s¢   d Z ddlZddlmZmZ ddlmZmZ ddlm	Z	m
Z
mZ dd„ ZG dd	„ d	ƒZG d
d„ dejƒZG dd„ dƒZG dd„ deejƒZG dd„ deejƒZdS )zG
Test the interaction between trial and errors logged during test run.
é    N)ÚreactorÚtask)ÚfailureÚlog)Ú	_synctestÚreporterÚunittestc                  C   s,   zdd  W | S  t y   t ¡ } Y | S w )z*
    Return a new, realistic failure.
    é   r   N)ÚZeroDivisionErrorr   ÚFailure)Úf© r   úaC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/trial/test/test_log.pyÚmakeFailure   s   
þ
þr   c                   @   sF   e Zd ZdZG dd„ dƒZG dd„ deejƒZG dd„ deejƒZ	dS )	ÚMaskz?
    Hide C{MockTest}s from Trial's automatic test finder.
    c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
zMask.FailureLoggingMixinc                 C   s   dS )z/
            Don't log any errors.
            Nr   ©Úselfr   r   r   Útest_silent    s    z$Mask.FailureLoggingMixin.test_silentc                 C   s   t  tƒ ¡ dS )z-
            Log a single error.
            N©r   Úerrr   r   r   r   r   Útest_single%   s   z$Mask.FailureLoggingMixin.test_singlec                 C   s   t  tƒ ¡ t  tƒ ¡ dS )z)
            Log two errors.
            Nr   r   r   r   r   Útest_double+   s   z$Mask.FailureLoggingMixin.test_doublec                 C   s   t  tƒ ¡ dd  dS )z8
            Log a single error, then fail.
            r	   Nr   r   r   r   r   Útest_singleThenFail2   s   z,Mask.FailureLoggingMixin.test_singleThenFailN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r   ÚFailureLoggingMixin   s
    r   c                   @   s   e Zd ZdS )zMask.SynchronousFailureLoggingN)r   r   r   r   r   r   r   ÚSynchronousFailureLogging9   s    r   c                   @   s   e Zd Zdd„ ZdS )zMask.AsynchronousFailureLoggingc                 C   s   t  tddd„ ¡S )zC
            Log an error in an asynchronous callback.
            r   c                   S   s   t  tƒ ¡S ©Nr   r   r   r   r   Ú<lambda>A   s    zAMask.AsynchronousFailureLogging.test_inCallback.<locals>.<lambda>N)r   Z
deferLaterr   r   r   r   r   Útest_inCallback=   s   z/Mask.AsynchronousFailureLogging.test_inCallbackN)r   r   r   r    r   r   r   r   ÚAsynchronousFailureLogging<   s    r!   N)
r   r   r   Ú__doc__r   r   ÚSynchronousTestCaser   ÚTestCaser!   r   r   r   r   r      s
    r   c                   @   sP   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d„ Z
dd„ ZdS )ÚObserverTestsz
    Tests for L{_synctest._LogObserver}, a helper for the implementation of
    L{SynchronousTestCase.flushLoggedErrors}.
    c                 C   s   t  ¡ | _t ¡ | _d S r   )r   Ú
TestResultÚresultr   Ú_LogObserverÚobserverr   r   r   r   ÚsetUpJ   s   
zObserverTests.setUpc                 C   s0   | j  dt ¡ dddœ¡ |  | j  ¡ g ¡ dS )zW
        Test that a standard log message doesn't go anywhere near the result.
        )zsome messager   ú-)ÚmessageÚtimeÚisErrorÚsystemN)r)   ÚgotEventr-   ÚassertEqualÚ	getErrorsr   r   r   r   Útest_msgN   s   üÿzObserverTests.test_msgc              	   C   s<   t ƒ }| j dt ¡ dd|ddœ¡ |  | j ¡ |g¡ dS )zF
        Test that an observed error gets added to the result
        r   r	   r+   N©r,   r-   r.   r/   r   Úwhy)r   r)   r0   r-   r1   r2   ©r   r   r   r   r   Ú
test_error\   s   úÿ
zObserverTests.test_errorc                 C   sL   |   ¡  | j ¡ }|  | j ¡ g ¡ |  t|ƒd¡ |  |d  t¡¡ dS )zS
        Check that flushing the observer with no args removes all errors.
        r	   r   N)	r7   r)   ÚflushErrorsr1   r2   ÚlenÚ
assertTrueÚcheckr
   )r   Úflushedr   r   r   Ú
test_flushm   s
   
zObserverTests.test_flushc                 C   s   t  tdƒ¡S )Nz
test error)r   r   ÚRuntimeErrorr   r   r   r   Ú_makeRuntimeFailurew   ó   z!ObserverTests._makeRuntimeFailurec              
   C   sx   |   ¡  |  ¡ }| j tdt ¡ dd|dd�¡ | j t¡}|  | j 	¡ |g¡ |  t
|ƒd¡ |  |d  t¡¡ dS )zY
        Check that flushing the observer remove all failures of the given type.
        r   r	   r+   Nr4   r   )r7   r?   r)   r0   Údictr-   r8   r
   r1   r2   r9   r:   r;   )r   r   r<   r   r   r   Útest_flushByTypez   s   ÿÿzObserverTests.test_flushByTypec              	   C   sF   | j  t¡ tƒ }| j  dt ¡ dd|ddœ¡ |  | j  ¡ g ¡ dS )zS
        Check that C{_ignoreErrors} actually causes errors to be ignored.
        r   r	   r+   Nr4   )r)   Ú_ignoreErrorsr
   r   r0   r-   r1   r2   r6   r   r   r   Útest_ignoreErrorsŠ   s   úÿ
zObserverTests.test_ignoreErrorsc              	   C   sR   | j  t¡ | j  ¡  tƒ }| j  dt ¡ dd|ddœ¡ |  | j  ¡ |g¡ dS )zj
        Check that C{_clearIgnores} ensures that previously ignored errors
        get captured.
        r   r	   r+   Nr4   )	r)   rC   r
   Z_clearIgnoresr   r0   r-   r1   r2   r6   r   r   r   Útest_clearIgnoresœ   s   
úÿ
zObserverTests.test_clearIgnoresN)r   r   r   r"   r*   r3   r7   r=   r?   rB   rD   rE   r   r   r   r   r%   D   s    
r%   c                   @   sH   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d„ Z
dS )ÚLogErrorsMixinzb
    High-level tests demonstrating the expected behaviour of logged errors
    during tests.
    c                 C   s   t  ¡ | _d S r   )r   r&   r'   r   r   r   r   r*   ·   r@   zLogErrorsMixin.setUpc                 C   s   |   t¡ d S r   )ZflushLoggedErrorsr
   r   r   r   r   ÚtearDownº   r@   zLogErrorsMixin.tearDownc                 C   sf   |   d¡}|| jƒ |  t| jjƒd¡ |  | jjd d  t¡| jjd d ¡ |  d| jj¡ dS )zI
        Test that a logged error gets reported as a test error.
        r   r	   r   N)	ÚMockTestr'   r1   r9   Úerrorsr:   r;   r
   Ú	successes©r   Útestr   r   r   Útest_singleError½   s   

"ÿzLogErrorsMixin.test_singleErrorc                 C   s<   |   d¡}|| jƒ |  t| jjƒd¡ |  d| jj¡ dS )zf
        Test that when two errors get logged, they both get reported as test
        errors.
        r   é   r   N©rH   r'   r1   r9   rI   rJ   rK   r   r   r   Útest_twoErrorsÉ   s   

zLogErrorsMixin.test_twoErrorsc                 C   sh   |   d¡}|   d¡}|| jƒ || jƒ |  t| jjƒd¡ |  | jjd d |¡ |  d| jj¡ dS )zT
        Check that an error logged in one test doesn't fail the next test.
        r   r   r	   r   NrO   ©r   Út1Út2r   r   r   Útest_errorsIsolatedÓ   s   



z"LogErrorsMixin.test_errorsIsolatedc                 C   s¬   |   d¡}|   d¡}|| jƒ || jƒ |  t| jjƒd¡ |  | jjd d |¡ | jjd d  t¡ |  | jjd d |¡ | jjd d  t¡ |  d| jj¡ dS )zN
        An error logged in a failed test doesn't fail the next test.
        r   r   rN   r   r	   N)	rH   r'   r1   r9   rI   ZtrapÚ	TypeErrorr
   rJ   rQ   r   r   r   Ú test_errorsIsolatedWhenTestFailsß   s   



z/LogErrorsMixin.test_errorsIsolatedWhenTestFailsc                 C   sL   t  ¡ }|  t d|¡ tjjdd… }|  ¡ }|| jƒ |  |tjj¡ dS )zE
        There are no extra log observers after a test runs.
        Z_logObserverN)	r   r(   Úpatchr   ZtheLogPublisherÚ	observersrH   r'   r1   )r   r)   rX   rL   r   r   r   Útest_boundedObserversñ   s   
z$LogErrorsMixin.test_boundedObserversN)r   r   r   r"   r*   rG   rM   rP   rT   rV   rY   r   r   r   r   rF   ±   s    
rF   c                   @   s   e Zd ZejZdS )ÚSynchronousLogErrorsTestsN)r   r   r   r   r   rH   r   r   r   r   rZ   þ   s    
rZ   c                   @   s   e Zd ZejZdd„ ZdS )ÚAsynchronousLogErrorsTestsc                 C   sV   |   d¡}|| jƒ |  t| jjƒd¡ |  | jjd d  t¡| jjd d ¡ dS )zS
        Test that errors logged in callbacks get reported as test errors.
        r    r	   r   N)rH   r'   r1   r9   rI   r:   r;   r
   rK   r   r   r   r      s   

"ÿz*AsynchronousLogErrorsTests.test_inCallbackN)r   r   r   r   r!   rH   r    r   r   r   r   r[     s    r[   )r"   r-   Ztwisted.internetr   r   Ztwisted.pythonr   r   Ztwisted.trialr   r   r   r   r   r#   r%   rF   rZ   r$   r[   r   r   r   r   Ú<module>   s   *mM