
    F-Ph{6                       d Z ddlmZ ddlZddlmZ ddlmZ ddlZddlZddl	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mZ ddl m!Z! d2dZ"d3dZ#d4dZ$ G d d           Z% G d! d"          Z& G d# d$          Z'd5d%Z(d5d&Z)d6d-Z*d7d/Z+d8d1Z,dS )9z4Interactive debugging with PDB, the Python Debugger.    )annotationsN)Callable)	Generator)Any)outcomes)ExceptionInfo)CaptureManager)Config)ConftestImportFailure)hookimpl)PytestPluginManager)Parser)
UsageError)Node)
BaseReport)CallInfovaluestrreturntuple[str, str]c                    	 |                      d          \  }}n*# t          $ r}t          j        | d          |d}~ww xY w||fS )z#Validate syntax of --pdbcls option.:z) is not in the format 'modname:classname'N)split
ValueErrorargparseArgumentTypeError)r   modname	classnamees       Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/_pytest/debugging.py_validate_usepdb_clsr!      so    "[[--   (AAA
 
	 Ys    
A=Aparserr   Nonec                    |                      d          }|                    dddd           |                    ddd	t          d
           |                    dddd           d S )Ngeneralz--pdbusepdb
store_truezDStart the interactive Python debugger on errors or KeyboardInterrupt)destactionhelpz--pdbcls
usepdb_clszmodulename:classnamez{Specify a custom interactive Python debugger for use with --pdb.For example: --pdbcls=IPython.terminal.debugger:TerminalPdb)r(   metavartyper*   z--tracetracez(Immediately break when running each test)getgroup	addoptionr!   )r"   groups     r    pytest_addoptionr2   )   s    OOI&&E	OOS	     
OO&!F     
OO7	          configr
   c                   dd l |                     d          r'| j                            t	                      d           |                     d          r'| j                            t                      d           t          j                            j	        t          j
        t          j        f           t          j	        _	        | j        t          _
        | t          _        d	fd}|                     |           d S )
Nr   r.   pdbtracer&   	pdbinvoker   r#   c                 ~    t           j                                        \   _        t           _        t           _        d S N)	pytestPDB_savedpop	set_trace_pluginmanager_config)pdbs   r    finzpytest_configure.<locals>.finR   s3    
   ""		
M$r3   r   r#   )r@   getvaluepluginmanagerregisterPdbTrace	PdbInvoker:   r;   appendr=   r>   r?   add_cleanup)r4   rA   r@   s     @r    pytest_configurerJ   A   s    JJJw >%%hjj*===x   @%%ikk;???		0)2CD   'CM%3II# # # # # # sr3   c                      e Zd ZU dZdZded<   dZded<   g Zded<   d	ZdZ	d
ed<   e
dd            Ze
dd            Ze
dd            Ze
d             Ze
dd            ZdS )r:   z'Pseudo PDB that defers to the real pdb.NzPytestPluginManager | Noner>   zConfig | Noner?   zKlist[tuple[Callable[..., None], PytestPluginManager | None, Config | None]]r;   r   z"tuple[type[Any], type[Any]] | None_wrapped_pdb_clscapmanCaptureManager | Noner   
str | boolc                2    |r|                                 S dS )NF)is_capturing)clsrM   s     r    _is_capturingzpytestPDB._is_capturingg   s!     	)&&(((ur3   c                ^   | j         sdd l}|j        S | j                             d          }| j        r| j        d         |k    r| j        d         S |r|\  }}	 t          |           t          j        |         }|                    d          }t          ||d                   }|dd          D ]}	t          ||	          }nJ# t          $ r2}
d                    ||f          }t          d|d|
           |
d }
~
ww xY wdd l}|j        }|                     ||          }||f| _        |S )Nr   r+      .r   z--pdbcls: could not import z: )r?   r@   PdbrC   rL   
__import__sysmodulesr   getattr	Exceptionjoinr   _get_pdb_wrapper_class)rR   rM   r@   r+   r   r   modpartspdb_clspartexcr   wrapped_clss                r    _import_pdb_clszpytestPDB._import_pdb_clsm   sy   { 	JJJ 7N[)),77
 	+C$8$;z$I$I'** 	!+GY7###k'* ",,!#uQx00!!""I 5 5D%gt44GG5   '9!566 B%BBSBB  JJJgG00&AA *K8s   A)C 
D -C;;D c                <     dd l  G  fdd          }|S )Nr   c                      e Zd ZZdZ fdZ ed          rj        j        e_         fdZ ed          rj        j        e_        exZ	Z
 fdZ ed          rj        j        e_        eZeZ fdZ fd	Z xZS )
:pytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapperFc                    xj         dz  c_         t                                          |          }xj         dz  c_         |S )NrU   )_recursive_debugsuperdo_debugselfargret	__class__rR   s      r    rl   zCpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.do_debug   sG    $$)$$gg&&s++$$)$$
r3   rl   c                V   t                                          |          }j        dk    rŉj        J j                            j                  }|                                 | j        }t          	                    |          }|rP|dk    r|
                    dd           n|
                    dd| d           |J |                                 n|
                    dd           j        J j        j                            j        |            d	| _        |S )
Nr   global>z#PDB continue (IO-capturing resumed)z'PDB continue (IO-capturing resumed for )zPDB continuer4   r@   T)rk   do_continuerj   r?   r4   create_terminal_writerline_pytest_capmanr:   rS   sepresumer>   hookpytest_leave_pdb
_continued)	rn   ro   rp   twrM   	capturingrq   _pytestrR   s	         r    rw   zFpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.do_continue   s5   gg))#..'1,,;222 >>s{KKBGGIII!0F ) 7 7 ? ?I  4$00FF3(MNNNNFF # V) V V V    &111sN333)555"'88QU8VVV"&
r3   rw   c                    t                                          |          }j        dk    rt          j        d           |S )Nr   Quitting debugger)rk   do_quitrj   r   exitrm   s      r    r   zBpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.do_quit   s>     ggooc**'1,,M"5666
r3   r   c                    t                                          ||          }|s)| j        r"| j        r| j                            d           |S )zSuspend on setup().

                Needed after do_continue resumed, and entering another
                breakpoint again.
                Tin_)rk   setupr   rz   suspend_global_capture)rn   ftbrp   rq   s       r    r   z@pytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.setup   s\     ggmmAr** Mt M * M+BBtBLLL
r3   c                H   t                                          ||          \  }}|wt          dt          |          dz
            }|rU||         d         j                            dd          r.|dz  }|r'||         d         j                            dd          .||fS )Nr   rU   __tracebackhide__F)rk   	get_stackmaxlenf_localsget)rn   r   tstackirq   s        r    r   zDpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.get_stack   s     77,,Q22q9As5zzA~..A a 4 8 89Le T T Q  a 4 8 89Le T T axr3   )__name__
__module____qualname__rz   r   rl   hasattr__doc__rw   do_cdo_contr   do_qdo_exitr   r   __classcell__)rq   r   rM   rR   ra   s   @r    PytestPdbWrapperrh      s:       #NJ      ww
++ <#*#3#;       4 ww.. B&-&9&A#((D7      ww	** :")/"9DG                     r3   r   )_pytest.config)rR   ra   rM   r   r   s   ``` @r    r^   z pytestPDB._get_pdb_wrapper_class   sk    T	  T	  T	  T	  T	  T	  T	  T	  T	  T	 w T	  T	  T	 l  r3   c                   ddl }| j        d}n| j                            d          }|r|                    d           | j        r|j                            | j                  }|                                 | j        dk    r|	                    dd          }||
                    d|           no|                     |          }|dk    r|
                    dd	| d
           n9|r|
                    dd	| d| d           n|
                    dd	|             |                     |          di |}	| j        r&| j        j                            | j        |	           |	S )z4Initialize PDB debugging, dropping any IO capturing.r   NcapturemanagerTr   headerrt   rs   zPDB z (IO-capturing turned off)z (IO-capturing turned off for ru   rv    )r   r>   	getpluginsuspendr?   r4   rx   ry   rj   r<   r{   rS   re   r}   pytest_enter_pdb)
