o
    #if4                     @   s  d 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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  erddl!m"Z" ddl#m$Z$ de%dee%e%f fddZ&deddfddZ'deddfd d!Z(G d"d# d#Z)G d$d% d%Z*G d&d' d'Z+d(d) Z,d*d+ Z-d,ed-ee. d.e de fd/d0Z/d-ee. dej0fd1d2Z1d3ej0ddfd4d5Z2dS )6z4Interactive debugging with PDB, the Python Debugger.    N)Any)Callable)	Generator)List)Optional)Tuple)Type)TYPE_CHECKING)Union)outcomes)ExceptionInfo)Config)ConftestImportFailure)hookimpl)PytestPluginManager)Parser)
UsageError)Node)
BaseReport)CaptureManager)CallInfovaluereturnc              
   C   sD   z|  d\}}W ||fS  ty! } z	t| d|d}~ww )z#Validate syntax of --pdbcls option.:z) is not in the format 'modname:classname'N)split
ValueErrorargparseArgumentTypeError)r   modname	classnamee r!   J/var/www/html/corbot_env/lib/python3.10/site-packages/_pytest/debugging.py_validate_usepdb_cls$   s   r#   parserc                 C   sF   |  d}|jddddd |jddd	td
d |j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$   groupr!   r!   r"   pytest_addoption/   s(   

r2   configc                    s   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}| | d S )
Nr   r.   pdbtracer&   	pdbinvoker   c                      s   t j \ _t _t _d S N)	pytestPDB_savedpop	set_trace_pluginmanager_configr!   pdbr!   r"   finX   s
   zpytest_configure.<locals>.finr   N)r>   getvaluepluginmanagerregisterPdbTrace	PdbInvoker7   r8   appendr:   r;   r<   add_cleanup)r3   r?   r!   r=   r"   pytest_configureG   s   

rH   c                   @   s   e Zd ZU dZdZee ed< dZee	 ed< g Z
eeed ee ee	 f  ed< dZdZeeee ee f  ed< ed	ed
 deeef fddZed	ed
 fddZed	ed
 fddZedd ZedddZdS )r7   z'Pseudo PDB that defers to the real pdb.Nr;   r<   ).Nr8   r   _wrapped_pdb_clscapmanr   r   c                 C   s   |r|  S dS )NF)is_capturing)clsrJ   r!   r!   r"   _is_capturingm   s   zpytestPDB._is_capturingc              
   C   s   | j s
dd l}|jS | j d}| jr| jd |kr| jd S |ri|\}}z%t| tj| }|d}t	||d }|dd  D ]}	t	||	}qAW n% t
yh }
 zd||f}td|d|
 |
d }
~
ww dd l}|j}| ||}||f| _|S )Nr   r+      .r   z--pdbcls: could not import z: )r<   r>   PdbrA   rI   
__import__sysmodulesr   getattr	Exceptionjoinr   _get_pdb_wrapper_class)rL   rJ   r>   r+   r   r   modpartspdb_clspartexcr   wrapped_clsr!   r!   r"   _import_pdb_clss   s<   



zpytestPDB._import_pdb_clsc                    s$   dd l  G  fddd|}|S )Nr   c                       sl   e Zd ZZdZ fddZ fddZe ZZ fddZ	e	Z
e	Z fdd	Z fd
dZ  ZS )z:pytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapperFc                    s,    j d7  _ t |} j d8  _ |S )NrN   )_recursive_debugsuperdo_debugselfargret	__class__rL   r!   r"   ra      s   zCpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.do_debugc                    s   t  |}jdkrKjd usJ jj}|  | j}t	|}|rE|dkr2|
dd n|
dd|  |d us@J |  n|
dd jd usRJ jjjj| d d| _|S )	Nr   global>z#PDB continue (IO-capturing resumed)z*PDB continue (IO-capturing resumed for %s)zPDB continuer3   r>   T)r`   do_continuer_   r<   r3   create_terminal_writerline_pytest_capmanr7   rM   sepresumer;   hookpytest_leave_pdb
_continued)rc   rd   re   twrJ   	capturing)rg   _pytestrL   r!   r"   rk      s.   


zFpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.do_continuec                    s$   t  |}jdkrtd |S )a  Raise Exit outcome when quit command is used in pdb.

                This is a bit of a hack - it would be better if BdbQuit
                could be handled, but this would require to wrap the
                whole pytest run, and adjust the report etc.
                r   Quitting debugger)r`   do_quitr_   r   exitrb   rf   r!   r"   rx      s   

zBpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.do_quitc                    s0   t  ||}|s| jr| jr| jjdd |S )zSuspend on setup().

                Needed after do_continue resumed, and entering another
                breakpoint again.
                Tin_)r`   setuprs   rn   suspend_global_capture)rc   ftbre   rg   r!   r"   r|      s
   
