
    [Fi4                        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rddl!m"Z" ddl#m$Z$ de%dee%e%f   fdZ&deddfdZ'deddfdZ( G d d       Z) G d! d"      Z* G d# d$      Z+d% Z,d& Z-d'ed(ee.   d)e de fd*Z/d(ee.   dej`                  fd+Z1d,ej`                  ddfd-Z2y).z4Interactive 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                     	 | j                  d      \  }}||fS # t        $ r}t        j                  | d      |d}~ww xY w)z#Validate syntax of --pdbcls option.:z) is not in the format 'modname:classname'N)split
ValueErrorargparseArgumentTypeError)r   modname	classnamees       c/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/_pytest/debugging.py_validate_usepdb_clsr$   $   sZ    "[[-
 Y	  ((i@A
	s    	A<Aparserc                     | j                  d      }|j                  dddd       |j                  ddd	t        d
       |j                  dddd       y )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_addoptionr4   /   sw    OOI&E	S	   
&!F   
7	      configc                 
   dd l | j                  d      r$| j                  j                  t	               d       | j                  d      r$| j                  j                  t               d       t        j                  j                  j                  t        j                  t        j                  f       t        j                  _	        | j                  t        _
        | t        _        dfd}| j                  |       y )Nr   r0   pdbtracer(   	pdbinvokec                  x    t         j                  j                         \   _        t         _        t         _        y N)	pytestPDB_savedpop	set_trace_pluginmanager_config)pdbs   r#   finzpytest_configure.<locals>.finX   s-    
   "		
M$r5   r   N)rB   getvaluepluginmanagerregisterPdbTrace	PdbInvoker<   r=   appendr?   r@   rA   add_cleanup)r6   rC   rB   s     @r#   pytest_configurerL   G   s    w%%hj*=x %%ik;?		00)2C2CD ''CM%33II# sr5   c                      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       Zed	ed
   fd       Zed	ed
   fd       Zed        Zedd       Zy)r<   z'Pseudo PDB that defers to the real pdb.Nr@   rA   ).Nr=   r   _wrapped_pdb_clscapmanr   r   c                 (    |r|j                         S y)NF)is_capturing)clsrO   s     r#   _is_capturingzpytestPDB._is_capturingm   s    &&((r5   c                 J   | j                   sdd l}|j                  S | j                   j                  d      }| j                  r!| j                  d   |k(  r| j                  d   S |r[|\  }}	 t        |       t        j                  |   }|j                  d      }t        ||d         }|dd  D ]  }	t        ||	      } ndd l}|j                  }| j                  ||      }||f| _        |S # t        $ r*}
dj                  ||f      }t        d|d|
       |
d }
~
ww xY w)Nr   r-      .r   z--pdbcls: could not import z: )rA   rB   PdbrE   rN   
__import__sysmodulesr   getattr	Exceptionjoinr   _get_pdb_wrapper_class)rR   rO   rB   r-   r    r!   modpartspdb_clspartexcr   wrapped_clss                r#   _import_pdb_clszpytestPDB._import_pdb_clss   s8   {{ 77N[[)),7
C$8$8$;z$I''**!+GY7#kk'* ",!#uQx0!!"I 5D%gt4G5 ggG00&A *K8  '9!56 1%"SEBs   -AC/ /	D"8%DD"c                 2     dd l  G  fdd|      }|S )Nr   c                   j     e Zd ZW ZdZ fdZ fdZexZZ fdZ	e	Z
e	Z fdZ fdZ xZS ):pytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapperFc                 z    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   s9    $$)$g&s+$$)$
r5   c                 D   t         |   |      }j                  dk(  rj                  J j                  j                  j                        }|j                          | j                  }t        j                  |      }|rB|dk(  r|j                  dd       n|j                  dd|z         |J |j                          n|j                  dd       j                  J j                  j                  j                  j                  |        d| _        |S )	Nr   global>z#PDB continue (IO-capturing resumed)z*PDB continue (IO-capturing resumed for %s)zPDB continuer6   rB   T)rk   do_continuerj   rA   r6   create_terminal_writerline_pytest_capmanr<   rS   sepresumer@   hookpytest_leave_pdb
_continued)	rn   ro   rp   twrO   	capturingrq   _pytestrR   s	         r#   rv   zFpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.do_continue   s   g)#.''1,;;222 >>s{{KBGGI!00F ) 7 7 ?I $0FF3(MNFF # L"+!,
  &111sN3))555""''88QU8V"&
