
    daf                     >   d dl mZ d dlZd dlZd dlmZ d dlZd dlZd dlZd dl	m
Z
 d dlmZmZmZ  e
j                  d      Zd Zi fdZ G d	 d
 ed
d            Zej(                  d        Z G d d edd            Z G d d edd            ZdddZd Zd Z G d dej6                        Z G d de      Z G d de      Z G d de      Z G d  d! ed!d"            Z  ejB                  d#       G d$ d%e             Z"e#d&k(  r ejH                          yy)'    )
namedtupleN)dedent)import_helper)interpreters_run_outputclean_up_interpreters_xxinterpchannelsc                     t        | ||       y N)_run_interp)idsourceshareds      6/root/Python-3.12.4/Lib/test/test__xxinterpchannels.py
run_interpr   "   s    FF#    c                     t        |      }t        j                         }|| k(  r*t        j                         |k7  rt        t        ||       y t        j                  | ||       y r   )r   r   get_mainget_currentRuntimeErrorexec
run_string)r   r   r   _mainnsmains        r   r   r   &   sS    F^F  "Drz##%-VWFF3r   c                   0     e Zd Zed        Zd fd	Z xZS )Interpreterc                 Z    t        ||       r|S t        |t              r | |      S t        r   )
isinstancestrNotImplementedError)clsraws     r   from_rawzInterpreter.from_raw4   s*    c3JS!s8O%%r   c                 x   t        j                         }||k(  r'|sd}n|dk7  rt        dj                  |            |}ng|E|sd}n|dk(  rt        d      t	        |t         j
                        s6t        j
                  |      }n |r|dk(  rd}|}nt        j                         }t        | !  | ||      }|S )Nr   z)name mismatch (expected "main", got "{}")interpz!name mismatch (unexpected "main"))	r   r   
