a ze=1@sddlZddlZddlZddlZGdddejZGdddZGdddeZGdd d ejZGd d d eZ Gd d d eZ ddZ ddZ e e Z dddZddZedkredS)Nc@s,eZdZddZddZddZddZd S) TestGetProfilecCstddSNsys setprofileselfr L/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_sys_setprofile.pysetUpszTestGetProfile.setUpcCstddSrrrr r r tearDown szTestGetProfile.tearDowncCs|tdSr)Z assertIsNoner getprofilerr r r test_emptyszTestGetProfile.test_emptycCs&dd}t||t|dS)NcWsdSrr )argsr r r fnsz&TestGetProfile.test_setget..fn)rrZassertIsr )rrr r r test_setgets zTestGetProfile.test_setgetN)__name__ __module__ __qualname__r r rrr r r r rsrc@s.eZdZddZddZd ddZdd ZdS) HookWatchercCsg|_g|_dSr)frameseventsrr r r __init__szHookWatcher.__init__cCs(|dks|dks|dkr$|||dS)Ncallreturn exception add_eventrframeeventargr r r callbacks zHookWatcher.callbackNcCsf|durtd}z|j|}Wn(tyJt|j}|j|Yn0|j||t|fdS)zAdd an event to the log.N) r _getframerindex ValueErrorlenappendrident)rr rZframenor r r r#s   zHookWatcher.add_eventcs.t|jjttgd|_fdd|jDS)zRemove calls to add_event().Ncsg|]}|dvr|qS)r ).0itemZ disallowedr r 5z*HookWatcher.get_events..)r)r__func__rrrr r-r get_events0szHookWatcher.get_events)N)rrrrr"rr1r r r r rs rc@sNeZdZddZddZddZddZd d Zd d Zeeeeeed Z dS)ProfileSimulatorcCs||_g|_t|dSr)testcasestackrr)rr3r r r r9szProfileSimulator.__init__cCs|j|||dSr)dispatchrr r r r">szProfileSimulator.callbackcCs|d||j|dS)Nr)rr4r(rrr r r trace_callBs zProfileSimulator.trace_callcCs|d||jdS)Nr)rr4popr6r r r trace_returnFs zProfileSimulator.trace_returncCs|jddS)Nz2the profiler should never receive exception events)r3failr6r r r trace_exceptionJsz ProfileSimulator.trace_exceptioncCsdSrr r6r r r trace_passNszProfileSimulator.trace_pass)rrrZc_callZc_returnZ c_exceptionN) rrrrr"r7r9r;r<r5r r r r r28sr2c@seZdZddZdS) TestCaseBasecCs8t||}||kr4|dt|t|fdS)Nz'Expected events: %s Received events: %s)capture_events new_watcherr:pprintZpformat)rcallableZexpectedrr r r check_events\s zTestCaseBase.check_eventsN)rrrrBr r r r r=[sr=c@s|eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZdS)ProfileHookTestCasecCstSr)rrr r r r?dszProfileHookTestCase.new_watchercCs0dd}t|}||dd|fdd|fgdS)NcSsdSrr pr r r fhsz*ProfileHookTestCase.test_simple..fr#rrr)rBrrFf_identr r r test_simplegs zProfileHookTestCase.test_simplecCs0dd}t|}||dd|fdd|fgdS)NcSs dddSNr#rr rDr r r rFpsz-ProfileHookTestCase.test_exception..fr#rrrGrHr r r test_exceptionos z"ProfileHookTestCase.test_exceptioncCs0dd}t|}||dd|fdd|fgdS)NcSsz ddWn Yn0dSrKr rDr r r rFxsz4ProfileHookTestCase.test_caught_exception..fr#rrrGrHr r r test_caught_exceptionws z)ProfileHookTestCase.test_caught_exceptioncCs0dd}t|}||dd|fdd|fgdS)NcSsz ddWn Yn0dSrKr rDr r r rFsz;ProfileHookTestCase.test_caught_nested_exception..fr#rrrGrHr r r test_caught_nested_exceptions z0ProfileHookTestCase.test_caught_nested_exceptioncCs0dd}t|}||dd|fdd|fgdS)NcSs dddSrKr rDr r r rFsz4ProfileHookTestCase.test_nested_exception..fr#rrrGrHr r r test_nested_exceptions z)ProfileHookTestCase.test_nested_exceptionc sdddfdd}t}t|}||dd|fdd|fdd|fd d|fd d|fdd|fgdS) NcSs dddSrKr rDr r r rFsz>ProfileHookTestCase.test_exception_in_except_clause..fc s8z |Wn&z |Wn Yn0Yn0dSrr rDrFr r gs  z>ProfileHookTestCase.test_exception_in_except_clause..gr#rr*rrGrrQrIg_identr rPr test_exception_in_except_clauses z3ProfileHookTestCase.test_exception_in_except_clausec s\ddfdd}t}t|}||dd|fdd|fdd|fdd |fdd|fgdS) NcSs dddSrKr rDr r r rFsz9ProfileHookTestCase.test_exception_propagation..fc s(z|W|dn |d0dS)Nfalling throughrrDrPr r rQs z9ProfileHookTestCase.test_exception_propagation..gr#rr*rrVrGrSr rPr test_exception_propagations z.ProfileHookTestCase.test_exception_propagationcCs0dd}t|}||dd|fdd|fgdS)NcSs&z ddWnddYn0dSrKr rDr r r rFsz/ProfileHookTestCase.test_raise_twice..fr#rrrGrHr r r test_raise_twices z$ProfileHookTestCase.test_raise_twicecCs0dd}t|}||dd|fdd|fgdS)NcSs z ddWnYn0dSrKr rDr r r rFsz1ProfileHookTestCase.test_raise_reraise..fr#rrrGrHr r r test_raise_reraises z&ProfileHookTestCase.test_raise_reraisecCs0dd}t|}||dd|fdd|fgdS)NcSs tdSr) ExceptionrDr r r rFsz)ProfileHookTestCase.test_raise..fr#rrrGrHr r r test_raises zProfileHookTestCase.test_raisecsddfddfddfddfd d }t}t}t}t}t|}||d d |fd d |fdd |fdd |fdd |fdd|fdd|fdd|fd d|fd d|fg dS)NcSs dddSrKr r r r r rFsz5ProfileHookTestCase.test_distant_exception..fcs dSrr r rPr r rQsz5ProfileHookTestCase.test_distant_exception..gcs dSrr r rQr r hsz5ProfileHookTestCase.test_distant_exception..hcs dSrr r r]r r isz5ProfileHookTestCase.test_distant_exception..ics dSrr rDr_r r jsz5ProfileHookTestCase.test_distant_exception..jr#rr*rRrrGrrarIrTZh_identZi_identZj_identr rFrQr]r_r test_distant_exceptions*    z*ProfileHookTestCase.test_distant_exceptionc stddfdd}t}t|}||dd|fdd|fdd|fdd|fdd|fdd|fdd|fdd|fgdS) NcsstdD] }|VqdSNr*ranger`r r r rFs z-ProfileHookTestCase.test_generator..fcsD]}qdSrr rEr_rPr r rQs z-ProfileHookTestCase.test_generator..gr#rr*rrGrSr rPr test_generators z"ProfileHookTestCase.test_generatorc stddfdd}t}t|}||dd|fdd|fdd|fdd|fdd|fdd|fdd|fdd|fgdS) NcsstdD] }|VqdSrgrhr`r r r rFs z2ProfileHookTestCase.test_stop_iteration..fcsD]}qdSrr rjrPr r rQs z2ProfileHookTestCase.test_stop_iteration..gr#rr*rrGrSr rPr test_stop_iterations z'ProfileHookTestCase.test_stop_iterationN)rrrr?rJrLrMrNrOrUrWrXrYr[rfrkrlr r r r rCcs     rCc@s\eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dS)ProfileSimulatorTestCasecCst|Sr)r2rr r r r?sz$ProfileSimulatorTestCase.new_watchercCs0dd}t|}||dd|fdd|fgdS)NcSsdSrr rDr r r rFsz/ProfileSimulatorTestCase.test_simple..fr#rrrGrHr r r rJs z$ProfileSimulatorTestCase.test_simplecCs0dd}t|}||dd|fdd|fgdS)NcSs dddSrKr rDr r r rF%sz8ProfileSimulatorTestCase.test_basic_exception..fr#rrrGrHr r r test_basic_exception$s z-ProfileSimulatorTestCase.test_basic_exceptioncCs0dd}t|}||dd|fdd|fgdS)NcSsz ddWn Yn0dSrKr rDr r r rF-sz9ProfileSimulatorTestCase.test_caught_exception..fr#rrrGrHr r r rM,s z.ProfileSimulatorTestCase.test_caught_exceptioncsddfddfddfddfd d }t}t}t}t}t|}||d d |fd d |fdd |fdd |fdd |fdd|fdd|fdd|fd d|fd d|fg dS)NcSs dddSrKr r r r r rF6sz:ProfileSimulatorTestCase.test_distant_exception..fcs dSrr r rPr r rQ8sz:ProfileSimulatorTestCase.test_distant_exception..gcs dSrr r r\r r r]:sz:ProfileSimulatorTestCase.test_distant_exception..hcs dSrr r r^r r r_<sz:ProfileSimulatorTestCase.test_distant_exception..ics dSrr rDr`r r ra>sz:ProfileSimulatorTestCase.test_distant_exception..jr#rr*rRrbrcrrGrdr rer rf5s*    z/ProfileSimulatorTestCase.test_distant_exceptioncs8ifdd}t|}||dd|fdd|fgdS)NcstjidfidSN*dictgetrDkwargsr r rFTsz7ProfileSimulatorTestCase.test_unbound_method..fr#rrrGrHr rtr test_unbound_methodRs  z,ProfileSimulatorTestCase.test_unbound_methodcCs0dd}t|}||dd|fdd|fgdS)NcSs tdSrrqrDr r r rF\sz?ProfileSimulatorTestCase.test_unbound_method_no_args..fr#rrrGrHr r r test_unbound_method_no_args[s z4ProfileSimulatorTestCase.test_unbound_method_no_argscCs0dd}t|}||dd|fdd|fgdS)NcSsttddSrorrrsprintrDr r r rFdszDProfileSimulatorTestCase.test_unbound_method_invalid_args..fr#rrrGrHr r r test_unbound_method_invalid_argscs z9ProfileSimulatorTestCase.test_unbound_method_invalid_argscs8ifdd}t|}||dd|fdd|fgdS)NcstjfidSrrqrDrtr r rFmszGProfileSimulatorTestCase.test_unbound_method_no_keyword_args..fr#rrrGrHr rtr #test_unbound_method_no_keyword_argsks  z.fr#rrrGrHr rtr (test_unbound_method_invalid_keyword_argsts  zAProfileSimulatorTestCase.test_unbound_method_invalid_keyword_argsN) rrrr?rJrnrMrfrvrwrzr{r|r r r r rms   rmcCs$t|dr|j}n|j}|j|jfS)Nf_code)hasattrr}__code__co_firstlinenoco_name)functioncoder r r r)}s r)cCsz ||Wn Yn0dSrr )rFrEr r r protectsrcCsn|durt}t}tz0t|jt||tdW|r^tn|r\t0| ddS)Nr#) rgc isenableddisablerrr"renabler1)rArEZold_gcr r r r>s     r>cCsddl}|t|dS)Nr)r@r>)rAr@r r r show_eventssr__main__)N)rr@rZunittestZTestCaserrr2r=rCrmr)rZ protect_identr>rrmainr r r r s" #6e