
    daf              	       h   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	dZ
d Zd Zd Zd Zd Zd	Zd
ZdZ G d dej&                        Z G d d      Z G d deej&                        Zej.                  j0                  Zej4                  dfej6                  dfej8                  dfej:                  dfej<                  dfej>                  dfgZ ejB                  dfejD                  dfejF                  dfgZ$e e$z   ejJ                  dfejL                  dfgz   Z' ejP                  ejR                  e'D  cg c]  \  } }| 	 c}} d      ejT                  z  Z+d Z,g de,_        d Z-g d e-_        d! Z.g d"e._        d# Z/g d$e/_        d% Z0g d&e0_        ejb                  ejd                  fZ3 G d' d(e      Z4 G d) d*e4ej&                        Z5ejL                  ejJ                  ej8                  ejD                  ej:                  fZ6ej4                  ej6                  fZ7dd+l8m9Z9  G d, d-e4ej&                        Z: G d. d/      Z; G d0 d1      Z< G d2 d3eej&                        Z= G d4 d5eej&                        Z> G d6 d7eej&                        Z? G d8 d9eej&                        Z@ G d: d;      ZA G d< d=eej&                        ZB G d> d?eA      ZC G d@ dAeA      ZD G dB dCeA      ZE G dD dEeA      ZF G dF dGeA      ZG G dH dIeB      ZH G dJ dK      ZI G dL dM      ZJ G dN dO      ZK G dP dQeK      ZL G dR dSeK      ZMeAeJeIeLeMfZN G dT dUeB      ZO G dV dW      ZPePeIfZQ G dX dYeB      ZR G dZ d[eej&                        ZSeJeIeLeMfZT G d\ d]eej&                        ZUd^ ZV G d_ d`      ZW G da dbeW      ZX G dc dd      ZYeWeXfZZeWeXeIfZ[eWeXeIeAeYfZ\ G de dfeB      Z] G dg dheB      Z^ G di djeej&                        Z_ G dk dlej&                  e      Z` G dm dneej&                        Zayc c}} w )oz"Test suite for the sys.monitoring.    Nr      c                       y N r       //root/Python-3.12.4/Lib/test/test_monitoring.pyf1r
          r   c                  D    t        g        t        j                  d       y Nr   )lensys	getsizeofr   r   r	   f2r      s    GMM!r   c                      t         D ]  }  y r   )PAIR)items    r	   floopr      s     r   c               #      K   d  d  y wr   r   r   r   r	   genr      s     		   
c                  "    t               D ]  }  y r   )r   )_s    r	   g1r      s    U r            c                       e Zd Zd Zd Zy)MonitoringBasicTestc                 p   t         j                  }|j                   |j                   |j                   |j
                   |j                   |j                   |j                   |j                   |j                   |j                   |j                   |j                   |j                  j                   y r   )r   
monitoringeventsuse_tool_idfree_tool_idget_tool
get_events
set_eventsget_local_eventsset_local_eventsregister_callbackrestart_eventsDISABLEMISSING	NO_EVENTS)selfms     r	   test_has_objectsz$MonitoringBasicTest.test_has_objects(   st    NN				

													r   c                    t         j                  j                  t        d       | j	                  t         j                  j                  t              d       t         j                  j                  t        d       | j	                  t         j                  j                  t              d       t         j                  j                  t        d       | j                  t              5  t         j                  j                  t        t         j                  j                  j                         d d d        | j                  t              5  t         j                  j                  t        t         j                  j                  j                         d d d        t         j                  j                  t               | j	                  t         j                  j                  t              d        | j                  t              5  t         j                  j                  t        t         j                  j                  j                         d d d        y # 1 sw Y   )xY w# 1 sw Y   xY w# 1 sw Y   y xY w)NzMonitoringTest.Tool   r   )r   r"   r$   	TEST_TOOLassertEqualr&   r(   r'   assertRaises
ValueErrorr#   C_RETURNC_RAISEr%   CALLr0   s    r	   	test_toolzMonitoringBasicTest.test_tool8   s   ""9.CD00;=RS!!)R0229=rB!!)Q/z* 	QNN%%i1F1F1O1OP	Qz* 	PNN%%i1F1F1N1NO	P##I.00;TBz* 	MNN%%i1F1F1K1KL	M 	M	Q 	Q	P 	P	M 	Ms'   (AIAI#AI/I #I,/I8N)__name__
__module____qualname__r2   r=   r   r   r	   r    r    &   s     Mr   r    c                       e Zd Zd Zd Zy)MonitoringTestBasec                    t        d      D ]1  }| j                  t        j                  j	                  |      d       3 | j                  t        j                  j                  t              d        | j                  t        j                  j                  t              d        | j                  t        j                  j                  t              d        t        j                  j                  t        d| j                  j                  z          t        j                  j                  t        d| j                  j                  z          t        j                  j                  t        d| j                  j                  z          y )N   r   ztest ztest2 ztest3 )ranger6   r   r"   r'   assertIsr&   r5   
TEST_TOOL2
TEST_TOOL3r$   	__class__r>   r0   tools     r	   setUpzMonitoringTestBase.setUpJ   s    !H 	ADS^^66t<a@	Acnn--i8$?cnn--j94@cnn--j94@""9g8O8O.OP"":x$..:Q:Q/QR"":x$..:Q:Q/QRr   c                 T   t        d      D ]1  }| j                  t        j                  j	                  |      d       3 t        j                  j                  t               t        j                  j                  t               t        j                  j                  t               y )NrD   r   )	rE   r6   r   r"   r'   r%   r5   rG   rH   rJ   s     r	   tearDownzMonitoringTestBase.tearDownU   sl    !H 	ADS^^66t<a@	A##I.##J/##J/r   N)r>   r?   r@   rL   rN   r   r   r	   rB   rB   H   s    	S0r   rB   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)MonitoringCountTestc                      G d d      } |       }t         j                  j                  t        ||       |t        j
                  k(  s|t        j                  k(  r3t         j                  j                  t        t        j                         n$t         j                  j                  t        |       | j                  |j                  d       d|_
         |        | j                  |j                  |       t         j                  j                  t        |d       }d|_
         |        | j                  |j                  d       | j                  ||       t         j                  j                  t        d       y )Nc                       e Zd Zd Zd Zy)6MonitoringCountTest.check_event_count.<locals>.Counterc                     d| _         y r   countr<   s    r	   __init__z?MonitoringCountTest.check_event_count.<locals>.Counter.__init__c   s	    
r   c                 .    | xj                   dz  c_         y Nr   rU   r0   argss     r	   __call__z?MonitoringCountTest.check_event_count.<locals>.Counter.__call__e   s    

a
r   Nr>   r?   r@   rW   r\   r   r   r	   CounterrS   b   s     r   r^   r   )r   r"   r+   r5   Er9   r:   r(   r;   r6   rV   )r0   funceventexpectedr^   counterprevs          r	   check_event_countz%MonitoringCountTest.check_event_count`   s    	  	  )((E7CAJJ%199"4NN%%i8NN%%i7*1~~//	5$G*w'!!)Q/r   c                 N    | j                  t        t        j                  d       y rY   )re   r
   r_   PY_STARTr<   s    r	   test_start_countz$MonitoringCountTest.test_start_county       r1::q1r   c                 N    | j                  t        t        j                  d       y Nr   )re   r   r_   	PY_RESUMEr<   s    r	   test_resume_countz%MonitoringCountTest.test_resume_count|       r1;;2r   c                 N    | j                  t        t        j                  d       y rY   )re   r
   r_   	PY_RETURNr<   s    r	   test_return_countz%MonitoringCountTest.test_return_count   rn   r   c                 N    | j                  t        t        j                  d       y )Nr   )re   r   r_   r;   r<   s    r	   test_call_countz#MonitoringCountTest.test_call_count   s    r1661-r   c                 N    | j                  t        t        j                  d       y rk   )re   r   r_   r9   r<   s    r	   test_c_return_countz'MonitoringCountTest.test_c_return_count   ri   r   N)	r>   r?   r@   re   rh   rm   rq   rs   ru   r   r   r	   rP   rP   ^   s     02233.2r   rP   startresumereturnyieldjumpbranchraiseunwindexception_handledc_raisec_returnc                       y r   r   r   r   r	   	just_passr      r   r   )py_callrv   rx   c                      t         r   	Exceptionr   r   r	   
just_raiser      s    
Or   )r   rv   r|   r}   c                      t        g        y r   r   r   r   r	   	just_callr      s	    Gr   )r   rv   c_callr   rx   c                  .    	 ddz   y # t         $ r Y y w xY wNr   r   r   r   r   r	   caughtr      s     	! s    	)r   rv   r|   r~   r{   rx   c                      t                y r   )r   r   r   r	   nested_callr      s    Kr   )r   rv   r   rv   rx   rx   c                       e Zd Zd ZddZy)MonitoringEventsBasec                    g t         D ]2  \  }}|dfd
}t        j                  j                  t        ||       4 fd}t        j                  j                  t        t
        j                  |       t        j                  j                  t        t               g 	  |        t        j                  j                  t        d       d d S #  Y /xY w)N)
