+
    Bi]_                     d   ^ RI t ^ RIt^ RIHtHt ^ RIHtHtHt ]P                  ! R4      t
 ! R R] P                  4      t ! R R] P                  4      t ! R	 R
] P                  4      t ! R R] P                  4      t ! R R] P                  4      t]R8X  d   ] P$                  ! 4        R# R# )    N)contextmanager	ExitStack)catch_unraisable_exceptionimport_helper
gc_collect	_testcapic                      a  ] tR t^t o ^ t^t^t]3R ltR t]	]3R l4       t
R tR tR tR tR tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR t R t!R t"Rt#V t$R# )TestDictWatchersc                ,    \         P                  V4      # N)r   add_dict_watcherselfkinds   &&3/usr/lib/python3.14/test/test_capi/test_watchers.pyadd_watcherTestDictWatchers.add_watcher       ))$//    c                0    \         P                  V4       R # r   )r   clear_dict_watcherr   
watcher_ids   &&r   clear_watcherTestDictWatchers.clear_watcher       $$Z0r   c              #     "   V P                  V4      p Vx  V P                  V4       R #   T P                  T4       i ; i5ir   r   r   r   r   wids   && r   watcherTestDictWatchers.watcher   ;     t$	$Is#Ds#   A, A?Ac                P    \         P                  4       pV P                  W!4       R # r   )r   get_dict_watcher_eventsassertEqualr   expectedactuals   && r   assert_eventsTestDictWatchers.assert_events"   s    224*r   c                0    \         P                  W4       R # r   )r   
watch_dictr   r    ds   &&&r   watchTestDictWatchers.watch&       S$r   c                0    \         P                  W4       R # r   )r   unwatch_dictr/   s   &&&r   unwatchTestDictWatchers.unwatch)       s&r   c                    / pV P                  4       ;_uu_ 4       pV P                  W!4       R VR&   V P                  R.4       RRR4       R#   + '       g   i     R# ; i)barfoonew:foo:barNr!   r1   r+   r   r0   r    s   &  r   test_set_new_item"TestDictWatchers.test_set_new_item,   sE    \\^^sJJsAeH/ ^^^s   )AA	c                    R R/pV P                  4       ;_uu_ 4       pV P                  W!4       RVR &   V P                  R.4       RRR4       R#   + '       g   i     R# ; i)r;   r:   bazmod:foo:bazNr=   r>   s   &  r   test_set_existing_item'TestDictWatchers.test_set_existing_item3   sI    EN\\^^sJJsAeH/ ^^^s   )AA!	c                    / pR R/pV P                  4       ;_uu_ 4       pV P                  W14       VP                  V4       V P                  R.4       RRR4       R#   + '       g   i     R# ; i)r;   r:   cloneN)r!   r1   updater+   )r   r0   d2r    s   &   r   
test_cloneTestDictWatchers.test_clone:   sP    U^\\^^sJJsHHRLy) ^^^s   5AA/	c                    / pV P                  4       ;_uu_ 4       pR VR&   V P                  . 4       RRR4       R#   + '       g   i     R# ; i)r:   r;   N)r!   r+   r>   s   &  r   test_no_event_if_not_watched-TestDictWatchers.test_no_event_if_not_watchedB   s7    \\^^sAeHr" ^^^s	   <A	c                    R R/pV P                  4       ;_uu_ 4       pV P                  W!4       VR  V P                  R.4       RRR4       R#   + '       g   i     R# ; ir;   r:   del:fooNr=   r>   s   &  r   test_delTestDictWatchers.test_delH   sG    EN\\^^sJJs%	{+ ^^^s   'AA	c                    R R/pV P                  4       ;_uu_ 4       pV P                  W!4       VP                  R 4       V P                  R.4       RRR4       R#   + '       g   i     R# ; irP   )r!   r1   popr+   r>   s   &  r   test_popTestDictWatchers.test_popO   sK    EN\\^^sJJsEE%L	{+ ^^^s   5AA-	c                    R R/pV P                  4       ;_uu_ 4       pV P                  W!4       VP                  4        V P                  R.4       RRR4       R#   + '       g   i     R# ; i)r;   r:   clearN)r!   r1   rY   r+   r>   s   &  r   
test_clearTestDictWatchers.test_clearV   sI    EN\\^^sJJsGGIy) ^^^s   4AA,	c                    R R/pV P                  4       ;_uu_ 4       pV P                  W!4       ?V P                  R.4       RRR4       R#   + '       g   i     R# ; i)r;   r:   deallocNr=   r>   s   &  r   test_deallocTestDictWatchers.test_dealloc]   sC    EN\\^^sJJs	{+ ^^^s   %AA	c                     ! R  R4      pV! 4       pV P                  4       ;_uu_ 4       pV P                  W2P                  4       RVn        RVn        V=V P	                  . RO4       RRR4       V P                  4       ;_uu_ 4       pV P                  W2P                  4       \        ^d4       F
  pRVn        K  	  V P	                  R.R.^c,          ,           4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)c                       ] tR t^etRtR# )0TestDictWatchers.test_object_dict.<locals>.MyObj N__name__