ValueErrorformatr   InterpreterIDcreatesuper__new__)r!   namer   r   self	__class__s        r   r+   zInterpreter.__new__=   s    $$&: ?FFtLN NB^ !DEEb,"<"<=!//3DB$$&BwsD"-r   NN)__name__
__module____qualname__classmethodr#   r+   __classcell__r.   s   @r   r   r   2   s    & & r   r   zname idc               #   T   K   	 d  J d       # t         j                  $ r Y y w xY ww)Nzchannel not closed)channelsChannelClosedError r   r   expect_channel_closedr:   X   s4     + 	+**u && s   ( (%(%(c                   2     e Zd Zd fd	Zd Zd Zd Z xZS )ChannelActionc                 <    |sd}|sd}t         |   | |||      }|S )Nbothr   r*   r+   )r!   actionendr%   r-   r.   s        r   r+   zChannelAction.__new__d   s,    CFwsFC8r   c                 :   | j                   dk(  r#| j                  dvr[t        | j                        | j                   dv r#| j                  dvr*t        | j                        t        | j                         | j                  dvrt        | j                        y )Nuse)sameoppositesendrecvcloseforce-close)r>   rD   rE   rF   rG   )r   rD   otherextra)r@   rA   r&   r%   )r-   argskwargss      r   __init__zChannelAction.__init__l   s    ;;%xxCC **[[44xxKK **T[[));;@@T[[)) Ar   c                 l    | j                   dk(  r|S | j                   dk(  r	|dk(  rdS dS | j                   S )NrD   rE   rF   rG   rA   r-   rA   s     r   resolve_endzChannelAction.resolve_endx   s9    88vJXX# F]66688Or   c                     | j                   dk(  r|S | j                   dk(  r
|t        |S | j                   dk(  r
|t        |S | j                   dk(  r*|j                  dk(  r|S |r|j                  dk(  r|S t        y )NrD   rK   rL   r   )r%   r   r,   )r-   r%   rK   rL   s       r   resolve_interpzChannelAction.resolve_interp   s    ;;& M[[G#}""L[[G#}""L[[F"{{f$5::/"" #r   r/   )r0   r1   r2   r+   rO   rS   rU   r4   r5   s   @r   r<   r<   b   s    
*#r   r<   zaction end interpc                   >     e Zd Zd	dd fdZd Zd ZdddZ xZS )
ChannelStateFclosedc                *    t         |   | ||      }|S r   r?   )r!   pendingrY   r-   r.   s       r   r+   zChannelState.__new__   s    wsGV4r   c                 V     t        |       | j                  dz   | j                        S N   rX   typer[   rY   r-   s    r   incrzChannelState.incr   "    tDz$,,*4;;??r   c                 V     t        |       | j                  dz
  | j                        S r]   r_   ra   s    r   decrzChannelState.decr   rc   r   Tforcec                    | j                   r|r| j                  dk(  r| S  t        |       |rdd      S | j                  d      S )Nr   TrX   )rY   r[   r`   )r-   rg   s     r   rI   zChannelState.close   s?    ;;DLLA-tDzu!tDD$,,tDDr   )r   )r0   r1   r2   r+   rb   re   rI   r4   r5   s   @r   rW   rW      s,    % @@ " E Er   rW   zpending closedT
hideclosedc                    |j                   r|dk(  r|dk(  r|j                  rd}nd}nd}	 t        | |||      }|rd|S # t        j                  $ r |s|s |j                         }Y |S w xY w)NrC   rG   FT.)rY   r[   _run_actionr7   r8   rI   )cidr@   rA   staterj   
expectfailresults          r   
run_actionrq      s    ||U?sf}JJ
S&#u5 IM && * Ms   A   (A,+A,c                 R   |dk(  r|dk(  r&t         j                  | d       |j                         S |dk(  rR|j                  s!	 t         j	                  |        t        d      t         j	                  |        |j                         S t        |      |dk(  r1i }|dv rd||<   t        j                  | fi | |j                         S |d	k(  r5d
di}|dv rd||<   t        j                  | fi | |j                  d      S t        |      # t         j                  $ r |cY S w xY w)NrC   rF      spamrG   zexpected ChannelEmptyErrorrI   rG   rF   TrJ   rg   rf   )
r7   rF   rb   r[   rG   	ExceptionChannelEmptyErrorre   r&   rI   )rm   r@   rA   rn   rN   s        r   rl   rl      s'   &=MM#w'::<F]==BMM#& $$@AAc"zz|#S/!	7	""F3Ks%f%{{}	=	 T ""F3Ks%f%{{{&&  1  11 ! L!s   D D&%D&c                      t         j                         D ]  } 	 t         j                  |         y # t         j                  $ r Y 1w xY wr   )r7   list_alldestroyChannelNotFoundErrorrm   s    r   clean_up_channelsr|      sG      " 	S! ,, 		s   1AAc                       e Zd Zd Zy)TestBasec                 ,    t                t                y r   )r|   r   ra   s    r   tearDownzTestBase.tearDown   s    r   N)r0   r1   r2   r   r9   r   r   r~   r~      s     r   r~   c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)ChannelIDTestsc                     t         j                  dd      }| j                  t        |      d       | j                  |j                  d       y )N
   Trf   r>   )r7   _channel_idassertEqualintrA   r-   rm   s     r   test_default_kwargsz"ChannelIDTests.test_default_kwargs   s?    ""2T"2S2&&)r   c                    t         j                  ddd      }| j                  |j                  d       t         j                  dddd      }| j                  |j                  d       t         j                  ddd      }| j                  |j                  d       t         j                  dddd	      }| j                  |j                  d       t         j                  dddd      }| j                  |j                  d
       y )Nr   TrF   rg   rF   FrF   rG   rg   rG   rg   rG   )rG   rF   rg   r>   )r7   r   r   rA   r   s     r   test_with_kwargszChannelIDTests.test_with_kwargs   s    ""2D"=&)""2DuD"I&)""2D"=&)""2DuD"I&)""2Dt4"H&)r   c                      G d dt               }t        j                   |       d      }| j                  t	        |      d       y )Nc                       e Zd Zd Zy)*ChannelIDTests.test_coerce_id.<locals>.Intc                      yNr   r9   ra   s    r   	__index__z4ChannelIDTests.test_coerce_id.<locals>.Int.__index__  s    r   N)r0   r1   r2   r   r9   r   r   Intr     s    r   r   Trf   r   )r   r7   r   r   r   )r-   r   rm   s      r   test_coerce_idzChannelIDTests.test_coerce_id  s;    	# 	 ""35"5S2&r   c                    | j                  t        t        j                  t	                      | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t
        t        j                  d       | j                  t        t        j                  d       y )Ng      $@10s   10l            )assertRaises	TypeErrorr7   r   objectr&   OverflowErrorra   s    r   test_bad_idzChannelIDTests.test_bad_id  s    )X%9%968D)X%9%94@)X%9%94@)X%9%95A*h&:&:B?-)=)=uEr   c                     | j                  t              5  t        j                  ddd       d d d        y # 1 sw Y   y xY w)Nr   FrF   rG   )r   r&   r7   r   ra   s    r   test_bad_kwargszChannelIDTests.test_bad_kwargs  s:    z* 	=  %e <	= 	= 	=s	   8Ac                     t         j                         }| j                  t         j                        5  t         j	                  t        |      dz          d d d        y # 1 sw Y   y xY wNr^   )r7   r)   r   rz   r   r   r   s     r   test_does_not_existz"ChannelIDTests.test_does_not_exist  sM    oox<<= 	/  SA.	/ 	/ 	/s   "AA(c                 h    t         j                  dd      }| j                  t        |      d       y )Nr   Trf   r   )r7   r   r   r   r   s     r   test_strzChannelIDTests.test_str$  s+    ""2T"2S4(r   c                    t         j                  dd      }| j                  t        |      d       t         j                  ddd      }| j                  t        |      d       t         j                  ddd      }| j                  t        |      d       t         j                  dddd	      }| j                  t        |      d       y )
Nr   Trf   zChannelID(10)r   zChannelID(10, send=True)r   zChannelID(10, recv=True)r   )r7   r   r   reprr   s     r   	test_reprzChannelIDTests.test_repr(  s    ""2T"2cO4""2D"=c$>?""2D"=c$>?""2Dt4"HcO4r   c                    t         j                         }t         j                  t        |            }t         j                         }| j	                  ||k(         | j	                  ||k(         | j	                  |t        |      k(         | j	                  t        |      |k(         | j	                  |t        t        |            k(         | j	                  t        t        |            |k(         | j                  |t        t        |            dz   k(         | j                  |t        t        |            k(         | j                  |ddz  k(         | j                  |t        d      k(         | j                  |dk(         | j                  ||k(         | j                  ||k7         | j                  ||k7         | j	                  ||k7         y )N皙?     infspam)r7   r)   r   r   
assertTruefloatassertFalser   )r-   cid1cid2cid3s       r   test_equalityzChannelIDTests.test_equality5  sm    ##CI. %%D	)*D	T)*c$i 001c$i(D01s4y!1C!778SY/0D)u-.(&&&%r   c                    t         j                         }t         j                         }t         j                  ||       t         j                  |      }| j	                  ||       | j                  t        |      t        |             y r   )r7   r)   rF   rG   r   assertIsr`   )r-   chanobjgots       r   test_shareablezChannelIDTests.test_shareableK  s\     oodC mmD!c"d3ic+r   N)r0   r1   r2   r   r   r   r   r   r   r   r   r   r   r9   r   r   r   r      s5    ** 'F=/
)5&,,r   r   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z ej4                  d      d        Zd Zd Zd Zd Zd Z d Z!d Z"d  Z#d! Z$d" Z%d# Z&d$ Z'd% Z(d& Z)d' Z*d( Z+y))*ChannelTestsc                 l    t         j                         }| j                  |t         j                         y r   )r7   r)   assertIsInstance	ChannelIDr   s     r   test_create_cidzChannelTests.test_create_cidZ  s$    ooc8#5#56r   c                    t         j                         }t         j                         }t         j                         }t         j                         }t         j                         }| j                  |t	        |      dz          | j                  |t	        |      dz          | j                  t        |      t        |      z
  |||h       y r   )r7   rx   r)   r   r   set)r-   beforeid1id2id3afters         r   test_sequential_idsz ChannelTests.test_sequential_ids^  s    ""$oooooo!!#c#hl+c#hl+Uc&k1Cc?Cr   c                 H   t        j                         }t        |t        d            }t	        |j                               }t        j                         }t        |t        d            }t	        |j                               }| j                  |t	        |      dz          y )Nz{
            import _xxinterpchannels as _channels
            cid = _channels.create()
            print(cid)
            r^   )r   r)   r   r   r   stripr   )r-   r   outr   r   r   s         r   test_ids_globalzChannelTests.test_ids_globali  s    !!##v '   
 399;!!##v '   
 399;s4y1}-r   c                     t         j                         }t         j                  |d      }t         j                  |d      }| j                  |g        | j                  |g        y)z=Test listing interpreters for a channel with no associations.TrF   FN)r7   r)   list_interpretersr   )r-   rm   send_interpsrecv_interpss       r   #test_channel_list_interpreters_nonez0ChannelTests.test_channel_list_interpreters_none|  sZ     oo11#D1A11#E1Br*r*r   c                 (   t        j                         }t        j                         }t        j	                  |d       t        j                  |d      }t        j                  |d      }| j                  ||g       | j                  |g        t        j                         }t        |t        d| d             t        j                  |d      }t        j                  |d      }| j                  ||g       | j                  ||g       y)z(Test basic listing channel interpreters.rF   Tr   FT
            import _xxinterpchannels as _channels
            obj = _channels.recv()
            N)	r   r   r7   r)   rF   r   r   r   r   )r-   interp0rm   r   r   interp1s         r   $test_channel_list_interpreters_basicz1ChannelTests.test_channel_list_interpreters_basic  s    '')ooc6"11#D1A11#E1By1r*%%'GV )""% '%  	
  11#D1A11#E1By1y1r   c                 ^   t        j                         }t        j                         }t        j                         }t        j                         }t        j                         }t        j	                  |d       t        |t        d| d             t        |t        d| d             t        |t        d| d             t        j                  |d      }t        j                  |d      }| j                  t        |      ||h       | j                  t        |      ||h       y	)
