
    dafL                     &   d dl Z d dlmZmZ d dlmZmZ  ej                  d      Z G d de j                        Z
 G d de j                        Z G d	 d
e j                        Z G d de j                        Zedk(  r e j                          yy)    N)contextmanager	ExitStack)catch_unraisable_exceptionimport_helper	_testcapic                       e Zd ZdZdZdZefdZd Zeefd       Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z y)TestDictWatchersr         c                 ,    t         j                  |      S N)r   add_dict_watcherselfkinds     7/root/Python-3.12.4/Lib/test/test_capi/test_watchers.pyadd_watcherzTestDictWatchers.add_watcher       ))$//    c                 .    t         j                  |       y r   )r   clear_dict_watcherr   
watcher_ids     r   clear_watcherzTestDictWatchers.clear_watcher       $$Z0r   c              #      K   | j                  |      }	 | | j                  |       y # | j                  |       w xY wwr   r   r   r   r   wids      r   watcherzTestDictWatchers.watcher   <     t$	$Is#Ds#   A+ A>Ac                 P    t         j                         }| j                  ||       y r   )r   get_dict_watcher_eventsassertEqualr   expectedactuals      r   assert_eventszTestDictWatchers.assert_events   s     224*r   c                 0    t         j                  ||       y r   )r   
watch_dictr   r   ds      r   watchzTestDictWatchers.watch#       S!$r   c                 0    t         j                  ||       y r   )r   unwatch_dictr,   s      r   unwatchzTestDictWatchers.unwatch&       sA&r   c                     i }| j                         5 }| j                  ||       d|d<   | j                  dg       d d d        y # 1 sw Y   y xY w)Nbarfoonew:foo:barr    r.   r)   r   r-   r   s      r   test_set_new_itemz"TestDictWatchers.test_set_new_item)   sN    \\^ 	0sJJsAAeH/	0 	0 	0s   *AAc                     ddi}| j                         5 }| j                  ||       d|d<   | j                  dg       d d d        y # 1 sw Y   y xY w)Nr6   r5   bazzmod:foo:bazr8   r9   s      r   test_set_existing_itemz'TestDictWatchers.test_set_existing_item0   sR    EN\\^ 	0sJJsAAeH/	0 	0 	0s   *AAc                     i }ddi}| j                         5 }| j                  ||       |j                  |       | j                  dg       d d d        y # 1 sw Y   y xY w)Nr6   r5   clone)r    r.   updater)   )r   r-   d2r   s       r   
test_clonezTestDictWatchers.test_clone7   sY    U^\\^ 	*sJJsAHHRLy)	* 	* 	*s   6AAc                 ~    i }| j                         5 }d|d<   | j                  g        d d d        y # 1 sw Y   y xY w)Nr5   r6   )r    r)   r9   s      r   test_no_event_if_not_watchedz-TestDictWatchers.test_no_event_if_not_watched?   s>    \\^ 	#sAeHr"	# 	# 	#s   3<c                     ddi}| j                         5 }| j                  ||       |d= | j                  dg       d d d        y # 1 sw Y   y xY wNr6   r5   zdel:foor8   r9   s      r   test_delzTestDictWatchers.test_delE   sP    EN\\^ 	,sJJsA%	{+	, 	, 	,s   (AAc                     ddi}| j                         5 }| j                  ||       |j                  d       | j                  dg       d d d        y # 1 sw Y   y xY wrF   )r    r.   popr)   r9   s      r   test_popzTestDictWatchers.test_popL   sT    EN\\^ 	,sJJsAEE%L	{+	, 	, 	,s   6AAc                     ddi}| j                         5 }| j                  ||       |j                          | j                  dg       d d d        y # 1 sw Y   y xY w)Nr6   r5   clear)r    r.   rL   r)   r9   s      r   
test_clearzTestDictWatchers.test_clearS   sR    EN\\^ 	*sJJsAGGIy)	* 	* 	*s   5AAc                     ddi}| j                         5 }| j                  ||       ~| j                  dg       d d d        y # 1 sw Y   y xY w)Nr6   r5   deallocr8   r9   s      r   test_dealloczTestDictWatchers.test_deallocZ   sL    EN\\^ 	,sJJsA	{+	, 	, 	,s   &AAc                     i }| j                         5 }| j                  ||       d|d<   | j                  ||       d|d<   | j                  dg       d d d        y # 1 sw Y   y xY w)Nr5   r6   r<   hmmr7   )r    r.   r2   r)   r9   s      r   test_unwatchzTestDictWatchers.test_unwatcha   se    \\^ 	0sJJsAAeHLLa AeH/	0 	0 	0s   AAA&c                    i }| j                  | j                        5 }| j                  ||       t               5 }d|d<   | j	                  d|j
                  j                         | j                  t        |j
                  j                        d       d d d        | j                  g        d d d        y # 1 sw Y   #xY w# 1 sw Y   y xY w)Nr   r5   r6   z0PyDict_EVENT_ADDED watcher callback for <dict atboom!)r    ERRORr.   r   assertIn
