
Mc           @   s  d  Z  d d d d d d d d d	 d
 d d d d d d d d d d g 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
 Z
 d d l m Z m Z m Z m Z m Z d d l m Z d d l m Z d d l m Z m Z d d l m Z d d l m Z d d l m Z m Z d d l m  Z  e! d  Z" d    Z# d!   Z$ d"   Z% d#   Z& e' d$  Z( d%   Z) d&   Z* d e f d'     YZ+ d( Z, d e f d)     YZ- d e f d*     YZ. d	 e/ f d+     YZ0 d e0 f d,     YZ1 d e f d-     YZ2 d.   Z3 d/   Z4 d
 e/ f d0     YZ5 d e5 f d1     YZ6 d e/ f d2     YZ7 d e/ f d3     YZ8 d e/ f d4     YZ9 d S(5   sK   
A miscellany of code used to run Trial tests.

Maintainer: Jonathan Lange
t
   suiteVisitt	   TestSuitet   DestructiveTestSuitet   DocTestCaset   DocTestSuitet   DryRunVisitort   ErrorHoldert   LoggedSuitet   PyUnitTestCaset
   TestHoldert
   TestLoadert   TrialRunnert
   TrialSuitet   filenameToModulet	   isPackaget   isPackageDirectoryt
   isTestCaset   namet   samefilet   NOT_IN_TESTiN(   t   reflectt   logt   failuret   modulest   filepath(   t   set(   t   defer(   t   utilt   unittest(   t	   ITestCase(   t   UncleanWarningsReporterWrapper(   R    R   (   t
   implementsR   c         C   sE   t  |  t j  s t St j j t j j |  j   d } | d k S(   s>   Given an object return True if the object looks like a packagei    t   __init__(	   t
   isinstancet   typest
   ModuleTypet   Falset   ost   patht   splitextt   basenamet   __file__(   t   moduleR(   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR   +   s    %c         C   sT   xM t  t j     d D]5 } d | } t j j t j j |  |   r | Sq Wt S(   s   Is the directory at path 'dirname' a Python package directory?
    Returns the name of the __init__ file (it may have a weird extension)
    if dirname is a package directory.  Otherwise, returns Falsei    R    (   t   zipt   impt   get_suffixesR%   R&   t   existst   joinR$   (   t   dirnamet   extt   initFile(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR   3   s
    
!c         C   s"   t  j j |   t  j j |  k S(   s   
    A hacky implementation of C{os.path.samefile}. Used by L{filenameToModule}
    when the platform doesn't provide C{os.path.samefile}. Do not use this.
    (   R%   R&   t   abspath(   t	   filename1t	   filename2(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR   >   s    c         C   s   t  j j |   s( t d |  f   n  y t j t j |    } Wn t t f k
 rd t |   SXt  j j	 | j
  d d } t t  j d t  } t  j j |   r | |  |  r t j | j =t |   } n  | S(   sV  
    Given a filename, do whatever possible to return a module object matching
    that file.

    If the file in question is a module in Python path, properly import and
    return that module. Otherwise, load the source manually.

    @param fn: A filename.
    @return: A module object.
    @raise ValueError: If C{fn} does not exist.
    s   %r doesn't existi    s   .pyR   (   R%   R&   R.   t
   ValueErrorR   t   namedAnyt   filenameToModuleNamet   AttributeErrort   _importFromFileR'   R)   t   getattrR   t   isfilet   sysR   t   __name__(   t   fnt   rett   retFilet   same(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR   F   s    "c         C   s   t  |   }  | s; t j j t j j |   d  d } n  | t j k rU t j | St |  d  } z t j	 | |  |  } Wd  | j
   X| S(   Nii    t   r(   t   _resolveDirectoryR%   R&   R'   t   splitR=   R   t   openR,   t   load_sourcet   close(   R?   t
   moduleNamet   fdR*   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR:   c   s    )c         C   sV   t  j j |   rR t |   } | r< t  j j |  |  }  qR t d |  f   n  |  S(   Ns   %r is not a package directory(   R%   R&   t   isdirR   R/   R6   (   R?   R2   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyRD   q   s    c         C   sg   t  |  j |  j t    |  k r` x< t |  j  D]( } t  |  j | t    |  k r1 | Sq1 Wn  |  j S(   s   
    Find the attribute name on the method's class which refers to the method.

    For some methods, notably decorators which have not had __name__ set correctly:

    getattr(method.im_class, method.__name__) != method
    (   R;   t   im_classR>   t   objectt   dir(   t   methodt   alias(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   _getMethodNameInClass{   s
    !c           B   s   e  Z d  Z d   Z RS(   sQ   
    A test suite which remove the tests once run, to minimize memory usage.
    c         C   s=   x6 |  j  r8 | j r Pn  |  j  j d  } | |  q W| S(   sn   
        Almost the same as L{TestSuite.run}, but with C{self._tests} being
        empty at the end.
        i    (   t   _testst
   shouldStopt   pop(   t   selft   resultt   test(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   run   s    	(   R>   t
   __module__t   __doc__RX   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR      s   s   <not in test>c           B   s   e  Z d  Z d   Z RS(   s[   
    Any errors logged in this suite will be reported to the L{TestResult}
    object.
    c         C   sn   t  j } | j   t t |   j |  | j   x* | j   D] } | j t	 t
  |  q@ W| j   d S(   s   
        Run the suite, storing all errors in C{result}. If an error is logged
        while no tests are running, then it will be added as an error to
        C{result}.

        @param result: A L{TestResult} object.
        N(   R   t   _logObservert   _addt   superR   RX   t   _removet	   getErrorst   addErrorR	   R   t   flushErrors(   RU   RV   t   observert   error(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyRX      s    	

(   R>   RY   RZ   RX   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR      s   c           B   s   e  Z d  Z d   Z RS(   s   
    DEPRECATED in Twisted 8.0.

    Behaves like doctest.DocTestSuite, but decorates individual TestCases so
    they support visit and so that id() behaviour is meaningful and consistent
    between Python versions.
    c         C   s`   t  j d d t d d t j |   t j |  } x$ | j D] } |  j t	 |   q? Wd  S(   Ns*   DocTestSuite is deprecated in Twisted 8.0.t   categoryt
   stackleveli   (
   t   warningst   warnt   DeprecationWarningR   R    t   doctestR   RR   t   addTestR   (   RU   t
   testModulet   suiteRW   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR       s    (   R>   RY   RZ   R    (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR      s   c           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s  
    DEPRECATED in Twisted 8.0.

    This class decorates the pyunit.TestCase class, mainly to work around the
    differences between unittest in Python 2.3, 2.4, and 2.5. These
    differences are::

        - The way doctest unittests describe themselves
        - Where the implementation of TestCase.run is (used to be in __call__)
        - Where the test method name is kept (mangled-private or non-mangled
          private variable)

    It also implements visit, which we like.
    c         C   s,   t  j d d t | |  _ |  j | _ d  S(   Ns   Deprecated in Twisted 8.0.Rd   (   Rf   Rg   Rh   t   _testt   id(   RU   RW   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR       s    	c         C   sV   |  j  j } t |  j  d d   } | d  k r< |  j  j } n  | j d | j d | S(   Nt   _TestCase__testMethodNamet   .(   Rm   t	   __class__R;   t   Nonet   _testMethodNameRY   R>   (   RU   t   clst   tmn(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyRn      s    c         C   s   d |  j    f S(   Ns   PyUnitTestCase<%r>(   Rn   (   RU   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   __repr__   s    c         C   s   |  j  |  S(   N(   Rm   (   RU   t   results(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   __call__   s    c         C   s$   t  j d d t | |  j  d S(   s   
        Call the given visitor with the original, standard library, test case
        that C{self} wraps. See L{unittest.TestCase.visit}.

        Deprecated in Twisted 8.0.
        s'   Test visitors deprecated in Twisted 8.0Rd   N(   Rf   Rg   Rh   Rm   (   RU   t   visitor(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   visit   s    c         C   s   t  |  j |  S(   N(   R;   Rm   (   RU   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   __getattr__   s    (	   R>   RY   RZ   R    Rn   Rv   Rx   Rz   R{   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR      s   						c           B   s   e  Z d  Z d   Z RS(   s$   
    DEPRECATED in Twisted 8.0.
    c         C   s   |  j  j   S(   s   
        In Python 2.4, doctests have correct id() behaviour. In Python 2.3,
        id() returns 'runit'.

        Here we override id() so that at least it will always contain the
        fully qualified Python name of the doctest.
        (   Rm   t   shortDescription(   RU   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyRn   
  s    (   R>   RY   RZ   Rn   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR     s   c           B   s,   e  Z d  Z d d  Z d   Z d   Z RS(   s   
    Suite to wrap around every single test in a C{trial} run. Used internally
    by Trial to set up things necessary for Trial tests to work, regardless of
    what context they are run in.
    c         C   s)   t  |  } t t |   j | g  d  S(   N(   R   R]   R   R    (   RU   t   testsRl   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR      s    c            s_   d d l  m } t j     | j d d   f d    | j d  t j d  j    d  S(   Ni(   t   reactort   aftert   shutdownc              s     j  d   S(   N(   t   callbackRr   (    (   t   d(    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   <lambda>%  s    t   mktemp(	   t   twisted.internetR~   R   t   Deferredt   addSystemEventTriggert   fireSystemEventR   t   TestCaset   _wait(   RU   R~   (    (   R   s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   _bail!  s    c         C   s&   z t  j |  |  Wd  |  j   Xd  S(   N(   R   RX   R   (   RU   RV   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyRX   -  s    (    (   R>   RY   RZ   R    R   RX   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR     s   	c         C   sO   t  |   r t j |   } n- y |  j   } Wn t k
 rJ |  j } n X| S(   s   
    @param thing: an object from modules (instance of PythonModule,
    PythonAttribute), a TestCase subclass, or an instance of a TestCase.
    (   R   R   t   qualRn   R9   R   (   t   thingt   theName(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR   4  s    c         C   s-   y t  |  t j  SWn t k
 r( t SXd S(   s   
    Returns C{True} if C{obj} is a class that contains test cases, C{False}
    otherwise. Used to find all the tests in a module.
    N(   t
   issubclasst   pyunitR   t	   TypeErrorR$   (   t   obj(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR   G  s    c           B   sT   e  Z d  Z e e  d Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z RS(   s   
    Placeholder for a L{TestCase} inside a reporter. As far as a L{TestResult}
    is concerned, this looks exactly like a unit test.
    c         C   s   | |  _  d S(   sM   
        @param description: A string to be displayed L{TestResult}.
        N(   t   description(   RU   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR    ]  s    c         C   s   |  j  |  S(   N(   RX   (   RU   RV   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyRx   d  s    c         C   s   |  j  S(   N(   R   (   RU   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyRn   h  s    c         C   s   d S(   Ni    (    (   RU   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   countTestCasesl  s    c         C   s+   | j  |   | j |   | j |   d S(   s   
        This test is just a placeholder. Run the test successfully.

        @param result: The C{TestResult} to store the results in.
        @type result: L{twisted.trial.itrial.ITestResult}.
        N(   t	   startTestt
   addSuccesst   stopTest(   RU   RV   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyRX   p  s    c         C   s   |  j  S(   N(   R   (   RU   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR|   |  s    N(   R>   RY   RZ   R   R   Rr   t   failureExceptionR    Rx   Rn   R   RX   R|   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR	   S  s   
					c           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s  
    Used to insert arbitrary errors into a test suite run. Provides enough
    methods to look like a C{TestCase}, however, when it is run, it simply adds
    an error to the C{TestResult}. The most common use-case is for when a
    module fails to import.
    c         C   s#   t  t |   j |  | |  _ d S(   s)  
        @param description: A string used by C{TestResult}s to identify this
        error. Generally, this is the name of a module that failed to import.

        @param error: The error to be added to the result. Can be an exc_info
        tuple or a L{twisted.python.failure.Failure}.
        N(   R]   R   R    Rc   (   RU   R   Rc   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR      s    c         C   s   d |  j  |  j f S(   Ns%   <ErrorHolder description=%r error=%r>(   R   Rc   (   RU   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyRv     s    	c         C   s:   | j  |   | j |  t j |  j   | j |   d S(   s   
        Run the test, reporting the error.

        @param result: The C{TestResult} to store the results in.
        @type result: L{twisted.trial.itrial.ITestResult}.
        N(   R   R`   R   t   excInfoOrFailureToExcInfoRc   R   (   RU   RV   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyRX     s    c         C   s   | |   d S(   s1   
        See L{unittest.TestCase.visit}.
        N(    (   RU   Ry   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyRz     s    (   R>   RY   RZ   R    Rv   RX   Rz   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR     s
   			c           B   s   e  Z d  Z d Z d Z d   Z d   Z d   Z d   Z d   Z	 e	 Z
 d   Z e Z d	   Z d
   Z d   Z e d  Z d   Z e d  Z e d  Z e Z e d  Z d   Z RS(   s4  
    I find tests inside function, modules, files -- whatever -- then return
    them wrapped inside a Test (either a L{TestSuite} or a L{TestCase}).

    @ivar methodPrefix: A string prefix. C{TestLoader} will assume that all the
    methods in a class that begin with C{methodPrefix} are test cases.

    @ivar modulePrefix: A string prefix. Every module in a package that begins
    with C{modulePrefix} is considered a module full of tests.

    @ivar forceGarbageCollection: A flag applied to each C{TestCase} loaded.
    See L{unittest.TestCase} for more information.

    @ivar sorter: A key function used to sort C{TestCase}s, test classes,
    modules and packages.

    @ivar suiteFactory: A callable which is passed a list of tests (which
    themselves may be suites of tests). Must return a test suite.
    RW   t   test_c         C   s   t  |  _ t |  _ g  |  _ d  S(   N(   R   t   suiteFactoryR   t   sortert   _importErrors(   RU   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR      s    		c         C   s   t  | d |  j S(   st   
        Sort the given things using L{sorter}.

        @param xs: A list of test cases, class or modules.
        t   key(   t   sortedR   (   RU   t   xs(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   sort  s    c         C   sO   g  } x9 t  j |  D]( \ } } t |  r | j |  q q W|  j |  S(   s-   Given a module, return all Trial test classes(   t   inspectt
   getmembersR   t   appendR   (   RU   R*   t   classesR   t   val(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   findTestClasses  s
    c         C   s)   t  j j |  r t |  St j |  S(   sB  
        Return a Python object given a string describing it.

        @param name: a string which may be either a filename or a
        fully-qualified Python name.

        @return: If C{name} is a filename, return the module. If C{name} is a
        fully-qualified Python name, return the object it refers to.
        (   R%   R&   R.   R   R   R7   (   RU   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt
   findByName  s    

c         C   s   t  | t j  s( t d | f   n  t | d  rA | j   St | d  rZ | j   S|  j   } x- |  j |  D] } | j	 |  j
 |   qv Wt | d  s | S|  j   } x' | j D] } | j	 |  j |   q W|  j | | g  S(   s  
        Return a test suite with all the tests from a module.

        Included are TestCase subclasses and doctests listed in the module's
        __doctests__ module. If that's not good for you, put a function named
        either C{testSuite} or C{test_suite} in your module that returns a
        TestSuite, and I'll use the results of that instead.

        If C{testSuite} and C{test_suite} are both present, then I'll use
        C{testSuite}.
        s   %r is not a modulet	   testSuitet
   test_suitet   __doctests__(   R!   R"   R#   R   t   hasattrR   R   R   R   Rj   t	   loadClassR   t   loadDoctests(   RU   R*   Rl   t	   testClasst   docSuiteRi   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt
   loadModule  s    

c         C   s   t  | t  p t  | t j  s7 t d | f   n  t |  sY t d | f   n  |  j |  } |  j g  | D] } |  j	 | |  j
 |  ^ qu  } |  j |  S(   sq   
        Given a class which contains test cases, return a sorted list of
        C{TestCase} instances.
        s   %r is not a classs   %r is not a test case(   R!   t   typeR"   t	   ClassTypeR   R   R6   t   getTestCaseNamesR   t	   _makeCaset   methodPrefixR   (   RU   t   klasst   namesR   R}   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR   	  s    !	,c         C   s   t  j | |  j  S(   s   
        Given a class that contains C{TestCase}s, return a list of names of
        methods that probably contain tests.
        (   R   t   prefixedMethodNamesR   (   RU   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR     s    c         C   sA   t  | t j  s( t d | f   n  |  j | j t |   S(   s~   
        Given a method of a C{TestCase} that represents a test, return a
        C{TestCase} instance for that test.
        s   %r not a method(   R!   R"   t
   MethodTypeR   R   RL   RQ   (   RU   RO   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt
   loadMethod  s    c         C   s
   | |  S(   N(    (   RU   R   t
   methodName(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR   (  s    c         C   s  t  |  s" t d | f   n  t j | j  } | rI | j   } n | j   } g  } x@ | D]8 } | j j d  d j	 |  j
  rb | j |  qb qb W|  j   } xe |  j |  D]T } y | j   }	 Wn t | j t j    }
 n X|  j |	  }
 | j |
  q W| S(   s  
        Load tests from a module object representing a package, and return a
        TestSuite containing those tests.

        Tests are only loaded from modules whose name begins with 'test_'
        (or whatever C{modulePrefix} is set to).

        @param package: a types.ModuleType object (or reasonable facsimilie
        obtained by importing) which may contain tests.

        @param recurse: A boolean.  If True, inspect modules within packages
        within the given package (and so on), otherwise, only inspect modules
        in the package itself.

        @raise: TypeError if 'package' is not a package.

        @return: a TestSuite created with my suiteFactory, containing all the
        tests.
        s   %r is not a packageRp   i(   R   R   R   t	   getModuleR>   t   walkModulest   iterModulesR   RE   t
   startswitht   modulePrefixR   R   R   t   loadR   R   t   FailureR   Rj   (   RU   t   packaget   recurset   pkgobjt	   discoveryt
   discoveredt   discoRl   t   modinfoR*   t
   thingToAdd(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   loadPackage+  s&    "c         C   s   t  | t  r? y t j |  } Wq? t | t j    SXn  t j |  s_ t	 j
 d  d Si  } t j d k r d   } | | d <n  t j | |  S(   s   
        Return a suite of tests for all the doctests defined in C{module}.

        @param module: A module object or a module name.
        s&   trial only supports doctesting modulesNi   i   c         S   s.   t  |  d |  j  |  _ |  j j   |  _ d S(   s   
                Save C{test.globs} and replace it with a copy so that if
                necessary, the original will be available for the next test
                run.
                t   _savedGlobalsN(   R;   t   globsR   t   copy(   RW   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   saveGlobalsf  s    t   setUp(   i   i   (   R!   t   strR   R7   R   R   R   R   t   ismoduleRf   Rg   R=   t   version_infoRi   R   (   RU   R*   t	   extraArgsR   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR   U  s    	c         C   s   t  | t j  r; t |  r. |  j | |  S|  j |  St  | t j  rZ |  j |  St  | t  rv |  j |  St  | t j	  r |  j
 |  St d | f   d S(   sS  
        Given a Python object, return whatever tests that are in it. Whatever
        'in' might mean.

        @param thing: A Python object. A module, method, class or package.
        @param recurse: Whether or not to look in subpackages of packages.
        Defaults to False.

        @return: A C{TestCase} or C{TestSuite}.
        s#   No loader for %r. Unrecognized typeN(   R!   R"   R#   R   R   R   R   R   R   R   R   R   (   RU   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   loadAnythingq  s    c         C   s=   y |  j  |  } Wn t | t j    SX|  j | |  S(   s`  
        Given a string representing a Python object, return whatever tests
        are in that object.

        If C{name} is somehow inaccessible (e.g. the module can't be imported,
        there is no Python object with that name etc) then return an
        L{ErrorHolder}.

        @param name: The fully-qualified name of a Python object.
        (   R   R   R   R   R   (   RU   R   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt
   loadByName  s
    c         C   s   g  } g  } xN | D]F } y | j  |  j |   Wq | j  t | t j     q Xq Wg  |  j |  D] } |  j | |  ^ qm } | j |  |  j |  S(   s  
        Construct a TestSuite containing all the tests found in 'names', where
        names is a list of fully qualified python names and/or filenames. The
        suite returned will have no duplicate tests, even if the same object
        is named twice.
        (	   R   R   R   R   R   t   _uniqueTestsR   t   extendR   (   RU   R   R   t   thingst   errorsR   R   t   suites(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   loadByNames  s    $+c         C   ss   g  } xI | D]A } t  | t j  r> | j | | j f  q | j | f  q Wg  t |  D] } | d ^ q_ S(   s  
        Gather unique suite objects from loaded things. This will guarantee
        uniqueness of inherited methods on TestCases which would otherwise hash
        to same value and collapse to one test unexpectedly if using simpler
        means: e.g. set().
        i    (   R!   R"   R   R   RL   R   (   RU   R   t   entriesR   t   entry(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR     s    (   R>   RY   RZ   R   R   R    R   R   R   R   t   loadTestsFromModuleR   t   loadTestsFromTestCaseR   R   R   R$   R   R   R   R   t   loadTestsFromNameR   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR
     s*   										*	c           B   s    e  Z d  Z d   Z d   Z RS(   sa   
    A visitor that makes a reporter think that every test visited has run
    successfully.
    c         C   s   | |  _  d S(   s:   
        @param reporter: A C{TestResult} object.
        N(   t   reporter(   RU   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR      s    c         C   s4   |  j  j |  |  j  j |  |  j  j |  d S(   sQ   
        Convince the reporter that this test has been run successfully.
        N(   R   R   R   R   (   RU   t   testCase(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   markSuccessful  s    (   R>   RY   RZ   R    R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR     s   	c        
   B   s   e  Z d  Z d Z d Z d   Z d   Z d   Z e Z	 d   Z
 d d e j e d e e d e d	 	 Z d
   Z d   Z d   Z d   Z d   Z RS(   s=   
    A specialised runner that the trial front end uses.
    t   debugs   dry-runc         C   s   t  j   } y d d  l } Wn  t k
 r> d GHt j   n Xxj d D]b } t j j |  rF y t	 | d  } Wn t
 k
 r t j   q X| j j | j    qF qF W| S(   Nis   readline module not availables   .pdbrct   pdbrcRC   (   s   .pdbrcR   (   t   pdbt   Pdbt   readlinet   ImportErrorR=   t	   exc_clearR%   R&   R.   t   filet   IOErrort   rcLinesR   t	   readlines(   RU   t   dbgR   R&   t   rcFile(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   _getDebugger  s    c         C   sT   |  j    t j   } t j |  j  } t j |  \ } |  _ t j	 | j
  | S(   N(   t   _tearDownLogFileR%   t   getcwdR   t   FilePatht   workingDirectoryR   t   _unusedTestDirectoryt   _testDirLockt   chdirR&   (   RU   t
   currentDirt   baset   testdir(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   _setUpTestdir  s    
c         C   s   t  j |  |  j j   d  S(   N(   R%   R   R   t   unlock(   RU   t   oldDir(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   _tearDownTestdir  s    c         C   s@   |  j  |  j |  j |  j |  j  } |  j r< t |  } n  | S(   N(   t   reporterFactoryt   streamt   tbformatt   rterrorst   _logt   uncleanWarningsR   (   RU   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   _makeResult  s
    	s   test.logt   defaultc         C   s   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d  |  _ |	 pQ d |  _	 d  |  _
 d  |  _ |
 |  _ | r t j |  j d  |  _ n  d  S(   Nt   _trial_temps   profile.data(   R  t   logfilet   modeR  R  R  R  Rr   t   _resultR   t   _logFileObservert   _logFileObjectt   _forceGarbageCollectionR   t   profiledRX   (   RU   R  R  R  R  t   profilet   tracebackFormatt   realTimeErrorsR  R   t   forceGarbageCollection(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR      s    
											c         C   sZ   |  j  d  k	 r. t j |  j  j  d  |  _  n  |  j d  k	 rV |  j j   d  |  _ n  d  S(   N(   R  Rr   R   t   removeObservert   emitR  RH   (   RU   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR     s    c         C   sl   |  j    |  j d k r% t j } n t |  j d  } | |  _ t j |  |  _ t j	 |  j j
 d  d  S(   Nt   -t   ai    (   R   R  R=   t   stdoutR   R  R   t   FileLogObserverR  t   startLoggingWithObserverR  (   RU   t   logFile(    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   _setUpLogFile'  s    
	c         C   s@   t  j | t  } |  j r3 t  j | t  j  } n  |  j |  S(   sC   
        Run the test or suite and return a result object.
        (   R   t   decorateR   R  t    _ForceGarbageCollectionDecoratort   _runWithoutDecoration(   RU   RW   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyRX   2  s
    	c            s  |  j     t | g   t j   } |  j |  j k r} x t j   D]- }  j |   j |   j	 |  qI Wn |  j |  j
 k r |  j         f d   } n   f d   } |  j   } z |  j   |   Wd |  j   |  j |  Xt j   } t  d d  } | d k rt j d t j  j  d t d d  j    j  j   j d	  j | |   j d
   j   n
  j    S(   sR   
        Private helper that runs the given test but doesn't decorate it.
        c              s    j    j   S(   N(   t   runcallRX   (    (   Rl   t   debuggerRV   (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR   P  s    c              s     j    S(   N(   RX   (    (   Rl   RV   (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR   R  s    Nt   donesR   %s should implement done() but doesn't. Falling back to printErrors() and friends.Rd   Re   i   s   Ran %d tests in %.3fss   
(   R  R   t   timeR  t   DRY_RUNR   t   _iterateTestsR   R   R   t   DEBUGR   R   R  R   R  R;   Rr   Rf   Rg   R   R   Rq   Rh   t   printErrorst   writelnt	   separatort   testsRunt   writet   printSummaryR$  (   RU   RW   t	   startTimet   singleRX   R   t   endTimeR$  (    (   R#  RV   Rl   s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR!  =  sB    



c         C   s   d } x{ t  r | d 7} |  j j d | f  | d k rN |  j |  } n |  j |  } | j d k rp Pn  | j   s	 Pq	 q	 W| S(   s8   
        Repeatedly run C{test} until it fails.
        i    i   s   Test Pass %d
(   t   TrueR  R-  RX   R!  R,  t   wasSuccessful(   RU   RW   t   countRV   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   runUntilFailuren  s    	
N(   R>   RY   RZ   R(  R&  R   R   R  R   R  R  Rr   R=   R  R$   R    R   R  RX   R!  R5  (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyR     s,   									1(:   RZ   t   __all__R   R%   R"   Rf   R=   R   R,   Ri   R%  t   twisted.pythonR   R   R   R   R   t   twisted.python.compatR   R   R   t   twisted.trialR   R   t   twisted.trial.itrialR   t   twisted.trial.reporterR   t   twisted.trial.unittestR    R   t   zope.interfaceR   t
   __import__R   R   R   R   R   Rr   R:   RD   RQ   R   R   R   R   RM   R   R   R   R   R   R	   R   R
   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/trial/runner.pyt   <module>	   sP   	H(					
	7		.- 