
    &es                     >   U d 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Zddl	Z	ddl
mZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm Z  ddlm!Z! ddlm"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl1m3Z3 ddl4m5Z5 dd l6m7Z7 erddl8Z8d!Z9d"Z:d#Z;d$Z<d%Z=e9e:e;e<e=fZ>da?da@eed&                  eAd'<   d(e*d)dfd*ZBdad+ZCd,ed-e.d)eed.                  fd/ZD eEejF        G                    d0          d                   d1k     reDZHd-e.d)eed.                  fd2ZDe3ZId3 Z3d4ed)eJfd5ZKd6e(d4ed-e.d)eJfd7ZLd4ed)eJfd8ZM G d9 d:e"          ZN G d; d<eO          ZPd)ed=         fd>ZQ	 	 	 	 dbd@ed&         dAeeJ         dBeEdCeJd)d=f
dDZR G dE dFejS                  ZTd)eeUeEf         fdGZVdH ZWdI ZX G dJ dKejY                  ZZdcdNZ[dOe\d)eJfdPZ]ed)edQ         fdR            Z^ G dS dTejY                  Z_dUeTd)e,fdVZ`d)ed&         fdWZadddXZbd)eEfdYZcd)eEfdZZdd)eEfd[Zed\eUd)eEfd]Zf ejg        d^_          d)eeUef         fd`            ZhdS )ez6Discover and run ipdoctests in modules and test files.    N)contextmanager)Path)Any)Callable)Dict)	Generator)Iterable)List)Optional)Pattern)Sequence)Tuple)Type)TYPE_CHECKING)Union)outcomes)ExceptionInfo)ReprFileLocation)TerminalRepr)TerminalWritersafe_getattr)Config)Parser)FixtureRequest)	Collector)OutcomeException
fnmatch_ex)import_path)approx)PytestWarningnonecdiffndiffudiffonly_first_failureIPDoctestOutputCheckerCHECKER_CLASSparserreturnc                    |                      ddddg           |                      ddd	           |                     d
          }|                    ddddd           |                    dt          j        ddt
          d           |                    ddg ddd           |                    ddddd           |                    dddd d!           d S )"Nipdoctest_optionflagszoption flags for ipdoctestsargsELLIPSIS)typedefaultipdoctest_encodingz!encoding used for ipdoctest fileszutf-8)r1   collectz--ipdoctest-modules
store_trueFz!run ipdoctests in all .py modulesipdoctestmodules)actionr1   helpdestz--ipdoctest-reportr&   z;choose another output format for diffs on ipdoctest failureipdoctestreport)r0   r1   r7   choicesr8   z--ipdoctest-globappendpatz4ipdoctests file matching pattern, default: test*.txtipdoctestglob)r6   r1   metavarr7   r8   z --ipdoctest-ignore-import-errorszignore ipdoctest ImportErrorsipdoctest_ignore_import_errorsz--ipdoctest-continue-on-failurez>for a given ipdoctest, continue to run after the first failureipdoctest_continue_on_failure)addinigetgroup	addoptionstrlowerDOCTEST_REPORT_CHOICES)r*   groups     Glib/python3.11/site-packages/IPython/testing/plugin/pytest_ipdoctest.pypytest_addoptionrI   H   sO   
MM%	     MMA7     OOI&&E	OO0     
OOYJ&     
OOC     
OO*,-     
OO)M,          c                  
    d a d S N)RUNNER_CLASS rJ   rH   pytest_unconfigurerO   z   s     LLLrJ   	file_pathparent)IPDoctestModuleIPDoctestTextfilec                 4   |j         }| j        dk    rV|j        j        rIt	          t          |           t          |           f          st                              ||           }|S n/t          || |          rt                              ||           }|S d S )Nz.pypath)configsuffixoptionr5   any_is_setup_py_is_main_pyrR   from_parent_is_ipdoctestrS   )rP   rQ   rW   modtxts        rH   pytest_collect_filera      s     ]F5  =) 	#)$$k)&<&<=3
 3
 	 $3#>#>vI#>#V#VCJ	vy&	1	1 !2!>!>vI!>!V!V