unraisableobjectr%   str	exc_valuer)   r   r-   r   cms       r   
test_errorzTestDictWatchers.test_errorj   s    \\tzz\* 		#cJJsA+- H %FMM((   R]]%<%<!=wGH r"		# 		#H H		# 		#s#   CAB9C9C	>CCc                 ,   i }| j                  | j                        5 }| j                  ||       t               5 }~| j	                  t        |j                  j                        d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NrU   rV   )r    rW   r.   r   r%   r[   rY   r\   r]   s       r   test_dealloc_errorz#TestDictWatchers.test_dealloc_errorw   s    \\tzz\* 	HcJJsA+- H  R]]%<%<!=wGH	H 	HH H	H 	Hs"   B
1A>-B
>B	B

Bc                 :   i }i }| j                         5 }| j                  | j                        5 }| j                  ||       | j                  ||       d|d<   d|d<   | j                  ddg       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NrU   r5   r6   r<   rR   r7   second)r    SECONDr.   r)   )r   d1rA   wid1wid2s        r   test_two_watchersz"TestDictWatchers.test_two_watchers   s    \\^ 	>t4;;/ >4

4$

4$!5	!5	""M8#<=>	> 	>> >	> 	>s#   BAB4BB	
BBc                     | j                         5 }| j                  t        d      5  | j                  |d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wNzCannot watch non-dictionaryr
   r    assertRaisesRegex
ValueErrorr.   r   r   s     r   test_watch_non_dictz$TestDictWatchers.test_watch_non_dict   s[    \\^ 	#s''
4RS #

3"#	# 	## #	# 	#!   AAAA	AA!c                     i }| j                  t        d      5  | j                  d|       d d d        | j                  t        d      5  | j                  d|       d d d        y # 1 sw Y   ;xY w# 1 sw Y   y xY wNzInvalid dict watcher ID -1zInvalid dict watcher ID 8   rl   rm   r.   r   r-   s     r   "test_watch_out_of_range_watcher_idz3TestDictWatchers.test_watch_out_of_range_watcher_id   st    ##J0MN 	JJr1	##J0LM 	JJq!	 		 		 	   A&
A2&A/2A;c                     i }| j                  t        d      5  | j                  d|       d d d        y # 1 sw Y   y xY wNzNo dict watcher set for ID 1r
   ru   rv   s     r    test_watch_unassigned_watcher_idz1TestDictWatchers.test_watch_unassigned_watcher_id   s;    ##J0OP 	JJq!	 	 	   5>c                     | j                         5 }| j                  t        d      5  | j                  |d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wrj   r    rl   rm   r2   rn   s     r   test_unwatch_non_dictz&TestDictWatchers.test_unwatch_non_dict   s[    \\^ 	%s''