z?Test listing interpreters for a channel with many associations.rF   N
            import _xxinterpchannels as _channels
            _channels.send(z, "send")
            r   r   Tr   FN)
r   r   r)   r7   rF   r   r   r   r   r   )r-   r   r   interp2interp3rm   r   r   s           r   'test_channel_list_interpreters_multiplez4ChannelTests.test_channel_list_interpreters_multiple  s'   '')%%'%%'%%'ooc6"GV )5 !%  	 	GV )""% '%  	 	GV )""% '%  	  11#D1A11#E1B\*Wg,>?\*Wg,>?r   c                 R   t        j                         }t        j                         }t        j                         }t        j	                  |d       t        |t        d| d             t        j                  |d      }t        j                  |d      }| j                  ||g       | j                  ||g       t        j                  |       t        j                  |d      }t        j                  |d      }| j                  ||g       | j                  |g        y)z?Test listing channel interpreters with a destroyed interpreter.rF   r   r   Tr   FN)
r   r   r)   r7   rF   r   r   r   r   ry   r-   r   r   rm   r   r   s         r   (test_channel_list_interpreters_destroyedz5ChannelTests.test_channel_list_interpreters_destroyed  s   '')%%'ooc6"GV )""% '%  	
  11#D1A11#E1By1y1W%11#D1A11#E1By1r*r   c                    t        j                         }t        j                         }t        j                         }t        j                         }t        j	                  |d       t        |t        d| d             t        j	                  |d       t        |t        d| d             t        j                  |d      }t        j                  |d      }| j                  t        |      d       | j                  t        |      d       t        j                  |d       t        j                  |d      }t        j                  |d      }| j                  t        |      d	       | j                  t        |      d       t        |t        d
| d             t        j                  |d      }t        j                  |d      }| j                  t        |      d	       | j                  ||g       y)z:Test listing channel interpreters with a released channel.datar   r   Tr   Fr^   r   r   Q
            import _xxinterpchannels as _channels
            _channels.release(N)r   r   r)   r7   rF   r   r   r   r   lenrelease)r-   r   r   r   rm   r   r   s          r   'test_channel_list_interpreters_releasedz4ChannelTests.test_channel_list_interpreters_released  s    '')%%'%%'ooc6"GV )""% '%  	 	c6"GV )""% '%  	
  11#D1A11#E1B\*A.\*A. 	4(11#D1A11#E1B\*A.\*A. 	GV )"e $%  	
  11#D1A11#E1B\*A.y1r   c                    t        j                         }t        j                         }t        j                         }t        j	                  |d       t        j                  |d      }t        j                  |d      }| j                  t        |      d       | j                  t        |      d       t        j                  |d       | j                  t        j                        5  t        j                  |d       ddd       | j                  t        j                        5  t        j                  |d       ddd       y# 1 sw Y   IxY w# 1 sw Y   yxY w)	z8Test listing channel interpreters with a closed channel.rF   Tr   Fr^   r   rf   N)r   r   r)   r7   rF   r   r   r   rI   r   r8   r   s         r   %test_channel_list_interpreters_closedz2ChannelTests.test_channel_list_interpreters_closed  s   '')%%'ooc6"  11#D1A11#E1B\*A.\*A. 	s$'x::; 	7&&s&6	7x::; 	8&&s&7	8 	8	7 	7	8 	8s   -E,EEE"c                    t        j                         }t        j                         }t        j                         }t        j	                  |d       t        j                  |d      }t        j                  |d      }| j                  t        |      d       | j                  t        |      d       t        j                  |d       | j                  t        j                        5  t        j                  |d       ddd       t        j                  |d      }| j                  t        |      d       t        |t        d| d	             y# 1 sw Y   UxY w)
zCTest listing channel interpreters with a channel's send end closed.rF   Tr   Fr^   r   NO
            import _xxinterpchannels as _channels
            _channels.close(, force=True)
            )r   r   r)   r7   rF   r   r   r   rI   r   r8   r   r   r   s         r   .test_channel_list_interpreters_closed_send_endz;ChannelTests.test_channel_list_interpreters_closed_send_end  s4   '')%%'ooc6"  11#D1A11#E1B\*A.\*A. 	s&x::; 	7&&s&6	7  11#E1B\*A. 	GV ) E "%  	 		7 	7s   -EE"c                     t         j                         }d}t         j                  ||       t         j                  |      }| j	                  ||       | j                  ||       y Nrs   )r7   r)   rF   rG   r   assertIsNot)r-   rm   origr   s       r   test_send_recv_mainz ChannelTests.test_send_recv_main2  sO    ooc4 mmC d#d#r   c                 V    t        j                         }t        |t        d            }y )Na  
            import _xxinterpchannels as _channels
            cid = _channels.create()
            orig = b'spam'
            _channels.send(cid, orig)
            obj = _channels.recv(cid)
            assert obj is not orig
            assert obj == orig
            )r   r)   r   r   )r-   r   r   s      r   test_send_recv_same_interpreterz,ChannelTests.test_send_recv_same_interpreter;  s(    !!##v '   r   c                     t         j                         }t        j                         }t        |t	        d| d            }t         j                  |      }| j                  |d       y )Nr   , b'spam')
            rs   )r7   r)   r   r   r   rG   r   )r-   rm   r   r   r   s        r   %test_send_recv_different_interpretersz2ChannelTests.test_send_recv_different_interpretersG  sc    oo!!##v +5 !'    mmC g&r   c                    t         j                         fd}t        j                  |      }|j	                          t         j                  d       |j                          t         j                        }| j                  |d       y )Nc                      	 	 t         j                        } 	 t         j                  |        y # t         j                  $ r t        j                  d       Y nw xY w])Nr   )r7   rG   rv   timesleeprF   )r   rm   s    r   fz8ChannelTests.test_send_recv_different_threads.<locals>.fU  sS    $"--,C MM#s#  11 $JJsO$	 s   1 (AAtargetrs   )	r7   r)   	threadingThreadstartrF   joinrG   r   )r-   r   tr   rm   s       @r    test_send_recv_different_threadsz-ChannelTests.test_send_recv_different_threadsR  sd    oo	$ A&		c7#	mmC g&r   c                 R   t         j                         t        j                         d fd}t        j                  |      }|j                          t         j                  d       |j                          t         j                        }| j                  |d       y )Nc            
      >    t        t        d  d  d            y )Nz
                import time
                import _xxinterpchannels as _channels
                while True:
                    try:
                        obj = _channels.recv(z)
                        break
                    except _channels.ChannelEmptyError:
                        time.sleep(0.1)
                assert(obj == b'spam')
                _channels.send(z, b'eggs')
                )r   r   )rm   r   r   s   r   r   zIChannelTests.test_send_recv_different_interpreters_and_threads.<locals>.fk  s8    c6 /.
 /2U 3 
 !$u %+ $ Cr   r   rs      eggs)
