ó
šßÈ[c           @   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
 m Z m Z d „  Z e e _ e j d ƒ Z d	 „  Z d
 e f d „  ƒ  YZ d e j f d „  ƒ  YZ d S(   sV   
This plugin provides advanced doctest support and enables the testing of .rst
files.
i   (   t   sixiÿÿÿÿNi   (   t   OutputCheckert   FIXc         C   sx   |  j  d d d d d ƒ|  j  d d d d d ƒ|  j d d ƒ |  j d	 d
 d d d d ƒ|  j d d d t ƒd  S(   Ns   --doctest-plust   actiont
   store_truet   helpsW   enable running doctests with additional features not found in the normal doctest plugins   --doctest-rsts-   enable running doctests in .rst documentationt   doctest_plust   doctest_norecursedirssD   like the norecursedirs option but applies only to doctest collectiont   typet   argst   defaultt   doctest_rsts)   Run the doctests in the rst documentation(    (   t	   addoptiont   addinit   False(   t   parser(    (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyt   pytest_addoption   s    		t   REMOTE_DATAc            s  ˆ j  j d ƒ ‰ ˆ d  k sF ˆ j j sF ˆ j d ƒ pB ˆ j j rJ d  St j t j	 Bt
 B‰ d ˆ j f ‡ ‡ ‡ f d †  ƒ  Y} d ˆ j t j f ‡  ‡ ‡ f d †  ƒ  Y} d t j f ‡ f d †  ƒ  Y‰  ˆ j  j t | | ˆ j d	 ƒ p÷ ˆ j j ƒ d
 ƒ ˆ j  j ˆ ƒ d  S(   Nt   doctestR   t   DocTestModulePlusc              s   e  Z ‡  ‡ ‡ f d  †  Z RS(   c         3   s]  |  j  j d k r d  S|  j  j d k rs y |  j j j |  j  ƒ } Wq› t k
 ro |  j j j |  j  ƒ } q› Xn( y |  j  j ƒ  } Wn t	 k
 rš d  SXt
 ƒ  } t j d t d ˆ d t ƒ  ƒ } x‘ | j | ƒ D]€ } | j rÕ ˆ  j d d ƒ d k r8x9 | j D]+ } | j j t ƒ rt | j t j <qqWn  ˆ j | j |  | | ƒ VqÕ qÕ Wd  S(	   Ns   setup.pys   conftest.pyt   verboset   optionflagst   checkert   remote_datat   nonet   any(   t   fspatht   basenamet   configt	   _conftestt   importconftestt   AttributeErrort   pluginmanagert   _importconftestt   pyimportt   ImportErrort   DocTestFinderPlusR   t   DebugRunnerR   R   t   findt   examplest	   getoptiont   optionst   getR   t   Truet   SKIPt   DoctestItemt   name(   t   selft   modulet   findert   runnert   testt   example(   R   t   doctest_plugint   opts(    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyt   collectI   s,    			(   t   __name__t
   __module__R7   (    (   R   R5   R6   (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyR   B   s   t   DocTestTextfilePlusc              s/   e  Z d  „  Z ‡  ‡ ‡ f d †  Z d „  Z RS(   c         S   s   d  S(   N(    (   R/   (    (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyt   objn   s    c            ss   i  |  _  ˆ j |  ƒ } t j t |  j ƒ d t d ˆ d ˆ  ƒ  d t d | j ƒ d t	 d t d d	 ƒ\ } } d  S(
   Nt   module_relativeR   R   t
   extraglobst
   getfixturet   raise_on_errorR   t   encodings   utf-8(
   t   funcargst   _setup_fixturesR   t   testfilet   strR   R   t   dictt   getfuncargvalueR+   (   R/   t   fixture_requestt   failedt   tot(   t   DocTestParserPlusR5   R6   (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyt   runtestq   s    	c         S   s   |  j  d d |  j f S(   s]  
            Overwrite pytest's ``DoctestItem`` because
            ``DocTestTextfilePlus`` does not have a ``dtest`` attribute
            which is used by pytest>=3.2.0 to return the location of the
            tests.

            For details see `pytest-dev/pytest#2651
            <https://github.com/pytest-dev/pytest/pull/2651>`_.
            s   [doctest] %sN(   R   t   NoneR.   (   R/   (    (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyt
   reportinfo|   s    
(   R8   R9   R;   RK   RM   (    (   RJ   R5   R6   (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyR:   i   s   	RJ   c              s    e  Z d  Z d ‡  f d † Z RS(   sÀ  
        An extension to the builtin DocTestParser that handles the
        special directives for skipping tests.

        The directives are:

           - ``.. doctest-skip::``: Skip the next doctest chunk.

           - ``.. doctest-requires:: module1, module2``: Skip the next
             doctest chunk if the given modules/packages are not
             installed.

           - ``.. doctest-skip-all``: Skip all subsequent doctests.
        c            sÓ  t  j j |  | d | ƒ} g  } t } t } xŸ| D]—} t | t j ƒ rJ| rJg  } t } | j ƒ  j ƒ  } d d „  | Dƒ k r’ t	 } q4 n  t
 | ƒ s¤ q4 n  | d }	 t j d |	 ƒ }
 |
 r|
 j d ƒ } | d  k s| j ƒ  d k rt j d k rt	 } q4 qn  t j d |	 ƒ }
 |
 rËt j d	 |
 j d ƒ ƒ } qËq4 t | t  j ƒ r4 | sx| sxt j | ƒ r‹t	 | j t  j <n  ˆ  j d
 d ƒ d k rË| j j t ƒ rËt	 | j t  j <qËq4 q4 W| S(   NR.   s   .. doctest-skip-allc         s   s   |  ] } | j  ƒ  Vq d  S(   N(   t   strip(   t   .0t   x(    (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pys	   <genexpr>ª   s    iÿÿÿÿs    \.\.\s+doctest-skip\s*::(\s+.*)?i   t   win32s#   \.\.\s+doctest-requires\s*::\s+(.*)s   \s*,?\s*R   R   R   (   R   t   DocTestParsert   parseR   t
   isinstanceR    t   string_typesRN   t
   splitlinesR+   t   lent   ret   matcht   groupRL   t   syst   platformt   splitt   ExampleR$   t   check_required_modulesR)   R,   R(   R*   R   (   R/   t   sR.   t   resultt   requiredt	   skip_nextt   skip_allt   entryt   linest	   last_lineRY   t   marker(   R   (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyRS   ˜   sJ    
		!N(   R8   R9   t   __doc__RL   RS   (    (   R   (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyRJ   ˆ   s   R   t   doctestplus(   R    t	   getpluginRL   t   optiont   doctestmodulest   getiniR   R   t   ELLIPSISt   NORMALIZE_WHITESPACER   t   DoctestModuleR-   t   pytestt   ModuleRR   t   registert   DoctestPlusR   t
   unregister(   R   R   R:   (    (   RJ   R   R5   R6   sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyt   pytest_configure4   s    %'+D		Ru   c           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s(   | |  _  | |  _ | |  _ g  |  _ d S(   sœ  
        doctest_module_item_cls should be a class inheriting
        `pytest.doctest.DoctestItem` and `pytest.File`.  This class handles
        running of a single doctest found in a Python module.  This is passed
        in as an argument because the actual class to be used may not be
        available at import time, depending on whether or not the doctest
        plugin for py.test is available.
        N(   t   _doctest_module_item_clst   _doctest_textfile_item_clst   _run_rst_doctestst   _ignore_paths(   R/   t   doctest_module_item_clst   doctest_textfile_item_clst   run_rst_doctests(    (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyt   __init__Ö   s    
			c         C   sD   x= | j  d ƒ D], } | j d | ƒ r |  j j | ƒ Pq q Wt S(   s@   Skip paths that match any of the doctest_norecursedirs patterns.R   t   fnmatch(   Rn   t   checkR{   t   appendR   (   R/   t   pathR   t   pattern(    (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyt   pytest_ignore_collectç   s
    c         C   s  x* |  j  D] } | j | ƒ | k r
 d Sq
 W| j d k r_ | j d k rO d S|  j | | ƒ S|  j r| j d k rt | ƒ j t	 j
 j ƒ } | j j d ƒ r¨ d Sd | k rÿ t | ƒ d | d d d … j d ƒ } t d	 „  | | Dƒ ƒ rÿ d Sn  |  j | | ƒ Sd S(
   sÁ  Implements an enhanced version of the doctest module from py.test
        (specifically, as enabled by the --doctest-modules option) which
        supports skipping all doctests in a specific docstring by way of a
        special ``__doctest_skip__`` module-level variable.  It can also skip
        tests that have special requirements by way of
        ``__doctest_requires__``.

        ``__doctest_skip__`` should be a list of functions, classes, or class
        methods whose docstrings should be ignored when collecting doctests.

        This also supports wildcard patterns.  For example, to run doctests in
        a class's docstring, but skip all doctests in its modules use, at the
        module level::

            __doctest_skip__ = ['ClassName.*']

        You may also use the string ``'.'`` in ``__doctest_skip__`` to refer
        to the module itself, in case its module-level docstring contains
        doctests.

        ``__doctest_requires__`` should be a dictionary mapping wildcard
        patterns (in the same format as ``__doctest_skip__``) to a list of one
        or more modules that should be *importable* in order for the tests to
        run.  For example, if some tests require the scipy module to work they
        will be skipped unless ``import scipy`` is possible.  It is also
        possible to use a tuple of wildcard patterns as a key in this dict::

            __doctest_requires__ = {('func1', 'func2'): ['scipy']}

        s   .pys   conf.pys   .rstt   _t   docsi   Niÿÿÿÿc         s   s*   |  ]  } | j  d  ƒ p! | d k Vq d S(   R†   t   apiN(   t
   startswith(   RO   RP   (    (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pys	   <genexpr>2  s    (   R{   t   commonRL   t   extR   Rx   Rz   RD   R]   t   osRƒ   t   sepR‰   RW   t   indexR   Ry   (   R/   Rƒ   t   parentt   ignore_patht   partst
   docs_index(    (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyt   pytest_collect_fileô   s      *(   R8   R9   R   R…   R“   (    (    (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyRu   Õ   s   		R$   c           B   s8   e  Z d  Z i  Z e d „  ƒ Z d d d d d „ Z RS(   s   Extension to the default `doctest.DoctestFinder` that supports
    ``__doctest_skip__`` magic.  See `pytest_collect_file` for more details.
    c         C   sx   xq | D]i } | |  j  k r0 |  j  | s0 t Sn  y t j | ƒ Wn t k
 rb t |  j  | <t SXt |  j  | <q Wt S(   N(   t   _import_cacheR   t   impt   find_moduleR#   R+   (   t   clst   modst   mod(    (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyR_   B  s    c            sµ   t  j j ˆ ˆ ˆ  | | | ƒ } t ˆ d ƒ s? t ˆ d ƒ r± ˆ  d  k rf t ˆ d ƒ rf ˆ j ‰  n t d j t ˆ ƒ f ƒ ƒ ‚ ‡  ‡ ‡ f d †  } t	 t
 | | ƒ ƒ } n  | S(   Nt   __doctest_skip__t   __doctest_requires__R8   sL   DocTestFinder.find: name must be given when obj.__name__ doesn't exist: {!r}c            s  xq t  ˆ d g  ƒ D]] } | d k r) t S| d k rH |  j ˆ  k rH t St j |  j d j ˆ  | f ƒ ƒ r t Sq Wt  ˆ d i  ƒ } x† t j | ƒ D]u \ } } t | t ƒ s½ | f } n  xK | D]C } t j |  j d j ˆ  | f ƒ ƒ sô qÄ n  ˆ j	 | ƒ sÄ t SqÄ Wq– Wt
 S(   NRš   t   *t   .R›   (   t   getattrR   R.   R€   t   joinR    t	   iteritemsRT   t   tupleR_   R+   (   R3   t   patt   reqst   patsR˜   (   R.   R;   R/   (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyt   test_filter^  s$    $(   R   t   DocTestFinderR&   t   hasattrRL   R8   t
   ValueErrort   formatR   t   listt   filter(   R/   R;   R.   R0   t   globsR=   t   testsR¥   (    (   R.   R;   R/   sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyR&   Q  s    		N(   R8   R9   Ri   R”   t   classmethodR_   RL   R&   (    (    (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyR$   :  s
   	(   Ri   t   bundledR    R   R€   R•   RŒ   RX   R[   Rr   t   output_checkerR   R   R   t   register_optionflagR   Rw   t   objectRu   R¦   R$   (    (    (    sO   lib/python2.7/site-packages/astropy/extern/plugins/pytest_doctestplus/plugin.pyt   <module>   s   			¡e