4rJ   .   c                 <    t          t          |           |          S rL   )_collect_filer   )rV   rQ   s     rH   ra   ra      s     T$ZZ000rJ   c                 X    dd l }t          |j                            |                     S )Nr   )py.path_import_pathrV   local)rV   rootpys      rH   r    r       s'    BGMM$//000rJ   rV   c                 T    | j         dk    rdS |                                 }d|v pd|v S )Nzsetup.pyFs
   setuptoolss	   distutils)name
read_bytes)rV   contentss     rH   r[   r[      s8    yJu  HH$@(@@rJ   rW   c                     j         dv r|j                                      rdS |                     d          pdg}t	          fd|D                       S )N)z.txtz.rstTr=   z	test*.txtc              3   8   K   | ]}t          |          V  d S rL   r   ).0globrV   s     rH   	<genexpr>z _is_ipdoctest.<locals>.<genexpr>   s-      88$z$%%888888rJ   )rX   session
isinitpath	getoptionrZ   )rW   rV   rQ   globss    `  rH   r^   r^      sh    {&&&6>+D+DT+J+J&t_-->+E8888%888888rJ   c                     | j         dk    S )Nz__main__.py)rm   rU   s    rH   r\   r\      s    9%%rJ   c                   V    e Zd Zdeeeee         f                  ddfdZdeddfdZ	dS )ReprFailDoctestreprlocation_linesr+   Nc                     || _         d S rL   )r|   )selfr|   s     rH   __init__zReprFailDoctest.__init__   s     #5rJ   twc                 ~    | j         D ]4\  }}|D ]}|                    |           |                    |           5d S rL   )r|   line
toterminal)r~   r   reprlocationlinesr   s        rH   r   zReprFailDoctest.toterminal   sZ    #'#: 	( 	(L%  ##B''''	( 	(rJ   )
__name__
__module____qualname__r   r   r   rD   r   r   r   rN   rJ   rH   r{   r{      sn        5"*51A8C=1P+Q"R5	5 5 5 5
(^ ( ( ( ( ( ( (rJ   r{   c                   4     e Zd Zded         ddf fdZ xZS )MultipleDoctestFailuresfailureszdoctest.DocTestFailurer+   Nc                 V    t                                                       || _        d S rL   )superr   r   )r~   r   	__class__s     rH   r   z MultipleDoctestFailures.__init__   s$     rJ   )r   r   r   r   r   __classcell__r   s   @rH   r   r      sQ        !*B!C ! ! ! ! ! ! ! ! ! ! !rJ   r   IPDocTestRunnerc                  <    dd l ddlm}   G fdd|           }|S )Nr      )r   c                        e Zd ZdZ	 	 	 	 dded         dee         ded	ed
df
 fdZddddded
dffdZ	ddddde
ee         eej        f         d
dffdZ xZS )/_init_runner_class.<locals>.PytestDoctestRunnerzRunner to collect failures.

        Note that the out variable in this case is a list instead of a
        stdout-like object.
        Nr   Tcheckerr(   verboseoptionflagscontinue_on_failurer+   c                 ^    t                                          |||           || _        d S )N)r   r   r   )r   r   r   )r~   r   r   r   r   r   s        rH   r   z8_init_runner_class.<locals>.PytestDoctestRunner.__init__   s2     GGWg;WWW':D$$$rJ   testdoctest.DocTestexamplezdoctest.Examplegotc                 h     j         |||          }| j        r|                    |           d S |rL   )DocTestFailurer   r;   )r~   outr   r   r   failuredoctests         rH   report_failurez>_init_runner_class.<locals>.PytestDoctestRunner.report_failure   sC     -g,T7C@@G' 

7#####rJ   exc_infoc                    t          |d         t                    r|d         t          |d         t          j                  rt	          j        d            j        |||          }| j        r|                    |           d S |)Nr   zQuitting debugger)	
isinstancer   bdbBdbQuitr   exitUnexpectedExceptionr   r;   )r~   r   r   r   r   r   r   s         rH   report_unexpected_exceptionzK_init_runner_class.<locals>.PytestDoctestRunner.report_unexpected_exception   s     (1+'788 "qk!(1+s{33 312221g1$JJG' 

7#####rJ   NNr   T)r   r   r   __doc__r   boolintr   rD   r   r   r   BaseExceptiontypesTracebackTyper   r   )r   r   s   @rH   PytestDoctestRunnerr      s5       	 	 ;?&* (,	; 	;67	; d^	; 		;
 "&	; 	; 	; 	; 	; 	; 	;	 $	 '		
 	 	 	 	 	 	 		 $	 '		
 D/@SST	 	 	 	 	 	 	 	 	 	 	rJ   r   )r   	ipdoctestr   )r   r   r   s     @rH   _init_runner_classr      s[    NNN******- - - - - - -o - - -^ rJ   Tr   r   r   r   c                 R    t           t                      a t          | |||          S )Nr   r   r   r   )rM   r   r   s       rH   _get_runnerr      s:     )++ /	   rJ   c                       e Zd Z	 	 ddeddded         ded         d	df
 fd
Zedddeddddf fd            ZddZddZ	ddZ
ddZdee         d	eeef         f fdZd	eedef         ee         ef         fdZ eej                            d          d                   dk     red	efd            Z xZS  xZS )IPDoctestItemNrm   rQ   z)Union[IPDoctestTextfile, IPDoctestModule]runnerr   dtestr   r+   c                     t                                          ||           || _        || _        d | _        d | _        d S rL   )r   r   r   r   objfixture_request)r~   rm   rQ   r   r   r   s        rH   r   zIPDoctestItem.__init__  sB     	v&&&
9=rJ   c                N    t                                          ||||          S )zThe public named constructor.)rm   rQ   r   r   )r   r]   )clsrQ   rm   r   r   r   s        rH   r]   zIPDoctestItem.from_parent  s'     ww""VFRW"XXXrJ   c                    | j         Jt          |           | _        t          | j        j                  }| j                            d                                          D ]
\  }}|||<   | j         j                            |           ddlm	} t          | j         j        d         |          ri | _        | j                            t          j                   t          j                            | j         j                   t          j                            dd            t           t          j        d<   t          j        | j         _        d S d S d S )N)
getfixtureipdoctest_namespacer   	IPExampler   ___builtins__)r   _setup_fixturesr   dictgetfixturevalueitemsrx   updater   r   r   examples_user_ns_orig_ipuser_nspopbuiltins)r~   rx   rm   valuer   s        rH   setupzIPDoctestItem.setup,  s<   :!#24#8#8D D$8$HIIIE#3CC%   egg$ $e $dJ##E***,,,,,,$*-a0)<< / &(""))#+666""4:#3444 T***.6N+#&;
   - "!/ /rJ   c                 .   ddl m} t          | j        j        d         |          rPi | j        _        t          j                                         t          j        	                    | j
                   | `