event_namec                 (    j                  |        y r   append)r   r[   r#   s     r	   recordz2MonitoringEventsBase.gather_events.<locals>.record   s    j)r   c                 l    t        |t              rj                  d       y j                  d       y )Nr   r   )
isinstancePY_CALLABLESr   )codeoffsetobjargr#   s       r	   record_callz7MonitoringEventsBase.gather_events.<locals>.record_call   s%    #|,i(h'r   r   )	SIMPLE_EVENTSr   r"   r+   r5   r_   r;   r(   SIMPLE_EVENT_SET)r0   r`   ra   r   r   r   r#   s         @r	   gather_eventsz"MonitoringEventsBase.gather_events   s    !. 	GE:)3 *NN,,YvF	G	(
 	((AFFKH!!)-=>	F 	!!)Q/	s   "C CNc                 f    | j                  |      }||j                  }| j                  ||       y r   )r   r#   r6   )r0   r`   rb   r#   s       r	   check_eventsz!MonitoringEventsBase.check_events   s1    ##D){{H*r   r   )r>   r?   r@   r   r   r   r   r	   r   r      s    .+r   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)MonitoringEventsTestc                 .    | j                  t               y r   )r   r   r<   s    r	   test_just_passz#MonitoringEventsTest.test_just_pass       )$r   c                     	 | j                  t               | j                  t        j
                  j                  t              d       y # t        $ r Y ?w xY wr   )r   r   r   r6   r   r"   r'   r5   r<   s    r	   test_just_raisez$MonitoringEventsTest.test_just_raise  sJ    	j) 	229=qA  		s   A 	AAc                 .    | j                  t               y r   )r   r   r<   s    r	   test_just_callz#MonitoringEventsTest.test_just_call	  r   r   c                 .    | j                  t               y r   )r   r   r<   s    r	   test_caughtz MonitoringEventsTest.test_caught  s    &!r   c                 .    | j                  t               y r   )r   r   r<   s    r	   test_nested_callz%MonitoringEventsTest.test_nested_call  s    +&r   N)r>   r?   r@   r   r   r   r   r   r   r   r	   r   r      s    %B%"'r   r   )testfuncc                       e Zd Zd Zd Zy)SimulateProfileTestc                     | j                  t              }t        j                  |      }| j	                  |d   |d          | j	                  |d   |d   |d   z          | j	                  |d   |d   |d   z          y )Nr   r   rv   rx   r}   r|   r~   )r   r   collectionsr^   r6   )r0   r#   cs      r	   test_balancedz!SimulateProfileTest.test_balanced  s~    ##H-'8a
m47Qx[1X;%>?7Q':%;ak%IJr   c                    d | _         g g t               fd}fd}fd}t        D ]'  }t        j                  j                  t        ||       ) t        D ]'  }t        j                  j                  t        ||       ) t        j                  j                  t        t        j                  |       t        j                  j                  t        t               t                t        j                  j                  t        d       | j                  g        | j                  t        j                         g       | j                  t              d       y )Nc                      t        j                  d      }sj                  d       y j                         }||k7  rj                  d| d|        y y )Nr   emptyz	 Popping z
 expected )r   	_getframer   pop)r[   framerb   errorsstacks      r	   upz0SimulateProfileTest.test_frame_stack.<locals>.up%  sQ    MM!$Eg& 99;H$MMIeWJxj"IJ %r   c                      t        j                  d      }j                  |       j                  |j                         y rY   )r   r   r   addf_code)r[   r   seenr   s     r	   downz2SimulateProfileTest.test_frame_stack.<locals>.down-  s-    MM!$ELLHHU\\"r   c                 p    t        |t              s%j                  t        j                  d             y y rY   )r   r   r   r   r   )r   r   callabler   r   s       r	   callz2SimulateProfileTest.test_frame_stack.<locals>.call1  s'    h5S]]1-. 6r   r   	   )maxDiffset	UP_EVENTSr   r"   r+   r5   DOWN_EVENTSr_   r;   r(   r   r   r6   r   r   )r0   r   r   r   ra   r   r   r   s        @@@r	   test_frame_stackz$SimulateProfileTest.test_frame_stack   s    u	K	#	/  	CENN,,YrB	C  	EENN,,YtD	E((AFFDA!!)-=>
!!)Q/$ 12TA&r   N)r>   r?   r@   r   r   r   r   r	   r   r     s    K'r   r   c                       e Zd Zd Zd Zy)CounterWithDisablec                      d| _         d| _        y )NFr   )disablerV   r<   s    r	   rW   zCounterWithDisable.__init__C  s    
r   c                 z    | xj                   dz  c_         | j                  rt        j                  j                  S y rY   )rV   r   r   r"   r-   rZ   s     r	   r\   zCounterWithDisable.__call__G  s+    

a
<<>>))) r   Nr]   r   r   r	   r   r   A  s    *r   r   c                       e Zd Zd Zd Zy)RecorderWithDisablec                      d| _         || _        y )NF)r   r#   r0   r#   s     r	   rW   zRecorderWithDisable.__init__O  s    r   c                     | j                   j                  |       | j                  rt        j                  j
                  S y r   )r#   r   r   r   r"   r-   )r0   r   ra   s      r	   r\   zRecorderWithDisable.__call__S  s0    5!<<>>))) r   Nr]   r   r   r	   r   r   M  s    *r   r   c                       e Zd Zd Zd Zy)MontoringDisableAndRestartTestc                    	 t               }t        j                  j                  t        t
        j                  |       t        j                  j                  t        t
        j                         | j                  |j                  d       d|_	        t                | j                  |j                  d       d|_        d|_	        t                | j                  |j                  d       d|_	        t                | j                  |j                  d       t        j                  j                  t        d       t        j                  j                          y # t        j                  j                          w xY w)Nr   r   T)r   r   r"   r+   r5   r_   rg   r(   r6   rV   r
   r   r,   r0   rc   s     r	   test_disablez+MontoringDisableAndRestartTest.test_disable[  s    	,(*GNN,,Y

GLNN%%i<W]]A.GMDW]]A."GOGMDW]]A.GMDW]]A.NN%%i3NN))+CNN))+s   D=E  E>c                    	 t               }t        j                  j                  t        t
        j                  |       t        j                  j                  t        t
        j                         d|_        t                d|_
        t                | j                  |j                  d       t        j                  j                          d|_
        t                | j                  |j                  d       t        j                  j                  t        d       t        j                  j                          y # t        j                  j                          w xY w)NTr   r   )r   r   r"   r+   r5   r_   rg   r(   r   r
   rV   r6   r,   r   s     r	   test_restartz+MontoringDisableAndRestartTest.test_restarto  s    	,(*GNN,,Y

GLNN%%i<"GODGMDW]]A.NN))+GMDW]]A.NN%%i3NN))+CNN))+s   DD= = EN)r>   r?   r@   r   r   r   r   r	   r   r   Y  s    ,(,r   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)MultipleMonitorsTestc                    	 | j                  t        j                  j                         i        t	               }t	               }t        j                  j                  t        t        j                  |       t        j                  j                  t        t        j                  |       t        j                  j                  t        t        j                         t        j                  j                  t        t        j                         | j                  t        j                  j                  t              t        j                         | j                  t        j                  j                  t              t        j                         | j                  t        j                  j                         ddt        z  dt        z  z  i       d|_        d|_        t                |j                  }|j                  }| j                  ||fd       t        j                  j                  t        d       t        j                  j                  t        d       t        j                  j                  t        t        j                  d        t        j                  j                  t        t        j                  d        | j                  t        j                  j                         i        y # t        j                  j                  t        d       t        j                  j                  t        d       t        j                  j                  t        t        j                  d        t        j                  j                  t        t        j                  d        | j                  t        j                  j                         i        w xY w)Nrg   r   r   r   r   )r6   r   r"   _all_eventsr   r+   r5   r_   rg   rG   r(   r'   rV   r
   r0   counter1counter2count1count2s        r	   test_two_samez"MultipleMonitorsTest.test_two_same  s@   	?S^^7792>)+H)+HNN,,Y

HMNN,,ZXNNN%%i<NN%%j!**=S^^66yA1::NS^^66zBAJJOS^^779Ji\]ak\kHl;mnHNHND^^F^^Fff-v6NN%%i3NN%%j!4NN,,Y

DINN,,ZTJS^^7792>	 NN%%i3NN%%j!4NN,,Y

DINN,,ZTJS^^7792>s   HK2 2COc                 
   	 | j                  t        j                  j                         i        t	               }t	               }t	               }t        j                  j                  t        t        j                  |       t        j                  j                  t        t        j                  |       t        j                  j                  t        t        j                  |       t        j                  j                  t        t        j                         t        j                  j                  t        t        j                         t        j                  j                  t        t        j                         | j                  t        j                  j                  t              t        j                         | j                  t        j                  j                  t              t        j                         | j                  t        j                  j                  t              t        j                         | j                  t        j                  j                         ddt        z  dt        z  z  dt        z  z  i       d|_        d|_        d|_        t                |j                  }|j                  }|j                  }| j                  |||fd       t        j                  j                  t        d       t        j                  j                  t        d       t        j                  j                  t        d       t        j                  j                  t        t        j                  d        t        j                  j                  t        t        j                  d        t        j                  j                  t        t        j                  d        | j                  t        j                  j                         i        y # t        j                  j                  t        d       t        j                  j                  t        d       t        j                  j                  t        d       t        j                  j                  t        t        j                  d        t        j                  j                  t        t        j                  d        t        j                  j                  t        t        j                  d        | j                  t        j                  j                         i        w xY w)Nrg   r   r   )r   r   r   )r6   r   r"   r   r   r+   r5   r_   rg   rG   rH   r(   r'   rV   r
   )r0   r   r   counter3r   r   count3s          r	   test_three_samez$MultipleMonitorsTest.test_three_same  s!   	?S^^7792>)+H)+H)+HNN,,Y

