
    tfh                         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 Z G d d          Z G d	 d
ej                  Z G d d          Z G d deej                  Z G 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                  Z    	 ddz   n## t           $ r t          j                    } Y nw xY w| S )z*
    Return a new, realistic failure.
       r   )ZeroDivisionErrorr   Failure)fs    Z/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/trial/test/test_log.pymakeFailurer      sC    	A   OHs    ((c                   |    e Zd ZdZ G d d          Z G d deej                  Z G d deej                  Z	dS )	Maskz?
    Hide C{MockTest}s from Trial's automatic test finder.
    c                   &    e Zd Zd Zd Zd Zd ZdS )Mask.FailureLoggingMixinc                     dS )z/
            Don't log any errors.
            N selfs    r   test_silentz$Mask.FailureLoggingMixin.test_silent    s          c                 F    t          j        t                                 dS )z-
            Log a single error.
            Nr   errr   r   s    r   test_singlez$Mask.FailureLoggingMixin.test_single%   s     GKMM"""""r   c                     t          j        t                                 t          j        t                                 dS )z)
            Log two errors.
            Nr   r   s    r   test_doublez$Mask.FailureLoggingMixin.test_double+   s2     GKMM"""GKMM"""""r   c                 P    t          j        t                                 ddz    dS )z8
            Log a single error, then fail.
            r   Nr   r   s    r   test_singleThenFailz,Mask.FailureLoggingMixin.test_singleThenFail2   s%     GKMM"""HHHHr   N)__name__
__module____qualname__r   r   r    r"   r   r   r   FailureLoggingMixinr      sP        	 	 	
	# 	# 	#	# 	# 	#	 	 	 	 	r   r&   c                       e Zd ZdS )Mask.SynchronousFailureLoggingN)r#   r$   r%   r   r   r   SynchronousFailureLoggingr(   9   s        r   r)   c                       e Zd Zd ZdS )Mask.AsynchronousFailureLoggingc                 :    t          j        t          dd           S )zC
            Log an error in an asynchronous callback.
            r   c                  B    t          j        t                                S Nr   r   r   r   <lambda>zAMask.AsynchronousFailureLogging.test_inCallback.<locals>.<lambda>A   s    sw{}}7M7M r   )r   
deferLaterr   r   s    r   test_inCallbackz/Mask.AsynchronousFailureLogging.test_inCallback=   s     ?7A/M/MNNNr   N)r#   r$   r%   r1   r   r   r   AsynchronousFailureLoggingr+   <   s(        	O 	O 	O 	O 	Or   r2   N)
r#   r$   r%   __doc__r&   r	   SynchronousTestCaser)   TestCaser2   r   r   r   r   r      s                4    $79U   O O O O O%8(:K O O O O Or   r   c                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )ObserverTestsz
    Tests for L{_synctest._LogObserver}, a helper for the implementation of
    L{SynchronousTestCase.flushLoggedErrors}.
    c                 f    t          j                    | _        t          j                    | _        d S r.   )r   
TestResultresultr   _LogObserverobserverr   s    r   setUpzObserverTests.setUpJ   s&    )++!.00r   c                     | j                             dt          j                    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<   gotEventrA   assertEqual	getErrorsr   s    r   test_msgzObserverTests.test_msgN   sf     	,		 	
 	
 	
 	0022B77777r   c           	          t                      }| j                            dt          j                    dd|dd           |                     | j                                        |g           dS )zF
        Test that an observed error gets added to the result
        r   r   r?   Nr@   rA   rB   rC   r   why)r   r<   rD   rA   rE   rF   r   r   s     r   
test_errorzObserverTests.test_error\   sw     MM	 		
 		
 		
 	0022QC88888r   c                 f   |                                   | j                                        }|                     | j                                        g            |                     t          |          d           |                     |d                             t                               dS )zS
        Check that flushing the observer with no args removes all errors.
        r   r   N)	rL   r<   flushErrorsrE   rF   len
assertTruecheckr   )r   flusheds     r   
test_flushzObserverTests.test_flushm   s     	-++--0022B777Wq)))
(():;;<<<<<r   c                 D    t          j        t          d                    S )Nz
test error)r   r   RuntimeErrorr   s    r   _makeRuntimeFailurez!ObserverTests._makeRuntimeFailurew   s    |L99:::r   c           
         |                                   |                                 }| j                            t	          dt          j                    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?   NrI   r   )rL   rV   r<   rD   dictrA   rN   r   rE   rF   rO   rP   rQ   )r   r   rR   s      r   test_flushByTypezObserverTests.test_flushByTypez   s     	$$&&aQTX  	
 	
 	

 -++,=>>0022QC888Wq)))
