ó
šßÈ[c           @   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 m Z d d l m	 Z	 d „  Z
 d e f d „  ƒ  YZ e	 j e ƒ d	 e e f d
 „  ƒ  Yƒ Z d S(   sn   
Implements the wrapper for the Astropy test runner in the form of the
``./setup.py test`` distutils command.
iÿÿÿÿN(   t   Commandi   (   t   sixc            s6   d „  ‰  g  |  D]" } t  ‡  f d †  | Dƒ ƒ ^ q S(   s¢   
    This is for Python 2.x and 3.x compatibility.  distutils expects Command
    options to all be byte strings on Python 2 and Unicode strings on Python 3.
    c         S   s   |  d  k r d  St |  ƒ S(   N(   t   Nonet   str(   t   x(    (    s4   lib/python2.7/site-packages/astropy/tests/command.pyt   to_str_or_none   s    c         3   s   |  ] } ˆ  | ƒ Vq d  S(   N(    (   t   .0R   (   R   (    s4   lib/python2.7/site-packages/astropy/tests/command.pys	   <genexpr>   s    (   t   tuple(   t   optionst   y(    (   R   s4   lib/python2.7/site-packages/astropy/tests/command.pyt   _fix_user_options   s    	t   FixRemoteDataOptionc           B   s   e  Z d  Z d „  Z RS(   s  
    This metaclass is used to catch cases where the user is running the tests
    with --remote-data. We've now changed the --remote-data option so that it
    takes arguments, but we still want --remote-data to work as before and to
    enable all remote tests. With this metaclass, we can modify sys.argv
    before distutils/setuptools try to parse the command-line options.
    c         C   sŠ   y t  j j d ƒ } Wn t k
 r) n Xd t  j | <y t  j j d ƒ } Wn t k
 r` n Xd t  j | <t t |  ƒ j | | | ƒ S(   Ns   --remote-datas   --remote-data=anys   -Rs   -R=any(   t   syst   argvt   indext
   ValueErrort   superR   t   __init__(   t   clst   namet   basest   dctt   idx(    (    s4   lib/python2.7/site-packages/astropy/tests/command.pyR   (   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s4   lib/python2.7/site-packages/astropy/tests/command.pyR       s   t   AstropyTestc           B   sŒ   e  Z d  Z d4 d5 d6 d7 d8 d9 d: d; d< d= d> d? dA dB dC dD g Z e e ƒ Z d- Z d. „  Z d/ „  Z d0 „  Z	 d1 „  Z
 d2 „  Z d3 „  Z RS(E   s   Run the tests for this packages   package=t   Psw   The name of a specific package to test, e.g. 'io.fits' or 'utils'.  If nothing is specified, all default tests are run.s
   test-path=t   tsH  Specify a test location by path.  If a relative path to a  .py file, it is relative to the built package, so e.g., a  leading "astropy/" is necessary.  If a relative  path to a .rst file, it is relative to the directory *below* the --docs-path directory, so a leading "docs/" is usually necessary.  May also be an absolute path.s   verbose-resultst   Vs#   Turn on verbose output from pytest.s   plugins=t   ps&   Plugins to enable when running pytest.s	   pastebin=t   bs8   Enable pytest pastebin output. Either 'all' or 'failed'.s   args=t   as,   Additional arguments to be passed to pytest.s   remote-data=t   RsZ   Run tests that download remote data. Should be one of none/astropy/any (defaults to none).t   pep8t   8sP   Enable PEP8 checking and disable regular tests. Requires the pytest-pep8 plugin.t   pdbt   ds0   Start the interactive Python debugger on errors.t   coveraget   cs8   Create a coverage report. Requires the coverage package.s
   open-filest   osA   Fail if any tests leave files open.  Requires the psutil package.s	   parallel=t   js”   Run the tests in parallel on the specified number of CPUs.  If "auto", all the cores on the machine will be used.  Requires the pytest-xdist plugin.s
   docs-path=sŒ   The path to the documentation .rst files.  If not provided, and the current directory contains a directory called "docs", that will be used.s	   skip-docss(   Don't test the documentation .rst files.s   repeat=sP   How many times to repeat each test (can be used to check for sporadic failures).s
   temp-root=s°   The root directory in which to create the temporary testing files. If unspecified the system default is used (e.g. /tmp) as explained in the documentation for tempfile.mkstemp.t    c         C   s”   d  |  _ d  |  _ t |  _ d  |  _ d  |  _ d  |  _ d |  _ t |  _	 t |  _
 t |  _ t |  _ d |  _ d  |  _ t |  _ d  |  _ d  |  _ d  S(   Nt   nonei    (   R   t   packaget	   test_patht   Falset   verbose_resultst   pluginst   pastebint   argst   remote_dataR"   R$   R&   t
   open_filest   parallelt	   docs_patht	   skip_docst   repeatt	   temp_root(   t   self(    (    s4   lib/python2.7/site-packages/astropy/tests/command.pyt   initialize_optionss   s     															c         C   s   d  S(   N(    (   R:   (    (    s4   lib/python2.7/site-packages/astropy/tests/command.pyt   finalize_options…   s    c         C   sx   d } d } |  j  r> |  j ƒ  \ } } | | 7} | | 7} n  t j rP d } n d } d } | j | |  d | d | ƒS(   s9   
        Build a Python script to run the tests.
        R*   s5   import __builtin__; __builtin__._ASTROPY_TEST_ = Trues/   import builtins; builtins._ASTROPY_TEST_ = Truesº  {cmd_pre}{0}; import {1.package_name}, sys; result = ({1.package_name}.test(package={1.package!r}, test_path={1.test_path!r}, args={1.args!r}, plugins={1.plugins!r}, verbose={1.verbose_results!r}, pastebin={1.pastebin!r}, remote_data={1.remote_data!r}, pep8={1.pep8!r}, pdb={1.pdb!r}, open_files={1.open_files!r}, parallel={1.parallel!r}, docs_path={1.docs_path!r}, skip_docs={1.skip_docs!r}, repeat={1.repeat!r})); {cmd_post}sys.exit(result)t   cmd_pret   cmd_post(   R&   t   _generate_coverage_commandsR   t   PY2t   format(   R:   R=   R>   t   pret   postt   set_flagt   cmd(    (    s4   lib/python2.7/site-packages/astropy/tests/command.pyt   generate_testing_commandŠ   s    	
		c         C   s™  |  j  j r% |  j  j |  j  j ƒ n  |  j  j rJ |  j  j |  j  j ƒ n  |  j d
 k râ |  j  j d ƒ j d d
 ƒ } | d
 k	 rµ t j	 j
 | d ƒ rµ t j	 j | d ƒ |  _ qâ t j	 j
 d ƒ râ t j	 j d ƒ |  _ qâ n  |  j ƒ  z‰ yI |  j ƒ  } t j t j d d | g d |  j d t ƒ} | j ƒ  } Wn9 t k
 rsd	 d
 l } | j | j ƒ | j ƒ  } n XWd
 t j |  j ƒ Xt | ƒ ‚ d
 S(   s    
        Run the tests!
        t
   build_docst
   source_diri   t   docss   -Bs   -ct   cwdt	   close_fdsiÿÿÿÿN(   t   distributiont   install_requirest   fetch_build_eggst   tests_requireR6   R   t   get_option_dictt   gett   ost   patht   existst   abspatht   _build_temp_installRF   t
   subprocesst   PopenR   t
   executablet   testing_pathR.   t   waitt   KeyboardInterruptt   signalt   send_signalt   SIGINTt   shutilt   rmtreet   tmp_dirt
   SystemExit(   R:   t   cfg_docs_dirRE   t   testproct   retcodeR]   (    (    s4   lib/python2.7/site-packages/astropy/tests/command.pyt   run°   s2    	"
 c         C   sö   t  j d |  j d d |  j ƒ } t j j | ƒ |  _ |  j d ƒ |  j	 j
 d ƒ } |  j | _ |  j d ƒ |  j d ƒ } | j |  _ |  j d k	 rß t j j |  j t j j |  j ƒ ƒ } t j |  j | ƒ | |  _ n  t j d |  j ƒ d S(   s  
        Install the package and to a temporary directory for the purposes of
        testing. This allows us to test the install command, include the
        entry points, and also avoids creating pyc and __pycache__ directories
        inside the build directory
        t   prefixs   -test-t   dirt   installs	   setup.cfgN(   t   tempfilet   mkdtempt   package_nameR9   RR   RS   t   realpathRb   t   reinitialize_commandRL   t   get_command_objRh   t   run_commandt   get_finalized_commandt   install_libRZ   R6   R   t   joint   basenameR`   t   copytreet   copy(   R:   Rb   t   install_cmdt   new_docs_path(    (    s4   lib/python2.7/site-packages/astropy/tests/command.pyRV   ñ   s    c   
      C   s‹  |  j  d k r t d ƒ ‚ n  y d d l } Wn t k
 rM t d ƒ ‚ n Xt j j |  j |  j j	 d d ƒ d d	 ƒ } t
 | d
 ƒ  } | j ƒ  } Wd QXt j s± d } n d } | j	 d | ƒ j	 d |  j j	 d d ƒ ƒ } t j j |  j d	 ƒ } t
 | d ƒ  } | j | j d ƒ ƒ Wd QXd j t j j d ƒ t j j | ƒ ƒ } d j t j j d ƒ t j j |  j ƒ ƒ }	 | |	 f S(   sf   
        This method creates the post and pre commands if coverage is to be
        generated
        i    s*   --coverage can not be used with --paralleliÿÿÿÿNs;   --coverage requires that the coverage package is installed.t   .t   /t   testst
   coveragerct   rt   2t   3s   {ignore_python_version}s   {packagename}t   wbs   utf-8s\   import coverage; cov = coverage.coverage(data_file=r"{0}", config_file=r"{1}"); cov.start();s	   .coveragesi   cov.stop(); from astropy.tests.helper import _save_coverage; _save_coverage(cov, result, r"{0}", r"{1}");(   R5   R   R&   t   ImportErrorRR   RS   Rt   RZ   Rm   t   replacet   opent   readR   R@   Rb   t   writet   encodeRA   RU   (
   R:   R&   R}   t   fdt   coveragerc_contentt   ignore_python_versiont   tmp_coveragerct   tmpR=   R>   (    (    s4   lib/python2.7/site-packages/astropy/tests/command.pyR?     s6    			$'(   s   package=R   sw   The name of a specific package to test, e.g. 'io.fits' or 'utils'.  If nothing is specified, all default tests are run.(   s
   test-path=R   sH  Specify a test location by path.  If a relative path to a  .py file, it is relative to the built package, so e.g., a  leading "astropy/" is necessary.  If a relative  path to a .rst file, it is relative to the directory *below* the --docs-path directory, so a leading "docs/" is usually necessary.  May also be an absolute path.(   s   verbose-resultsR   s#   Turn on verbose output from pytest.(   s   plugins=R   s&   Plugins to enable when running pytest.(   s	   pastebin=R   s8   Enable pytest pastebin output. Either 'all' or 'failed'.(   s   args=R    s,   Additional arguments to be passed to pytest.(   s   remote-data=R!   sZ   Run tests that download remote data. Should be one of none/astropy/any (defaults to none).(   R"   R#   sP   Enable PEP8 checking and disable regular tests. Requires the pytest-pep8 plugin.(   R$   R%   s0   Start the interactive Python debugger on errors.(   R&   R'   s8   Create a coverage report. Requires the coverage package.(   s
   open-filesR(   sA   Fail if any tests leave files open.  Requires the psutil package.(   s	   parallel=R)   s”   Run the tests in parallel on the specified number of CPUs.  If "auto", all the cores on the machine will be used.  Requires the pytest-xdist plugin.N(   s
   docs-path=NsŒ   The path to the documentation .rst files.  If not provided, and the current directory contains a directory called "docs", that will be used.(   s	   skip-docsNs(   Don't test the documentation .rst files.(   s   repeat=NsP   How many times to repeat each test (can be used to check for sporadic failures).(   s
   temp-root=Ns°   The root directory in which to create the temporary testing files. If unspecified the system default is used (e.g. /tmp) as explained in the documentation for tempfile.mkstemp.(   R   R   t   descriptionR   t   user_optionsR
   Rm   R;   R<   RF   Rg   RV   R?   (    (    (    s4   lib/python2.7/site-packages/astropy/tests/command.pyR   ;   sN                 				&	A	)(   R   RR   R`   RW   R   Rk   t
   setuptoolsR    t   externR   R
   t   typeR   t   add_metaclasst   objectR   (    (    (    s4   lib/python2.7/site-packages/astropy/tests/command.pyt   <module>   s   	