r7   r)   r   r   r  r  rF   r  rG   r   )r-   r   r  r   rm   r   r   s       @@@r   1test_send_recv_different_interpreters_and_threadsz>ChannelTests.test_send_recv_different_interpreters_and_threadsf  sw    oo!!#	 A&		c7#	mmC g&r   c                     | j                  t        j                        5  t        j                  dd       d d d        y # 1 sw Y   y xY w)Nr   rs   )r   r7   rz   rF   ra   s    r   test_send_not_foundz ChannelTests.test_send_not_found  s9    x<<= 	'MM"g&	' 	' 	's   A  A	c                     | j                  t        j                        5  t        j                  d       d d d        y # 1 sw Y   y xY wr   )r   r7   rz   rG   ra   s    r   test_recv_not_foundz ChannelTests.test_recv_not_found  s7    x<<= 	MM"	 	 	s	   ?Ac                     t         j                         }| j                  t         j                        5  t         j	                  |       d d d        y # 1 sw Y   y xY wr   )r7   r)   r   rv   rG   r   s     r   test_recv_emptyzChannelTests.test_recv_empty  sC    oox99: 	MM#	 	 	s   AAc                    t               }t        j                         }t        j                  ||      }t        j	                  |d        t        j	                  |d       t        j	                  |d       t        j	                  |d       t        j                  ||      }t        j                  ||      }t        j                  |      }t        j                  ||      }t        j                  ||      }| j                  ||       | j                  |d        | j                  |d       | j                  |d       | j                  |d       | j                  ||       y )Nr^   rs   r  )r   r7   r)   rG   rF   r   r   )	r-   defaultrm   obj1obj2obj3obj4obj5obj6s	            r   test_recv_defaultzChannelTests.test_recv_default  s   (oo}}S'*c4 c1c7#c7#}}S'*}}S'*}}S!}}S'*}}S'*dG$dD!q!w'w'dG$r   c           	         | j                  d      5  t        j                         }t        j                         }t        j                  |t        d| d             t        j                  |       | j                  t        d| d      5  t        j                  |       d d d        ~d d d        | j                  d      5  t        j                         }t        j                         }t        j                  |t        d| d             t        j                  |d       t        j                  |       t        j                  |       | j                  t        d| d      5  t        j                  |       d d d        ~d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   +xY w# 1 sw Y   y xY w)	NrY   zV
                import _xxinterpchannels as _channels
                _channels.send(, b'spam')
                zchannel z
 is closedz
still openr  z	 is empty)subTestr7   r)   r   r   r   ry   assertRaisesRegexr   rG   rF   )r-   r   r%   r   s       r   "test_recv_sending_interp_destroyedz/ChannelTests.test_recv_sending_interp_destroyed  s   \\(# 	??$D!((*F##FF 8  $v &4 -    (''*24&
(CE $d#$ 	 \\,' 	??$D!((*F##FF 8  $v &4 -  MM$(  (MM$''*24&	(BD $d#$ 	 		$ $	 	0$ $	 	sI   A;FF#	FB&F7+F+	F7F	FF(+F4	0F77G c                 P   t         j                         }g d}|D ]}  }| j                  |      5  t         j                  ||       t         j	                  |      }| j                  ||       | j                  t        |      t        |             d d d         y # 1 sw Y   xY w)N)Nr   rs   *   )r7   r)   r  rF   rG   r   r   r`   )r-   rm   objectsr   r   s        r   test_allowed_typeszChannelTests.test_allowed_types  s    oo
  	4Cc" 4c3'mmC(  c*d3ic34 4	44 4s   A"BB%	c                 6   t         j                         }t        j                         }t        |t	        d      t        |j                              }t         j                  |      }| j                  |d       | j                  |j                         d       y )Nz
            import _xxinterpchannels as _channels
            print(cid.end)
            _channels.send(cid, b'spam')
            r{   rs   rF   )
r7   r)   r   r   r   dictrF   rG   r   r   r-   rm   r%   r   r   s        r   test_run_string_arg_unresolvedz+ChannelTests.test_run_string_arg_unresolved  sx    oo$$&&& * #
 SXX  mmC g&f-r   z(disabled until high-level channels existc                 d   t         j                         }t         j                  |d      }t        j                         }t	        |t        d      t        |j                              }t         j                  |      }| j                  |d       | j                  |j                         d       y )NT)_resolvez
            import _xxinterpchannels as _channels
            print(chan.id.end)
            _channels.send(chan.id, b'spam')
            )r   rs   rF   )r7   r)   r   r   r   r   r#  rF   rG   r   r   r$  s        r   test_run_string_arg_resolvedz)ChannelTests.test_run_string_arg_resolved  s    oo""3"6$$&&& * #
 chh! mmC g&f-r   c                    t         j                         }t         j                  |d       t         j                  |       t         j	                  |       | j                  t         j                        5  t         j                  |d       d d d        | j                  t         j                        5  t         j                  |       d d d        y # 1 sw Y   GxY w# 1 sw Y   y xY wNrs   r  r7   r)   rF   rG   rI   r   r8   r   s     r   test_close_single_userz#ChannelTests.test_close_single_user  s    ooc7#csx::; 	(MM#w'	(x::; 	MM#	 		( 	(	 	   4C2CCC&c           	      "   t         j                         }t        j                         }t        j                         }t        j                  |t	        d| d             t        j                  |t	        d| d             t         j                  |       | j                  t        j                        5 }t        j                  |t	        d| d             d d d        | j                  dt        j                               | j                  t        j                        5 }t        j                  |t	        d| d             d d d        | j                  dt        |j                               y # 1 sw Y   xY w# 1 sw Y   ;xY w)Nr   r   zN
            import _xxinterpchannels as _channels
            _channels.recv(r   z 
                _channels.send(r  r8   )r7   r)   r   r   r   rI   r   RunFailedErrorassertInr   	exception)r-   rm   r   r   cms        r   test_close_multiple_usersz&ChannelTests.test_close_multiple_users  sp   oo!!#!!#V 15 !- & 	 	V 15 !- & 	 	s|::; 	r##C 5  #u %1 * 	 	*C,=>|::; 	r##C 5  #u %1 * 	 	*C,=>	 	
	 	s   7$E9'$F9FFc                 >   t         j                         }t         j                  |d       t         j                  |       t         j	                  |       | j                  t         j                        5  t         j	                  |       d d d        y # 1 sw Y   y xY wr   r+  r   s     r   test_close_multiple_timesz&ChannelTests.test_close_multiple_times  si    ooc7#csx::; 	 NN3	  	  	 s   4BBc                 F   g d}|D ]  \  }}| j                  ||f      5  t        j                         }t        j                  |d       t        j	                  |       t        j                  |||       | j                  t        j                        5  t        j                  |d       d d d        | j                  t        j                        5  t        j	                  |       d d d        d d d         y # 1 sw Y   QxY w# 1 sw Y    xY w# 1 sw Y   xY w)N))FFTF)FT)TTrs   r   r  )r  r7   r)   rF   rG   rI   r   r8   )r-   testsrF   rG   rm   s        r   test_close_emptyzChannelTests.test_close_empty&  s       
	'JD$tTl+ 	'oo'c7+c"sD9&&x'B'BC 0MM#w/0&&x'B'BC 'MM#&'	' 	'
	'0 0' '	' 	's<   A7DC>.'DD