(():;;<<<<<r   c           	         | j                             t                     t                      }| j                             dt          j                    dd|dd           |                     | j                                         g            dS )zS
        Check that C{_ignoreErrors} actually causes errors to be ignored.
        r   r   r?   NrI   )r<   _ignoreErrorsr   r   rD   rA   rE   rF   rK   s     r   test_ignoreErrorszObserverTests.test_ignoreErrors   s     	##$5666MM	 		
 		
 		
 	0022B77777r   c           	      R   | j                             t                     | j                                          t	                      }| j                             dt          j                    dd|dd           |                     | j                                         |g           dS )zj
        Check that C{_clearIgnores} ensures that previously ignored errors
        get captured.
        r   r   r?   NrI   )	r<   r[   r   _clearIgnoresr   rD   rA   rE   rF   rK   s     r   test_clearIgnoreszObserverTests.test_clearIgnores   s    
 	##$5666##%%%MM	 		
 		
 		
 	0022QC88888r   N)r#   r$   r%   r3   r=   rG   rL   rS   rV   rY   r\   r_   r   r   r   r7   r7   D   s         
1 1 18 8 89 9 9"= = =; ; ;= = = 8 8 8$9 9 9 9 9r   r7   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
LogErrorsMixinzb
    High-level tests demonstrating the expected behaviour of logged errors
    during tests.
    c                 6    t          j                    | _        d S r.   )r   r9   r:   r   s    r   r=   zLogErrorsMixin.setUp   s    )++r   c                 :    |                      t                     d S r.   )flushLoggedErrorsr   r   s    r   tearDownzLogErrorsMixin.tearDown   s    011111r   c                    |                      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:   rE   rO   errorsrP   rQ   r   	successesr   tests     r   test_singleErrorzLogErrorsMixin.test_singleError   s     }}]++T[T[/00!444Kq!!$**+<==t{?QRS?TUV?W	
 	
 	
 	DK122222r   c                     |                      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rg   r:   rE   rO   rh   ri   rj   s     r   test_twoErrorszLogErrorsMixin.test_twoErrors   sk    
 }}]++T[T[/00!444DK122222r   c                    |                      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t2s      r   test_errorsIsolatedz"LogErrorsMixin.test_errorsIsolated   s     ]]=))]]=))
4;
4;T[/00!444+A.q12666DK122222r   c                    |                      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)	rg   r:   rE   rO   rh   trap	TypeErrorr   ri   rr   s      r    test_errorsIsolatedWhenTestFailsz/LogErrorsMixin.test_errorsIsolatedWhenTestFails   s    ]]011]]=))
4;
4;T[/00!444+A.q126661a %%i000+A.q126661a %%&7888DK122222r   c                 (   t          j                    }|                     t           d|           t          j        j        dd         }|                                 } || j                   |                     |t          j        j                   dS )zE
        There are no extra log observers after a test runs.
        _logObserverN)	r   r;   patchr   theLogPublisher	observersrg   r:   rE   )r   r<   r~   rk   s       r   test_boundedObserversz$LogErrorsMixin.test_boundedObservers   s}    
 )++

9nh777'1!!!4	}}T[C$7$ABBBBBr   N)r#   r$   r%   r3   r=   re   rl   rp   ru   ry   r   r   r   r   ra   ra      s         
, , ,2 2 2
3 
3 
33 3 3
3 
3 
33 3 3$
C 
C 
C 
C 
Cr   ra   c                       e Zd Zej        ZdS )SynchronousLogErrorsTestsN)r#   r$   r%   r   r)   rg   r   r   r   r   r      s        -HHHr   r   c                   "    e Zd Zej        Zd ZdS )AsynchronousLogErrorsTestsc                 ^   |                      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.
        r1   r   r   N)rg   r:   rE   rO   rh   rP   rQ   r   rj   s     r   r1   z*AsynchronousLogErrorsTests.test_inCallback  s     }}.//T[T[/00!444Kq!!$**+<==t{?QRS?TUV?W	
 	
 	
 	
 	
r   N)r#   r$   r%   r   r2   rg   r1   r   r   r   r   r     s+        .H	
 	
 	
 	
 	
r   r   )r3   rA   twisted.internetr   r   twisted.pythonr   r   twisted.trialr   r   r	   r   r   r4   r7   ra   r   r5   r   r   r   r   <module>r      s     * * * * * * * * ' ' ' ' ' ' ' ' 7 7 7 7 7 7 7 7 7 7  'O 'O 'O 'O 'O 'O 'O 'OTj9 j9 j9 j9 j9H0 j9 j9 j9ZJC JC JC JC JC JC JC JCZ. . . . .0L . . .
 
 
 
 
1B 
 
 
 
 
r   