
    Xheu                        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mZmZmZmZmZmZmZmZmZmZmZmZ ddlZddlmZ ddlm Z m!Z!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l3m4Z4m5Z5 ddl6m7Z7 ddl8m9Z9 er
ddl:Z:ddl;m<Z< dZ=dZ>dZ?dZ@dZAe=e>e?e@eAfZBdaCdaDeed      eEd<    eFej                  j                  d      D  cg c]
  }  eI|        c}       ZJde*ddfdZKdRd ZLd!ed"e0deed#      fd$ZMeJd   d%k  reMZNd"e0deed#      fd&ZMe5ZOd' Z5d(edePfd)ZQd*e(d(ed"e0dePfd+ZRd(edePfd,ZS G d- d.e"      ZT G d/ d0eU      ZVded1   fd2ZW	 	 	 	 dSd3ed   d4eeP   d5eId6ePdd1f
d7ZX G d8 d9ej                        ZZdee[eIf   fd:Z\d; Z]d< Z^ G d= d>ej                        Z`dTd?Zad@ebdePfdAZcededB   fdC       Zd G dD dEej                        ZedFeZde-fdGZfded   fdHZgdUdIZhdeIfdJZideIfdKZjdeIfdLZkdMe[deIfdNZl ej                  dOP      dee[ef   fdQ       Zny# e.$ r
 ddl+m-Z- Y w xY wc c} w )Vz6Discover and run ipdoctests in modules and test files.    N)contextmanager)Path)TYPE_CHECKINGAnyCallableDict	GeneratorIterableListOptionalPatternSequenceTupleTypeUnion)outcomes)ExceptionInfoReprFileLocationTerminalRepr)TerminalWritersafe_getattr)Config)Parser)
TopRequest)FixtureRequest)	Collector)OutcomeException)
fnmatch_eximport_path)approx)PytestWarning   IPDoctestOutputCheckernonecdiffndiffudiffonly_first_failurer%   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)r4   collectz--ipdoctest-modules
store_trueFz!run ipdoctests in all .py modulesipdoctestmodules)actionr4   helpdestz--ipdoctest-reportr)   z;choose another output format for diffs on ipdoctest failureipdoctestreport)r3   r4   r:   choicesr;   z--ipdoctest-globappendpatz4ipdoctests file matching pattern, default: test*.txtipdoctestglob)r9   r4   metavarr:   r;   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     [/var/www/html/myenv/lib/python3.12/site-packages/IPython/testing/plugin/pytest_ipdoctest.pypytest_addoptionrL   P   s    
MM%	   MMA7   OOI&E	OO0   
OOYYJ&   
OOC   
OO*,-   
OO)M,      c                      d a y N)RUNNER_CLASS rM   rK   pytest_unconfigurerR      s	     LrM   	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optionr8   any_is_setup_py_is_main_pyrU   from_parent_is_ipdoctestrV   )rS   rT   rZ   modtxts        rK   pytest_collect_filerd      s     ]]F5 ==))#)$k)&<=3
 $3#>#>vI#>#VCJ  
vy&	1!2!>!>vI!>!V
rM      c                 ,    t        t        |       |      S rO   )_collect_filer   )rY   rT   s     rK   rd   rd      s     T$Z00rM   c                 R    dd l }t        |j                  j                  |             S )Nr   )py.path_import_pathrY   local)rY   rootpys      rK   r    r       s    BGGMM$/00rM   rY   c                 V    | j                   dk7  ry| j                         }d|v xs d|v S )Nzsetup.pyFs
   setuptoolss	   distutils)name
read_bytes)rY   contentss     rK   r^   r^      s2    yyJ HH$@(@@rM   rZ   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rO   )r   ).0globrY   s     rK   	<genexpr>z _is_ipdoctest.<locals>.<genexpr>   s     8$z$%8s   )r[   session
isinitpath	getoptionr]   )rZ   rY   rT   globss    `  rK   ra   ra      sL    {{&&6>>+D+DT+J_->+E8%888rM   c                      | j                   dk(  S )Nz__main__.py)ro   rX   s    rK   r_   r_      s    99%%rM   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 rO   )r~   )selfr~   s     rK   __init__zReprFailDoctest.__init__   s     #5rM   twc                 ~    | j                   D ].  \  }}|D ]  }|j                  |        |j                  |       0 y rO   )r~   line
toterminal)r   r   reprlocationlinesr   s        rK   r   zReprFailDoctest.toterminal   sD    #'#:#: 	(L% ##B'	(rM   )
__name__
__module____qualname__r   r   r   rG   r   r   r   rQ   rM   rK   r}   r}      s>    5"*51A8C=1P+Q"R5	5
(^ ( (rM   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 rO   )superr   r   )r   r   	__class__s     rK   r   z MultipleDoctestFailures.__init__   s     rM   )r   r   r   r   r   __classcell__r   s   @rK   r   r      s!    !*B!C ! ! !rM   r   IPDocTestRunnerc                  6    dd l ddlm}   G fdd|       }|S )Nr   r#   )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        rK   r   z8_init_runner_class.<locals>.PytestDoctestRunner.__init__   s!     GWg;W':D$rM   testdoctest.DocTestexamplezdoctest.Examplegotc                 l     j                   |||      }| j                  r|j                  |       y |rO   )DocTestFailurer   r>   )r   outr   r   r   failuredoctests         rK   report_failurez>_init_runner_class.<locals>.PytestDoctestRunner.report_failure   s5     -g,,T7C@G''

