
    3hhM                     .   S SK r S SKrS SKrS SKJr  S SKrS SKrS SKJr  \R                  " S5      r
S SKJr  S SKJr  SSKJrJr   " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r\S:X  a  \R.                  " 5         gg)    N)dedent)import_helper_interpchannels)interpreterschannels   )_run_outputTestBasec                       \ rS rSrS rSrg)LowLevelTests   c                 8    [         R                  " [        5        g N)	importlibreloadr   )selfs    M/opt/python-3.13.8/usr/lib/python3.13/test/test_interpreters/test_channels.pytest_highlevel_reloaded%LowLevelTests.test_highlevel_reloaded   s    "     N)__name__
__module____qualname____firstlineno__r   __static_attributes__r   r   r   r   r      s    #r   r   c                   ,    \ rS rSrS rS rS rS rSrg)TestChannels"   c                     [         R                  " 5       u  pU R                  U[         R                  5        U R                  U[         R                  5        g r   )r   createassertIsInstanceRecvChannelSendChannel)r   rss      r   test_createTestChannels.test_create$   s<     a!5!56a!5!56r   c                 0   U R                  [        R                  " 5       / 5        [        5       n[	        S5       H)  n[        R
                  " 5       nUR                  U5        M+     [        [        R                  " 5       5      nU R                  XA5        g )N   )assertEqualr   list_allsetranger"   add)r   created_chafters        r   test_list_allTestChannels.test_list_all)   sj    **,b1%qA"BKKO  H%%'((r   c                    [         R                  " 5       n[        R                  " 5       u  p#U R                  [         R                  " U5      5        U R                  [         R                  " U5      5        UR                  U5        UR                  U5        UR                  5       nUR                  5       nUR                  X#S9  UR                  U5        UR                  U5        UR                  [        S5      5        UR                  5       nUR                  5       nU R                  XB5        U R                  XS5        U R                  Xb5        U R                  Xs5        g )N)rchschz
            rch2 = rch.recv()
            sch2 = rch.recv()
            assert rch2 == rch
            assert sch2 == sch

            sch.send_nowait(rch2)
            sch.send_nowait(sch2)
            )r   r"   r   