HMNN,,ZXNNN,,ZXNNN%%i<NN%%j!**=NN%%j!**=S^^66yA1::NS^^66zBAJJOS^^66zBAJJOS^^779Ji\]ak\kHlpqup  IA  <B  CHNHNHND^^F^^F^^Ffff5yANN%%i3NN%%j!4NN%%j!4NN,,Y

DINN,,ZTJNN,,ZTJS^^7792> NN%%i3NN%%j!4NN%%j!4NN,,Y

DINN,,ZTJNN,,ZTJS^^7792>s   K!P D5Uc                    	 | j                  t        j                  j                         i        t	               }t	               }t        j                  j                  t        t        j                  |       t        j                  j                  t        t        j                  |       t        j                  j                  t        t        j                         t        j                  j                  t        t        j                         | j                  t        j                  j                  t              t        j                         | j                  t        j                  j                  t              t        j                         | j                  t        j                  j                         dt        z  dt        z  d       d|_        d|_        t                |j                  }|j                  }| j                  ||fd       t        j                  j                  t        d       t        j                  j                  t        d       t        j                  j                  t        t        j                  d        t        j                  j                  t        t        j                  d        | j                  t        j                  j                         i        y # t        j                  j                  t        d       t        j                  j                  t        d       t        j                  j                  t        t        j                  d        t        j                  j                  t        t        j                  d        | j                  t        j                  j                         i        w xY w)Nr   )rg   rp   r   r   )r6   r   r"   r   r   r+   r5   r_   rg   rG   rp   r(   r'   rV   r
   r   s        r	   test_two_differentz'MultipleMonitorsTest.test_two_different  s;   	?S^^7792>)+H)+HNN,,Y

HMNN,,ZhONN%%i<NN%%j!++>S^^66yA1::NS^^66zBAKKPS^^779Yefjtet;uvHNHND^^F^^Fff-v6NN%%i3NN%%j!4NN,,Y

DINN,,ZdKS^^7792>	 NN%%i3NN%%j!4NN,,Y

DINN,,ZdKS^^7792>s   HK0 0COc                    	 | j                  t        j                  j                         i        t	               }t	               }t        j                  j                  t        t        j                  |       t        j                  j                  t        t        j                  |       t        j                  j                  t        t        j                         t        j                  j                  t        t        j                         | j                  t        j                  j                  t              t        j                         | j                  t        j                  j                  t              t        j                         | j                  t        j                  j                         ddt        z  dt        z  z  i       d|_        d|_        d|_        t                |j                  }|j                  }| j                  ||fd       d|_        d|_        t                |j                  }|j                  }| j                  ||fd       t        j                  j                  t        d       t        j                  j                  t        d       t        j                  j                  t        t        j                  d        t        j                  j                  t        t        j                  d        | j                  t        j                  j                         i        t        j                  j                          y # t        j                  j                  t        d       t        j                  j                  t        d       t        j                  j                  t        t        j                  d        t        j                  j                  t        t        j                  d        | j                  t        j                  j                         i        t        j                  j                          w xY w)Nrg   r   r   Tr   r   )r6   r   r"   r   r   r+   r5   r_   rg   rG   r(   r'   rV   r   r
   r,   r   s        r	   test_two_with_disablez*MultipleMonitorsTest.test_two_with_disable  s   	,S^^7792>)+H)+HNN,,Y

HMNN,,ZXNNN%%i<NN%%j!**=S^^66yA1::NS^^66zBAJJOS^^779Ji\]ak\kHl;mnHNHN#HD^^F^^Fff-v6HNHND^^F^^Fff-v6NN%%i3NN%%j!4NN,,Y

DINN,,ZTJS^^7792>NN))+ NN%%i3NN%%j!4NN,,Y

DINN,,ZTJS^^7792>NN))+s   IM C<Qc                 P   d }|j                   }	 | j                  t        j                  j	                         i        t        j                  j                  t        |t        j                  t        j                  z         t        j                  j                  t        |t        j                         t        j                  j                  t        d       t        j                  j                  t        d       | j                  t        j                  j	                         i        y# t        j                  j                  t        d       t        j                  j                  t        d       | j                  t        j                  j	                         i        w xY w)zWTest that the second tool can set events with instruction events set by the first tool.c                       y r   r   r   r   r	   fz;MultipleMonitorsTest.test_with_instruction_event.<locals>.f  s    r   r   N)__code__r6   r   r"   r   r*   r5   r_   INSTRUCTIONLINErG   r(   )r0   r   r   s      r	   test_with_instruction_eventz0MultipleMonitorsTest.test_with_instruction_event  s    	zz	?S^^7792>NN++ItQ]]QVV=STNN++JaffENN%%i3NN%%j!4S^^7792> NN%%i3NN%%j!4S^^7792>s   B%D- -A8F%N)r>   r?   r@   r   r   r   r   r   r   r   r	   r   r     s    ?2?B?2,B?r   r   c                   :    e Zd Zd Zd Zd ZefdZd Zd Z	d Z
y)	LineMonitoringTestc                    	 | j                  t        j                  j                         i        g }t	        |      }t        j                  j                  t        t        j                  |       t        j                  j                  t        t        j                         t                t        j                  j                  t        d       t        j                  j                  t        t        j                  d        t        j                  j                  j                  }| j                  ||dz   d|dz   g       t        j                  j                  t        d       t        j                  j                  t        t        j                  d        | j                  t        j                  j                         i        t        j                  j                          y # t        j                  j                  t        d       t        j                  j                  t        t        j                  d        | j                  t        j                  j                         i        t        j                  j                          w xY w)Nr            )r6   r   r"   r   r   r+   r5   r_   r   r(   r
   r   test_lines_singler   co_firstlinenor,   r0   r#   recorderrv   s       r	   r  z$LineMonitoringTest.test_lines_single
  s   	,S^^7792>F*62HNN,,YINN%%i8DNN%%i3NN,,YE&88AAPPEVeAgr57%;<NN%%i3NN,,YES^^7792>NN))+ NN%%i3NN,,YES^^7792>NN))+s   E G& &B%Jc                 $   	 | j                  t        j                  j                         i        g }t	        |      }t        j                  j                  t        t        j                  |       t        j                  j                  t        t        j                         t                t        j                  j                  t        d       t        j                  j                  t        t        j                  d        t        j                  j                  j                  }| j                  ||dz   ddddd|dz   g       t        j                  j                  t        d       t        j                  j                  t        t        j                  d        | j                  t        j                  j                         i        t        j                  j                          y # t        j                  j                  t        d       t        j                  j                  t        t        j                  d        | j                  t        j                  j                         i        t        j                  j                          w xY w)Nr   r         r  )r6   r   r"   r   r   r+   r5   r_   r   r(   r   r   test_lines_loopr   r  r,   r  s       r	   r
  z"LineMonitoringTest.test_lines_loop  s   	,S^^7792>F*62HNN,,YINN%%i8GNN%%i3NN,,YE&66??NNEVeAgr2r2r57%KLNN%%i3NN,,YES^^7792>NN))+ NN%%i3NN,,YES^^7792>NN))+s   EG* *B%Jc                 2   	 | j                  t        j                  j                         i        g }t	        |      }g }t	        |      }t        j                  j                  t        t        j                  |       t        j                  j                  t        t        j                  |       t        j                  j                  t        t        j                         t        j                  j                  t        t        j                         t                t        j                  j                  t        d       t        j                  j                  t        d       t        j                  j                  t        t        j                  d        t        j                  j                  t        t        j                  d        t        j                  j                  j                  }|dz   d|dz   g}| j                  ||       | j                  ||       t        j                  j                  t        d       t        j                  j                  t        d       t        j                  j                  t        t        j                  d        t        j                  j                  t        t        j                  d        | j                  t        j                  j                         i        t        j                  j!                          y # t        j                  j                  t        d       t        j                  j                  t        d       t        j                  j                  t        t        j                  d        t        j                  j                  t        t        j                  d        | j                  t        j                  j                         i        t        j                  j!                          w xY w)Nr   
   r     )r6   r   r"   r   r   r+   r5   r_   r   rG   r(   r
   r   test_lines_twor   r  r,   )r0   r#   r  events2	recorder2rv   rb   s          r	   r  z!LineMonitoringTest.test_lines_two.  sk   	,S^^7792>F*62HG+G4INN,,YINN,,ZKNN%%i8#..:S:ST^`a`f`f:gDNN%%i3S^^5N5Nz[\5]NN,,YENN,,ZF&55>>MMEb"eBh/HVX.Wh/NN%%i3NN%%j!4NN,,YENN,,ZFS^^7792>NN))+ NN%%i3NN%%j!4NN,,YENN,,ZFS^^7792>NN))+s   HL C<Pc                    	 | j                  t        j                  j                         i        g }t	        |      }t        j                  j                  |t        j                  |       t        j                  j                  |t        j                          |        t        j                  j                  |d       t        j                  j                  |t        j                  d        |dd D cg c]  }||j                  j                  z
   }}| j                  ||       t        j                  j                  |d       y c c}w # t        j                  j                  |d       w xY w)Nr   r   r   )r6   r   r"   r   r   r+   r_   r   r(   r   r  )r0   r`   rb   rK   r#   r  lineliness           r	   check_lineszLineMonitoringTest.check_linesH  s   	/S^^7792>F*62HNN,,T1668DNN%%dAFF3FNN%%dA.NN,,T1664@FLQrlTddT]]999TETUH-NN%%dA. U NN%%dA.s   C5E 7 EE E "E3c                 2    d }| j                  |g d       y )Nc                      d} d} d} d} d} y )Nr   r   r   r      r   r  s    r	   r`   z,LineMonitoringTest.test_linear.<locals>.funcZ  s    DDDDDr   )r   r   r   r   r  r  r0   r`   s     r	   test_linearzLineMonitoringTest.test_linearX  s    	 	{+r   c                 2    d }| j                  |g d       y )Nc                  <    dj                  d      rd} d} d} y d} d} y )Ntruetr   r   r  rD   )
