
pGNc           @   s  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m	 Z	 d d l
 m Z m Z d e f d     YZ d e	 j f d	     YZ d
 e f d     YZ d d  d     YZ d d! d     YZ d e e f d     YZ d d" d     YZ d e e	 j f d     YZ d e e	 j f d     YZ d e	 j f d     YZ d e	 j f d     YZ d e	 j f d     YZ d e	 j f d     YZ d S(#   s"   
Tests for L{twisted.python.log}.
iN(   t   StringIO(   t   unittest(   t   logt   failuret   FakeWarningc           B   s   e  Z d  Z RS(   s   
    A unique L{Warning} subclass used by tests for interactions of
    L{twisted.python.log} with the L{warnings} module.
    (   t   __name__t
   __module__t   __doc__(    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR      s   t   LogTestc           B   sb   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   c         C   sB   g  |  _  |  j  j |  _ t j |  j  |  j t j |  j  d  S(   N(   t   catchert   appendt   observerR   t   addObservert
   addCleanupt   removeObserver(   t   self(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   setUp   s    	c         C   s   |  j  } t j d d t | j   } |  j | d d d  |  j | d t  |  j | j d   |  j t |  d  d  S(   Nt   testt   testShouldCatcht   messagei    t   time(	   R	   R   t   msgt   Truet   popt   assertEqualt
   failUnlesst   has_keyt   len(   R   R	   t   i(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   testObservation!   s    	c         C   s   |  j  } t j i d d 6d d 6d d 6t j i d d 6t j d d d	 | j   } |  j | d d  |  j | d d  |  j | d d	  |  j | d
 d d  d  S(   Ns   not the defaultt	   subsystemt   at   subsubsystemt   ct   othert   bt   foot   dR   i    (   R	   R   t   callWithContextR   R   R   (   R   R	   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   testContext+   s    	c         C   s|   xu d t    t  f t j t    t f g D]I \ } } t j |  |  j j   } |  j | d d  |  j	 |  q+ Wd  S(   Ns   hello worldt   isErrori   (   s   hello worlds   hello world(
   t   KeyErrorR   t   Failuret   RuntimeErrorR   t   errR	   R   R   t   flushLoggedErrors(   R   t   et   igR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt
   testErrors8   s    %c         C   s   x d t    t  f t j t    t f g D]` \ } } t j | d  |  j j   } |  j | d d  |  j | d d  |  j	 |  q+ Wd  S(   Ns   hello worldt   foobarR(   i   t   why(   s   hello worlds   hello world(
   R)   R   R*   R+   R   R,   R	   R   R   R-   (   R   R.   R/   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   testErrorsWithWhyA   s    %c         C   s  g  } g  } d   } x= | j  | | j  g D]& } t j |  |  j t j |  q+ Wx t d  D] } g  | (g  | (t j d  |  j t  } |  j	 t
 |  d  |  j	 t
 |  d  |  j	 t
 |  d  |  j	 | d d d	  |  j	 | d d d
  qb Wd S(   s  
        Exceptions raised by log observers are logged but the observer which
        raised the exception remains registered with the publisher.  These
        exceptions do not prevent the event from being sent to other observers
        registered with the publisher.
        c         S   s   d d d  S(   Ni   i    (    (   t   events(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   brokenU   s    i   s   Howdy, y'all.i   i   R   i    N(   s   Howdy, y'all.(   s   Howdy, y'all.(   R
   R   R   R   R   t   xrangeR   R-   t   ZeroDivisionErrorR   R   (   R   t   L1t   L2R5   R   R   t   excs(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_erroneousErrorsL   s     	c            s:  g   g    t  j   } d t f  f d     Y} |   } | j | j   |  j | j | j  g  z2 | j }   f d   } | | _ | j d  Wd | | _ |  j | j | j  g  X| j d  |  j | j d  |  j t	   d  |  j  d	 d
 d  |  j t	    d  |  j
   d	 t  d S(   s   
        If logging causes an error, make sure that if logging the fact that
        logging failed also causes an error, the log observer is not removed.
        t   FailingObserverc              s   e  Z d  Z   f d   Z RS(   i    c            sH   |  j  d 7_  |  j  d k  r7 t d |  j  f   n   j |  d  S(   Ni   i   s   Failure #%s(   t   callsR+   R
   (   R   R   t   kwargs(   R4   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR   }   s    (   R   R   R=   R   (    (   R4   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR<   {   s   c            s      j  |  j  t d   d  S(   Ns   Fake recursion error(   R
   t   valueR+   (   R   R2   R>   (   t   errors(    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt
   failingErr   s    s   error in first observerNs   but this should succeedi   i   i    R   (   s   but this should succeed(   R   t   LogPublishert   objectR   R   t	   observerst   _errR   R=   R   t   assertIsInstanceR+   (   R   t	   publisherR<   R   t   oldErrorRA   (    (   R@   R4   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt%   test_doubleErrorDoesNotRemoveObserverr   s(    
				c         C   s   t  j   } | j |  j  | j t d  t d d  |  j j   } |  j | d | d  |  j |  j g   | j t d  t d d d t	   |  j j   } |  j | d | d  |  j |  j g   d S(   sy   
        L{twisted.python.log.showwarning} emits the warning as a message
        to the Twisted logging system.
        s   unique warning messages   warning-filename.pyi   t   formatsQ   warning-filename.py:27: twisted.test.test_log.FakeWarning: unique warning messaget   lineN(
   R   RB   R   R   t   showwarningR   R	   R   R   RC   (   R   RG   t   event(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_showwarning   s$    
c      	   C   s   d } t  } d } d } t   } t j | | | | d | |  j | j   t j | | | |   t j	 d
 k r d } t   } t j | | | | d | d | |  j | j   t j | | | | |   n  d	 S(   s   
        L{twisted.python.log.showwarning} passes warnings with an explicit file
        target on to the underlying Python warning system.
        s   another unique messages   warning-filename.pyi   t   filei   i   s   hello worldRK   N(   i   i   (
   R   R    R   RL   R   t   getvaluet   warningst   formatwarningt   syst   version_info(   R   R   t   categoryt   filenamet   linenot   outputRK   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_warningToFile   s$    				c            s   g      f d   } d   } t  j   } | j |  | j |  | j d  |  j | j | | g  |  j t    d  |  j   d t  d S(   sk   
        Log publisher does not use the global L{log.err} when reporting broken
        observers.
        c            s*   |  j  d  r&   j |  d j  n  d  S(   NR(   R   (   t   getR
   R?   (   t	   eventDict(   R@   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   logError   s    c         S   s   t  d   d  S(   Nt*   test_publisherLocalyReportsBrokenObservers(   R+   (   R[   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   fail   s    s   Hello!i   i    N(	   R   RB   R   R   R   RD   R   RF   R+   (   R   R\   R^   RG   (    (   R@   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt-   test_publisherReportsBrokenObserversPrivately   s    	(   R   R   R   R   R'   R0   R3   R;   RI   RN   RY   R_   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR      s   		
					&	3	 	t   FakeFilec           B   s   e  Z d    Z d   Z RS(   c         C   s   |  j  |  d  S(   N(   R
   (   R   t   bytes(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   write   s    c         C   s   d  S(   N(    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   flush   s    (   R   R   Rb   Rc   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR`      s   	t   EvilStrc           B   s   e  Z d    Z RS(   c         C   s   d d d  S(   Ni   i    (    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   __str__  s    (   R   R   Re   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRd     s   t   EvilReprc           B   s   e  Z d    Z d   Z RS(   c         C   s   d S(   Ns   Happy Evil Repr(    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRe     s    c         C   s   d d d  S(   Ni   i    (    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   __repr__
  s    (   R   R   Re   Rg   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRf     s   	t   EvilReprStrc           B   s   e  Z RS(    (   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRh     s   t   LogPublisherTestCaseMixinc           B   s   e  Z d    Z d   Z RS(   c         C   s   t    |  _ t j   |  _ t j |  j  |  _ |  j j |  j j  y t	 d  Wn t
 k
 rp d |  _ n' Xt t  t j   |  _ t j d  d S(   s   
        Add a log observer which records log events in C{self.out}.  Also,
        make sure the default string encoding is ASCII so that
        L{testSingleUnicode} can test the behavior of logging unencodable
        unicode messages.
        u   ½t   asciiN(   R`   t   outR   RB   t   lpt   FileLogObservert   floR   t   emitt   strt   UnicodeEncodeErrort   Nonet   _origEncodingt   reloadRS   t   getdefaultencodingt   setdefaultencoding(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR     s    
c         C   s`   x1 |  j  D]& } |  j t | t  d | f  q
 W|  j d k	 r\ t j |  j  t ` n  d S(   s   
        Verify that everything written to the fake file C{self.out} was a
        C{str}.  Also, restore the default string encoding to its previous
        setting, if it was modified by L{setUp}.
        s   %r was not a stringN(   Rk   R   t
   isinstanceRp   Rs   Rr   RS   Rv   (   R   t   chunk(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   tearDown(  s
    $(   R   R   R   Ry   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRi     s   	t   LogPublisherTestCasec           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s-   |  j  j d  |  j t |  j  d  d  S(   Ns   Hello, world.i   (   Rl   R   R   R   Rk   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   testSingleString8  s    c         C   s0   |  j  j d d  |  j t |  j  d  d  S(   Ns   Hello, s   world.i   (   Rl   R   R   R   Rk   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   testMultipleString=  s    c         C   s[   |  j  j d  |  j t |  j  d  |  j d |  j d  |  j d |  j d  d  S(   Nu   Hello, ½ world.i   s   with str errori    Rq   (   Rl   R   R   R   Rk   t   assertIn(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   testSingleUnicodeE  s    (   R   R   R{   R|   R~   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRz   7  s   		t   FileObserverTestCasec           B   s   e  Z d    Z e e d d  d k r3 d e _ 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(   c      	   C   sh  d } t  j |  } d } t  j |  } t j j d d  } z d t j d <t  j   |  j |  j j	 |  d  |  j |  j j	 |  d  d t j d <t  j   |  j |  j j	 |  d  |  j |  j j	 |  d  d t j d <t  j   |  j |  j j	 |  d  |  j |  j j	 |  d  Wd | d k rLt j d =n | t j d <t  j   Xd S(   s  
        Attempt to verify that L{FileLogObserver.getTimezoneOffset} returns
        correct values for the current C{TZ} environment setting.  Do this
        by setting C{TZ} to various well-known values and asserting that the
        reported offset is correct.
        i  i   i   i    i   i   i   i  i   i   t   TZs   America/New_Yorki@8  iPF  s   Europe/Berliniis   Africa/JohannesburgN(	   i  i   i   i    i    i    i   i   i   (	   i  i   i   i    i    i    i   i   i    (
   R   t   mktimet   ost   environRZ   Rr   t   tzsetR   Rn   t   getTimezoneOffset(   R   t   localDaylightTuplet   utcDaylightTimestampt   localStandardTuplet   utcStandardTimestampt   originalTimezone(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_getTimezoneOffsetN  sD    


R   sW   Platform cannot change timezone, cannot verify correct offsets in well-known timezones.c      
   C   so  t  j d  t  j } d
   |  j _ |  j |  j j |  d  d   |  j _ |  j |  j j |  d  d   |  j _ |  j |  j j |  d  d   |  j _ |  j |  j j |  d  d   |  j _ |  j |  j j |  d  d   |  j _ |  j |  j j |  d  d   |  j _ |  j |  j j |  d  d |  j _ |  j |  j j |  d  d S(   su   
        Test the method of L{FileLogObserver} which turns a timestamp into a
        human-readable string.
        i  i   i   i   i   i   i   i   i    c         S   s   d S(   NiPF  (    (   t   when(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   <lambda>  s    s   2001-02-02 23:05:06-0500c         S   s   d S(   Ni(    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR     s    s   2001-02-03 05:05:06+0100c         S   s   d S(   NiPe(    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR     s    s   2001-02-03 15:05:06+1100c         S   s   d S(   Ni  (    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR     s    s   2001-02-03 02:35:06-0130c         S   s   d S(   Ni(    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR     s    s   2001-02-03 05:35:06+0130c         S   s   d S(   Ni  (    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR     s    s   2001-02-03 03:35:06-0030c         S   s   d S(   Ni(    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR     s    s   2001-02-03 04:35:06+0030s   %Y %ms   2001 02N(	   i  i   i   i   i   i   i   i   i    (   R   R   t   timezoneRn   R   R   t
   formatTimet
   timeFormat(   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_timeFormatting  s"    c         C   sG   |  j  j t    |  j t |  j  d  |  j d |  j d  d  S(   Ni   t   UNFORMATTABLEi    (   Rl   R   Rd   R   R   Rk   t   assertNotIn(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt%   test_loggingAnObjectWithBroken__str__  s    c         C   sP   |  j  j d d d t    |  j t |  j  d  |  j d |  j d  d  S(   NRJ   s   %(blat)st   blati   s-   Invalid format string or unformattable objecti    (   Rl   R   Rd   R   R   Rk   R}   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt(   test_formattingAnObjectWithBroken__str__  s    c         C   sM   |  j  j d d t   |  j t |  j  d  |  j d |  j d  d  S(   Nt   huht   systemi   s-   Invalid format string or unformattable objecti    (   Rl   R   Rd   R   R   Rk   R}   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_brokenSystem__str__  s    c         C   sS   |  j  j d d d t   g  |  j t |  j  d  |  j d |  j d  d  S(   NRJ   s   %(blat)sR   i   s   UNFORMATTABLE OBJECTi    (   Rl   R   Rf   R   R   Rk   R}   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt1   test_formattingAnObjectWithBroken__repr__Indirect  s    c         C   sP   |  j  j d d t   g |  j t |  j  d  |  j d |  j d  d  S(   NR   R   i   s   UNFORMATTABLE OBJECTi    (   Rl   R   Rf   R   R   Rk   R}   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt%   test_systemWithBroker__repr__Indirect  s    c         C   sM   |  j  j d d d d  |  j t |  j  d  |  j d |  j d  d  S(   NRJ   s
   hooj %s %sR   i   s-   Invalid format string or unformattable objecti    (   Rl   R   R   R   Rk   R}   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_simpleBrokenFormat  s    c         C   sM   |  j  j d d d d  |  j t |  j  d  |  j d |  j d  d  S(   NRJ   i*   R   i   s-   Invalid format string or unformattable objecti    (   Rl   R   R   R   Rk   R}   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_ridiculousFormat  s    c         C   sP   |  j  j d t   d d  |  j t |  j  d  |  j d |  j d  d  S(   NRJ   R   i   t   PATHOLOGICALi    (   Rl   R   Rh   R   R   Rk   R}   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt!   test_evilFormat__repr__And__str__  s    c         C   s6   |  j  j d d d t  |  j t |  j  d  d S(   sP   
        This kind of eventDict used to fail silently, so test it does.
        R   t    R(   i    N(   Rl   R   t   FalseR   R   Rk   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_strangeEventDict  s    c         C   s6  t  j t  j } } |  j t t  d t  j  |  j t t  d t  j  t   } t j |  } |  j | j  t j	 d  |  j
 d | j    |  j t  j t j  |  j t  j j t  |  j t  j j | j p t  j    |  j t  j t j  |  j t  j j t  |  j t  j j | j p.t  j    d S(   sj   
        startLogging() installs FileLogObserver and overrides sys.stdout and
        sys.stderr.
        t   stdoutt   stderrs   Hello!N(   RS   R   R   R   t   setattrR    R   t   startLoggingt   stopR   R}   RP   RF   t   StdioOnnaStickR   R(   R   t   encodingRu   R   (   R   t
   origStdoutt
   origStderrt   fakeFileR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_startLogging  s     	c         C   s   t    t _ |  j t t d t j  |  j t t d t j  d   } t j |  |  j t j |  t j	 t j  } |  j | j
  |  j t j t j  t j } t j	 t j  } |  j t j |  d S(   s   
        There are some obscure error conditions that can occur when logging is
        started twice. See http://twistedmatrix.com/trac/ticket/3289 for more
        information.
        R   R   c         S   s+   |  d r' t  j j |  d j    n  d  S(   NR(   R   (   RS   t
   __stdout__Rb   t   getTraceback(   R[   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt	   showError  s    
N(   R    RS   R   R   R   R   R   R   R   R   R   RF   R   t   assertIdentical(   R   R   R   t
   fakeStdout(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_startLoggingTwice  s    			N(   R   R   R   t   getattrR   Rr   t   skipR   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR   M  s   	1	.										t   PythonLoggingObserverTestCasec           B   sM   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   s5   
    Test the bridge with python logging module.
    c         C   s   t    |  _ t j d  } | j   |  _ | j t j  t j |  j  |  _	 t j
 t j  } |  j	 j |  | j |  j	  t j   |  _ t j   |  _ |  j j |  j j  d  S(   NR   (   R    Rk   t   loggingt	   getLoggert   getEffectiveLevelt   originalLevelt   setLevelt   DEBUGt   StreamHandlert   hdlrt	   Formattert   BASIC_FORMATt   setFormattert
   addHandlerR   RB   Rl   t   PythonLoggingObservert   obsR   Ro   (   R   t
   rootLoggert   fmt(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR   %  s    c         C   s=   t  j d  } | j |  j  | j |  j  t  j   d  S(   NR   (   R   R   t   removeHandlerR   R   R   t   shutdown(   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRy   4  s    c         C   sF   |  j  j d  |  j d |  j j    |  j d |  j j    d S(   s<   
        Test simple output, and default log level.
        s   Hello, world.t   INFON(   Rl   R   R}   Rk   RP   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_singleString:  s    c         C   sE   |  j  j d t j t d   d t  |  j d |  j j    d S(   s$   
        Test error output.
        R   s   That is bad.R(   t   ERRORN(	   Rl   R   R   R*   t
   ValueErrorR   R}   Rk   RP   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_errorStringB  s    (c         C   s<   |  j  j d d d d d d  |  j d |  j j    d S(	   s-   
        Test logging with a format.
        RJ   s   %(bar)s oo %(foo)st   bart   HelloR$   t   worlds   Hello oo worldN(   Rl   R   R}   Rk   RP   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_formatStringI  s    c         C   s   |  j  j d d t j |  j d |  j j    |  j d |  j j    |  j j   |  j  j d d t j |  j d |  j j    |  j d |  j j    d S(   sG   
        Test the logLevel keyword for customizing level used.
        s	   Spam egg.t   logLevelR   s   Foo bar.t   WARNINGN(	   Rl   R   R   R   R}   Rk   RP   t   resetR   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_customLevelP  s    c         C   s6   |  j  j d d d t  |  j |  j j   d  d S(   sx   
        Verify that an event dictionary which is not an error and has an empty
        message isn't recorded.
        R   R   R(   N(   Rl   R   R   R   Rk   RP   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR   \  s    (
   R   R   R   R   Ry   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR   !  s   						t    PythonLoggingIntegrationTestCasec           B   s    e  Z d  Z d   Z d   Z RS(   s4   
    Test integration of python logging bridge.
    c         C   s   t  j } t  j } g  } zi | j t  _ | j t  _ t  j   } | j   |  j | d | j  | j	   |  j t
 |  d  Wd | t  _ | t  _ Xd S(   s~   
        Test that start and stop methods of the observer actually register
        and unregister to the log system.
        i    N(   R   R   R   R
   t   removeR   t   startR   Ro   R   R   (   R   t   oldAddObservert   oldRemoveObservert   lR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_startStopObserveri  s    		

	c            s   d t  j f   f d     Y      } g  } t  j j } z6 | j t  j _ | j d  |  j t |  d  Wd | t  j _ Xd S(   s   
        Test that we can inherit L{log.PythonLoggingObserver} and use super:
        that's basically a validation that L{log.PythonLoggingObserver} is
        new-style class.
        t
   MyObserverc              s   e  Z   f d    Z RS(   c            s   t    |   j |  d  S(   N(   t   superRo   (   R   R[   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRo     s    (   R   R   Ro   (    (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR     s   R$   i   N(   R   R   Ro   R
   R   R   (   R   R   R   t   oldEmit(    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_inheritance}  s    	(   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR   e  s   	t   DefaultObserverTestCasec           B   s   e  Z d  Z d   Z RS(   s$   
    Test the default observer.
    c         C   s   d d l  m  } t j   } |   | _ | j   d } t j t   |  |  j   } |  j | | j j	    |  j
 t |  d  | j   d S(   su   
        The reason argument passed to log.err() appears in the report
        generated by DefaultObserver.
        i(   R    s   The reason.i   N(   R    R   t   DefaultObserverR   R   R,   t	   ExceptionR-   t   assertSubstringRP   R   R   R   (   R   R    R   t   reasonR@   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_failureLogger  s    
(   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR     s   t   StdioOnnaStickTestCasec           B   s_   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   sF   
    StdioOnnaStick should act like the normal sys.stdout object.
    c         C   s    g  |  _  t j |  j  j  d  S(   N(   t
   resultLogsR   R   R
   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR     s    	c         C   s   t  j |  j j  d  S(   N(   R   R   R   R
   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyRy     s    c         C   s'   g  |  j  D] } d j | d  ^ q
 S(   NR   R   (   R   t   join(   R   R%   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   getLogMessages  s    c         C   s_   t  j   } | j d  |  j |  j   d g  | j d  |  j |  j   d d g  d S(   s   
        Writing to a StdioOnnaStick instance results in Twisted log messages.

        Log messages are generated every time a '
' is encountered.
        s   Hello there
This is a tests   Hello theres   !
s   This is a test!N(   R   R   Rb   R   R   (   R   t   stdio(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt
   test_write  s
    c         C   sS   t  j   } | j d  |  j |  j d d t  |  j |  j d d t  d S(   s{   
        The log messages written by StdioOnnaStick have printed=1 keyword, and
        by default are not errors.
        s   hello
i    R(   t   printedN(   R   R   Rb   R   R   R   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_metadata  s    c         C   s?   t  j   } | j d d g  |  j |  j   d d g  d S(   sT   
        Writing lines to a StdioOnnaStick results in Twisted log messages.
        s   log 1s   log 2N(   R   R   t
   writelinesR   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_writeLines  s    c         C   sT   t  j } t j   t  _ |  j t t  d |  d Gd GH|  j |  j   d g  d S(   sW   
        When StdioOnnaStick is set as sys.stdout, prints become log messages.
        R   t   Thiss	   is a tests   This is a testN(   RS   R   R   R   R   R   R   R   (   R   t	   oldStdout(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt
   test_print  s    	c         C   s>   t  j d t  } | j d  |  j |  j d d t  d S(   sR   
        StdioOnnaStick created with isError=True log messages as errors.
        R(   s   log 1
i    N(   R   R   R   Rb   R   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt
   test_error  s    c         C   s   d } t  j d d  } |  j | j d  | j | d  | j d | g  t j } | t _ |  j t	 t d |  | GH|  j |  j
   | j d  d | j d  | j d  g  d S(   s   
        StdioOnnaStick converts unicode prints to strings, in order to be
        compatible with the normal stdout/stderr objects.
        u   Hello, ½ world.R   s   utf-8u   
u   Also, R   N(   R   R   R   R   Rb   R   RS   R   R   R   R   t   encode(   R   t   unicodeStringR   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   test_unicode  s    		(   R   R   R   R   Ry   R   R   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyR     s   										(    (    (    (   R   R   RS   R   R   RQ   t	   cStringIOR    t   twisted.trialR   t   twisted.pythonR   R   t   WarningR   t   TestCaseR   t   listR`   Rd   Rf   Rh   Ri   Rz   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_log.pyt   <module>   s"   <'D,