__module____qualname____firstlineno____static_attributes__rc   r   r   MyObjrb   e   s    Tr   rj   r:   rB   r<   Nzmod:foo:bar)r<   rC   rQ   )r!   r1   __dict__r;   r+   range)r   rj   or    _s   &    r   test_object_dict!TestDictWatchers.test_object_dictd   s    G\\^^sJJsJJ'AEAEHI  \\^^sJJsJJ'3Z  -21EEF	 ^ ^ ^^s   ?C)	AC<)C9	<D	c                    / pV P                  4       ;_uu_ 4       pV P                  W!4       R VR&   V P                  W!4       RVR&   V P                  R.4       RRR4       R#   + '       g   i     R# ; i)r:   r;   rB   hmmr<   N)r!   r1   r6   r+   r>   s   &  r   test_unwatchTestDictWatchers.test_unwatchu   sZ    \\^^sJJsAeHLL AeH/ ^^^s   ?A$$A5	c           	     *   / pV P                  V P                  R 7      ;_uu_ 4       pV P                  W!4       \        4       ;_uu_ 4       pRVR&   V P	                  RVP
                  P                  4       V P                  VP
                  P                  4       V P                  \        VP
                  P                  4      R4       RRR4       V P                  . 4       RRR4       R#   + '       g   i     L+; i  + '       g   i     R# ; i)r   r:   r;   zFException ignored in PyDict_EVENT_ADDED watcher callback for <dict at boom!N)r!   ERRORr1   r   assertIn
unraisableerr_msgassertIsNoneobjectr'   str	exc_valuer+   r   r0   r    cms   &   r   
test_errorTestDictWatchers.test_error~   s    \\tzz\**cJJs+-- %HMM))
 !!"--"6"67  R]]%<%<!=wG . r" +*-- +**s$   $DB C.	D.C>9DD	c           	     j   / pV P                  V P                  R 7      ;_uu_ 4       pV P                  W!4       \        4       ;_uu_ 4       p?V P	                  \        VP                  P                  4      R4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)rv   rw   N)r!   rx   r1   r   r'   r~   rz   r   r   s   &   r   test_dealloc_error#TestDictWatchers.test_dealloc_error   sw    \\tzz\**cJJs+--  R]]%<%<!=wG . +*-- +**s#   $B!1B	<B!BB!!B2	c           	     v   / p/ pV P                  4       ;_uu_ 4       pV P                  V P                  R 7      ;_uu_ 4       pV P                  W14       V P                  WB4       RVR&   RVR&   V P                  RR.4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)rv   r:   r;   rB   rr   r<   secondN)r!   SECONDr1   r+   )r   d1rI   wid1wid2s   &    r   test_two_watchers"TestDictWatchers.test_two_watchers   s    \\^^t4;;//4

4$

4$!5	!5	""M8#<= 0 ^// ^^s$   %B'A B	B'B$B''B8	c           	        V P                  4       ;_uu_ 4       pV P                  \        R 4      ;_uu_ 4        V P                  V^4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; izCannot watch non-dictionaryNr!   assertRaisesRegex
ValueErrorr1   r   r    s   & r   test_watch_non_dict$TestDictWatchers.test_watch_non_dict   sO    \\^^s''
4RSS

