
    fs                        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*ZBd^d+ZCd,ed-e.d)eed.      fd/ZD eEej                  j                  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	 	 	 	 d_d?ed&   d@eeJ   dAeEdBeJd)d=f
dCZR G dD dEej                        ZTd)eeUeEf   fdFZVdG ZWdH ZX G dI dJej                        ZZd`dKZ[dLe\d)eJfdMZ]ed)edN   fdO       Z^ G dP dQej                        Z_dReTd)e,fdSZ`d)ed&   fdTZadadUZbd)eEfdVZcd)eEfdWZdd)eEfdXZedYeUd)eEfdZZf ej                  d[\      d)eeUef   fd]       Zhy)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                 ~   | j                  ddddg       | j                  ddd	       | j                  d
      }|j                  ddddd       |j                  dt        j                  ddt
        d       |j                  ddg ddd       |j                  ddddd       |j                  dddd d!       y )"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     b/var/www/cvtools/html/venv/lib/python3.12/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                      d a y N)RUNNER_CLASS rJ   rH   pytest_unconfigurerO   z   s	     LrJ   	file_pathparent)IPDoctestModuleIPDoctestTextfilec                 $   |j                   }| j                  dk(  rO|j                  j                  r8t	        t        |       t        |       f      st        j                  ||       }|S y t        || |      rt        j                  ||       }|S y )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#>#>vI#>#VCJ  
vy&	1!2!>!>vI!>!V
rJ   .   c                 ,    t        t        |       |      S rL   )_collect_filer   )rV   rQ   s     rH   ra   ra      s     T$Z00rJ   c                 R    dd l }t        |j                  j                  |             S )Nr   )py.path_import_pathrV   local)rV   rootpys      rH   r    r       s    BGGMM$/00rJ   rV   c                 V    | j                   dk7  ry| j                         }d|v xs d|v S )Nzsetup.pyFs
   setuptoolss	   distutils)name
read_bytes)rV   contentss     rH   r[   r[      s2    yyJ HH$@(@@rJ   rW   c                     j                   dv r|j                  j                        ry| j                  d      xs dg}t	        fd|D              S )N)z.txtz.rstTr=   z	test*.txtc              3   6   K   | ]  }t        |        y wrL   r   ).0globrV   s     rH   	<genexpr>z _is_ipdoctest.<locals>.<genexpr>   s     8$z$%8s   )rX   session
isinitpath	getoptionrZ   )rW   rV   rQ   globss    `  rH   r^   r^      sL    {{&&6>>+D+DT+J_->+E8%888rJ   c                      | j                   dk(  S )Nz__main__.py)rm   rU   s    rH   r\   r\      s    99%%rJ   c                   B    e Zd Zdeeeee   f      ddfdZdeddfdZ	y)ReprFailDoctestreprlocation_linesr+   Nc                     || _         y rL   )r|   )selfr|   s     rH   __init__zReprFailDoctest.__init__   s     #5rJ   twc                 ~    | j                   D ].  \  }}|D ]  }|j                  |        |j                  |       0 y rL   )r|   line
toterminal)r~   r   reprlocationlinesr   s        rH   r   zReprFailDoctest.toterminal   sD    #'#:#: 	(L% ##B'	(rJ   )
__name__
__module____qualname__r   r   r   rD   r   r   r   rN   rJ   rH   r{   r{      s>    5"*51A8C=1P+Q"R5	5
(^ ( (rJ   r{   c                   .     e Zd Zded   ddf fdZ xZS )MultipleDoctestFailuresfailureszdoctest.DocTestFailurer+   Nc                 0    t         |           || _        y 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      s!    !*B!C ! ! !rJ   r   IPDocTestRunnerc                  6    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.
        Ncheckerr(   verboseoptionflagscontinue_on_failurer+   c                 8    t         |   |||       || _        y )N)r   r   r   )r   r   r   )r~   r   r   r   r   r   s        rH   r   z8_init_runner_class.<locals>.PytestDoctestRunner.__init__   s!     GWg;W':D$rJ   testdoctest.DocTestexamplezdoctest.Examplegotc                 l     j                   |||      }| j                  r|j                  |       y |rL   )DocTestFailurer   r;   )r~   outr   r   r   failuredoctests         rH   report_failurez>_init_runner_class.<locals>.PytestDoctestRunner.report_failure   s5     -g,,T7C@G''

7#rJ   exc_infoc                     t        |d   t              r|d   t        |d   t        j                        rt	        j
                  d        j                  |||      }| j                  r|j                  |       y |)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   sm     (1+'78qk!(1+s{{3121g11$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      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                 @    t         
t               a t        | |||      S )Nr   r   r   r   )rM   r   r   s       rH   _get_runnerr      s-     )+ /	 rJ   c                   D    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*                  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 | _        y rL   )r   r   r   r   objfixture_request)r~   rm   rQ   r   r   r   s        rH   r   zIPDoctestItem.__init__  s1     	v&
9=rJ   c                *    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     w"VFRW"XXrJ   c                    | j                   ot        |       | _        t        | j                  j                        }| j                  j	                  d      j                         D ]
  \  }}|||<    | j                   j                  j                  |       ddlm	} t        | j                   j                  d   |      ri | _        | j                  j                  t        j                         t        j                  j                  | j                   j                         t        j                  j                  dd        t         t        j                  d<   t        j                  | j                   _        y y y )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#8D D$8$8$H$HIE#33CC% eg$e $d$ JJ##E*,$**--a0)< &("""))#++6""4::#3#34 T*.6N+#&;;

  = "rJ   c                 R   ddl m} t        | j                  j                  d   |      rZi | j                  _        t        j                  j                          t        j                  j                  | j                         | `
