Format: application/x-python-code
⬇ Download File (3.8 KB)
   1  o
   2  
   3  ��h�@s dZdd�Zdd�ZdeiZdS)a
   4  Handlers for IPythonDirective's @doctest pseudo-decorator.
   5  
   6  The Sphinx extension that provides support for embedded IPython code provides
   7  a pseudo-decorator @doctest, which treats the input/output block as a
   8  doctest, raising a RuntimeError during doc generation if the actual output
   9  (after running the input) does not match the expected output.
  10  
  11  An example usage is:
  12  
  13  .. code-block:: rst
  14  
  15     .. ipython::
  16  
  17          In [1]: x = 1
  18  
  19          @doctest
  20          In [2]: x + 2
  21          Out[3]: 3
  22  
  23  One can also provide arguments to the decorator. The first argument should be
  24  the name of a custom handler. The specification of any other arguments is
  25  determined by the handler. For example,
  26  
  27  .. code-block:: rst
  28  
  29        .. ipython::
  30  
  31           @doctest float
  32           In [154]: 0.1 + 0.2
  33           Out[154]: 0.3
  34  
  35  allows the actual output ``0.30000000000000004`` to match the expected output
  36  due to a comparison with `np.allclose`.
  37  
  38  This module contains handlers for the @doctest pseudo-decorator. Handlers
  39  should have the following function signature::
  40  
  41      handler(sphinx_shell, args, input_lines, found, submitted)
  42  
  43  where `sphinx_shell` is the embedded Sphinx shell, `args` contains the list
  44  of arguments that follow: '@doctest handler_name', `input_lines` contains
  45  a list of the lines relevant to the current doctest, `found` is a string
  46  containing the output from the IPython shell, and `submitted` is a string
  47  containing the expected output from the IPython shell.
  48  
  49  Handlers must be registered in the `doctests` dict at the end of this module.
  50  
  51  cCs`ddl}ddlm}m}|�d�r|dd�}|�d�r'|jt|�td�}|S|�t|��}|S)	aI
  52      Simplistic converter of strings from repr to float NumPy arrays.
  53  
  54      If the repr representation has ellipsis in it, then this will fail.
  55  
  56      Parameters
  57      ----------
  58      s : str
  59          The repr version of a NumPy array.
  60  
  61      Examples
  62      --------
  63      >>> s = "array([ 0.3,  inf,  nan])"
  64      >>> a = str_to_array(s)
  65  
  66      �N)�inf�nan�array�������[)Zdtype)�numpyrr�
  67  startswithr�eval�floatZ
  68  atleast_1d)�s�nprr�a�r�Wc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/sphinxext/custom_doctests.py�str_to_array3s
  69  
  70  �rcs@ddl}t|�dkrd}d}n zt|d�}t|d�}Wnty.d�|�}t|�|�wz
  71  t|�}t|�}Wnd}	Yn#|�|�}
  72  |�|�}|�|
  73  |�}	|	|j||
  74  ||||d	�O}	d
  75  �|j}|durrd}
  76  d}n|j	j
  77  j}
  78  d��fd
  79  d�|j
  80  D��}|	r�d}|j|
  81  |d�|�t|�t|��d�}t|��dS)z�
  82      Doctest which allow the submitted output to vary slightly from the input.
  83  
  84      Here is how it might appear in an rst file:
  85  
  86      .. code-block:: rst
  87  
  88         .. ipython::
  89  
  90            @doctest float
  91            In [1]: 0.1 + 0.2
  92            Out[1]: 0.3
  93  
  94      rN�g�h㈵��>g:�0�yE>�zEBoth `rtol` and `atol` must be specified if either are specified: {0}T)�rtol�atolz    ZUnavailable�
  95  csg|]}�|�qSrr)�.0�line�ZTABrr�
  96  <listcomp>�sz!float_doctest.<locals>.<listcomp>z�doctest float comparison failure
  97  
  98  Document source: {0}
  99  
 100  Raw content: 
 101  {1}
 102  
 103  On input line(s):
 104  {TAB}{2}
 105  
 106  we found output:
 107  {TAB}{3}
 108  
 109  instead of the expected:
 110  {TAB}{4}
 111  
 112  r)r�lenr�
 113  IndexError�formatr�isnanZallclose�	directive�stateZdocumentZcurrent_source�join�content�repr�RuntimeError)Zsphinx_shell�argsZinput_lines�foundZ	submittedr
 114  rr�e�errorZfound_isnanZsubmitted_isnanr�sourcer"rrr�
 115  float_doctestUsN�
 116  �
 117  
 118  
 119  �
 120  ��r*rN)�__doc__rr*Zdoctestsrrrr�<module>s
 121  2"E