+D>DD
DDD 	c                 l   t         j                         }t         j                  |d       t         j                  |d       | j                  t         j                        5  t         j                  |       d d d        t         j                  |       t         j                  |d       y # 1 sw Y   5xY w)Nrs      hamr  r7   r)   rF   r   ChannelNotEmptyErrorrI   rG   r   s     r   %test_close_defaults_with_unused_itemsz2ChannelTests.test_close_defaults_with_unused_items9  sy    ooc7#c6"x<<= 	 NN3	 cc7#	  	 s    B**B3c                    t         j                         }t         j                  |d       t         j                  |d       | j                  t         j                        5  t         j                  |d       d d d        t         j                  |       t         j                  |d       t         j                  |       t         j                  |       t         j                  |d       y # 1 sw Y   vxY w)Nrs   r;  TrG   r  r<  r   s     r   *test_close_recv_with_unused_items_unforcedz7ChannelTests.test_close_recv_with_unused_items_unforcedC  s    ooc7#c6"x<<= 	+NN3TN*	+cc7#ccs&	+ 	+s    C--C6c                 ,   t         j                         }t         j                  |d       t         j                  |d       t         j                  |d       | j	                  t         j
                        5  t         j                  |d       d d d        t         j                  |       t         j                  |       | j	                  t         j
                        5  t         j                  |       d d d        y # 1 sw Y   qxY w# 1 sw Y   y xY w)Nrs   r;  Tr   r  r7   r)   rF   rI   r   r8   rG   r   s     r   *test_close_send_with_unused_items_unforcedz7ChannelTests.test_close_send_with_unused_items_unforcedP  s    ooc7#c6"s&x::; 	(MM#w'	(ccx::; 	MM#	 			( 	(	 	s   7C>D
>D
Dc                    t         j                         }t         j                  |d       t         j                  |d       | j                  t         j                        5  t         j                  |dd       d d d        t         j                  |       t         j                  |d       t         j                  |       t         j                  |       t         j                  |d       y # 1 sw Y   vxY w)Nrs   r;  Trt   r  r@  r<  r   s     r   *test_close_both_with_unused_items_unforcedz7ChannelTests.test_close_both_with_unused_items_unforced]  s    ooc7#c6"x<<= 	6NN3TN5	6cc7#ccs&	6 	6s    C..C7c                    t         j                         }t         j                  |d       t         j                  |d       t         j                  |dd       | j	                  t         j
                        5  t         j                  |d       d d d        | j	                  t         j
                        5  t         j                  |       d d d        y # 1 sw Y   GxY w# 1 sw Y   y xY w)Nrs   r;  Tr   r  rC  r   s     r   (test_close_recv_with_unused_items_forcedz5ChannelTests.test_close_recv_with_unused_items_forcedj      ooc7#c6"sT2x::; 	(MM#w'	(x::; 	MM#	 		( 	(	 	   8C6C!C!C*c                    t         j                         }t         j                  |d       t         j                  |d       t         j                  |dd       | j	                  t         j
                        5  t         j                  |d       d d d        | j	                  t         j
                        5  t         j                  |       d d d        y # 1 sw Y   GxY w# 1 sw Y   y xY w)Nrs   r;  Tr   r  rC  r   s     r   (test_close_send_with_unused_items_forcedz5ChannelTests.test_close_send_with_unused_items_forcedu  rI  rJ  c                    t         j                         }t         j                  |d       t         j                  |d       t         j                  |ddd       | j	                  t         j
                        5  t         j                  |d       d d d        | j	                  t         j
                        5  t         j                  |       d d d        y # 1 sw Y   GxY w# 1 sw Y   y xY w)Nrs   r;  Tr   r  rC  r   s     r   (test_close_both_with_unused_items_forcedz5ChannelTests.test_close_both_with_unused_items_forced  s    ooc7#c6"sD=x::; 	(MM#w'	(x::; 	MM#	 		( 	(	 	s   9C7C"C"C+c                 |   t         j                         }t         j                  |       | j                  t         j                        5  t         j                  |d       d d d        | j                  t         j                        5  t         j                  |       d d d        y # 1 sw Y   GxY w# 1 sw Y   y xY wr   )r7   r)   rI   r   r8   rF   rG   r   s     r   test_close_never_usedz"ChannelTests.test_close_never_used  s    oosx::; 	(MM#w'	(x::; 	MM#	 		( 	(	 	   	B&B2&B/2B;c                    t         j                         }t         j                  |d       t        j                         }t        j                  |t        d| d             | j                  t         j                        5  t         j                  |       d d d        | j                  t         j                        5  t         j                  |       d d d        y # 1 sw Y   GxY w# 1 sw Y   y xY w)Nrs   r   r   )