r5   c                 n    t         |   |      }j                  dk(  rt        j                  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)rk   do_quitrj   r   exitrm   s      r#   r   zBpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.do_quit   s3     goc*''1,MM"56
r5   c                     t         |   ||      }|s4| j                  r(| j                  r| j                  j	                  d       |S )zSuspend on setup().

                Needed after do_continue resumed, and entering another
                breakpoint again.
                Tin_)rk   setupr~   ry   suspend_global_capture)rn   ftbrp   rq   s       r#   r   z@pytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.setup   sE     gmAr*t **++BBtBL
r5   c                    t         |   ||      \  }}|ft        dt        |      dz
        }|rL||   d   j                  j                  dd      r*|dz  }|r#||   d   j                  j                  dd      r*||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     7,Q2q9As5zA~.Aa 4 4 8 89Le TQ a 4 4 8 89Le Taxr5   )__name__
__module____qualname__ry   r~   rl   rv   do_cdo_contr   do_qdo_exitr   r   __classcell__)rq   r   rO   rR   s   @r#   PytestPdbWrapperrh      sC    #NJ6 )(D7 DG   r5   r   )_pytest.config)rR   ra   rO   r   r   s   ` ` @r#   r^   z pytestPDB._get_pdb_wrapper_class   s#    M	  M	 w M	 ^  r5   c                    ddl }| j                  d}n| j                  j                  d      }|r|j                  d       | j                  r|j
                  j                  | j                        }|j                          | j                  dk(  r|j                  dd      }||j                  d|       n^| j                  |      }|dk(  r|j                  dd	| d
       n1|r|j                  dd	| d| d       n|j                  dd	|         | j                  |      di |}	| j                  r1| j                  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    )r   r@   	getpluginsuspendrA   r6   rw   rx   rj   r>   rz   rS   re   r|   pytest_enter_pdb)
rR   methodargskwargsr   rO   r   r   r   _pdbs
             r#   	_init_pdbzpytestPDB._init_pdb   sQ    	%/3F''112BCFNNtN$;;66s{{CBGGI##q(Hd3%FF3' # 1 1& 9I H,sd6(2L$MN""6(*HSTU
 sd6(O4*s""6*4V4##44CKKT4Rr5   c                     t        j                         j                  } | j                  dg|i |}|j	                  |       y)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  s;     &&s}}[:4:6:ur5   rD   )r   r   r   __doc__r@   r   r   __annotations__rA   r   r=   r   r   r   rj   rN   r	   r   classmethodr   strboolrS   re   r^   r   r?   r   r5   r#   r<   r<   b   s"   148NH018 $GXf$ 	 Dhy!8,?#@(6BRRS  >BhuT#YS	%9:;B8,<#= %T	BR  
 $X.>%? $ $L R X>N5O R  R h $ $L  r5   r<   c                   :    e Zd ZdedddeddfdZdee   ddfd	Zy)
rI   nodecallzCallInfo[Any]reportr   Nc                    |j                   j                  j                  d      }|rc|j                  d       |j	                         \  }}t
        j                  j                  |       t
        j                  j                  |       |j                  J t        |j                  j                  t        j                        st        ||j                  |       y y )Nr   Tr   )r6   rF   r   r   read_global_capturerY   stdoutwriteexcinfo
