U
    
W[T  ã                   @   s^   d dl mZ d dlmZ zd dlZW n ek
r<   dZY nX d dlmZ G dd„ deƒZdS )é    )ÚTestCase)ÚFailureN)Úsyslogc                   @   s€   e Zd ZdZdZedkr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d„ Zdd„ Zdd„ Zd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                 C   s4   |   tjd| j¡ |   tjd| j¡ t d¡| _d S )NÚopenlogr   r   )Zpatchr   ZSyslogObserverr   Úobserver©Úself© r
   úA/usr/lib/python3/dist-packages/twisted/python/test/test_syslog.pyÚsetUp   s    zSyslogObserverTests.setUpc                 C   s   |||f| _ g | _d S ©N)Z	logOpenedÚevents)r	   ÚprefixÚoptionsZfacilityr
   r
   r   r      s    zSyslogObserverTests.openlogc                 C   s   | j  ||f¡ d S r   )r   Úappend)r	   r   Úmessager
   r
   r   r   $   s    zSyslogObserverTests.syslogc                 C   s&   | j  ddddœ¡ |  | jg ¡ dS )zm
        L{SyslogObserver.emit} ignores events with an empty value for the
        C{'message'} key.
        r
   Fú-©r   ÚisErrorÚsystemN)r   ÚemitÚassertEqualr   r   r
   r
   r   Útest_emitWithoutMessage(   s    z+SyslogObserverTests.test_emitWithoutMessagec                 C   s2   | 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   Ú	stdsyslogZ	LOG_DEBUGr   r   r   r
   r
   r   Útest_emitCustomPriority1   s      þ
þz+SyslogObserverTests.test_emitCustomPriorityc                 C   s8   | 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   Zfoo)r   r   r   Úfailurer   N)r   r   r   Ú	Exceptionr   r   r   Z	LOG_ALERTr   r
   r
   r   Útest_emitErrorPriority>   s      
þ
þz*SyslogObserverTests.test_emitErrorPriorityc              	   C   s<   | 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   Zbar)r   r   r   r   r    r   N)r   r   r   Z
LOG_NOTICEr   r!   r   r   r   r
   r
   r   Ú%test_emitCustomPriorityOverridesErrorK   s      
ý
þz9SyslogObserverTests.test_emitCustomPriorityOverridesErrorc                 C   s8   | j  dddtjdœ¡ |  | jtjtjB dfg¡ dS )r   r   Fr   )r   r   r   ZsyslogFacilityr   N)r   r   r   ZLOG_CRONr   r   ÚLOG_INFOr   r
   r
   r   Útest_emitCustomFacilityY   s      þþz+SyslogObserverTests.test_emitCustomFacilityc                 C   s.   | 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   FZnonDefaultSystemr   z[nonDefaultSystem] hello, worldN©r   r   r   r   r   r$   r   r
   r
   r   Útest_emitCustomSystemf   s    
ÿ
þz)SyslogObserverTests.test_emitCustomSystemc                 C   s.   | 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   r
   r
   r   Útest_emitMessager   s     þ
þz$SyslogObserverTests.test_emitMessagec                 C   s6   | 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   r
   r
   r   Útest_emitMultilineMessage   s     þÿþz-SyslogObserverTests.test_emitMultilineMessagec                 C   s6   | 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   r)   r*   Nr&   r   r
   r
   r   Ú!test_emitStripsTrailingEmptyLinesŒ   s     þÿþz5SyslogObserverTests.test_emitStripsTrailingEmptyLines)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úskipr   r   r   r   r   r"   r#   r%   r'   r(   r+   r,   r
   r
   r
   r   r      s    	r   )	Ztwisted.trial.unittestr   Ztwisted.python.failurer   r   r   ÚImportErrorZtwisted.pythonr   r
   r
   r
   r   Ú<module>   s   