startswithr  s    r	   r`   z,LineMonitoringTest.test_branch.<locals>.funcd  s-      % D Dr   r   r   r   rD   r  r  s     r	   test_branchzLineMonitoringTest.test_branchc  s    	 	y)r   c                 `    d }| j                  |g d       d }| j                  |g d       y )Nc                  (    	 d} d} d} y #  d} Y d} y xY wNr   r   r  rD   r   r  s    r	   func1z1LineMonitoringTest.test_try_except.<locals>.func1p  s)     DDs   	 r!  c                  "    	 d} d#  d} Y d} y xY wr%  r   r  s    r	   func2z1LineMonitoringTest.test_try_except.<locals>.func2z  s"    Ds    )r   r   r   r   r  rD   r  )r0   r&  r(  s      r	   test_try_exceptz"LineMonitoringTest.test_try_exceptn  s0    	 		*	 	.r   N)r>   r?   r@   r  r
  r  r5   r  r  r"  r)  r   r   r	   r   r     s*    ,$,$,4 09 / 	,	*/r   r   c                   $    e Zd Zd Zd Zd Zd Zy)TestDisablec              #   B   K   t        d      D ]  }|rd 
d  y w)Nr  r   r   rE   )r0   condis      r	   r   zTestDisable.gen  s&     r 	A		s   c                     	 ddz   y #   xY wr   r   r<   s    r	   raise_handle_reraisez TestDisable.raise_handle_reraise  s    	aC	s    c                 h   t         D ]  \  }}	 t               }d|_        t        j                  j                  t        ||       t        j                  j                  t        |       | j                  d      D ]  } | j                  |j                  d       t        j                  j                  t        d       t        j                  j                  t        |d         y # t        j                  j                  t        d       t        j                  j                  t        |d        w xY w)NTr   r   r   )INSTRUMENTED_EVENTSr   r   r   r"   r+   r5   r(   r   
assertLessrV   )r0   ra   namerc   r   s        r	   test_disable_legal_eventsz%TestDisable.test_disable_legal_events  s    . 	IKE4
I,."&00E7K)))U;! Aq1)))Q700E4H	I )))Q700E4Hs   BC&&AD1c                 x   t         D ]  \  }}	 t               }d|_        t        j                  j                  t        ||       t        j                  j                  t        |       | j                  t              5  | j                          d d d        t        j                  j                  t        d       t        j                  j                  t        |d         y # 1 sw Y   UxY w# t        j                  j                  t        d       t        j                  j                  t        |d        w xY w)NTr   )EXCEPT_EVENTSr   r   r   r"   r+   r5   r(   r7   r8   r1  )r0   ra   r5  rc   s       r	   test_disable_illegal_eventsz'TestDisable.test_disable_illegal_events  s    ( 
	IKE4	I,."&00E7K)))U;&&z2 0--/0 )))Q700E4H
	I0 0 )))Q700E4Hs%   A/C.=C"C."C+	'C..AD9N)r>   r?   r@   r   r1  r6  r9  r   r   r	   r+  r+    s    IIr   r+  c                   0    e Zd Zej                  Zd Zd Zy)ExceptionRecorderc                     || _         y r   r#   r   s     r	   rW   zExceptionRecorder.__init__  	    r   c                 P    | j                   j                  dt        |      f       y )Nr|   r#   r   typer0   r   r   excs       r	   r\   zExceptionRecorder.__call__      GT#Y/0r   N)r>   r?   r@   r_   RAISE