rR   methodargskwargsr   rM   r   r   r   _pdbs
             r    	_init_pdbzpytestPDB._init_pdb   s    	%,0FF'112BCCF 	%NNtN$$$; 	566s{CCBGGIII#q((Hd33%FF3'''' # 1 1& 9 9I H,,s$M6$M$M$MNNNN" 5U6UUUUU   
 sO6OO444*s""6**44V44 	S#44CKT4RRRr3   r#   c                    t          j                    j        } | j        dg|R i |}|                    |           dS )zBInvoke debugging via ``Pdb.set_trace``, dropping any IO capturing.r=   N)rY   	_getframef_backr   r=   )rR   r   r   framer   s        r    r=   zpytestPDB.set_trace  sK     &s}[:4:::6::ur3   )rM   rN   r   rO   )rM   rN   rB   )r   r   r   r   r>   __annotations__r?   r;   rj   rL   classmethodrS   re   r^   r   r=   r   r3   r    r:   r:   \   s        1115N5555!G!!!! 	      ;?????   [
 $ $ $ [$L Y  Y  Y  [Y v $ $ [$L    [  r3   r:   c                      e Zd Zdd	ZddZdS )rG   noder   callCallInfo[Any]reportr   r   r#   c                   |j         j                            d          }|rk|                    d           |                                \  }}t
          j                            |           t
          j                            |           |j        J t          |j        j
        t          j                  st          ||j        |           d S d S )Nr   Tr   )r4   rD   r   r   read_global_capturerY   stdoutwriteexcinfo
isinstancer   unittestSkipTest
_enter_pdb)rn   r   r   r   rM   outerrs          r    pytest_exception_interactz#PdbInvoke.pytest_exception_interact   s     *445EFF 	"))d)3331133HCJS!!!JS!!!|'''$,,h.?@@ 	3tT\622222	3 	3r3   r   ExceptionInfo[BaseException]c                B    t          |          }t          |           d S r9   )_postmortem_exc_or_tbpost_mortem)rn   r   	exc_or_tbs      r    pytest_internalerrorzPdbInvoke.pytest_internalerror.  s#    )'22	Ir3   N)r   r   r   r   r   r   r   r#   )r   r   r   r#   )r   r   r   r   r   r   r3   r    rG   rG     s<        3 3 3 3     r3   rG   c                  :    e Zd Z ed          dd            ZdS )rF   T)wrapperr   Generator[None, object, object]c              #  ,   K   t          |           d V S r9   ) wrap_pytest_function_for_tracing)rn   
pyfuncitems     r    pytest_pyfunc_callzPdbTrace.pytest_pyfunc_call4  s      (444r3   N)r   r   )r   r   r   r   r   r   r3   r    rF   rF   3  s@        Xd     r3   rF   c                    t                               d          | j        t          j                  dfd            }|| _        dS )zChange the Python function object of the given Function item by a
    wrapper which actually enters pdb before calling the python function
    itself, effectively leaving the user in the pdb prompt in the first
    statement of the function.runcallr   r#   c                 \    t          j        g| R i |}                    |           d S r9   )	functoolspartialr   )r   r   funcr   testfunctions      r    r   z1wrap_pytest_function_for_tracing.<locals>.wrapperE  s;     ??????Tr3   NrB   )r:   r   objr   wraps)r   r   r   r   s     @@r    r   r   :  sg    
 y))D>L
 _\""      #" JNNNr3   c                \    | j                             d          rt          |            dS dS )zaWrap the given pytestfunct item for tracing support if --trace was given in
    the command line.r.   N)r4   rC   r   )r   s    r    &maybe_wrap_pytest_function_for_tracingr   M  s;     !!'** 5(444445 5r3   r   r   r   r   repr   c                @   | j         j                            d          j        }|                                 | j         j        j        }d|j        fd|j        fd|j	        ffD ]S\  }}||dfv rH|rF|
                    dd|z              |dd          d	k    r
|d d         }|                    |           T|
                    dd
           |                    |           |
                    dd           t          |          }d|_        t          |           |S )Nterminalreporterr   stderrlogallrt   z	captured 
	tracebackzentering PDBT)r4   rD   r   _twry   optionshowcapture	capstdout	capstderrcaplogr{   
toterminalr   	_pdbshownr   )r   r   r   r   r   sectionnamecontent	tb_or_excs           r    r   r   T  s4    
	"	,	,-?	@	@	DBGGIII+$0K 
3=!	3=!	
! 	 	W
 ;...7.FF3k1222rss|t##!#2#,GGGFF3NN2FF3%g..ICM	Jr3   #types.TracebackType | BaseExceptionc                \   ddl m} t          j        dk    }t	          | j        |          r#| j        }|r|j        d         S |j        d         S t	          | j        t                    r | j        j        }|r|S |j	        J |j	        S | j
        J |r| j
        d         S | j
        d         S )Nr   )UnexpectedException)      rU      )doctestr   rY   version_infor   r   exc_infor   cause__traceback___excinfo)r   r   get_excunderlying_excr   s        r    r   r   s  s     ,+++++')G'-!455 # ! 	.!*1--&q))	GM#8	9	9 # # 	L"...""+++ 	'#A&&""r3   r   c                    t                               d          }|                                 |                    d |            |j        rt          j        d           d S d S )Nr   r   )r:   r   resetinteractionquittingr   r   )r   ps     r    r   r     sa    M**AGGIIIMM$	"""z +)*****+ +r3   )r   r   r   r   )r"   r   r   r#   )r4   r
   r   r#   rB   )r   r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r#   )-r   
__future__r   r   collections.abcr   r   r   rY   typestypingr   r   r   r   _pytest._coder   _pytest.capturer	   r   r
   r   r   r   _pytest.config.argparsingr   _pytest.config.exceptionsr   _pytest.nodesr   _pytest.reportsr   _pytest.runnerr   r!   r2   rJ   r:   rG   rF   r   r   r   r   r   r   r3   r    <module>r     s   ; : " " " " " "  $ $ $ $ $ $ % % % % % %     



               ' ' ' ' ' ' * * * * * * ! ! ! ! ! ! 0 0 0 0 0 0 # # # # # # . . . . . . , , , , , , 0 0 0 0 0 0       & & & & & & # # # # # #          0   6@ @ @ @ @ @ @ @F       (          &5 5 5 5   ># # # #>+ + + + + +r3   