7#rM   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         rK   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#rM   NNr   T)r   r   r   __doc__r   boolintr   rG   r   r   r   BaseExceptiontypesTracebackTyper   r   )r   r   s   @rK   PytestDoctestRunnerr      s    	 ;?&* (,	;67	; d^	; 		;
 "&	; 	;	 $	 '		
 	 		 $	 '		
 D/@S@SST	 	 	rM   r   )r   	ipdoctestr   )r   r   r   s     @rK   _init_runner_classr      s    *-o -^ rM   r   r   r   r   c                 @    t         
t               a t        | |||      S )Nr   r   r   r   )rP   r   r   s       rK   _get_runnerr     s-     )+ /	 rM   c                       e Zd ZU eeef   ed<   	 	 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d   dk  red
efd       Z xZS  xZS )IPDoctestItem_user_ns_origNro   rT   z)Union[IPDoctestTextfile, IPDoctestModule]runnerr   dtestr   r.   c                 l    t         |   ||       || _        || _        d | _        d | _        i | _        y rO   )r   r   r   r   objfixture_requestr   )r   ro   rT   r   r   r   s        rK   r   zIPDoctestItem.__init__  s9     	v&
9=rM   c                *    t         |   ||||      S )zThe public named constructor.)ro   rT   r   r   )r   r`   )clsrT   ro   r   r   r   s        rK   r`   zIPDoctestItem.from_parent*  s     w"VFRW"XXrM   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itemsrz   updater   r   r   examplesr   _ipuser_nspopbuiltins)r   rz   ro   valuer   s        rK   setupzIPDoctestItem.setup7  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+#&;;

  = "rM   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   rz   r   r   clearr   r   )r   r   s     rK   teardownzIPDoctestItem.teardownP  sp    ( djj))!,i8!DJJKKKKt112"

 rM   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        rK   runtestzIPDoctestItem.runtest\  s   zz%%%{{&&&4::&11313  '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systemrZ   pluginmanager	getpluginsuspend_global_captureread_global_capturesysstdoutwritestderr)r   capmanr   errs       rK   r   z2IPDoctestItem._disable_output_capturing_for_darwinz  s~    ??(**445EF))d)3113HCJJS!JJS!	 rM   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#   r<   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linenor3   r   r   _get_checker_get_report_choicerZ   ry   	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                       rK   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   rY   r  ro   r   s    rK   
reportinfozIPDoctestItem.reportinfo  s7    zz%%%yy$**++-=		-IIIrM   r   re   c                 ,    t        | j                        S rO   r   r   r  s    rK   rY   zIPDoctestItem.path      $$rM   )NNr.   N)r   r   r   r   rG   r   __annotations__r   r   classmethodr`   r   r   r   r   r   r   r   r   r  r   r   r  pytest_versionpropertyr   rY   r   r   s   @rK   r   r     s,   S>! /3-1   <  *+	 
 )*  
  
Y;
Y 	
Y
 "
Y !
Y 
Y/2
!4<	">3}->3 
sL 	!>3@JE%(:C(?"@(3-QT"TU J a1		%$ 	% 
	% rM   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_WHITESPACEr2   IGNORE_EXCEPTION_DETAILCOMPARISON_FLAGSALLOW_UNICODEALLOW_BYTESNUMBER)r   r   r%  r&  r'  r2   r(  r)  _get_allow_unicode_flag_get_allow_bytes_flag_get_number_flagr   s    rK   _get_flag_lookupr1    sZ    &==%;;$99!! ' ? ? 11-/)+!
 
rM   c                 r    | j                   j                  d      }t               }d}|D ]
  }|||   z  } |S )Nr0   r   )rZ   getinir1  )rT   optionflags_strflag_lookup_tableflag_accflags        rK   get_optionflagsr8    sI    mm**+BCO(*H ,%d++,OrM   c                 R    | j                  d      }|r| j                  d      rd}|S )NrC   usepdbF)getvalue)rZ   r   s     rK   _get_continue_on_failurer<    s/     //*IJ ??8$"'rM   c                        e Zd ZdZdee   fdZe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 )
rV   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#   )IPDocTestParserr5   r   __main__Fr   r   r   r   ro   r   r   )r   r   r?  rZ   r3  rY   	read_textrG   ro   r8  r   r  r<  get_doctestr   r   r`   )r   r   r?  encodingtextr  ro   rz   r   r   r-   r   s               rK   r6   zIPDoctestTextfile.collect  s     . ;;%%&:;yy""8,tyy>yy~~Z(%d+# N 8 E	
 !"!!$tXqA==++499V4 ,   s   C4C6r   re   c                 ,    t        | j                        S rO   r  r  s    rK   rY   zIPDoctestTextfile.path  r  rM   r   rY   rY   c                j    |dd l }|j                  j                  |      }t        |   d||d|S Nr   )rT   r   rQ   ri   rY   rk   r   r`   r   rT   r   rY   kwrm   r   s         rK   r`   zIPDoctestTextfile.from_parent  :     t,7&JfVJrJJrM   )r   r   r   r   r
   r   r6   r"  r#  r   rY   r!  r   r`   r   r   s   @rK   rV   rV     ss    
C-0 8 a1		%$ 	% 
	% 

 #'	K
 4.	K 
	K rM   rV   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)rt   r  r   s     rK   rv   z%_check_all_skipped.<locals>.<genexpr>.  s$     PQaiimmGLL%8Ps   03z%all docstests skipped by +SKIP option)r   allr   pytestskip)r   all_skippedr   s     @rK   r   r   )  s1     P$--PPK;< rM   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    rK   