event_typerW   r\   r   r   r	   r;  r;    s    J1r   r;  c                   &    e Zd Zd ZeeffdZd Zy)CheckEventsc                 .   	 | j                  t        j                  j                         i        g }d}|D ]:  }|j                  }t        j                  j                  || ||             ||z  }< t        j                  j                  ||        |        t        j                  j                  |d       |D ]-  }t        j                  j                  ||j                  d        / |t        j                  j                  |d       |D ]-  }t        j                  j                  ||j                  d        / S # t        j                  j                  |d       |D ]-  }t        j                  j                  ||j                  d        / w xY wr   )r6   r   r"   r   rF  r+   r(   )r0   r`   rK   	recorders
event_list
all_eventsr  evs           r	   r'   zCheckEvents.get_events  sS   	RS^^7792>JJ% !((00r8J;OPb 
! NN%%dJ7FNN%%dA.% R00x7J7JDQRNN%%dA.% R00x7J7JDQR NN%%dA.% R00x7J7JDQRs   C+E   AFc                     | j                  |||      }||k7  rt        |t        j                         | j	                  ||       y )N)file)r'   printr   stderrr6   )r0   r`   rb   rK   rJ  r#   s         r	   r   zCheckEvents.check_events  s:    tY7X&,*r   c                 :   | j                  |t        |      }| j                  t        |      dz  d       t	        |d d d   |dd d         D ]K  \  }}|d   }| j                  |d       |d   }| j                  |d       | j                  |d   |d          M y )Nr   r   r   )r|   reraise)handledr}   )r'   r5   r6   r   zipassertIn)r0   r`   rJ  r#   rhr0h0s           r	   check_balancedzCheckEvents.check_balanced  s    y)<VQ*ssF14a4L1 	)DAq1BMM"231BMM"34QqT1Q4(	)r   N)r>   r?   r@   r'   r5   r;  r   r[  r   r   r	   rH  rH    s    R( 1:FWEY +)r   rH  c                   $    e Zd Zej                  Zy)StopiterationRecorderN)r>   r?   r@   r_   STOP_ITERATIONrF  r   r   r	   r]  r]    s    !!Jr   r]  c                   *    e Zd Zej                  Zd Zy)ReraiseRecorderc                 P    | j                   j                  dt        |      f       y )NrS  r@  rB  s       r	   r\   zReraiseRecorder.__call__      ItCy12r   N)r>   r?   r@   r_   RERAISErF  r\   r   r   r	   r`  r`    s    J3r   r`  c                   *    e Zd Zej                  Zd Zy)UnwindRecorderc                 P    | j                   j                  dt        |      f       y )Nr}   r@  rB  s       r	   r\   zUnwindRecorder.__call__  s    Hd3i01r   N)r>   r?   r@   r_   	PY_UNWINDrF  r\   r   r   r	   re  re    s    J2r   re  c                   *    e Zd Zej                  Zd Zy)ExceptionHandledRecorderc                 P    | j                   j                  dt        |      f       y )NrT  r@  rB  s       r	   r\   z!ExceptionHandledRecorder.__call__  rb  r   N)r>   r?   r@   r_   EXCEPTION_HANDLEDrF  r\   r   r   r	   ri  ri    s    $$J3r   ri  c                   *    e Zd Zej                  Zd Zy)ThrowRecorderc                 P    | j                   j                  dt        |      f       y )Nthrowr@  rB  s       r	   r\   zThrowRecorder.__call__  rD  r   N)r>   r?   r@   r_   PY_THROWrF  r\   r   r   r	   rm  rm    s    J1r   rm  c                   n    e Zd ZeeeefZd Zd Z	de
fde
fgZde
fde
fgZd Zd Zd Zd	 Zd
 Zd Zd Zy)ExceptionMonitoringTestc                 <    d }| j                  |dt        fg       y )Nc                  *    	 d} t         #  d} Y d} y xY wNr   r  rD   KeyErrorr  s    r	   r&  z=ExceptionMonitoringTest.test_simple_try_except.<locals>.func1  "    D   
 r|   )r   rw  r0   r&  s     r	   test_simple_try_exceptz.ExceptionMonitoringTest.test_simple_try_except  s!    	 	%7H"5!67r   c                 V    d fd}| j                  |dt        fgt        f       y )Nc               3      K   d ywNr   r   r   r   r   r	   r   zAExceptionMonitoringTest.test_implicit_stop_iteration.<locals>.gen  s     Gs   c                              D ]  }  y r   r   )r   r   s    r	   implicit_stop_iterationzUExceptionMonitoringTest.test_implicit_stop_iteration.<locals>.implicit_stop_iteration  s    U r   r|   rJ  )r   StopIterationr]  )r0   r  r   s     @r	   test_implicit_stop_iterationz4ExceptionMonitoringTest.test_implicit_stop_iteration  s1    		 	1Wm4L3MZoYqrr   r|   rT  rS  c                 D    d }| j                  || j                         y )Nc                  ,    	 	 ddz   y #   xY w#  Y y xY wr   r   r   r   r	   r`   z;ExceptionMonitoringTest.test_explicit_reraise.<locals>.func/  s&    aCs   	  r  r[  exception_recordersr  s     r	   test_explicit_reraisez-ExceptionMonitoringTest.test_explicit_reraise-  (    	 	00 	 	2r   c                 D    d }| j                  || j                         y )Nc                  D    	 	 ddz   y # t         $ r}  d } ~ ww xY w#  Y y xY wr   r   exs    r	   r`   zAExceptionMonitoringTest.test_explicit_reraise_named.<locals>.func>  s/    aC  s   	 	 r  r  r  s     r	   test_explicit_reraise_namedz3ExceptionMonitoringTest.test_explicit_reraise_named<  r  r   c                 D    d }| j                  || j                         y )Nc                  >    	 	 ddz   y # t         $ r Y y w xY w#  Y y xY wr   r8   r   r   r	   r`   z;ExceptionMonitoringTest.test_implicit_reraise.<locals>.funcM  s.    aC! s   	 	  r  r  r  s     r	   test_implicit_reraisez-ExceptionMonitoringTest.test_implicit_reraiseK  r  r   c                 D    d }| j                  || j                         y )Nc                  L    	 	 ddz   y # t         $ r
} Y d } ~ y d } ~ ww xY w#  Y y xY wr   r  r  s    r	   r`   zAExceptionMonitoringTest.test_implicit_reraise_named.<locals>.func]  s/    aC! s   	 	  #r  r  r  s     r	   test_implicit_reraise_namedz3ExceptionMonitoringTest.test_implicit_reraise_named[  r  r   c                 D    d }| j                  || j                         y )Nc                  *    	 	 ddz   y # w xY w#  Y y xY wr   r   r   r   r	   r`   z6ExceptionMonitoringTest.test_try_finally.<locals>.funcl  s#    aCDs   	  r  r  r  s     r	   test_try_finallyz(ExceptionMonitoringTest.test_try_finallyj  r  r   c                 D    d }| j                  || j                         y )Nc                  b    d fd} 	  |        j                  d        y # t        $ r Y y w xY w)Nc                 6   K   t        d      D ]  } t         y wrY   )rE   ZeroDivisionError)r/  s    r	   async_generatorzMExceptionMonitoringTest.test_async_for.<locals>.func.<locals>.async_generator}  s     q A++s   c                  V   K   	         2 3 d {   } 
7 6 y # t         $ r Y y w xY wwr   r   )r   r  s    r	   
async_loopzHExceptionMonitoringTest.test_async_for.<locals>.func.<locals>.async_loop  s;     &5&7  d&7  s4   )   )	&)&))sendr  )r  r  s    @r	   r`   z4ExceptionMonitoringTest.test_async_for.<locals>.func{  s4    
!!$'  s   " 	..r  r  r  s     r	   test_async_forz&ExceptionMonitoringTest.test_async_fory  s(    	& 	00 	 	2r   c                     d fd}| j                  || j                         | j                  |t        | j                  t        fz         }| j                  |d   dt        f       y )Nc               3      K   d d y wr~  r   r   r   r	   r   z/ExceptionMonitoringTest.test_throw.<locals>.gen  s     GGr   c                  t    	         } t        |        | j                  t               y # t        $ r Y y w xY wr   )nextro  
IndexError)gr   s    r	   r`   z0ExceptionMonitoringTest.test_throw.<locals>.func  s4    EQ
# s   '+ 	77r  r   ro  )r[  r  r'   r5   rm  r6   r  )r0   r`   r#   r   s      @r	   
test_throwz"ExceptionMonitoringTest.test_throw  sp    		 	00 	 	2 $$'77

 	Wj$9:r   N)r>   r?   r@   r;  r`  ri  re  r  r{  r  r  initialrS  r  r  r  r  r  r  r  r   r   r	   rr  rr    s|     	 	
8
s 
#$	%&G 
%&	%&G
222 2222;r   rr  c                   0    e Zd Zej                  Zd Zd Zy)LineRecorderc                     || _         y r   r=  r   s     r	   rW   zLineRecorder.__init__  r>  r   c                 n    | j                   j                  d|j                  ||j                  z
  f       y )Nr  )r#   r   co_namer  )r0   r   r  s      r	   r\   zLineRecorder.__call__  s*    FDLL$9L9L2LMNr   N)r>   r?   r@   r_   r   rF  rW   r\   r   r   r	   r  r    s    JOr   r  c                   0    e Zd Zej                  Zd Zd Zy)CallRecorderc                     || _         y r   r=  r   s     r	   rW   zCallRecorder.__init__  r>  r   c                 T    | j                   j                  d|j                  |f       y )Nr   )r#   r   r>   r0   r   r   r`   r   s        r	   r\   zCallRecorder.__call__  s    FDMM378r   N)r>   r?   r@   r_   r;   rF  rW   r\   r   r   r	   r  r    s    J9r   r  c                       e Zd Zd Zd Zy)CEventRecorderc                     || _         y r   r=  r   s     r	   rW   zCEventRecorder.__init__  r>  r   c                 h    | j                   j                  | j                  |j                  |f       y r   )r#   r   r   r>   r  s        r	   r\   zCEventRecorder.__call__  s#    DOOT]]C@Ar   Nr]   r   r   r	   r  r    s    Br   r  c                   (    e Zd Zej                  ZdZy)CReturnRecorderC returnN)r>   r?   r@   r_   r9   rF  r   r   r   r	   r  r    s    JJr   r  c                   (    e Zd Zej                  ZdZy)CRaiseRecorderC raiseN)r>   r?   r@   r_   r:   rF  r   r   r   r	   r  r    s    JJr   r  c                       e Zd Zd Zd Zd Zy)TestManyEventsc                 ~    d }| j                  |t        dddt        j                  j                  fddddd	g
       y )Nc                      d} d}d}y Nr   r   r   r   line1line2line3s      r	   r&  z)TestManyEvents.test_simple.<locals>.func1      EEEr   r  r'   r  r   r&  r  r&  r   r  r&  r   r  r&  r   r  r'   r  r   r(   r   rJ  rb   r   MANY_RECORDERSr   r"   r.   rz  s     r	   test_simplezTestManyEvents.test_simple  sJ    	
 	%^&Wcnn445   &%I' 	(r   c                     d }| j                  |t        dddt        j                  j                  fdddddgfd	ddgfd
ddg	       y )Nc                  .    d} g j                  d       d}y r  r   r  r  s     r	   r(  z)TestManyEvents.test_c_call.<locals>.func2      EIIaLEr   r  r   r(  r  r(  r   r  r(  r   r   r   r  r  r(  r   r  r  r  r  r0   r(  s     r	   test_c_callzTestManyEvents.test_c_call  sb    	
 	%^&Wcnn445  Xs#A3' &%	I' 		(r   c                     d }| j                  |t        dddt        j                  j                  fddddt
        fd	d
dddg       y )Nc                  *    	 d} t         #  d} Y d} y xY wru  rv  r  s    r	   func3z-TestManyEvents.test_try_except.<locals>.func3  rx  ry  r  r   r  r  r  r   r  r  r   r  r  r   r|   r  r  r   r  r  r  r  r  rD   r  r  r  )r   r  r   r"   r.   rw  r0   r  s     r	   r)  zTestManyEvents.test_try_except  s[    	 	%^&Wcnn445   h   &%I' 	(r   N)r>   r?   r@   r  r  r)  r   r   r	   r  r    s    ( ($(r   r  c                   0    e Zd Zej                  Zd Zd Zy)InstructionRecorderc                     || _         y r   r=  r   s     r	   rW   zInstructionRecorder.__init__  r>  r   c                 t    |j                   dk7  r)| j                  j                  d|j                   |f       y y )Nr'   instruction)r  r#   r   )r0   r   r   s      r	   r\   zInstructionRecorder.__call__  s0    <<<'KKt||VDE (r   N)r>   r?   r@   r_   r   rF  rW   r\   r   r   r	   r  r    s    JFr   r  c                   (    e Zd ZdZd Zd Zd Zd Zy)TestLineAndInstructionEventsNc                 >    d }| j                  |t        g d       y )Nc                      d} d}d}y r  r   r  s      r	   r&  z7TestLineAndInstructionEvents.test_simple.<locals>.func1#  r  r   r  r  r  r&  r   r  r&  r   r  r  r&  rD   )r  r&  r  r  )r  r&  r  )r  r&     )r  r&     r  r  r   LINE_AND_INSTRUCTION_RECORDERSrz  s     r	   r  z(TestLineAndInstructionEvents.test_simple!  s%    	
 	%-K Y( 	)r   c                 >    d }| j                  |t        g d       y )Nc                  .    d} g j                  d       d}y r  r   r  s     r	   r(  z7TestLineAndInstructionEvents.test_c_call.<locals>.func28  r  r   )r  r  r  r(  r   )r  r(  r   r  )r  r(  rD   )r  r(  r  )r  r(     )r  r(     )r  r(  &   r  )r  r(  (   )r  r(  *   )r  r(  ,   r  r  r  r  s     r	   r  z(TestLineAndInstructionEvents.test_c_call6  s%    	
 	%-K Y( 	)r   c                 >    d }| j                  |t        g d       y )Nc                  *    	 d} t         #  d} Y d} y xY wru  rv  r  s    r	   r  z;TestLineAndInstructionEvents.test_try_except.<locals>.func3P  rx  ry  )r  r  )r  r  r   r  )r  r  r   )r  r  rD   r  )r  r  r  )r  r     )r  r     r  )r  r     r  )r  r  r	  )r  r     )r  r  r  r  )r  r  r  )r  r      )r  r  "   r  r  r  r  s     r	   r)  z,TestLineAndInstructionEvents.test_try_exceptN  s%    	 	%-K Y( 	)r   c                     d }| j                  |t        g d       t        j                  j	                          | j                  |t        g d       y )Nc                      d} d}d}y r  r   r  s      r	   r&  z=TestLineAndInstructionEvents.test_with_restart.<locals>.func1p  r  r   r  r  )r   r  r   r"   r,   rz  s     r	   test_with_restartz.TestLineAndInstructionEvents.test_with_restarto  sS    	
 	%-K Y( 	) 	%%'%-K Y( 	)r   )r>   r?   r@   r   r  r  r)  r	  r   r   r	   r  r    s    G)*)0)B")r   r  c                       e Zd ZeeffdZed        Zg dZd Z	d Z
