ó
[³XMc           @   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(   iÿÿÿÿN(   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   -*-iÿÿÿÿs)   %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   s6   d d j  g  t j t j ƒ D] }  |  j ^ q ƒ f S(   Ns   (%s)t    (   t   joinR   t
   getPluginsR   t	   IReportert   longOpt(   t   p(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   _zshReporterAction\   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 dA d g d d d g d dA d g d dA d g d dA d g d d d g d d d g d dA d  g g Z
 d! d" d# d$ g d% d& dA d' g d( dA d) d* g d+ dA d, d- g g Z i d. d/ 6e d+ 6Z i d$ d! 6d0 d% 6Z d1 g Z e j Z dA Z dA Z d2 „  Z d3 „  Z d4 „  Z d5 „  Z d6 „  Z d7 „  Z d8 „  Z d9 „  Z d: „  Z e Z d; „  Z d< „  Z  d= „  Z! d> „  Z" d? „  Z# d@ „  Z$ RS(B   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.s   (plain emacs cgitb)t   tbformats   random seeds:   *:file|module|package|TestCase|testMethod:_files -g '*.py'c         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.pyRS      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   (   RT   t   coverdirt   result(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyRW   ”   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.
        iÿÿÿÿNt   counti   t   tracei    (   RZ   t   Tracet   tracert   syst   settracet   globaltrace(   RT   RZ   (    (    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
NRR   (   R2   R3   t   isfileR]   t   stderrt   writet   abspathR7   t   addt   updateR0   (   RT   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]   R^   R	   (   RT   (    (    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   R:   R   R;   R<   t   descriptionR]   t   exit(   RT   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(   RT   (    (    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(   RT   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(   RT   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   Rr   (   RT   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(   NRN   s/   Argument to --random must be a positive integeri    id   (   t   longR   R   Rr   t   time(   RT   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.Rv   N(   R   R]   t   modulesRx   Ry   t   RuntimeWarningR.   (   RT   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(   NRR   (   Rf   R~   R.   (   RT   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   R:   R   R;   R‹   t   klassR<   R   t   namedAnyR   Rr   (   RT   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   RG   RD   s+   you must specify --debug when using --nopm (   R“   R   Rr   t   FalseR   t   DO_POST_MORTEM(   RT   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   postOptions,  s    

N(%   t   __name__t
   __module__R2   R3   R4   R]   t   argvRk   t   longdescR.   t   optFlagst   optParametersR>   t   zsh_actionst   zsh_actionDescrt
   zsh_extrasR   t   TreeReportert   fallbackReporterR~   R\   RS   RW   R`   Rg   Rh   Rl   Ro   Rt   R{   t   opt_xR„   Rˆ   RŒ   RŽ   R“   R–   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyR?   _   s^    				



					
											
c         C   s?   |  d r t  j ƒ  n  |  d s+ |  d r; t j t ƒ n  d  S(   NRD   s   debug-stacktraces(   R   t   startDebugModeR    t   setDebuggingt   True(   t   config(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   _initialDebugSetup<  s    
c         C   s+   t  |  ƒ } |  d } | j |  d | ƒ S(   Ns
   no-recurseRR   (   t
   _getLoadert   loadByNames(   R¦   t   loadert   recurse(    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt	   _getSuiteE  s    c            sr   t  j ƒ  } |  d rU t j ƒ  ‰  ˆ  j |  d ƒ ‡  f d †  | _ d |  d GHn  |  d sn t  j | _ n  | S(   NRN   c            s
   ˆ  j  ƒ  S(   N(   RN   (   t   x(   t   randomer(    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyt   <lambda>Q  s    s$   Running tests shuffled with seed %d
s   until-failure(   R   t
   TestLoaderRN   t   Randomt   seedt   sortert   DestructiveTestSuitet   suiteFactory(   R¦   Rª   (    (   R®   s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyR¨   L  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(   NRD   s   dry-runR   t   modeRI   RL   t   tracebackFormatRQ   t   realTimeErrorsRB   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   _makeRunnerY  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   summaryRW   (   R   R]   R™   R   R?   t   parseOptionsR   t   errort
   SystemExitR§   R¿   R¬   t   runUntilFailuret   runR\   R^   R.   t   resultst   write_resultsR”   RW   R3   Rj   t   wasSuccessful(   R¦   t   uet   trialRunnert   suitet   test_resultRÇ   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/scripts/trial.pyRÆ   k  s&    	

	()   R]   R2   RN   Rm   R†   Rx   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   Rp   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(
				
	Ý					