
    2hhfQ                     0   S SK r S SKJrJr  S SKJrJrJrJr  \R                  " S5      r
 " S S\ R                  5      r " S S\ R                  5      r " S	 S
\ R                  5      r " S S\ R                  5      r\S:X  a  \ R"                  " 5         gg)    N)contextmanager	ExitStack)catch_unraisable_exceptionimport_helper
gc_collectsuppress_immortalization	_testcapic                       \ rS rSrSrSrSr\4S jrS r\	\4S j5       r
S rS	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S r"S r#g!)"TestDictWatchers   r         c                 ,    [         R                  U5      $ N)r	   add_dict_watcherselfkinds     E/opt/python-3.13.8/usr/lib/python3.13/test/test_capi/test_watchers.pyadd_watcherTestDictWatchers.add_watcher       ))$//    c                 .    [         R                  U5        g r   )r	   clear_dict_watcherr   
watcher_ids     r   clear_watcherTestDictWatchers.clear_watcher       $$Z0r   c              #      #    U R                  U5      n Uv   U R                  U5        g ! U R                  U5        f = f7fr   r   r   r   r   wids      r   watcherTestDictWatchers.watcher   ;     t$	$Is#Ds#   A+ A>Ac                 N    [         R                  5       nU R                  X!5        g r   )r	   get_dict_watcher_eventsassertEqualr   expectedactuals      r   assert_eventsTestDictWatchers.assert_events!   s    224*r   c                 .    [         R                  X5        g r   )r	   
watch_dictr   r$   ds      r   watchTestDictWatchers.watch%       S$r   c                 .    [         R                  X5        g r   )r	   unwatch_dictr3   s      r   unwatchTestDictWatchers.unwatch(       s&r   c                     0 nU R                  5        nU R                  X!5        SUS'   U R                  S/5        S S S 5        g ! , (       d  f       g = f)Nbarfoonew:foo:barr%   r5   r/   r   r4   r$   s      r   test_set_new_item"TestDictWatchers.test_set_new_item+   sA    \\^sJJsAeH/ ^^s   )A
Ac                     SS0nU R                  5        nU R                  X!5        SUS'   U R                  S/5        S S S 5        g ! , (       d  f       g = f)Nr?   r>   bazmod:foo:bazrA   rB   s      r   test_set_existing_item'TestDictWatchers.test_set_existing_item2   sE    EN\\^sJJsAeH/ ^^s   )A
Ac                     0 nSS0nU R                  5        nU R                  X15        UR                  U5        U R                  S/5        S S S 5        g ! , (       d  f       g = f)Nr?   r>   clone)r%   r5   updater/   )r   r4   d2r$   s       r   
test_cloneTestDictWatchers.test_clone9   sL    U^\\^sJJsHHRLy) ^^s   5A
A#c                     0 nU R                  5        nSUS'   U R                  / 5        S S S 5        g ! , (       d  f       g = f)Nr>   r?   )r%   r/   rB   s      r   test_no_event_if_not_watched-TestDictWatchers.test_no_event_if_not_watchedA   s3    \\^sAeHr" ^^s	   3
Ac                     SS0nU R                  5        nU R                  X!5        US	 U R                  S/5        S S S 5        g ! , (       d  f       g = fNr?   r>   del:foorA   rB   s      r   test_delTestDictWatchers.test_delG   sC    EN\\^sJJs%	{+ ^^s   'A
Ac                     SS0nU R                  5        nU R                  X!5        UR                  S5        U R                  S/5        S S S 5        g ! , (       d  f       g = frT   )r%   r5   popr/   rB   s      r   test_popTestDictWatchers.test_popN   sG    EN\\^sJJsEE%L	{+ ^^s   5A
A!c                     SS0nU R                  5        nU R                  X!5        UR                  5         U R                  S/5        S S S 5        g ! , (       d  f       g = f)Nr?   r>   clear)r%   r5   r]   r/   rB   s      r   
test_clearTestDictWatchers.test_clearU   sE    EN\\^sJJsGGIy) ^^s   4A
A c                     SS0nU R                  5        nU R                  X!5        AU R                  S/5        S S S 5        g ! , (       d  f       g = f)Nr?   r>   deallocrA   rB   s      r   test_deallocTestDictWatchers.test_dealloc\   s?    EN\\^sJJs	{+ ^^s   %A
Ac                     " S S5      nU" 5       nU R                  5        nU R                  X2R                  5        SUl        SUl        U?U R	                  / SQ5        S S S 5        U R                  5        nU R                  X2R                  5        [        S5       H
  nSUl        M     U R	                  S/S/S	-  -   5        S S S 5        g ! , (       d  f       Nu= f! , (       d  f       g = f)
Nc                       \ rS rSrSrg)0TestDictWatchers.test_object_dict.<locals>.MyObjd    N__name__
__module____qualname____firstlineno____static_attributes__rh   r   r   MyObjrf   d   s    Tr   ro   r>   rF   )r@   rG   rU   rg   r@   zmod:foo:barc   )r%   r5   __dict__r?   r/   range)r   ro   or$   _s        r   test_object_dict!TestDictWatchers.test_object_dictc   s    G\\^sJJsJJ'AEAEHI  \\^sJJsJJ'3Z  -21EEF	 ^ ^ ^s   ?C9AC!
C!
C/c                     0 nU R                  5        nU R                  X!5        SUS'   U R                  X!5        SUS'   U R                  S/5        S S S 5        g ! , (       d  f       g = f)Nr>   r?   rF   hmmr@   )r%   r5   r:   r/   rB   s      r   test_unwatchTestDictWatchers.test_unwatcht   sV    \\^sJJsAeHLL AeH/ ^^s   ?A
A)c                    0 nU R                  U R                  S9 nU R                  X!5        [        5        nSUS'   U R	                  SUR
                  R                  5        U R                  UR
                  R                  5        U R                  [        UR
                  R                  5      S5        S S S 5        U R                  / 5        S S S 5        g ! , (       d  f       N(= f! , (       d  f       g = f)Nr   r>   r?   zFException ignored in PyDict_EVENT_ADDED watcher callback for <dict at boom!)r%   ERRORr5   r   assertIn
unraisableerr_msgassertIsNoneobjectr+   str	exc_valuer/   r   r4   r$   cms       r   
test_errorTestDictWatchers.test_error}   s    \\tzz\*cJJs+- %HMM))
 !!"--"6"67  R]]%<%<!=wG . r" +*-- +*s#   C+B C8C+