ed        Zddd	ej                  j                  fd
ddgZd Zd Zy)TestInstallIncrementallyc                 ~   	 | j                  t        j                  j                         i        g }d}|D ]1  }||j                  z  }t        j                  j                  ||       3 |D ]3  }t        j                  j                  ||j                   ||             5  |        t        j                  j                  |d       |D ]-  }t        j                  j                  ||j                  d        / |D ]  }| j                  ||        	 t        j                  j                  |d       |D ]-  }t        j                  j                  ||j                  d        / y # t        j                  j                  |d       |D ]-  }t        j                  j                  ||j                  d        / w xY wr   )r6   r   r"   r   rF  r(   r+   rV  )	r0   r`   must_includerK   rJ  rK  rL  r  r  s	            r	   r   z%TestInstallIncrementally.check_events  s   	RS^^7792>JJ% <h111
))$
;< & b00x7J7JHU_L`abFNN%%dA.% R00x7J7JDQR$ 0dJ/0 NN%%dA.% R00x7J7JDQR NN%%dA.% R00x7J7JDQRs   DE( (AF<c                      d} y rY   r   )r  s    r	   r&  zTestInstallIncrementally.func1  s    r   )r  r  r  r  c                 l    t         t        g}| j                  | j                  || j                         y N)rJ  r  )r  r  r   r&  MUST_INCLUDE_LIr0   rJ  s     r	   test_line_then_instructionz3TestInstallIncrementally.test_line_then_instruction  2    "$79	$**&/@T@T 	 	Vr   c                 l    t         t        g}| j                  | j                  || j                         y r  )r  r  r   r&  r  r  s     r	   test_instruction_then_linez3TestInstallIncrementally.test_instruction_then_line  1    )<9	$**&/@T@T 	 	Vr   c                      t        d       y )Nr   r   r   r   r	   r(  zTestInstallIncrementally.func2  s	    Br   r  r   r(  )r   r   r   )r  r(  r  )r  r(  r  c                 l    t         t        g}| j                  | j                  || j                         y r  )r  r  r   r(  MUST_INCLUDE_CIr  s     r	   test_call_then_instructionz3TestInstallIncrementally.test_call_then_instruction  r  r   c                 l    t         t        g}| j                  | j                  || j                         y r  )r  r  r   r(  r  r  s     r	   test_instruction_then_callz3TestInstallIncrementally.test_instruction_then_call  r  r   N)r>   r?   r@   r5   r;  r   staticmethodr&  r  r  r  r(  r   r"   r.   r  r  r  r   r   r	   r  r    s    4=J[I] R*  )OV
V
   (Wcnn445((*OV
Vr   r  c                   0    e Zd ZedfdZd Zd Zd Zd Zy)TestLocalEventsr   c                    	 | j                  t        j                  j                         i        g }d}|D ]:  }|j                  }t        j                  j                  || ||             ||z  }< t        j                  j                  ||j                  |        |        t        j                  j                  ||j                  d       |D ]-  }t        j                  j                  ||j                  d        / | j                  ||       t        j                  j                  ||j                  d       |D ]-  }t        j                  j                  ||j                  d        / y # t        j                  j                  ||j                  d       |D ]-  }t        j                  j                  ||j                  d        / w xY wr   )r6   r   r"   r   rF  r+   r*   r   )	r0   r`   rb   rK   rJ  rK  rL  r  rM  s	            r	   r   zTestLocalEvents.check_events  sx   	RS^^7792>JJ% !((00r8J;OPb 
! NN++D$--LFNN++D$--C% R00x7J7JDQRZ2NN++D$--C% R00x7J7JDQR NN++D$--C% R00x7J7JDQRs   DE2 2AGc                 >    d }| j                  |t        g d       y )Nc                      d} d}d}y r  r   r  s      r	   r&  z*TestLocalEvents.test_simple.<locals>.func1  r  r   )r  r  r  r  r   LOCAL_RECORDERSrz  s     r	   r  zTestLocalEvents.test_simple  s$    	
 	%_ J" 	#r   c           
      T    d }| j                  |t        dddddgfdddgfdg	       y )
Nc                  .    d} g j                  d       d}y r  r   r  s     r	   r(  z*TestLocalEvents.test_c_call.<locals>.func2  r  r   r  r  r   r   r   r  r  r  r$  r  s     r	   r  zTestLocalEvents.test_c_call  sE    	
 	%_  Xs#A3' J" 	#r   c                 >    d }| j                  |t        g d       y )Nc                  *    	 d} t         #  d} Y d} y xY wru  rv  r  s    r	   r  z.TestLocalEvents.test_try_except.<locals>.func3
  rx  ry  )r  r  r  r  r  r  r  r$  r  s     r	   r)  zTestLocalEvents.test_try_except  s$    	 	%_ J" 	#r   c                     | j                  t              5  t        j                  j	                  t
        t        j                  t        j                         d d d        y # 1 sw Y   y xY wr   )
