o
    ¯b-  ã                   @   s`   d dl mZ d dlmZ zd dlZW n ey   dZY n	w eZd dlmZ G dd„ deƒZ	dS )é    )ÚFailure)ÚTestCaseN)Úsyslogc                   @   s€   e Zd ZdZdZedu 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   )Úpatchr   Ú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)Ú	logOpenedÚevents)r   ÚprefixÚoptionsÚ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   Ú	stdsyslogÚ	LOG_DEBUGr   r   r
   r   r   r   Útest_emitCustomPriority.   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   Úfoo)r   r   r   Úfailurer!   N)r	   r   r   Ú	Exceptionr   r   r"   Ú	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   Úbar)r   r   r   r    r&   r!   N)r	   r   r"   Ú
LOG_NOTICEr   r'   r   r   r
   r   r   r   Ú%test_emitCustomPriorityOverridesErrorL   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   ÚsyslogFacilityr!   N)r	   r   r"   ÚLOG_CRONr   r   ÚLOG_INFOr
   r   r   r   Útest_emitCustomFacility\   s   üÿÿz+SyslogObserverTests.test_emitCustomFacilityc                 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
   r   r   r   Útest_emitCustomSystemm   s   ýÿÿz)SyslogObserverTests.test_emitCustomSystemc                 C   r1   )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!   Nr3   r
   r   r   r   Útest_emitMessage}   s   
ÿz$SyslogObserverTests.test_emitMessagec                 C   ó6   | 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,ú
[-] 	worldNr3   r
   r   r   r   Útest_emitMultilineMessage‡   s   
ÿþz-SyslogObserverTests.test_emitMultilineMessagec                 C   r6   )zw
        Trailing empty lines of a multiline message are omitted from the
        messages sent to the syslog.
        )zhello,
world

Fr   r   r7   r8   Nr3   r
   r   r   r   Ú!test_emitStripsTrailingEmptyLines“   s   
ÿþz5SyslogObserverTests.test_emitStripsTrailingEmptyLines)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r"   Úskipr   r   r   r   r$   r)   r,   r0   r4   r5   r9   r:   r   r   r   r   r      s"    
r   )
Útwisted.python.failurer   Útwisted.trial.unittestr   r   Ú
_stdsyslogÚImportErrorr"   Útwisted.pythonr   r   r   r   r   Ú<module>   s   ÿ