C(	$C++
C9c                 8   0 nU R                  U R                  S9 nU R                  X!5        [        5        nAU R	                  [        UR                  R                  5      S5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nr|   r}   )r%   r~   r5   r   r+   r   r   r   r   s       r   test_dealloc_error#TestDictWatchers.test_dealloc_error   sn    \\tzz\*cJJs+-  R]]%<%<!=wG . +*-- +*s"   B1A:)B:
B	B
Bc                 D   0 n0 nU R                  5        nU R                  U R                  S9 nU R                  X15        U R                  XB5        SUS'   SUS'   U R                  SS/5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nr|   r>   r?   rF   rx   r@   second)r%   SECONDr5   r/   )r   d1rM   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
Bc                     U R                  5        nU R                  [        S5         U R                  US5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = fNzCannot watch non-dictionaryr   r%   assertRaisesRegex
ValueErrorr5   r   r$   s     r   test_watch_non_dict$TestDictWatchers.test_watch_non_dict   sH    \\^s''
4RS

3" T ^SS ^!   AAA
A	A
A+c                    0 nU R                  [        S5         U R                  SU5        S S S 5        U R                  [        S5         U R                  SU5        S S S 5        g ! , (       d  f       N@= f! , (       d  f       g = fNzInvalid dict watcher ID -1zInvalid dict watcher ID 8   r   r   r5   r   r4   s     r   "test_watch_out_of_range_watcher_id3TestDictWatchers.test_watch_out_of_range_watcher_id   se    ##J0MNJJr1 O##J0LMJJq! NM ONMM   A&
A7&
A47
Bc                     0 nU R                  [        S5         U R                  SU5        S S S 5        g ! , (       d  f       g = fNzNo dict watcher set for ID 3   r   r   s     r    test_watch_unassigned_watcher_id1TestDictWatchers.test_watch_unassigned_watcher_id   s3    ##J0OPJJq! QPP	   5
Ac                     U R                  5        nU R                  [        S5         U R                  US5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = fr   r%   r   r   r:   r   s     r   test_unwatch_non_dict&TestDictWatchers.test_unwatch_non_dict   sH    \\^s''
4RSS!$ T ^SS ^r   c                    0 nU R                  [        S5         U R                  SU5        S S S 5        U R                  [        S5         U R                  SU5        S S S 5        g ! , (       d  f       N@= f! , (       d  f       g = fr   r   r   r:   r   s     r   $test_unwatch_out_of_range_watcher_id5TestDictWatchers.test_unwatch_out_of_range_watcher_id   se    ##J0MNLLQ O##J0LMLLA NM ONMMr   c                     0 nU R                  [        S5         U R                  SU5        S S S 5        g ! , (       d  f       g = fr   r   r   s     r   "test_unwatch_unassigned_watcher_id3TestDictWatchers.test_unwatch_unassigned_watcher_id   s3    ##J0OPLLA QPPr   c                    U R                  [        S5         U R                  S5        S S S 5        U R                  [        S5         U R                  S5        S S S 5        g ! , (       d  f       N?= f! , (       d  f       g = fr   r   r   r   r   s    r   "test_clear_out_of_range_watcher_id3TestDictWatchers.test_clear_out_of_range_watcher_id   s`    ##J0MNr" O##J0LMq! NM ONMMs   A"A3"
A03
Bc                     U R                  [        S5         U R                  S5        S S S 5        g ! , (       d  f       g = fr   r   r   s    r    test_clear_unassigned_watcher_id1TestDictWatchers.test_clear_unassigned_watcher_id   .    ##J0OPq! QPP	   2
A rh   N)$rj   rk   rl   rm   EVENTSr~   r   r   r   r   r%   r/   r5   r:   rC   rH   rN   rQ   rV   rZ   r^   rb   ru   ry   r   r   r   r   r   r   r   r   r   r   r   rn   rh   r   r   r   r      s    FEF% 01 ! $ $+%'00*#,,*,G"0#H	>#

%

""r   r   c                       \ rS rSrSrSrSrSr\4S jrS r	\
\4S j5       rS	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r Sr!g) TestTypeWatchers   r   r   r   r   c                 ,    [         R                  U5      $ r   )r	   add_type_watcherr   s     r   r   TestTypeWatchers.add_watcher   r   r   c                 .    [         R                  U5        g r   )r	   clear_type_watcherr   s     r   r   TestTypeWatchers.clear_watcher   r    r   c              #      #    U R                  U5      n Uv   U R                  U5        g ! U R                  U5        f = f7fr   r"   r#   s      r   r%   TestTypeWatchers.watcher   r'   r(   c                 N    [         R                  5       nU R                  X!5        g r   )r	   get_type_modified_eventsr+   r,   s      r   r/   TestTypeWatchers.assert_events   s    335*r   c                 .    [         R                  X5        g r   )r	   
watch_typer   r$   ts      r   r5   TestTypeWatchers.watch   r7   r   c                 .    [         R                  X5        g r   )r	   unwatch_typer   s      r   r:   TestTypeWatchers.unwatch   r<   r   c                      " S S5      nU R                  5        nU R                  X!5        SUl        U R                  U/5        S S S 5        g ! , (       d  f       g = f)Nc                       \ rS rSrSrg)+TestTypeWatchers.test_watch_type.<locals>.C   rh   Nri   rh   r   r   Cr          r   r   r>   r%   r5   r?   r/   r   r   r$   s      r   test_watch_type TestTypeWatchers.test_watch_type   s?    \\^sJJsAEs# ^^s   +A
Ac                      " S S5      nU R                  5        nU R                  X!5        SUl        SUl        U R	                  U/5        S S S 5        g ! , (       d  f       g = f)Nc                       \ rS rSrSrg)2TestTypeWatchers.test_event_aggregation.<locals>.C   rh   Nri   rh   r   r   r   r      r   r   r   r>   rF   )r%   r5   r?   r>   r/   r   s      r   test_event_aggregation'TestTypeWatchers.test_event_aggregation   sF    \\^sJJsAEAEs# ^^s   2A
A$c                     " S S5      nU R                  5        nU R                  X!5        SUl        U R                  UR                  S5        SUl        U R                  X/5        S S S 5        g ! , (       d  f       g = f)Nc                       \ rS rSrSrg):TestTypeWatchers.test_lookup_resets_aggregation.<locals>.C   rh   Nri   rh   r   r   r   r      r   r   r   r>   rF   )r%   r5   r?   r+   r>   r/   r   s      r   test_lookup_resets_aggregation/TestTypeWatchers.test_lookup_resets_aggregation   sZ    \\^sJJsAEQUUE*AEv& ^^s   AA22
B c                 L    " S S5      nU R                  5        nU R                  X!5        SUl        U R                  UR                  S5        U R	                  U/5        U R                  X!5        SUl        U R	                  U/5        S S S 5        g ! , (       d  f       g = f)Nc                       \ rS rSrSrg)-TestTypeWatchers.test_unwatch_type.<locals>.Ci	  rh   Nri   rh   r   r   r   r   	  r   r   r   r>   rF   )r%   r5   r?   r+   r/   r:   r>   r   s      r   test_unwatch_type"TestTypeWatchers.test_unwatch_type  sv    \\^sJJsAEQUUE*s#LL AEs# ^^s   A1B
B#c                 ~    " S S5      nU R                  5        nU R                  5        nU R                  X15        SUl        U R                  UR                  S5        U R	                  U/5        S S S 5        SUl        U R	                  U/5        S S S 5        g ! , (       d  f       N0= f! , (       d  f       g = f)Nc                       \ rS rSrSrg).TestTypeWatchers.test_clear_watcher.<locals>.Ci  rh   Nri   rh   r   r   r   r     r   r   r   r>   rF   )r%   r5   r?   r+   r/   r>   )r   r   rt   r$   s       r   test_clear_watcher#TestTypeWatchers.test_clear_watcher  s    \\^q3

3"  .""A3'	  
 AEs# ^ ^s#   B.AB3!B.
B+	'B..
B<c                      " S S5      n " S SU5      nU R                  5        nU R                  X25        SUl        U R                  U/5        S S S 5        g ! , (       d  f       g = f)Nc                       \ rS rSrSrg)4TestTypeWatchers.test_watch_type_subclass.<locals>.Ci!  rh   Nri   rh   r   r   r   r   !  r   r   r   c                       \ rS rSrSrg)4TestTypeWatchers.test_watch_type_subclass.<locals>.Di"  rh   Nri   rh   r   r   Dr   "  s    Dr   r   r>   r   )r   r   r   r$   s       r   test_watch_type_subclass)TestTypeWatchers.test_watch_type_subclass   sG    \\^sJJsAEs# ^^s   +A
A(c                     " S S5      nU R                  U R                  S9 nU R                  X!5        [        5        nSUl        U R                  UR                  R                  SU< 35        U R                  UR                  R                  S 5        U R                  [        UR                  R                  5      S5        S S S 5        U R                  / 5        S S S 5        g ! , (       d  f       N(= f! , (       d  f       g = f)Nc                       \ rS rSrSrg)&TestTypeWatchers.test_error.<locals>.Ci)  rh   Nri   rh   r   r   r   r  )  r   r   r   r|   r>   z2Exception ignored in type watcher callback #0 for r}   )r%   r~   r5   r   r?   r+   r   r   assertIsr   r   r   r/   )r   r   r$   r   s       r   r   TestTypeWatchers.test_error(  s    \\tzz\*cJJs+-  !6!6HNPbmm22D9  R]]%<%<!=wG . r" +*-- +*s$   C: BC)C:)
C7	3C::
Dc                     " S S5      n " S S5      nU R                  5        nU R                  U R                  S9 nU R                  X45        U R                  X15        U R                  XB5        SUl        SUl        U R                  X//5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nc                       \ rS rSrSrg).TestTypeWatchers.test_two_watchers.<locals>.C1i5  rh   Nri   rh   r   r   C1r  5      $r   r	  c                       \ rS rSrSrg).TestTypeWatchers.test_two_watchers.<locals>.C2i6  rh   Nri   rh   r   r   C2r  6  r
  r   r  r|   r>   rF   )r%   WRAPassertNotEqualr5   r?   rx   r/   )r   r	  r  r   r   s        r   r   "TestTypeWatchers.test_two_watchers4  s    \\^t499-##D/

4$

4$""B:. . ^-- ^s#   B6AB%B6%
B3	/B66
Cc                 B    " S S5      n[        5        nSnX0R                  S-
  :  a3  UR                  U R                  5       5      nX0R                  S-
  :  a  M3  U R	                  X15        SUl        U R                  U/5        S S S 5        g ! , (       d  f       g = f)Nc                       \ rS rSrSrg)-TestTypeWatchers.test_all_watchers.<locals>.CiA  rh   Nri   rh   r   r   r   r  A  r   r   r   r   r   r>   )r   TYPE_MAX_WATCHERSenter_contextr%   r5   r?   r/   )r   r   stacklast_wids       r   test_all_watchers"TestTypeWatchers.test_all_watchers@  s|    [EH 33a77 ..t||~> 33a77JJx#AEs# [[s   AB*B
Bc                     U R                  5        nU R                  [        S5         U R                  US5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = fNzCannot watch non-typer   r   r   s     r   test_watch_non_type$TestTypeWatchers.test_watch_non_typeL  sH    \\^s''
4LM

3" N ^MM ^r   c                 4    " S S5      nU R                  [        S5         U R                  SU5        S S S 5        U R                  [        S5         U R                  U R                  U5        S S S 5        g ! , (       d  f       NJ= f! , (       d  f       g = f)Nc                       \ rS rSrSrg)>TestTypeWatchers.test_watch_out_of_range_watcher_id.<locals>.CiR  rh   Nri   rh   r   r   r   r   R  r   r   r   Invalid type watcher ID -1r   Invalid type watcher ID 8)r   r   r5   r  r   r   s     r   r   3TestTypeWatchers.test_watch_out_of_range_watcher_idQ  sk    ##J0MNJJr1 O##J0LMJJt--q1 NM ONMM   A8B	8
B	
Bc                      " S S5      nU R                  [        S5         U R                  SU5        S S S 5        g ! , (       d  f       g = f)Nc                       \ rS rSrSrg)<TestTypeWatchers.test_watch_unassigned_watcher_id.<locals>.CiY  rh   Nri   rh   r   r   r   r(  Y  r   r   r   No type watcher set for ID 1r   r   r#  s     r   r   1TestTypeWatchers.test_watch_unassigned_watcher_idX  s3    ##J0OPJJq! QPP	   =
Ac                     U R                  5        nU R                  [        S5         U R                  US5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = fr  r   r   s     r   test_unwatch_non_type&TestTypeWatchers.test_unwatch_non_type]  sH    \\^s''
4LMS!$ N ^MM ^r   c                 4    " S S5      nU R                  [        S5         U R                  SU5        S S S 5        U R                  [        S5         U R                  U R                  U5        S S S 5        g ! , (       d  f       NJ= f! , (       d  f       g = f)Nc                       \ rS rSrSrg)@TestTypeWatchers.test_unwatch_out_of_range_watcher_id.<locals>.Cic  rh   Nri   rh   r   r   r   r1  c  r   r   r   r!  r   r"  )r   r   r:   r  r#  s     r   r   5TestTypeWatchers.test_unwatch_out_of_range_watcher_idb  sk    ##J0MNLLQ O##J0LMLL//3 NM ONMMr%  c                      " S S5      nU R                  [        S5         U R                  SU5        S S S 5        g ! , (       d  f       g = f)Nc                       \ rS rSrSrg)>TestTypeWatchers.test_unwatch_unassigned_watcher_id.<locals>.Cij  rh   Nri   rh   r   r   r   r5  j  r   r   r   r)  r   r   r#  s     r   r   3TestTypeWatchers.test_unwatch_unassigned_watcher_idi  s3    ##J0OPLLA QPPr+  c                    U R                  [        S5         U R                  S5        S S S 5        U R                  [        S5         U R                  U R                  5        S S S 5        g ! , (       d  f       NI= f! , (       d  f       g = f)Nr!  r   r"  )r   r   r   r  r   s    r   r   3TestTypeWatchers.test_clear_out_of_range_watcher_idn  sf    ##J0MNr" O##J0LMt556 NM ONMMs   A,A=,
A:=
Bc                     U R                  [        S5         U R                  S5        S S S 5        g ! , (       d  f       g = f)Nr)  r   r   r   s    r   r   1TestTypeWatchers.test_clear_unassigned_watcher_idt  r   r   c                 (   U R                  [        S5         [        5        n[        U R                  S-   5       H"  nUR                  U R                  5       5        M$     S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nzno more type watcher IDsr   )r   RuntimeErrorr   rr   r  r  r%   )r   r  rt   s      r   test_no_more_ids_available+TestTypeWatchers.test_no_more_ids_availablex  sf    ##L2MNt559:A''7 ;  ON ONs"   B?A2!B2
B 	<B
Brh   N)"rj   rk   rl   rm   TYPESr~   r  r  r   r   r   r%   r/   r5   r:   r   r   r   r   r   r   r   r   r  r  r   r   r-  r   r   r   r   r=  rn   rh   r   r   r   r      s    EED $ 01   $ $+%'$$	'	$$$
#
/
$#
2
%
4
7"8r   r   c                   v    \ rS rSr\S 5       rS r\" 5       S 5       rS r	\" 5       S 5       r
S rS rS	 rS
rg)TestCodeObjectWatchersi  c              #      #    [         R                  U5      n Uv   [         R                  U5        g ! [         R                  U5        f = f7fr   )r	   add_code_watcherclear_code_watcher)r   which_watcherr$   s      r   code_watcher#TestCodeObjectWatchers.code_watcher  s;     ((7	.I((-I((-   A3 AA

Ac                 @   [        5         U R                  U[        R                  S5      5        U R                  U[        R	                  S5      5        U R                  U[        R                  S5      5        U R                  U[        R	                  S5      5        g )Nr   r   )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                 (   U R                  SSSS5        [        R                  SSS5      nU R                  SSSS5        AU R                  SSSS5        U R                  S5         U R                  SSSS5        [        R                  SSS5      nU R                  SSSS5        AU R                  SSSS5        U R                  S5         U R                  SSSS5        [        R                  SSS5      nU R                  SSSS5        AU R                  SSSS5        S S S 5        S S S 5        [        R                  SSS5      nU R                  SSSS5        AU R                  SSSS5        g ! , (       d  f       NW= f! , (       d  f       N`= f)	Nr   test_watchersdummy1dummy2r   dummy3r   dummy4)rP  r	   code_newemptyrF  )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E2!F2
F 	<F
Fc                    U R                  S5         [        5        n[        R                  SSS5      nU R	                  UR
                  R                  SU< 35        U R                  UR
                  R                  5        U R	                  [        UR
                  R                  5      S5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nr   rS  dummy0r   z?Exception ignored in PY_CODE_EVENT_CREATE watcher callback for r}   )rF  r   r	   rX  r+   r   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3C
C	C
C#c                 D   [         R                  SSS5      nU R                  S5         [        5        nA[	        5         U R                  [        UR                  R                  5      S5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)NrS  r`  r   r   r}   )	r	   rX  rF  r   r   r+   r   r   r   )r   ra  r   s      r   r   )TestCodeObjectWatchers.test_dealloc_error  sp    $$_hBq!+-  R]]%<%<!=wG	 . "!-- "!s"   B;B /B 
B	
B
Bc                    U R                  [        S5         [        R                  S5        S S S 5        U R                  [        S5         [        R                  S5        S S S 5        g ! , (       d  f       NC= f! , (       d  f       g = f)NzInvalid code watcher ID -1r   zInvalid code watcher ID 8r   r   r   r	   rD  r   s    r   r   9TestCodeObjectWatchers.test_clear_out_of_range_watcher_id  `    ##J0MN((, O##J0LM((+ NM ONMM   A*A;*
A8;
B	c                     U R                  [        S5         [        R                  S5        S S S 5        g ! , (       d  f       g = f)NzNo code watcher set for ID 1r   rf  r   s    r   r   7TestCodeObjectWatchers.test_clear_unassigned_watcher_id  .    ##J0OP((+ QPP	   6
Ac                     U R                  [        S5         [        R                  5         S S S 5        g ! , (       d  f       g = f)Nz"no more code watcher IDs available)r   r<  r	   allocate_too_many_code_watchersr   s    r   test_allocate_too_many_watchers6TestCodeObjectWatchers.test_allocate_too_many_watchers  s,    ##L2WX557 YXX	   5
Arh   N)rj   rk   rl   rm   r   rF  rP  r   r]  r   r   r   r   rp  rn   rh   r   r   rA  rA    s`    . .
Q -  -BH H  H,,8r   rA  c                   N    \ rS rSr\S 5       rS rS rS rS r	S r
S rS	 rS
rg)TestFuncWatchersi  c              #      #    [         R                  U5      n S v   [         R                  U5        g ! [         R                  U5        f = f7fr   )r	   add_func_watcherclear_func_watcher)r   funcr$   s      r   r   TestFuncWatchers.add_watcher  s9     ((.	.((-I((-rH  c                 *  ^ / mU4S jnU R                  U5         S nU R                  [        R                  US 4T5        [	        U5      nU R
                  R                  nXBl        U R                  [        R                  X$4T5        SnXRl        U R                  [        R                  X%4T5        Sn[        R                  X%5        U R                  [        R                  X%4T5        SS0nXbl        U R                  [        R                  X&4T5        SS0n[        R                  X&5        U R                  [        R                  X&4T5        / mAU R                  [        R                  US 4T5        S S S 5        g ! , (       d  f       g = f)Nc                  (   > TR                  U 5        g r   append)argseventss    r   r%   =TestFuncWatchers.test_func_events_dispatched.<locals>.watcher  s    MM$r   c                      g r   rh   rh   r   r   myfunc<TestFuncWatchers.test_func_events_dispatched.<locals>.myfunc  s    r   ){   )  r   r  r  )r   r   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   r  ,TestFuncWatchers.test_func_events_dispatched  sS   	  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                 H  ^^ / mU4S jn/ mU4S jnU R                  U5         U R                  U5         S n[        R                  US 4nU R                  UT5        U R                  UT5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nc                  (   > TR                  U 5        g r   r|  )r~  events0s    r   first_watcher>TestFuncWatchers.test_multiple_watchers.<locals>.first_watcher      NN4 r   c                  (   > TR                  U 5        g r   r|  )r~  events1s    r   second_watcher?TestFuncWatchers.test_multiple_watchers.<locals>.second_watcher  r  r   c                      g r   rh   rh   r   r   r  7TestFuncWatchers.test_multiple_watchers.<locals>.myfunc      r   )r   r	   r  r   )r   r  r  r  eventr  r  s        @@r   test_multiple_watchers'TestFuncWatchers.test_multiple_watchers	  s    	! 	! m,!!.1 #66EeW-eW- 2 -,11 -,s"   B;B1B
B	B
B!c           	        ^  " S S[         5      mU4S jnU R                  U5         [        5        nS nU R                  UR                  R
                  S[        U5      SS  35        U R                  UR                  R                  5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nc                       \ rS rSrSrg);TestFuncWatchers.test_watcher_raises_error.<locals>.MyErrori  rh   Nri   rh   r   r   MyErrorr        r   r  c                     > T" S5      eNztesting 123rh   r~  r  s    r   r%   ;TestFuncWatchers.test_watcher_raises_error.<locals>.watcher      -((r   c                      g r   rh   rh   r   r   r  :TestFuncWatchers.test_watcher_raises_error.<locals>.myfunc$  r  r   zBException ignored in PyFunction_EVENT_CREATE watcher callback for r   r   )		Exceptionr   r   r+   r   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#   B3AB"B3"
B0	,B33
Cc                 "  ^  " S S[         5      mU4S jnS nU R                  U5         [        5        nAU R                  UR                  R
                  T5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nc                       \ rS rSrSrg)CTestFuncWatchers.test_dealloc_watcher_raises_error.<locals>.MyErrori/  rh   Nri   rh   r   r   r  r  /  r  r   r  c                     > T" S5      er  rh   r  s    r   r%   CTestFuncWatchers.test_dealloc_watcher_raises_error.<locals>.watcher2  r  r   c                      g r   rh   rh   r   r   r  BTestFuncWatchers.test_dealloc_watcher_raises_error.<locals>.myfunc5  s    r   )r  r   r   assertIsInstancer   r   )r   r%   r  r   r  s       @r   !test_dealloc_watcher_raises_error2TestFuncWatchers.test_dealloc_watcher_raises_error.  sk    	i 		)	 g&+-%%bmm&=&=wG . '&-- '&s"   B (A/B /
A=	9B  
Bc                    U R                  [        S5         [        R                  S5        S S S 5        U R                  [        S5         [        R                  S5        S S S 5        g ! , (       d  f       NC= f! , (       d  f       g = f)Nzinvalid func watcher ID -1r   zinvalid func watcher ID 8r   r   r   r	   rw  r   s    r   r   3TestFuncWatchers.test_clear_out_of_range_watcher_id>  rh  ri  c                     U R                  [        S5         [        R                  S5        S S S 5        g ! , (       d  f       g = f)Nzno func watcher set for ID 1r   r  r   s    r   r   1TestFuncWatchers.test_clear_unassigned_watcher_idD  rl  rm  c                     U R                  [        S5         [        R                  5         S S S 5        g ! , (       d  f       g = f)Nzno more func watcher IDs)r   r<  r	   allocate_too_many_func_watchersr   s    r   rp  0TestFuncWatchers.test_allocate_too_many_watchersH  s,    ##L2MN557 ONNrr  rh   N)rj   rk   rl   rm   r   r   r  r  r  r  r   r   rp  rn   rh   r   r   rt  rt    s:    . ."UH.$8&H ,,8r   rt  __main__)unittest
contextlibr   r   test.supportr   r   r   r   import_moduler	   TestCaser   r   rA  rt  rj   mainrh   r   r   <module>r     s     0* * ''4	|"x(( |"~p8x(( p8fZ8X.. Z8zn8x(( n8b zMMO r   