r7   r8   r   r"   r*   r5   r   r   r_   rE  r<   s    r	   test_set_non_local_eventz(TestLocalEvents.test_set_non_local_event  sI    z* 	TNN++Iy7I7I177S	T 	T 	Ts   AA!!A*N)	r>   r?   r@   r5   r   r  r  r)  r+  r   r   r	   r   r     s"    09R R*
###$Tr   r   c                     | j                         D ]/  \  }}}||cxk  r|k  sn |d| dc S || j                  z
  c S  y)Nz[offset=]r   )co_linesr  )r   r   rv   endr  s        r	   line_from_offsetr0    sU     MMO .sDF S |!&++$----	.
 r   c                   4    e Zd Zej                  ZdZd Zd Zy)JumpRecorderrz   c                     || _         y r   r=  r   s     r	   rW   zJumpRecorder.__init__+  r>  r   c                     t        ||      }t        ||      }| j                  j                  | j                  |j                  ||f       y r   )r0  r#   r   r5  r  )r0   r   from_to	from_lineto_lines         r	   r\   zJumpRecorder.__call__.  s=    $T51	"4,DIIt||YHIr   N)	r>   r?   r@   r_   JUMPrF  r5  rW   r\   r   r   r	   r2  r2  &  s    JDJr   r2  c                   (    e Zd Zej                  ZdZy)BranchRecorderr{   N)r>   r?   r@   r_   BRANCHrF  r5  r   r   r	   r;  r;  4  s    JDr   r;  c                   0    e Zd Zej                  Zd Zd Zy)ReturnRecorderc                     || _         y r   r=  r   s     r	   rW   zReturnRecorder.__init__=  r>  r   c                 >    | j                   j                  d|f       y )Nrx   )r#   r   )r0   r   r   vals       r	   r\   zReturnRecorder.__call__@  s    Hc?+r   N)r>   r?   r@   r_   rp   rF  rW   r\   r   r   r	   r>  r>  9  s    J,r   r>  c                       e Zd ZdZd Zd Zy)TestBranchAndJumpEventsNc                 r    d }| j                  |t        g d       | j                  |t        g d       y )Nc                  6    d} t        d      D ]	  }|rd} d}  y )Nr   r   r   rD   r-  )xas     r	   r`   z/TestBranchAndJumpEvents.test_loop.<locals>.funcM  s'    A1X AA	r   )r{   r`   r   r   r{   r`   r   rD   rz   r`   rD   r   rH  r{   r`   r   r   rz   r`   r   r   rH  r  )r  r  r`   r   r  r`   r   rH  r  r`   r   rI  )r  r`   rD   rJ  rN  rH  rO  rK  r  r`   r   rL  rN  rH  r  )r   JUMP_AND_BRANCH_RECORDERSJUMP_BRANCH_AND_LINE_RECORDERSr  s     r	   	test_loopz!TestBranchAndJumpEvents.test_loopK  sC    	 	$,E S& 	' 	$,J X( 	)r   c                      G d d      fd}| j                  |t        g d       | j                  |t        dddd	d
t        fddddddddddg       y )Nc                       e Zd Zd Zy)5TestBranchAndJumpEvents.test_except_star.<locals>.Fooc                      y r   r   r<   s    r	   methz:TestBranchAndJumpEvents.test_except_star.<locals>.Foo.metht  s    r   N)r>   r?   r@   rX  r   r   r	   FoorV  s  s    r   rY  c                      	 	 t         # g xt        % x#}         }|j                          d } ~ nd } ~  nn x Y y cY w xY w# t         $ r Y y w xY wr   )rw  r   rX  )er   rY  s     r	   r`   z6TestBranchAndJumpEvents.test_except_star.<locals>.funcw  sK    ("N(	 (Aqvvxxx( s)   
 A1	AA  A 	AA)r  rM  rN  rO  rP  r{   r`   r   r   r  r`   r  r  rX  r   rz   r`   r  r  rz   r`   r  z[offset=114]r{   r`   z[offset=120]z[offset=122]r  r  r  rM  rN  rO  r|   rP  r\  r]  r^  )rx   Nr_  r`  ra  r  )r   rR  FLOW_AND_LINE_RECORDERSrw  )r0   r`   rY  s     @r	   test_except_starz(TestBranchAndJumpEvents.test_except_starq  s    	 		 	$,J X( 	) 	$,C&h$"/>&Q( 	)r   )r>   r?   r@   r   rS  rc  r   r   r	   rC  rC  H  s    G$)L-)r   rC  c                   \    e Zd ZeeeefZd ZddZ	d Z
ddZd ZddZd ZddZd	 Zd
 Zy)TestLoadSuperAttrc                 $    i }t        |||       |S r   )exec)r0   cods      r	   _execzTestLoadSuperAttr._exec  s    RAr   c                     |rdnd}| dt        j                  |       }t        |dd      }| j                  | j	                  |      |       | j                  |      S )Nzx = 1zsuper = super
<string>rg  )textwrapdedentcompiler6   _has_load_super_attrrj  )r0   codestr	optimized
assignmentrh  s        r	   _exec_superzTestLoadSuperAttr._exec_super  s^     !*W
L8??7#;"<=Wj&12226	Bzz"~r   c                      t        d t        j                  |      D              }|st         fd|j                  D              }|S )Nc              3   :   K   | ]  }|j                   d k(    yw)LOAD_SUPER_ATTRN)opname).0instrs     r	   	<genexpr>z9TestLoadSuperAttr._has_load_super_attr.<locals>.<genexpr>  s     Z%,,"33Zs   c              3   x   K   | ]1  }t        |t        j                        xr j                  |       3 y wr   )r   typesCodeTyperq  )rz  r   r0   s     r	   r|  z9TestLoadSuperAttr._has_load_super_attr.<locals>.<genexpr>  s7       1enn-N$2K2KA2NNs   7:)anydisget_instructions	co_consts)r0   rh  hass   `  r	   rq  z&TestLoadSuperAttr._has_load_super_attr  sD    ZAUAUVXAYZZ  C 
r   c                    d}| j                  ||      }dddt        j                  j                  fddd|d   fddd	t        j                  j                  fd
d	t        j                  j                  fddddddddg}|d   |fS )Na[  
            class A:
                def method(self, x):
                    return x

            class B(A):
                def method(self, x):
                    return super(
                    ).method(
                        x
                    )

            b = B()
            def f():
                return b.method(1)
        r  r   r   r  r   r   methodbr  r  r   superr  r  r  r   r  r  r   )r   r  r   r  r  ru  r   r"   r.   r0   rs  rr  ri  rb   s        r	   _super_method_callz$TestLoadSuperAttr._super_method_call  s      Wi0&S#..001Xqv&!Wcnn445#.."8"89!!!!!!&%
" vxr   c                     | j                  d      \  }}| j                  d      \  }}| j                  || j                  |       | j                  || j                  |       y NF)rs  Tr  )r  r   	RECORDERSr0   nonopt_funcnonopt_expectedopt_funcopt_expecteds        r	   test_method_callz"TestLoadSuperAttr.test_method_call  sd    '+'>'>'>'O$_!%!8!84!8!H,+/Z(dnn|Tr   c                     d}| j                  ||      }dddt        j                  j                  fdddd|d   fd	d
dd	ddddddg}|d   |fS )Na?  
            class A:
                def method(self, x):
                    return x

            class B(A):
                def method(self, x):
                    return super(
                        x,
                        self,
                    ).method(
                        x
                    )

            b = B()
            def f():
                try:
                    return b.method(1)
                except TypeError:
                    pass
                else:
                    assert False, "should have raised TypeError"
        r  r   r   r  )r  r   r   r  r  r  r  r  )r   r  r   )r  r  r   )r  r   r   )r  r   r   r  r  r  r  s        r	   _super_method_call_errorz*TestLoadSuperAttr._super_method_call_error  s~    . Wi0&S#..001Xqv&!!!! #&%
" vxr   c                     | j                  d      \  }}| j                  d      \  }}| j                  || j                  |       | j                  || j                  |       y r  )r  r   r  r  s        r	   test_method_call_errorz(TestLoadSuperAttr.test_method_call_error  sd    '+'D'Du'D'U$_!%!>!>!>!N,+/Z(dnn|Tr   c                     d}| j                  ||      }dddt        j                  j                  fddd|d   fddd	t        j                  j                  fd
d	t        j                  j                  fddddg}|d   |fS )Nz
            class A:
                x = 1

            class B(A):
                def method(self):
                    return super(
                    ).x

            b = B()
            def f():
                return b.method()
        r  r   r   r  r  r  r  r  r  r  r  r  r  r  s        r	   _super_attrzTestLoadSuperAttr._super_attr  s     Wi0&S#..001Xqv&!Wcnn445#.."8"89!!&%
 vxr   c                     | j                  d      \  }}| j                  d      \  }}| j                  || j                  |       | j                  || j                  |       y r  )r  r   r  r  s        r	   	test_attrzTestLoadSuperAttr.test_attr<  sd    '+'7'7%'7'H$_!%!1!1D!1!A,+/Z(dnn|Tr   c                 *   t        j                  d      }d }dD ]  }| j                  |      5  |rdnd}|j                  d|      }|j                  d	|      }t	        |d