4RS %S!$%	% 	%% %	% 	%rp   c                     i }| j                  t        d      5  | j                  d|       d d d        | j                  t        d      5  | j                  d|       d d d        y # 1 sw Y   ;xY w# 1 sw Y   y xY wrr   rl   rm   r2   rv   s     r   $test_unwatch_out_of_range_watcher_idz5TestDictWatchers.test_unwatch_out_of_range_watcher_id   st    ##J0MN 	 LLQ	 ##J0LM 	LLA	 		  	 	 	rx   c                     i }| j                  t        d      5  | j                  d|       d d d        y # 1 sw Y   y xY wrz   r   rv   s     r   "test_unwatch_unassigned_watcher_idz3TestDictWatchers.test_unwatch_unassigned_watcher_id   s;    ##J0OP 	LLA	 	 	r|   c                     | j                  t        d      5  | j                  d       d d d        | j                  t        d      5  | j                  d       d d d        y # 1 sw Y   :xY w# 1 sw Y   y xY wrr   rl   rm   r   r   s    r   "test_clear_out_of_range_watcher_idz3TestDictWatchers.test_clear_out_of_range_watcher_id   so    ##J0MN 	#r"	###J0LM 	"q!	" 	"	# 	#	" 	"s   A"A."A+.A7c                 |    | j                  t        d      5  | j                  d       d d d        y # 1 sw Y   y xY wrz   r   r   s    r    test_clear_unassigned_watcher_idz1TestDictWatchers.test_clear_unassigned_watcher_id   6    ##J0OP 	"q!	" 	" 	"   2;N)!__name__
__module____qualname__EVENTSrW   rd   r   r   r   r    r)   r.   r2   r:   r=   rB   rD   rG   rJ   rM   rP   rS   r_   ra   rh   ro   rw   r{   r   r   r   r   r    r   r   r	   r	      s    FEF% 01 ! $ $+%'00*#,,*,0#H	>#

%

""r   r	   c                       e Zd ZdZdZdZdZefdZd Ze	efd       Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)TestTypeWatchersr   r
   r   rt   c                 ,    t         j                  |      S r   )r   add_type_watcherr   s     r   r   zTestTypeWatchers.add_watcher   r   r   c                 .    t         j                  |       y r   )r   clear_type_watcherr   s     r   r   zTestTypeWatchers.clear_watcher   r   r   c              #      K   | j                  |      }	 | | j                  |       y # | j                  |       w xY wwr   r   r   s      r   r    zTestTypeWatchers.watcher   r!   r"   c                 P    t         j                         }| j                  ||       y r   )r   get_type_modified_eventsr%   r&   s      r   r)   zTestTypeWatchers.assert_events   s     335*r   c                 0    t         j                  ||       y r   )r   