| j        j                                         d S )Nr   r   r   )r   r   r   r   r   rx   r   r   clearr   r   )r~   r   s     rH   teardownzIPDoctestItem.teardownE  s    (((((( dj)!,i88 	#!DJKKt1222"
     rJ   c                    | j         J | j        J t          | j                    |                                  g }t	          t
          d          }t          t
          dd           }t          j                    }t          j	        | j
        j                   	 | j                            | j         |d           t          j	        |           |rt          t
          d|           nt	          t
          d          rt          t
          d           n]# t          j	        |           |rt          t
          d|           w t	          t
          d          rt          t
          d           w w xY w|rt          |          d S )Nr   F)r   clear_globs)r   r   _check_all_skipped$_disable_output_capturing_for_darwinhasattrr   getattrosgetcwdchdirfspathdirnamerunsetattrdelattrr   )r~   r   had_underscore_valueunderscore_original_valuecurdirs        rH   runtestzIPDoctestItem.runtestQ  s   z%%%{&&&4:&&&1133335  'x55$+Hc4$@$@!
 
$%%%		' KOODJH%OHHHHV# '#'@AAAA3'' '#&&&	 HV# '#'@AAAA3'' '#&&&&'  	4)(333	4 	4s   "D AE.c                 T   t          j                    dk    rdS | j        j                            d          }|rm|                    d           |                                \  }}t          j        	                    |           t          j
        	                    |           dS dS )zNDisable output capturing. Otherwise, stdout is lost to ipdoctest (pytest#985).DarwinNcapturemanagerT)in_)platformsystemrW   pluginmanager	getpluginsuspend_global_captureread_global_capturesysstdoutwritestderr)r~   capmanr   errs       rH   r   z2IPDoctestItem._disable_output_capturing_for_darwino  s    ?((F*445EFF 	"))d)3331133HCJS!!!JS!!!!!		" 	"rJ   excinfoc                    dd l }d }t          |j        |j        |j        f          r	|j        g}n&t          |j        t
                    r|j        j        }|!t                                          |          S g }|D ]}|j	        }|j
        j        }j        d }nj        |j        z   dz   }t          |          j        }	t          |||	          }
