
    ^hs                        % S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
Jr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJ r   SSKJ!r!  SSKJ"r"  SSK#J$r$  SSK%J&r&  SSK'J(r(  SSK)J*r*  SSK+J,r,  SSK-J.r.  SSK/J0r0  SSK1J2r2  SSK1J3r3  SSK4J5r5  SS K6J7r7  \(       a  SSK8r8S!r9S"r:S#r;S$r<S%r=\9\:\;\<\=4r>Sq?Sq@\\S&      \AS''   S(\*S)S4S* jrBS^S+ jrCS,\S-\.S)\\S.      4S/ jrD\E" \R                  R                  S05      S   5      S1:  a  \DrHS-\.S)\\S.      4S2 jrD\3rIS3 r3S4\S)\J4S5 jrKS6\(S4\S-\.S)\J4S7 jrLS4\S)\J4S8 jrM " S9 S:\"5      rN " S; S<\O5      rPS)\S=   4S> jrQ    S_S?\S&   S@\\J   SA\ESB\JS)S=4
SC jjrR " SD SE\R                  5      rTS)\\U\E4   4SF jrVSG rWSH rX " SI SJ\R                  5      rZS`SK jr[SL\\S)\J4SM jr]\S)\SN   4SO j5       r^ " SP SQ\R                  5      r_SR\TS)\,4SS jr`S)\S&   4ST jraSaSU jrbS)\E4SV jrcS)\E4SW jrdS)\E4SX jreSY\US)\E4SZ jrf\R                  " S[S\9S)\\U\4   4S] j5       rhg)bz6Discover 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           	      T   U R                  SSSS/S9  U R                  SSSS	9  U R                  S
5      nUR                  SSSSSS9  UR                  S[        R                  SS[
        SS9  UR                  SS/ SSSS9  UR                  SSSSSS9  UR                  SSSS S!S9  g )"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     a/home/james-whalen/.local/lib/python3.13/site-packages/IPython/testing/plugin/pytest_ipdoctest.pypytest_addoptionrI   H   s    
MM%	   MMA7   OOI&E	OO0   
OOYYJ&   
OOC   
OO*,-   
OO)M,      c                      S q g N)RUNNER_CLASS rJ   rH   pytest_unconfigurerO   z   s	     LrJ   	file_pathparent)IPDoctestModuleIPDoctestTextfilec                 2   UR                   nU R                  S:X  aU  UR                  R                  (       a9  [	        [        U 5      [        U 5      45      (       d  [        R                  XS9nU$ g [        X U5      (       a  [        R                  XS9nU$ g )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#>#>v#>#VCJ  
v&	1	1!2!>!>v!>!V
rJ   .   c                 ,    [        [        U 5      U5      $ rL   )_collect_filer   )rV   rQ   s     rH   ra   ra      s     T$Z00rJ   c                 R    SS K n[        UR                  R                  U 5      5      $ )Nr   )py.path_import_pathrV   local)rV   rootpys      rH   r    r       s    BGGMM$/00rJ   rV   c                 f    U R                   S:w  a  gU R                  5       nSU;   =(       d    SU;   $ )Nzsetup.pyFs
   setuptoolss	   distutils)name
read_bytes)rV   contentss     rH   r[   r[      s2    yyJ HH$@(@@rJ   rW   c                    ^ TR                   S;   a!  UR                  R                  T5      (       a  gU R                  S5      =(       d    S/n[	        U4S jU 5       5      $ )N)z.txtz.rstTr=   z	test*.txtc              3   <   >#    U  H  n[        UT5      v   M     g 7frL   r   ).0globrV   s     rH   	<genexpr> _is_ipdoctest.<locals>.<genexpr>   s     8%$z$%%%s   )rX   session
isinitpath	getoptionrZ   )rW   rV   rQ   globss    `  rH   r^   r^      sO    {{&&6>>+D+DT+J+J_->+E8%888rJ   c                      U R                   S:H  $ )Nz__main__.py)rm   rU   s    rH   r\   r\      s    99%%rJ   c                   N    \ rS rSrS\\\\\   4      SS4S jrS\	SS4S jr
Srg)	ReprFailDoctest   reprlocation_linesr+   Nc                     Xl         g rL   r~   )selfr~   s     rH   __init__ReprFailDoctest.__init__   s
     #5rJ   twc                     U R                    H0  u  p#U H  nUR                  U5        M     UR                  U5        M2     g rL   )r~   line
toterminal)r   r   reprlocationlinesr   s        rH   r   ReprFailDoctest.toterminal   s8    #'#:#:L ##B' $;rJ   r   )__name__
__module____qualname____firstlineno__r   r   r   rD   r   r   r   __static_attributes__rN   rJ   rH   r|   r|      s>    5"*51A8C=1P+Q"R5	5
(^ ( (rJ   r|   c                   :   ^  \ rS rSrS\S   SS4U 4S jjrSrU =r$ )MultipleDoctestFailures   failureszdoctest.DocTestFailurer+   Nc                 .   > [         TU ]  5         Xl        g rL   )superr   r   )r   r   	__class__s     rH   r    MultipleDoctestFailures.__init__   s     rJ   )r   )r   r   r   r   r   r   r   __classcell__r   s   @rH   r   r      s!    !*B!C ! ! !rJ   r   IPDocTestRunnerc                  8   ^ SS K mSSKJn    " U4S jSU 5      nU$ )Nr      )r   c                      >^  \ rS rSrSr    SS\S   S\\   S\S\S	S4
U 4S
 jjjrSSSSS\	S	S4U4S jjr
SSSSS\\\   \\R                  4   S	S4U4S jjrSrU =r$ )/_init_runner_class.<locals>.PytestDoctestRunner   zpRunner to collect failures.

Note that the out variable in this case is a list instead of a
stdout-like object.
Ncheckerr(   verboseoptionflagscontinue_on_failurer+   c                 .   > [         TU ]  XUS9  X@l        g )N)r   r   r   )r   r   r   )r   r   r   r   r   r   s        rH   r   8_init_runner_class.<locals>.PytestDoctestRunner.__init__   s     GW;W':$rJ   testdoctest.DocTestexamplezdoctest.Examplegotc                 t   > TR                   " X#U5      nU R                  (       a  UR                  U5        g UerL   )DocTestFailurer   r;   )r   outr   r   r   failuredoctests         rH   report_failure>_init_runner_class.<locals>.PytestDoctestRunner.report_failure   s1     ,,TC@G''

7#rJ   exc_infoc                   > [        US   [        5      (       a  US   e[        US   [        R                  5      (       a  [        R
                  " S5        TR                  " X#U5      nU R                  (       a  UR                  U5        g Ue)Nr   zQuitting debugger)	
isinstancer   bdbBdbQuitr   exitUnexpectedExceptionr   r;   )r   r   r   r   r   r   r   s         rH   report_unexpected_exceptionK_init_runner_class.<locals>.PytestDoctestRunner.report_unexpected_exception   so     (1+'788qk!(1+s{{331211$JG''

7#rJ   )r   NNr   T)r   r   r   r   __doc__r   boolintr   rD   r   r   r   BaseExceptiontypesTracebackTyper   r   r   )r   r   s   @rH   PytestDoctestRunnerr      s    	 ;?&* (,	;67	; d^	; 		;
 "&	; 	; 	;	 $	 '		
 	 		 $	 '		
 D/@S@SST	 	 	rJ   r   )r   	ipdoctestr   )r   r   r   s     @rH   _init_runner_classr      s    *-o -^ rJ   r   r   r   r   c                 <    [         c
  [        5       q [        U UUUS9$ )Nr   r   r   r   )rM   r   r   s       rH   _get_runnerr      s-     )+ /	 rJ   c                   l  ^  \ rS rSr  SS\SSS\S   S\S	   S
S4
U 4S jjjr\SSS\SSSS	4U 4S jj5       rSS jr	SS jr
SS jrSS jrS\\   S
\\\4   4U 4S jjrS
\\S\4   \\   \4   4S jr\" \R,                  R/                  S5      S   5      S:  a  \S
\4S j5       rSrU =r$ SrU =r$ )IPDoctestItemi  Nrm   rQ   z)Union[IPDoctestTextfile, IPDoctestModule]runnerr   dtestr   r+   c                 X   > [         TU ]  X5        X0l        X@l        S U l        S U l        g rL   )r   r   r   r   objfixture_request)r   rm   rQ   r   r   r   s        rH   r   IPDoctestItem.__init__  s+     	&
9=rJ   c                    > [         TU ]  X!X4S9$ )zThe public named constructor.)rm   rQ   r   r   )r   r]   )clsrQ   rm   r   r   r   s        rH   r]   IPDoctestItem.from_parent  s     w"F"XXrJ   c                    U R                   Gbq  [        U 5      U l        [        U R                  R                  S9nU R                  R	                  S5      R                  5        H	  u  p#X1U'   M     U R                   R                  R                  U5        SSKJ	n  [        U R                   R                  S   U5      (       a  0 U l        U R                  R                  [        R                  5        [        R                  R                  U R                   R                  5        [        R                  R                  SS 5        [         [        R                  S'   [        R                  U R                   l        g g g )N)
getfixtureipdoctest_namespacer   	IPExampler   ___builtins__)r   _setup_fixturesr   dictgetfixturevalueitemsry   updater   r   r   examples_user_ns_orig_ipuser_nspopbuiltins)r   ry   rm   valuer   s        rH   setupIPDoctestItem.setup,  s   ::!#24#8D D$8$8$H$HIE#33CC% eg  $d  JJ##E*,$**--a0)<< &("""))#++6""4::#3#34 T*.6N+#&;;

  = "rJ   c                 \   SSK Jn  [        U R                  R                  S   U5      (       aZ  0 U R                  l        [        R                  R                  5         [        R                  R                  U R                  5        U ?
U R                  R
                  R                  5         g )Nr   r   r   )r   r   r   r   r   ry   r   r   clearr   r   )r   r   s     rH   teardownIPDoctestItem.teardownE  ss    ( djj))!,i88!DJJKKKKt112"

 rJ   c                    U R                   c   eU R                  c   e[        U R                   5        U R                  5         / n[	        [
        S5      n[        [
        SS 5      n[        R                  " 5       n[        R                  " U R                  R                  5         U R                  R                  U R                   USS9  [        R                  " U5        U(       a  [        [
        SU5        O%[	        [
        S5      (       a  [        [
        S5        U(       a  [        U5      eg ! [        R                  " U5        U(       a  [        [
        SU5        f [	        [
        S5      (       a  [        [
        S5        f f = f)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   runtestIPDoctestItem.runtestQ  s#   zz%%%{{&&&4::&11335  'x5$+Hc4$@!
 
$$%		' KKOODJJH%OHHHV##'@A3''#&)(33  HHV##'@A3''#& (s   '%D3 3AF
c                 P   [         R                  " 5       S:w  a  gU R                  R                  R	                  S5      nU(       a`  UR                  SS9  UR                  5       u  p#[        R                  R                  U5        [        R                  R                  U5        gg)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   2IPDoctestItem._disable_output_capturing_for_darwino  s|    ??(**445EF))d)3113HCJJS!JJS!	 rJ   excinfoc                 &  > SS K nS n[        UR                  UR                  UR                  45      (       a  UR                  /nO5[        UR                  [
        5      (       a  UR                  R                  nUc  [        TU ]!  U5      $ / nU GHf  nUR                  nUR                  nUR                  nUR                  c  S n	OUR                  UR                  -   S-   n	[        U5      R                  n
[        XU
5      n[!        5       n[#        U R$                  R'                  S5      5      nU	b  UR                  R(                  c   eUR                  R(                  R+                  S5      nUR                  c   e[-        U5       VVs/ s H  u  nnSXR                  -   S-   U4-  PM     nnnU[/        UR                  S-
  S5      UR                  S-    nO?S/nSnUR0                  R+                  5        H  nUR3                  S	U S
U 35        SnM     [        XRR                  5      (       a.  XR5                  XeR6                  U5      R9                  S5      -  nO|[:        R<                  " UR>                  5      nUS[A        UR                  5      -  /-  nU[B        RD                  " UR>                  6  Vs/ s H  nURG                  S5      PM     sn-  nUR3                  X45        GMi     [I        U5      $ s  snnf s  snf )Nr   r   r9   Fz%03d %s	   z?EXAMPLE LOCATION UNKNOWN, not showing all tests of that examplez>>>z???  z...
zUNEXPECTED EXCEPTION: %s)%r   r   r   r   r   r   r   r   repr_failurer   r   filenamelinenor0   r   r   _get_checker_get_report_choicerW   rx   	docstring
splitlines	enumeratemaxsourcer;   output_differencer   splitr   from_exc_infor   repr	tracebackformat_exceptionstripr|   )r   r  r   r   r~   r   r   r   r  r  messager   r   report_choicer   ixindentr   inner_excinfor   s                       rH   r  IPDoctestItem.repr_failure{  s    	  	 MMG22G4O4OP
 
  H'>??}}--H7'00GooG<<D}}H{{"w~~597m,,G+HgFL"nG.t{{/D/DEV/WXM!||--999..99%@{{...GPQVGWGWVaI[[1!4a 88GW   c'..1"4a87>>A;MN V #NN557DLL4xq!78"F 8 '#9#9::22[[-%+ !. ; ;G<L<L M4tM<O<O7PPQQ+4+E+EwGWGW+X+XaAGGDM+X  %%|&;<S  T 1221(s   #LLzos.PathLike[str]c                     U R                   c   eU R                  U R                   R                  SU R                  -  4$ )Nz[ipdoctest] %s)r   rV   r  rm   r   s    rH   
reportinfoIPDoctestItem.reportinfo  s7    zz%%%yy$**++-=		-IIIrJ   rb   r   rc   c                 ,    [        U R                  5      $ rL   r   r   r-  s    rH   rV   IPDoctestItem.path      $$rJ   )r   r   r   r   r   )NNr+   N)r   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   r   s   @rH   r   r     s9   
 /3-1>> <> *+	>
 )*> 
> > 
Y;
Y 	
Y
 "
Y !
Y 
Y/2
!4<	">3}->3 
sL 	!>3@JE%(:C(?"@(3-QT"TU J 6##C(+,q0		%$ 	% 
	% 1rJ   r   c                      SS K n [        U R                  U R                  U R                  U R
                  U R                  U R                  [        5       [        5       [        5       S9	$ )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_lookuprF    sZ    &==%;;$99!! ' ? ? 11-/)+!
 
rJ   c                 t    U R                   R                  S5      n[        5       nSnU H
  nX2U   -  nM     U$ )Nr-   r   )rW   getinirF  )rQ   optionflags_strflag_lookup_tableflag_accflags        rH   get_optionflagsrM    sA    mm**+BCO(*Hd++  OrJ   c                 f    U R                  S5      nU(       a  U R                  S5      (       a  SnU$ )Nr@   usepdbF)getvalue)rW   r   s     rH   _get_continue_on_failurerQ    s2     //*IJ ??8$$"'rJ   c                      ^  \ rS rSrSrS\\   4S jr\" \	R                  R                  S5      S   5      S:  a)  \S\4S j5       r\SSS	.S
\\   4U 4S jjj5       rSrU =r$ SrU =r$ )rS   i  Nr+   c              #     #    SS K nSSKJn  U R                  R	                  S5      nU R
                  R                  U5      n[        U R
                  5      nU R
                  R                  nSS0n[        U 5      n[        SU[        5       [        U R                  5      S9n	U" 5       n
U
R                  XGXeS5      nUR                  (       a!  [        R!                  XR                  XS	9v   g g 7f)
Nr   r   )IPDocTestParserr2   r   __main__Fr   r   r   r   rm   r   r   )r   r   rT  rW   rH  rV   	read_textrD   rm   rM  r   r  rQ  get_doctestr   r   r]   )r   r   rT  encodingtextr  rm   ry   r   r   r*   r   s               rH   r3   IPDoctestTextfile.collect  s     . ;;%%&:;yy""8,tyy>yy~~Z(%d+# N 8 E	
 !"!!$tqA==++99V ,   s   C/C1rb   r   rc   c                 ,    [        U R                  5      $ rL   r1  r-  s    rH   rV   IPDoctestTextfile.path
  r3  rJ   r   rV   rV   c                l   > Ub  SS K nUR                  R                  U5      n[        TU ]  " SXS.UD6$ Nr   )rQ   r   rN   rg   rV   ri   r   r]   r   rQ   r   rV   kwrk   r   s         rH   r]   IPDoctestTextfile.from_parent  8     t,7&JfJrJJrJ   rN   )r   r   r   r   r   r	   r   r3   r   r6  r7  r  r8  r   rV   r5  r   r]   r   r   r   s   @rH   rS   rS     s    
C-0 8 6##C(+,q0		%$ 	% 
	% 

 #'	K
 4.	K 
	K 1rJ   rS   c                    ^ SSK m[        U4S jU R                   5       5      nU(       a  [        R                  " S5        gg)zRRaise pytest.skip() if all examples in the given DocTest have the SKIP
option set.r   Nc              3   n   >#    U  H*  oR                   R                  TR                  S 5      v   M,     g7f)FN)optionsgetSKIP)rr   r(  r   s     rH   rt   %_check_all_skipped.<locals>.<genexpr>#  s%     P-QiimmGLL%88-s   25z%all docstests skipped by +SKIP option)r   allr   r6  skip)r   all_skippedr   s     @rH   r   r     s1     P$--PPK;< rJ   r   c                      [        U SS5      SL$ )ziReturn 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_mockedrr  (  s     	SMtT	rJ   )NNNc               #      ^#    [         R                  mSS.S[        S[        4   S[        [        [        /[        4      S[        4U4S jjjn U [         l         Sv   T[         l        g! T[         l        f = f7f)z|Context manager which replaces ``inspect.unwrap`` with a version
that's aware of mock objects and doesn't recurse into them.Nstopfunc.ru  r+   c                   >^ ^  Ub	  U[         L a  T" T [         S9$ UmT" T UU 4S jS9$ ! [         a*  n[        R                  " SU< ST < S3[        5        e S nAff = f)Nrt  c                 8   > [        U 5      =(       d    T" T5      $ rL   )rr  )r   _stoprv  s    rH   <lambda>F_patch_unwrap_mock_aware.<locals>._mock_aware_unwrap.<locals>.<lambda>>  s    jo6Tt6TrJ   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)rr  	Exceptionwarningswarnr"   )rv  ru  ery  real_unwraps   `  @rH   _mock_aware_unwrap4_patch_unwrap_mock_aware.<locals>._mock_aware_unwrap7  si    	|tz1"4j99Et*TUU 	MM GHO 	 	s   * * 
A%AA)inspectunwrapr   r   r   )r  r  s    @rH   _patch_unwrap_mock_awarer  1  sr      ..K MQsCx +3HcUCZ4H+I	 " (GN%$s   AA<A,  A<,A99A<c                      ^  \ rS rSrS\\   4S jr\" \R                  R                  S5      S   5      S:  a)  \S\4S j5       r\SSS	.S
\\   4U 4S jjj5       rSrU =r$ SrU =r$ )rR   iO  r+   c              #   :  #    SS K nSSKJnJn   " S SU5      nU R                  R
                  S:X  a  [        [        R                  R                  S5      S   5      S:  aJ  U R                  R                  R                  U R                  U R                  R                  S	5      5      nOU R                  R                  R                  U R                  U R                  R                  S	5      U R                  R                  S
9nO) [        U R                  U R                  R                  S9nU" U" 5       S9n['        U 5      n[)        SU[+        5       [-        U R                  5      S9nUR/                  WUR0                  5       H6  n	U	R2                  (       d  M  [4        R7                  X	R
                  XS9v   M8     g ! [          aG    U R                  R#                  S5      (       a%  [        R$                  " SU R                  -  5         Ne f = f7f)Nr   r   )DocTestFinderrT  c                   @   ^  \ rS rSrSrU 4S jr  SU 4S jjrSrU =r$ )7IPDoctestModule.collect.<locals>.MockAwareDocTestFinderiT  zA 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                    > [        U[        5      (       a  [        USU5      n[        US5      (       a  [        R
                  " U5      n[        TU ]  UU5      $ )zDoctest 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   r8  r   r   r  r  r   _find_lineno)r   r   source_linesr   s      rH   r  DIPDoctestModule.collect.<locals>.MockAwareDocTestFinder._find_lineno[  sU     c8,,!#vs3C3..!..-C w+  rJ   c           
         > [        U5      (       a  g [        5          [        TU ]  XX4XVU5        S S S 5        g ! , (       d  f       g = frL   )rr  r  r   _find)	r   testsr   rm   moduler  ry   seenr   s	           rH   r  =IPDoctestModule.collect.<locals>.MockAwareDocTestFinder._findo  s8     c??-/GMD,t 0//s	   9
ArN   r4  )	r   r   r   r   r   r  r  r   r   r   s   @rH   MockAwareDocTestFinderr  T  s    (		 	rJ   r  zconftest.pyrb   rc   
importmode)rootpath)rj   r?   zunable to import module %r)r*   FrV  rW  )r   r   r  rT  rV   rm   r   r6  r7  r  rW   r  _importconftestrx   r  r    ImportErrorrP  rn  rM  r   r  rQ  findr   r   r   r]   )
r   r   r  rT  r  r  finderr   r   r   s
             rH   r3   IPDoctestModule.collectP  s    =$	] $	L 99>>]*6%%++C034q822BBIIKK)),7
 22BBIIKK)),7![[11 C $TYYT[[5I5IJ (/@A%d+# N 8 E	
 KK8D}}}#//yy 0   9  ;;''(HIIKK <tyy HI	s2   DH(G 3A+H"%HAHHHHrb   r   rc   c                 ,    [        U R                  5      $ rL   r1  r-  s    rH   rV   IPDoctestModule.path  r3  rJ   Nr_  rV   c                l   > Ub  SS K nUR                  R                  U5      n[        TU ]  " SXS.UD6$ ra  rb  rc  s         rH   r]   IPDoctestModule.from_parent  rf  rJ   rN   )r   r   r   r   r	   r   r3   r   r6  r7  r  r8  r   rV   r5  r   r]   r   r   r   s   @rH   rR   rR   O  s    L-0 L\ 6##C(+,q0		%$ 	% 
	% 

 #'	K
 4.	K 
	K 1rJ   rR   doctest_itemc                     SS jn0 U l         U R                  R                  nUR                  XSSS9U l        [        U SS9nUR                  5         U$ )zIUsed by IPDoctestTextfile and IPDoctestItem to setup fixture information.Nc                      g rL   rN   rN   rJ   rH   rv  _setup_fixtures.<locals>.func  s    rJ   F)noderv  r   funcargsT)	_ispytestr4  )r  rv   _fixturemanagergetfixtureinfo_fixtureinfor   _fillfixtures)r  rv  fmr   s       rH   r   r     sa     L				-	-B " 1 1$ !2 !L %\TBO!!#rJ   c                  @   ^ SS K n SS KmSSKJn   " U4S jSU5      nU$ )Nr   r   )r(   c                   
  >^  \ rS rSr YR	                  S YR
                  5      r YR	                  S YR
                  5      r YR	                  S YR                  5      r	S\
S\
S\S\4U U4S	 jjrS\
S\
S\
4S
 jrSrU =r$ )2_init_checker_class.<locals>.LiteralsOutputCheckeri  z(\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U ]  XU5      (       a  gU[        5       -  nU[        5       -  nU[	        5       -  nU(       d  U(       d  U(       d  gS[
        [           S[        S[        4U	4S jjnU(       a&  U" U R                  U5      nU" U R                  U5      nU(       a&  U" U R                  U5      nU" U R                  U5      nU(       a  U R                  X5      n[         TU ]  XU5      $ )NTFregexr`   r+   c                 *   > TR                  U SU5      $ )Nz\1\2)sub)r  r`   res     rH   remove_prefixesX_init_checker_class.<locals>.LiteralsOutputChecker.check_output.<locals>.remove_prefixes  s    vveWc22rJ   )
r   check_outputrB  rC  rD  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  ?_init_checker_class.<locals>.LiteralsOutputChecker.check_output  s    w#D{;;'*A*CCM%(=(??K&)9);;L \3ws| 3# 3# 3 &t'?'?F%d&>&>D&t'='=tD%d&<&<cB55d@7';??rJ   c                 0   [        U R                  R                  U5      5      n[        U R                  R                  U5      5      n[        U5      [        U5      :w  a  U$ Sn[	        X45       GH!  u  pgUR                  S5      nUR                  S5      n	U	c  UR                  S5      n	Uc  SO
[        U5      n
U	b  U
[        U	5      -  n
[        UR                  5       5      [        [        UR                  5       5      SU
* -  S9:X  d  M  US UR                  5       U-    UR                  5       -   X'R                  5       U-   S  -   nXVR                  5       UR                  5       -
  UR                  5       UR                  5       -
  -
  -  nGM$     U$ )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  M_init_checker_class.<locals>.LiteralsOutputChecker._remove_unwanted_precision  sT   11$78E0056D5zSY&
FE(*+''**=*+''+*># ww{3H!)!1As8}	'X.I#veAGGI.>B
N'SS
 0aggi&01AGGI=EEGfDTDV@WW  eeg	1QUUWqwwy5HIIF )  JrJ   rN   )r   r   r   r   compileUNICODEr  r  VERBOSEr  rD   r   r   r  r  r   r   )r   r  s   @rH   LiteralsOutputCheckerr    s    
 !jj)CRZZPJJ'A2::NZZ& JJ)

.	@S 	@s 	@ 	@ 	@ 	@6	3 	S 	S 	 	rJ   r  )r   r  r   r(   )r   r(   r  r  s      @rH   _init_checker_classr    s$    1O 6 Ob ! rJ   c                  8    [         c
  [        5       q [        5       $ )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                  .    SSK n U R                  " S5      $ )z+Register and return the ALLOW_UNICODE flag.r   Nr?  r   register_optionflagrE  s    rH   rB  rB  1  s    &&77rJ   c                  .    SSK n U R                  " S5      $ )z)Register and return the ALLOW_BYTES flag.r   Nr@  r  rE  s    rH   rC  rC  8  s    &&}55rJ   c                  .    SSK n U R                  " S5      $ )z$Register and return the NUMBER flag.r   NrA  r  rE  s    rH   rD  rD  ?  s    &&x00rJ   keyc           
          SSK n[        UR                  [        UR                  [
        UR                  [        UR                  [        S0U    $ )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  sN      	$W%9%9#W%9%9#W%9%90'2S2S"A 
 rJ   rv   )scopec                      [        5       $ )z_Fixture that returns a :py:class:`dict` that will be injected into the
namespace of ipdoctests.)r   rN   rJ   rH   r   r   W  s     6MrJ   r4  r   )r   r   r+   N)r+   r(   )ir   r   r   r  r   r  r  r"  r   r}  
contextlibr   pathlibr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r6  _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   r7  r  re   rh   r   r[   r^   r\   r|   r|  r   r   r   Itemr   rD   rF  rM  rQ  ModulerS   r   objectrr  r  rR   r   r  r  rB  rC  rD  r  fixturer   rN   rJ   rH   <module>r     sX   =  
  	  
    %                  , / + & ' ! , + # - & ' % /# % % % +? ( ,  :>x567 >/V / /d e:;<" v$Q'(1,'M11 
%>?	@1 L1At A A9& 9 9i 9D 9&d &t &
(l 
(!i !3D!23 3n 37" $	./d^  	
 (r%FKK r%j$sCx.  2K 2Kj=F t  %),<"= % %:bKfmm bKJ- N  V!T":; V!r(8 86s 61# 1C C " i T#s(^  !rJ   