assertTrueis_shareablesend_nowaitrecvprepare_mainexecr   r,   )r   interpr8   r9   rch2sch2rch3sch3s           r   test_shareableTestChannels.test_shareable2   s   $$&??$%%c*	,%%c*	, 	xxzxxz-F   	 xxzxxz####r   c                 :   [         R                  " 5       u  pUR                  nUR                  nUR                  5         UR                  nUR                  nU R	                  U5        U R	                  U5        U R                  U5        U R                  U5        g r   )r   r"   	is_closedcloseassertFalser:   )r   r8   r9   rbeforesbeforeraftersafters          r   test_is_closedTestChannels.test_is_closedT   sq    ??$----		!!r   r   N)	r   r   r   r   r(   r5   rE   rO   r   r   r   r   r   r   "   s    7
) $D r   r   c                   2    \ rS rSrS rS rS rS rS rSr	g)	TestRecvChannelAttrsb   c                     [         R                  " 5       u  pU R                  UR                  [        R
                  5        g r   r   r"   r#   id	_channels	ChannelID)r   r8   r2   s      r   test_id_type!TestRecvChannelAttrs.test_id_typed   s*    "cffi&9&9:r   c                     [         R                  " S5      nU R                  UR                  S5        U R	                  [
        5         [         R                  " S5        S S S 5        g ! , (       d  f       g = fNr	   1)r   r$   r,   rV   assertRaises	TypeErrorr   r8   s     r   test_custom_id#TestRecvChannelAttrs.test_custom_idh   N    ""1%#y)  % *))   A((
A6c                     [         R                  " S5      nU R                  [        5         SUl        S S S 5        g ! , (       d  f       g = fNr	      )r   r$   r^   AttributeErrorrV   r`   s     r   test_id_readonly%TestRecvChannelAttrs.test_id_readonlyo   3    ""1%~.CF /..	   =
Ac                     [         R                  " 5       u  p[         R                  " 5       u  p2U R                  X5        U R                  X5        g r   r   r"   r,   assertNotEqual)r   ch1r2   ch2s       r   test_equality"TestRecvChannelAttrs.test_equalityt   s:    """C%r   c                     [         R                  " 5       u  p[        R                  " U5      n[        R                  " U5      nU R                  XA5        g r   r   r"   pickledumpsloadsr,   )r   r3   r2   data	unpickleds        r   test_pickle TestRecvChannelAttrs.test_picklez   s:    !||BLL&	'r   r   N
r   r   r   r   rY   ra   ri   rr   r{   r   r   r   r   rR   rR   b       ;&
&(r   rR   c                   2    \ rS rSrS rS rS rS rS rSr	g)	TestSendChannelAttrs   c                     [         R                  " 5       u  pU R                  UR                  [        R
                  5        g r   rU   )r   r2   r9   s      r   rY   !TestSendChannelAttrs.test_id_type   s*    "cffi&9&9:r   c                     [         R                  " S5      nU R                  UR                  S5        U R	                  [
        5         [         R                  " S5        S S S 5        g ! , (       d  f       g = fr\   )r   r%   r,   rV   r^   r_   r   r9   s     r   ra   #TestSendChannelAttrs.test_custom_id   rc   rd   c                     [         R                  " S5      nU R                  [        5         SUl        S S S 5        g ! , (       d  f       g = frf   )r   r%   r^   rh   rV   r   s     r   ri   %TestSendChannelAttrs.test_id_readonly   rk   rl   c                     [         R                  " 5       u  p[         R                  " 5       u  pU R                  X"5        U R                  X#5        g r   rn   )r   r2   rp   rq   s       r   rr   "TestSendChannelAttrs.test_equality   s:    """C%r   c                     [         R                  " 5       u  p[        R                  " U5      n[        R                  " U5      nU R                  XB5        g r   ru   )r   r2   r3   ry   rz   s        r   r{    TestSendChannelAttrs.test_pickle   s:    !||BLL&	'r   r   Nr}   r   r   r   r   r      r~   r   r   c                       \ rS rSrS rS r\R                  " S5      S 5       rS r	S r
S rS	 r\R                  " S5      S
 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g)TestSendRecv   c                     [         R                  " 5       u  pSnUR                  U5        UR                  5       nU R	                  XC5        U R                  XC5        g N   spam)r   r"   r<   r=   r,   assertIsNotr   r&   r'   origobjs        r   test_send_recv_main TestSendRecv.test_send_recv_main   sH     	dffh##r   c                 b    [         R                  " 5       nUR                  [        S5      5        g )Na;  
            from test.support.interpreters import channels
            r, s = channels.create()
            orig = b'spam'
            s.send_nowait(orig)
            obj = r.recv()
            assert obj == orig, 'expected: obj == orig'
            assert obj is not orig, 'expected: obj is not orig'
            r   r"   r?   r   r   r@   s     r   test_send_recv_same_interpreter,TestSendRecv.test_send_recv_same_interpreter   s(    $$&F   	r   zbroken (see BPO-...)c           	         [         R                  " 5       u  p[         R                  " 5       u  p4SnUR                  U5        [        [        R                  " 5       [        S[        U5       S35      [        XS9S9nUR                  5       nU R                  US5        U R                  [        U5      [        U5      5        g )Nr   z
                obj1 = r.recv()
                assert obj1 == b'spam', 'expected: obj1 == orig1'
                # When going to another interpreter we get a copy.
                assert id(obj1) != , 'expected: obj1 is not orig1'
                orig2 = b'eggs'
                print(id(orig2))
                s.send_nowait(orig2)
                r&   r'   r      eggs)r   r"   r<   r
   r   r   rV   dictr=   r,   ro   intr   r1s1r2s2orig1outobj2s           r   %test_send_recv_different_interpreters2TestSendRecv.test_send_recv_different_interpreters   s    ""
u! $ %'uI; /	  B% wwyw'BtHc#h/r   c                 8  ^^ [         R                  " 5       u  mmUU4S jn[        R                  " US9nUR	                  5         SnTR                  U5        TR                  5       nUR                  5         U R                  XC5        U R                  XC5        g )Nc                     >   TR                  5       n  TR                  U 5        g ! [        R                   a    [        R                  " S5         Of = fMV  Ng?)r=   r   ChannelEmptyErrortimesleepsend)r   r&   r'   s    r   f8TestSendRecv.test_send_recv_different_threads.<locals>.f   sM    $&&(C FF3K  11 $JJsO$	 s   ' *AAtargetr   )
r   r"   	threadingThreadstartr   r=   joinr,   r   )r   r   tr   r   r&   r'   s        @@r    test_send_recv_different_threads-TestSendRecv.test_send_recv_different_threads   ss     1	 A&			tffh	##r   c                     [         R                  " 5       u  pSnUR                  U5        UR                  5       nU R	                  XC5        U R                  XC5        g r   )r   r"   r<   recv_nowaitr,   r   r   s        r   test_send_recv_nowait_main'TestSendRecv.test_send_recv_nowait_main   sH     	dmmo##r   c                 v    [         R                  " 5       u  pUR                  S 5      nU R                  U5        g r   )r   r"   r   assertIsNone)r   r&   r2   r   s       r   'test_send_recv_nowait_main_with_default4TestSendRecv.test_send_recv_nowait_main_with_default   s,     mmD!#r   c                 b    [         R                  " 5       nUR                  [        S5      5        g )Na  
            from test.support.interpreters import channels
            r, s = channels.create()
            orig = b'spam'
            s.send_nowait(orig)
            obj = r.recv_nowait()
            assert obj == orig, 'expected: obj == orig'
            # When going back to the same interpreter we get the same object.
            assert obj is not orig, 'expected: obj is not orig'
            r   r   s     r   &test_send_recv_nowait_same_interpreter3TestSendRecv.test_send_recv_nowait_same_interpreter   s(    $$&F 	 	 		r   c           	         [         R                  " 5       u  p[         R                  " 5       u  p4SnUR                  U5        [        [        R                  " 5       [        S[        U5       S35      [        XS9S9nUR                  5       nU R                  US5        U R                  [        U5      [        U5      5        g )Nr   z
                obj1 = r.recv_nowait()
                assert obj1 == b'spam', 'expected: obj1 == orig1'
                # When going to another interpreter we get a copy.
                assert id(obj1) != r   r   r   r   )r   r"   r<   r
   r   r   rV   r   r   r,   ro   r   r   s           r   ,test_send_recv_nowait_different_interpreters9TestSendRecv.test_send_recv_nowait_different_interpreters  s    ""
u! $ %'uI; /	  B% ~~w'BtHc#h/r   c                     [         R                  " 5       u  pU R                  [        5         UR	                  SS9  S S S 5        g ! , (       d  f       g = f)Nr	   )timeout)r   r"   r^   TimeoutErrorr=   )r   r&   r2   s      r   test_recv_timeoutTestSendRecv.test_recv_timeout  s8     |,FF1F -,,s   A
Ac                     [         R                  " S5      nU R                  [         R                  5         UR	                  5         S S S 5        g ! , (       d  f       g = fN@B )r   r$   r^   ChannelNotFoundErrorr=   r   r3   s     r    test_recv_channel_does_not_exist-TestSendRecv.test_recv_channel_does_not_exist  s;    !!),x<<=GGI >==   A
Ac                     [         R                  " S5      nU R                  [         R                  5         UR	                  S5        S S S 5        g ! , (       d  f       g = fNr   r   )r   r%   r^   r   r   r   s     r    test_send_channel_does_not_exist-TestSendRecv.test_send_channel_does_not_exist#  s>    !!),x<<=GGG >==   A
Ac                     [         R                  " S5      nU R                  [         R                  5         UR	                  5         S S S 5        g ! , (       d  f       g = fr   )r   r$   r^   r   r   r   s     r   'test_recv_nowait_channel_does_not_exist4TestSendRecv.test_recv_nowait_channel_does_not_exist(  s<    !!),x<<=NN >==r   c                     [         R                  " S5      nU R                  [         R                  5         UR	                  S5        S S S 5        g ! , (       d  f       g = fr   )r   r%   r^   r   r<   r   s     r   'test_send_nowait_channel_does_not_exist4TestSendRecv.test_send_nowait_channel_does_not_exist-  s>    !!),x<<=NN7# >==r   c                     [         R                  " 5       u  pU R                  [         R                  5         UR	                  5         S S S 5        g ! , (       d  f       g = fr   )r   r"   r^   r   r   )r   r3   r2   s      r   test_recv_nowait_empty#TestSendRecv.test_recv_nowait_empty2  s:    !x99:NN ;::s   A
Ac                 l   [        5       n[        R                  " 5       u  p#UR                  U5      nUR	                  S 5        UR	                  S5        UR	                  S5        UR	                  S5        UR                  U5      nUR                  U5      nUR                  5       nUR                  U5      nUR                  U5      n	U R                  XA5        U R                  US 5        U R                  US5        U R                  US5        U R                  US5        U R                  X5        g )Nr	   r   r   )objectr   r"   r   r<   assertIsr,   )
r   defaultr8   r9   obj1r   obj3obj4obj5obj6s
             r   test_recv_nowait_default%TestSendRecv.test_recv_nowait_default7  s    (??$w'  w'w' w'w'd$dD!q!w'w'd$r   c                   ^^ [        S5      nS m[        R                  " 5       u  mnUU4S jn[        R                  " US9nUR                  5         UR                  U5        UR                  5         U R                  TU5        U R                  T[        5        U R                  TU5        SUSS& U R                  TU5        STSS& U R                  TU5        g )N   spamspamspamc                     >   TR                  5       m g ! [        R                   a    [        R                  " S5         Of = fMD  r   )r=   r   r   r   r   )r   r8   s   r   r   (TestSendRecv.test_send_buffer.<locals>.fQ  s>    $((*C11 $JJsO$	 s    *AAr   r            ham.)	bytearrayr   r"   r   r   r   send_bufferr   r   r#   
memoryviewr,   )r   bufr9   r   r   r   r8   s        @@r   test_send_bufferTestSendRecv.test_send_bufferL  s    (??$S	$ A&			c"c:.c"Aac"Aac"r   c                 R   [        S5      n[        R                  " 5       u  p#UR                  U5        UR	                  5       nU R                  XA5        U R                  U[        5        U R                  XA5        SUSS& U R                  XA5        SUSS& U R                  XA5        g )Nr   r   r   r   r   )	r   r   r"   send_buffer_nowaitr=   r   r#   r   r,   )r   r   r8   r9   r   s        r   test_send_buffer_nowait$TestSendRecv.test_send_buffer_nowaith  s    (??$s#hhj"c:."Aa"Aa"r   c                   ^  SU 4S jjnT R                  S5         [        R                  " 5       u  p#U" X#5      nAT R                  [        R                  UR                  5      S5        UR                  5       nT R                  [        R                  UR                  5      S5        T R                  U[        R                  5        T R                  [        R                  UR                  5      S5        T R                  [        R                  5         UR                  5         S S S 5        S S S 5        T R                  S5         [        R                  " 5       u  p#U" X#[        R                  5      nAT R                  [        R                  UR                  5      S5        UR                  5       nT R                  U[        R                  5        T R                  [        R                  UR                  5      S5        T R                  [        R                  5         UR                  5         S S S 5        S S S 5        T R                  S5         [        R                  " 5       u  p#U" X#[        R                  5      nAT R                  [        R                  UR                  5      S5        T R                  [        R                  5         UR                  5         S S S 5        T R                  [        R                  UR                  5      S5        T R                  [        R                  5         UR                  5         S S S 5        S S S 5        T R                  S5         [        R                  " 5       u  p#U" X#[        R                  5      nAT R                  [        R                  UR                  5      S5        T R                  [        R                  5         UR                  5         S S S 5        UR!                  S[        R                  S	9  T R                  [        R                  UR                  5      S5        U" X#[        R                  S5      nT R                  [        R                  UR                  5      S
5        UR!                  S[        R                  S	9  T R                  [        R                  UR                  5      S5        AT R                  [        R                  UR                  5      S5        UR                  5       nUR                  5       nT R                  US5        T R                  US5        T R                  [        R                  UR                  5      S5        T R                  [        R                  5         UR                  5         S S S 5        S S S 5        g ! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN3= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GNR= f! , (       d  f       N= f! , (       d  f       g = f)Nr   c                 \  > U(       d  SnOVU[         R                  L a  SnO@U[         R                  L a  SnO*U[         R                  L a  SnO[	        [        U5      5      e[        R                  " 5       n[        U[        SUR                   SU SU S35      5        TR                  [        R                  U R                  5      US	-   5        US
:X  aT  U R                  5       nTR                  US5        TR                  [        R                  U R                  5      US-   5        U$ )N z, unbound=channels.UNBOUNDz , unbound=channels.UNBOUND_ERRORz!, unbound=channels.UNBOUND_REMOVEzk
                from test.support.interpreters import channels
                sch = channels.SendChannel(zd)
                obj1 = b'spam'
                obj2 = b'eggs'
                sch.send_nowait(obj1z&)
                sch.send_nowait(obj2z)
                rg   r   r   r	   )r   UNBOUNDUNBOUND_ERRORUNBOUND_REMOVENotImplementedErrorreprr   r"   r
   r   rV   r,   rW   	get_countr=   )r8   r9   unboundpresize	extraargsr@   r   r   s          r   commonBTestSendRecv.test_send_cleared_with_subinterpreter.<locals>.commonx  s   	H,,,8	H222>	H333?	)$w-88!((*F ,,,/FF8 4% &/K 0%%.K 0( !  ##CFF+!
 !|xxz  w/  ''/aK
 Mr   r   r	   r  r	  r
  s   ham)r  r+   *   r   rg   )Nr   )subTestr   r"   r,   rW   r  rV   r=   r   r  r^   r   r   r	  ItemInterpreterDestroyedr
  r<   )r   r  r8   r9   r@   r   r   s   `      r   %test_send_cleared_with_subinterpreter2TestSendRecv.test_send_cleared_with_subinterpreterw  sX   "	H \\)$(HCC%FY008!<88:DY008!<MM$ 0 01Y008!<""8#=#=>! ? % \\)$(HCCh&6&67FY008!<88:DMM$ 0 01Y008!<""8#=#=>! ? % \\/*(HCCh&<&<=FY008!<""8#D#DE
 F Y008!<""8#=#=>! ? + \\*+(HCCh&=&=>FY008!<""8#=#=>! ? OOFH,C,CODY008!<Ch&=&=qAFY008!<OOB(?(?O@Y008!<Y008!<88:D88:DT6*T2&Y008!<""8#=#=>! ?- ,+7 ?> %$( ?> %$" FE ?> +*& ?>  ?>- ,+s   C=WW)W
CX'W08XA>X8X(AX8>X&X80A>Y-.Y
?F+Y-*Y;Y-
W	W
W-0
W?	:X
X
X#	X8&
X5	0X88
Y

Y	Y-
Y*	&Y--
Y;c                 *   [         R                  " 5       u  p[        R                  " 5       nUR                  S 5        UR	                  5         U R                  [        R                  UR                  5      S5        [        U[        SUR                   S35      5        U R                  [        R                  UR                  5      S5        AU R                  [        R                  UR                  5      S5        UR	                  5       nU R                  U[         R                  5        U R                  [        R                  UR                  5      S5        U R                  [         R                  5         UR	                  5         S S S 5        U R                  [        R                  UR                  5      S5        UR	                  5       nU R                  U[         R                  5        U R                  [        R                  UR                  5      S5        UR	                  5       nU R                  U[         R                  5        U R                  [        R                  UR                  5      S5        g ! , (       d  f       N= f)	Nr   zc
            from test.support.interpreters import channels
            sch = channels.SendChannel(a  )
            sch.send_nowait(1, unbound=channels.UNBOUND)
            sch.send_nowait(2, unbound=channels.UNBOUND_ERROR)
            sch.send_nowait(3)
            sch.send_nowait(4, unbound=channels.UNBOUND_REMOVE)
            sch.send_nowait(5, unbound=channels.UNBOUND)
               r   r+   rg   r	   )r   r"   r   r<   r=   r,   rW   r  rV   r
   r   r   r  r^   r  )r   r8   r9   r@   r   r   r   s          r   +test_send_cleared_with_subinterpreter_mixed8TestSendRecv.test_send_cleared_with_subinterpreter_mixed  s   ??$$$&
 	
,,SVV4a8FF (((+x 0$  	 	,,SVV4a8,,SVV4a8xxzdH,,-,,SVV4a8x@@AHHJ B,,SVV4a8xxzdH,,-,,SVV4a8xxzdH,,-,,SVV4a8 BAs   =J
Jc           
         [         R                  " 5       u  p[        R                  " 5       n[        R                  " 5       nUR                  S5        [	        U[        SUR                   SUR                   S35      5        [	        U[        SUR                   SUR                   S35      5        U R                  [        R                  UR                  5      S5        UR                  S5        [	        U[        S5      5        [	        U[        S	5      5        [	        U[        S
5      5        U R                  [        R                  UR                  5      S5        UR                  5       nU R                  US5        U R                  [        R                  UR                  5      S5        UR                  5       nU R                  US5        U R                  [        R                  UR                  5      S5        AU R                  [        R                  UR                  5      S5        UR                  5       nU R                  U[         R                  5        U R                  [        R                  UR                  5      S5        UR                  5       nU R                  US5        U R                  [        R                  UR                  5      S5        AU R                  [        R                  UR                  5      S5        U R                  [         R                  5         UR                  5         S S S 5        U R                  [        R                  UR                  5      S5        UR                  5       n	U R                  U	[         R                  5        U R                  [        R                  UR                  5      S5        UR                  5       n
U R                  U
[         R                  5        U R                  [        R                  UR                  5      S5        g ! , (       d  f       N= f)Nr	   zc
            from test.support.interpreters import channels
            rch = channels.RecvChannel(z))
            sch = channels.SendChannel(z)
            obj1 = rch.recv()
            sch.send_nowait(2, unbound=channels.UNBOUND)
            sch.send_nowait(obj1, unbound=channels.UNBOUND_REMOVE)
            zJ)
            obj2 = rch.recv()
            obj1 = rch.recv()
            r   r+   z
            sch.send_nowait(4, unbound=channels.UNBOUND)
            # interp closed here
            sch.send_nowait(5, unbound=channels.UNBOUND_REMOVE)
            sch.send_nowait(6, unbound=channels.UNBOUND)
            a+  
            sch.send_nowait(7, unbound=channels.UNBOUND_ERROR)
            # interp closed here
            sch.send_nowait(obj1, unbound=channels.UNBOUND_ERROR)
            sch.send_nowait(obj2, unbound=channels.UNBOUND_REMOVE)
            sch.send_nowait(8, unbound=channels.UNBOUND)
            z
            sch.send_nowait(9, unbound=channels.UNBOUND_REMOVE)
            sch.send_nowait(10, unbound=channels.UNBOUND)
            
   	   r   r      r     rg   )r   r"   r   r<   r
   r   rV   r,   rW   r  r=   r   r  r^   r  )r   r8   r9   interp1interp2r   r   r   obj7obj8obj10s              r   .test_send_cleared_with_subinterpreter_multiple;TestSendRecv.test_send_cleared_with_subinterpreter_multiple  s<   ??$%%'%%'GV )((+x 0((+x 0%  	 	GV )((+x 0((+x 0%  	 	,,SVV4a8GV %  	 	GV %  	 	GV %  	 	,,SVV4b9xxzq!,,SVV4a8xxzq!,,SVV4a8,,SVV4a8 xxzdH,,-,,SVV4a8xxzq!,,SVV4a8,,SVV4a8 x@@AHHJ B,,SVV4a8 xxzdH,,-,,SVV4a8 
eX--.,,SVV4a8 BAs   2P99
Qr   N)r   r   r   r   r   r   unittestskipr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r&  r   r   r   r   r   r      s    $
 ]])*0 +0.$,$ ]])*0 +0.



$

%*#8#`"D'9RQ9r   r   __main__)r   rv   r   textwrapr   r(  r   test.supportr   import_modulerW   r   test.support.interpretersr   utilsr
   r   r   r   rR   r   r   r   mainr   r   r   <module>r1     s          &''(9:	 % . (#H #$= 8 = @(8 (>(8 (>s98 s9l zMMO r   