t!                      }t#          | j                            d                    }|z|j
        j        J |j
        j                            d          }j        J fdt-          |          D             }|t/          |j        dz
  d          |j        dz            }n>dg}d}|j                                        D ]}|                    d	| d
|            d} t          ||j                  r3||                    ||j        |                              d          z  }nTt;          j        |j                  }|dtA          |j                  z  gz  }|d tC          j"        |j         D             z  }|                    |
|f           tG          |          S )Nr   r   r9   Fc                 :    g | ]\  }}d |j         z   dz   |fz  S )z%03d %sr   )lineno)rr   ixr   s      rH   
<listcomp>z.IPDoctestItem.repr_failure.<locals>.<listcomp>  s?       =CaIT[1!4a 88  rJ   	   z?EXAMPLE LOCATION UNKNOWN, not showing all tests of that examplez>>>z???  z...
zUNEXPECTED EXCEPTION: %sc                 8    g | ]}|                     d           S )r  )strip)rr   r  s     rH   r  z.IPDoctestItem.repr_failure.<locals>.<listcomp>  s/       &'AGGDMM  rJ   )$r   r   r   r   r   r   r   r   repr_failurer   r   filenamer   r0   r   r   _get_checker_get_report_choicerW   rw   	docstring
splitlines	enumeratemaxsourcer;   output_differencer   splitr   from_exc_infor   repr	tracebackformat_exceptionr{   )r~   r   r   r   r|   r   r   r	  r   messager   r   report_choicer   indentr   inner_excinfor   r   s                    @rH   r  zIPDoctestItem.repr_failure{  s    	  	 MG2G4OP
 
 	.  HH'>?? 	.}-H77''000 )	= )	=GoG<D}H{"w~597mm,G+HfgFFL"nnG.t{/D/DEV/W/WXXM!|-999.99%@@{...   GPQVGWGW   c'.1"4a887>A;MMN V #N5577 # #DLL!7!7!7!7!7888"FF'7#9:: 	22W[- %++ !. ;G<L M M4tM<O7P7PPQQ  +4+EwGW+X    %%|U&;<<<<1222rJ   zos.PathLike[str]c                 L    | j         J | j        | j         j        d| j        z  fS )Nz[ipdoctest] %s)r   rV   r   rm   r~   s    rH   
reportinfozIPDoctestItem.reportinfo  s,    z%%%y$*+-=	-IIIrJ   rb   r   rc   c                 *    t          | j                  S rL   r   r   r  s    rH   rV   zIPDoctestItem.path      $$$rJ   )NNr+   N)r   r   r   rD   r   r   classmethodr]   r   r   r   r   r   r   r   r   r  r   r   r  pytest__version__r  propertyr   rV   r   r   s   @rH   r   r     s       
 /3-1> >> <> *+	>
 )*> 
> > > > > > 
Y;
Y 	
Y
 "
Y !
Y 
Y 
Y 
Y 
Y [
Y/ / / /2
! 
! 
! 
!4 4 4 4<	" 	" 	" 	">3}->3 
sL 	!>3 >3 >3 >3 >3 >3@JE%(:C(?"@(3-QT"TU J J J J s6##C((+,,q00		%$ 	% 	% 	% 
	% 	% 	% 	% 	% 1000rJ   r   c                      dd l } t          | j        | j        | j        | j        | j        | j        t                      t                      t                      	  	        S )Nr   )	DONT_ACCEPT_TRUE_FOR_1DONT_ACCEPT_BLANKLINENORMALIZE_WHITESPACEr/   IGNORE_EXCEPTION_DETAILCOMPARISON_FLAGSALLOW_UNICODEALLOW_BYTESNUMBER)r   r   r'  r(  r)  r/   r*  r+  _get_allow_unicode_flag_get_allow_bytes_flag_get_number_flagr   s    rH   _get_flag_lookupr3    sa    NNN&=%;$9! ' ? 1-//)++!!
 
 
 