watch_typer   r   ts      r   r.   zTestTypeWatchers.watch   r/   r   c                 0    t         j                  ||       y r   )r   unwatch_typer   s      r   r2   zTestTypeWatchers.unwatch   r3   r   c                      G d d      }| j                         5 }| j                  ||       d|_        | j                  |g       d d d        y # 1 sw Y   y xY w)Nc                       e Zd Zy)+TestTypeWatchers.test_watch_type.<locals>.CNr   r   r   r   r   r   Cr          r   r   r5   r    r.   r6   r)   r   r   r   s      r   test_watch_typez TestTypeWatchers.test_watch_type   sL    \\^ 	$sJJsAAEs#	$ 	$ 	$s   ,AAc                      G d d      }| j                         5 }| j                  ||       d|_        d|_        | j	                  |g       d d d        y # 1 sw Y   y xY w)Nc                       e Zd Zy)2TestTypeWatchers.test_event_aggregation.<locals>.CNr   r   r   r   r   r      r   r   r   r5   r<   )r    r.   r6   r5   r)   r   s      r   test_event_aggregationz'TestTypeWatchers.test_event_aggregation   sS    \\^ 	$sJJsAAEAEs#	$ 	$ 	$s   3AA c                      G d d      }| j                         5 }| j                  ||       d|_        | j                  |j                  d       d|_        | j                  ||g       d d d        y # 1 sw Y   y xY w)Nc                       e Zd Zy):TestTypeWatchers.test_lookup_resets_aggregation.<locals>.CNr   r   r   r   r   r      r   r   r   r5   r<   )r    r.   r6   r%   r5   r)   r   s      r   test_lookup_resets_aggregationz/TestTypeWatchers.test_lookup_resets_aggregation   si    \\^ 	'sJJsAAEQUUE*AE1v&	' 	' 	's   AA44A=c                 F    G d d      }| j                         5 }| j                  ||       d|_        | j                  |j                  d       | j	                  |g       | j                  ||       d|_        | j	                  |g       d d d        y # 1 sw Y   y xY w)Nc                       e Zd Zy)-TestTypeWatchers.test_unwatch_type.<locals>.CNr   r   r   r   r   r      r   r   r   r5   r<   )r    r.   r6   r%   r)   r2   r5   r   s      r   test_unwatch_typez"TestTypeWatchers.test_unwatch_type   s    \\^ 	$sJJsAAEQUUE*s#LLa AEs#	$ 	$ 	$s   A3BB c                 l    G d d      }| j                         5 }| j                         5 }| j                  ||       d|_        | j                  |j                  d       | j	                  |g       d d d        d|_        | j	                  |g       d d d        y # 1 sw Y   +xY w# 1 sw Y   y xY w)Nc                       e Zd Zy).TestTypeWatchers.test_clear_watcher.<locals>.CNr   r   r   r   r   r      r   r   r   r5   r<   )r    r.   r6   r%   r)   r5   )r   r   _r   s       r   test_clear_watcherz#TestTypeWatchers.test_clear_watcher   s    \\^ 	$q (3

3"  .""A3'	(
 AEs#	$ 	$( (	$ 	$s#   B*AB4!B*B'	#B**B3c                      G d d      } G d d|      }| j                         5 }| j                  ||       d|_        | j                  |g       d d d        y # 1 sw Y   y xY w)Nc                       e Zd Zy)4TestTypeWatchers.test_watch_type_subclass.<locals>.CNr   r   r   r   r   r     r   r   r   c                       e Zd Zy)4TestTypeWatchers.test_watch_type_subclass.<locals>.DNr   r   r   r   Dr     r   r   r   r5   r   )r   r   r   r   s       r   test_watch_type_subclassz)TestTypeWatchers.test_watch_type_subclass  sT    \\^ 	$sJJsAAEs#	$ 	$ 	$s   ,AA$c                     G d d      }| j                  | j                        5 }| j                  ||       t               5 }d|_        | j                  |j                  j                  |       | j                  t        |j                  j                        d       d d d        | j                  g        d d d        y # 1 sw Y   #xY w# 1 sw Y   y xY w)Nc                       e Zd Zy)&TestTypeWatchers.test_error.<locals>.CNr   r   r   r   r   r     r   r   r   rU   r5   rV   )r    rW   r.   r   r6   assertIsrY   rZ   r%   r[   r\   r)   )r   r   r   r^   s       r   r_   zTestTypeWatchers.test_error  s    \\tzz\* 	#cJJsA+- Hbmm22A6  R]]%<%<!=wGH r"	# 	#H H	# 	#s$   CAC!CC	CCc                     G d d      } G d d      }| j                         5 }| j                  | j                        5 }| j                  ||       | j                  ||       | j                  ||       d|_        d|_        | j                  ||gg       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nc                       e Zd Zy).TestTypeWatchers.test_two_watchers.<locals>.C1Nr   r   r   r   C1r     r   r   r   c                       e Zd Zy).TestTypeWatchers.test_two_watchers.<locals>.C2Nr   r   r   r   C2r     r   r   r   rU   r5   r<   )r    WRAPassertNotEqualr.   r6   rR   r)   )r   r   r   rf   rg   s        r   rh   z"TestTypeWatchers.test_two_watchers  s    \\^ 	/t499- /##D$/

