a ze@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z m Z ddl mZddlmZddlmZddlmZddlmZdd ZGd d d eZd d ZddZddZddZddZddZddZ ddZ!ddZ"ddZ#e$d Z%e&d!e%j'd"d#Z(d$d%Z)d&d'Z*d(d)Z+d*d+Z,d,d-Z-d.d/Z.d0d1Z/d2d3Z0d4d5Z1d6d7Z2d8d9Z3d:d;Z4dd?Z6d@dAZ7dBdCZ8GdDdEdEej9Z:GdFdGdGej9Z;dHdIZdS)KN) ExitStackredirect_stdout)StringIO)support) _FakeInput)patch) BreakpointcCsdt_it_dgt_dS)N)rnextZbplistZ bpbynumberr r A/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_pdb.pyreset_Breakpointsr c@s$eZdZddZddZddZdS) PdbTestInputcCs ||_dSN)input)selfrr r r __init__ szPdbTestInput.__init__cCs0tj|_t|jt_ttdr&tnd|_dS)Ngettrace)sysstdin real_stdinrrhasattrr orig_tracerr r r __enter__#s zPdbTestInput.__enter__cGs|jt_|jrt|jdSr)rrrrsettrace)rexcr r r __exit__(szPdbTestInput.__exit__N)__name__ __module__ __qualname__rrrr r r r rsrcCsdSrr r r r r test_pdb_displayhook.sr!cCsdSrr r r r r test_pdb_basic_commandsKsr"cCsdSrr r r r r test_pdb_breakpoint_commandssr#cCsdSrr r r r r test_pdb_pp_repr_excLsr$cCsdSrr r r r r do_nothinghsr%cCs tddS)N*)printr r r r do_somethingksr(cCsdSrr r r r r test_list_commandsnsr)cCsdSrr r r r r test_pdb_whatis_commandsr*cCsdSrr r r r r test_post_mortemsr+cCsdSrr r r r r test_pdb_skip_modules5sr,Zmodule_to_skipz6def foo_pony(callback): x = 1; callback(); return NonecCsdSrr r r r r #test_pdb_skip_modules_with_callbackQsr-cCsdSrr r r r r test_pdb_continue_in_bottomframe|sr.cCsttjddd||dS)NTF)ZnosigintZreadrc)getattrpdbPdb)methodargr r r pdb_invokesr4cCsdSrr r r r r $test_pdb_run_with_incorrect_argumentsr5cCsdSrr r r r r test_pdb_run_with_code_objectsr6cCsdSrr r r r r &test_next_until_return_at_return_eventsr7cCsdSrr r r r r #test_pdb_next_command_for_generatorsr8cCsdSrr r r r r #test_pdb_next_command_for_coroutineLsr9cCsdSrr r r r r "test_pdb_next_command_for_asyncgensr:cCsdSrr r r r r %test_pdb_return_command_for_generatorsr;cCsdSrr r r r r %test_pdb_return_command_for_coroutinesr<cCsdSrr r r r r $test_pdb_until_command_for_generator"sr=cCsdSrr r r r r $test_pdb_until_command_for_coroutineNsr>cCsdSrr r r r r +test_pdb_next_command_in_generator_for_loop}sr?cCsdSrr r r r r !test_pdb_next_command_subiteratorsr@cCsdSrr r r r r test_pdb_issue_20766srAcCsdSrr r r r r test_pdb_issue_43318srBc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Z e!j"d=d>Z#d?d@Z$dAS)B PdbTestCasecCsttjdSrrunlinkTESTFNrr r r tearDown szPdbTestCase.tearDowncCs|tjdtjddg|}tj|tjtjtjit j ddid$}| t |\}}Wdn1sp0Y|ot|}|ot|}||fS)N __pycache__-mr0PYTHONIOENCODINGutf-8stdoutrstderrenv) addCleanuprrmtreer executable subprocessPopenPIPESTDOUTosenviron communicatestrencodebytesdecode)rZpdb_argscommandscmdprocrMrNr r r _run_pdbs2zPdbTestCase._run_pdbcCsZd}t|d }|t|Wdn1s40Y|tj|||g|S)Nmain.pyw)openwritetextwrapdedentrPrrEra)rscriptr^filenamefr r r run_pdb_scripts  .zPdbTestCase.run_pdb_scriptcCsd|_t|j|jd}|jd}t|jt|d}Wdn1sR0Yt|d }|t|Wdn1s0Y| tj|j| d|jg|S)Nt_main /__main__.py /__init__.pyrcrI) module_namerrQrWmkdirrdrerfrgrPra)rrhr^ main_file init_filerjr r r run_pdb_module's      .zPdbTestCase.run_pdb_modulecCslttjd}||Wdn1s,0Y|s>dn|dtj|df}||t|tjdS)Nwbrr )rdrrFre assertEqualr0Z find_function)rZ file_content func_nameexpectedrjr r r _assert_find_function5s(z!PdbTestCase._assert_find_functioncCs|ddddS)NZfoo)rxrr r r test_find_function_empty_file>sz)PdbTestCase.test_find_function_empty_filecCs|ddddS)Nu@def foo(): pass def bœr(): pass def quux(): pass bœr)r{rxr[rr r r test_find_function_foundAs  z$PdbTestCase.test_find_function_foundcCs|dddddS)NuV# coding: iso-8859-15 def foo(): pass def bœr(): pass def quux(): pass z iso-8859-15r{)r{r}rr r r -test_find_function_found_with_encoding_cookieQs  z9PdbTestCase.test_find_function_found_with_encoding_cookiecCs|tjddddS)Nudef bœr(): pass r{)r{r )rxcodecsBOM_UTF8r[rr r r !test_find_function_found_with_bombs  z-PdbTestCase.test_find_function_found_with_bomcCsttjd}|dWdn1s,0Ytjddtjg}tj|tjtjtj d}| |j j | d\}}|d|ddS) Nrtsprint("testing my pdb") rIr0rMrrNsquit s SyntaxErrorz0Got a syntax error running test script under PDB)rdrrFrerrRrSrTrUrVrPrMcloserY assertNotInrrjr_r`rMrNr r r test_issue7964ls(zPdbTestCase.test_issue7964cCsd}d}d}tdd }|t|Wdn1s<0Y|tjd|||\}}|t dd| DddS) Nz from bar import bar def foo(): bar() def nope(): pass def foobar(): foo() nope() foobar() z from bar import bar break bar continue step step quit z5 def bar(): pass zbar.pyrccss|]}d|vVqdS)zmain.py(5)foo()->NoneNr .0lr r r ryz.PdbTestCase.test_issue13183..z+Fail to step into the caller after a return) rdrerfrgrPrrErk assertTrueany splitlines)rrhr^ZbarrjrMrNr r r test_issue13183{s .zPdbTestCase.test_issue13183cCsttjd&}|tddWdn1s80Ytjdtjg}t j |t j t j t j it jddid}||jj|d\}}|d |d dS) Nrta import threading import pdb def start_pdb(): pdb.Pdb(readrc=False).set_trace() x = 1 y = 1 t = threading.Thread(target=start_pdb) t.start()ascii-urJrKrLscont Error*Got an error running test script under PDBrdrrFrerfrgr[rrRrSrTrUrVrWrXrPrMrrYrrr r r test_issue13120s  $ zPdbTestCase.test_issue13120cCsttjd&}|tddWdn1s80Ytjdtjg}t j |t j t j t j it jddid}||jj|d\}}|d |d dS) Nrta import threading import pdb evt = threading.Event() def start_pdb(): evt.wait() pdb.Pdb(readrc=False).set_trace() t = threading.Thread(target=start_pdb) t.start() pdb.Pdb(readrc=False).set_trace() evt.set() t.join()rrrJrKrLs cont cont rrrrr r r test_issue36250s $zPdbTestCase.test_issue36250cCs6d}d}d}|||\}}|||d||dS)Nz def f: pass z SyntaxError:zE Expected: {} Got: {} Fail to handle a syntax error in the debuggee.)rkassertInformat)rrhr^rwrMrNr r r test_issue16180szPdbTestCase.test_issue16180cCsLd}d}|||\}}ddd|D}||d||ddS)Nzprint('hello')z[ continue run a b c run d e f quit  cSsg|] }|qSr )strip)rxr r r ryz/PdbTestCase.test_issue26053..z#Restarting .* with arguments: a b cz#Restarting .* with arguments: d e f)rkjoinrZ assertRegex)rrhr^rMrNresr r r test_issue26053s  zPdbTestCase.test_issue26053c Cs@td}tjdd}z ttdd}|dWdn1sP0Ytdd}||Wdn1s0Yt j dg}t j |t j t j t j d}|*|d\}}|d |Wdn1s0YWdn1s0YW|dur<|tjd<n|dur:|tjd<0dS) Nz_ import pdb; pdb.Pdb(readrc=False).set_trace() print('hello') HOME.pdbrcrczinvalid rbrsq s(NameError: name 'invalid' is not defined)rfrgrWrXpoprtemp_cwdrdrerrRrSrTrUrYr)rrh save_homerjr_r`rMrNr r r test_readrc_kwargs0   ( ( D  zPdbTestCase.test_readrc_kwargc Cstjdd}t}tdtj|d}|tjj_ z`t |d}| dWdn1sf0Y| t jddW|dur|tjd<n|dur|tjd<0Wdn1s0YWdn1s0YdS)Nrzos.path.expanduserrrcinvalidr)rWrXrrtemp_dirrpathr expanduserZ return_valuerdrerur0r1ZrcLines)rrrZrc_pathrjr r r test_readrc_homedirs  ( zPdbTestCase.test_readrc_homedircCsxt}d}t@}|td||ttjdtj|dWdn1sV0Y|| |ddS)Nz"Nobody expects... blah, blah, blahz sys.stdout set_trace)headerr) rr enter_contextrobjectr0r1rrugetvalue)rrMrZ resourcesr r r test_headers*zPdbTestCase.test_headercCs:d}d}|||\}}|tdd|D|dS)Nzprint("SUCCESS")/ continue quit css|]}d|vVqdSSUCCESSNr rr r r r/ryz.PdbTestCase.test_run_module..rsrrrrrhr^rMrNr r r test_run_module(szPdbTestCase.test_run_modulecCs:d}d}|||\}}|tdd|D|dS)NzQ if __name__ == '__main__': print("SUCCESS") rcss|]}d|vVqdSrr rr r r r;ryz9PdbTestCase.test_module_is_run_as_main..rrr r r test_module_is_run_as_main1sz&PdbTestCase.test_module_is_run_as_maincCsXd}d}|||\}}|tdd|D||tdd|D|dS)Nz{ if __name__ == '__main__': pass print("SUCCESS") pass z* b 3 quit css|]}d|vVqdS)zBreakpoint 1 atNr rr r r rIryz.PdbTestCase.test_breakpoint..css|]}d|vVqdSrr rr r r rJry)rsrrrallrr r r test_breakpoint=s zPdbTestCase.test_breakpointcCs2d}|ddg|\}}|tj|dddS)Nz( c quit rIr0 r)rarr0Z_usagereplace)rr^rMrNr r r test_run_pdb_with_pdbLs  z!PdbTestCase.test_run_pdb_with_pdbcCsd}t||d}t|t|dWdn1s@0Y|tj||d|gd\}}|d|dS)NrlrnrcrIrz,ImportError: No module named t_main.__main__) rrQrWrprdrPrarr)rrorrrMrNr r r test_module_without_a_mainWs   z&PdbTestCase.test_module_without_a_maincCsd}d}t||d|}t|t|ddWdn1sL0Y|tj||d|ddgd\}}|d |dS) NZt_pkgrl/rnrcrI.rz;'t_pkg.t_main' is a package and cannot be directly executed) rrQrWmakedirsrdrPrarr)rZpkg_nameromodpathrMrNr r r test_package_without_a_maincs   z'PdbTestCase.test_package_without_a_maincCs:d}d}|||\}}|tdd|D|dS)NzY #This is a comment, on line 2 print("SUCCESS") z quit css|]}d|vVqdS)z__main__.py(4)()Nr rr r r r{sz=PdbTestCase.test_blocks_at_first_code_line..rrr r r test_blocks_at_first_code_lineqs z*PdbTestCase.test_blocks_at_first_code_linecCsnd|_t|j|jd}|jd}|jd}|tj|jt|jt|d }|t dWdn1s|0Yt|d }|t dWdn1s0Yt|d }|t dWdn1s0Yd }| d |jg|\}}| t d d | D|| t d d | D| t dd | DdS)Nrlrmrn /module.pyrc6 top_var = "VAR from top" z from . import top_var from .module import var from . import module pass # We'll stop here and print the vars zY var = "VAR from module" var2 = "second var" zz b 5 c p top_var p var p module.var2 quit rIcss|]}d|vVqdSzVAR from moduleNr rr r r rryz4PdbTestCase.test_relative_imports..css|]}d|vVqdS)z VAR from topNr rr r r rrycss|]}d|vVqdS)z second varNr rr r r rryrorrQrPrWrprdrerfrgrarrrrrqrrZ module_filerjr^rM_r r r test_relative_imports~s$      . . .z!PdbTestCase.test_relative_importscCs:d|_t|j|jd}|jd}|jd}|tj|jt|jt|d }|t dWdn1s|0Yt|d }|t dWdn1s0Yt|d }|t dWdn1s0Yd }| d |jd g|\}}| t d d | D|dS)Nrlz /runme.pyrnrrcrzl from . import module pass # We'll stop here and print the vars z5 var = "VAR from module" zQ b 3 c p module.var quit rIz.runmecss|]}d|vVqdSrr rr r r rryzDPdbTestCase.test_relative_imports_on_plain_module..rrr r r %test_relative_imports_on_plain_modules       . . .z1PdbTestCase.test_relative_imports_on_plain_modulecCsBdgd}|d|d\}}||ddgddS)Nr)zprint(z debug print(zdebug doesnotexistcrr ) z3(Pdb) *** SyntaxError: unexpected EOF while parsing!(Pdb) ENTERING RECURSIVE DEBUGGERz-*** SyntaxError: unexpected EOF while parsingLEAVING RECURSIVE DEBUGGERrz> (1)()z9((Pdb)) *** NameError: name 'doesnotexist' is not definedr(Pdb) rrkrur)rr^rMrr r r test_errors_in_commandsz"PdbTestCase.test_errors_in_commandcs$fdd}|dd|dddS)NcsVdd|dg}d|d\}}|dddd|d|d gdS) Nrzrun qpassr z-> passz(Pdb) *** Cannot run z: rr)Zbad_argmsgr^rMrrr r checksz*PdbTestCase.test_issue34266..check\zNo escaped character"zNo closing quotationr )rrr rr test_issue34266s zPdbTestCase.test_issue34266cCsxtd}d}tN}dtj|}|||\}}|| dd d|Wdn1sj0YdS)NQ import sys print('sys.path[0] is', sys.path[0]) c q(Pdb) sys.path[0] is rr) rfrgrrrWrrealpathrkrusplitrstrip)rrhr^cwdrwrMrNr r r test_issue42384s   zPdbTestCase.test_issue42384c Cstd}d}t}tj|}tj|d}tj|d}d|}t|t tj|dd}| |Wdn1s0Yt|t tj|dtj|d| tjddg|\}} | |dd d |Wdn1s 0YdS) Nrrdir_onedir_tworfoo.pyrcrrr)rfrgrrrWrrrrprdresymlinkrarurr) rrhr^rrrrwrjrMrNr r r test_issue42384_symlinks     (  z#PdbTestCase.test_issue42384_symlinkc Cs t}tdd$}td}||Wdn1s>0Ytj|d}t |t tj|dtj|d}t|d}|dWdn1s0Y| dgd\}}d}| | dd  d |Wdn1s0YdS) Nrrcz print('The correct file was executed') import os os.chdir("subdir") subdirz$print("The wrong file was executed")zc c qz#(Pdb) The correct file was executedrr)rrrdrfrgrerWrrrprarurr) rrrjsrZ wrong_filerMrNrwr r r test_issue42383s   (  (zPdbTestCase.test_issue42383N)%rrr rGrarkrsrxrzr~rrrrrrrrrrrrrrrrrrrrrrrrZskip_unless_symlinkrrr r r r rC sB  $         % rCc@s4eZdZddZddZddZddZd d Zd S) ChecklineTestscCs tdSr) linecache clearcacherr r r setUp*szChecklineTests.setUpcCsttjdSrrDrr r r rG-szChecklineTests.tearDowncCsXttjd}|dWdn1s,0Yt}||tjdddSNrcz print(123)r )rdrrFrer0r1ru checklinerrjdbr r r test_checkline_before_debugging0s(z.ChecklineTests.test_checkline_before_debuggingcCs`ttjd}|dWdn1s,0Yt}|||tjdddSr) rdrrFrer0r1resetrurrr r r test_checkline_after_reset6s (z)ChecklineTests.test_checkline_after_resetcCstd}ttjd}||Wdn1s60Yt|d}tt :t }t |D]}| |tj|qlWdn1s0YdS)Nz\ # Comment """ docstring """ ''' docstring ''' rcr)rfrgrdrrFrelenrrrr0r1rangeZ assertFalser)rrrjZ num_linesrlinenor r r test_checkline_is_not_executable=s (  z/ChecklineTests.test_checkline_is_not_executableN)rrr rrGrrrr r r r r)s rcGs2ddlm}ttttt|g}t|S)Nr)test_pdb) testrunittestZ makeSuiterCrdoctestZ DocTestSuiteZ TestSuite)argsrZsuitesr r r load_testsNs  r__main__)?rrWr0rtypesrrrSrfr contextlibrriorrrZtest.test_doctestrZ unittest.mockrZbdbrr rrr!r"r#r$r%r(r)r*r+r, ModuleTypemodexec__dict__r-r.r4r5r6r7r8r9r:r;r<r=r>r?r@rArBZTestCaserCrrrmainr r r r sp     k_*>  +*@;8=7*,/*/!%