_is_mockedrZ  3  s     	SMtT	rM   )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)Nr\  c                 .    t        |       xs        S rO   )rZ  )r   _stopr^  s    rK   <lambda>zF_patch_unwrap_mock_aware.<locals>._mock_aware_unwrap.<locals>.<lambda>I  s    jo6Tt rM   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)rZ  	Exceptionwarningswarnr"   )r^  r]  era  real_unwraps   `  @rK   _mock_aware_unwrapz4_patch_unwrap_mock_aware.<locals>._mock_aware_unwrapB  si    	|tz1"4j99Et*TUU 	MM GHO 	 	s   - - 	A"AA)inspectunwrapr   r   r   )rh  rg  s    @rK   _patch_unwrap_mock_awarerk  <  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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 )
rU   r.   c              #   >  K   dd l }ddlm}m}  G d d|      }| j                  j
                  dk(  rt        d   dk  rJ| j                  j                  j                  | j                  | j                  j                  d            }nd	| j                  j                  i}t        d
k\  rd|d<    | j                  j                  j                  | j                  | j                  j                  d      fi |}n=	 d| j                  j                  i}t        d
k\  rd|d<   t        | j                  fi |} | |             }t#        |       }t%        d|t'               t)        | j                              }	|j+                  |j,                        D ]4  }
|
j.                  st0        j3                  | |
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   ri  rj  r   _find_lineno)r   r   source_linesr   s      rK   rt  zDIPDoctestModule.collect.<locals>.MockAwareDocTestFinder._find_linenof  sO     c8,!#vs3C3.!..-C w+  rM   c           
          t        |      ry t               5  t        |   |||||||       d d d        y # 1 sw Y   y xY wrO   )rZ  rk  r   _find)	r   testsr   ro   moduleru  rz   seenr   s	           rK   rw  z=IPDoctestModule.collect.<locals>.MockAwareDocTestFinder._findz  sE     c?-/ GMsD&,t  s	   7A r  )r   r   r   r   rt  rw  r   r   s   @rK   MockAwareDocTestFinderrp  _  s    (		 	rM   r{  zconftest.pyre   
importmoderootpath)   r#   Fconsider_namespace_packagesrl   rB   zunable to import module %r)r-   rA  rB  )r   r   rn  r?  rY   ro   r"  rZ   r   _importconftestry   r}  r    ImportErrorr;  rU  rV  r8  r   r  r<  findr   r   r   r`   )r   r   rn  r?  r{  ry  kwargsfinderr   r   r   s              rK   r6   zIPDoctestModule.collect[  s    =$	] $	L 99>>]*a 1$22BBIIKK)),7
 %dkk&:&:;!V+<AF89B22BBIIKK)),7 	 $++"6"67!V+<AF89$TYY9&9 (/@A%d+# N 8 E	
 KK8 	D}}#//tyyt 0  	  ;;''(HIKK <tyy HI Js2   C9H<<G 8A.H'(HAHHHHr   re   c                 ,    t        | j                        S rO   r  r  s    rK   rY   zIPDoctestModule.path  r  rM   NrH  rY   c                j    |dd l }|j                  j                  |      }t        |   d||d|S rJ  rK  rL  s         rK   r`   zIPDoctestModule.from_parent  rN  rM   )r   r   r   r
   r   r6   r"  r#  r   rY   r!  r   r`   r   r   s   @rK   rU   rU   Z  sq    R-0 Rh a1		%$ 	% 
	% 

 #'	K
 4.	K 
	K rM   rU   doctest_itemc                     d	d}i | _         | j                  j                  }| |dd}t        dk  rd|d<    |j                  d
