
    ^hi.                     H   S r SSKrSSKrSSKrSSKJr  \R                  " \5      r " S S\R                  5      r	 " S S\R                  5      r " S S	\R                  5      r " S
 S\R                  5      r\R                   " S5      r " S S\R$                  \5      rg)a  Nose Plugin that supports IPython doctests.

Limitations:

- When generating examples for use as doctests, make sure that you have
  pretty-printing OFF.  This can be done either by setting the
  ``PlainTextFormatter.pprint`` option in your configuration file to  False, or
  by interactively disabling it with  %Pprint.  This is required so that IPython
  output matches that of normal Python, which is used by doctest for internal
  execution.

- Do not rely on specific prompt numbers for results (such as using
  '_34==True', for example).  For IPython tests run via an external process the
  prompt numbers may be different, and IPython tests run as normal python code
  won't even have these special _NN variables set at all.
    N)modified_envc                   (   ^  \ rS rSrU 4S jrSrU =r$ )DocTestFinder(   c                    > [         TU ]  XX4U5      n[        [        USS5      5      (       a3  Ub0  UR                   H   nSUR
                  [        R                  '   M"     U$ )N__skip_doctest__FT)super	_get_testboolgetattrexamplesoptionsdoctestSKIP)	selfobjnamemoduleglobssource_linestestexample	__class__s	           Z/home/james-whalen/.local/lib/python3.13/site-packages/IPython/testing/plugin/ipdoctest.pyr
   DocTestFinder._get_test)   sW    w F<H/788T=M==04- )      )__name__
__module____qualname____firstlineno__r
   __static_attributes____classcell__r   s   @r   r   r   (   s     r   r   c                   B    \ rS rSrSr\R                  " S5      rS rSr	g)IPDoctestOutputChecker3   zSecond-chance checker with support for random tests.

If the default comparison doesn't pass, this checker looks in the expected
output string for flags that tell us to ignore the output.
z#\s*random\s+c                     [         R                  R                  XUU5      nU(       d!  U R                  R	                  U5      (       a  gU$ )zCheck output, accepting special markers embedded in the output.

If the output didn't pass the default validation but the special string
'#random' is included, we accept it.T)r   OutputCheckercheck_output	random_research)r   wantgotoptionflagsrets        r   r*   #IPDoctestOutputChecker.check_output<   s@     ##00S1<>t~~,,T22
r   r   N)
r   r   r    r!   __doc__recompiler+   r*   r"   r   r   r   r&   r&   3   s     

+,Ir   r&   c                       \ rS rSrSrg)	IPExampleO   r   N)r   r   r    r!   r"   r   r   r   r6   r6   O   s    $r   r6   c                   4   \ rS rSrSrSrSrSrSrSr	\
R                  " \	\\\\4-  \
R                  \
R                  -  5      r\
R                  " \	\\\\4-  \
R                  \
R                  -  5      r\
R                  " S5      rS	 rSS
 jrSS jrS rSrg)IPDocTestParserR   z
A class used to parse strings containing doctest examples.

Note: This is a version modified to properly recognize IPython input and
convert any IPython examples into valid Python ones.
z>>>z\.\.\.zIn\ \[\d+\]:z\ \ \ \.\.\.+:a]  
        # Source consists of a PS1 line followed by zero or more PS2 lines.
        (?P<source>
            (?:^(?P<indent> [ ]*) (?P<ps1> %s) .*)    # PS1 line
            (?:\n           [ ]*  (?P<ps2> %s) .*)*)  # PS2 lines
        \n? # a newline
        # Want consists of any non-blank lines that do not start with PS1.
        (?P<want> (?:(?![ ]*$)    # Not a blank line
                     (?![ ]*%s)   # Not a line starting with PS1
                     (?![ ]*%s)   # Not a line starting with PS2
                     .*$\n?       # But any other line
                  )*)
                  z#\s*all-random\s+c                     [         R                  R                  U5      n[        UR	                  5       5      S:X  a  [         R                  U5      $ U$ )z/Convert input IPython source into valid Python.   )_ipinput_transformer_managertransform_celllen