d      }| j                  | j                  |             | j                  |      }| j                  |      }	| j                  |d   | j                   |d||             | j                  |	d   | j                   |d	||	             d d d         y # 1 sw Y   xY w)Nz
            class C:
                def method(self):
                    return {cls}().__repr__{call}
            c = C()
            def f():
                return c.method()
        c           	      (   | dk(  rdnt         j                  j                  }dddt         j                  j                  fddd|d   fd	d| t         j                  j                  fd
| t         j                  j                  fg|r
dd|fd
d|fgng ddS )Nintr   r  r   r   r  r  r   r  r  __repr__r  r  )r   r"   r.   )r5  call_methodnsrepr_args       r	   get_expectedz?TestLoadSuperAttr.test_vs_other_type_call.<locals>.get_expectedM  s     EMqs~~/E/EH*cnn445 2c7+%s~~556T3>>#9#9: %  X6#Z: +- + * r   )TF)r  z() r  )clsr   r  rm  rg  r   r  )
rn  ro  subTestformatrp  
assertTruerq  rj  r   r  )
r0   code_templater  r  call_str
code_supercode_intco_superns_superns_ints
             r	   test_vs_other_type_callz)TestLoadSuperAttr.test_vs_other_type_callC  s#     ) 	( ) 	K+6 #.4B*11gH1M
(//E/I":z6B 9 9( CD::h/H-!!SM"nn)';I " 
 !!3K"nn)%fE "  	 s   CD		D	N)F)r>   r?   r@   r  r  r  r  r  rj  ru  rq  r  r  r  r  r  r  r  r   r   r	   re  re    sG    lNOKI
# JU* XU <U1r   re  c                       e Zd Zd Zd Zy)TestSetGetEventsc                 ,   t         j                  j                  t        t        j
                         | j                  t         j                  j                  t              t        j
                         t         j                  j                  t        t        j
                         | j                  t         j                  j                  t              t        j
                         t         j                  j                  t        d       | j                  t         j                  j                  t              d       t         j                  j                  t        d       | j                  t         j                  j                  t              d       y r   )	r   r"   r(   r5   r_   rg   r6   r'   rG   r<   s    r	   test_globalzTestSetGetEvents.test_globaly  s    !!)QZZ8229=qzzJ!!*ajj922:>

K!!)Q/229=qA!!*Q/22:>Br   c                 \   t         j                  }t        j                  j	                  t
        |t        j                         | j                  t        j                  j                  t
        |      t        j                         t        j                  j	                  t        |t        j                         | j                  t        j                  j                  t        |      t        j                         t        j                  j	                  t
        |d       | j                  t        j                  j                  t
        |      d       t        j                  j	                  t        |d       | j                  t        j                  j                  t        |      d       y r   )r
   r   r   r"   r*   r5   r_   rg   r6   r)   rG   )r0   r   s     r	   
test_localzTestSetGetEvents.test_local  s    {{''	4D88DI1::V''
D!**E88TJAJJW''	4;88DI1M''
D!<88TJANr   N)r>   r?   r@   r  r  r   r   r	   r  r  w  s    C	Or   r  c                   "    e Zd Zed        Zd Zy)TestUninitializedc                       y r   r   r   r   r	   r   zTestUninitialized.f  s    r   c                     | j                  t        j                  j                  t        | j
                  j                        d       y r   )r6   r   r"   r)   r5   r   r   r<   s    r	   #test_get_local_events_uninitializedz5TestUninitialized.test_get_local_events_uninitialized  s,    88DFFOOTVWXr   N)r>   r?   r@   r  r   r  r   r   r	   r  r    s     Yr   r  c                   $    e Zd Zd Zd Zd Zd Zy)TestRegressionsc                    d fdfdfd} |        | j                  d       d 	 t        j                  j                  t        t
        j                          |        | j                  d       t        j                  j                  t        d       y # t        j                  j                  t        d       w xY w)Nc               3   B   K   	 d  y # t         $ r	 d d  Y y w xY ww)Ninnerr   )r   s   r	   r  z*TestRegressions.test_105162.<locals>.inner  s%       s   
 c               3   \   K   	         E d {    y 7 # t         $ r	 d d  Y y w xY ww)Nouterr   )r   r  s   r	   r  z*TestRegressions.test_105162.<locals>.outer  s-      7""  s(   ,
  , ),),c                  `            } | j                  d        | j                  t               y r   )r  ro  r   )r   r  s    r	   runz(TestRegressions.test_105162.<locals>.run  s!    'CHHTNIIi r   r  r   )r6   r   r"   r(   r5   r_   rl   )r0   r  r   r  r  s     @@@r	   test_105162zTestRegressions.test_105162  s    			! 	)	4NN%%i=EVW-NN%%i3CNN%%i3s   AB" "&Cc                      G d d      fd}	  |        t         j                  j                  t        d       y # t         j                  j                  t        d       w xY w)Nc                       e Zd Zd Zy)(TestRegressions.test_108390.<locals>.Fooc                 n    |r3t         j                  j                  t        t        j
                         y y r   )r   r"   r(   r5   r_   rl   )r0   	set_events     r	   rW   z1TestRegressions.test_108390.<locals>.Foo.__init__  s"    NN--iE r   N)r>   r?   r@   rW   r   r   r	   rY  r    s    Fr   rY  c                  <    t        d      D ]  }  | dk(          y )Nd   c   r-  )r/  rY  s    r	   !make_foo_optimized_then_set_eventzFTestRegressions.test_108390.<locals>.make_foo_optimized_then_set_event  s!    3Z AGr   r   )r   r"   r(   r5   )r0   r  rY  s     @r	   test_108390zTestRegressions.test_108390  sH    	F 	F
		4-/NN%%i3CNN%%i3s	   > &A$c                 V   t         j                  j                  dd       | j                  t         j                  j                  d       t         j                  j                  dd       t         j                  j                  dt        j                  d        t         j                  j                  dt        j                  d        t         j                  j                  dt        j                  t        j                  z         t         j                  j                  dd       y )Nr   testc                  B    t         j                  j                  dd      S r   )r   r"   r(   r[   s    r	   <lambda>z/TestRegressions.test_gh108976.<locals>.<lambda>  s    #..B[B[\]_`Ba r   c                       yr   r   r  s    r	   r  z/TestRegressions.test_gh108976.<locals>.<lambda>  s    r   )
r   r"   r$   
addCleanupr%   r(   r+   r_   r   r   r<   s    r	   test_gh108976zTestRegressions.test_gh108976  s    ""1f-33Q7!!!Q'((AFF4ab((AMM?K!!!QVVamm%;<!!!Q'r   c                    dd}d}g }g t         j                  j                  dd       | j                  t         j                  j                  d       t         j                  j                  dd       t         j                  j                  dt        j                  fd       t         j                  j                  dt        j                          ||   ||  t         j                  j                  dd       | j                  d   |df       | j                  d   |t         j                  j                  f       y )Nr   c                     | |z   S r   r   )rG  r  s     r	   r   z0TestRegressions.test_call_function_ex.<locals>.f  s    q5Lr   )r   r   r   r  c                 *    j                  ||f      S r   r   )r   r   r   arg0	call_datas       r	   r  z7TestRegressions.test_call_function_ex.<locals>.<lambda>  s    YbYiYiksuyjzY{ r   )r   r"   r$   r  r%   r(   r+   r_   r;   r6   r.   )r0   r   r[   
empty_argsr  s       @r	   test_call_function_exz%TestRegressions.test_call_function_ex  s    	
	""1f-33Q7!!!Q'((AFF4{|!!!QVV,	4	:!!!Q'11v.13>>+A+A'BCr   N)r>   r?   r@   r  r  r  r  r   r   r	   r  r    s    4B4 (Dr   r  )b__doc__r   r  	functoolsoperatorr   rn  r~  unittestasyncior   r
   r   r   r   r   r5   rG   rH   TestCaser    rB   rP   r"   r#   r_   rg   rl   rp   PY_YIELDr9  r<  r3  rE  rg  rk  r8  r:   r9   r   reduceor_r;   r   r   r   r   r   r   FunctionType
MethodTyper   r   r   r   r   test.profileer   r   r   r   r   r   r   r+  r;  rH  r]  r`  re  ri  rm  rr  r  r  r  r  r  r  r  r  r  r  r  r%  r   r0  r2  r;  r>  rQ  rR  rb  rC  re  r  r  r  )rM  r   s   00r	   <module>r     s   (  
   
    	
 	

M(++ MD0 0,(2,h.?.? (2V NN ZZ[[([[(ZZVVVXXx  WWg[[(-. $m3YY	ZZ7  $9##HLL]2S'2q22SUVWZ[Z`Z`` 		 
 	   ""E$4$45+- +>'/1B1B '* ZZAKKajjI	zz1;;' "''.0A0A ''T	* 	*	* 	*&,%79J9J &,RC?-x/@/@ C?Lz/+X->-> z/x)I$h&7&7 )IX1 1$)$h&7&7 $)N"- "3' 32& 230 31% 1h;k h;T	O 	O9 9B Bn 
^ 
 #L,Q__9([ 9(v
F 
F "5l!B s); s)j@V183D3D @VD o~MET((*;*; ETNJ J\ 
, , ).8 !-~|!K &FWYgg V)k V)pT TnO)8+<+< O.Y))+= YLD((*;*; LDo/ 3Ts    P.