i || _        t        | d      }t        dk  r|j                          |S )zIUsed by IPDoctestTextfile and IPDoctestItem to setup fixture information.Nc                       y rO   rQ   rQ   rM   rK   r^  z_setup_fixtures.<locals>.func  s    rM   )noder^  r   )r~  r   FfuncargsT)	_ispytestr  rQ   )r  rw   _fixturemanagerr"  getfixtureinfo_fixtureinfor   _fillfixtures)r  r^  fmr  r   s        rK   r   r     s     L				-	-B"D>F"z 1 1 1 !
!L %\TBO%%'rM   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regexrc   r.   c                 *    j                  | d|      S )Nz\1\2)sub)r  rc   res     rK   remove_prefixeszX_init_checker_class.<locals>.LiteralsOutputChecker.check_output.<locals>.remove_prefixes  s    vveWc22rM   )
r   check_outputr-  r.  r/  r   rG   _unicode_literal_re_bytes_literal_re_remove_unwanted_precision)
r   r  r   r   allow_unicodeallow_bytesallow_numberr  r   r  s
           rK   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;??rM   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ziprJ   r   floatr!   startend)r   r  r   wantsgotsoffsetwgr  exponent	precisions              rK   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  JrM   )r   r   r   compileUNICODEr  r  VERBOSEr  rG   r   r   r  r  r   )r   r  s   @rK   LiteralsOutputCheckerr    s    
 !jj)CRZZPJJ'A2::NZZ& JJ)

.	@S 	@s 	@ 	@ 	@6	3 	S 	S 	rM   r  )r   r  r   r%   )r   r%   r  r  s      @rK   _init_checker_classr    s$    1O 6 Ob ! rM   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  rQ   rM   rK   r  r  2  s     +-?rM   c                  .    ddl }  | j                  d      S )z+Register and return the ALLOW_UNICODE flag.r   Nr*  r   register_optionflagr0  s    rK   r-  r-  F  s    &7&&77rM   c                  .    ddl }  | j                  d      S )z)Register and return the ALLOW_BYTES flag.r   Nr+  r  r0  s    rK   r.  r.  M  s    &7&&}55rM   c                  .    ddl }  | j                  d      S )z$Register and return the NUMBER flag.r   Nr,  r  r0  s    rK   r/  r/  T  s    &7&&x00rM   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     rK   r  r  [  sN      	$W%9%9#W%9%9#W%9%90'2S2S"A 
 rM   rw   )scopec                      t               S )zcFixture that returns a :py:class:`dict` that will be injected into the
    namespace of ipdoctests.)r   rQ   rM   rK   r   r   l  s     6MrM   r  r   )r   r   r.   N)r.   r%   )or   r   r   ri  r   r   r   r  r   rd  
contextlibr   pathlibr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   rU  _pytestr   _pytest._code.coder   r   r   _pytest._ior   _pytest.compatr   _pytest.configr   _pytest.config.argparsingr   _pytest.fixturesr   r   r  _pytest.nodesr   _pytest.outcomesr   _pytest.pathlibr   r    _pytest.python_apir!   _pytest.warning_typesr"   r   r   r%   r  r  r  r  r  rI   rP   r+   r   tuple__version__r  r   r"  rL   rR   rd   rg   rj   r   r^   ra   r_   r}   rc  r   r   r   Itemr   rG   r1  r8  r<  ModulerV   r   objectrZ  rk  rU   r   r  r  r-  r.  r/  r  fixturer   )parts   0rK   <module>r     s   = 
   	  
    %        L L & ' ! ,0= $ - 3 % /1# % % % +? ( ,  :>x567 >f.@.@.F.Fs.KLdD	LM/V / /d e:;<" !q'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^  	
 (u%FKK u%p$sCx.  2K 2Kj=F t  %),<"= % %:hKfmm hKV- N (V!T":; V!r(8 86s 61# 1C C " i T#s(^  !A  0//0@ Ms   ?I 0I II