o
    Ú­jº4  ã                   @   sò  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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mZ ddlmZ ddlmZ ddlm Z  er–d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!   úN/var/www/html/CropPilot/venv/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"   ÚfinU   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_configureD   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_capturingj   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_clsp   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 )zŽSuspend 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rh|j | j¡}| ¡  | jdkrh| 	dd¡}|dur>| 
d|¡ n*|  |¡}|dkrR| 
dd	|› d
�¡ n|r_| 
dd||f ¡ 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'PDB %s (IO-capturing turned off for %s)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î   s8   


ÿþ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   _   s(   
 þÿ  &V
'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 fdd„ƒZdS )rD   T)Úhookwrapperr   )NNNc                 c   s   � t |ƒ d V  d S r6   )Ú wrap_pytest_function_for_tracing)rc   Ú
pyfuncitemr!   r!   r"   Úpytest_pyfunc_call3  s   €
zPdbTrace.pytest_pyfunc_callN)rŠ   r‹   rŒ   r   r   r¼   r!   r!   r!   r"   rD   2  s    rD   c                    s2   t  d¡‰ | j‰t ˆ¡‡ ‡fdd„ƒ}|| _dS )zñChange 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"   ÚwrapperD  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   sT   ddl m} t| j|ƒr| jjd S t| jtƒr| jjd S | jd us%J ‚| jd S )Nr   )ÚUnexpectedExceptioné   )ÚdoctestrÙ   r®   r   Úexc_infor   r­   Ú_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   Útypesr¯   Útypingr   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`     @ÿÿÿ
þ