rJ   c                 z    | j                             d          }t                      }d}|D ]}|||         z  }|S )Nr-   r   )rW   getinir3  )rQ   optionflags_strflag_lookup_tableflag_accflags        rH   get_optionflagsr:    sO    m**+BCCO(**H , ,%d++OrJ   c                 b    |                      d          }|r|                      d          rd}|S )Nr@   usepdbF)getvalue)rW   r   s     rH   _get_continue_on_failurer>    s?     //*IJJ ( ??8$$ 	("'rJ   c                        e Zd ZdZdee         fdZ eej	        
                    d          d                   dk     r,edefd            Zedddd	ee         f fd
            Z xZS  xZS )rS   Nr+   c              #     K   dd l }ddlm} | j                            d          }| j                            |          }t          | j                  }| j        j        }ddi}t          |           }t          d|t                      t          | j                            }	 |            }
|
                    ||||d          }|j        r't                              | |j        |	|	          V  d S d S )
Nr   r   )IPDocTestParserr2   r   __main__Fr   r   r   r   rm   r   r   )r   r   rA  rW   r5  rV   	read_textrD   rm   r:  r   r
  r>  get_doctestr   r   r]   )r~   r   rA  encodingtextr	  rm   rx   r   r   r*   r   s               rH   r3   zIPDoctestTextfile.collect  s#     ...... ;%%&:;;y""8,,ty>>y~Z(%d++# NN 8 E E	
 
 
 !""!!$tXqAA= 	++49V4 ,       	 	rJ   rb   r   rc   c                 *    t          | j                  S rL   r  r  s    rH   rV   zIPDoctestTextfile.path
  r   rJ   r   rV   rV   c                |    |dd l }|j                            |          } t                      j        d||d|S Nr   )rQ   r   rN   rg   rV   ri   r   r]   r   rQ   r   rV   kwrk   r   s         rH   r]   zIPDoctestTextfile.from_parent  K     t,,&577&JfVJJrJJJrJ   )r   r   r   r   r	   r   r3   r   r#  r$  r  r%  r   rV   r"  r   r]   r   r   s   @rH   rS   rS     s        
C-0    8 s6##C((+,,q00		%$ 	% 	% 	% 
	% 

 #'	K 	K 	K
 4.	K 	K 	K 	K 	K 
	K 	K 	K 	K 	K 1000rJ   rS   r   r   c                     ddl t          fd| j        D                       }|rt          j        d           dS dS )zVRaise pytest.skip() if all examples in the given DocTest have the SKIP
    option set.r   Nc              3   X   K   | ]$}|j                             j        d           V  %dS )FN)optionsgetSKIP)rr   r  r   s     rH   rt   z%_check_all_skipped.<locals>.<genexpr>#  s5      PPQaimmGL%88PPPPPPrJ   z%all docstests skipped by +SKIP option)r   allr   r#  skip)r   all_skippedr   s     @rH   r   r     s[     NNNPPPP$-PPPPPK =;<<<<<= =rJ   r   c                 (    t          | dd          duS )zmReturn if an object is possibly a mock object by checking the
    existence of a highly improbable attribute.1pytest_mock_example_attribute_that_shouldnt_existNr   )r   s    rH   
_is_mockedr[  (  s!     	SMtTT	rJ   )NNNc               #     K   t           j        dddt          dt          f         dt          t          t          gt          f                  dt          ffd} | t           _        	 dV  t           _        dS # t           _        w xY w)zContext manager which replaces ``inspect.unwrap`` with a version
    that's aware of mock objects and doesn't recurse into them.Nstopfunc.r^  r+   c                     	 |	|t           u r  t                     S |   fd          S # t          $ r'}t          j        d|d dt                      d }~ww xY w)Nr]  c                 8    t          |           p
           S rL   )r[  )r   _stopr_  s    rH   <lambda>zF_patch_unwrap_mock_aware.<locals>._mock_aware_unwrap.<locals>.<lambda>>  s    joo6Tt rJ   zGot z when unwrapping z.  This is usually caused by a violation of Python's object protocol; see e.g. https://github.com/pytest-dev/pytest/issues/5080)r[  	Exceptionwarningswarnr"   )r_  r^  erb  real_unwraps   `  @rH   _mock_aware_unwrapz4_patch_unwrap_mock_aware.<locals>._mock_aware_unwrap7  s    	|tz11"{4j9999E;t*T*T*T*T*TUUUU 	 	 	MM GHaaO 	   	s   5 5 
