ó
[³XMc           @   st   d  d l  m Z d  d l m Z y d  d l Z Wn e k
 rI d Z n Xd  d l m Z d e f d „  ƒ  YZ	 d S(   iÿÿÿÿ(   t   TestCase(   t   FailureN(   t   syslogt   SyslogObserverTestsc           B   s•   e  Z d  Z d Z e d k r' d Z n  d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   sS   
    Tests for L{SyslogObserver} which sends Twisted log events to the syslog.
    s(   syslog is not supported on this platformc         C   sH   |  j  t j d |  j ƒ |  j  t j d |  j ƒ t j d ƒ |  _ d  S(   Nt   openlogR   R   (   t   patchR   t   SyslogObserverR   t   observer(   t   self(    (    sC   /usr/lib/python2.7/dist-packages/twisted/python/test/test_syslog.pyt   setUp   s    c         C   s   | | | f |  _  g  |  _ d  S(   N(   t	   logOpenedt   events(   R   t   prefixt   optionst   facility(    (    sC   /usr/lib/python2.7/dist-packages/twisted/python/test/test_syslog.pyR      s    c         C   s   |  j  j | | f ƒ d  S(   N(   R   t   append(   R   R   t   message(    (    sC   /usr/lib/python2.7/dist-packages/twisted/python/test/test_syslog.pyR   $   s    c         C   s<   |  j  j i d d 6t d 6d d 6ƒ |  j |  j g  ƒ d S(   sm   
        L{SyslogObserver.emit} ignores events with an empty value for the
        C{'message'} key.
        R   t   isErrort   -t   systemN(    (   R   t   emitt   Falset   assertEqualR   (   R   (    (    sC   /usr/lib/python2.7/dist-packages/twisted/python/test/test_syslog.pyt   test_emitWithoutMessage(   s    %c         C   sR   |  j  j i d	 d 6t d 6d d 6t j d 6ƒ |  j |  j t j d f g ƒ d S(
   s¢   
        L{SyslogObserver.emit} uses the value of the C{'syslogPriority'} as the
        syslog priority, if that key is present in the event dictionary.
        s   hello, worldR   R   R   R   t   syslogPrioritys   [-] hello, worldN(   s   hello, world(   R   R   R   t	   stdsyslogt	   LOG_DEBUGR   R   (   R   (    (    sC   /usr/lib/python2.7/dist-packages/twisted/python/test/test_syslog.pyt   test_emitCustomPriority1   s    c         C   s[   |  j  j i d
 d 6t d 6d d 6t t d ƒ ƒ d 6ƒ |  j |  j t j d f g ƒ d	 S(   sd   
        L{SyslogObserver.emit} uses C{LOG_ALERT} if the event represents an
        error.
        s   hello, worldR   R   R   R   t   foot   failures   [-] hello, worldN(   s   hello, world(	   R   R   t   TrueR   t	   ExceptionR   R   R   t	   LOG_ALERT(   R   (    (    sC   /usr/lib/python2.7/dist-packages/twisted/python/test/test_syslog.pyt   test_emitErrorPriority>   s    c         C   se   |  j  j i d d 6t d 6d d 6t j d 6t t d ƒ ƒ d 6ƒ |  j |  j t j d	 f g ƒ d
 S(   s£   
        L{SyslogObserver.emit} uses the value of the C{'syslogPriority'} key if
        it is specified even if the event dictionary represents an error.
        s   hello, worldR   R   R   R   R   t   barR   s   [-] hello, worldN(   s   hello, world(	   R   R   R   R   t
   LOG_NOTICER   R   R   R   (   R   (    (    sC   /usr/lib/python2.7/dist-packages/twisted/python/test/test_syslog.pyt%   test_emitCustomPriorityOverridesErrorK   s    
c         C   sY   |  j  j i d	 d 6t d 6d d 6t j d 6ƒ |  j |  j t j t j Bd f g ƒ d S(
   s¢   
        L{SyslogObserver.emit} uses the value of the C{'syslogPriority'} as the
        syslog priority, if that key is present in the event dictionary.
        s   hello, worldR   R   R   R   t   syslogFacilitys   [-] hello, worldN(   s   hello, world(   R   R   R   R   t   LOG_CRONR   R   t   LOG_INFO(   R   (    (    sC   /usr/lib/python2.7/dist-packages/twisted/python/test/test_syslog.pyt   test_emitCustomFacilityY   s    c         C   sH   |  j  j i d d 6t d 6d d 6ƒ |  j |  j t j d f g ƒ d S(	   st   
        L{SyslogObserver.emit} uses the value of the C{'system'} key to prefix
        the logged message.
        s   hello, worldR   R   t   nonDefaultSystemR   s   [nonDefaultSystem] hello, worldN(   s   hello, world(   R   R   R   R   R   R   R'   (   R   (    (    sC   /usr/lib/python2.7/dist-packages/twisted/python/test/test_syslog.pyt   test_emitCustomSystemf   s
    c         C   sH   |  j  j i d d 6t d 6d d 6ƒ |  j |  j t j d f g ƒ d S(	   s‹   
        L{SyslogObserver.emit} logs the value of the C{'message'} key of the
        event dictionary it is passed to the syslog.
        s   hello, worldR   R   R   R   s   [-] hello, worldN(   s   hello, world(   R   R   R   R   R   R   R'   (   R   (    (    sC   /usr/lib/python2.7/dist-packages/twisted/python/test/test_syslog.pyt   test_emitMessager   s    c         C   sT   |  j  j i d	 d 6t d 6d d 6ƒ |  j |  j t j d f t j d f g ƒ d S(
   sW   
        Each line of a multiline message is emitted separately to the syslog.
        s   hello,
worldR   R   R   R   s
   [-] hello,s
   [-] 	worldN(   s   hello,
world(   R   R   R   R   R   R   R'   (   R   (    (    sC   /usr/lib/python2.7/dist-packages/twisted/python/test/test_syslog.pyt   test_emitMultilineMessage   s    c         C   sT   |  j  j i d	 d 6t d 6d d 6ƒ |  j |  j t j d f t j d f g ƒ d S(
   sw   
        Trailing empty lines of a multiline message are omitted from the
        messages sent to the syslog.
        s   hello,
world

R   R   R   R   s
   [-] hello,s
   [-] 	worldN(   s   hello,
world

(   R   R   R   R   R   R   R'   (   R   (    (    sC   /usr/lib/python2.7/dist-packages/twisted/python/test/test_syslog.pyt!   test_emitStripsTrailingEmptyLinesŒ   s    N(   t   __name__t
   __module__t   __doc__t   NoneR   R   t   skipR	   R   R   R   R   R!   R$   R(   R*   R+   R,   R-   (    (    (    sC   /usr/lib/python2.7/dist-packages/twisted/python/test/test_syslog.pyR      s    													(
   t   twisted.trial.unittestR    t   twisted.python.failureR   R   R   t   ImportErrorR1   t   twisted.pythonR   (    (    (    sC   /usr/lib/python2.7/dist-packages/twisted/python/test/test_syslog.pyt   <module>   s   
