
    Vh-                     f    d dl mZ d dlmZ 	 d dlZeZd dlmZ  G d de      Z	y# e$ r dZY w xY w)    )Failure)TestCaseN)syslogc                   d    e Zd ZdZdZedZd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zy)SyslogObserverTestszS
    Tests for L{SyslogObserver} which sends Twisted log events to the syslog.
    Nz(syslog is not supported on this platformc                     | j                  t        j                  d| j                         | j                  t        j                  d| j                         t        j                  d      | _        y )Nopenlogr   r   )patchr   SyslogObserverr	   observerselfs    O/home/dcms/DCMS/lib/python3.12/site-packages/twisted/python/test/test_syslog.pysetUpzSyslogObserverTests.setUp   sI    

6(()T\\B

6(((DKK@--.CD    c                 &    |||f| _         g | _        y N)	logOpenedevents)r   prefixoptionsfacilitys       r   r	   zSyslogObserverTests.openlog   s     '84r   c                 >    | j                   j                  ||f       y r   )r   append)r   r   messages      r   r   zSyslogObserverTests.syslog#   s    GW-.r   c                 z    | j                   j                  dddd       | j                  | j                  g        y)zm
        L{SyslogObserver.emit} ignores events with an empty value for the
        C{'message'} key.
         F-r   isErrorsystemN)r   emitassertEqualr   r   s    r   test_emitWithoutMessagez+SyslogObserverTests.test_emitWithoutMessage&   s1    
 	resKLb)r   c                     | j                   j                  dddt        j                  d       | j	                  | j
                  t        j                  dfg       y)
        L{SyslogObserver.emit} uses the value of the C{'syslogPriority'} as the
        syslog priority, if that key is present in the event dictionary.
        zhello, worldFr   )r   r    r!   syslogPriority[-] hello, worldN)r   r"   	stdsyslog	LOG_DEBUGr#   r   r   s    r   test_emitCustomPriorityz+SyslogObserverTests.test_emitCustomPriority.   sR    
 	, "+"5"5		
 		(;(;=O'P&QRr   c           
          | j                   j                  dddt        t        d            d       | j	                  | j
                  t        j                  dfg       y)zd
        L{SyslogObserver.emit} uses C{LOG_ALERT} if the event represents an
        error.
        r'   Tr   foo)r   r    r!   failurer)   N)r   r"   r   	Exceptionr#   r   r*   	LOG_ALERTr   s    r   test_emitErrorPriorityz*SyslogObserverTests.test_emitErrorPriority=   sV    
 	,"9U#34		
 		(;(;=O'P&QRr   c                     | j                   j                  dddt        j                  t	        t        d            d       | j                  | j                  t        j                  dfg       y)z
        L{SyslogObserver.emit} uses the value of the C{'syslogPriority'} key if
        it is specified even if the event dictionary represents an error.
        r'   Tr   bar)r   r    r!   r(   r/   r)   N)r   r"   r*   
LOG_NOTICEr   r0   r#   r   r   s    r   %test_emitCustomPriorityOverridesErrorz9SyslogObserverTests.test_emitCustomPriorityOverridesErrorL   s_    
 	,"+"6"6"9U#34	
 		(<(<>P'Q&RSr   c                     | j                   j                  dddt        j                  d       | j	                  | j
                  t        j                  t        j                  z  dfg       y)r&   r'   Fr   )r   r    r!   syslogFacilityr)   N)r   r"   r*   LOG_CRONr#   r   LOG_INFOr   s    r   test_emitCustomFacilityz+SyslogObserverTests.test_emitCustomFacility\   s`    
 	, "+"4"4		
 	KK9--	0B0BBDVWX	
r   c                     | j                   j                  dddd       | j                  | j                  t        j
                  dfg       y)zt
        L{SyslogObserver.emit} uses the value of the C{'system'} key to prefix
        the logged message.
        r'   FnonDefaultSystemr   z[nonDefaultSystem] hello, worldNr   r"   r#   r   r*   r:   r   s    r   test_emitCustomSystemz)SyslogObserverTests.test_emitCustomSystemm   sL    
 	, ,	
 	KK9--/PQR	
r   c                     | j                   j                  dddd       | j                  | j                  t        j
                  dfg       y)z
        L{SyslogObserver.emit} logs the value of the C{'message'} key of the
        event dictionary it is passed to the syslog.
        r'   Fr   r   r)   Nr>   r   s    r   test_emitMessagez$SyslogObserverTests.test_emitMessage}   sE    
 	)esK	
 		(:(:<N'O&PQr   c                     | j                   j                  dddd       | j                  | j                  t        j
                  dft        j
                  dfg       y)zW
        Each line of a multiline message is emitted separately to the syslog.
        )zhello,
worldFr   r   
[-] hello,
[-] 	worldNr>   r   s    r   test_emitMultilineMessagez-SyslogObserverTests.test_emitMultilineMessage   sU     	*uL	
 	KK  ,/)2D2Dm1TU	
r   c                     | j                   j                  dddd       | j                  | j                  t        j
                  dft        j
                  dfg       y)zw
        Trailing empty lines of a multiline message are omitted from the
        messages sent to the syslog.
        )zhello,
world

Fr   r   rC   rD   Nr>   r   s    r   !test_emitStripsTrailingEmptyLinesz5SyslogObserverTests.test_emitStripsTrailingEmptyLines   sU    
 	.5CP	
 	KK  ,/)2D2Dm1TU	
r   )__name__
__module____qualname____doc__r   r*   skipr   r	   r   r$   r,   r2   r6   r;   r?   rA   rE   rG   r   r   r   r   r      sZ     F9E
/*SST 
"
 R


r   r   )
twisted.python.failurer   twisted.trial.unittestr   r   
_stdsyslogr*   twisted.pythonImportErrorr   r   r   r   <module>rR      sC    + +& I%N
( N
  Is   & 00