| j                  j
                  j                          y )Nr   r   r   )r   r   r   r   r   rx   r   r   clearr   r   )r~   r   s     rH   teardownzIPDoctestItem.teardownE  sp    ( djj))!,i8!DJJKKKKt112"

 rJ   c                    | j                   J | j                  J t        | j                          | j                          g }t	        t
        d      }t        t
        dd       }t        j                         }t        j                  | j                  j                         	 | j                  j                  | j                   |d       t        j                  |       |rt        t
        d|       n!t	        t
        d      rt        t
        d       	 |rt        |      y # t        j                  |       |rt        t
        d|       w t	        t
        d      rt        t
        d       w w xY w)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   zz%%%{{&&&4::&11335  'x5$+Hc4$@!
 
$$%		' KKOODJJH%OHHHV##'@A3'#&)(33  HHV##'@A3'#& (s   #(D# #AE/c                 J   t        j                         dk7  ry| j                  j                  j	                  d      }|rd|j                  d       |j                         \  }}t        j                  j                  |       t        j                  j                  |       yy)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~    ??(**445EF))d)3113HCJJS!JJS!	 rJ   excinfoc                    dd l }d }t        |j                  |j                  |j                  f      r|j                  g}n0t        |j                  t
              r|j                  j                  }|t        | !  |      S g }|D ]X  }|j                  }|j                  }|j                  }|j                  d }	n|j                  |j                  z   dz   }	t        |      j                  }
t        ||	|
      }t!               }t#        | j$                  j'                  d            }|	|j                  j(                  J |j                  j(                  j+                  d      }|j                  J t-        |      D cg c]  \  }}d||j                  z   dz   |fz   }}}|t/        |j                  dz
  d      |j                  dz    }n=dg}d}|j0                  j+                         D ]  }|j3                  d	| d