3" T ^SS ^^"   A0A	A0A-(A00B	c                <   / pV P                  \        R 4      ;_uu_ 4        V P                  RV4       RRR4       V P                  \        R4      ;_uu_ 4        V P                  ^V4       RRR4       R#   + '       g   i     LK; i  + '       g   i     R# ; izInvalid dict watcher ID -1NzInvalid dict watcher ID 8r   r   r1   r   r0   s   & r   "test_watch_out_of_range_watcher_id3TestDictWatchers.test_watch_out_of_range_watcher_id   sn    ##J0MNNJJr1 O##J0LMMJJq! NM ONMMM   A7B
7B	
B	c                    / pV P                  \        R 4      ;_uu_ 4        V P                  ^V4       RRR4       R#   + '       g   i     R# ; izNo dict watcher set for ID 3Nr   r   s   & r    test_watch_unassigned_watcher_id1TestDictWatchers.test_watch_unassigned_watcher_id   s9    ##J0OPPJJq! QPPP	   >A	c           	        V P                  4       ;_uu_ 4       pV P                  \        R 4      ;_uu_ 4        V P                  V^4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; ir   r!   r   r   r6   r   s   & r   test_unwatch_non_dict&TestDictWatchers.test_unwatch_non_dict   sO    \\^^s''
4RSSS!$ T ^SS ^^r   c                <   / pV P                  \        R 4      ;_uu_ 4        V P                  RV4       RRR4       V P                  \        R4      ;_uu_ 4        V P                  ^V4       RRR4       R#   + '       g   i     LK; i  + '       g   i     R# ; ir   r   r   r6   r   s   & r   $test_unwatch_out_of_range_watcher_id5TestDictWatchers.test_unwatch_out_of_range_watcher_id   sn    ##J0MNNLLQ O##J0LMMLLA NM ONMMMr   c                    / pV P                  \        R 4      ;_uu_ 4        V P                  ^V4       RRR4       R#   + '       g   i     R# ; ir   r   r   s   & r   "test_unwatch_unassigned_watcher_id3TestDictWatchers.test_unwatch_unassigned_watcher_id   s9    ##J0OPPLLA QPPPr   c                4   V P                  \        R 4      ;_uu_ 4        V P                  R4       RRR4       V P                  \        R4      ;_uu_ 4        V P                  ^4       RRR4       R#   + '       g   i     LJ; i  + '       g   i     R# ; ir   r   r   r   r   s   &r   "test_clear_out_of_range_watcher_id3TestDictWatchers.test_clear_out_of_range_watcher_id   si    ##J0MNNr" O##J0LMMq! NM ONMMMs   A3B3B	B	c                    V P                  \        R 4      ;_uu_ 4        V P                  ^4       RRR4       R#   + '       g   i     R# ; ir   r   r   s   &r    test_clear_unassigned_watcher_id1TestDictWatchers.test_clear_unassigned_watcher_id   4    ##J0OPPq! QPPP	   ;A	rc   N)%re   rf   rg   rh   EVENTSrx   r   r   r   r   r!   r+   r1   r6   r?   rD   rJ   rM   rR   rV   rZ   r^   ro   rs   r   r   r   r   r   r   r   r   r   r   r   ri   __classdictcell____classdict__s   @r   r
   r
      s     FEF% 01 ! $ $+%'00*#,,*,G"0#H	>#

%

"" "r   r
   c                      a  ] tR t^t o ^ t^t^t^t]3R ltR t	]
]3R l4       tR tR tR tR tR tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tR t Rt!V t"R# )TestTypeWatchersc                ,    \         P                  V4      # r   )r   add_type_watcherr   s   &&r   r   TestTypeWatchers.add_watcher   r   r   c                0    \         P                  V4       R # r   )r   clear_type_watcherr   s   &&r   r   TestTypeWatchers.clear_watcher   r   r   c              #     "   V P                  V4      p Vx  V P                  V4       R #   T P                  T4       i ; i5ir   r   r   s   && r   r!   TestTypeWatchers.watcher   r#   r$   c                P    \         P                  4       pV P                  W!4       R # r   )r   get_type_modified_eventsr'   r(   s   && r   r+   TestTypeWatchers.assert_events   s    335*r   c                0    \         P                  W4       R # r   )r   
watch_typer   r    ts   &&&r   r1   TestTypeWatchers.watch   r3   r   c                0    \         P                  W4       R # r   )r   unwatch_typer   s   &&&r   r6   TestTypeWatchers.unwatch   r8   r   c                     ! R  R4      pV P                  4       ;_uu_ 4       pV P                  W!4       RVn        V P                  V.4       RRR4       R#   + '       g   i     R# ; i)c                       ] tR t^tRtR# )+TestTypeWatchers.test_watch_type.<locals>.Crc   Nrd   rc   r   r   Cr          r   r   r:   Nr!   r1   r;   r+   r   r   r    s   &  r   test_watch_type TestTypeWatchers.test_watch_type   sC    \\^^sJJsAEs# ^^^s   +AA)	c                     ! R  R4      pV P                  4       ;_uu_ 4       pV P                  W!4       RVn        RVn        V P	                  V.4       RRR4       R#   + '       g   i     R# ; i)c                       ] tR t^tRtR# )2TestTypeWatchers.test_event_aggregation.<locals>.Crc   Nrd   rc   r   r   r   r      r   r   r   r:   rB   N)r!   r1   r;   r:   r+   r   s   &  r   test_event_aggregation'TestTypeWatchers.test_event_aggregation   sJ    \\^^sJJsAEAEs# ^^^s   2AA0	c                    ! R  R4      pV P                  4       ;_uu_ 4       pV P                  W!4       RVn        V P                  VP                  R4       RVn        V P                  W.4       RRR4       R#   + '       g   i     R# ; i)c                       ] tR t^tRtR# ):TestTypeWatchers.test_lookup_resets_aggregation.<locals>.Crc   Nrd   rc   r   r   r   r      r   r   r   r:   rB   N)r!   r1   r;   r'   r:   r+   r   s   &  r   test_lookup_resets_aggregation/TestTypeWatchers.test_lookup_resets_aggregation   s^    \\^^sJJsAEQUUE*AEv& ^^^s   AA;;B	c                d    ! R  R4      pV P                  4       ;_uu_ 4       pV P                  W!4       RVn        V P                  VP                  R4       V P	                  V.4       V P                  W!4       RVn        V P	                  V.4       RRR4       R#   + '       g   i     R# ; i)c                       ] tR tRtRtR# )-TestTypeWatchers.test_unwatch_type.<locals>.Ci
  rc   Nrd   rc   r   r   r   r   
  r   r   r   r:   rB   N)r!   r1   r;   r'   r+   r6   r:   r   s   &  r   test_unwatch_type"TestTypeWatchers.test_unwatch_type	  sz    \\^^sJJsAEQUUE*s#LL AEs# ^^^s   A1BB/	c           	         ! R  R4      pV P                  4       ;_uu_ 4       pV P                  4       ;_uu_ 4       pV P                  W14       RVn        V P                  VP                  R4       V P	                  V.4       RRR4       RVn        V P	                  V.4       RRR4       R#   + '       g   i     L3; i  + '       g   i     R# ; i)c                       ] tR tRtRtR# ).TestTypeWatchers.test_clear_watcher.<locals>.Ci  rc   Nrd   rc   r   r   r   r     r   r   r   r:   NrB   )r!   r1   r;   r'   r+   r:   )r   r   rn   r    s   &   r   test_clear_watcher#TestTypeWatchers.test_clear_watcher  s    \\^^q3

