ó
[³XMc           @   s©   d  Z  d d l Z d d l m Z m Z d d l m Z m Z d d l m	 Z	 m
 Z
 d „  Z d e f d „  ƒ  YZ d	 e	 j f d
 „  ƒ  YZ d e	 j f d „  ƒ  YZ d S(   sG   
Test the interaction between trial and errors logged during test run.
iÿÿÿÿN(   t   reactort   task(   t   failuret   log(   t   unittestt   reporterc          C   s0   y d d Wn t  k
 r+ t j ƒ  }  n X|  S(   s*   
    Return a new, realistic failure.
    i   i    (   t   ZeroDivisionErrorR   t   Failure(   t   f(    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   makeFailure   s
    t   Maskc           B   s'   e  Z d  Z d e j f d „  ƒ  YZ RS(   s?   
    Hide C{MockTest}s from Trial's automatic test finder.
    t   MockTestc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s   d S(   s/   
            Don't log any errors.
            N(    (   t   self(    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   test_silent    s    c         C   s   t  j t ƒ  ƒ d S(   s-   
            Log a single error.
            N(   R   t   errR	   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   test_single%   s    c         C   s$   t  j t ƒ  ƒ t  j t ƒ  ƒ d S(   s)   
            Log two errors.
            N(   R   R   R	   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   test_double+   s    c         C   s   t  j t d d „  ƒ S(   sC   
            Log an error in an asynchronous callback.
            i    c           S   s   t  j t ƒ  ƒ S(   N(   R   R   R	   (    (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   <lambda>6   s    (   R   t
   deferLaterR    (   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   test_inCallback2   s    (   t   __name__t
   __module__R   R   R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyR      s   			(   R   R   t   __doc__R   t   TestCaseR   (    (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyR
      s   t   TestObserverc           B   sV   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   ss   
    Tests for L{unittest._LogObserver}, a helper for the implementation of
    L{TestCase.flushLoggedErrors}.
    c         C   s"   t  j ƒ  |  _ t j ƒ  |  _ d  S(   N(   R   t
   TestResultt   resultR   t   _LogObservert   observer(   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   setUp>   s    c         C   sO   |  j  j i d	 d 6t j ƒ  d 6d d 6d d 6ƒ |  j |  j  j ƒ  g  ƒ d S(
   sW   
        Test that a standard log message doesn't go anywhere near the result.
        s   some messaget   messaget   timei    t   isErrort   -t   systemN(   s   some message(   R   t   gotEventR   t   assertEqualt	   getErrors(   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   test_msgC   s    c         C   si   t  ƒ  } |  j j i d
 d 6t j ƒ  d 6d d 6d d 6| d 6d	 d 6ƒ |  j |  j j ƒ  | g ƒ d	 S(   sF   
        Test that an observed error gets added to the result
        R   R   i   R    R!   R"   R   t   whyN(    (   R	   R   R#   R   t   NoneR$   R%   (   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt
   test_errorM   s    	c         C   sf   |  j  ƒ  |  j j ƒ  } |  j |  j j ƒ  g  ƒ |  j t | ƒ d ƒ |  j | d j t ƒ ƒ d S(   sS   
        Check that flushing the observer with no args removes all errors.
        i   i    N(	   R)   R   t   flushErrorsR$   R%   t   lent
   assertTruet   checkR   (   R   t   flushed(    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt
   test_flushY   s
    
c         C   s   t  j t d ƒ ƒ S(   Ns
   test error(   R   R   t   RuntimeError(   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   _makeRuntimeFailured   s    c         C   sµ   |  j  ƒ  |  j ƒ  } |  j j t d d d t j ƒ  d d d d d | d d
 ƒ ƒ |  j j t ƒ } |  j	 |  j j
 ƒ  | g ƒ |  j	 t | ƒ d ƒ |  j | d	 j t ƒ ƒ d
 S(   sY   
        Check that flushing the observer remove all failures of the given type.
        R   R   R    i   R"   R!   R   R'   i    N(    (   R)   R1   R   R#   t   dictR   R(   R*   R   R$   R%   R+   R,   R-   (   R   R   R.   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   test_flushByTypeh   s    
'c         C   sv   |  j  j t ƒ t ƒ  } |  j  j i d
 d 6t j ƒ  d 6d d 6d d 6| d 6d	 d 6ƒ |  j |  j  j ƒ  g  ƒ d	 S(   sS   
        Check that C{_ignoreErrors} actually causes errors to be ignored.
        R   R   i   R    R!   R"   R   R'   N(    (	   R   t   _ignoreErrorsR   R	   R#   R   R(   R$   R%   (   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   test_ignoreErrorsv   s    	c         C   s†   |  j  j t ƒ |  j  j ƒ  t ƒ  } |  j  j i d
 d 6t j ƒ  d 6d d 6d d 6| d 6d	 d 6ƒ |  j |  j  j	 ƒ  | g ƒ d	 S(   sj   
        Check that C{_clearIgnores} ensures that previously ignored errors
        get captured.
        R   R   i   R    R!   R"   R   R'   N(    (
   R   R4   R   t   _clearIgnoresR	   R#   R   R(   R$   R%   (   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   test_clearIgnoresƒ   s    	(   R   R   R   R   R&   R)   R/   R1   R3   R5   R7   (    (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyR   9   s   		
					t	   LogErrorsc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sb   
    High-level tests demonstrating the expected behaviour of logged errors
    during tests.
    c         C   s   t  j ƒ  |  _ d  S(   N(   R   R   R   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyR   ™   s    c         C   s   |  j  t ƒ d  S(   N(   t   flushLoggedErrorsR   (   R   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   tearDownœ   s    c         C   sq   t  j d ƒ } | |  j ƒ |  j t |  j j ƒ d ƒ |  j |  j j d d j t ƒ |  j j d d ƒ d S(   sI   
        Test that a logged error gets reported as a test error.
        R   i   i    N(	   R
   R   R   R$   R+   t   errorsR,   R-   R   (   R   t   test(    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   test_singleErrorŸ   s
     c         C   s<   t  j d ƒ } | |  j ƒ |  j t |  j j ƒ d ƒ d S(   sf   
        Test that when two errors get logged, they both get reported as test
        errors.
        R   i   N(   R
   R   R   R$   R+   R;   (   R   R<   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   test_twoErrors©   s    c         C   sq   t  j d ƒ } | |  j ƒ |  j t |  j j ƒ d ƒ |  j |  j j d d j t ƒ |  j j d d ƒ d S(   sS   
        Test that errors logged in callbacks get reported as test errors.
        R   i   i    N(	   R
   R   R   R$   R+   R;   R,   R-   R   (   R   R<   (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyR   ²   s
     c         C   sv   t  j d ƒ } t  j d ƒ } | |  j ƒ | |  j ƒ |  j t |  j j ƒ d ƒ |  j |  j j d d | ƒ d S(   sT   
        Check that an error logged in one test doesn't fail the next test.
        R   R   i   i    N(   R
   R   R   R$   R+   R;   (   R   t   t1t   t2(    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   test_errorsIsolated¼   s    (	   R   R   R   R   R:   R=   R>   R   RA   (    (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyR8   “   s   			
			
(   R   R   t   twisted.internetR    R   t   twisted.pythonR   R   t   twisted.trialR   R   R	   t   objectR
   R   R   R8   (    (    (    s?   /usr/lib/python2.7/dist-packages/twisted/trial/test/test_log.pyt   <module>   s   	Z