'L i{6dZddlmZddlZddlmZddlmZddlZddlZddl Z ddl m Z ddl Z ddl mZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddl m!Z!d!dZ"d"dZ#d#dZ$GddZ%GddZ&GddZ'd$dZ(d$dZ) d%dZ* d&dZ+d'd Z,y)(z4Interactive debugging with PDB, the Python Debugger.) annotationsN)Callable) Generator)Any)outcomes) ExceptionInfo)CaptureManager)Config)ConftestImportFailure)hookimpl)PytestPluginManager)Parser) UsageError)Node) BaseReport)CallInfoc |jd\}}||fS#t$r}tj|d|d}~wwxYw)z#Validate syntax of --pdbcls option.:z) is not in the format 'modname:classname'N)split ValueErrorargparseArgumentTypeError)valuemodname classnamees W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/_pytest/debugging.py_validate_usepdb_clsrsZ"[[- Y  ((i@ A  s A<Ac|jd}|jdddd|jddd td |jd d ddy)Ngeneralz--pdbusepdb store_truezDStart the interactive Python debugger on errors or KeyboardInterrupt)destactionhelpz--pdbcls usepdb_clszmodulename:classnamez{Specify a custom interactive Python debugger for use with --pdb.For example: --pdbcls=IPython.terminal.debugger:TerminalPdb)r#metavartyper%z--tracetracez(Immediately break when running each test)getgroup addoptionr)parsergroups rpytest_addoptionr.)sq OOI &E OO  S   OO & !F  OO  7 c ddl|jdr$|jjt d|jdr$|jjt dt jjjt jt jft j_ |jt _ |t _ dfd }|j|y)Nrr)pdbtracer! pdbinvokecxtjj\_t_t_yN) pytestPDB_savedpop set_trace_pluginmanager_config)pdbsrfinzpytest_configure..finRs-    "  M  $  r/returnNone) r;getvalue pluginmanagerregisterPdbTrace PdbInvoker5r6appendr8r9r: add_cleanup)configr<r;s @rpytest_configurerHAs w%%hj*= x %%ik;?   00)2C2CD''CM%33II# sr/ceZdZUdZdZded<dZded<gZded<d ZdZ d ed <e dd Z e dd Z e ddZ e dZe ddZy)r5z'Pseudo PDB that defers to the real pdb.NzPytestPluginManager | Noner9z Config | Noner:zKlist[tuple[Callable[..., None], PytestPluginManager | None, Config | None]]r6rz"tuple[type[Any], type[Any]] | None_wrapped_pdb_clsc(|r|jSy)NF) is_capturing)clscapmans r _is_capturingzpytestPDB._is_capturinggs &&( (r/cJ|jsddl}|jS|jjd}|jr!|jd|k(r|jdS|r[|\}} t |t j|}|jd}t||d}|ddD]} t|| }nddl}|j}|j||} || f|_| S#t$r*} dj||f} td| d| | d} ~ wwxYw)Nrr&.rz--pdbcls: could not import z: )r:r;Pdbr@rJ __import__sysmodulesrgetattr Exceptionjoinr_get_pdb_wrapper_class) rMrNr;r&rrmodpartspdb_clspartexcr wrapped_clss r_import_pdb_clszpytestPDB._import_pdb_clsms8{{ 77N[[)),7   C$8$8$;z$I''* * !+ GY 7#kk'*",!#uQx0!!"I5D%gt4G5 ggG00&A *K8 '9!56 1%"SEB s-AC// D"8%DD"c6ddlGfdd}|S)NrcNeZdZWZdZfdZeWdrWj je_fdZeWdrWjje_exZ Z fdZ eWdrWjje _e Z e Z fdZfd ZxZS) :pytestPDB._get_pdb_wrapper_class..PytestPdbWrapperFczxjdz c_t| |}xjdzc_|S)NrQ)_recursive_debugsuperdo_debugselfargret __class__rMs rrhzCpytestPDB._get_pdb_wrapper_class..PytestPdbWrapper.do_debugs9$$)$g&s+$$)$ r/rhcFt||}jdk(rjJjj j}|j |j}tj|}|rC|dk(r|jddn|jdd|d|J|jn|jddjJjjjj|d |_|S) Nrglobal>z#PDB continue (IO-capturing resumed)z'PDB continue (IO-capturing resumed for )z PDB continuerGr;T)rg do_continuerfr:rGcreate_terminal_writerline_pytest_capmanr5rOsepresumer9hookpytest_leave_pdb _continued) rjrkrltwrN capturingrm_pytestrMs rrszFpytestPDB._get_pdb_wrapper_class..PytestPdbWrapper.do_continues g)#.''1,;;222 >>s{{KBGGI!00F ) 7 7 ?I $0FF3(MNFF #"I)TU V &111 sN3))555""''88 QU8V"& r/rscnt||}jdk(rtjd|S)NrQuitting debugger)rgdo_quitrfrexitris rrzBpytestPDB._get_pdb_wrapper_class..PytestPdbWrapper.do_quits3 goc*''1,MM"56 r/rct|||}|s4|jr(|jr|jj d|S)zSuspend on setup(). Needed after do_continue resumed, and entering another breakpoint again. Tin_)rgsetupr{rvsuspend_global_capture)rjftbrlrms rrz@pytestPDB._get_pdb_wrapper_class..PytestPdbWrapper.setupsE gmAr*t**++BBtBL r/ct|||\}}|ftdt|dz }|rL||djj ddr*|dz}|r#||djj ddr*||fS)NrrQ__tracebackhide__F)rg get_stackmaxlenf_localsget)rjrtstackirms rrzDpytestPDB._get_pdb_wrapper_class..PytestPdbWrapper.get_stacks 7,Q2q9As5zA~.Aa 4 4 8 89Le TQa 4 4 8 89Le Taxr/)__name__ __module__ __qualname__rvr{rhhasattr__doc__rsdo_cdo_contrdo_qdo_exitrr __classcell__)rmr~rNrMr]s@rPytestPdbWrapperrds#NJ  w +#*#3#3#;#;  4w .&-&9&9&A&A #( (D7 w *")//"9"9DG   r/r)_pytest.config)rMr]rNrr~s``` @rrZz pytestPDB._get_pdb_wrapper_classs#T T wT l r/cddl}|jd}n|jjd}|r|jd|jr|j j |j}|j|jdk(r|jdd}||jd|n^|j|}|dk(r|jdd |d n1|r|jdd |d |d n|jdd ||j|di|} |jr1|jjj|j| | S)z4Initialize PDB debugging, dropping any IO capturing.rNcapturemanagerTrheaderrprozPDB z (IO-capturing turned off)z (IO-capturing turned off for rqrr)rr9 getpluginsuspendr:rGrtrurfr7rwrOrarypytest_enter_pdb) rMmethodargskwargsr~rNr|rr}_pdbs r _init_pdbzpytestPDB._init_pdbsQ     %,0F''112BCF  NNtN $ ;;66s{{CB GGI##q(Hd3%FF3' # 1 1& 9I H,sd6(2L$MN""6(*H STU sd6(O4*s""6*4V4       # # 4 4CKKT 4 R r/ctjj}|jdg|i|}|j |y)zBInvoke debugging via ``Pdb.set_trace``, dropping any IO capturing.r8N)rU _getframef_backrr8)rMrrframers rr8zpytestPDB.set_traces; &&s}}[:4:6: ur/)rNCaptureManager | Noner>z str | bool)rNrr=)rrrrr9__annotations__r:r6rfrJ classmethodrOrarZrr8rr/rr5r5\s115N.5!G]!    ;?8? $$LY Y v$$Lr/r5c,eZdZ ddZddZy)rDc|jjjd}|rc|jd|j \}}t j j|t j j||jJt|jjtjst||j|yy)NrTr)rGrArrread_global_capturerUstdoutwriteexcinfo isinstancerunittestSkipTest _enter_pdb)rjnodecallreportrNouterrs rpytest_exception_interactz#PdbInvoke.pytest_exception_interact s**445EF   ) )d ) 3113HC JJ  S ! JJ  S !||'''$,,,,h.?.?@ tT\\6 2Ar/c0t|}t|yr4)_postmortem_exc_or_tb post_mortem)rjr exc_or_tbs rpytest_internalerrorzPdbInvoke.pytest_internalerror.s)'2 Ir/N)rrrz CallInfo[Any]rrr>r?)rExceptionInfo[BaseException]r>r?)rrrrrrr/rrDrDs, 3 3 - 37A 3  3r/rDc,eZdZedddZy)rCT)wrapperc#(Kt|dSwr4) wrap_pytest_function_for_tracing)rj pyfuncitems rpytest_pyfunc_callzPdbTrace.pytest_pyfunc_call4s(4sN)r>zGenerator[None, object, object])rrrr rrr/rrCrC3s dr/rCctjd|jtjdfd }||_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.runcallcZtjg|i|}j|yr4) functoolspartialr)rrfuncr testfunctions rrz1wrap_pytest_function_for_tracing..wrapperEs)  ??? Tr/Nr=)r5robjrwraps)rrrrs @@rrr:sD   y )D>>L __\"#JNr/cR|jjdr t|yy)zaWrap the given pytestfunct item for tracing support if --trace was given in the command line.r)N)rGr@r)rs r&maybe_wrap_pytest_function_for_tracingrMs%!!'*(4+r/cD|jjjdj}|j |jj j }d|jfd|jfd|jffD]B\}}||dfvs |s|jdd|z|ddd k(r|dd}|j |D|jdd |j||jdd t|}d |_ t||S) Nterminalreporterrstderrlogallrpz captured  tracebackz entering PDBT)rGrAr_twruoption showcapture capstdout capstderrcaplogrw toterminalr _pdbshownr)rrrepr|r sectionnamecontent tb_or_excs rrrTs  " " , ,-? @ D DBGGI++$$00K 3==! 3==!  !  W ;. .7 FF3 k1 2rs|t#!#2, GGG  FF3 NN2FF3%g.ICM  Jr/cddlm}tjdk\}t |j |r,|j }|r|j dS|j dSt |j tr4|j j}|r|S|jJ|jS|jJ|r|jdS|jdS)Nr)UnexpectedException) rQ) doctestrrU version_inforrexc_infor cause __traceback___excinfo)rrget_excunderlying_excrs rrrss,')G'--!45! !**1- -&&q)) GMM#8 9 ## L""..."""+++ ##A& &""r/ctjd}|j|jd||jrt j dyy)Nrr)r5rreset interactionquittingrr)rps rrrsBM*AGGIMM$ "zz )*r/)rstrr>ztuple[str, str])r,rr>r?)rGr r>r?r=)rrrrrrr>r)rrr>#types.TracebackType | BaseException)rrr>r?)-r __future__rrcollections.abcrrrrUtypestypingrrr~r _pytest._coder_pytest.capturer rr r r r _pytest.config.argparsingr_pytest.config.exceptionsr _pytest.nodesr_pytest.reportsr_pytest.runnerrrr.rHr5rDrCrrrrrrr/rr s;"$% '*!0#.,0&# 06@@F(&5 5# )#(#>+r/