
CMc        "   @   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 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 d l m Z m Z m Z m Z d d l m Z d d l m Z m Z m Z e d	  Z d d
 l m Z d e  f d     YZ! d e" f d     YZ# d e$ f d     YZ% d   Z& d e$ f d     YZ' d   Z( d e j) e$ f d     YZ* d e$ f d     YZ+ e+   Z, g  Z- d e* f d     YZ) d e  f d     YZ. d e$ f d     YZ/ d   Z0 d  e j1 f d!     YZ1 d" e j2 e j3 d#  f d$     YZ4 d%   Z5 d&   Z6 d' e4 f d(     YZ7 d) e7 f d*     YZ8 d+ e4 f d,     YZ9 e j: e7 e j) e j3  e j: e8 e j; e j3  e< e d- e=  Z> e> re j: e8 e> e j3  n  d.   Z? y e@ e j1    Wn& eA k
 r6d/   ZB eB e j1 _B n Xd0 e) f d1     YZC eC   ZD d2   ZE d3 d4 d5 d6 d7 d8 d9 d: d; d< d= d> d? d@ dA dB dC dD dE dF dG dH dI dJ dK dL dM dN dO dP dQ dR dS dT g" ZF x! eF D] ZG eE eG  eH   eG <qWd d d g ZI d S(U   sP   
Things likely to be used by writers of unit tests.