4$

4$""B:./	/ 	// /	/ 	/s$   B8AB,B8,B5	1B88Cc                 8    G d d      }t               5 }d}|| j                  dz
  k  r2|j                  | j                               }|| j                  dz
  k  r2| j	                  ||       d|_        | j                  |g       d d d        y # 1 sw Y   y xY w)Nc                       e Zd Zy)-TestTypeWatchers.test_all_watchers.<locals>.CNr   r   r   r   r   r   *  r   r   r   rs   r
   r5   )r   TYPE_MAX_WATCHERSenter_contextr    r.   r6   r)   )r   r   stacklast_wids       r   test_all_watchersz"TestTypeWatchers.test_all_watchers)  s    [ 	$EH T33a77 ..t||~> T33a77JJx#AEs#	$ 	$ 	$s   AB+BBc                     | j                         5 }| j                  t        d      5  | j                  |d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wNzCannot watch non-typer
   rk   rn   s     r   test_watch_non_typez$TestTypeWatchers.test_watch_non_type5  s[    \\^ 	#s''
4LM #

3"#	# 	## #	# 	#rp   c                      G d d      }| j                  t        d      5  | j                  d|       d d d        | j                  t        d      5  | j                  | j                  |       d d d        y # 1 sw Y   ExY w# 1 sw Y   y xY w)Nc                       e Zd Zy)>TestTypeWatchers.test_watch_out_of_range_watcher_id.<locals>.CNr   r   r   r   r   r   ;  r   r   r   Invalid type watcher ID -1rs   Invalid type watcher ID 8)rl   rm   r.   r   r   r   s     r   rw   z3TestTypeWatchers.test_watch_out_of_range_watcher_id:  sz    ##J0MN 	JJr1	##J0LM 	2JJt--q1	2 	2	 		2 	2   A8B8BBc                      G d d      }| j                  t        d      5  | j                  d|       d d d        y # 1 sw Y   y xY w)Nc                       e Zd Zy)<TestTypeWatchers.test_watch_unassigned_watcher_id.<locals>.CNr   r   r   r   r   r   B  r   r   r   No type watcher set for ID 1r
   ru   r   s     r   r{   z1TestTypeWatchers.test_watch_unassigned_watcher_idA  s;    ##J0OP 	JJq!	 	 		   =Ac                     | j                         5 }| j                  t        d      5  | j                  |d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wr   r~   rn   s     r   test_unwatch_non_typez&TestTypeWatchers.test_unwatch_non_typeF  s[    \\^ 	%s''
4LM %S!$%	% 	%% %	% 	%rp   c                      G d d      }| j                  t        d      5  | j                  d|       d d d        | j                  t        d      5  | j                  | j                  |       d d d        y # 1 sw Y   ExY w# 1 sw Y   y xY w)Nc                       e Zd Zy)@TestTypeWatchers.test_unwatch_out_of_range_watcher_id.<locals>.CNr   r   r   r   r   r   L  r   r   r   r   rs   r   )rl   rm   r2   r   r   s     r   r   z5TestTypeWatchers.test_unwatch_out_of_range_watcher_idK  sz    ##J0MN 	 LLQ	 ##J0LM 	4LL//3	4 	4	  	 	4 	4r   c                      G d d      }| j                  t        d      5  | j                  d|       d d d        y # 1 sw Y   y xY w)Nc                       e Zd Zy)>TestTypeWatchers.test_unwatch_unassigned_watcher_id.<locals>.CNr   r   r   r   r   r   S  r   r   r   r   r
   r   r   s     r   r   z3TestTypeWatchers.test_unwatch_unassigned_watcher_idR  s;    ##J0OP 	LLA	 	 	r   c                    | j                  t        d      5  | j                  d       d d d        | j                  t        d      5  | j                  | j                         d d d        y # 1 sw Y   DxY w# 1 sw Y   y xY w)Nr   rs   r   )rl   rm   r   r   r   s    r   r   z3TestTypeWatchers.test_clear_out_of_range_watcher_idW  su    ##J0MN 	#r"	###J0LM 	7t556	7 	7	# 	#	7 	7s   A,A8,A58Bc                 |    | j                  t        d      5  | j                  d       d d d        y # 1 sw Y   y xY w)Nr   r
   r   r   s    r   r   z1TestTypeWatchers.test_clear_unassigned_watcher_id]  r   r   c                    | j                  t        d      5  t               5 }t        | j                  dz         D ]!  }|j                  | j                                # 	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nzno more type watcher IDsr
   )rl   RuntimeErrorr   ranger   r   r    )r   r   r   s      r   test_no_more_ids_availablez+TestTypeWatchers.test_no_more_ids_availablea  s|    ##L2MN 	8 8t559: 8A''788	8 	88 8	8 	8s"   A==A1 A=1A:	6A==BN) r   r   r   TYPESrW   r   r   r   r   r   r    r)   r.   r2   r   r   r   r   r   r   r_   rh   r   r   rw   r{   r   r   r   r   r   r   r   r   r   r   r      s    EED $ 01   $ $+%'$$	'	$$$#