3"  .""A3'	  
 AEs# ^ ^^s#   CAB.	!C.B>9CC	c                     ! R  R4      p ! R RV4      pV P                  4       ;_uu_ 4       pV P                  W24       RVn        V P                  V.4       RRR4       R#   + '       g   i     R# ; i)c                       ] tR tRtRtR# )4TestTypeWatchers.test_watch_type_subclass.<locals>.Ci"  rc   Nrd   rc   r   r   r   r   "  r   r   r   c                       ] tR tRtRtR# )4TestTypeWatchers.test_watch_type_subclass.<locals>.Di#  rc   Nrd   rc   r   r   Dr   #  s    Dr   r   r:   Nr   )r   r   r   r    s   &   r   test_watch_type_subclass)TestTypeWatchers.test_watch_type_subclass!  sK    \\^^sJJsAEs# ^^^s   +A##A4	c           	     H    ! R  R4      pV P                  V P                  R7      ;_uu_ 4       pV P                  W!4       \        4       ;_uu_ 4       pRVn        V P                  VP                  P                  RV: 24       V P                  VP                  P                  R4       V P                  \        VP                  P                  4      R4       RRR4       V P                  . 4       RRR4       R#   + '       g   i     L+; i  + '       g   i     R# ; i)c                       ] tR tRtRtR# )&TestTypeWatchers.test_error.<locals>.Ci*  rc   Nrd   rc   r   r   r   r   *  r   r   r   rv   r:   z2Exception ignored in type watcher callback #1 for Nrw   )r!   rx   r1   r   r;   r'   rz   r{   assertIsr}   r~   r   r+   )r   r   r    r   s   &   r   r   TestTypeWatchers.test_error)  s    \\tzz\**cJJs+--  MM))HN bmm22D9  R]]%<%<!=wG . r" +*-- +**s$   $DBC=	D=DDD!	c           	         ! R  R4      p ! R R4      pV P                  4       ;_uu_ 4       pV P                  V P                  R7      ;_uu_ 4       pV P                  W44       V P                  W14       V P                  WB4       RVn        RVn        V P                  W..4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)c                       ] tR tRtRtR# ).TestTypeWatchers.test_two_watchers.<locals>.C1i8  rc   Nrd   rc   r   r   C1r   8      $r   r   c                       ] tR tRtRtR# ).TestTypeWatchers.test_two_watchers.<locals>.C2i9  rc   Nrd   rc   r   r   C2r  9  r  r   r  rv   r:   rB   N)r!   WRAPassertNotEqualr1   r;   rr   r+   )r   r   r  r   r   s   &    r   r   "TestTypeWatchers.test_two_watchers7  s    \\^^t499--##D/

4$

4$""B:. . ^-- ^^s$   %CAB9	'C9C	CC	c                @    ! R  R4      p\        4       ;_uu_ 4       pRpW0P                  ^,
          8  d"   VP                  V P                  4       4      pK8  V P	                  W14       RVn        V P                  V.4       RRR4       R#   + '       g   i     R# ; i)c                       ] tR tRtRtR# )-TestTypeWatchers.test_all_watchers.<locals>.CiD  rc   Nrd   rc   r   r   r   r
  D  r   r   r   r:   Nr   )r   TYPE_MAX_WATCHERSenter_contextr!   r1   r;   r+   )r   r   stacklast_wids   &   r   test_all_watchers"TestTypeWatchers.test_all_watchersC  sm    [[EH 33a77 ..t||~>JJx#AEs# [[[s   A%BB	c           	        V P                  4       ;_uu_ 4       pV P                  \        R 4      ;_uu_ 4        V P                  V^4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; izCannot watch non-typeNr   r   s   & r   test_watch_non_type$TestTypeWatchers.test_watch_non_typeO  sO    \\^^s''
4LMM

