ó
ćNXc           @   s)   d  Z  d   Z d   Z i e d 6Z d S(   s   
Handlers for IPythonDirective's @doctest pseudo-decorator.

The Sphinx extension that provides support for embedded IPython code provides
a pseudo-decorator @doctest, which treats the input/output block as a
doctest, raising a RuntimeError during doc generation if the actual output
(after running the input) does not match the expected output.

An example usage is:

.. code-block:: rst

   .. ipython::

        In [1]: x = 1

        @doctest
        In [2]: x + 2
        Out[3]: 3

One can also provide arguments to the decorator. The first argument should be
the name of a custom handler. The specification of any other arguments is
determined by the handler. For example,

.. code-block:: rst

      .. ipython::

         @doctest float
         In [154]: 0.1 + 0.2
         Out[154]: 0.3

allows the actual output ``0.30000000000000004`` to match the expected output
due to a comparison with `np.allclose`.

This module contains handlers for the @doctest pseudo-decorator. Handlers
should have the following function signature::

    handler(sphinx_shell, args, input_lines, found, submitted)

where `sphinx_shell` is the embedded Sphinx shell, `args` contains the list
of arguments that follow: '@doctest handler_name', `input_lines` contains
a list of the lines relevant to the current doctest, `found` is a string
containing the output from the IPython shell, and `submitted` is a string
containing the expected output from the IPython shell.

Handlers must be registered in the `doctests` dict at the end of this module.

c         C   s   d d l  } d d l  m } m } |  j d  rA |  d d !}  n  |  j d  rn | j t |   d t } n | j t |    } | S(   sI  
    Simplistic converter of strings from repr to float NumPy arrays.

    If the repr representation has ellipsis in it, then this will fail.

    Parameters
    ----------
    s : str
        The repr version of a NumPy array.

    Examples
    --------
    >>> s = "array([ 0.3,  inf,  nan])"
    >>> a = str_to_array(s)

    i˙˙˙˙N(   t   inft   nanu   arrayi   u   [t   dtype(   t   numpyR    R   t
   startswitht   arrayt   evalt   floatt
   atleast_1d(   t   st   npR    R   t   a(    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/custom_doctests.pyt   str_to_array3   s    c         C   sÁ  d d l  } t |  d k r- d } d } nS y$ t | d  } t | d  } Wn, t k
 r d j |  } t |   n Xy t |  } t |  } Wn t }	 n_ X| j |  }
 | j |  } | j |
 |  }	 |	 | j | |
 | | d | d	 | O}	 d } |  j	 } | d k r4d } d } n8 | j j j } d j g  | j D] } | | ^ qS } |	 r˝d } | j | | d j |  t |  t |  d | } t |   n  d S(   s˙   
    Doctest which allow the submitted output to vary slightly from the input.

    Here is how it might appear in an rst file:

    .. code-block:: rst

       .. ipython::

          @doctest float
          In [1]: 0.1 + 0.2
          Out[1]: 0.3

    i˙˙˙˙Ni   gńhăľřä>g:0âyE>i   sE   Both `rtol` and `atol` must be specified if either are specified: {0}t   rtolt   atolt    i   t   Unavailables   
sĽ   doctest float comparison failure

Document source: {0}

Raw content: 
{1}

On input line(s):
{TAB}{2}

we found output:
{TAB}{3}

instead of the expected:
{TAB}{4}

t   TABs       (   R   t   lenR   t
   IndexErrort   formatR   t   Truet   isnant   allcloset	   directivet   Nonet   statet   documentt   current_sourcet   joint   contentt   reprt   RuntimeError(   t   sphinx_shellt   argst   input_linest   foundt	   submittedR
   R   R   t   et   errort   found_isnant   submitted_isnanR   R   t   sourceR   t   line(    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/custom_doctests.pyt   float_doctestU   sD    		
		)!R   N(   t   __doc__R   R,   t   doctests(    (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/sphinxext/custom_doctests.pyt   <module>1   s   	"	D