
    Vhh                         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y)zG
Test the interaction between trial and errors logged during test run.
    N)reactortask)failurelog)	_synctestreporterunittestc                  Z    	 ddz    S # t         $ r t        j                         } Y | S w xY w)z*
    Return a new, realistic failure.
       r   )ZeroDivisionErrorr   Failure)fs    K/home/dcms/DCMS/lib/python3.12/site-packages/twisted/trial/test/test_log.pymakeFailurer      s7    	A H  OOHs   	 **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	y)	Maskz?
    Hide C{MockTest}s from Trial's automatic test finder.
    c                   $    e Zd Zd Zd Zd Zd Zy)Mask.FailureLoggingMixinc                      y)z/
            Don't log any errors.
            N selfs    r   test_silentz$Mask.FailureLoggingMixin.test_silent    s        c                 >    t        j                  t                      y)z-
            Log a single error.
            Nr   errr   r   s    r   test_singlez$Mask.FailureLoggingMixin.test_single%   s     GGKM"r   c                 x    t        j                  t                      t        j                  t                      y)z)
            Log two errors.
            Nr   r   s    r   test_doublez$Mask.FailureLoggingMixin.test_double+   s      GGKM"GGKM"r   c                 H    t        j                  t                      ddz    y)z8
            Log a single error, then fail.
            r   Nr   r   s    r   test_singleThenFailz,Mask.FailureLoggingMixin.test_singleThenFail2   s     GGKM"Hr   N)__name__
__module____qualname__r   r   r    r"   r   r   r   FailureLoggingMixinr      s    	
	#	#	r   r&   c                       e Zd Zy)Mask.SynchronousFailureLoggingN)r#   r$   r%   r   r   r   SynchronousFailureLoggingr(   9   s    r   r)   c                       e Zd Zd Zy)Mask.AsynchronousFailureLoggingc                 :    t        j                  t        dd       S )zC
            Log an error in an asynchronous callback.
            r   c                  <    t        j                  t                     S Nr   r   r   r   <lambda>zAMask.AsynchronousFailureLogging.test_inCallback.<locals>.<lambda>A   s    sww{}7M r   )r   
deferLaterr   r   s    r   test_inCallbackz/Mask.AsynchronousFailureLogging.test_inCallback=   s     ??7A/MNNr   N)r#   r$   r%   r1   r   r   r   AsynchronousFailureLoggingr+   <   s    	Or   r2   N)
r#   r$   r%   __doc__r&   r	   SynchronousTestCaser)   TestCaser2   r   r   r   r   r      s=     4$79U9U O%8(:K:K Or   r   c                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)ObserverTestsz
    Tests for L{_synctest._LogObserver}, a helper for the implementation of
    L{SynchronousTestCase.flushLoggedErrors}.
    c                 h    t        j                         | _        t        j                         | _        y r.   )r   
TestResultresultr   _LogObserverobserverr   s    r   setUpzObserverTests.setUpJ   s"    ))+!..0r   c                     | j                   j                  dt        j                         ddd       | j                  | j                   j	                         g        y)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   sL     	,				
 	002B7r   c           	          t               }| j                  j                  dt        j                         dd|dd       | j	                  | j                  j                         |g       y)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\   s[     M				
 	002QC8r   c                 0   | j                          | j                  j                         }| j                  | j                  j	                         g        | j                  t        |      d       | j                  |d   j                  t                     y)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   sm     	--++-002B7Wq)
(():;<r   c                 >    t        j                  t        d            S )Nz
test error)r   r   RuntimeErrorr   s    r   _makeRuntimeFailurez!ObserverTests._makeRuntimeFailurew   s    |L9::r   c           
         | j                          | j                         }| j                  j                  t	        dt        j
                         dd|d             | j                  j                  t              }| j                  | j                  j                         |g       | j                  t        |      d       | j                  |d   j                  t                     y)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2QC8Wq)
(():;<r   c           	         | j                   j                  t               t               }| j                   j	                  dt        j
                         dd|dd       | j                  | j                   j                         g        y)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   sl     	##$56M				
 	002B7r   c           	      H   | j                   j                  t               | j                   j                          t	               }| j                   j                  dt        j                         dd|dd       | j                  | j                   j                         |g       y)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##%M				
 	002QC8r   N)r#   r$   r%   r3   r=   rG   rL   rS   rV   rY   r\   r_   r   r   r   r7   r7   D   s/    
189"=;= 8$9r   r7   c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
LogErrorsMixinzb
    High-level tests demonstrating the expected behaviour of logged errors
    during tests.
    c                 6    t        j                         | _        y r.   )r   r9   r:   r   s    r   r=   zLogErrorsMixin.setUp   s    ))+r   c                 .    | j                  t               y r.   )flushLoggedErrorsr   r   s    r   tearDownzLogErrorsMixin.tearDown   s    01r   c                    | j                  d      } || j                         | j                  t        | j                  j                        d       | j                  | j                  j                  d   d   j                  t              | j                  j                  d   d          | j                  d| j                  j                         y)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!4KKq!!$**+<=t{{?Q?QRS?TUV?W	
 	DKK112r   c                     | j                  d      } || j                         | j                  t        | j                  j                        d       | j                  d| j                  j
                         y)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   sW    
 }}]+T[[T[[//0!4DKK112r   c                    | j                  d      }| j                  d      } || j                          || j                         | j                  t        | j                  j                        d       | j                  | j                  j                  d   d   |       | j                  d| j                  j
                         y)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!4++A.q126DKK112r   c                    | j                  d      }| j                  d      } || j                          || j                         | j                  t        | j                  j                        d       | j                  | j                  j                  d   d   |       | j                  j                  d   d   j                  t               | j                  | j                  j                  d   d   |       | j                  j                  d   d   j                  t               | j                  d| j                  j                         y)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]]=)
4;;
4;;T[[//0!4++A.q1261a %%i0++A.q1261a %%&78DKK112r   c                 ,   t        j                         }| j                  t         d|       t        j                  j
                  dd }| j                         } || j                         | j                  |t        j                  j
                         y)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   sk    
 ))+

9nh7''11!4	}}T[[C$7$7$A$ABr   N)r#   r$   r%   r3   r=   re   rl   rp   ru   ry   r   r   r   r   ra   ra      s+    
,2
33
33$
Cr   ra   c                   $    e Zd Zej                  Zy)SynchronousLogErrorsTestsN)r#   r$   r%   r   r)   rg   r   r   r   r   r      s    --Hr   r   c                   *    e Zd Zej                  Zd Zy)AsynchronousLogErrorsTestsc                 Z   | j                  d      } || j                         | j                  t        | j                  j                        d       | j                  | j                  j                  d   d   j                  t              | j                  j                  d   d          y)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!4KKq!!$**+<=t{{?Q?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      sy     * ' 7 7'O 'OTj9H00 j9ZJC JCZ.0L0L .
1B1B 
r   