U Wg: @sddlmZddlZddlZddlZddlmZddlmZeoHeeddfZ Gdd d e Z Gd d d e Z Gd d d eZGddde ZddZGdddeZedkredS))print_functionN)TestCase)PY312gettotalrefcountz%Broken on debug builds of Python 3.12c@s eZdZdS) SomeErrorN)__name__ __module__ __qualname__r r K/opt/hc_python/lib64/python3.8/site-packages/greenlet/tests/test_tracing.pyrsrc@s2eZdZdZd ddZddZddZd d ZdS) GreenletTracerNFcCsg|_||_dSN)actionserror_on_trace)selfrr r r __init__szGreenletTracer.__init__cGs|j||jrtdSr)rappendrrrargsr r r __call__s zGreenletTracer.__call__cCst||_|jSr)greenletsettraceoldtracerrr r r __enter__s zGreenletTracer.__enter__cGst|jdSr)rrrrr r r __exit__"szGreenletTracer.__exit__)Frr r rrrrrr r r r r s  r c@s(eZdZdZddZddZddZdS) TestGreenletTracingz* Tests of ``greenlet.settrace()`` c Cst}dd}dd}t0}t|}|t|}|t|jW5QRX||d||ffd||ffd||ffd||ffgdS)NcSsdSrr r r r r dummy-sz:TestGreenletTracing.test_a_greenlet_tracing..dummycSs tdSr)rr r r r dummyexc/sz=TestGreenletTracing.test_a_greenlet_tracing..dummyexcswitchthrow)r getcurrentr r! assertRaisesr assertEqual)rmainrr rg1g2r r r test_a_greenlet_tracing+s      z+TestGreenletTracing.test_a_greenlet_tracingc sttfdd}t|}|tdd$}|t|j|tdW5QRX||d|ffgdS)Ncs dSr)r!r r&r r rAszDTestGreenletTracing.test_b_exception_disables_tracing..dummyT)rr!)rr#r!r r$rr%gettrace)rrgrr r*r !test_b_exception_disables_tracing?s    z5TestGreenletTracing.test_b_exception_disables_tracingc Cs$t}|t|W5QRXdSr)r rr)rtracerr r r test_set_same_tracer_twiceMsz.TestGreenletTracing.test_set_same_tracer_twiceN)rr r __doc__r)r-r/r r r r r&src@s0eZdZdZddZddZddZdd ZdS) PythonTracerNcCs g|_dSr)rrr r r rZszPythonTracer.__init__cCs|j||jjfdSr)rrf_codeco_name)rframeeventargr r r r]szPythonTracer.__call__cCst||_|jSr)sys setprofilerrrr r r ras zPythonTracer.__enter__cGst|jdSr)r7r8rrr r r reszPythonTracer.__exit__rr r r r r1Ws r1cCsdSN*r r r r r tpt_callbackhsr;c@sxeZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ e jeddZe jeddZdS)TestPythonTracingz Tests of the interaction of ``sys.settrace()`` with greenlet facilities. NOTE: Most of this is probably CPython specific. Nc Cs2t }tW5QRX||dddddgdS)Nreturnrcallr;r>r;r@rc_callr)r1r;r%)rrr r r test_trace_events_trivialus z+TestPythonTracing.test_trace_events_trivialc Cst}|W5QRX|Sr)r1r!rZgletrr r r _trace_switchszTestPythonTracing._trace_switchc Cs,||}||ddddddddd g dS) Nr=)rDrG)r@runr?rAr>rH)Zc_returnrGrBrC)rGr%rFr r r $_check_trace_events_func_already_sets z6TestPythonTracing._check_trace_events_func_already_setcCsdd}|t|dS)NcSstSrr;r r r r rHszOTestPythonTracing.test_trace_events_into_greenlet_func_already_set..run)rJrrrHr r r 0test_trace_events_into_greenlet_func_already_setszBTestPythonTracing.test_trace_events_into_greenlet_func_already_setcCs"Gdddtj}||dS)Nc@seZdZddZdS)zQTestPythonTracing.test_trace_events_into_greenlet_subclass_already_set..XcSstSrrKrr r r rHszUTestPythonTracing.test_trace_events_into_greenlet_subclass_already_set..X.runNrr r rHr r r r XsrO)rrJrrOr r r 4test_trace_events_into_greenlet_subclass_already_setszFTestPythonTracing.test_trace_events_into_greenlet_subclass_already_setc Cs8|t|||jddddddddgdS)Nr=r?rArIrBrC)r!r;rr%r)rr,r.r r r /_check_trace_events_from_greenlet_sets_profilerszATestPythonTracing._check_trace_events_from_greenlet_sets_profilercs(tfdd}|t|dS)NcstSrrr;r r.r r rHszQTestPythonTracing.test_trace_events_from_greenlet_func_sets_profiler..run)r1rRrrLr rTr 2test_trace_events_from_greenlet_func_sets_profilers   zDTestPythonTracing.test_trace_events_from_greenlet_func_sets_profilercs.tGfdddtj}||dS)NcseZdZfddZdS)zSTestPythonTracing.test_trace_events_from_greenlet_subclass_sets_profiler..XcstSrrSrrTr r rHszWTestPythonTracing.test_trace_events_from_greenlet_subclass_sets_profiler..X.runNrNr rTr r rOsrO)r1rrRrPr rTr 6test_trace_events_from_greenlet_subclass_sets_profilerszHTestPythonTracing.test_trace_events_from_greenlet_subclass_sets_profilerc s|tddfdd}fdd}t|t|}||dt|jdddd d ddd d g dS) Ncs ttdSr9)rr;r!r r(r.r r g1_runs zPTestPythonTracing.test_trace_events_multiple_greenlets_switching..g1_runcs ttdSr)r;rr!r r'r.r r g2_runszPTestPythonTracing.test_trace_events_multiple_greenlets_switching..g2_runr:r=r?rArDrX)r@rZrBrCr1rr!r%r;rrrXrZxr r'r(r.r .test_trace_events_multiple_greenlets_switchings*   z@TestPythonTracing.test_trace_events_multiple_greenlets_switchingc stddfdd}fdd}t|t|}||dt|jdddd ddd d gdS) Ncs.tjttdSr9)rr#parentr!rr;r rWr r rXs zYTestPythonTracing.test_trace_events_multiple_greenlets_switching_siblings..g1_runcs.tjttdSr)rr#rar!r;rr rYr r rZs zYTestPythonTracing.test_trace_events_multiple_greenlets_switching_siblings..g2_runr:r=r?rAr[rBrCr\r]r r_r 7test_trace_events_multiple_greenlets_switching_siblingss,   zITestPythonTracing.test_trace_events_multiple_greenlets_switching_siblings)rr r r0ZmaxDiffrErGrJrMrQrRrUrVunittestZskipIfDEBUG_BUILD_PY312r`rbr r r r r<ks   %r<__main__) __future__rr7rrcrrhasattrrd Exceptionrobjectr rr1r;r<rr&r r r r s"    18