
oUNc           @   s  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 m Z m Z m Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z d  d	 l m Z m Z m Z i d
 d 6d
 d
 6d d 6d d 6d d 6d d 6Z d   Z d   Z d   Z d   Z  d   Z! d e j" e	 j# f d     YZ" d   Z$ d   Z% d   Z& d   Z' d   Z( d S(   iN(   t   defer(   t   app(   t   usaget   reflectt   failuret   versionst	   deprecate(   t   FilePath(   t   plugin(   t   spewer(   t   set(   t   runnert   itrialt   reportert   defaultt   plaint   brieft   emacst   verboset   cgitbc         C   s  d } |  j  |  t |  } |  j |  } | d k sF | d k r\ t d |  f   n  |  | | !j d  } i  } x | D]| } t | j    d k r q n  | j d  } t |  d k r t d |  | f   n  | d	 j   | | d j   <q W| S(
   s  
    Accepts a single line in Emacs local variable declaration format and
    returns a dict of all the variables {name: value}.
    Raises ValueError if 'line' is in the wrong format.

    See http://www.gnu.org/software/emacs/manual/html_node/File-Variables.html
    s   -*-is)   %r not a valid local variable declarationt   ;i    t   :i   s"   %r contains invalid declaration %ri   (   t   findt   lent   rfindt
   ValueErrort   splitt   strip(   t   linet   parent   startt   endt   itemst	   localVarst   itemR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   _parseLocalVariables   s     "c         C   sh   t  |  d  } | j   | j   g } | j   x0 | D]( } y t |  SWq8 t k
 r_ q8 Xq8 Wi  S(   s   
    Accepts a filename and attempts to load the Emacs variable declarations
    from that file, simulating what Emacs does.

    See http://www.gnu.org/software/emacs/manual/html_node/File-Variables.html
    t   r(   t   filet   readlinet   closeR#   R   (   t   filenamet   ft   linesR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   loadLocalVariables9   s    
c         C   s5   t  |   j d d   } | d  k r( g  S| j d  S(   Ns   test-case-namet   ,(   R+   t   gett   NoneR   (   R(   t   testCaseVar(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   getTestModulesK   s    c         C   s;   t  j j |   } | j d  o: t  j j |  d d k S(   s   
    Returns true if 'filename' looks like a file containing unit tests.
    False otherwise.  Doesn't care whether filename exists.
    t   test_i   s   .py(   t   ost   patht   basenamet
   startswitht   splitext(   R(   R4   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt
   isTestFileR   s    c          C   s/   t  j g  t j t j  D] }  |  j ^ q  S(   N(   R   t   CompleteListR   t
   getPluginsR   t	   IReportert   longOpt(   t   p(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   _reporterAction\   s    	t   Optionsc           B   s  e  Z d  e j j e j d  f Z d Z d d g d d d g d d	 d
 g d d d g d dH d g d d d g d dH d g d dH d g d dH d g d d d g d d d g d dH d  g g Z
 d! d" d# d$ g d% d& dH d' g d( dH d) d* g d+ dH d, d- g g Z e j d. i e j d/ d0 d1 g  d2 6e d+ 6e j d3 d$  d! 6e j d3 d4  d% 6d5 e j d6 d3 d7 d8 e g  Z e j Z dH Z dH Z d9   Z d:   Z d;   Z d<   Z d=   Z d>   Z d?   Z d@   Z  dA   Z! e! Z" dB   Z# dC   Z$ dD   Z% dE   Z& dF   Z' dG   Z( RS(I   s@   %s [options] [[file|package|module|TestCase|testmethod]...]
    i    su   trial loads and executes a suite of unit tests, obtained from modules, packages and files listed on the command line.t   helpt   ht   rterrorst   es;   realtime errors, print out tracebacks as soon as they occurt   debugt   bsY   Run tests in the Python debugger. Will load '.pdbrc' from current directory if it exists.s   debug-stacktracest   Bs2   Report Deferred creation and callback stack tracest   nopmsF   don't automatically jump into debugger for postmorteming of exceptionss   dry-runt   ns   do everything but run the testss   force-gcs<   Have Trial run gc.collect() before and after each test case.t   profiles#   Run tests under the Python profilers   unclean-warningss'   Turn dirty reactor errors into warningss   until-failuret   us   Repeat test until it failss
   no-recurset   Ns   Don't recurse into packagess   help-reporterss,   Help on available output plugins (reporters)t   logfilet   ls   test.logs   log file namet   randomt   zs2   Run tests in random order using the specified seeds   temp-directoryt   _trial_temps+   Path to use as working directory for tests.R   R   sK   The reporter to use for this test run.  See --help-reporters for more info.t
   optActionsR   R   R   t   tbformatt   descrs   random seedt   extraActionss   *.pys/   file | module | package | TestCase | testMethodt   repeatc         C   s!   t    |  d <t j j |   d  S(   Nt   tests(   R
   R   R>   t   __init__(   t   self(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyRV      s    c         C   s2   d } t  |  d  j |  } d | j f GH| S(   sx   
        Return a L{FilePath} representing the directory into which coverage
        results should be written.
        t   coverages   temp-directorys!   Setting coverage directory to %s.(   R   t   childR3   (   RW   t   coverdirt   result(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyRZ      s    c         C   s>   d d l  } | j d d d d  |  _ t j |  j j  d S(   s   
        Generate coverage information in the I{coverage} file in the
        directory specified by the I{trial-temp} option.
        iNt   counti   t   tracei    (   R]   t   Tracet   tracert   syst   settracet   globaltrace(   RW   R]   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   opt_coverage   s    c         C   sz   t  j j |  s- t j j d | f  d St  j j |  } t |  r_ |  d j |  n |  d j	 t
 |   d S(   sF   
        Filename to grep for test cases (-*- test-case-name)
        s   File %r doesn't exist
NRU   (   R2   R3   t   isfileR`   t   stderrt   writet   abspathR7   t   addt   updateR0   (   RW   R(   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   opt_testmodule   s    c         C   s   t  j t  d S(   s   
        Print an insanely verbose log of everything that happens.  Useful
        when debugging freezes or locks in complex code.
        N(   R`   Ra   R	   (   RW   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   opt_spew   s    c         C   sQ   d } | GHx1 t  j t j  D] } d G| j Gd G| j GHq WHt j d  d  S(   Ns   Trial's output can be customized using plugins called Reporters. You can
select any of the following reporters using --reporter=<foo>
s      s   	i    (   R   R9   R   R:   R;   t   descriptionR`   t   exit(   RW   t   synopsisR<   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   opt_help_reporters   s    c         C   s   t  j   d S(   s/   
        Disable the garbage collector
        N(   t   gct   disable(   RW   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   opt_disablegc   s    c         C   s9   y t  | |  d <Wn  t k
 r4 t j d   n Xd S(   s   
        Specify the format to display tracebacks with. Valid formats are
        'plain', 'emacs', and 'cgitb' which uses the nicely verbose stdlib
        cgitb.text function
        RQ   s.   tbformat must be 'plain', 'emacs', or 'cgitb'.N(   t   TBFORMAT_MAPt   KeyErrorR   t
   UsageError(   RW   t   opt(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   opt_tbformat   s
    c         C   si   t  j t j t j t j d d d d   d t d d |  j	 d k rU g  |  _	 n  |  j	 j |  d S(   s   
        Add an extra argument.  (This is a hack necessary for interfacing with
        emacs's `gud'.)  NOTE: This option is deprecated as of Twisted 11.0
        t   Twistedi   i    t   categoryt
   stackleveli   N(   t   warningst   warnR   t   getDeprecationWarningStringR>   t	   opt_extraR   t   Versiont   DeprecationWarningt   extraR.   t   append(   RW   t   arg(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyR~      s    c         C   sD   y t  j t |   Wn& t t f k
 r? t j d   n Xd S(   s-   
        see sys.setrecursionlimit()
        s-   argument to recursionlimit must be an integerN(   R`   t   setrecursionlimitt   intt	   TypeErrorR   R   Ru   (   RW   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   opt_recursionlimit   s
    c         C   s   y t  |  |  d <Wn  t k
 r6 t j d   nP X|  d d k  rY t j d   n- |  d d k r t  t j   d  |  d <n  d  S(   NRM   s/   Argument to --random must be a positive integeri    id   (   t   longR   R   Ru   t   time(   RW   t   option(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt
   opt_random  s    c         C   sW   xP | j  d  D]? } | t j k rB t j d | f d t n  d t j | <q Wd S(   sP   
        Fake the lack of the specified modules, separated with commas.
        R,   s/   Module '%s' already imported, disabling anyway.Ry   N(   R   R`   t   modulesR{   R|   t   RuntimeWarningR.   (   RW   R   t   module(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   opt_without_module  s    	

c         G   s;   |  d j  |  |  j d  k	 r7 |  d j  |  j  n  d  S(   NRU   (   Ri   R   R.   (   RW   t   args(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt	   parseArgs!  s    c         C   sb   xL t  j t j  D]8 } d | j | j f } | j | k r t j |  Sq Wt	 j
 d   d  S(   Ns   %s.%ssV   Only pass names of Reporter plugins to --reporter. See --help-reporters for more info.(   R   R9   R   R:   R   t   klassR;   R   t   namedAnyR   Ru   (   RW   t   nameR<   t   qual(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   _loadReporterByName'  s
    c         C   sf   |  j  |  d  |  d <d |  k r0 d |  d <n  |  d rb |  d sV t j d   n  t t _ n  d  S(   NR   RQ   R   RF   RC   s+   you must specify --debug when using --nopm (   R   R   Ru   t   FalseR   t   DO_POST_MORTEM(   RW   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   postOptions1  s    

N()   t   __name__t
   __module__R2   R3   R4   R`   t   argvRn   t   longdescR.   t   optFlagst   optParametersR   t   CompletionsR8   R=   t   CompleteFilest	   Completert   Truet   compDataR   t   TreeReportert   fallbackReporterR   R_   RV   RZ   Rc   Rj   Rk   Ro   Rr   Rw   R~   t   opt_xR   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyR>   `   sd    									
											
c         C   s?   |  d r t  j   n  |  d s+ |  d r; t j t  n  d  S(   NRC   s   debug-stacktraces(   R   t   startDebugModeR    t   setDebuggingR   (   t   config(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   _initialDebugSetupA  s    
c         C   s+   t  |   } |  d } | j |  d |  S(   Ns
   no-recurseRU   (   t
   _getLoadert   loadByNames(   R   t   loadert   recurse(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt	   _getSuiteJ  s    c            sr   t  j   } |  d rU t j       j |  d    f d   | _ d |  d GHn  |  d sn t  j | _ n  | S(   NRM   c            s
     j    S(   N(   RM   (   t   x(   t   randomer(    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   <lambda>V  s    s$   Running tests shuffled with seed %d
s   until-failure(   R   t
   TestLoaderRM   t   Randomt   seedt   sortert   DestructiveTestSuitet   suiteFactory(   R   R   (    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyR   Q  s    

c         C   s   d  } |  d r t j j } n  |  d r8 t j j } n  t j |  d d | d |  d d |  d d |  d d	 |  d
 d |  d d |  d d |  d S(   NRC   s   dry-runR   t   modeRH   RK   t   tracebackFormatRQ   t   realTimeErrorsRA   t   uncleanWarningss   unclean-warningst   workingDirectorys   temp-directoryt   forceGarbageCollections   force-gc(   R.   R   t   TrialRunnert   DEBUGt   DRY_RUN(   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   _makeRunner^  s    







c          C   s$  t  t j  d k r( t j j d  n  t   }  y |  j   Wn0 t j k
 rq } t d t j d | f  n Xt	 |   t
 |   } t |   } |  d r | j |  } n | j |  } |  j rt j d   |  j j   } | j d d d t d |  j   j  n  t j | j    d  S(	   Ni   s   --helps   %s: %si    s   until-failuret   show_missingt   summaryRZ   (   R   R`   R   R   R>   t   parseOptionsR   t   errort
   SystemExitR   R   R   t   runUntilFailuret   runR_   Ra   R.   t   resultst   write_resultsR   RZ   R3   Rm   t   wasSuccessful(   R   t   uet   trialRunnert   suitet   test_resultR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyR   p  s&    	

	()   R`   R2   RM   Rp   R   R{   t   twisted.internetR    t   twisted.applicationR   t   twisted.pythonR   R   R   R   R   t   twisted.python.filepathR   t   twistedR   t   twisted.python.utilR	   t   twisted.python.compatR
   t   twisted.trialR   R   R   Rs   R#   R+   R0   R7   R=   R>   t   ReactorSelectionMixinR   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   <module>   s4   H(
				
						