ó
šßÈ[c           @` s3  d  Z  d d l m Z m Z m Z 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 m Z d d l m Z m Z d d l m Z d d l m Z m Z d d	 l m Z m Z d
 d d g Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   uI   Implements the Astropy TestRunner which is a thin wrapper around py.test.i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   OrderedDicti   (   t   set_temp_configt   set_temp_cache(   t   six(   t   wrapst   find_current_module(   t   AstropyWarningt   AstropyDeprecationWarningu
   TestRunneru   TestRunnerBaseu   keywordt   keywordc           B` s&   e  Z d  Z d d d „ Z d „  Z RS(   u9  
    A decorator to mark a method as keyword argument for the ``TestRunner``.

    Parameters
    ----------
    default_value : `object`
        The default value for the keyword argument. (Default: `None`)

    priority : `int`
        keyword argument methods are executed in order of descending priority.
    i    c         C` s   | |  _  | |  _ d  S(   N(   t   default_valuet   priority(   t   selfR   R   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyt   __init__#   s    	c         ` s7   ‡  f d †  } |  j  | _ |  j | _ ˆ  j | _ | S(   Nc          ` s   ˆ  |  | Ž  S(   N(    (   t   argst   kwargs(   t   f(    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR   (   s    (   R   t   _default_valueR   t	   _priorityt   __doc__(   R   R   R   (    (   R   s3   lib/python2.7/site-packages/astropy/tests/runner.pyt   __call__'   s
    N(   t   __name__t
   __module__R   t   NoneR   R   (    (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR      s   t   TestRunnerBasec           B` sG   e  Z d  Z d „  Z d „  Z d „  Z d Z d „  Z e d „  ƒ Z	 RS(   uú  
    The base class for the TestRunner.

    A test runner can be constructed by creating a subclass of this class and
    defining 'keyword' methods. These are methods that have the
    `~astropy.tests.runner.keyword` decorator, these methods are used to
    construct allowed keyword arguments to the
    `~astropy.tests.runner.TestRunnerBase.run_tests` method as a way to allow
    customization of individual keyword arguments (and associated logic)
    without having to re-implement the whole
    `~astropy.tests.runner.TestRunnerBase.run_tests` method.

    Examples
    --------

    A simple keyword method::

        class MyRunner(TestRunnerBase):

            @keyword('default_value'):
            def spam(self, spam, kwargs):
                """
                spam : `str`
                    The parameter description for the run_tests docstring.
                """
                # Return value must be a list with a CLI parameter for pytest.
                return ['--spam={}'.format(spam)]
    c         C` s   t  j j | ƒ |  _ d  S(   N(   t   ost   patht   abspatht	   base_path(   R   R   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR   R   s    c   	      O` sf  t  j r$ t j |  d t j ƒ} n t j |  d t j ƒ} t d „  | ƒ } t | d d „  d t ƒ} t	 ƒ  |  _
 d } x | D]… \ } } y" | d  t d  ƒ t k r¯ w‚ n  Wn t k
 rÃ n X| j |  j
 | <| j r‚ | d 7} | | j j ƒ  7} | d	 7} q‚ q‚ Wt  j r5|  j j d
 | ƒ |  j j _ n |  j j d
 | ƒ |  j _ t t |  ƒ j |  ƒ S(   Nt	   predicatec         S` s   |  d j  d k S(   Ni   u   keyword(   R   (   t   func(    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyt   <lambda>j   s    t   keyc         S` s   |  d j  S(   Ni   (   R   (   t   x(    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR"   l   s    t   reverseu    u    i   u   

t   keywordsu           (   R   t   PY2t   inspectt
   getmemberst   ismethodt
   isfunctiont   filtert   sortedt   TrueR   R&   R   t   Falset   NotImplementedt	   ExceptionR   R   t   stript   RUN_TESTS_DOCSTRINGt   formatt	   run_testst   __func__t   superR   t   __new__(	   t   clsR   R   t	   functionsR&   t   sorted_keywordst   doc_keywordst   nameR!   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR8   U   s,    	
	
	!c         K` så   t  j |  j ƒ } | j | ƒ g  } x‹ | j ƒ  D]} } t |  | ƒ } | | | | ƒ } | t k r~ t d j | ƒ ƒ ‚ n  t	 | t
 ƒ s¥ t d j | ƒ ƒ ‚ n  | | 7} q2 Wt j rá g  | D] } | j d ƒ ^ qÃ } n  | S(   Nu1   run_tests() got an unexpected keyword argument {}u$   {} keyword method must return a listu   utf-8(   t   copyt   deepcopyR&   t   updatet   keyst   getattrR0   t	   TypeErrorR4   t
   isinstancet   listR   R'   t   encode(   R   R   R&   R   R   R!   t   resultR$   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyt   _generate_argsŽ   s    	%uµ   
        Run the tests for the package.

        This method builds arguments for and then calls ``pytest.main``.

        Parameters
        ----------
        {keywords}

        c   	      K` só   d d  l  } t |  j j ƒ  ƒ } t | j ƒ  ƒ } | j | ƒ ss t | j | ƒ ƒ } t d j | d ƒ ƒ ‚ n  |  j	 |   } t
 j d ƒ } t
 j d ƒ } t | d t ƒ; t | d t ƒ" | j d | d |  j d ƒ SWd  QXWd  QXd  S(	   Ni    u1   run_tests() got an unexpected keyword argument {}u   astropy_configu   astropy_cachet   deleteR   t   pluginsu   plugins(   t   pytestt   setR&   RA   t   issubsetRE   t
   differenceRC   R4   RH   t   tempfilet   mkdtempR   R.   R   t   main(	   R   R   RK   t   allowed_kwargst   passed_kwargst   wrong_kwargsR   t   astropy_configt   astropy_cache(    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR5   ´   s    c         ` sv   |  | ƒ ‰  t  ˆ  j d d d ƒ‡  f d †  ƒ } t d ƒ } | d	 k	 rZ | j | _ n  t | d ƒ rr | ` n  | S(
   u‡  
        Constructs a `TestRunner` to run in the given path, and returns a
        ``test()`` function which takes the same arguments as
        `TestRunner.run_tests`.

        The returned ``test()`` function will be defined in the module this
        was called from.  This is used to implement the ``astropy.test()``
        function (or the equivalent for affiliated packages).
        u   __doc__t   exclude_argsu   selfc          ` s   ˆ  j  |    S(   N(   R5   (   R   (   t   runner(    s3   lib/python2.7/site-packages/astropy/tests/runner.pyt   testß   s    i   u   __wrapped__(   u   __doc__(   u   selfN(   R   R5   R	   R   R   R   t   hasattrt   __wrapped__(   R9   R   RY   t   module(    (   RX   s3   lib/python2.7/site-packages/astropy/tests/runner.pyt   make_test_runner_inÑ   s    '	(
   R   R   R   R   R8   RH   R3   R5   t   classmethodR]   (    (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR   4   s   		9	$	t
   TestRunnerc           B` s:  e  Z d  Z e d d ƒ d „  ƒ Z e d d ƒ d „  ƒ Z e ƒ  d „  ƒ Z e ƒ  d „  ƒ Z e ƒ  d „  ƒ Z e ƒ  d	 „  ƒ Z	 e ƒ  d
 „  ƒ Z
 e d d ƒ d „  ƒ Z e ƒ  d „  ƒ Z e ƒ  d „  ƒ Z e ƒ  d „  ƒ Z e d ƒ d „  ƒ Z e ƒ  d „  ƒ Z e ƒ  d „  ƒ Z e ƒ  d „  ƒ Z d „  Z RS(   u)   
    A test runner for astropy tests
    R   iè  c         C` s   | r t  j d t ƒ n  g  S(   NuŽ   The coverage option is ignored on run_tests, since it can not be made to work in that context.  Use 'python setup.py test --coverage' instead.(   t   warningst   warnR
   (   R   t   coverageR   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyRb   ù   s
    
i   c         C` s   | d k r |  j |  _ nZ t j j |  j | j d t j j ƒ ƒ |  _ t j j |  j ƒ su t	 d j
 | ƒ ƒ ‚ n  | d s‰ |  j g Sg  S(   u¿   
        package : str, optional
            The name of a specific package to test, e.g. 'io.fits' or 'utils'.
            If nothing is specified all default Astropy tests are run.
        u   .u   Package not found: {0}u	   test_pathN(   R   R   t   package_pathR   R   t   joint   replacet   sept   isdirt
   ValueErrorR4   (   R   t   packageR   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyRi     s    

c   	      C` s4  g  } |  j  | d | ƒ | r0t j j | ƒ \ } } | d k rø | d d k rc t d ƒ ‚ n  t j j | d ƒ } t j j t j j | t j | ƒ ƒ } t j j	 | | f ƒ } t j j
 | ƒ rø | | k rø | j d d d g ƒ | } qø n  t j j | ƒ p| d k s%t d
 ƒ ‚ n  | | g Sg  S(   u×   
        test_path : str, optional
            Specify location to test by path. May be a single file or
            directory. Must be specified absolutely or relative to the
            calling directory.
        u   packageu   .rstu    u	   docs_pathu6   Can not test .rst files without a docs_path specified.u   -pu   astropy.tests.pytest_pluginsu   --doctest-rstu   .pyu=   Test path must be a directory or a path to a .py or .rst file(   u   .rstu    N(   u   .pyu   .rst(   Ri   R   R   t   splitextR   Rh   R   Rd   t   pardirt   commonprefixt   existst   extendRg   (	   R   t	   test_pathR   t   all_argst   baset   extt   abs_docs_patht   abs_test_patht   common(    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyRo     s(    	
c         C` s*   | r& t  j | d t j j d ƒ ƒSg  S(   u•   
        args : str, optional
            Additional arguments to be passed to ``pytest.main`` in the ``args``
            keyword argument.
        t   posixu   win(   t   shlext   splitt   syst   platformt
   startswith(   R   R   R   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR   G  s     c         C` s   g  S(   u   
        plugins : list, optional
            Plugins to be passed to ``pytest.main`` in the ``plugins`` keyword
            argument.
        (    (   R   RJ   R   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyRJ   S  s    c         C` s   | r d g Sg  S(   u¸   
        verbose : bool, optional
            Convenience option to turn on verbose output from py.test. Passing
            True is the same as specifying ``-v`` in ``args``.
        u   -v(    (   R   t   verboseR   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR|   \  s    c         C` s;   | d k	 r7 | d k r( d j | ƒ g St d ƒ ‚ n  g  S(   uõ   
        pastebin : ('failed', 'all', None), optional
            Convenience option for turning on py.test pastebin output. Set to
            'failed' to upload info for failed tests, or 'all' to upload info
            for all tests.
        u   failedu   allu   --pastebin={0}u$   pastebin should be 'failed' or 'all'N(   u   failedu   all(   R   R4   Rh   (   R   t   pastebinR   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR}   h  s
    R   u   nonec         C` sh   | t  k r d } nC | t k r* d } n. | d k rX t j d j | ƒ t ƒ d } n  d j | ƒ g S(   us  
        remote_data : {'none', 'astropy', 'any'}, optional
            Controls whether to run tests marked with @remote_data. This can be
            set to run no tests with remote data (``none``), only ones that use
            data from http://data.astropy.org (``astropy``), or all tests that
            use remote data (``any``). The default is ``none``.
        u   anyu   noneu   astropyuÍ   The remote_data option should be one of none/astropy/any (found {0}). For backward-compatibility, assuming 'any', but you should change the option to be one of the supported ones to avoid issues in future.u   --remote-data={0}(   u   noneu   astropyu   any(   R.   R/   R`   Ra   R4   R   (   R   t   remote_dataR   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR~   x  s    
			c         C` sJ   | rF y d d l  } Wn t k
 r5 t d ƒ ‚ qF Xd d d g Sn  g  S(   u½   
        pep8 : bool, optional
            Turn on PEP8 checking via the pytest-pep8 plugin and disable normal
            tests. Same as specifying ``--pep8 -k pep8`` in ``args``.
        i    NuR   PEP8 checking requires pytest-pep8 plugin: http://pypi.python.org/pypi/pytest-pep8u   --pep8u   -ku   pep8(   t   pytest_pep8t   ImportError(   R   t   pep8R   R   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR   ‘  s    c         C` s   | r d g Sg  S(   uœ   
        pdb : bool, optional
            Turn on PDB post-mortem analysis for failing tests. Same as
            specifying ``--pdb`` in ``args``.
        u   --pdb(    (   R   t   pdbR   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR‚   £  s    c         C` sm   | ri | d d k r% t  d ƒ ‚ n  y d d l } Wn t k
 rT t  d ƒ ‚ n Xd g St d ƒ n  g  S(   uÞ   
        open_files : bool, optional
            Fail when any tests leave files open.  Off by default, because
            this adds extra run time to the test suite.  Requires the
            ``psutil`` package.
        u   paralleli    uI   open file detection may not be used in conjunction with parallel testing.NuC   open file detection requested, but psutil package is not installed.u   --open-filesu   Checking for unclosed files(   t   SystemErrort   psutilR€   t   print(   R   t
   open_filesR   R„   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR†   ®  s    i    c         C` sW   | d k rS y d d l  m } Wn t k
 r? t d ƒ ‚ n Xd t j | ƒ g Sg  S(   u  
        parallel : int or 'auto', optional
            When provided, run the tests in parallel on the specified
            number of CPUs.  If parallel is ``'auto'``, it will use the all
            the cores on the machine.  Requires the ``pytest-xdist`` plugin.
        i    (   t   pluginu;   running tests in parallel requires the pytest-xdist packageu   -n(   t   xdistR‡   R€   Rƒ   R   t	   text_type(   R   t   parallelR   R‡   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyRŠ   É  s    c         C` s³   | d k	 r‰ | d r‰ | d d k	 rU t j j | | d j d t j j ƒ ƒ } n  t j j | ƒ s‰ t j d j	 | ƒ ƒ d } q‰ n  | r¯ | d r¯ | d r¯ | d g Sg  S(   ua   
        docs_path : str, optional
            The path to the documentation .rst files.
        u	   skip_docsu   packageu   .u=   Can not test .rst docs, since docs path ({0}) does not exist.u	   test_pathu   --doctest-rstN(
   R   R   R   Rd   Re   Rf   Rm   R`   Ra   R4   (   R   t	   docs_pathR   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR‹   Ü  s    	%

c         C` s   g  S(   uu   
        skip_docs : `bool`, optional
            When `True`, skips running the doctests in the .rst files.
        (    (   R   t	   skip_docsR   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyRŒ   ð  s    c         C` s   | r d j  | ƒ g Sg  S(   u­   
        repeat : `int`, optional
            If set, specifies how many times each test should be run. This is
            useful for diagnosing sporadic failures.
        u   --repeat={0}(   R4   (   R   t   repeatR   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR   ù  s    c         K` s&   d d l  m } t t |  ƒ j |   S(   Ni   (   t   Table(   t   tableRŽ   R7   R_   R5   (   R   R   RŽ   (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR5     s    (   R   R   R   R   Rb   Ri   Ro   R   RJ   R|   R}   R~   R   R‚   R†   RŠ   R‹   RŒ   R   R5   (    (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyR_   ó   s"   ,		(   R   t
   __future__R    R   R   R   R(   R   R>   Rw   Ry   RO   R`   t   collectionsR   t   config.pathsR   R   t   externR   t   utilsR   R	   t   utils.exceptionsR
   R   t   __all__t   objectR   R   R_   (    (    (    s3   lib/python2.7/site-packages/astropy/tests/runner.pyt   <module>   s"   "¿