/
$#
2
%
4
7"8r   r   c                   F    e Zd Zed        Zd Zd Zd Zd Zd Z	d Z
d Zy	)
TestCodeObjectWatchersc              #      K   t         j                  |      }	 | t         j                  |       y # t         j                  |       w xY wwr   )r   add_code_watcherclear_code_watcher)r   which_watcherr   s      r   code_watcherz#TestCodeObjectWatchers.code_watcheri  s<     ((7	.I((-I((-   A3 AA

Ac                 ,   | j                  |t        j                  d             | j                  |t        j                  d             | j                  |t        j                  d             | j                  |t        j                  d             y )Nr   r
   )r%   r   #get_code_watcher_num_created_events%get_code_watcher_num_destroyed_events)r   exp_created_0exp_destroyed_0exp_created_1exp_destroyed_1s        r   assert_event_countsz*TestCodeObjectWatchers.assert_event_countsq  s~    9HHK	MYLLQO	Q9HHK	MYLLQO	Qr   c                    | j                  dddd       t        j                  ddd      }| j                  dddd       ~| j                  dddd       | j                  d      5  | j                  dddd       t        j                  ddd      }| j                  dddd       ~| j                  dddd       | j                  d      5  | j                  dddd       t        j                  ddd      }| j                  dddd       ~| j                  dddd       d d d        d d d        t        j                  ddd      }| j                  dddd       ~| j                  dddd       y # 1 sw Y   RxY w# 1 sw Y   VxY w)	Nr   test_watchersdummy1dummy2r
   dummy3r   dummy4)r  r   code_newemptyr   )r   co1co2co3co4s        r   "test_code_object_events_dispatchedz9TestCodeObjectWatchers.test_code_object_events_dispatched|  s     Aq!, %%oxC  Aq!,  Aq!, q! 	5$$Q1a0))/8QGC$$Q1a0$$Q1a0 ""1% 5((Aq!4--oxK((Aq!4((Aq!45	5  %%oxC  Aq!,  Aq!,5 5	5 	5s&   &A&E>AE2!E>2E;	7E>>Fc                 l   | j                  d      5  t               5 }t        j                  ddd      }| j	                  |j
                  j                  d|       | j	                  t        |j
                  j                        d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r  dummy0r   z*PY_CODE_EVENT_CREATE watcher callback for rV   )	r   r   r   r  r%   rY   rZ   r[   r\   )r   r^   cos      r   r_   z!TestCodeObjectWatchers.test_error  s    q! 	H+- H,,_hJ  MM((@G   R]]%<%<!=wGH	H 	HH H	H 	Hs#   B*A0BB*B'	#B**B3c                    t         j                  ddd      }| j                  d      5  t               5 }~| j	                  t        |j                  j                        d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr  r  r   r   rV   )r   r  r   r   r%   r[   rY   r\   )r   r  r^   s      r   ra   z)TestCodeObjectWatchers.test_dealloc_error  s    $$_hBq! 	H+- H  R]]%<%<!=wGH	H 	HH H	H 	Hs"   B1A6%B6A?	;BBc                    | j                  t        d      5  t        j                  d       d d d        | j                  t        d      5  t        j                  d       d d d        y # 1 sw Y   >xY w# 1 sw Y   y xY w)NzInvalid code watcher ID -1rs   zInvalid code watcher ID 8rt   rl   rm   r   r   r   s    r   r   z9TestCodeObjectWatchers.test_clear_out_of_range_watcher_id  o    ##J0MN 	-((,	-##J0LM 	,((+	, 	,	- 	-	, 	,   A*A6*A36A?c                     | j                  t        d      5  t        j                  d       d d d        y # 1 sw Y   y xY w)NzNo code watcher set for ID 1r
   r  r   s    r   r   z7TestCodeObjectWatchers.test_clear_unassigned_watcher_id  6    ##J0OP 	,((+	, 	, 	,   6?c                     | j                  t        d      5  t        j                          d d d        y # 1 sw Y   y xY w)Nz"no more code watcher IDs available)rl   r   r   allocate_too_many_code_watchersr   s    r   test_allocate_too_many_watchersz6TestCodeObjectWatchers.test_allocate_too_many_watchers  s4    ##L2WX 	8557	8 	8 	8   5>N)r   r   r   r   r   r  r  r_   ra   r   r   r  r   r   r   r   r   h  s;    . .	Q-B	HH,,8r   r   c                   F    e Zd Zed        Zd Zd Zd Zd Zd Z	d Z