A&"A!!A&)inspectunwrapr   r   r   )ri  rh  s    @rH   _patch_unwrap_mock_awarerl  1  s       .K MQ  sCx +3HcUCZ4H+I	     " (GN%$$$$$s   &A8 8Bc                        e Zd Zdee         fdZ eej        	                    d          d                   dk     r,e
defd            Zedddd	ee         f fd
            Z xZS  xZS )rR   r+   c              #     K   dd l }ddlm}m}  G d d|          }| j        j        dk    rt          t          j        	                    d          d                   dk     r>| j
        j                            | j        | j
                            d	                    }n| j
        j                            | j        | j
                            d	          | j
        j        
          }nj	 t          | j        | j
        j                  }nH# t           $ r; | j
                            d          rt          j        d| j        z             n Y nw xY w | |                      }t'          |           }t)          d|t+                      t-          | j
                            }|                    ||j                  D ].}	|	j        r%t4                              | |	j        ||	          V  /d S )Nr   r   )DocTestFinderrA  c                   2     e Zd ZdZ fdZ	 	 d fdZ xZS )7IPDoctestModule.collect.<locals>.MockAwareDocTestFinderzA hackish ipdoctest finder that overrides stdlib internals to fix a stdlib bug.

            https://github.com/pytest-dev/pytest/issues/3456
            https://bugs.python.org/issue25532
            c                     t          |t                    rt          |d|          }t          |d          rt	          j        |          }t                                          ||          S )a3  Doctest code does not take into account `@property`, this
                is a hackish way to fix it. https://bugs.python.org/issue17446

                Wrapped Doctests will need to be unwrapped so the correct
                line number is returned. This will be reported upstream. #8796
                fget__wrapped__)r   r%  r   r   rj  rk  r   _find_lineno)r~   r   source_linesr   s      rH   ru  zDIPDoctestModule.collect.<locals>.MockAwareDocTestFinder._find_lineno[  sm     c8,, 4!#vs33C3.. .!.--C ww++   rJ   r+   Nc           
          t          |          rd S t                      5  t                                          |||||||           d d d            d S # 1 swxY w Y   d S rL   )r[  rl  r   _find)	r~   testsr   rm   modulerv  rx   seenr   s	           rH   rx  z=IPDoctestModule.collect.<locals>.MockAwareDocTestFinder._findo  s     c?? F-//  GGMMsD&,t                   s   (AAAr!  )r   r   r   r   ru  rx  r   r   s   @rH   MockAwareDocTestFinderrq  T  sh             (		 	 	 	 	 	 	 	 	 	rJ   r|  zconftest.pyrb   rc   
importmode)rootpath)rj   r?   zunable to import module %r)r*   FrC  rD  )r   r   ro  rA  rV   rm   r   r#  r$  r  rW   r   _importconftestrw   r~  r    ImportErrorr=  rW  r:  r   r
  r>  findr   r   r   r]   )
r~   r   ro  rA  r|  rz  finderr   r   r   s
             rH   r3   zIPDoctestModule.collectP  s?     ========$	 $	 $	 $	 $	] $	 $	 $	L 9>]**6%++C00344q882BBIK)),77 
 2BBIK)),77![1 C  $TYT[5IJJJ   ;''(HII K <ty HIIII JI ('/@/@AAA%d++# NN 8 E E	
 
 
 KK88 	 	D} #//tyt 0     	 	s   , D AEErb   r   rc   c                 *    t          | j                  S rL   r  r  s    rH   rV   zIPDoctestModule.path  r   rJ   NrJ  rV   c                |    |dd l }|j                            |          } t                      j        d||d|S rL  rM  rN  s         rH   r]   zIPDoctestModule.from_parent  rP  rJ   )r   r   r   r	   r   r3   r   r#  r$  r  r%  r   rV   r"  r   r]   r   r   s   @rH   rR   rR   O  s        L-0 L L L L\ s6##C((+,,q00		%$ 	% 	% 	% 
	% 

 #'	K 	K 	K
 4.	K 	K 	K 	K 	K 
	K 	K 	K 	K 	K 1000rJ   rR   doctest_itemc                     dd}i | _         | j        j        }|                    | |dd          | _        t          | d          }|                                 |S )	zIUsed by IPDoctestTextfile and IPDoctestItem to setup fixture information.r+   Nc                      d S rL   rN   rN   rJ   rH   r_  z_setup_fixtures.<locals>.func  s    rJ   F)noder_  r   funcargsT)	_ispytestr!  )r  ru   _fixturemanagergetfixtureinfo_fixtureinfor   _fillfixtures)r  r_  fmr   s       rH   r   r     s}        L			-B " 1 1$ !2 ! !L %\TBBBO!!###rJ   c                  D    dd l } dd lddlm}  G fdd|          }|S )Nr   r   )r(   c                        e Zd Z                    dj                  Z                    dj                  Z                    dj                  Zde	de	de