r7   r)   rF   r   r   r   r   r8   rG   rI   r-   rm   r%   s      r   !test_close_by_unassociated_interpz.ChannelTests.test_close_by_unassociated_interp  s    ooc7#$$& 4 E "0 ) 	 x::; 	MM#	x::; 	 NN3	  	 	 		  	 s   C>C)C&)C2c                 .   t         j                         }t         j                  |d       t         j                  |d       t         j                  |d       t         j                  |       t         j	                  |d       | j                  t         j                        5  t         j                  |d       d d d        | j                  t         j                        5  t         j                  |       d d d        y # 1 sw Y   GxY w# 1 sw Y   y xY w)Nrs   Trf   r  r+  r   s     r   -test_close_used_multiple_times_by_single_userz:ChannelTests.test_close_used_multiple_times_by_single_user  s    ooc7#c7#c7#cs$'x::; 	(MM#w'	(x::; 	MM#	 		( 	(	 	s   "C? D?DDc                    t         j                         }| j                  t         j                        5  t         j	                  dd       d d d        t         j                  |       | j                  t         j                        5  t         j	                  |d       d d d        y # 1 sw Y   ^xY w# 1 sw Y   y xY w)Nr   Tr   )r7   r)   r   rz   r   rI   r8   r   s     r   .test_channel_list_interpreters_invalid_channelz;ChannelTests.test_channel_list_interpreters_invalid_channel  s    oox<<= 	8&&t$&7	8 	sx::; 	7&&s&6	7 	7	8 	8
	7 	7s   B)B5)B25B>c                     t         j                         }| j                  t              5  t         j	                  |       d d d        y # 1 sw Y   y xY wr   )r7   r)   r   r   r   r   s     r   +test_channel_list_interpreters_invalid_argsz8ChannelTests.test_channel_list_interpreters_invalid_args  s?    ooy) 	,&&s+	, 	, 	,s   A		AN),r0   r1   r2   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  r  r  r  r  r  r!  r%  unittestskipr(  r,  r3  r5  r9  r>  rA  rD  rF  rH  rL  rN  rP  rT  rV  rX  rZ  r9   r   r   r   r   X  s    7	D.&+2,@4+.)2V8,!8J$
	''('8'
%*<4&.$ X]]=>. ?.$	?0 '&$''			 	7,r   r   c                   P    e Zd ZdZ	 	 d Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)ChannelReleaseTestsa  
    - main / interp / other
    - run in: current thread / new thread / other thread / different threads
    - end / opposite
    - force / no force
    - used / not used  (associated / not associated)
    - empty / emptied / never emptied / partly emptied
    - closed / not closed
    - released / not released
    - creator (interp) / other
    - associated interpreter not running
    - associated interpreter destroyed
    c                    t         j                         }t         j                  |d       t         j                  |       t         j	                  |dd       | j                  t         j                        5  t         j                  |d       d d d        | j                  t         j                        5  t         j                  |       d d d        y # 1 sw Y   GxY w# 1 sw Y   y xY wNrs   Tr   r  r7   r)   rF   rG   r   r   r8   r   s     r   test_single_userz$ChannelReleaseTests.test_single_user  s    ooc7#c4d3x::; 	(MM#w'	(x::; 	MM#	 		( 	(	 	s   7C5C C C)c           
         t         j                         }t        j                         }t        j                         }t        j                  |t	        d| d             t        |t	        d| d| d            }t        j                  |t	        d| d             | j                  |j                         d       y )	Nr   r   r   z )
            _channels.release(z+)
            print(repr(obj))
            z
            _channels.release(r   zb'spam')r7   r)   r   r   r   r   r   r   )r-   rm   r   r   r   s        r   test_multiple_usersz'ChannelReleaseTests.test_multiple_users  s    oo!!#!!#V 15 !- & 	 #v +""% '"e $'    	V 1"e $- & 	 	i0r   c                    t         j                         }t         j                  |d       t         j                  |       t         j	                  |       | j                  t         j                        5  t         j                  |d       d d d        | j                  t         j                        5  t         j                  |       d d d        y # 1 sw Y   GxY w# 1 sw Y   y xY wr*  ra  r   s     r   test_no_kwargsz"ChannelReleaseTests.test_no_kwargs
  s    ooc7#cx::; 	(MM#w'	(x::; 	MM#	 		( 	(	 	r-  c                 J   t         j                         }t         j                  |d       t         j                  |       t         j	                  |dd       | j                  t         j                        5  t         j	                  |dd       d d d        y # 1 sw Y   y xY w)Nrs   Tr   ra  r   s     r   test_multiple_timesz'ChannelReleaseTests.test_multiple_times  s{    ooc7#c4d3x::; 	8St$7	8 	8 	8s   7BB"c                 F   t         j                         }t         j                  |d       t         j                  |d       t         j                  |dd       | j	                  t         j
                        5  t         j                  |       d d d        y # 1 sw Y   y xY w)Nrs   r;  Tr   )r7   r)   rF   r   r   r8   rG   r   s     r   test_with_unused_itemsz*ChannelReleaseTests.test_with_unused_items  st    ooc7#c6"4d3x::; 	MM#	 	 	s   8BB c                 |   t         j                         }t         j                  |       | j                  t         j                        5  t         j                  |d       d d d        | j                  t         j                        5  t         j                  |       d d d        y # 1 sw Y   GxY w# 1 sw Y   y xY wr   )r7   r)   r   r   r8   rF   rG   r   s     r   test_never_usedz#ChannelReleaseTests.test_never_used'  s    oox::; 	(MM#w'	(x::; 	MM#	 		( 	(	 	rQ  c                    t         j                         }t         j                  |d       t        j                         }t        j                  |t        d| d             t         j                  |      }t         j                  |       | j                  t         j                        5  t         j                  |d       d d d        | j                  |d       y # 1 sw Y   xY w)Nrs   r   r   r  )r7   r)   rF   r   r   r   rG   r   r   r8   r   )r-   rm   r%   r   s       r   test_by_unassociated_interpz/ChannelReleaseTests.test_by_unassociated_interp0  s    ooc7#$$& 4"e $0 ) 	 mmC x::; 	(MM#w'	(g&	( 	(s   +CC&c           
      2   t         j                         }t        j                         }t        j                  |t	        d| d| d             | j                  t         j                        5  t         j                  |       d d d        y # 1 sw Y   y xY w)NzT
            import _xxinterpchannels as _channels
            obj = _channels.send(z), b'spam')
            _channels.release(r   )r7   r)   r   r   r   r   r8   rG   rS  s      r   test_close_if_unassociatedz.ChannelReleaseTests.test_close_if_unassociated?  s    oo$$& 4""% '"e $0 ) 	 x::; 	MM#	 	 	s   .BBc                 *   t         j                         }t         j                  |d        t         j                  |       t         j                  |d       t         j	                  |d       t         j                  |      }| j                  |d       y )Nrs   Tr   )r7   r)   rF   rG   r   r   )r-   rm   r   s      r   test_partiallyz"ChannelReleaseTests.test_partiallyL  sg    ooc4 cc7#4(mmC g&r   c                 0   t         j                         }t         j                  |d       t         j                  |d       t         j                  |d       t         j                  |       t         j	                  |dd       | j                  t         j                        5  t         j                  |d       d d d        | j                  t         j                        5  t         j                  |       d d d        y # 1 sw Y   GxY w# 1 sw Y   y xY wr`  ra  r   s     r   'test_used_multiple_times_by_single_userz;ChannelReleaseTests.test_used_multiple_times_by_single_userW  s    ooc7#c7#c7#c4d3x::; 	(MM#w'	(x::; 	MM#	 		( 	(	 	s   #D !D D	DN)r0   r1   r2   __doc__rb  rd  rf  rh  rj  rl  rn  rp  rr  rt  r9   r   r   r^  r^    sC    "	1(	8'	'r   r^  c                   t     e Zd ZdZ fdZed        Zed        Zd ZddZ	d Z
