
    tf-                     p    d dl mZ d dlmZ 	 d dlZeZd dlmZ n# e$ r dZY nw xY w G d de          Z	dS )    )Failure)TestCaseN)syslogc                   f    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dS )SyslogObserverTestszS
    Tests for L{SyslogObserver} which sends Twisted log events to the syslog.
    Nz(syslog is not supported on this platformc                     |                      t          j        d| j                   |                      t          j        d| j                   t          j        d          | _        d S )Nopenlogr   r   )patchr   SyslogObserverr	   observerselfs    ^/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/python/test/test_syslog.pysetUpzSyslogObserverTests.setUp   sO    

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

6((DK@@@-.CDD    c                 (    |||f| _         g | _        d S N)	logOpenedevents)r   prefixoptionsfacilitys       r   r	   zSyslogObserverTests.openlog   s     '84r   c                 >    | j                             ||f           d S r   )r   append)r   r   messages      r   r   zSyslogObserverTests.syslog#   s#    GW-.....r   c                 x    | j                             dddd           |                     | j        g            dS )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&   sB    
 	resKKLLLb)))))r   c                     | j                             dddt          j        d           |                     | j        t          j        dfg           dS )
        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.   sc    
 	, "+"5	 	
 	
 	
 		(;=O'P&QRRRRRr   c           
          | j                             dddt          t          d                    d           |                     | j        t          j        dfg           dS )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=   sp    
 	,"9U#3#344	 	
 	
 	
 		(;=O'P&QRRRRRr   c                     | j                             dddt          j        t	          t          d                    d           |                     | j        t          j        dfg           dS )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   sv    
 	,"+"6"9U#3#344 	
 	
 	
 		(<>P'Q&RSSSSSr   c                     | j                             dddt          j        d           |                     | j        t          j        t          j        z  dfg           dS )r&   r'   Fr   )r   r    r!   syslogFacilityr)   N)r   r"   r*   LOG_CRONr#   r   LOG_INFOr   s    r   test_emitCustomFacilityz+SyslogObserverTests.test_emitCustomFacility\   sv    
 	, "+"4	 	
 	
 	
 	K9-	0BBDVWX	
 	
 	
 	
 	
r   c                     | j                             dddd           |                     | j        t          j        dfg           dS )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   sh    
 	, , 	
 	
 	
 	K9-/PQR	
 	
 	
 	
 	
r   c                     | j                             dddd           |                     | j        t          j        dfg           dS )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}   sW    
 	)esKK	
 	
 	
 		(:<N'O&PQQQQQr   c                     | j                             dddd           |                     | j        t          j        dft          j        dfg           dS )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   sl     	*uLL	
 	
 	
 	K ,/)2Dm1TU	
 	
 	
 	
 	
r   c                     | j                             dddd           |                     | j        t          j        dft          j        dfg           dS )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   sl    
 	.5CPP	
 	
 	
 	K ,/)2Dm1T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      s          F9E E E
  / / /* * *S S SS S ST T T 
 
 
"
 
 
 R R R

 

 


 
 
 
 
r   r   )
twisted.python.failurer   twisted.trial.unittestr   r   
_stdsyslogr*   twisted.pythonImportErrorr   r   r   r   <module>rR      s    + * * * * * + + + + + +& I%%%%%%%	    IIIN
 N
 N
 N
 N
( N
 N
 N
 N
 N
s    %%