Maintainer: Jonathan Lange
iN(   t   pformat(   t   findlinestarts(   t   defert   utils(   t
   componentst   failuret   logt   monkey(   t   getDeprecationWarningString(   t   itrialt   reportert   utilt   unittest(   t
   implementst   SkipTestc           B   s   e  Z d  Z RS(   s   
    Raise this (with a reason) to skip the current test. You may also set
    method.skip to a reason string to skip it, or set class.skip to skip the
    entire TestCase.
    (   t   __name__t
   __module__t   __doc__(    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR      s   t   FailTestc           B   s   e  Z d  Z RS(   s7   Raised to indicate the current test has failed to pass.(   R   R   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   %   s   t   Todoc           B   s,   e  Z d  Z d d  Z d   Z d   Z RS(   sK  
    Internal object used to mark a L{TestCase} as 'todo'. Tests marked 'todo'
    are reported differently in Trial L{TestResult}s. If todo'd tests fail,
    they do not fail the suite and the errors are reported in a separate
    category. If todo'd tests succeed, Trial L{TestResult}s will report an
    unexpected success.
    c         C   s   | |  _  | |  _ d S(   sr  
        @param reason: A string explaining why the test is marked 'todo'

        @param errors: An iterable of exception types that the test is
        expected to raise. If one of these errors is raised by the test, it
        will be trapped. Raising any other kind of error will fail the test.
        If C{None} is passed, then all errors will be trapped.
        N(   t   reasont   errors(   t   selfR   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   __init__2   s    		c         C   s   d |  j  |  j f S(   Ns   <Todo reason=%r errors=%r>(   R   R   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   __repr__>   s    c         C   s>   |  j  d k r t Sx$ |  j  D] } | j |  r t Sq Wt S(   s   
        @param failure: A L{twisted.python.failure.Failure}.

        @return: C{True} if C{failure} is expected, C{False} otherwise.
        N(   R   t   Nonet   Truet   checkt   False(   R   R   t   error(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   expectedA   s    N(   R   R   R   R   R   R   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   )   s   	c         C   s{   t  |  t  r t d |   St  |  t  rw |  \ } } y t |  } Wn t k
 rc | g } n Xt d | d |  Sd S(   s  
    Return a L{Todo} object built from C{value}.

    If C{value} is a string, return a Todo that expects any exception with
    C{value} as a reason. If C{value} is a tuple, the second element is used
    as the reason and the first element as the excepted error(s).

    @param value: A string or a tuple of C{(errors, reason)}, where C{errors}
    is either a single exception class or an iterable of exception classes.

    @return: A L{Todo} object.
    R   R   N(   t
   isinstancet   strR   t   tuplet   listt	   TypeError(   t   valueR   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   makeTodoO   s    t   _Warningc           B   s   e  Z d  Z d   Z RS(   s]  
    A L{_Warning} instance represents one warning emitted through the Python
    warning system (L{warnings}).  This is used to insulate callers of
    L{_collectWarnings} from changes to the Python warnings system which might
    otherwise require changes to the warning objects that function passes to
    the observer object it accepts.

    @ivar message: The string which was passed as the message parameter to
        L{warnings.warn}.

    @ivar category: The L{Warning} subclass which was passed as the category
        parameter to L{warnings.warn}.

    @ivar filename: The name of the file containing the definition of the code
        object which was C{stacklevel} frames above the call to
        L{warnings.warn}, where C{stacklevel} is the value of the C{stacklevel}
        parameter passed to L{warnings.warn}.

    @ivar lineno: The source line associated with the active instruction of the
        code object object which was C{stacklevel} frames above the call to
        L{warnings.warn}, where C{stacklevel} is the value of the C{stacklevel}
        parameter passed to L{warnings.warn}.
    c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   t   messaget   categoryt   filenamet   lineno(   R   R'   R(   R)   R*   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR      s    			(   R   R   R   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR&   h   s   c   	         s   d d   f d  } x= t j j   D], } | d k	 r% y d | _ WqQ qQ Xq% q% Wt j } t j } t j d  z | t _ | | |   } Wd | t j (| t _ X| S(   sU  
    Call C{f} with C{args} positional arguments and C{kwargs} keyword arguments
    and collect all warnings which are emitted as a result in a list.

    @param observeWarning: A callable which will be invoked with a L{_Warning}
        instance each time a warning is emitted.

    @return: The return value of C{f(*args, **kwargs)}.
    c            s9   t  |  t  s t    t |  j d | | |   d  S(   Ni    (   R   t   Warningt   AssertionErrorR&   t   args(   R'   R(   R)   R*   t   filet   line(   t   observeWarning(    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   showWarning   s    t   alwaysN(	   R   t   syst   modulest
   itervaluest   __warningregistry__t   warningst   filterst   showwarningt   simplefilter(	   R0   t   fR-   t   kwargsR1   t   vt   origFilterst   origShowt   result(    (   R0   s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _collectWarnings   s     

		

t   _Assertionsc           B   s  e  Z d  Z d d  Z d d  Z e Z Z Z d d  Z	 e	 Z
 Z Z d   Z e Z d d  Z e Z Z Z d d  Z e Z d d  Z e Z d d	  Z e Z Z Z d d
  Z e Z d d  Z e Z d d d  Z e Z  Z! e Z" d d d  Z# e# Z$ Z% e# Z& d d  Z' e' Z( d   Z) e) Z* d d  Z+ e+ Z, d d  Z- e- Z. d   Z/ e/ Z0 d   Z1 e1 Z2 d   Z3 e3 Z4 RS(   s]  
    Replaces many of the built-in TestCase assertions. In general, these
    assertions provide better error messages and are easier to use in
    callbacks. Also provides new assertions such as L{failUnlessFailure}.

    Although the tests are defined as 'failIf*' and 'failUnless*', they can
    also be called as 'assertNot*' and 'assert*'.
    c         C   s   |  j  |   d S(   s   
        Absolutely fail the test.  Do not pass go, do not collect $200.

        @param msg: the message that will be displayed as the reason for the
        failure
        N(   t   failureException(   R   t   msg(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   fail   s    c         C   s   | r |  j  |   n  | S(   s   
        Fail the test if C{condition} evaluates to True.

        @param condition: any object that defines __nonzero__
        (   RC   (   R   t	   conditionRD   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failIf   s    c         C   s   | s |  j  |   n  | S(   s   
        Fail the test if C{condition} evaluates to False.

        @param condition: any object that defines __nonzero__
        (   RC   (   R   RF   RD   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt
   failUnless   s    c         O   s   y | | |   } WnO | k
 r) } | S|  j  d t j   d | j t j   j   f   n X|  j  d | j | f   d S(   s9  
        Fail the test unless calling the function C{f} with the given
        C{args} and C{kwargs} raises C{exception}. The failure will report
        the traceback and call stack of the unexpected exception.

        @param exception: exception type that is to be expected
        @param f: the function to call

        @return: The raised exception instance, if it is of the given type.
        @raise self.failureException: Raised if the function call does
            not raise an exception or if it raises an exception of a
            different type.
        s   %s raised instead of %s:
 %si    s   %s not raised (%r returned)N(   RC   R3   t   exc_infoR   R   t   Failuret   getTraceback(   R   t	   exceptionR;   R-   R<   R@   t   inst(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failUnlessRaises   s    		t    c         C   so   | | k sk | d k r! d } n  t |  d k r@ | d 7} n  |  j d | t |  t |  f   n  | S(   s   
        Fail the test if C{first} and C{second} are not equal.

        @param msg: A string describing the failure that's included in the
            exception.
        RO   i    s   
s   %snot equal:
a = %s
b = %s
N(   R   t   lenRC   R    (   R   t   firstt   secondRD   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failUnlessEqual   s    	"c         C   s2   | | k	 r. |  j  | p% d | | f   n  | S(   s  
        Fail the test if C{first} is not C{second}.  This is an
        obect-identity-equality test, not an object equality
        (i.e. C{__eq__}) test.

        @param msg: if msg is None, then the failure message will be
        '%r is not %r' % (first, second)
        s   %r is not %r(   RC   (   R   RQ   RR   RD   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failUnlessIdentical  s    	"c         C   s2   | | k r. |  j  | p% d | | f   n  | S(   s  
        Fail the test if C{first} is C{second}.  This is an
        obect-identity-equality test, not an object equality
        (i.e. C{__eq__}) test.

        @param msg: if msg is None, then the failure message will be
        '%r is %r' % (first, second)
        s   %r is %r(   RC   (   R   RQ   RR   RD   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failIfIdentical  s    	"c         C   s2   | | k s. |  j  | p% d | | f   n  | S(   s   
        Fail the test if C{first} == C{second}.

        @param msg: if msg is None, then the failure message will be
        '%r == %r' % (first, second)
        s   %r == %r(   RC   (   R   RQ   RR   RD   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failIfEqual$  s    "c         C   s2   | | k r. |  j  | p% d | | f   n  | S(   s  
        Fail the test if C{containee} is not found in C{container}.

        @param containee: the value that should be in C{container}
        @param container: a sequence type, or in the case of a mapping type,
                          will follow semantics of 'if key in dict.keys()'
        @param msg: if msg is None, then the failure message will be
                    '%r not in %r' % (first, second)
        s   %r not in %r(   RC   (   R   t	   containeet	   containerRD   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failUnlessIn0  s    
c         C   s2   | | k r. |  j  | p% d | | f   n  | S(   s  
        Fail the test if C{containee} is found in C{container}.

        @param containee: the value that should not be in C{container}
        @param container: a sequence type, or in the case of a mapping type,
                          will follow semantics of 'if key in dict.keys()'
        @param msg: if msg is None, then the failure message will be
                    '%r in %r' % (first, second)
        s   %r in %r(   RC   (   R   RW   RX   RD   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failIfIn@  s    
i   c         C   sB   t  | | |  d k r> |  j | p5 d | | | f   n  | S(   s  
        Fail if the two objects are equal as determined by their
        difference rounded to the given number of decimal places
        (default 7) and comparing to zero.

        @note: decimal places (from zero) is usually not the same
               as significant digits (measured from the most
               signficant digit).

        @note: included for compatiblity with PyUnit test cases
        i    s   %r == %r within %r places(   t   roundRC   (   R   RQ   RR   t   placesRD   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failIfAlmostEqualP  s    c         C   sB   t  | | |  d k r> |  j | p5 d | | | f   n  | S(   s  
        Fail if the two objects are unequal as determined by their
        difference rounded to the given number of decimal places
        (default 7) and comparing to zero.

        @note: decimal places (from zero) is usually not the same
               as significant digits (measured from the most
               signficant digit).

        @note: included for compatiblity with PyUnit test cases
        i    s   %r != %r within %r places(   R[   RC   (   R   RQ   RR   R\   RD   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failUnlessAlmostEqualc  s    c         C   s<   t  | |  | k r8 |  j | p/ d | | f   n  | S(   s   
        Fail if C{first} - C{second} > C{tolerance}

        @param msg: if msg is None, then the failure message will be
                    '%r ~== %r' % (first, second)
        s	   %s ~== %s(   t   absRC   (   R   RQ   RR   t	   toleranceRD   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failUnlessApproximatesv  s    "c            s1     f d   }    f d   } | j  | |  S(   s   
        Fail if C{deferred} does not errback with one of C{expectedFailures}.
        Returns the original Deferred with callbacks added. You will need
        to return this Deferred from your test case.
        c            s     j  d |  f   d  S(   Ns&   did not catch an error, instead got %r(   RC   (   t   ignore(   R   (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _cb  s    c            s?   |  j     r |  j Sd  t |   f }   j |   d  S(   Ns   
Expected: %r
Got:
%s(   R   R$   R    RC   (   R   t   output(   R   t   expectedFailures(    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _eb  s
    (   t   addCallbacks(   R   t   deferredRe   Rc   Rf   (    (   R   Re   s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failUnlessFailure  s    c         C   s   |  j  | | |  S(   sH   
        Fail if C{substring} does not exist within C{astring}.
        (   RY   (   R   t	   substringt   astringRD   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failUnlessSubstring  s    c         C   s   |  j  | | |  S(   s;   
        Fail if C{astring} contains C{substring}.
        (   RZ   (   R   Rj   Rk   RD   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failIfSubstring  s    c         O   s   g  } t  | j | | |  } | s4 |  j d  n  | d }	 xF | d D]: }
 |
 j |
 j f |	 j |	 j f k rI |  j d  qI qI W|  j |	 j |  |  j |	 j |  |  j | j |	 j	  d |	 j	 | f  | S(   s  
        Fail if the given function doesn't generate the specified warning when
        called. It calls the function, checks the warning, and forwards the
        result of the function if everything is fine.

        @param category: the category of the warning to check.
        @param message: the output message of the warning to check.
        @param filename: the filename where the warning should come from.
        @param f: the function which is supposed to generate the warning.
        @type f: any callable.
        @param args: the arguments to C{f}.
        @param kwargs: the keywords arguments to C{f}.

        @return: the result of the original function C{f}.
        s   No warnings emittedi    i   s   Can't handle different warningss   Warning in %r, expected %r(
   RA   t   appendRE   R'   R(   t   assertEqualt   assertIdenticalRH   t
   startswithR)   (   R   R(   R'   R)   R;   R-   R<   t   warningsShownR@   RQ   t   other(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failUnlessWarns  s    
c         C   s-   t  | |  s) |  j d | | f  n  d S(   s  
        Fail if C{instance} is not an instance of the given class or of
        one of the given classes.

        @param instance: the object to test the type (first argument of the
            C{isinstance} call).
        @type instance: any.
        @param classOrTuple: the class or classes to test against (second
            argument of the C{isinstance} call).
        @type classOrTuple: class, type, or tuple.
        s   %r is not an instance of %sN(   R   RE   (   R   t   instancet   classOrTuple(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failUnlessIsInstance  s    c         C   s-   t  | |  r) |  j d | | f  n  d S(   s  
        Fail if C{instance} is not an instance of the given class or of
        one of the given classes.

        @param instance: the object to test the type (first argument of the
            C{isinstance} call).
        @type instance: any.
        @param classOrTuple: the class or classes to test against (second
            argument of the C{isinstance} call).
        @type classOrTuple: class, type, or tuple.
        s   %r is an instance of %sN(   R   RE   (   R   Ru   Rv   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   failIfIsInstance  s    N(5   R   R   R   R   RE   RG   t	   assertNott   assertFalset   failUnlessFalseRH   t   assert_t
   assertTruet   failUnlessTrueRN   t   assertRaisesRS   Ro   t   assertEqualst   failUnlessEqualsRT   Rp   RU   t   assertNotIdenticalRV   t   assertNotEqualt   assertNotEqualst   failIfEqualsRY   t   assertInRZ   t   assertNotInR]   t   assertNotAlmostEqualt   assertNotAlmostEqualst   failIfAlmostEqualsR^   t   assertAlmostEqualt   assertAlmostEqualst   failUnlessAlmostEqualsRa   t   assertApproximatesRi   t   assertFailureRl   t   assertSubstringRm   t   assertNotSubstringRt   t   assertWarnsRw   t   assertIsInstanceRx   t   assertNotIsInstance(    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyRB      sP   				



		*		t   _LogObserverc           B   sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   s  
    Observes the Twisted logs and catches any errors.

    @ivar _errors: A C{list} of L{Failure} instances which were received as
        error events from the Twisted logging system.

    @ivar _added: A C{int} giving the number of times C{_add} has been called
        less the number of times C{_remove} has been called; used to only add
        this observer to the Twisted logging since once, regardless of the
        number of calls to the add method.

    @ivar _ignored: A C{list} of exception types which will not be recorded.
    c         C   s   g  |  _  d |  _ g  |  _ d  S(   Ni    (   t   _errorst   _addedt   _ignored(   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR      s    		c         C   s   |  j  d k rm t j |  j  t j |  j |  _ t _ t j |  j |  _	 t _ t j
 |  j
 |  _ t _
 n  |  j  d 7_  d  S(   Ni    i   (   R   R   t   addObservert   gotEventt   _flushErrorst   flushErrorst   _oldFEt   _ignoret   _ignoreErrorst   _oldIEt   _clearIgnorest   _oldCI(   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _add  s    c         C   sY   |  j  d 8_  |  j  d k rU t j |  j  |  j t _ |  j t _ |  j t _	 n  d  S(   Ni   i    (
   R   R   t   removeObserverR   R   R   R   R   R   R   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _remove  s    c         G   s   |  j  j |  d S(   sF   
        Do not store any errors with any of the given types.
        N(   R   t   extend(   R   t
   errorTypes(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    c         C   s   g  |  _  d S(   sJ   
        Stop ignoring any errors we might currently be ignoring.
        N(   R   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    c         G   st   | r^ g  } g  } x= |  j  D]2 } | j |   rA | j |  q | j |  q W| |  _  n |  j  } g  |  _  | S(   s   
        Flush errors from the list of caught errors. If no arguments are
        specified, remove all errors. If arguments are specified, only remove
        errors of those types from the stored list.
        (   R   R   Rn   (   R   R   t   flushedt	   remainderR;   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   &  s    		c         C   s   |  j  S(   sB   
        Return a list of errors caught by this observer.
        (   R   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt	   getErrors;  s    c         C   sj   | j  d t  rf d | k rf | d } t |  j  d k sP | j |  j   rf |  j j |  qf n  d S(   s   
        The actual observer method. Called whenever a message is logged.

        @param event: A dictionary containing the log message. Actual
        structure undocumented (see source for L{twisted.python.log}).
        t   isErrorR   i    N(   t   getR   RP   R   R   R   Rn   (   R   t   eventR;   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   B  s    
((   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s   									t   TestCasec           B   s  e  Z d  Z e e j  e Z d d  Z e	 j
 d* k rO d   Z 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 d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d+ d  Z" d   Z# d   Z$ d   Z% d   Z& d    Z' d!   Z( d"   Z) d#   Z* d$   Z+ d%   Z, d&   Z- d'   Z. d(   Z/ e0 d)  Z1 RS(,   s  
    A unit test. The atom of the unit testing universe.

    This class extends C{unittest.TestCase} from the standard library. The
    main feature is the ability to return C{Deferred}s from tests and fixture
    methods and to have the suite wait for those C{Deferred}s to fire.

    To write a unit test, subclass C{TestCase} and define a method (say,
    'test_foo') on the subclass. To run the test, instantiate your subclass
    with the name of the method, and call L{run} on the instance, passing a
    L{TestResult} object.

    The C{trial} script will automatically find any C{TestCase} subclasses
    defined in modules beginning with 'test_' and construct test cases for all
    methods beginning with 'test'.

    If an error is logged during the test run, the test will fail with an
    error. See L{log.err}.

    @ivar failureException: An exception class, defaulting to C{FailTest}. If
    the test method raises this exception, it will be reported as a failure,
    rather than an exception. All of the assertion methods raise this if the
    assertion fails.

    @ivar skip: C{None} or a string explaining why this test is to be
    skipped. If defined, the test will not be run. Instead, it will be
    reported to the result object as 'skipped' (if the C{TestResult} supports
    skipping).

    @ivar suppress: C{None} or a list of tuples of C{(args, kwargs)} to be
    passed to C{warnings.filterwarnings}. Use these to suppress warnings
    raised in a test. Useful for testing deprecated code. See also
    L{util.suppress}.

    @ivar timeout: A real number of seconds. If set, the test will
    raise an error if it takes longer than C{timeout} seconds.
    If not set, util.DEFAULT_TIMEOUT_DURATION is used.

    @ivar todo: C{None}, a string or a tuple of C{(errors, reason)} where
    C{errors} is either an exception class or an iterable of exception
    classes, and C{reason} is a string. See L{Todo} or L{makeTodo} for more
    information.
    t   runTestc         C   sl   t  t |   j |  | |  _ t |  |  } | |  g |  _ |  j j t j |   t	 |  _
 g  |  _ d S(   s  
        Construct an asynchronous test case for C{methodName}.

        @param methodName: The name of a method on C{self}. This method should
        be a unit test. That is, it should be a short method that calls some of
        the assert* methods. If C{methodName} is unspecified, L{runTest} will
        be used as the test method. This is mostly useful for testing Trial.
        N(   t   superR   R   t   _testMethodNamet   getattrt   _parentsR   R   t   getPythonContainersR   t   _passedt	   _cleanups(   R   t
   methodNamet
   testMethod(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    			i   i   c         C   s
   |  | k S(   N(    (   R   Rs   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   __eq__  s    c         C   s
   |  | k	 S(   N(    (   R   Rs   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   __ne__  s    c            s   d d l  m   j          f d   } t j | t j d t   } t     } t	 j
 t j  j   |  }  j  | |   | j  f d    | S(   Ni(   t   reactorc            s   t  j d     f  } t j |  } y |  j |  Wnt t  j k
 r  j   t   _   j	   } | d  k	 r | j |  r  j   | |  q  j   |  n Xd  S(   Ns    %r (%s) still running at %s secs(   R   t   TimeoutErrorR   RJ   t   errbackt   AlreadyCalledErrort   crashR   t	   _timedOutt   getTodoR   R   t   addExpectedFailuret   addError(   t   dt   eR;   t   todo(   R   R@   t   timeoutR   R   (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt	   onTimeout  s    	
	R(   c            s     j    r   j   p |  S(   N(   t   activet   cancel(   t   x(   t   call(    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   <lambda>  s    (   t   twisted.internetR   t
   getTimeoutR   t   suppressWarningsR   t   suppresst   DeprecationWarningR   R   t   maybeDeferredt   runWithWarningsSuppressedt   getSuppresst	   callLatert   addBoth(   R   R   R@   R   t   methodR   (    (   R   R   R   R   R   R@   s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _run  s    c         C   s,   t  t |   j   } | d  k r( |  j S| S(   N(   R   R   t   shortDescriptionR   R   (   R   t   desc(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    c         O   s   |  j  | |   S(   N(   t   run(   R   R-   R<   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   __call__  s    c         C   s>   |  j  d |  } | j |  j |  j d | f d | f | S(   Nt   setUpt   callbackArgst   errbackArgs(   R   Rg   t   deferTestMethodt   _ebDeferSetUp(   R   t   ignoredR@   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt
   deferSetUp  s
    	
c         C   sg   | j  t  r+ | j |  |  j |   n, | j |  |  | j  t  rW | j   n  |  j d  |  S(   N(	   R   R   t   addSkipt
   _getReasonR   t   KeyboardInterruptt   stopt   deferRunCleanupsR   (   R   R   R@   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    c         C   sg   |  j  |  j |  } | j |  j |  j d | f d | f | j |  j |  | j |  j |  | S(   NR   R   (   R   R   Rg   t   _cbDeferTestMethodt   _ebDeferTestMethodR   R   t   deferTearDown(   R   R   R@   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    	
c         C   s8   |  j    d  k	 r+ | j |  |  j     n	 t |  _ | S(   N(   R   R   t   addUnexpectedSuccessR   R   (   R   R   R@   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    	c         C   s   |  j    } | d  k	 r= | j |  r= | j |  | |  n | j |  j t  re | j |  |  ng | j t  r | j	 |  |  | j
   n; | j t  r | j |  |  j |   n | j	 |  |  d  S(   N(   R   R   R   R   R   RC   R   t
   addFailureR   R   R   R   R   R   (   R   R;   R@   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    c         C   s)   |  j  d |  } | j |  j |  | S(   Nt   tearDown(   R   t
   addErrbackt   _ebDeferTearDown(   R   R   R@   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    c         C   s9   | j  |  |  | j t  r, | j   n  t |  _ d  S(   N(   R   R   R   R   R   R   (   R   R   R@   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    c         C   s#   |  j    } | j |  j |  | S(   sd   
        Run any scheduled cleanups and report errors (if any to the result
        object.
        (   t   _runCleanupst   addCallbackt   _cbDeferRunCleanups(   R   R   R@   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   	  s    c         C   sb   x[ | D]S \ } } | t  j k r | j |  |  | j t  rN | j   n  t |  _ q q Wd  S(   N(   R   t   FAILURER   R   R   R   R   R   (   R   t   cleanupResultsR@   t   flagR   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    c         C   s   y. t  j |  |  j   } | s- t |  _ n  Wn& | j |  t j    t |  _ n Xx0 |  j j	   D] } | j |  |  t |  _ qg W|  j
   |  j   |  j r | j |   n  d  S(   N(   R   t   _Janitort   postCaseCleanupR   R   R   R   RJ   t	   _observerR   t   flushLoggedErrorst   _removeObservert
   addSuccess(   R   R@   t   cleanR   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _cleanUp  s    

	c         C   s>   y t  j |  |  j   Wn | j |  t j    n Xd  S(   N(   R   R   t   postClassCleanupR   R   RJ   (   R   R@   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _classCleanUp*  s    c            s      f d   } | S(   s   
        Create a method which wraps the reactor method C{name}. The new
        method issues a deprecation warning and calls the original.
        c             s7   t  j d     f d d d t  j   |  |   S(   Ns{   reactor.%s cannot be used inside unit tests. In the future, using %s will fail the test and may crash or hang the test run.t
   stackleveli   R(   (   R7   t   warnR   t   _reactorMethods(   t   at   kw(   t   nameR   (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _5  s    	(    (   R   R  R  (    (   R   R  s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _makeReactorMethod0  s    c         C   sV   i  |  _  xF d d d g D]5 } t | |  |  j  | <t | | |  j |   q Wd S(   s   
        Deprecate C{iterate}, C{crash} and C{stop} on C{reactor}. That is,
        each method is wrapped in a function that issues a deprecation
        warning, then calls the original.

        @param reactor: The Twisted reactor.
        R   t   iterateR   N(   R  R   t   setattrR	  (   R   R   R  (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _deprecateReactor>  s    	c         C   s=   x- |  j  j   D] \ } } t | | |  q Wi  |  _  d S(   s   
        Restore the deprecated reactor methods. Undoes what
        L{_deprecateReactor} did.

        @param reactor: The Twisted reactor.
        N(   R  t	   iteritemsR  (   R   R   R  R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _undeprecateReactorK  s    c         C   s   t  |  _ |  j j   d  S(   N(   t   _logObserverR   R   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _installObserverV  s    	c         C   s   |  j  j   d  S(   N(   R   R   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   Z  s    c         G   s   |  j  j |   S(   s  
        Remove stored errors received from the log.

        C{TestCase} stores each error logged during the run of the test and
        reports them as errors during the cleanup phase (after C{tearDown}).

        @param *errorTypes: If unspecifed, flush all errors. Otherwise, only
        flush errors that match the given types.

        @return: A list of failures that have been removed.
        (   R   R   (   R   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   ]  s    c         C   su  | d	 k r# |  j } g  |  j (ng  } x |  j D] } x | D] } t | t j t j f  sw t d | f   n  t j | j	 } t
 j |  } | t j j | j  k r q@ n  t t | j   } | d d } | d d }	 | | j k o|	 k n sq@ n  | j |  Pq@ Wq3 Wt |  j j |  g  | D]4 }
 i |
 j d 6|
 j d 6|
 j d 6|
 j d 6^ q=S(
   sv  
        Remove stored warnings from the list of captured warnings and return
        them.

        @param offendingFunctions: If C{None}, all warnings issued during the
            currently running test will be flushed.  Otherwise, only warnings
            which I{point} to a function included in this list will be flushed.
            All warnings include a filename and source line number; if these
            parts of a warning point to a source line which is part of a
            function, then the warning I{points} to that function.
        @type offendingFunctions: L{NoneType} or L{list} of functions or methods.

        @raise ValueError: If C{offendingFunctions} is not C{None} and includes
            an object which is not a L{FunctionType} or L{MethodType} instance.

        @return: A C{list}, each element of which is a C{dict} giving
            information about one warning which was flushed by this call.  The
            keys of each C{dict} are:

                - C{'message'}: The string which was passed as the I{message}
                  parameter to L{warnings.warn}.

                - C{'category'}: The warning subclass which was passed as the
                  I{category} parameter to L{warnings.warn}.

                - C{'filename'}: The name of the file containing the definition
                  of the code object which was C{stacklevel} frames above the
                  call to L{warnings.warn}, where C{stacklevel} is the value of
                  the C{stacklevel} parameter passed to L{warnings.warn}.

                - C{'lineno'}: The source line associated with the active
                  instruction of the code object object which was C{stacklevel}
                  frames above the call to L{warnings.warn}, where
                  C{stacklevel} is the value of the C{stacklevel} parameter
                  passed to L{warnings.warn}.
        s   %r is not a function or methodi    i   iR'   R(   R)   R*   N(   R   t	   _warningsR   t   typest   FunctionTypet
   MethodTypet
   ValueErrorR3   R4   R   t   inspectt
   getabsfilet   ost   patht   normcaseR)   R"   t   _findlinestartst	   func_codeR*   Rn   t   mapt   removeR'   R(   (   R   t   offendingFunctionst   toFlusht   aWarningt	   aFunctiont   aModuleR)   t
   lineStartsRQ   t   lastt   w(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   flushWarningsl  s0    %
	c         O   s   |  j  j | | | f  d S(   s  
        Add the given function to a list of functions to be called after the
        test has run, but before C{tearDown}.

        Functions will be run in reverse order of being added. This helps
        ensure that tear down complements set up.

        The function C{f} may return a Deferred. If so, C{TestCase} will wait
        until the Deferred has fired before proceeding to the next function.
        N(   R   Rn   (   R   R;   R-   R<   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt
   addCleanup  s    c         O   s   | | |   } |  j  |  j g  } y t |  } Wn t k
 rS | } d }	 n X| \ } }	 t |  d k r |  j d | f  n  | d d }
 t | | d |	 } |  j | |
  | S(   s[  
        Call a function that should have been deprecated at a specific version
        and in favor of a specific alternative, and assert that it was thusly
        deprecated.

        @param version: A 2-sequence of (since, replacement), where C{since} is
            a the first L{version<twisted.python.versions.Version>} that C{f}
            should have been deprecated since, and C{replacement} is a suggested
            replacement for the deprecated functionality, as described by
            L{twisted.python.deprecate.deprecated}.  If there is no suggested
            replacement, this parameter may also be simply a
            L{version<twisted.python.versions.Version>} by itself.

        @param f: The deprecated function to call.

        @param args: The arguments to pass to C{f}.

        @param kwargs: The keyword arguments to pass to C{f}.

        @return: Whatever C{f} returns.

        @raise: Whatever C{f} raises.  If any exception is
            raised by C{f}, though, no assertions will be made about emitted
            deprecations.

        @raise FailTest: if no warnings were emitted by C{f}, or if the
            L{DeprecationWarning} emitted did not produce the canonical
            please-use-something-else message that is standard for Twisted
            deprecations according to the given version and replacement.
        i    s   %r is not deprecated.R'   t   replacementN(	   R'  t   callDeprecatedR"   R#   R   RP   RE   R   Ro   (   R   t   versionR;   R-   R<   R@   Rr   t   infot   sinceR)  t   observedWarningt   expectedWarning(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR*    s    
c         C   si   d   } g  } xJ t  |  j  d k r[ |  j j   \ } } } | j | | | |   q Wt j |  S(   s   
        Run the cleanups added with L{addCleanup} in order.

        @return: A C{Deferred} that fires when all cleanups are run.
        c            s       f d   S(   Nc              s         S(   N(    (    (   R<   R-   R;   (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    (    (   R;   R-   R<   (    (   R<   R-   R;   s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _makeFunction  s    i    (   RP   R   t   popRn   R   t   _runSequentially(   R   R0  t	   callablesR;   R-   R<   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    	c         C   s6   t  j | | | f  } | j   |  j | j  | S(   s  
        Monkey patch an object for the duration of the test.

        The monkey patch will be reverted at the end of the test using the
        L{addCleanup} mechanism.

        The L{MonkeyPatcher} is returned so that users can restore and
        re-apply the monkey patch within their tests.

        @param obj: The object to monkey patch.
        @param attribute: The name of the attribute to change.
        @param value: The value to set the attribute to.
        @return: A L{monkey.MonkeyPatcher} object.
        (   R   t   MonkeyPatchert   patchR(  t   restore(   R   t   objt	   attributeR$   t   monkeyPatch(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR5    s    
c         C   s   d S(   s   
        If no C{methodName} argument is passed to the constructor, L{run} will
        treat this method as the thing with the actual test inside.
        N(    (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   #  s    c            s7  t  j d  j    d d l m   t j  d  } | d k rT t    n |  t	  _
  j    j   r  j   j     j   d S j       f d   } g   _ t  j j |  xE  j   D]7 } y t j |   Wq  j  t j    q Xq W j   d S(   sQ  
        Run the test case, storing the results in C{result}.

        First runs C{setUp} on self, then runs the test method (defined in the
        constructor), then runs C{tearDown}. Any of these may return
        L{Deferred}s. After they complete, does some reactor cleanup.

        @param result: A L{TestResult} object.
        s
   --> %s <--i(   R   Nc             sp   t   _  j    zE  j d    }  z  j |   Wd   j    j   XWd   j    Xd  S(   N(	   R   R   R  R   R   t   _waitR   R  R  (   R   (   R   R   R@   (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   runThunkE  s    	(   R   RD   t   idR   R   R	   t	   IReporterR   t   PyUnitResultAdapterR   R   t	   startTestt   getSkipR   t   stopTestR  R  RA   Rn   R'  R7   t   warn_explicitR   R   RJ   (   R   R@   t
   new_resultR;  R&  (    (   R   R   R@   s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   *  s,    
	
	c         C   sH   t  | j j  d k r+ | j j d } n t j d d d | } | S(   Ni    sS   Do not raise unittest.SkipTest with no arguments! Give a reason for skipping tests!R  i   (   RP   R$   R-   R7   R  (   R   R;   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   `  s    c         C   s   t  j |  j d d  S(   sU  
        Return the skip reason set on this test, if any is set. Checks on the
        instance first, then the class, then the module, then packages. As
        soon as it finds something with a C{skip} attribute, returns that.
        Returns C{None} if it cannot find anything. See L{TestCase} docstring
        for more details.
        t   skipN(   R   t   acquireAttributeR   R   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR@  j  s    c         C   s2   t  j |  j d d  } | d k r( d St |  S(   sQ  
        Return a L{Todo} object if the test is marked todo. Checks on the
        instance first, then the class, then the module, then packages. As
        soon as it finds something with a C{todo} attribute, returns that.
        Returns C{None} if it cannot find anything. See L{TestCase} docstring
        for more details.
        R   N(   R   RE  R   R   R%   (   R   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   t  s    c         C   s^   t  j |  j d t  j  } y t |  SWn. t t f k
 rY t j d d t	 t  j SXd S(   se  
        Returns the timeout value set on this test. Checks on the instance
        first, then the class, then the module, then packages. As soon as it
        finds something with a C{timeout} attribute, returns that. Returns
        L{util.DEFAULT_TIMEOUT_DURATION} if it cannot find anything. See
        L{TestCase} docstring for more details.
        R   s)   'timeout' attribute needs to be a number.R(   N(
   R   RE  R   t   DEFAULT_TIMEOUT_DURATIONt   floatR  R#   R7   R  R   (   R   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    c         C   s   t  j |  j d g   S(   sx  
        Returns any warning suppressions set for this test. Checks on the
        instance first, then the class, then the module, then packages. As
        soon as it finds something with a C{suppress} attribute, returns that.
        Returns any empty list (i.e. suppress no warnings) if it cannot find
        anything. See L{TestCase} docstring for more details.
        R   (   R   RE  R   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    c         C   s!   t  j d d t | |   d S(   s   
        Visit this test case. Call C{visitor} with C{self} as a parameter.

        Deprecated in Twisted 8.0.

        @param visitor: A callable which expects a single parameter: a test
        case.

        @return: None
        s'   Test visitors deprecated in Twisted 8.0R(   N(   R7   R  R   (   R   t   visitor(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   visit  s    c         C   s   d } t  j j |  j j |  |  j j |  |  j |   } t  j j |  s[ t  j |  n  t	 j
 d d |  } t  j j | d  S(   s   Returns a unique name that may be used as either a temporary
        directory or filename.

        @note: you must call os.mkdir on the value returned from this
               method if you wish to use it as a directory!
        i    RO   t   temp(   R  R  t   joint	   __class__R   R   R   t   existst   makedirst   tempfilet   mkdtemp(   R   t   MAX_FILENAMEt   baset   dirname(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   mktemp  s    c            s-  d d l  m  | r% t d   n  g      f d   }    f d   } t j | t j d d d t   }  f d	   } t j | t j d d d t   } | j d
  ze | j
 |    r d
 S| j
 |  |  _ z  j   Wd
  ` X  s|  j rd
 St    Wd
 d
   | j   Xd
 S(   sJ   Take a Deferred that only ever callbacks. Block until it happens.
        i(   R   s   _wait is not reentrantc            s      d  k	 r   j |   n  d  S(   N(   R   Rn   (   t   any(   t   results(    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyRn     s    c            s     d  k	 r  j   n  d  S(   N(   R   R   (   t   ign(   RV  R   (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    R'   s   reactor\.crash cannot be used.*R(   c              s     j    d  S(   N(   R   (    (   R   (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    N(   R   R   t   RuntimeErrorR   R   R   R   R   Rn   R   R   R   R   R   R   R1  (   R   R   t   runningRn   R   R   (    (   RV  R   s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR:    s8    	(   i   i   N(2   R   R   R   R   R	   t	   ITestCaseR   RC   R   R3   t   version_infoR   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  R	  R  R  R  R   R   R   R'  R(  R*  R   R5  R   R   R   R@  R   R   R   RI  RT  t   _wait_is_runningR:  (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   T  sT   +		 																						Q		4				6	
	
					t   UnsupportedTrialFeaturec           B   s   e  Z d  Z RS(   s?   A feature of twisted.trial was used that pyunit cannot support.(   R   R   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR]     s   R>  c           B   sz   e  Z d  Z 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(   s   
    Wrap a C{TestResult} from the standard library's C{unittest} so that it
    supports the extended result types from Trial, and also supports
    L{twisted.python.failure.Failure}s being passed to L{addError} and
    L{addFailure}.
    c         C   s   | |  _  d S(   sM   
        @param original: A C{TestResult} instance from C{unittest}.
        N(   t   original(   R   R^  (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    c         C   s   t  j |  S(   N(   R   t   excInfoOrFailureToExcInfo(   R   t   err(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt	   _exc_info  s    c         C   s   |  j  j |  d  S(   N(   R^  R?  (   R   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR?    s    c         C   s   |  j  j |  d  S(   N(   R^  RA  (   R   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyRA    s    c         C   s    |  j  j | |  j |   d  S(   N(   R^  R   Ra  (   R   t   testRE   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    c         C   s    |  j  j | |  j |   d  S(   N(   R^  R   Ra  (   R   Rb  R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    c         C   s)   |  j  j | t t | |  d  f  d  S(   N(   R^  R   R]  R   (   R   Rb  t   featureR,  (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _unsupported"  s
    	c         C   s   |  j  | d |  d S(   s/   
        Report the skip as a failure.
        RD  N(   Rd  (   R   Rb  R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   )  s    c         C   s   |  j  | d |  d S(   s=   
        Report the unexpected success as a failure.
        s   unexpected successN(   Rd  (   R   Rb  R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   /  s    c         C   s   |  j  | d |  d S(   sG   
        Report the expected failure (i.e. todo) as a failure.
        s   expected failureN(   Rd  (   R   Rb  R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   5  s    c         C   s   |  j  j |  d  S(   N(   R^  R   (   R   Rb  (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   ;  s    c         C   s   d  S(   N(    (   R   R   R   R  t   printStatus(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   upDownError>  s    (   R   R   R   R   Ra  R?  RA  R   R   Rd  R   R   R   R   Rf  (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR>    s   											c         C   s   t  j d d t x |  j D] } t | d d  } | d k	 rN | |  q t | t j  r t	 j
 |  } | j |  q t | t j  r t | |  q | j |  q Wd S(   s   
    Visit each test in C{suite} with C{visitor}.

    Deprecated in Twisted 8.0.

    @param visitor: A callable which takes a single argument, the L{TestCase}
    instance to visit.
    @return: None
    s'   Test visitors deprecated in Twisted 8.0R(   RI  N(   R7   R  R   t   _testsR   R   R   t   pyunitR   R	   RZ  RI  t	   TestSuitet
   suiteVisit(   t   suiteRH  t   caseRI  (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyRj  C  s    
Ri  c           B   s&   e  Z d  Z e Z d   Z d   Z RS(   s   
    Extend the standard library's C{TestSuite} with support for the visitor
    pattern and a consistently overrideable C{run} method.
    c         C   s   |  j  |  S(   N(   R   (   R   R@   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   e  s    c         C   s/   x( |  j  D] } | j r Pn  | |  q
 W| S(   s;   
        Call C{run} on every member of the suite.
        (   Rg  t
   shouldStop(   R   R@   Rb  (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR   i  s
    	(   R   R   R   Rj  RI  R   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyRi  ]  s   	t   TestDecoratort   _originalTestc           B   s-   e  Z d  Z e e j  d   Z d   Z RS(   s   
    Decorator for test cases.

    @param _originalTest: The wrapped instance of test.
    @type _originalTest: A provider of L{itrial.ITestCase}
    c         C   s   |  j  |  S(   sQ   
        Run the unit test.

        @param result: A TestResult object.
        (   R   (   R   R@   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    c         C   s   |  j  j t j | |  j   S(   sQ   
        Run the unit test.

        @param result: A TestResult object.
        (   Ro  R   R
   t   _AdaptedReporterRL  (   R   R@   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    	(   R   R   R   R   R	   RZ  R   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyRn  w  s   		c         C   s   g  |  _  d S(   s   
    Clear all tests from C{suite}.

    This messes with the internals of C{suite}. In particular, it assumes that
    the suite keeps all of its tests in a list in an instance variable called
    C{_tests}.
    N(   Rg  (   Rk  (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   _clearSuite  s    c         C   s`   y t  |   } Wn t k
 r* | |   SXt |   x$ | D] } |  j t | |   q< W|  S(   s2  
    Decorate all test cases in C{test} with C{decorator}.

    C{test} can be a test case or a test suite. If it is a test suite, then the
    structure of the suite is preserved.

    L{decorate} tries to preserve the class of the test suites it finds, but
    assumes the presence of the C{_tests} attribute on the suite.

    @param test: The C{TestCase} or C{TestSuite} to decorate.

    @param decorator: A unary callable used to decorate C{TestCase}s.

    @return: A decorated C{TestCase} or a C{TestSuite} containing decorated
        C{TestCase}s.
    (   t   iterR#   Rq  t   addTestt   decorate(   Rb  t	   decoratort   testsRl  (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyRt    s    
t   _PyUnitTestCaseAdapterc           B   s   e  Z d  Z d   Z RS(   s2   
    Adapt from pyunit.TestCase to ITestCase.
    c         C   s!   t  j d d t | |   d S(   s,   
        Deprecated in Twisted 8.0.
        s'   Test visitors deprecated in Twisted 8.0R(   N(   R7   R  R   (   R   RH  (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyRI    s    (   R   R   R   RI  (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyRw    s   t   _BrokenIDTestCaseAdapterc           B   s   e  Z d  Z d   Z RS(   s   
    Adapter for pyunit-style C{TestCase} subclasses that have undesirable id()
    methods. That is L{pyunit.FunctionTestCase} and L{pyunit.DocTestCase}.
    c         C   s,   |  j  j   } | d k	 r | S|  j  j   S(   sH   
        Return the fully-qualified Python name of the doctest.
        N(   Ro  R   R   R<  (   R   t   testID(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR<    s    (   R   R   R   R<  (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyRx    s   t    _ForceGarbageCollectionDecoratorc           B   s   e  Z d  Z d   Z RS(   s   
    Forces garbage collection to be run before and after the test. Any errors
    logged during the post-test collection are added to the test result as
    errors.
    c         C   sm   t  j   t j |  |  t j   t  j   x$ t j   D] } | j |  |  q; Wt j   t j	   d  S(   N(
   t   gct   collectRn  R   R  R   R   R   R   R   (   R   R@   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    



(   R   R   R   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyRz    s   t   DocTestCasec         c   sZ   y t  |   } Wn t k
 r( |  Vn. Xx* | D]" } x t |  D] } | VqC Wq0 Wd S(   sF   
    Iterate through all of the test cases in C{testSuiteOrCase}.
    N(   Rr  R#   t   _iterateTests(   t   testSuiteOrCaseRk  Rb  t   subtest(    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR~    s    	c         C   s   t  |  j  S(   N(   Rr  Rg  (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   __iter__  s    t   _SubTestCasec           B   s   e  Z d    Z RS(   c         C   s   t  j |  d  d  S(   NR   (   R   R   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR     s    (   R   R   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR    s   c            s     f d   } | S(   sR   
    Internal method used to deprecate top-level assertions. Do not use this.
    c             s9   t  j d     f d d d t t t    |  |   S(   NsJ   unittest.%s is deprecated.  Instead use the %r method on unittest.TestCaseR  i   R(   (   R7   R  R   R   t   _inst(   R-   R<   (   R  (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyR  '  s    	(    (   R  R  (    (   R  s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt
   _deprecate#  s    RE   RS   RV   R   RH   RT   RY   RU   RZ   RG   R^   R]   RN   R   R   Rl   Rm   R   R   R   R   Ro   R   R   R   R   R|   Rp   R   R   R   Ri   R   R   (J   R   t   doctestR  R  R7   R3   RO  R{  R  t   pprintR    t   disR   R  R   R   R   t   twisted.pythonR   R   R   R   t   twisted.python.deprecateR   t   twisted.trialR	   R
   R   t
   __import__Rh  t   zope.interfaceR   t	   ExceptionR   R,   R   t   objectR   R%   R&   RA   R   RB   R   R  R\  R]  R>  Rj  Ri  t   proxyForInterfaceRZ  Rn  Rq  Rt  Rw  Rx  Rz  t   registerAdaptert   FunctionTestCaseR   R   t   _docTestCaseR~  Rr  R#   R  R  R  R  t   _assertionsR   t   globalst   __all__(    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/trial/unittest.pyt   <module>	   s   H"&	 	) A_	  >			 											