|        d} t        ||j                        r0||j5                  ||j6                  |      j9                  d      z  }nwt;        j<                  |j>                        }|dtA        |j                        z  gz  }|tC        jD                  |j>                   D cg c]  }|jG                  d       c}z  }|j3                  ||f       [ tI        |      S c c}}w c c}w )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   rw   	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  zIPDoctestItem.repr_failure{  s    	  	 MMG22G4O4OP
  H'>?}}--H7'00 )	=GooG<<D}}H{{"w~~597m,,G+HfgFL"nG.t{{/D/DEV/WXM!||--999..99%@{{...GPQVGW=CaIT[[1!4a 88  c'..1"4a87>>A;MN V #NN557 #DLL4xq!78"F# '7#9#9:22W[[-%+ !. ; ;G<L<L M4tM<O<O7PPQQ+4+E+EwGWGW+X&'AGGDM  %%|U&;<S)	=T 1221(s   !K.0K4zos.PathLike[str]c                 ~    | j                   J | j                  | j                   j                  d| j                  z  fS )Nz[ipdoctest] %s)r   rV   r  rm   r~   s    rH   
reportinfozIPDoctestItem.reportinfo  s7    zz%%%yy$**++-=		-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     s4   
 /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                      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_lookupr0    sZ    &==%;;$99!! ' ? ? 11-/)+!
 
rJ   c                 r    | j                   j                  d      }t               }d}|D ]
  }|||   z  } |S )Nr-   r   )rW   getinir0  )rQ   optionflags_strflag_lookup_tableflag_accflags        rH   get_optionflagsr7    sI    mm**+BCO(*H ,%d++,OrJ   c                 R    | j                  d      }|r| j                  d      rd}|S )Nr@   usepdbF)getvalue)rW   r   s     rH   _get_continue_on_failurer;    s/     //*IJ ??8$"'rJ   c                        e Zd ZdZdee   fdZ eej                  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                  j	                  d      }| j
                  j                  |      }t        | j
                        }| j
                  j                  }ddi}t        |       }t        d|t               t        | j                              }	 |       }
|
j                  ||||d      }|j                  r&t        j!                  | |j                  |	|	       y y w)
Nr   r   )IPDocTestParserr2   r   __main__Fr   r   r   r   rm   r   r   )r   r   r>  rW   r2  rV   	read_textrD   rm   r7  r   r  r;  get_doctestr   r   r]   )r~   r   r>  encodingtextr  rm   rx   r   r   r*   r   s               rH   r3   zIPDoctestTextfile.collect  s     . ;;%%&:;yy""8,tyy>yy~~Z(%d+# N 8 E	
 !"!!$tXqA==++499V4 ,   s   C4C6rb   r   rc   c                 ,    t        | j                        S rL   r  r  s    rH   rV   zIPDoctestTextfile.path
  r  rJ   r   rV   rV   c                j    |dd l }|j                  j                  |      }t        |   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  :     t,7&JfVJr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 6##C(+,q0		%$ 	% 
	% 

 #'	K
 4.	K 
	K 1rJ   rS   c                 z    ddl t        fd| j                  D              }|rt        j                  d       yy)zVRaise pytest.skip() if all examples in the given DocTest have the SKIP
    option set.r   Nc              3   j   K   | ]*  }|j                   j                  j                  d        , yw)FN)optionsgetSKIP)rr   r  r   s     rH   rt   z%_check_all_skipped.<locals>.<genexpr>#  s$     PQaiimmGLL%8Ps   03z%all docstests skipped by +SKIP option)r   allr   r   skip)r   all_skippedr   s     @rH   r   r     s1     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_mockedrX  (  s     	SMt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 t         _        y# t         _        w xY w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)NrZ  c                 .    t        |       xs        S rL   )rX  )r   _stopr\  s    rH   <lambda>zF_patch_unwrap_mock_aware.<locals>._mock_aware_unwrap.<locals>.<lambda>>  s    jo6T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)rX  	Exceptionwarningswarnr"   )r\  r[  er_  real_unwraps   `  @rH   _mock_aware_unwrapz4_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   )rf  re  s    @rH   _patch_unwrap_mock_awareri  1  sn      ..K MQsCx +3HcUCZ4H+I	" (GN%$s   AA9A) A9)A66A9c                        e Zd Zdee   fdZ eej                  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                  j                  d      d         dk  rJ| j                  j                  j                  | j                  | j                  j                  d	            }n| j                  j                  j                  | j                  | j                  j                  d	      | j                  j                  
      }n,	 t        | j                  | j                  j                        } | |             }t'        |       }t)        d|t+               t-        | j                              }|j/                  |j0                        D ]4  }	|	j2                  st4        j7                  | |	j
                  ||	       6 y # t         $ rB | j                  j#                  d      r#t        j$                  d| j                  z         n Y w xY ww)Nr   r   )DocTestFinderr>  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   rg  rh  r   _find_lineno)r~   r   source_linesr   s      rH   rr  zDIPDoctestModule.collect.<locals>.MockAwareDocTestFinder._find_lineno[  sO     c8,!#vs3C3.!..-C w+  rJ   c           
          t        |      ry t               5  t        |   |||||||       d d d        y # 1 sw Y   y xY wrL   )rX  ri  r   _find)	r~   testsr   rm   modulers  rx   seenr   s	           rH   ru  z=IPDoctestModule.collect.<locals>.MockAwareDocTestFinder._findo  sE     c?-/ GMsD&,t  s	   7A r  )r   r   r   r   rr  ru  r   r   s   @rH   MockAwareDocTestFinderrn  T  s    (		 	rJ   ry  zconftest.pyrb   rc   
