ó
ęNXc           @  sĻ  d  Z  d d l m 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 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 d d	 l m Z d d
 l m  Z  y d d l m! Z! d   Z" Wn0 e# k
 rmd e$ f d     YZ! d   Z" n Xd Z% d e& f d     YZ' d e' f d     YZ( d   Z) e* d  Z+ d   Z, d   Z- e j. d d  Z/ e/ j0 d d d d d e/ j0 d  d! d" d d# e/ j0 d$ d d% e/ j0 d& d' d d( d) d d* d d+ e2 d d, e/ j0 d- d! d" d d. e/ j0 d/ d d( d) e* d* e3 d d0 e/ j0 d1 d* d2 d d3 d4   Z4 d5   Z5 e6 d6 k rĖe5   n  d S(7   s|   IPython Test Process Controller

This module runs one or more subprocesses which will actually run the IPython
test suite.

i’’’’(   t   print_functionNi   (   t   havet   test_group_namest   test_sectionst   StreamCapturert   test_for(   t   compress_user(   t   bytes_to_str(   t   get_sys_info(   t   TemporaryDirectory(   t
   strip_ansi(   t   TimeoutExpiredc         C  s   |  j  |  S(   N(   t   wait(   t   pt   timeout(    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyt
   popen_wait(   s    R   c           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyR   +   s   c         C  sc   xA t  t d |   D]) } |  j   d k	 r3 d St j d  q W|  j   d k r_ t  n  d S(   s$   backport of Popen.wait from Python 3i
   Ng¹?(   t   ranget   intt   pollt   Nonet   timet   sleepR   (   R   R   t   i(    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyR   -   s    i
   t   TestControllerc           B  s}   e  Z d  Z d Z d Z d Z d Z d Z d Z	 d   Z
 d   Z e e d  Z d   Z d   Z d   Z d   Z e Z RS(	   s   Run tests in a subprocess
    c         C  s   g  |  _  i  |  _ g  |  _ d  S(   N(   t   cmdt   envt   dirs(   t   self(    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyt   __init__H   s    		c         C  s   d S(   s¹   Create temporary directories etc.
        
        This is only called when we know the test group will be run. Things
        created here may be cleaned up by self.cleanup().
        N(    (   R   (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyt   setupM   s    c         C  s¤   t  j j   } | j |  j  | r. t } n  t d |  |  _ } | j   | r^ | j	 n d  } | rs t j n d  } t j |  j d | d | d | |  _ d  S(   Nt   echot   stdoutt   stderrR   (   t   ost   environt   copyt   updateR   t   TrueR   t   stdout_capturert   startt   writefdR   t
   subprocesst   STDOUTt   PopenR   t   process(   R   t   buffer_outputt   capture_outputR   t   cR!   R"   (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyt   launchU   s    	
c         C  s6   |  j  j   |  j j   |  j j   |  _ |  j  j S(   N(   R.   R   R(   t   haltt
   get_bufferR!   t
   returncode(   R   (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyR   c   s    c         C  s   d S(   s^  Print extra information about this test run.
        
        If we're running in parallel and showing the concise view, this is only
        called if the test group fails. Otherwise, it's called before the test
        group is started.
        
        The base implementation does nothing, but it can be overridden by
        subclasses.
        N(    (   R   (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyt   print_extra_infoi   s    
c         C  s±   |  j  } | d k s' | j   d k	 r+ d Sy t d | j  | j   Wn n; Xx7 t d  D]) } | j   d k r t j d  qa Pqa W| j   d k r­ t d  n  d S(   s2   Cleanup on exit by killing any leftover processes.Ns   Cleaning up stale PID: %di
   g¹?s+   ... failed. Manual cleanup may be required.(	   R.   R   R   t   printt   pidt   killR   R   R   (   R   t   subpR   (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyt   cleanup_processu   s    	c         C  s,   |  j    x |  j D] } | j   q Wd S(   sD   Kill process if it's still alive, and clean up temporary directoriesN(   R;   R   t   cleanup(   R   t   td(    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyR<      s    
N(   R   R   t   __doc__R   t   sectionR   R   R   R.   R!   R   R   t   FalseR2   R   R6   R;   R<   t   __del__(    (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyR   8   s   						t   PyTestControllerc           B  s\   e  Z d  Z d Z d   Z d   Z d   Z e d    Z	 d   Z
 d   Z e d  Z RS(	   s-   Run Python tests using IPython.testing.iptestc         C  sD   t  j |   | |  _ t j d d | g |  _ d |  _ | |  _ d S(   s   Create new test runner.s   -cs;   from IPython.testing.iptest import run_iptest; run_iptest()N(	   R   R   R?   t   syst
   executableR   R   t   pycmdt   options(   R   R?   RF   (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyR      s
    		c         C  sN  t    } |  j j |  | j |  j d <t    |  _ } |  j j |  | j |  j d <| j |  j d <| j |  j d <t j j |  j j d  } | |  _	 t j
 | d  t j j d d  } | rÜ | t j | } n | } | |  j d <|  j j r|  j   n  |  j j r!|  j   n  |  j j |  j d	 <|  j j |  j j  d  S(
   Nt
   IPYTHONDIRt   IPTEST_WORKING_DIRt   MPLCONFIGDIRt   TMPDIRt   _no_access_i    t   PATHt    t   IPTEST_SUBPROC_STREAMS(   R	   R   t   appendt   nameR   t
   workingdirR#   t   patht   joint   noaccesst   mkdirR$   t   gett   pathsepRF   t   xunitt	   add_xunitt   coveraget   add_coveraget   subproc_streamsR   t   extendt
   extra_args(   R   t   ipydirRQ   RT   RL   (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyR   ¤   s,    		c         C  s'   t  j |  j t j  t j |   d S(   s   
        Make the non-accessible directory created in setup() accessible
        again, otherwise deleting the workingdir will fail.
        N(   R#   t   chmodRT   t   statt   S_IRWXUR   R<   (   R   (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyR<   Å   s    c         C  s+   y t  |  j j SWn t k
 r& t SXd  S(   N(   R   R?   t   will_runt   KeyErrorR'   (   R   (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyRc   Ķ   s    c         C  s6   t  j j |  j d  } |  j j d d | g  d  S(   Ns
   .xunit.xmls   --with-xunits   --xunit-file(   R#   RR   t   abspathR?   R   R]   (   R   t
   xunit_file(    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyRY   Ō   s    c         C  sĘ   y t  |  j j } Wn t k
 r0 d g } n Xd j d t j j d |  j  d d j |   } t j j |  j	 j
 d  } t | d   } | j |  Wd  QX| |  j d	 <d
 |  j |  _ d  S(   Nt   IPythons2   [run]
data_file = {data_file}
source =
  {source}
t	   data_files
   .coverage.t   sources   
  s   .coveragerct   wt   COVERAGE_PROCESS_STARTs-   import coverage; coverage.process_startup(); (   R   R?   t   includesRd   t   formatR#   RR   Re   RS   RQ   RP   t   opent   writeR   RE   (   R   t   sourcest   coverage_rct   config_filet   f(    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyR[   Ų   s    	c         C  s-   |  j  |  j d <t t |   j d |  d  S(   Ni   R/   (   RE   R   t   superRB   R2   (   R   R/   (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyR2   ė   s    N(   R   R   R>   R   RE   R   R   R<   t   propertyRc   RY   R[   R@   R2   (    (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyRB      s   			!			c         C  s   |  j  } | s t } n  g  | D] } t | |   ^ q } g  | D] } | j rA | ^ qA } g  | D] } | j sc | ^ qc } | | f S(   sV   Returns two lists of TestController instances, those to run, and those
    not to run.(   t
   testgroupst   py_test_group_namesRB   Rc   (   RF   Rv   RP   t   controllersR1   t   to_runt   not_run(    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyt   prepare_controllersš   s    		"""c         C  s±   z y| y1 |  j    | s& |  j   n  |  j d |  Wn. t k
 rg d d l } | j   |  d f SX|  j   } |  | f SWn t k
 r |  t j	 f SXWd |  j
   Xd S(   sĢ  Setup and run a test controller.
    
    If buffer_output is True, no output is displayed, to avoid it appearing
    interleaved. In this case, the caller is responsible for displaying test
    output on failure.
    
    Returns
    -------
    controller : TestController
      The same controller as passed in, as a convenience for using map() type
      APIs.
    exitcode : int
      The exit code of the test subprocess. Non-zero indicates failure.
    R/   i’’’’Ni   (   R   R6   R2   t	   Exceptiont	   tracebackt	   print_excR   t   KeyboardInterruptt   signalt   SIGINTR<   (   t
   controllerR/   R}   t   exitcode(    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyt   do_runż   s      

c    	        sČ  t    }  g      f d   } | d |  d  | d d j |  d |  d   | d t |  d	   | d
 |  d j d d   | d t |  d   | d |  d  t d     D  } g    D]$ \ } } d j | | d | ^ qÉ   g  } g  } x= t j   D]/ \ } } | r.| j |  q| j |  qW| r}  j d  | j     j d d j	 |  d  n  | r»  j d  | j     j d d j	 |  d  n  d j	    S(   s@   Return a string with a summary report of test-related variables.c           s     j  |  | f  d  S(   N(   RO   (   RP   t   value(   t   out(    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyt   _add#  s    s   IPython versiont   ipython_versions   IPython commits   {} ({})t   commit_hasht   commit_sources   IPython packaget   ipython_paths   Python versiont   sys_versions   
RM   s   sys.executablet   sys_executablet   Platformt   platformc         s  s!   |  ] \ } } t  |  Vq d  S(   N(   t   len(   t   .0t   nt   v(    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pys	   <genexpr>-  s    s   {:<{width}}: {}
t   widths-   
Tools and libraries available at test time:
s      t    s1   
Tools and libraries NOT available at test time:
(
   R   Rm   R   t   replacet   maxR   t   itemsRO   t   sortRS   (	   t   infR   R   R   R   t   availt	   not_availt   kt   is_avail(    (   R   sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyt   report  s4    	!1
!
!c           sJ  t  |   \ } } d d d  } g  } t j   } t   |  j d k rĶ xU| D]v } t d | j  t j j   t | d t	 \ } } | ræ | j
 |  | t j k ræ t d  Pqæ n  t   qP WnŌ yæ t j j |  j  } x£ | j t |  D] \ } } | d k rd	 n d
 }	 t | d | j |	   | rų | j   t t | j   | j
 |  | t j k rt d  Pqqų qų WWn t k
 r d SXx( | D]  } t | d | j d   qØWt j   }
 |
 | } t |  } t |  } t d d  t d  t t    d | } t d d d | sSt d | |  nf g  | D] } | j ^ qZ} t d j | | d j |   |  t   t d  t d |  t   |  j r0d d l m } m } | d d  } | j   | j   |  j d k rŃd } t j | d t t d  | d d t j j   d d! l m  } d" | f   f d#     Y  | j!   | j" j# d$ d% j t$ j%  d& | d' d(    | | j"  } | j d  t d)  q0|  j d* k r0y | j' d+ d,  Wq-| k
 r)} t d-  d d l( } | j)   q-Xq0n  | rFt j* d  n  d S(.   sµ  Run the entire IPython test suite by calling nose and trial.

    This function constructs :class:`IPTester` instances for all IPython
    modules and package and then runs each of them.  This causes the modules
    and packages of IPython to be tested each in their own subprocess using
    nose.

    Parameters
    ----------

    All parameters are passed as attributes of the options object.

    testgroups : list of str
      Run only these sections of the test suite. If empty, run all the available
      sections.

    fast : int or None
      Run the test suite in parallel, using n simultaneous processes. If None
      is passed, one process is used per CPU core. Default 1 (i.e. sequential)

    inc_slow : bool
      Include slow tests. By default, these tests aren't run.

    url : unicode
      Address:port to use when running the JS tests.

    xunit : bool
      Produce Xunit XML output. This is written to multiple foo.xunit.xml files.

    coverage : bool or str
      Measure code coverage from tests. True will store the raw coverage data,
      or pass 'html' or 'xml' to get reports.

    extra_args : list
      Extra arguments to pass to the test subprocesses, e.g. '-v'
    iF   t   -c         S  s2   |  d 7}  d | j  | t |   |  } |  | S(   NR   (   t   rjustR   (   t   ltextt   rtextR   t   fill(    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyt   justifyl  s    
 i   s   Test group:R/   t   Interruptedi    t   OKt   FAILEDs   Test group: Ns   NOT RUNt   _s?   Test suite completed for system with the following information:s   Took %.3fs.s   Status: t   endRM   s   OK (%d test groups).s-   ERROR - {} out of {} test groups failed ({}).s   , s"   You may wish to rerun these, with:s     iptesti’’’’(   RZ   t   CoverageExceptionRh   s	   .coveraget   htmlt   ipy_htmlcovt   ignore_errorss(   Writing HTML coverage report to %s/ ... (   t   HtmlReportert   CustomHtmlReporterc             s   e  Z   f d    Z RS(   c           sz   t    |   j |  x] |  j D]R } | j j t j  } d | k rM q  n  | j d  } d j | |  | _ q  Wd  S(   NRg   t   .(	   Rt   t   find_code_unitst
   code_unitsRP   t   splitR#   t   sept   indexRS   (   R   t   morfst   cut	   namepartst   ix(   R°   (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyR²   ¾  s    (   R   R   R²   (    (   R°   (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyR°   ½  s   t   omits   *{0}tests{0}*t   html_dirt
   html_titles   IPython test coverages   done.t   xmlt   outfiles   ipy_coverage.xmlsI   Generating coverage report failed. Are you running javascript tests only?(+   R{   R   R7   t   fastR?   RC   R!   t   flushR   R@   RO   R   R   t   multiprocessingt   poolt
   ThreadPoolt   imap_unorderedR6   R   R   R   R   Rm   RS   RZ   R«   t   combinet   savet   shutilt   rmtreeR'   t   coverage.htmlRÆ   t   _harvest_datat   configt	   from_argsR#   Rµ   R   t
   xml_reportR}   R~   t   exit(   RF   Ry   Rz   R„   t   failedt   t_startR   t   resRĆ   t
   res_stringt   t_endt   t_testst   nrunnerst   nfailt   tookR1   t   failed_sectionsRZ   R«   t   covR¼   RÆ   t   reportert   eR}   (    (   R°   sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyt   run_iptestallE  s    %






	


$
t   descriptions   Run IPython test suiteRv   t   nargst   *t   helps9   Run specified groups of tests. If omitted, run all tests.s   --allt   actiont
   store_trues&   Include slow tests not run by default.s   --urls   URL to use for the JS tests.s   -js   --fastt   ?t   constt   defaultt   typesl   Run test sections in parallel. This starts as many processes as you have cores, or you can specify a number.s   --xunits   Produce Xunit XML resultss
   --coverages>   Measure test coverage. Specify 'html' or 'xml' to get reports.s   --subproc-streamst   capturesk   What to do with stdout/stderr from subprocesses. 'capture' (default), 'show' and 'discard' are the options.c          C  s   t  j g   }  g  |  _ |  S(   sg   Get an argparse Namespace object with the default arguments, to pass to
    :func:`run_iptestall`.
    (   t	   argparsert
   parse_argsR^   (   RF   (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyt   default_optionsš  s    	c          C  sŌ   t  j j t  j j t  j   d d d   rP t d d t j t j d  n  y t j	 j
 d  }  Wn$ t k
 r t j	 d } g  } n" Xt j	 d |  !} t j	 |  d } t j |  } | | _ t |  d  S(   NRg   t   testings   __main__.pys2   Don't run iptest from the IPython source directoryt   filei   s   --(   R#   RR   t   existsRS   t   getcwdR7   RC   R"   RĻ   t   argvR¶   t
   ValueErrorRé   Rź   R^   RŻ   (   Rŗ   t   to_parseR^   RF   (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyt   mainų  s    	

	t   __main__(7   R>   t
   __future__R    t   argparset   jsont   multiprocessing.poolRĀ   R#   Ra   t   ret   requestsRČ   R   RC   R+   R   t   iptestR   R   Rw   R   R   R   t   IPython.utils.pathR   t   IPython.utils.py3compatR   t   IPython.utils.sysinfoR   t   IPython.utils.tempdirR	   t   IPython.utils.textR
   R   R   t   ImportErrorR|   t   NOTEBOOK_SHUTDOWN_TIMEOUTt   objectR   RB   R{   R'   R   R   RŻ   t   ArgumentParserRé   t   add_argumentR   R   R@   Rė   Ró   R   (    (    (    sX   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/testing/iptestcontroller.pyt   <module>   sd   (	^Z	"	&	'		