def fdZde	de	de	fd	Z xZS )
2_init_checker_class.<locals>.LiteralsOutputCheckerz(\W|^)[uU]([rR]?[\'\"])z(\W|^)[bB]([rR]?[\'\"])a  
            (?P<number>
              (?P<mantissa>
                (?P<integer1> [+-]?\d*)\.(?P<fraction>\d+)
                |
                (?P<integer2> [+-]?\d+)\.
              )
              (?:
                [Ee]
                (?P<exponent1> [+-]?\d+)
              )?
              |
              (?P<integer3> [+-]?\d+)
              (?:
                [Ee]
                (?P<exponent2> [+-]?\d+)
              )
            )
            wantr   r   r+   c                    t                                          |||          rdS |t                      z  }|t                      z  }|t	                      z  }|s|s|sdS dt
          t                   dt          dt          f	fd}|r" || j        |          } || j        |          }|r" || j        |          } || j        |          }|r| 	                    ||          }t                                          |||          S )NTFregexr`   r+   c                 2                         | d|          S )Nz\1\2)sub)r  r`   res     rH   remove_prefixeszX_init_checker_class.<locals>.LiteralsOutputChecker.check_output.<locals>.remove_prefixes  s    vveWc222rJ   )
r   check_outputr/  r0  r1  r   rD   _unicode_literal_re_bytes_literal_re_remove_unwanted_precision)
r~   r  r   r   allow_unicodeallow_bytesallow_numberr  r   r  s
           rH   r  z?_init_checker_class.<locals>.LiteralsOutputChecker.check_output  sI   ww##D#{;; t'*A*C*CCM%(=(?(??K&)9););;L   \ u3ws| 3# 3# 3 3 3 3 3 3  E&t'?FF%od&>DD C&t'=tDD%od&<cBB A55dC@@77''c;???rJ   c                    t          | j                            |                    }t          | j                            |                    }t          |          t          |          k    r|S d}t	          ||          D ]o\  }}|                    d          }|                    d          }	|	|                    d          }	|dnt          |          }
|	|
t          |	          z  }
t          |                                          t          t          |                                          d|
 z            k    r|d |	                                |z            |                                z   ||
                                |z   d          z   }||
                                |	                                z
  |
                                |	                                z
  z
  z  }q|S )Nr   fraction	exponent1	exponent2
   )abs)list
_number_refinditerlenziprG   r   floatr!   startend)r~   r  r   wantsgotsoffsetwgr  exponent	precisions              rH   r  zM_init_checker_class.<locals>.LiteralsOutputChecker._remove_unwanted_precision  s   11$7788E005566D5zzSYY&&
FE4(( J J1*+''**=*=*+''+*>*># ww{33H!)!1AAs8}}	'X.I##veAGGII.>.>B
N'S'S'SSS
 0aggii&001AGGII=AEEGGfDTDVDV@WW  aeegg		1QUUWWqwwyy5HIIFJrJ   )r   r   r   compileUNICODEr  r  VERBOSEr  rD   r   r   r  r  r   )r   r  s   @rH   LiteralsOutputCheckerr    s        
 !jj)CRZPPJJ'A2:NNZZ& J)
 