d Zd	 Zd
 Zd Zd Z xZS )ChannelCloseFixtureFc                 v   |dv sJ | j                   ri }net        j                  |      }t        j                  |      }t        j                  |      }|j                  ||j                  ||j                  |i}|sd}t        |   | |||||      }t               |_        t               |_	        ||_
        |S )Nr   rD   )QUICKr   r#   r,   r*   r+   r   _preppedrW   _state_known)	r!   rA   r%   rK   rL   creatorknownr-   r.   s	           r   r+   zChannelCloseFixture.__new__l  s    &&&&99E ))&1F((/E((/EV

E

EE
 GwsCwG"nr   c                     | j                   S r   r{  ra   s    r   rn   zChannelCloseFixture.state  s    {{r   c                     	 | j                   S # t        $ r@ | j                  | j                        }| j	                  |      | _         | j                   cY S w xY wr   )_cidAttributeError_get_interpreterr}  _new_channel)r-   r}  s     r   rm   zChannelCloseFixture.cid  sP    	99 	++DLL9G))'2DI99	s    AAAc                 J    | j                  |      }| j                  |       |S r   )r  _prep_interpreterr-   r%   s     r   get_interpreterz#ChannelCloseFixture.get_interpreter  s%    &&v.v&r   c                     || j                   }|dk(  r| j                  j                  dk(  ryt        | j                  j                        S )NrG   rF   F)rA   rn   rY   boolrR   s     r   expect_closed_errorz'ChannelCloseFixture.expect_closed_error  s@    ;((C&=TZZ..&8DJJ%%&&r   c                 &    | j                  |       y r   )r  r  s     r   prep_interpreterz$ChannelCloseFixture.prep_interpreter  s    v&r   c                     || _         y r   r  )r-   r@   rp   s      r   record_actionz!ChannelCloseFixture.record_action  s	    r   c                 ,    t                t                y r   )r   r|   ra   s    r   clean_upzChannelCloseFixture.clean_up  s    r   c                     |j                   dk(  rt        j                         S t        j                         }t        |j                  d| d       t        j                  |      | _        | j                  S )Nr   z
                import _xxsubinterpreters
                cid = _xxsubchannels.create()
                # We purposefully send back an int to avoid tying the
                # channel to the other interpreter.
                _xxsubchannels.send(zC, int(cid))
                del _xxsubinterpreters
                )r,   r7   r)   r   r   rG   r  )r-   r}  chs      r   r  z ChannelCloseFixture._new_channel  sg    <<6!??$$"Bwzz (%
 &(D )$  !b)DIyyr   c                     |dv r| j                   S |dk(  r| j                  S |dk(  r| j                  S |}	 | j                  |   }|S # t        $ r t        |      x}| j                  |<   Y |S w xY w)N)rD   r%   rK   rL   )r%   rK   rL   r|  KeyErrorr   )r-   r%   r,   s      r   r  z$ChannelCloseFixture._get_interpreter  s    '';;w::w::D?T* M  ?-8->>T*M?s   A #A.-A.c                     |j                   | j                  v ry | j                  j                  |j                          |j                  dk(  ry t	        |j                   d| j
                   d       y )Nr   a
  
            import _xxinterpchannels as channels
            import test.test__xxinterpchannels as helpers
            ChannelState = helpers.ChannelState
            try:
                cid
            except NameError:
                cid = channels._channel_id(r   )r   rz  addr,   r   rm   r  s     r   r  z%ChannelCloseFixture._prep_interpreter  sb    99%&))$;;& 699 #, -1HH: 6 	r   r   )r0   r1   r2   ry  r+   propertyrn   rm   r  r  r  r  r  r  r  r  r4   r5   s   @r   rw  rw  e  s_    
 E*    
'' r   rw  zend interp other extra creatorz%these tests take several hours to runc                   r    e Zd ZdZ	 	 d Zd Zd Zd Zd Zddd	Z	d
 Z
d ZddZd ZddZd Zd Zd Zy)ExhaustiveChannelTestsa  
    - main / interp / other
    - run in: current thread / new thread / other thread / different threads
    - end / opposite
    - force / no force
    - used / not used  (associated / not associated)
    - empty / emptied / never emptied / partly emptied
    - closed / not closed
    - released / not released
    - creator (interp) / other
    - associated interpreter not running
    - associated interpreter destroyed

    - close after unbound
    c              #   <  K   g  | j                  dd      D ]"  }| | j                         D ]	  }||z     $ | j                  dd      D ]"  }| | j                         D ]	  }||z     $ | j                  dd      D ]~  }| | j                  dd      D ]'  }||z   }| | j                         D ]	  }||z     ) | j                  dd      D ]'  }||z   }| | j                         D ]	  }||z     )  | j                  dd      D ]~  }| | j                  dd      D ]'  }||z   }| | j                         D ]	  }||z     ) | j                  dd      D ]'  }||z   }| | j                         D ]	  }||z     )  y w)NrD   rK   rL   )_iter_close_action_sets_iter_post_close_action_sets_iter_use_action_sets)r-   closeactionspostactions
useactionsactionss        r   iter_action_setsz'ExhaustiveChannelTests.iter_action_sets  s      !88I 	1L#@@B 1"[001	1 !88'J 	1L#@@B 1"[001	1 44VWE 	0J $ < <VW M 0$|3#'#D#D#F 0K!K//00
 !% < <Wg N 0$|3#'#D#D#F 0K!K//00	0 44WgF 	0J $ < <VW M 0$|3#'#D#D#F 0K!K//00
 !% < <Wg N 0$|3#'#D#D#F 0K!K//00	0s   FFc              #     K   ||f}t        dd|      g t        dd|      g t        dd|      t        dd|      g t        dd|      g t        dd|      g t        dd|      t        dd|      g |D ]8  }|D ]1  }|D ]*  }t        dd|      t        dd|      t        dd|      g , 3 : |D ]K  }|D ]D  }|D ]=  }|D ]6  }t        dd|      t        dd|      t        dd|      t        dd|      g 8 ? F M y w)NrC   rG   rF   r<   )r-   r   r   interpsr   interp4s         r   r  z,ExhaustiveChannelTests._iter_use_action_sets.  s    G$ %1 	 %1 	 %1%1 	 %1 	 %1 	 %1%1 	  	G" & G%eVW=%eVW=%eVW= 	  		G" & G#* )%A)%A)%A)%A	 		s   DDc           
   #      K   d}||f}dD ]&  }|rdnd}|D ]  }|D ]  }t        |||      g   ( dD ]3  }	dD ],  }