z@pytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.setupc                    sp   t  ||\}}|d u r4tdt|d }|r4|| d jddr4|d8 }|r4|| d jdds#||fS )Nr   rN   __tracebackhide__F)r`   	get_stackmaxlenf_localsget)rc   r~   tstackir   r!   r"   r      s   zDpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.get_stack)__name__
__module____qualname__rn   rs   ra   rk   do_cdo_contrx   do_qdo_exitr|   r   __classcell__r!   rv   rJ   rL   r   r"   PytestPdbWrapper   s    r   )_pytest.config)rL   rZ   rJ   r   r!   r   r"   rW      s   Oz pytestPDB._get_pdb_wrapper_classc           
      O   s  ddl }| jdu rd}n| jd}|r|jdd | jrk|j| j}|  | jdkrk|	dd}|dur>|
d| n-| |}|dkrR|
dd	| d
 n|rb|
dd	| d| d n	|
dd	|  | |di |}	| jr| jjj| j|	d |	S )z4Initialize PDB debugging, dropping any IO capturing.r   NcapturemanagerTrz   headerri   rh   zPDB z (IO-capturing turned off)z (IO-capturing turned off for )rj   r!   )r   r;   	getpluginsuspendr<   r3   rl   rm   r_   r9   ro   rM   r^   rq   pytest_enter_pdb)
rL   methodargskwargsrv   rJ   rt   r   ru   _pdbr!   r!   r"   	_init_pdb   s4   


zpytestPDB._init_pdbc                 O   s0   t  j}| jdg|R i |}|| dS )zBInvoke debugging via ``Pdb.set_trace``, dropping any IO capturing.r:   N)rR   	_getframef_backr   r:   )rL   r   r   framer   r!   r!   r"   r:     s   
zpytestPDB.set_tracer@   )r   r   r   __doc__r;   r   r   __annotations__r<   r   r8   r   r   r   r_   rI   r   r   classmethodr
   strboolrM   r^   rW   r   r:   r!   r!   r!   r"   r7   b   s(   
   &T
&r7   c                   @   s<   e Zd ZdedddeddfddZd	ee ddfd
dZdS )rE   nodecallzCallInfo[Any]reportr   Nc                 C   sv   |j jd}|r!|jdd | \}}tj| tj| |jd us(J t	|jj
tjs9t||j| d S d S )Nr   Trz   )r3   rB   r   r}   read_global_capturerR   stdoutwriteexcinfo
isinstancer   unittestSkipTest
_enter_pdb)rc   r   r   r   rJ   outerrr!   r!   r"   pytest_exception_interact  s   z#PdbInvoke.pytest_exception_interactr   c                 C   s   t |}t| d S r6   )_postmortem_tracebackpost_mortem)rc   r   r   r!   r!   r"   pytest_internalerror-  s   zPdbInvoke.pytest_internalerror)	r   r   r   r   r   r   r   BaseExceptionr   r!   r!   r!   r"   rE     s    
rE   c                   @   s.   e Zd Zedddedeef fddZdS )rD   T)wrapperr   Nc                 c   s    t | d V S r6   ) wrap_pytest_function_for_tracing)rc   
pyfuncitemr!   r!   r"   pytest_pyfunc_call3  s   zPdbTrace.pytest_pyfunc_call)r   r   r   r   r   objectr   r!   r!   r!   r"   rD   2  s    rD   c                    s2   t d | jt fd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.runcallc                     s&   t jg| R i |} | d S r6   )	functoolspartialr   )r   r   funcr   testfunctionr!   r"   r   D  s   z1wrap_pytest_function_for_tracing.<locals>.wrapperN)r7   r   objr   wraps)r   r   r!   r   r"   r   9  s
   

r   c                 C   s   | 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)r3   rA   r   )r   r!   r!   r"   &maybe_wrap_pytest_function_for_tracingL  s   r   r   r   repc                 C   s   | j jdj}|  | j jj}d|jfd|jfd|j	ffD ]'\}}||dfv rF|rF|
dd|  |dd  d	krA|d d }|| q|
dd
 || |
dd t|}d|_t| |S )Nterminalreporterr   stderrlogallri   z	captured 
	tracebackzentering PDBT)r3   rB   r   _twrm   optionshowcapture	capstdout	capstderrcaplogro   
toterminalr   	_pdbshownr   )r   r   r   rt   r   sectionnamecontentr   r!   r!   r"   r   S  s(   


r   c                 C   sd   ddl m} t| j|r| jjd S t| jtr&| jjjd us!J | jjjS | jd us-J | jd S )Nr   )UnexpectedException   )	doctestr   r   r   exc_infor   cause__traceback___excinfo)r   r   r!   r!   r"   r   r  s   

r   r   c                 C   s6   t d}|  |d |  |jrtd d S d S )Nr   rw   )r7   r   resetinteractionquittingr   ry   )r   pr!   r!   r"   r     s   
r   )3r   r   r   rR   typestypingr   r   r   r   r   r   r   r	   r
   r   rv   r   _pytest._coder   r   r   r   r   r   _pytest.config.argparsingr   _pytest.config.exceptionsr   _pytest.nodesr   _pytest.reportsr   _pytest.capturer   _pytest.runnerr   r   r#   r2   rH   r7   rE   rD   r   r   r   r   TracebackTyper   r   r!   r!   r!   r"   <module>   s`    =