d Zy	)
TestFuncWatchersc              #      K   t         j                  |      }	 d  t         j                  |       y # t         j                  |       w xY wwr   )r   add_func_watcherclear_func_watcher)r   funcr   s      r   r   zTestFuncWatchers.add_watcher  s:     ((.	.((-I((-r   c                 2   g fd}| j                  |      5  d }| j                  t        j                  |d f       t	        |      }| j
                  j                  }||_        | j                  t        j                  ||f       d}||_        | j                  t        j                  ||f       d}t        j                  ||       | j                  t        j                  ||f       ddi}||_        | j                  t        j                  ||f       ddi}t        j                  ||       | j                  t        j                  ||f       g ~| j                  t        j                  |d f       d d d        y # 1 sw Y   y xY w)Nc                  (    j                  |        y r   append)argseventss    r   r    z=TestFuncWatchers.test_func_events_dispatched.<locals>.watcher  s    MM$r   c                       y r   r   r   r   r   myfuncz<TestFuncWatchers.test_func_events_dispatched.<locals>.myfunc  s    r   ){   )  r   r.  r/  )r   rX   r   PYFUNC_EVENT_CREATEidtest_func_events_dispatched__code__PYFUNC_EVENT_MODIFY_CODE__defaults__PYFUNC_EVENT_MODIFY_DEFAULTSset_func_defaults_via_capi__kwdefaults__PYFUNC_EVENT_MODIFY_KWDEFAULTSset_func_kwdefaults_via_capiPYFUNC_EVENT_DESTROY)r   r    r-  	myfunc_idnew_codenew_defaultsnew_kwdefaultsr+  s          @r   r2  z,TestFuncWatchers.test_func_events_dispatched  st   	  g& 	UMM988&$GP6