splitlines	prefilter)r   sourceblocks      r   ip2pyIPDocTestParser.ip2py   sB    --<<VDu!"a'==''Lr   c                    UR                  5       nU R                  U5      nUS:  a3  SR                  UR                  S5       Vs/ s H  oDUS PM	     sn5      n/ nSu  pgU R                  R                  U5      (       a  SnOSnSn	[        U R                  R                  U5      5      n
U
(       a  [        R                  nO,[        U R                  R                  U5      5      n
[        nSn	U
 H  nUR                  XUR                  5        5        XqR                  SXlR                  5       5      -  nU R!                  XXy5      u  pnnX-  nU R#                  U5      (       d4  UR                  U" XUUU[%        UR'                  S	5      5      -   US
95        XqR                  SUR                  5       UR)                  5       5      -  nUR)                  5       nM     UR                  XS 5        U$ s  snf )a  
Divide the given string into examples and intervening text,
and return them as a list of alternating Examples and strings.
Line numbers for the Examples are 0-based.  The optional
argument `name` is a name identifying this string, and is only
used for error messages.
r   
N)r   r   z	
# random FTindent)linenorJ   r   )
expandtabs_min_indentjoinsplit_RANDOM_TESTr,   list_EXAMPLE_RE_PYfinditerr   Example_EXAMPLE_RE_IPr6   appendstartcount_parse_example_IS_BLANK_OR_COMMENTr@   groupend)r   stringr   
min_indentloutputcharnorK   random_markerrE   termsrT   mrC   r   r-   exc_msgs                    r   parseIPDocTestParser.parse   s    ""$%%f-
>YYT8JK8J1*+8JKLF ##F++(MM  T((11&9:ooG ,,55f=>EGEAMM&	23ll4;;F ((&? -VdG
 !D ,,V44gfG-3-7AGGH<M8N-N.57 8
 ll4AEEG<<FUUWF- 0 	fWo&g  Ls   G6c           	         [        UR                  S5      5      nUR                  S5      R                  S5      nUR                  S5      nUR                  S5      n[        U5      n	U R                  XeX#U	5        U(       a  U R	                  USS SU-  U-   X#5        SR                  U V
s/ s H  oXY-   S-   S PM     sn
5      nU(       a  U R                  U5      nUR                  S	5      nUR                  S5      n[        U5      S:  a"  [        R                  " S
US   5      (       a  US	 U R	                  USU-  UU[        U5      -   5        [        R                  " SSUS   5      US'   SR                  U Vs/ s H  oUS PM	     sn5      nU R                  R                  U5      nU(       a  UR                  S5      nOSnU R                  XU5      nUUX4$ s  sn
f s  snf )a  
Given a regular expression match from `_EXAMPLE_RE` (`m`),
return a pair `(source, want)`, where `source` is the matched
example's source code (with prompts and indentation stripped);
and `want` is the example's expected output (with indentation
stripped).

`name` is the string's name, and `lineno` is the line number
where the example starts; both are used for error messages.

Optional:
`ip2py`: if true, filter the input via IPython to convert the syntax
into valid python.
rJ   rC   rH   ps1ps2r<   N r-   z *$zOut\[\d+\]: \s*?\n?rI   r   msg)r@   r[   rO   _check_prompt_blank_check_prefixrN   rE   r3   matchsub_EXCEPTION_RE_find_options)r   rd   r   rK   rE   rJ   r   ri   rj   ps1_lenslrC   r-   
want_lineswlre   r   s                    r   rY   IPDocTestParser._parse_example   s   " QWWX&' wwx(..t4 ggenggenc(  tGL|AB/Vc1A4PLILbv~a/01LIJZZ'F
 wwvZZ%
z?Q288FJrN#C#C2:s6z4!C$55	7 5bAG
1yy
;
"VW+
;< $$T*ggenGG $$V6:w--? J& <s   -G$G)c                     X%-   nUS-   n[        U5       H@  u  p[        U	5      U:  d  M  X   S:w  d  M   [        SXH-   S-   < SU< SXU < SU	< 35      e   g)al  
Given the lines of a source string (including prompts and
leading indentation), check to make sure that every prompt is
followed by a space character.  If any line is not followed by
a space character, then raise ValueError.

Note: IPython-modified version which takes the input prompt length as a
parameter, so that prompts of variable length can be dealt with.
r<   rk   zline z of the docstring for z lacks blank after z: N)	enumerater@   
ValueError)
r   linesrJ   r   rK   rt   	space_idxmin_lenilines
             r   rn   #IPDocTestParser._check_prompt_blank  sd     N	A+ 'GA4yW$C)? "((1*d"&i"8$"@ A A (r   r   N)z<string>)F)r   r   r    r!   r2   _PS1_PY_PS2_PY_PS1_IP_PS2_IP_RE_TPLr3   r4   	MULTILINEVERBOSErR   rU   rP   rE   rf   rY   rn   r"   r   r   r   r9   r9   R   s     GGGGG ZZGGGG+L!L!#

!:<N ZZGGGG+L!L!#

!:<N ::23LBH?.BAr   r9   r   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )IPDocTestRunneri#  zKTest runner that synchronizes the IPython namespace with test globals.
    c                    > [        SSS.5         [        [        U ]  UX#U5      sS S S 5        $ ! , (       d  f       g = f)N8024)COLUMNSLINES)r   r	   r   run)r   r   compileflagsoutclear_globsr   s        r   r   IPDocTestRunner.run'  s3    dT:;243?KQ <;;s   /
=r   )NNT)r   r   r    r!   r2   r   r"   r#   r$   s   @r   r   r   #  s    Q Qr   r   )r2   r   loggingr3   testpathr   	getLoggerr   logr   r)   r&   rT   r6   DocTestParserr9   register_optionflagr   DocTestRunnerobjectr   r   r   r   <module>r      s   *   	 ! !G)) W22 8 ' &KAg++ KA\ ""6*Qg++F Qr   