|D ]%  }|D ]  }t        |	d|      t        |
d|      g   ' . 5 y w)Nrt   r7  rJ   rI   rH   rG   rF   r  )r-   r   r   endsr  rg   opr%   rA   recvopsendoprG   rF   s                r   r  z.ExhaustiveChannelTests._iter_close_action_sets_  s     G$" 	E"'WB!  C%b#v6 	 / 	F2 # D ' )&&$?)&&$? 	s   A+A-c              #   Z   K   dD ]"  }t        dd|      g t        dd|      g $ y w)N)rD   rL   rK   rC   rG   rF   r  r  s     r   r  z3ExhaustiveChannelTests._iter_post_close_action_setsr  sC     0 	FeVV4  eVV4 		s   )+c                 6    |D ]  }| j                  ||        y r   )rq   )r-   fixr  r@   s       r   run_actionsz"ExhaustiveChannelTests.run_actions{  s     	)FOOC(	)r   Tri   c                   |j                  |j                        }|j                  |j                  |j                  |j
                        }|j                  |       |j                  dk(  rAt        |j                  |j                  ||j                  |      }|j                  ||       y t        j                         }t        |j                   d|j                   dt#        |j                         dt#        |       dt#        |j                         d| d| d| d       t%        t&        j)                  t        j+                  |      d	      t-        t        j+                  |            
      }|j                  ||       y )Nr   ri   zB
                result = helpers.run_action(
                    z,
                    z!,
                    hideclosed=z6,
                    )
                channels.send(zF, result.pending.to_bytes(1, 'little'))
                channels.send(z2, b'X' if result.closed else b'')
                little)r[   rY   )rS   rA   rU   r%   rK   rL   r  r,   rq   rm   r@   rn   r  r7   r)   r   r   r   rW   r   
from_bytesrG   r  )r-   r  r@   rj   rA   r%   rp   r  s           r   rq   z!ExhaustiveChannelTests.run_action  sR     )&&szz399ciiHV$;;& 		%F ff-??$Dvyy 'WWI &--() *#YK  #))_% &  *| ,#f %#f %
# 
 "x}}T':HEHMM$/0F ff-r   c           
   #   h   K   g d}|D ]%  \  }}}dD ]  }dD ]  }t        |||||         ' y w)N))r   r%   rL   )r%   r   rL   )r   r   rL   )r   r   r   )rD   rK   r}  r   )rw  )r-   r   r%   rK   rL   r}  rA   s          r   iter_fixturesz$ExhaustiveChannelTests.iter_fixtures  s\     
 %1 	R FE57 R+ RC-c65%QQRR	Rs   02c                   |rdnd}t        ||j                  d      }|j                         s| j                  ||d       y | j	                  t
        j                        5  | j                  ||d       d d d        y # 1 sw Y   y xY w)NrJ   rI   rD   Fri   )r<   rA   r  rq   r   r7   r8   )r-   r  rg   r  rI   s        r   _closezExhaustiveChannelTests._close  sv    #]b#''62&&(OOC5O9""8#>#>? >Uu=> > >s   "B  B	Nc                 |   ||j                   dk(  r | j                  t        j                        5  t        j	                  |j
                         d d d        | j                  t        j                        5  t        j                  |j
                  d       d d d        | j                  t        j                        5  t        j                  |j
                         d d d        | j                  t        j                        5  t        j                  |j
                  d       d d d        y t        |j                  d       t        |j                  d       t        |j                  d       t        |j                  d       y # 1 sw Y   <xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)	Nr   rs   Trf   zn
                with helpers.expect_channel_closed():
                    channels.recv(cid)
                zw
                with helpers.expect_channel_closed():
                    channels.send(cid, b'spam')
                zo
                with helpers.expect_channel_closed():
                    channels.close(cid)
                z{
                with helpers.expect_channel_closed():
                    channels.close(cid, force=True)
                )
r,   r   r7   r8   rG   rm   rF   rI   r   r   )r-   r  r%   s      r   _assert_closed_in_interpz/ExhaustiveChannelTests._assert_closed_in_interp  sU   >V[[F2""8#>#>? 'cgg&'""8#>#>? 0cggw/0""8#>#>? (sww'(""8#>#>? 4swwd34 4 vyy #  vyy #  vyy #  vyy # +' '0 0( (4 4s/    F9!F F&"F2FF#&F/2F;c                    | j                  |j                  j                         t        |j                  j                        D ]!  }t
        j                  |j                         # | j                  |       dD ]5  }|j                  |      }|j                  dk(  r$| j                  ||       7 |j                  d      }| j                  ||       y )N)rD   rK   r   fresh)r   rn   rY   ranger[   r7   rG   rm   r  r  r,   )r-   r  _r%   s       r   _assert_closedz%ExhaustiveChannelTests._assert_closed  s    		(()syy(() 	#AMM#''"	#%%c*' 	7F((0F{{f$))#v6		7 $$W-%%c62r   c              #     K   d}| j                         D ]  }t                | j                         D ]  }|dz  }|dkD  r  y |r;|dz
  dz  dk(  r
t                t        ||dj                  t	        |                   nC|dz
  dz  dk(  rt        dd       t        d	d       t
        j                  j                          |||f  |st        d
        t                y w)Nr   r^   r      z({} actions)  rQ   .z---)r  printr  r'   r   sysstdoutflush)r-   verboseir  r  s        r   _iter_close_testsz(ExhaustiveChannelTests._iter_close_tests  s     ,,. 	GG))+ &Qt8A{a'!S."7"7G"EFA{a'cr*#2&

(8(8(:go%& e!	" 	s   CC&C&c                 L    dt         _        | j                         D ]  \  }}} y )NT)rw  ry  r  r-   r  r  r  s       r   _skim_close_testsz(ExhaustiveChannelTests._skim_close_tests  s,    $(!#557 	OAsG	r   c                 f   | j                         D ]  \  }}}| j                  dj                  |||            5  |j                  |j                         | j                  ||       | j                  |d       | j                  |       d d d        |j                           y # 1 sw Y   xY w)N	{} {}  {}Frf   	r  r  r'   r  r%   r  r  r  r  r  s       r   
test_closez!ExhaustiveChannelTests.test_close  s    #557 		OAsGk00CAB )$$SZZ0  g.Cu-##C() LLN		) )   AB''B0	c                 f   | j                         D ]  \  }}}| j                  dj                  |||            5  |j                  |j                         | j                  ||       | j                  |d       | j                  |       d d d        |j                           y # 1 sw Y   xY w)Nr  Trf   r  r  s       r   test_force_closez'ExhaustiveChannelTests.test_force_close  s    #557 		OAsGk00CAB )$$SZZ0  g.Ct,##C() LLN		) )r  r   )F)r0   r1   r2   ru  r  r  r  r  r  rq   r  r  r  r  r  r  r  r  r9   r   r   r  r    s`      +0Z/b&) 59 .@R>83 ,


r   r  __main__)%collectionsr   
contextlibr  textwrapr   r   r   r[  test.supportr   test.test__xxsubinterpretersr   r   r   import_moduler7   r   r   r   contextmanagerr:   r<   rW   rq   rl   r|   TestCaser~   r   r   r^  rw  r\  r  r0   r   r9   r   r   <module>r     sX   "  
     &  '=&&':; $ -/ 	4!*]I6 !L + +/#J0CD /#fE:n.>? E& 7; *!!H x    `,X `,Je	,8 e	,Pb( bJn*%:%EG nb 67{X { 8{|	 zHMMO r   