.	@S 	@s 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@6	3 	S 	S 	 	 	 	 	 	 	 	rJ   r  )r   r  r   r(   )r   r(   r  r  s      @rH   _init_checker_classr    so    NNNIII111111O O O O O O O 6 O O Ob ! rJ   c                  H    t           t                      a t                      S )a  Return a IPDoctestOutputChecker subclass that supports some
    additional options:

    * ALLOW_UNICODE and ALLOW_BYTES options to ignore u'' and b''
      prefixes (respectively) in string literals. Useful when the same
      ipdoctest should run in Python 2 and Python 3.

    * NUMBER to ignore floating-point differences smaller than the
      precision of the literal number in the ipdoctest.

    An inner class is used to avoid importing "ipdoctest" at the module
    level.
    )r)   r  rN   rJ   rH   r
  r
    s     +--??rJ   c                  *    ddl }  | j        d          S )z+Register and return the ALLOW_UNICODE flag.r   Nr,  r   register_optionflagr2  s    rH   r/  r/  1  s    NNN&7&777rJ   c                  *    ddl }  | j        d          S )z)Register and return the ALLOW_BYTES flag.r   Nr-  r  r2  s    rH   r0  r0  8  s    NNN&7&}555rJ   c                  *    ddl }  | j        d          S )z$Register and return the NUMBER flag.r   Nr.  r  r2  s    rH   r1  r1  ?  s    NNN&7&x000rJ   keyc           
          ddl }t          |j        t          |j        t
          |j        t          |j        t          di|          S )zReturn the actual `ipdoctest` module flag value.

    We want to do it as late as possible to avoid importing `ipdoctest` and all
    its dependencies when parsing options, as it adds overhead and breaks tests.
    r   N)
r   DOCTEST_REPORT_CHOICE_UDIFFREPORT_UDIFFDOCTEST_REPORT_CHOICE_CDIFFREPORT_CDIFFDOCTEST_REPORT_CHOICE_NDIFFREPORT_NDIFF(DOCTEST_REPORT_CHOICE_ONLY_FIRST_FAILUREREPORT_ONLY_FIRST_FAILUREDOCTEST_REPORT_CHOICE_NONE)r  r   s     rH   r  r  F  sH     NNN 	$W%9#W%9#W%90'2S"A 
 rJ   ru   )scopec                      t                      S )zcFixture that returns a :py:class:`dict` that will be injected into the
    namespace of ipdoctests.)r   rN   rJ   rH   r   r   W  s     66MrJ   r!  r   )r   r   r+   N)r+   r(   )ir   r   r   rj  r   r   r   r  r   re  
contextlibr   pathlibr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r#  _pytestr   _pytest._code.coder   r   r   _pytest._ior   _pytest.compatr   _pytest.configr   _pytest.config.argparsingr   _pytest.fixturesr   _pytest.nodesr   _pytest.outcomesr   _pytest.pathlibr   r    _pytest.python_apir!   _pytest.warning_typesr"   r   r  r  r  r  r  rF   rM   r)   __annotations__rI   rO   ra   r   r$  r  re   rh   r   r[   r^   r\   r{   rd  r   r   r   Itemr   rD   r3  r:  r>  ModulerS   r   objectr[  rl  rR   r   r  r
  r/  r0  r1  r  fixturer   rN   rJ   rH   <module>r     s   = < <  



  				  



       % % % % % %                                                                                                  , , , , , , / / / / / / + + + + + + & & & & & & ' ' ' ' ' ' ! ! ! ! ! ! , , , , , , + + + + + + # # # # # # - - - - - - & & & & & & ' ' ' ' ' ' % % % % % % / / / / / / NNN# % % % +? ( ,  :>x567 > > >/V / / / / /d    e:;<   " 3v$$Q'((1,,'M11 
%>?	@1 1 1 1 L1 1 1At A A A A A9& 9 9i 9D 9 9 9 9&d &t & & & &
( 
( 
( 
( 
(l 
( 
( 
(! ! ! ! !i ! ! !3D!23 3 3 3 3n 37" $	 ./d^  	
    (r% r% r% r% r%FK r% r% r%j$sCx.         2K 2K 2K 2K 2K 2K 2K 2Kj= = = =F t     %),<"= % % % %:bK bK bK bK bKfm bK bK bKJ- N     V!T":; V! V! V! V!r   (8 8 8 8 86s 6 6 6 61# 1 1 1 1C C    " i   T#s(^    !   rJ   