
[XMc           @   ss  d  Z  d d l Z d d l Z d d l Z d d l m Z m Z d d l m Z y d d l	 m
 Z
 Wn e k
 r} d Z
 n Xd   Z d e j f d     YZ d	 e f d
     YZ d e f d     YZ d e e 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 e j d  d k rod d l m Z n  d S(   s    
Test cases for failure module.
iN(   t   unittestt   util(   t   failure(   t   raiserc          C   s&   y d d Wn t  j   }  n X|  S(   Ni   i    (   R   t   Failure(   t   f(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   getDivisionFailure   s
    t   FailureTestCasec           B   s   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d e _	 d Z
 d	   Z d
   Z e j d d  g e _ d   Z e j d d  g e _ e j d  d k r d Z e e _ e e _ n  d   Z d   Z d   Z d   Z RS(   c         C   s_   y t  d   Wn t j   } n X| j t t  } |  j | t  |  j | j t   d S(   s   Trapping a failure.t   testN(   t   NotImplementedErrorR   R   t   trapt
   SystemExitt   RuntimeErrort   assertEqualst   type(   t   selfR   t   error(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   testFailAndTrap    s    c         C   s@   y t     Wn t j   } n X|  j t j | j t  d S(   s0   Making sure trap doesn't trap what it shouldn't.N(   t
   ValueErrorR   R   t   assertRaisesR
   t   OverflowError(   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   test_notTrapped*   s
    c         C   sY   t  j    } y d d Wn t j   } n X| j |  | j |  | j |  d  S(   Ni   i    (   t   StringIOR   R   t   printDetailedTracebackt   printBriefTracebackt   printTraceback(   R   t   outR   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   testPrinting2   s    c         C   s<   t    } t j |  } | j t   |  j | j |  d  S(   N(   R   R   R   R
   R   t   value(   R   t   eR   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   testExplictPass<   s    	c         C   sT   y | j    Wn3 t k
 rC t j t j   d  } | d d SXt d   d  S(   Ni   is3   f.raiseException() didn't raise ZeroDivisionError!?(   t   raiseExceptiont   ZeroDivisionErrort	   tracebackt
   extract_tbt   syst   exc_infot	   Exception(   R   R   t   tb(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   _getInnermostFrameLineC   s    c         C   s,   t    } |  j |  } |  j | d  d  S(   Ns   1/0(   R   R'   R   (   R   R   t	   innerline(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   testRaiseExceptionWithTBN   s    	c         C   s6   t    } | j   |  j |  } |  j | d  d  S(   Ns   1/0(   R   t   cleanFailureR'   R   (   R   R   R(   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   testLackOfTBT   s    	
sQ   the traceback is not preserved, exarkun said he'll try to fix this! god knows hows
   bugger offc         C   s'   y |  j   Wn t j   } n X| S(   N(   t   _stringExceptionR   R   (   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   _getStringFailure^   s
    c         C   sQ   |  j    } y | j   Wn$ |  j t j   d |  j  n Xt d   d  S(   Ni    s   Should have raised(   R-   R   R   R#   R$   R,   t   AssertionError(   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   test_raiseStringExceptionse   s    !t   messages(   raising a string exception is deprecatedc         C   sU   |  j    } t j   } | j d |  | j   j   } |  j | d |  j  d S(   s   
        L{Failure.printTraceback} should write out stack and exception
        information, even for string exceptions.
        t   fileiN(   R-   R   R   t   getvaluet
   splitlinest   assertEqualR,   (   R   R   t   outputt   lines(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   test_printStringExceptionsr   s
    i   i   s>   String exceptions aren't supported anymore starting Python 2.6c         C   s   |  j  t j t j  d S(   s   
        Creating a Failure with no arguments causes it to try to discover the
        current interpreter exception state.  If no such state exists, creating
        the Failure should raise a synchronous exception.
        N(   R   R   t   NoCurrentExceptionErrorR   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   testConstructionFails   s    c         C   s&   t    } |  j | j   | j  d S(   s   
        If the C{Failure} has not been cleaned, then C{getTracebackObject}
        should return the traceback object that it was given in the
        constructor.
        N(   R   R4   t   getTracebackObjectR&   (   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   test_getTracebackObject   s    	c         C   sQ   t    } t j | j    } | j   t j | j    } |  j | |  d S(   s   
        If the Failure has been cleaned, then C{getTracebackObject} should
        return an object that looks the same to L{traceback.extract_tb}.
        N(   R   R!   R"   R:   R*   R4   (   R   R   t   expectedt   observed(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt    test_getTracebackObjectFromClean   s
    	
c         C   s/   t  j t d   } |  j | j   d  d S(   s  
        L{failure.Failure}s need not be constructed with traceback objects. If
        a C{Failure} has no traceback information at all, C{getTracebackObject}
        should just return None.

        None is a good value, because traceback.extract_tb(None) -> [].
        s
   some errorN(   R   R   R%   R4   R:   t   None(   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt'   test_getTracebackObjectWithoutTraceback   s    (   i   i   (   t   __name__t
   __module__R   R   R   R   R'   R)   R+   t   todoR,   R-   R/   R   t   suppressR7   R#   t   version_infot   skipMsgt   skipR9   R;   R>   R@   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyR      s,   	
		
							
						t	   BrokenStrc           B   s   e  Z d  Z d   Z RS(   sb   
    An exception class the instances of which cannot be presented as strings via
    C{str}.
    c         C   s
   |   d  S(   N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   __str__   s    (   RA   RB   t   __doc__RI   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRH      s   t   BrokenExceptionMetaclassc           B   s   e  Z d  Z d   Z RS(   sa   
    A metaclass for an exception type which cannot be presented as a string via
    C{str}.
    c         C   s   t  d   d  S(   Ns#   You cannot make a string out of me.(   R   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRI      s    (   RA   RB   RJ   RI   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRK      s   t   BrokenExceptionTypec           B   s   e  Z d  Z e Z RS(   sa   
    The aforementioned exception type which cnanot be presented as a string via
    C{str}.
    (   RA   RB   RJ   RK   t   __metaclass__(    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRL      s   t   GetTracebackTestsc           B   sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   s,   
    Tests for L{Failure.getTraceback}.
    c         C   s>   t    } t j |  } | j d |  } |  j | t  d S(   s   
        Construct a L{Failure} with an exception that raises an exception from
        its C{__str__} method and then call C{getTraceback} with the specified
        detail and verify that it returns a string.
        t   detailN(   RH   R   R   t   getTracebackt   assertIsInstancet   str(   R   RO   t   xR   R!   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   _brokenValueTest   s    	c         C   s   |  j  d  d S(   s   
        A L{Failure} might wrap an exception with a C{__str__} method which
        raises an exception.  In this case, calling C{getTraceback} on the
        failure with the C{"brief"} detail does not raise an exception.
        t   briefN(   RT   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   test_brokenValueBriefDetail   s    c         C   s   |  j  d  d S(   sY   
        Like test_brokenValueBriefDetail, but for the C{"default"} detail case.
        t   defaultN(   RT   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   test_brokenValueDefaultDetail   s    c         C   s   |  j  d  d S(   sY   
        Like test_brokenValueBriefDetail, but for the C{"default"} detail case.
        t   verboseN(   RT   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   test_brokenValueVerboseDetail   s    c         C   s8   t  j t    } | j d |  } |  j | t  d S(   s   
        Construct a L{Failure} with an exception type that raises an exception
        from its C{__str__} method and then call C{getTraceback} with the
        specified detail and verify that it returns a string.
        RO   N(   R   R   RL   RP   RQ   RR   (   R   RO   R   R!   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   _brokenTypeTest   s    c         C   s   |  j  d  d S(   s  
        A L{Failure} might wrap an exception the type object of which has a
        C{__str__} method which raises an exception.  In this case, calling
        C{getTraceback} on the failure with the C{"brief"} detail does not raise
        an exception.
        RU   N(   R[   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   test_brokenTypeBriefDetail  s    c         C   s   |  j  d  d S(   sX   
        Like test_brokenTypeBriefDetail, but for the C{"default"} detail case.
        RW   N(   R[   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   test_brokenTypeDefaultDetail  s    c         C   s   |  j  d  d S(   sX   
        Like test_brokenTypeBriefDetail, but for the C{"verbose"} detail case.
        RY   N(   R[   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   test_brokenTypeVerboseDetail  s    (   RA   RB   RJ   RT   RV   RX   RZ   R[   R\   R]   R^   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRN      s   							
	t   FindFailureTestsc           B   sY   e  Z d  Z d   Z d   Z d   Z d   Z d   Z e d k rW d Z
 e
 e _ n  RS(   sE   
    Tests for functionality related to L{Failure._findFailure}.
    c         C   s@   y d d Wn  |  j  t j j   d  n X|  j d  d S(   s   
        Within an exception handler, _findFailure should return
        C{None} in case no Failure is associated with the current
        exception.
        i   i    s   No exception raised from 1/0!?N(   R4   R   R   t   _findFailureR?   t   fail(   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt$   test_findNoFailureInExceptionHandler  s
    c         C   s7   |  j  t j   d d  |  j  t j j   d  d S(   sS   
        Outside of an exception handler, _findFailure should return None.
        iN(   R4   R#   R$   R?   R   R   R`   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   test_findNoFailure-  s    c         C   sU   t    } | j   y | j   Wn  |  j t j j   |  n X|  j d  d S(   s   
        Within an exception handler, it should be possible to find the
        original Failure that caused the current exception (if it was
        caused by raiseException).
        s)   No exception raised from raiseException!?N(   R   R*   R   R4   R   R   R`   Ra   (   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   test_findFailure5  s    	
c         C   sd   t    } | j   y | j   Wn/ t j   } |  j | j   | j    n X|  j d  d S(   s   
        When a Failure is constructed in the context of an exception
        handler that is handling an exception raised by
        raiseException, the new Failure should be chained to that
        original Failure.
        s)   No exception raised from raiseException!?N(   R   R*   R   R   R   R4   RP   Ra   (   R   R   t   newF(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt,   test_failureConstructionFindsOriginalFailureE  s    	
 c         C   s[   y t  j   Wn9 t  j k
 rI t j   } |  j | j t  j   n X|  j d  d S(   s   
        Pyrex and Cython are known to insert fake stack frames so as to give
        more Python-like tracebacks. These stack frames with empty code objects
        should not break extraction of the exception.
        s$   No exception raised from extension?!N(   R   R   t   RaiserExceptionR   R   t
   assertTruet   checkRa   (   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt/   test_failureConstructionWithMungedStackSucceedsW  s    s   raiser extension not availableN(   RA   RB   RJ   Rb   Rc   Rd   Rf   Rj   R   R?   RF   RG   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyR_     s   					t   TestFormattableTracebackc           B   s    e  Z d  Z d   Z d   Z RS(   s  
    Whitebox tests that show that L{failure._Traceback} constructs objects that
    can be used by L{traceback.extract_tb}.

    If the objects can be used by L{traceback.extract_tb}, then they can be
    formatted using L{traceback.format_tb} and friends.
    c         C   sA   t  j d d d i  i  g g  } |  j t j |  d g  d S(   s   
        A C{_Traceback} object constructed with a single frame should be able
        to be passed to L{traceback.extract_tb}, and we should get a singleton
        list containing a (filename, lineno, methodname, line) tuple.
        t   methods   filename.pyi{   N(   s   filename.pyi{   s   methodN(   R   t
   _TracebackR4   R!   R"   R?   (   R   R&   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   test_singleFrameu  s    !c         C   sV   t  j d d d i  i  g d d d i  i  g g  } |  j t j |  d d g  d S(	   s   
        A C{_Traceback} object constructed with multiple frames should be able
        to be passed to L{traceback.extract_tb}, and we should get a list
        containing a tuple for each frame.
        t   method1s   filename.pyi{   t   method2i   N(   s   filename.pyi{   Ro   N(   s   filename.pyi   Rp   N(   R   Rm   R4   R!   R"   R?   (   R   R&   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   test_manyFrames  s    (   RA   RB   RJ   Rn   Rq   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRk   l  s   	t   TestFrameAttributesc           B   s   e  Z d  Z d   Z RS(   sq   
    _Frame objects should possess some basic attributes that qualify them as
    fake python Frame objects.
    c         C   sR   t  j d d  } |  j | j t  |  j | j t  |  j | j t  j  d S(   s   
        L{_Frame} instances have the C{f_globals} and C{f_locals} attributes
        bound to C{dict} instance.  They also have the C{f_code} attribute
        bound to something like a code object.
        t	   dummynamet   dummyfilenameN(   R   t   _FrameRQ   t	   f_globalst   dictt   f_localst   f_codet   _Code(   R   t   frame(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   test_fakeFrameAttributes  s    (   RA   RB   RJ   R|   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRr     s   i   i   (   t   TwoPointFiveFailureTests(   i   i   (   RJ   R#   R   R!   t   twisted.trialR    R   t   twisted.pythonR   t   twisted.testR   t   ImportErrorR?   R   t   TestCaseR   R%   RH   R   RK   t   objectRL   RN   R_   Rk   Rr   RE   t$   twisted.test.generator_failure_testsR}   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt   <module>   s(   
	
	KR%