importmode)rootpath)rj   r?   zunable to import module %r)r*   Fr@  rA  )r   r   rl  r>  rV   rm   r   r   r!  r  rW   r   _importconftestrw   r{  r    ImportErrorr:  rT  r7  r   r  r;  findr   r   r   r]   )
r~   r   rl  r>  ry  rw  finderr   r   r   s
             rH   r3   z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8 	D}}#//tyyt 0  	  ;;''(HIKK <tyy HI Js2   D	H+G 7A.H&(HAHHHHrb   r   rc   c                 ,    t        | j                        S rL   r  r  s    rH   rV   zIPDoctestModule.path  r  rJ   NrG  rV   c                j    |dd l }|j                  j                  |      }t        |   d||d|S rI  rJ  rK  s         rH   r]   zIPDoctestModule.from_parent  rM  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\ 6##C(+,q0		%$ 	% 
	% 

 #'	K
 4.	K 
	K 1rJ   rR   doctest_itemc                     dd}i | _         | j                  j                  }|j                  | |dd      | _        t        | d      }|j                          |S )zIUsed by IPDoctestTextfile and IPDoctestItem to setup fixture information.Nc                       y 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     sc     L				-	-B " 1 1$ !2 !L %\TBO!!#rJ   c                  >    dd l } dd lddlm}  G fdd|      }|S )Nr   r   )r(   c                        e Zd ZW j                  dW j                        ZW j                  dW j                        ZW j                  dW 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y|t               z  }|t               z  }|t	               z  }|s|s|sydt
        t           dt        dt        f	fd}|r& || j                  |      } || j                  |      }|r& || j                  |      } || j                  |      }|r| j                  ||      }t         |   |||      S )NTFregexr`   r+   c                 *    j                  | 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2rJ   )
r   check_outputr,  r-  r.  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  s    w#D#{;'*A*CCM%(=(??K&)9);;L \3ws| 3# 3# 3 &t'?'?F%d&>&>D&t'='=tD%d&<&<cB55dC@7'c;??rJ   c                 .   t        | j                  j                  |            }t        | j                  j                  |            }t        |      t        |      k7  r|S d}t	        ||      D ]!  \  }}|j                  d      }|j                  d      }	|	|j                  d      }	|dn
t        |      }
|	|
t        |	      z  }
t        |j                               t        t        |j                               d|
 z        k(  s|d |j                         |z    |j                         z   ||j                         |z   d  z   }||j                         |j                         z
  |j                         |j                         z
  z
  z  }$ |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  sc   11$78E0056D5zSY&
FE4( J1*+''**=*+''+*># ww{3H!)!1As8}	'X.I#veAGGI.>B
N'SS
 0aggi&01AGGI=AEEGfDTDV@WW  aeeg	1QUUWqwwy5HIIFJ  JrJ   )r   r   r   compileUNICODEr  r  VERBOSEr  rD   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                  6    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_optionflagr/  s    rH   r,  r,  1  s    &7&&77rJ   c                  .    ddl }  | j                  d      S )z)Register and return the ALLOW_BYTES flag.r   Nr*  r  r/  s    rH   r-  r-  8  s    &7&&}55rJ   c                  .    ddl }  | j                  d      S )z$Register and return the NUMBER flag.r   Nr+  r  r/  s    rH   r.  r.  ?  s    &7&&x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  sN      	$W%9%9#W%9%9#W%9%90'2S2S"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     6MrJ   r  r   )r   r   r+   N)r+   r(   )ir   r   r   rg  r   r   r   r  r   rb  
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{   ra  r   r   r   Itemr   rD   r0  r7  r;  ModulerS   r   objectrX  ri  rR   r   r  r  r,  r-  r.  r  fixturer   rN   rJ   rH   <module>r     sZ   =  
  	  
    %                  , / + & ' ! , + # - & ' % /# % % % +? ( ,  :>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   