I77@@H&FOMM9==vxPRXY!L".FMM9AA6<XZ`a!L00FMM9AA6<XZ`a$c]N$2F!MM9CCV^\^de$c]N226>JMM9CCV^\^de FMM9999dKVT;	U 	U 	Us   E*FFc                 0   g fd}g fd}| j                  |      5  | j                  |      5  d }t        j                  |d f}| j                  |       | j                  |       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nc                  (    j                  |        y r   r(  )r*  events0s    r   first_watcherz>TestFuncWatchers.test_multiple_watchers.<locals>.first_watcher      NN4 r   c                  (    j                  |        y r   r(  )r*  events1s    r   second_watcherz?TestFuncWatchers.test_multiple_watchers.<locals>.second_watcher  rD  r   c                       y r   r   r   r   r   r-  z7TestFuncWatchers.test_multiple_watchers.<locals>.myfunc      r   )r   r   r0  rX   )r   rC  rG  r-  eventrB  rF  s        @@r   test_multiple_watchersz'TestFuncWatchers.test_multiple_watchers  s    	! 	! m, 	.!!.1 . #66EeW-eW-.	. 	.. .	. 	.s"   B;B /B B		BBc                     G d dt               fd}| j                  |      5  t               5 }d }| j                  |j                  j
                  d|       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nc                       e Zd Zy);TestFuncWatchers.test_watcher_raises_error.<locals>.MyErrorNr   r   r   r   MyErrorrN        r   rO  c                       d      Nztesting 123r   r*  rO  s    r   r    z;TestFuncWatchers.test_watcher_raises_error.<locals>.watcher      -((r   c                       y r   r   r   r   r   r-  z:TestFuncWatchers.test_watcher_raises_error.<locals>.myfunc  rI  r   z-PyFunction_EVENT_CREATE watcher callback for )	Exceptionr   r   r%   rY   rZ   )r   r    r^   r-  rO  s       @r   test_watcher_raises_errorz*TestFuncWatchers.test_watcher_raises_error  s    	i 		) g& 	+-    MM((CF:N		 	 	 	s"   A<-A0A<0A9	5A<<Bc                     G d dt               fd}d }| j                  |      5  t               5 }~| j                  |j                  j
                         d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nc                       e Zd Zy)CTestFuncWatchers.test_dealloc_watcher_raises_error.<locals>.MyErrorNr   r   r   r   rO  rZ    rP  r   rO  c                       d      rR  r   rS  s    r   r    zCTestFuncWatchers.test_dealloc_watcher_raises_error.<locals>.watcher  rT  r   c                       y r   r   r   r   r   r-  zBTestFuncWatchers.test_dealloc_watcher_raises_error.<locals>.myfunc  s    r   )rV  r   r   assertIsInstancerY   r\   )r   r    r-  r^   rO  s       @r   !test_dealloc_watcher_raises_errorz2TestFuncWatchers.test_dealloc_watcher_raises_error  s    	i 		)	 g& 	H+- H%%bmm&=&=wGH	H 	HH H	H 	Hs"   A:(A.A:.A7	3A::Bc                    | j                  t        d      5  t        j                  d       d d d        | j                  t        d      5  t        j                  d       d d d        y # 1 sw Y   >xY w# 1 sw Y   y xY w)Nzinvalid func watcher ID -1rs   zinvalid func watcher ID 8rt   rl   rm   r   r$  r   s    r   r   z3TestFuncWatchers.test_clear_out_of_range_watcher_id  r  r  c                     | j                  t        d      5  t        j                  d       d d d        y # 1 sw Y   y xY w)Nzno func watcher set for ID 1r
   r`  r   s    r   r   z1TestFuncWatchers.test_clear_unassigned_watcher_id%  r  r  c                     | j                  t        d      5  t        j                          d d d        y # 1 sw Y   y xY w)Nzno more func watcher IDs)rl   r   r   allocate_too_many_func_watchersr   s    r   r  z0TestFuncWatchers.test_allocate_too_many_watchers)  s4    ##L2MN 	8557	8 	8 	8r  N)r   r   r   r   r   r2  rK  rW  r^  r   r   r  r   r   r   r!  r!    s:    . ."UH.$"H ,,8r   r!  __main__)unittest
contextlibr   r   test.supportr   r   import_moduler   TestCaser	   r   r   r!  r   mainr   r   r   <module>rk     s     0 B (M''4	i"x(( i"Xn8x(( n8bT8X.. T8nl8x(( l8^ zHMMO r   