isinstancer   unittestSkipTest
_enter_pdb)rn   r   r   r   rO   outerrs          r#   pytest_exception_interactz#PdbInvoke.pytest_exception_interact  s     **445EF))d)3113HCJJS!JJS!||'''$,,,,h.?.?@tT\\62 Ar5   r   c                 0    t        |      }t        |       y r;   )_postmortem_tracebackpost_mortem)rn   r   r   s      r#   pytest_internalerrorzPdbInvoke.pytest_internalerror-  s    "7+Br5   )	r   r   r   r   r   r   r   BaseExceptionr   r   r5   r#   rI   rI     s?    33 /39C3	3M-,H T r5   rI   c                   <    e Zd Z ed      dedeef   fd       Zy)rH   T)wrapperr   Nc              #   (   K   t        |       d S wr;   ) wrap_pytest_function_for_tracing)rn   
pyfuncitems     r#   pytest_pyfunc_callzPdbTrace.pytest_pyfunc_call3  s     (4s   )r   r   r   r   r   objectr   r   r5   r#   rH   rH   2  s,    d	$:N0O  r5   rH   c                     t         j                  d      | j                  t        j                        fd       }|| _        y)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                  Z    t        j                  g| i |}j                  |       y r;   )	functoolspartialr   )r   r   funcr   testfunctions      r#   r   z1wrap_pytest_function_for_tracing.<locals>.wrapperD  s)      ???Tr5   N)r<   r   objr   wraps)r   r   r   r   s     @@r#   r   r   9  sD    
 y)D>>L
 __\" # JNr5   c                 R    | j                   j                  d      rt        |        yy)zaWrap the given pytestfunct item for tracing support if --trace was given in
    the command line.r0   N)r6   rE   r   )r   s    r#   &maybe_wrap_pytest_function_for_tracingr   L  s%     !!'*(4 +r5   r   r   repc                 D   | j                   j                  j                  d      j                  }|j	                          | j                   j
                  j                  }d|j                  fd|j                  fd|j                  ffD ]B  \  }}||dfv s|s|j                  dd|z          |dd  d	k(  r|d d }|j	                  |       D |j                  dd
       |j                  |       |j                  dd       t        |      }d|_        t        |       |S )Nterminalreporterr   stderrlogallrt   z	captured 
	tracebackzentering PDBT)r6   rF   r   _twrx   optionshowcapture	capstdout	capstderrcaplogrz   
toterminalr   	_pdbshownr   )r   r   r   r   r   sectionnamecontentr   s           r#   r   r   S  s    
	"	"	,	,-?	@	D	DBGGI++$$00K 
3==!	3==!	

! 	W
 ;..7FF3k12rs|t#!#2,GGG	 FF3NN2FF3	w	'BCMOJr5   c                 ^   ddl m} t        | j                  |      r| j                  j                  d   S t        | j                  t
              rB| j                  j                  j                  J | j                  j                  j                  S | j                  J | j                  d   S )Nr   )UnexpectedException   )	doctestr   r   r   exc_infor   cause__traceback___excinfo)r   r   s     r#   r   r   r  s    +'--!45 }}%%a((	GMM#8	9 }}""00<<<}}""000+++""r5   r   c                     t         j                  d      }|j                          |j                  d |        |j                  rt        j                  d       y y )Nr   r   )r<   r   resetinteractionquittingr   r   )r   ps     r#   r   r     sB    M*AGGIMM$zz)* r5   )3r   r   r   rY   typestypingr   r   r   r   r   r   r	   r
   r   r   r   r   _pytest._coder   r   r   r   r   r   _pytest.config.argparsingr   _pytest.config.exceptionsr   _pytest.nodesr   _pytest.reportsr   _pytest.capturer   _pytest.runnerr   r   r$   r4   rL   r<   rI   rH   r   r   r   r   TracebackTyper   r   r   r5   r#   <module>r     s(   :   
              ' ! 0 # . , 0  & .'   c3h  V  0V  6y yx ( &5
&}5<F>#=#? #EDWDW #"+5&& +4 +r5   