3" N ^MM ^^r   c                `    ! R  R4      pV P                  \        R4      ;_uu_ 4        V P                  RV4       RRR4       V P                  \        R4      ;_uu_ 4        V P                  V P                  V4       RRR4       R#   + '       g   i     LU; i  + '       g   i     R# ; i)c                       ] tR tRtRtR# )>TestTypeWatchers.test_watch_out_of_range_watcher_id.<locals>.CiU  rc   Nrd   rc   r   r   r   r  U  r   r   r   Invalid type watcher ID -1NInvalid type watcher ID 8r   )r   r   r1   r  r   r   s   & r   r   3TestTypeWatchers.test_watch_out_of_range_watcher_idT  st    ##J0MNNJJr1 O##J0LMMJJt--q1 NM ONMMM   B	"B	B	B-	c                     ! R  R4      pV P                  \        R4      ;_uu_ 4        V P                  ^V4       RRR4       R#   + '       g   i     R# ; i)c                       ] tR tRtRtR# )<TestTypeWatchers.test_watch_unassigned_watcher_id.<locals>.Ci\  rc   Nrd   rc   r   r   r   r  \  r   r   r   No type watcher set for ID 1Nr   r  s   & r   r   1TestTypeWatchers.test_watch_unassigned_watcher_id[  s9    ##J0OPPJJq! QPPP   AA	c           	        V P                  4       ;_uu_ 4       pV P                  \        R 4      ;_uu_ 4        V P                  V^4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; ir  r   r   s   & r   test_unwatch_non_type&TestTypeWatchers.test_unwatch_non_type`  sO    \\^^s''
4LMMS!$ N ^MM ^^r   c                `    ! R  R4      pV P                  \        R4      ;_uu_ 4        V P                  RV4       RRR4       V P                  \        R4      ;_uu_ 4        V P                  V P                  V4       RRR4       R#   + '       g   i     LU; i  + '       g   i     R# ; i)c                       ] tR tRtRtR# )@TestTypeWatchers.test_unwatch_out_of_range_watcher_id.<locals>.Cif  rc   Nrd   rc   r   r   r   r(  f  r   r   r   r  Nr  r   )r   r   r6   r  r  s   & r   r   5TestTypeWatchers.test_unwatch_out_of_range_watcher_ide  st    ##J0MNNLLQ O##J0LMMLL//3 NM ONMMMr  c                     ! R  R4      pV P                  \        R4      ;_uu_ 4        V P                  ^V4       RRR4       R#   + '       g   i     R# ; i)c                       ] tR tRtRtR# )>TestTypeWatchers.test_unwatch_unassigned_watcher_id.<locals>.Cim  rc   Nrd   rc   r   r   r   r,  m  r   r   r   r   Nr   r  s   & r   r   3TestTypeWatchers.test_unwatch_unassigned_watcher_idl  s9    ##J0OPPLLA QPPPr"  c                H   V P                  \        R 4      ;_uu_ 4        V P                  R4       RRR4       V P                  \        R4      ;_uu_ 4        V P                  V P                  4       RRR4       R#   + '       g   i     LT; i  + '       g   i     R# ; i)r  Nr  r   )r   r   r   r  r   s   &r   r   3TestTypeWatchers.test_clear_out_of_range_watcher_idq  so    ##J0MNNr" O##J0LMMt556 NM ONMMMs   A=B=B	B!	c                    V P                  \        R 4      ;_uu_ 4        V P                  ^4       RRR4       R#   + '       g   i     R# ; i)r   Nr   r   s   &r   r   1TestTypeWatchers.test_clear_unassigned_watcher_idw  r   r   c           	     \   V P                  \        R 4      ;_uu_ 4        \        4       ;_uu_ 4       p\        V P                  ^,           4       F"  pVP                  V P                  4       4       K$  	  RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)zno more type watcher IDsN)r   RuntimeErrorr   rl   r  r  r!   )r   r  rn   s   &  r   test_no_more_ids_available+TestTypeWatchers.test_no_more_ids_available{  sn    ##L2MNNt559:A''7 ;  ON ONNs#   BAB	5BBBB+	rc   N)#re   rf   rg   rh   TYPESrx   r  r  r   r   r   r!   r+   r1   r6   r   r   r   r   r   r   r   r   r  r  r   r   r$  r   r   r   r   r4  ri   r   r   s   @r   r   r      s     EED $ 01   $ $+%'$$	'	$$$#
/
$#
2
%
4
7"8 8r   r   c                   Z   a  ] tR tRt o ]R 4       tR tR tR tR t	R t
R tR	 tR
tV tR# )TestCodeObjectWatchersi  c              #     "   \         P                  V4      p Vx  \         P                  V4       R #   \         P                  T4       i ; i5ir   )r   add_code_watcherclear_code_watcher)r   which_watcherr    s   && r   code_watcher#TestCodeObjectWatchers.code_watcher  s;     ((7	.I((-I((-   A4 AAAc                B   \        4        V P                  V\        P                  ^ 4      4       V P                  V\        P	                  ^ 4      4       V P                  V\        P                  ^4      4       V P                  V\        P	                  ^4      4       R# r   N)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_counts*TestCodeObjectWatchers.assert_event_counts  s    9HHK	MYLLQO	Q9HHK	MYLLQO	Qr   c           
     R   V P                  ^ ^ ^ ^ 4       \        P                  RR^ 4      pV P                  ^ ^ ^ ^ 4       ?V P                  ^ ^ ^ ^ 4       V P                  ^ 4      ;_uu_ 4        V P                  ^ ^ ^ ^ 4       \        P                  RR^ 4      pV P                  ^^ ^ ^ 4       ?V P                  ^^^ ^ 4       V P                  ^4      ;_uu_ 4        V P                  ^^^ ^ 4       \        P                  RR^ 4      pV P                  ^^^^ 4       ?V P                  ^^^^4       RRR4       RRR4       \        P                  RR^ 4      pV P                  ^ ^ ^ ^ 4       ?V P                  ^ ^ ^ ^ 4       R#   + '       g   i     LZ; i  + '       g   i     Le; i)r   test_watchersdummy1dummy2dummy3Ndummy4)rH  r   code_newemptyr=  )r   co1co2co3co4s   &    r   "test_code_object_events_dispatched9TestCodeObjectWatchers.test_code_object_events_dispatched  s     Aq!, %%oxC  Aq!,  Aq!, q!!$$Q1a0))/8QGC$$Q1a0$$Q1a0 ""1%%((Aq!4--oxK((Aq!4((Aq!4 & "  %%oxC  Aq!,  Aq!, &% "!s&   .A.FAF	1FFFF&	c           	        V P                  ^4      ;_uu_ 4        \        4       ;_uu_ 4       p\        P                  RR^ 4      pV P	                  VP
                  P                  RV: 24       V P                  VP
                  P                  4       V P	                  \        VP
                  P                  4      R4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)   rK  dummy0z?Exception ignored in PY_CODE_EVENT_CREATE watcher callback for rw   N)r=  r   r   rP  r'   rz   r{   r|   r}   r~   r   )r   r   cos   &  r   r   !TestCodeObjectWatchers.test_error  s    q!!+--,,_hJ  MM))AACH
 !!"--"6"67  R]]%<%<!=wG . "!-- "!!s#   C(BC	C(C% C((C9	c           	     p   \         P                  R R^ 4      pV P                  ^4      ;_uu_ 4        \        4       ;_uu_ 4       p?\	        4        V P                  \        VP                  P                  4      R4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)rK  rY  rw   N)	r   rP  r=  r   r   r'   r~   rz   r   )r   rZ  r   s   &  r   r   )TestCodeObjectWatchers.test_dealloc_error  sy    $$_hBq!!+--  R]]%<%<!=wG	 . "!-- "!!s#   B$;B	?B$B!B$$B5	c                D   V P                  \        R 4      ;_uu_ 4        \        P                  R4       RRR4       V P                  \        R4      ;_uu_ 4        \        P                  ^4       RRR4       R#   + '       g   i     LN; i  + '       g   i     R# ; i)zInvalid code watcher ID -1NzInvalid code watcher ID 8r   r   r   r   r;  r   s   &r   r   9TestCodeObjectWatchers.test_clear_out_of_range_watcher_id  i    ##J0MNN((, O##J0LMM((+ NM ONMMM   A;B;B	B	c                    V P                  \        R 4      ;_uu_ 4        \        P                  ^4       RRR4       R#   + '       g   i     R# ; i)zNo code watcher set for ID 1Nr_  r   s   &r   r   7TestCodeObjectWatchers.test_clear_unassigned_watcher_id  4    ##J0OPP((+ QPPP	   ?A	c                    V P                  \        R 4      ;_uu_ 4        \        P                  4        RRR4       R#   + '       g   i     R# ; i)z"no more code watcher IDs availableN)r   r3  r   allocate_too_many_code_watchersr   s   &r   test_allocate_too_many_watchers6TestCodeObjectWatchers.test_allocate_too_many_watchers  s2    ##L2WXX557 YXXX	   >A	rc   N)re   rf   rg   rh   r   r=  rH  rU  r   r   r   r   ri  ri   r   r   s   @r   r8  r8    sC     . .
Q-BHH,,8 8r   r8  c                   Z   a  ] tR tRt o ]R 4       tR tR tR tR t	R t
R tR	 tR
tV tR# )TestFuncWatchersi  c              #     "   \         P                  V4      p R x  \         P                  V4       R #   \         P                  T4       i ; i5ir   )r   add_func_watcherclear_func_watcher)r   funcr    s   && r   r   TestFuncWatchers.add_watcher  s9     ((.	.((-I((-r?  c                B  a . oV3R  lpV P                  V4      ;_uu_ 4        R pV P                  \        P                  VR3S4       \	        V4      pV P
                  P                  pWBn        V P                  \        P                  W$3S4       RpWRn        V P                  \        P                  W%3S4       Rp\        P                  W%4       V P                  \        P                  W%3S4       R^{/pWbn        V P                  \        P                  W&3S4       RR/p\        P                  W&4       V P                  \        P                  W&3S4       . o?V P                  \        P                  VR3S4       RRR4       R#   + '       g   i     R# ; i)c                  *   < SP                  V 4       R # r   append)argseventss   *r   r!   =TestFuncWatchers.test_func_events_dispatched.<locals>.watcher  s    MM$r   c                      R # r   rc   rc   r   r   myfunc<TestFuncWatchers.test_func_events_dispatched.<locals>.myfunc  s    r   N  r   ){   )r}  )r   ry   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_kwdefaultsrx  s   &      @r   r  ,TestFuncWatchers.test_func_events_dispatched  sY   	  g&&MM988&$GP6
I77@@H&OMM9==vPRXY!L".MM9AA6XZ`a!L00FMM9AA6XZ`a$c]N$2!MM9CCV\^de$c]N226JMM9CCV\^de FMM9999dKVT; '&&&s   E FF	c           	     t  aa . oV3R  lp. oV3R lpV P                  V4      ;_uu_ 4        V P                  V4      ;_uu_ 4        R p\        P                  VR3pV P                  VS4       V P                  VS4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)c                  *   < SP                  V 4       R # r   ru  )rw  events0s   *r   first_watcher>TestFuncWatchers.test_multiple_watchers.<locals>.first_watcher      NN4 r   c                  *   < SP                  V 4       R # r   ru  )rw  events1s   *r   second_watcher?TestFuncWatchers.test_multiple_watchers.<locals>.second_watcher  r  r   c                      R # r   rc   rc   r   r   r{  7TestFuncWatchers.test_multiple_watchers.<locals>.myfunc      r   N)r   r   r  ry   )r   r  r  r{  eventr  r  s   &    @@r   test_multiple_watchers'TestFuncWatchers.test_multiple_watchers
  s    	! 	! m,,!!.11 #66EeW-eW- 2 -,11 -,,s#   B&;B	B&B#B&&B7	c                  a  ! R  R\         4      oV3R lpV P                  V4      ;_uu_ 4        \        4       ;_uu_ 4       pR pV P                  VP                  P
                  R\        V4      ^R  24       V P                  VP                  P                  4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)c                       ] tR tRtRtR# );TestFuncWatchers.test_watcher_raises_error.<locals>.MyErrori  rc   Nrd   rc   r   r   MyErrorr        r   r  c                     < S! R 4      hztesting 123rc   rw  r  s   *r   r!   ;TestFuncWatchers.test_watcher_raises_error.<locals>.watcher       -((r   c                      R # r   rc   rc   r   r   r{  :TestFuncWatchers.test_watcher_raises_error.<locals>.myfunc%  r  r   zBException ignored in PyFunction_EVENT_CREATE watcher callback for Nr   )		Exceptionr   r   r'   rz   r{   reprr|   r}   )r   r!   r   r{  r  s   &   @r   test_watcher_raises_error*TestFuncWatchers.test_watcher_raises_error  s    	i 		) g&&+--   MM))DDHLQRSUDVCWY
 !!"--"6"67 . '&-- '&&s$   CAB3	!C3C>CC	c           	     N  a  ! R  R\         4      oV3R lpR pV P                  V4      ;_uu_ 4        \        4       ;_uu_ 4       p?V P                  VP                  P
                  S4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)c                       ] tR tRtRtR# )CTestFuncWatchers.test_dealloc_watcher_raises_error.<locals>.MyErrori0  rc   Nrd   rc   r   r   r  r  0  r  r   r  c                     < S! R 4      hr  rc   r  s   *r   r!   CTestFuncWatchers.test_dealloc_watcher_raises_error.<locals>.watcher3  r  r   c                      R # r   rc   rc   r   r   r{  BTestFuncWatchers.test_dealloc_watcher_raises_error.<locals>.myfunc6  s    r   N)r  r   r   assertIsInstancerz   r   )r   r!   r{  r   r  s   &   @r   !test_dealloc_watcher_raises_error2TestFuncWatchers.test_dealloc_watcher_raises_error/  st    	i 		)	 g&&+--%%bmm&=&=wG . '&-- '&&s#   B(B 	.B BBB$	c                D   V P                  \        R 4      ;_uu_ 4        \        P                  R4       RRR4       V P                  \        R4      ;_uu_ 4        \        P                  ^4       RRR4       R#   + '       g   i     LN; i  + '       g   i     R# ; i)zinvalid func watcher ID -1Nzinvalid func watcher ID 8r   r   r   r   rp  r   s   &r   r   3TestFuncWatchers.test_clear_out_of_range_watcher_id?  ra  rb  c                    V P                  \        R 4      ;_uu_ 4        \        P                  ^4       RRR4       R#   + '       g   i     R# ; i)zno func watcher set for ID 1Nr  r   s   &r   r   1TestFuncWatchers.test_clear_unassigned_watcher_idE  re  rf  c                    V P                  \        R 4      ;_uu_ 4        \        P                  4        RRR4       R#   + '       g   i     R# ; i)zno more func watcher IDsN)r   r3  r   allocate_too_many_func_watchersr   s   &r   ri  0TestFuncWatchers.test_allocate_too_many_watchersI  s2    ##L2MNN557 ONNNrk  rc   N)re   rf   rg   rh   r   r   r  r  r  r  r   r   ri  ri   r   r   s   @r   rm  rm    sB     . ."UH.$8&H ,,8 8r   rm  c                   Z   a  ] tR tRt o ]R 4       tR tR tR tR t	R t
R tR	 tR
tV tR# )TestContextObjectWatchersiN  c              #     "   \         P                  V4      p \         P                  V4      p Vx  \         P	                  V4       R #   \         d    R p L+i ; i  \         P	                  T4       i ; i5ir   )r   add_context_watcherget_context_switchesr   clear_context_watcher)r   r<  r    switchess   &&  r   context_watcher)TestContextObjectWatchers.context_watcherO  sh     ++M:	 55mDH	1N++C0  	H	
 ++C0s8   A7A
 A A7
AA7AA7A44A7c                    V P                  \        \        P                  ^ 4      4      V4       V P                  \        \        P                  ^4      4      V4       R# rA  )r'   lenr   r  )r   want_0want_1s   &&&r   rH  -TestContextObjectWatchers.assert_event_counts[  sB    Y;;A>?HY;;A>?Hr   c           	        V P                  ^ ^ 4       \        P                  ! 4       pVP                  V P                   ^ ^ 4       V P                  ^ ^ 4       V P	                  ^ 4      ;_uu_ 4        V P                  ^ ^ 4       VP                  V P                   ^^ 4       V P                  ^^ 4       V P	                  ^4      ;_uu_ 4        V P                  ^^ 4       VP                  V P                   ^^4       V P                  ^^4       RRR4       RRR4       VP                  V P                   ^ ^ 4       V P                  ^ ^ 4       R#   + '       g   i     LI; i  + '       g   i     LT; irA  )rH  contextvarscopy_contextrunr  )r   ctxs   & r   %test_context_object_events_dispatched?TestContextObjectWatchers.test_context_object_events_dispatched_  s     A& &&(((!Q/  A& !!!$$$$Q*GGD,,a3$$Q* %%a((((A.00!Q7((A. ) % 	((!Q/  A& )( %$s&   0AE!AE	E!EE!!E1	c                  a aa \         P                  ! 4       p\         P                  ! 4       o. oVV V3R  lp VP                  V4       S P                  S Uu. uF  q3P                  NK  	  upSV3 Uu. uF	  pRV: 2NK  	  up4       S P                  S Uu. uF  p\        VP                  4      NK  	  upRR.4       RoR# u upi u upi u upi   Roi ; i)c            	      4  <a  SP                  ^4      ;_uu_ 4        \        4       ;_uu_ 4       o SP                  V V3R l4       SP                  S P                  4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)rX  c                  :   < SP                  S P                  4      # r   )rv  rz   )r   unraisabless   r   <lambda>RTestContextObjectWatchers.test_callback_error.<locals>._in_outer.<locals>.<lambda>  s    +*<*<R]]*Kr   N)r  r   r  rv  rz   )r   	ctx_innerr   r  s   @r   	_in_outer@TestContextObjectWatchers.test_callback_error.<locals>._in_outer~  s^    %%a((/11RMM"KL&&r}}5 2 )(11 )((s"   B2A3	!B3B>BB	z>Exception ignored in Py_CONTEXT_SWITCHED watcher callback for rw   N)r  r  r  r'   r{   r~   r   )r   	ctx_outerr  xr  r  r  s   f    @@r   test_callback_error-TestContextObjectWatchers.test_callback_errory  s    ,,.	,,.		6
	MM)$=Aii= +4Y)?A)?#669W>)?AB D1c!++.D%w/1 K >A E Ks5    C C-C 5C
C C8
C C Cc                D   V P                  \        R 4      ;_uu_ 4        \        P                  R4       RRR4       V P                  \        R4      ;_uu_ 4        \        P                  ^4       RRR4       R#   + '       g   i     LN; i  + '       g   i     R# ; i)zInvalid context watcher ID -1NzInvalid context watcher ID 8r   r   r   r   r  r   s   &r   r   <TestContextObjectWatchers.test_clear_out_of_range_watcher_id  si    ##J0PQQ++B/ R##J0OPP++A. QP RQPPPrb  c                    V P                  \        R 4      ;_uu_ 4        \        P                  ^4       RRR4       R#   + '       g   i     R# ; i)zNo context watcher set for ID 1Nr  r   s   &r   r   :TestContextObjectWatchers.test_clear_unassigned_watcher_id  s4    ##J0RSS++A. TSSSrf  c                    V P                  \        R 4      ;_uu_ 4        \        P                  4        RRR4       R#   + '       g   i     R# ; i)z%no more context watcher IDs availableN)r   r3  r   "allocate_too_many_context_watchersr   s   &r   ri  9TestContextObjectWatchers.test_allocate_too_many_watchers  s2    ##L2Z[[88: \[[[rk  c                   \         P                  ! 4       p\        P                  4        V P	                  ^ 4      ;_uu_ 4       pVP                  R 4       RRR4       V P                  XVR.4       R#   + '       g   i     L&; i)r   c                      R # r   rc   rc   r   r   r  BTestContextObjectWatchers.test_exit_base_context.<locals>.<lambda>  s    Dr   N)r  Contextr   clear_context_stackr  r  r'   )r   r  r  s   &  r   test_exit_base_context0TestContextObjectWatchers.test_exit_base_context  s]    !!#%%'!!!$$GGL! %C;/ %$s   A44B	rc   N)re   rf   rg   rh   r   r  rH  r  r  r   r   ri  r  ri   r   r   s   @r   r  r  N  s@     	1 	1I'4.//;0 0r   r  __main__)unittestr  
contextlibr   r   test.supportr   r   r   import_moduler   TestCaser
   r   r8  rm  r  re   mainrc   r   r   <module>r     s      0  ''4	|"x(( |"~r8x(( r8jX8X.. X8vn8x(( n8bU0 1 1 U0n zMMO r   