a
    ze                      @   s   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ zddlZW n ey~   dZY n0 ddlZddlmZ dd ZG dd	 d	ejZed
kre  dS )zTests for streams.py.    N)mock)socket_helper)utilsc                   C   s   t d  d S N)asyncioZset_event_loop_policy r   r   4/usr/lib/python3.9/test/test_asyncio/test_streams.pytearDownModule   s    r	   c                       sp  e Zd ZdZ fddZ fddZeddd Zd	d
 Z	dd Z
ejdd Zdd Zeedu ddd Zejeedu ddd Zdd Zdd Zejdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Z d1d2 Z!d3d4 Z"d5d6 Z#d7d8 Z$d9d: Z%d;d< Z&d=d> Z'd?d@ Z(dAdB Z)dCdD Z*dEdF Z+dGdH Z,dIdJ Z-dKdL Z.dMdN Z/dOdP Z0dQdR Z1dSdT Z2dUdV Z3dWdX Z4dYdZ Z5d[d\ Z6d]d^ Z7ejd_d` Z8ee9j:dakdbdcdd Z;dedf Z<dgdh Z=didj Z>dkdl Z?dmdn Z@dodp ZAdqdr ZBdsdt ZCdudv ZDdwdx ZEdydz ZFd{d| ZGd}d~ ZHdd ZIdd ZJdd ZKdd ZL  ZMS )StreamTestss   line1
line2
line3
c                    s$   t    t | _| | j d S r   )supersetUpr   Znew_event_looploopset_event_loopself	__class__r   r   r      s    

zStreamTests.setUpc                    s,   t | j | j  t  t   d S r   )
test_utilsrun_brieflyr   closegcZcollectr   tearDownr   r   r   r   r   #   s    
zStreamTests.tearDownzasyncio.streams.eventsc                 C   s   t  }| |j|jj d S r   )r   StreamReaderassertIs_loopZget_event_loopreturn_value)r   Zm_eventsstreamr   r   r   test_ctor_global_loop+   s    z!StreamTests.test_ctor_global_loopc                    s   g  | j  fdd | t  | j |\}}W d    n1 sH0    Y  |d | }| j |}| |d | }| j |}| 	|
d |  |  g  d S )Nc                    s
     |S r   appendr   ctxmessagesr   r   <lambda>2       z7StreamTests._basetest_open_connection.<locals>.<lambda>   GET / HTTP/1.0

   HTTP/1.0 200 OK
   

Test message)r   set_exception_handlerassertWarnsDeprecationWarningrun_until_completewritereadlineassertEqualread
assertTrueendswithr   r   open_connection_futreaderwriterfdatar   r"   r   _basetest_open_connection0   s    .
z%StreamTests._basetest_open_connectionc                 C   sJ   t  .}tj|jd| ji}| | W d    n1 s<0    Y  d S Nr   )r   run_test_serverr   open_connectionaddressr   r9   r   httpdZconn_futr   r   r   test_open_connection?   s
    

z StreamTests.test_open_connectionc                 C   sH   t  ,}tj|j| jd}| | W d    n1 s:0    Y  d S Nr   )r   run_test_unix_serverr   open_unix_connectionr=   r   r9   r>   r   r   r   test_open_unix_connectionE   s
    
z%StreamTests.test_open_unix_connectionc              	      s   g  | j  fdd zH| t  | j |\}}W d    n1 sJ0    Y  W td  ntd  0 |d | }| j |}| 	|
d |  |  g  d S )Nc                    s
     |S r   r   r    r"   r   r   r$   N   r%   zCStreamTests._basetest_open_connection_no_loop_ssl.<locals>.<lambda>r&   r(   )r   r)   r*   r+   r,   r   r   r-   r0   r1   r2   r   r/   r3   r   r"   r   %_basetest_open_connection_no_loop_sslL   s    0
z1StreamTests._basetest_open_connection_no_loop_sslNzNo ssl modulec                 C   sT   t jdd4}tj|jt  | jd}| | W d    n1 sF0    Y  d S )NTZuse_ssl)sslr   )r   r;   r   r<   r=   dummy_ssl_contextr   rF   r>   r   r   r    test_open_connection_no_loop_ssl\   s    z,StreamTests.test_open_connection_no_loop_sslc                 C   sT   t jdd4}tj|jt  d| jd}| | W d    n1 sF0    Y  d S )NTrG    )rH   Zserver_hostnamer   )r   rC   r   rD   r=   rI   r   rF   r>   r   r   r   %test_open_unix_connection_no_loop_sslf   s    z1StreamTests.test_open_unix_connection_no_loop_sslc                    s   g  | j  fdd | t  | j |\}}W d    n1 sH0    Y  |jt  | }| 	t | j | W d    n1 s0    Y  |
  t| j  |  g  d S )Nc                    s
     |S r   r   r    r"   r   r   r$   t   r%   z=StreamTests._basetest_open_connection_error.<locals>.<lambda>)r   r)   r*   r+   r,   Z	_protocolZconnection_lostZeroDivisionErrorr0   assertRaisesr   r   r   r/   )r   r4   r5   r6   r7   r   r"   r   _basetest_open_connection_errorr   s    .*z+StreamTests._basetest_open_connection_errorc                 C   sJ   t  .}tj|jd| ji}| | W d    n1 s<0    Y  d S r:   )r   r;   r   r<   r=   r   rO   r>   r   r   r   test_open_connection_error   s
    

z&StreamTests.test_open_connection_errorc                 C   sH   t  ,}tj|j| jd}| | W d    n1 s:0    Y  d S rA   )r   rC   r   rD   r=   r   rO   r>   r   r   r   test_open_unix_connection_error   s
    
z+StreamTests.test_open_unix_connection_errorc                 C   s*   t j| jd}|d | d|j d S NrB   r%   )r   r   r   	feed_datar/   _bufferr   r   r   r   r   test_feed_empty_data   s    
z StreamTests.test_feed_empty_datac                 C   s.   t j| jd}|| j | | j|j d S rA   )r   r   r   rS   DATAr/   rT   rU   r   r   r   test_feed_nonempty_data   s    z#StreamTests.test_feed_nonempty_datac                 C   sL   t j| jd}|| j | j|d}| d| | | j|j d S )NrB   r   r%   )	r   r   r   rS   rW   r,   r0   r/   rT   r   r   r8   r   r   r   test_read_zero   s
    zStreamTests.test_read_zeroc                    sf   t j jd jd} fdd} j|  j|}  j|  dj	 d S )NrB      c                      s     j d S r   rS   rW   r   rU   r   r   cb   s    z!StreamTests.test_read.<locals>.cbr%   )
r   r   r   create_taskr0   	call_soonr,   r/   rW   rT   r   	read_taskr]   r8   r   rU   r   	test_read   s    zStreamTests.test_readc                 C   sR   t j| jd}|d |d | j|d}| d| | d|j d S )NrB   s   line1s   line2   r   r   r   rS   r,   r0   r/   rT   rY   r   r   r   test_read_line_breaks   s    

z!StreamTests.test_read_line_breaksc                    sb   t j| jd | j d} fdd}| j| | j|}| d| | d j d S )NrB   i   c                      s       d S r   )feed_eofr   r   r   r   r]      s    z%StreamTests.test_read_eof.<locals>.cbr%   	r   r   r   r^   r0   r_   r,   r/   rT   r`   r   rg   r   test_read_eof   s    zStreamTests.test_read_eofc                    sb   t j| jd | j d} fdd}| j| | j|}| d| | d j d S )NrB   c                      s      d   d    d S )Ns   chunk1
   chunk2rS   rf   r   rg   r   r   r]      s    

z+StreamTests.test_read_until_eof.<locals>.cbs   chunk1
chunk2r%   rh   r`   r   rg   r   test_read_until_eof   s    zStreamTests.test_read_until_eofc                 C   s^   t j| jd}|d | j|d}| d| |t  | 	t| jj|d d S NrB      line
      li)
r   r   r   rS   r,   r0   r/   set_exception
ValueErrorrN   rY   r   r   r   test_read_exception   s    
zStreamTests.test_read_exceptionc                 C   s|   |  td  tjd| jd W d    n1 s20    Y  |  td  tjd| jd W d    n1 sn0    Y  d S )NZimitr   limitr   rj   )assertRaisesRegexrs   r   r   r   r   r   r   r   test_invalid_limit   s    .zStreamTests.test_invalid_limitc                 C   sJ   t jd| jd}|d | j|d}| d| | d|j d S N   ru   s   chunkrc   r%   rd   rY   r   r   r   test_read_limit   s
    
zStreamTests.test_read_limitc                    sj   t j| jd  d | j  } fdd}| j| | j|}| d| | d j	 d S )NrB   s   chunk1 c                      s"     d   d   d d S )Ns   chunk2 s   chunk3 s   
 chunk4)rS   r   rg   r   r   r]      s    

z%StreamTests.test_readline.<locals>.cbs   chunk1 chunk2 chunk3 
s    chunk4)
r   r   r   rS   r^   r.   r_   r,   r/   rT   )r   ra   r]   liner   rg   r   test_readline   s    
zStreamTests.test_readlinec                 C   s   t jd| jd}|d |d | t| jj|  | d|j	 t jd| jd}|d |d |d | t| jj|  | d|j	 d S )Nrz   ru   rq   s
   ne1
line2
s   line2
s   ne1r%   )
r   r   r   rS   rN   rs   r,   r.   r/   rT   rU   r   r   r   &test_readline_limit_with_existing_data   s    




z2StreamTests.test_readline_limit_with_existing_datac                 C   s   t j| jd}| |  |d | |  | j|  | |  |d |  | j|  | 	|  d S )NrB   s
   some data
)
r   r   r   assertFalseat_eofrS   r,   r.   rf   r1   rU   r   r   r   test_at_eof  s    

zStreamTests.test_at_eofc                    s  t jd| jd  fdd}| j| | t| jj   | d j	 t jd| jd  fdd}| j| | t| jj   | d j	 t jd| jd  
d | j  }| d| | d j	  
d	 | t }| j   W d    n1 s0    Y  | d j	  
d
 | t }| j   W d    n1 sl0    Y  | d j	 d S )N   ru   c                      s*     d   d   d    d S )N   chunk1rk      chunk3
rl   r   rg   r   r   r]   /  s    


z+StreamTests.test_readline_limit.<locals>.cbr%   c                      s*     d   d   d    d S )Nr   s   chunk2
r   rl   r   rg   r   r   r]   =  s    


r   s   1234567
s	   12345678
s   12345678)r   r   r   r_   rN   rs   r,   r.   r/   rT   rS   )r   r]   r|   cmr   rg   r   test_readline_limit*  s6    

0
0zStreamTests.test_readline_limitc                 C   sd   t j| jd}|| jd d  || jdd   | j| }| d| | d|j d S )NrB      s   line1
s   line2
line3
)	r   r   r   rS   rW   r,   r.   r/   rT   r   r   r|   r   r   r   test_readline_nolimit_nowaitY  s    z(StreamTests.test_readline_nolimit_nowaitc                 C   s@   t j| jd}|d |  | j| }| d| d S )NrB   s	   some data)r   r   r   rS   rf   r,   r.   r/   r   r   r   r   test_readline_eofe  s
    
zStreamTests.test_readline_eofc                 C   s6   t j| jd}|  | j| }| d| d S rR   )r   r   r   rf   r,   r.   r/   r   r   r   r   test_readline_empty_eofm  s    z#StreamTests.test_readline_empty_eofc                 C   sZ   t j| jd}|| j | j|  | j|d}| d| | d|j	 d S )NrB   r   s   line2
ls   ine3
)
r   r   r   rS   rW   r,   r.   r0   r/   rT   rY   r   r   r   test_readline_read_byte_countt  s    z)StreamTests.test_readline_read_byte_countc                 C   sh   t j| jd}|d | j| }| d| |t  | 	t| jj|  | d|j
 d S )NrB   ro   r%   )r   r   r   rS   r,   r.   r/   rr   rs   rN   rT   rY   r   r   r   test_readline_exception  s    
z#StreamTests.test_readline_exceptionc                 C   sR   t j| jd}| td$ | j|jdd W d    n1 sD0    Y  d S )NrB   zSeparator should ber%   	separator)r   r   r   rw   rs   r,   	readuntilrU   r   r   r   test_readuntil_separator  s    z$StreamTests.test_readuntil_separatorc                 C   s   t j| jd}|d | j|jdd}| d| | d|j |d | j|d}| d| | d|j |d | j|d}| d| | d|j d S )NrB   s   lineAAA   AAAr   r%   s
   lineAAAxxxs   xxxr   r   r   rS   r,   r   r/   rT   rY   r   r   r   test_readuntil_multi_chunks  s    


z'StreamTests.test_readuntil_multi_chunksc                 C   sf  t j| jd}|d |d |d | j|d}| d| | d|j |d |d |d	 | j|d}| d| | d|j |d | j|d}| d| | d|j |d
 | j|d}| d
| | d|j |d |d |d |d | j|d}| d| | d|j d S )NrB   s   QWEaas   XYaa   as   aaas
   QWEaaXYaaar%   s   XYas   aas   Xaaas   XXXs   XXXaaar   rY   r   r   r   test_readuntil_multi_chunks_1  s8    











z)StreamTests.test_readuntil_multi_chunks_1c                 C   s   t j| jd}d}|| |  | t jd"}| j|d W d    n1 sZ0    Y  | 	|j
j| | |j
j | 	d|j d S )NrB      some dataAAzundefined expected bytesr   r%   )r   r   r   rS   rf   rw   IncompleteReadErrorr,   r   r/   	exceptionpartialassertIsNoneexpectedrT   )r   r   r8   r   r   r   r   test_readuntil_eof  s    
0zStreamTests.test_readuntil_eofc                 C   s   t j| jdd}|d | t jd"}| j|d W d    n1 sP0    Y  | d|j	 |d | t jd"}| j|d W d    n1 s0    Y  | d|j	 d S )	Nrz   r   rv   r   z	not foundr      Azis founds   some dataAAA)
r   r   r   rS   rw   LimitOverrunErrorr,   r   r/   rT   )r   r   r   r   r   r   test_readuntil_limit_found_sep  s    
0
0z*StreamTests.test_readuntil_limit_found_sepc                 C   s   t j| jd}|| j | j|d}| d| | | j|j | 	t
d" | j|d W d    n1 s|0    Y  | | j|j d S )NrB   r   r%   zless than zerorj   )r   r   r   rS   rW   r,   readexactlyr/   rT   rw   rs   rY   r   r   r   test_readexactly_zero_or_less  s    0z)StreamTests.test_readexactly_zero_or_lessc                    s|   t j jddt j } j|} fdd} j|  j|} 	 j j |  	 jj
 d S )NrB   rp   c                      s(     j   j   j d S r   r\   r   rU   r   r   r]     s    z(StreamTests.test_readexactly.<locals>.cb)r   r   r   lenrW   r^   r   r_   r,   r/   rT   )r   nra   r]   r8   r   rU   r   test_readexactly  s    zStreamTests.test_readexactlyc                 C   sJ   t jd| jd}|d | j|d}| d| | d|j d S ry   )r   r   r   rS   r,   r   r/   rT   rY   r   r   r   test_readexactly_limit   s
    
z"StreamTests.test_readexactly_limitc                    s   t j jddt j } j|} fdd} j|  t j	} j
| W d    n1 sv0    Y   |jj j  |jj|  t|jd  dj d S )NrB   rp   c                      s     j   d S r   )rS   rW   rf   r   rU   r   r   r]     s    z,StreamTests.test_readexactly_eof.<locals>.cbz-18 bytes read on a total of 36 expected bytesr%   )r   r   r   r   rW   r^   r   r_   rN   r   r,   r/   r   r   r   strrT   )r   r   ra   r]   r   r   rU   r   test_readexactly_eof  s    *z StreamTests.test_readexactly_eofc                 C   s^   t j| jd}|d | j|d}| d| |t  | 	t| jj|d d S rn   )
r   r   r   rS   r,   r   r/   rr   rs   rN   rY   r   r   r   test_readexactly_exception  s    
z&StreamTests.test_readexactly_exceptionc                 C   s@   t j| jd}| |  t }|| | | | d S rA   )r   r   r   r   r   rs   rr   r   r   r   excr   r   r   test_exception%  s
    
zStreamTests.test_exceptionc                    s`   t j| jd  fdd}| j  }| j| }| jt ||g | t|j	 d S )NrB   c                      s     t  d S r   )rr   rs   r   rg   r   r   set_err0  s    z2StreamTests.test_exception_waiter.<locals>.set_err)
r   r   r   r^   r.   r,   waitrN   rs   result)r   r   t1t2r   rg   r   test_exception_waiter-  s    z!StreamTests.test_exception_waiterc                 C   sj   t j| jd}| j| }t| j |  t| j |t	d t| j | 
|jd  d S )NrB   message)r   r   r   r^   r.   r   r   cancelrr   RuntimeErrorr   _waiter)r   r   tr   r   r   test_exception_cancel:  s    z!StreamTests.test_exception_cancelc                    s  G dd d}fdd}g  j  fdd |j }t | }W d    n1 sd0    Y  j j ||}|  |d |j }t |	 }W d    n1 s0    Y  j j ||}|  |d  g  d S )Nc                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )z/StreamTests.test_start_server.<locals>.MyServerc                 S   s   d | _ || _d S r   )serverr   )r   r   r   r   r   __init__J  s    z8StreamTests.test_start_server.<locals>.MyServer.__init__c                    s@   |  I d H }|| | I d H  |  | I d H  d S r   r.   r-   drainr   wait_closedr   client_readerclient_writerr8   r   r   r   handle_clientN  s
    
z=StreamTests.test_start_server.<locals>.MyServer.handle_clientc                 S   s0   t d}| jtj| j|| jd| _| S )Nz	127.0.0.1r   )sockr   )	socketcreate_serverr   r,   r   start_serverr   r   getsockname)r   r   r   r   r   startU  s    
z5StreamTests.test_start_server.<locals>.MyServer.startc                 S   s   | j | || d S r   r   r^   r   r   r   r   r   r   r   handle_client_callback]  s    zFStreamTests.test_start_server.<locals>.MyServer.handle_client_callbackc                 S   sF   t d}| }|  | jtj| j|d |d | jd| _	|S )Nr   r      )hostportr   )
r   r   r   r   r   r,   r   r   r   r   )r   r   addrr   r   r   start_callbacka  s    
z>StreamTests.test_start_server.<locals>.MyServer.start_callbackc                 S   s0   | j d ur,| j   | j| j   d | _ d S r   r   r   r   r,   r   r   r   r   r   stopk  s    

z4StreamTests.test_start_server.<locals>.MyServer.stopN	__name__
__module____qualname__r   r   r   r   r   r   r   r   r   r   MyServerH  s   
r   c                    sx     t, tj| d jiI d H \}}W d    n1 s<0    Y  |d | I d H }|  | I d H  |S )Nr      hello world!
)	r*   r+   r   r<   r   r-   r.   r   r   )r   r5   r6   msgbackr   r   r   clientq  s    .
z-StreamTests.test_start_server.<locals>.clientc                    s
     |S r   r   r    r"   r   r   r$   ~  r%   z/StreamTests.test_start_server.<locals>.<lambda>r   )
r   r)   r*   r+   r   r,   r^   r   r/   r   )r   r   r   r   r   msgr   r#   r   r   test_start_serverF  s"    )
&
&zStreamTests.test_start_serverc              	      sj  G dd d}fdd}g  j  fdd t z}|j |}t |  W d    n1 sp0    Y  j j ||}|	  
|d W d    n1 s0    Y  t |}|j |}t |  W d    n1 s0    Y  j j ||}|	  
|d W d    n1 sP0    Y  
 g  d S )Nc                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )z4StreamTests.test_start_unix_server.<locals>.MyServerc                 S   s   d | _ || _|| _d S r   )r   r   path)r   r   r   r   r   r   r     s    z=StreamTests.test_start_unix_server.<locals>.MyServer.__init__c                    s@   |  I d H }|| | I d H  |  | I d H  d S r   r   r   r   r   r   r     s
    
zBStreamTests.test_start_unix_server.<locals>.MyServer.handle_clientc                 S   s$   | j tj| j| j| j d| _d S N)r   r   )r   r,   r   start_unix_serverr   r   r   r   r   r   r   r     s    z:StreamTests.test_start_unix_server.<locals>.MyServer.startc                 S   s   | j | || d S r   r   r   r   r   r   r     s    zKStreamTests.test_start_unix_server.<locals>.MyServer.handle_client_callbackc                 S   s(   t j| j| j| jd}| j|| _d S r   )r   r   r   r   r   r,   r   )r   r   r   r   r   r     s
    zCStreamTests.test_start_unix_server.<locals>.MyServer.start_callbackc                 S   s0   | j d ur,| j   | j| j   d | _ d S r   r   r   r   r   r   r     s    

z9StreamTests.test_start_unix_server.<locals>.MyServer.stopNr   r   r   r   r   r     s   r   c                    sv     t* tj|  jdI d H \}}W d    n1 s:0    Y  |d | I d H }|  | I d H  |S )NrB   r   )	r*   r+   r   rD   r   r-   r.   r   r   )r   r5   r6   r   r   r   r   r     s    .
z2StreamTests.test_start_unix_server.<locals>.clientc                    s
     |S r   r   r    r"   r   r   r$     r%   z4StreamTests.test_start_unix_server.<locals>.<lambda>r   )r   r)   r   Zunix_socket_pathr*   r+   r   r,   r^   r   r/   r   )r   r   r   r   r   r   r   r   r   test_start_unix_server  s.    $
&*
(,z"StreamTests.test_start_unix_serverwin32zDon't have pipesc              	      s  d}t  \}}tjd|t|g}t|dd}tj| jdd}tj	|| jd | j
| j fdd	|\}}t }	|	| j zFt|	 tj|d
|hi}
| j
|
}| j
|  W td  ntd  0 t | | j
|d}| |d d S )NzHimport os, sys
fd = int(sys.argv[1])
os.write(fd, b'data')
os.close(fd)
z-crbr   r   r   rB   c                      s    S r   r   r   protocolr   r   r$     r%   z<StreamTests.test_read_all_from_pipe_reader.<locals>.<lambda>pass_fdsrj      data)ospipesys
executabler   openr   r   r   StreamReaderProtocolr,   Zconnect_read_pipeZSafeChildWatcherZattach_loopZset_child_watcherZcreate_subprocess_execr   r   r0   r/   )r   codeZrfdZwfdargsr   r5   Z	transport_ZwatcherZcreateprocr8   r   r   r   test_read_all_from_pipe_reader  s0    

z*StreamTests.test_read_all_from_pipe_readerc                 C   s6   |  tjd  t| j t }| |j| j d S r   )
addCleanupr   r   r   r   r   r   )r   r5   r   r   r   test_streamreader_constructor  s    z)StreamTests.test_streamreader_constructorc                 C   s@   |  tjd  t| j t }t|}| |j| j d S r   )	r   r   r   r   r   Mockr   r   r   )r   r5   r   r   r   r   %test_streamreaderprotocol_constructor  s
    
z1StreamTests.test_streamreaderprotocol_constructorc                    s   g  j  fdd t fdd}fdd}tj|d}|d |   }	t
ttf  j ||  W d    n1 s0    Y  |  g   d S )	Nc                    s
     |S r   r   r    r"   r   r   r$   "  r%   z/StreamTests.test_drain_raises.<locals>.<lambda>c                     sT   t d6} |  } | |  \}}|  W d    n1 sF0    Y  d S )N)	localhostr   )r   r   r   putacceptr   )r   r   Zcltr   )qr   r   r   %  s
    
z-StreamTests.test_drain_raises.<locals>.serverc                    sd     t, tj| | jdI d H \}}W d    n1 s<0    Y  |d | I d H  qFd S )NrB   s   foo
)r*   r+   r   r<   r   r-   r   )r   r   r5   r6   r   r   r   r   -  s    .
z-StreamTests.test_drain_raises.<locals>.client)targetT)r   r)   queueQueue	threadingThread	setDaemonr   getrN   ConnectionResetErrorConnectionAbortedErrorBrokenPipeErrorr,   joinr/   )r   r   r   threadr   r   )r#   r   r   r   test_drain_raises  s    

.zStreamTests.test_drain_raisesc                 C   s"   t j| jd}| dt| d S )NrB   <StreamReader>r   r   r   r/   reprrU   r   r   r   test___repr__F  s    zStreamTests.test___repr__c                 C   s$   t j| jdd}| dt| d S )N{   r   z<StreamReader limit=123>r
  rU   r   r   r   test___repr__nondefault_limitJ  s    z)StreamTests.test___repr__nondefault_limitc                 C   s*   t j| jd}|  | dt| d S )NrB   z<StreamReader eof>)r   r   r   rf   r/   r  rU   r   r   r   test___repr__eofN  s    zStreamTests.test___repr__eofc                 C   s,   t j| jd}|d | dt| d S )NrB   r   z<StreamReader 4 bytes>)r   r   r   rS   r/   r  rU   r   r   r   test___repr__dataS  s    
zStreamTests.test___repr__datac                 C   s2   t j| jd}t }|| | dt| d S )NrB   z'<StreamReader exception=RuntimeError()>)r   r   r   r   rr   r/   r  r   r   r   r   test___repr__exceptionX  s    
z"StreamTests.test___repr__exceptionc                 C   sb   t j| jd}t j| jd|_| t|d |jd  | j|j d |_| 	dt| d S )NrB   z,<StreamReader waiter=<Future pending[\S ]*>>r	  )
r   r   r   Futurer   ZassertRegexr  
set_resultr,   r/   rU   r   r   r   test___repr__waiter_  s    zStreamTests.test___repr__waiterc                 C   sB   t j| jd}t |_t |j_d|jj_| dt	| d S )NrB   z<Transport>z$<StreamReader transport=<Transport>>)
r   r   r   r   r   Z
_transport__repr__r   r/   r  rU   r   r   r   test___repr__transportj  s
    

z"StreamTests.test___repr__transportc              	   C   s   t dd}ttjd D ]x}| j|dX ttj||d}| t	|t	| | |j
|j
 | |j|j W d    q1 s0    Y  qd S )Ns   abc
   r   Zpickle_protocolr   )r   r   rangepickleHIGHEST_PROTOCOLsubTestloadsdumpsr/   r   r   r   r   eprotoe2r   r   r   #test_IncompleteReadError_pickleableq  s    z/StreamTests.test_IncompleteReadError_pickleablec              	   C   s   t dd}ttjd D ]h}| j|dH ttj||d}| t	|t	| | |j
|j
 W d    q1 sx0    Y  qd S )Nr   r  r   r  r   )r   r   r  r  r  r  r  r  r/   r   consumedr  r   r   r   !test_LimitOverrunError_pickleablez  s    z-StreamTests.test_LimitOverrunError_pickleablec              	   C   s   t  }| t0 | jtj|jd| ji\}}W d    n1 sJ0    Y  |	d |
 }| j|}| |d | }| j|}| |d | |  |  | |  | j|  W d    n1 s0    Y  d S )Nr   r&   r'   r(   )r   r;   r*   r+   r   r,   r   r<   r=   r-   r.   r/   r0   r1   r2   r   Z
is_closingr   r   r   r?   rdwrr7   r8   r   r   r   test_wait_closed_on_close  s     
&
z%StreamTests.test_wait_closed_on_closec              	   C   s   t  }| t0 | jtj|jd| ji\}}W d    n1 sJ0    Y  |	d |
 }| j|}| |d |  | j|  W d    n1 s0    Y  d S )Nr   r&   r'   )r   r;   r*   r+   r   r,   r   r<   r=   r-   r.   r/   r   r   r&  r   r   r   *test_wait_closed_on_close_with_unread_data  s    
&
z6StreamTests.test_wait_closed_on_close_with_unread_datac                    sl   fdd}g  j  fdd t  }j || W d    n1 sR0    Y   g  d S )Nc                    sr   t j| j I d H \}}|d | I d H } |d | I d H } |d |	  |
 I d H  d S )Nr&   r'   r(   )r   r<   r=   r-   r.   r/   r0   r1   r2   r   r   r?   r'  r(  r8   r   r   r   inner  s    
z0StreamTests.test_async_writer_api.<locals>.innerc                    s
     |S r   r   r    r"   r   r   r$     r%   z3StreamTests.test_async_writer_api.<locals>.<lambda>r   r)   r   r;   r,   r/   r   r,  r?   r   r   r   test_async_writer_api  s    
.z!StreamTests.test_async_writer_apic                    sl   fdd}g  j  fdd t  }j || W d    n1 sR0    Y   g  d S )Nc                    s   t j| j I d H \}}|d | I d H } |d | I d H } |d |	   
t( |d | I d H  W d    n1 s0    Y  d S )Nr&   r'   r(   r   )r   r<   r=   r-   r.   r/   r0   r1   r2   r   rN   r  r   r+  r   r   r   r,    s    

zFStreamTests.test_async_writer_api_exception_after_close.<locals>.innerc                    s
     |S r   r   r    r"   r   r   r$     r%   zIStreamTests.test_async_writer_api_exception_after_close.<locals>.<lambda>r-  r.  r   r   r   +test_async_writer_api_exception_after_close  s    
.z7StreamTests.test_async_writer_api_exception_after_closec              	      s   g  | j  fdd t }| t0 | j tj|j	d| j i\}}W d    n1 sb0    Y  |
  | }| j | | sJ | }| j |}|dksJ W d    n1 s0    Y  |  g  d S )Nc                    s
     |S r   r   r    r"   r   r   r$     r%   z?StreamTests.test_eof_feed_when_closing_writer.<locals>.<lambda>r   r%   )r   r)   r   r;   r*   r+   r,   r   r<   r=   r   r   r   r0   r/   r&  r   r"   r   !test_eof_feed_when_closing_writer  s"    

&*z-StreamTests.test_eof_feed_when_closing_writer)Nr   r   r   rW   r   r   r   Zpatchr   r9   r@   r   Zskip_unless_bind_unix_socketrE   rF   unittestZskipIfrH   rJ   rL   rO   rP   rQ   rV   rX   rZ   rb   re   ri   rm   rt   rx   r{   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   platformr   r   r   r  r  r  r  r  r  r  r  r#  r%  r)  r*  r/  r0  r1  __classcell__r   r   r   r   r
      s   


	

	/#L
K
'	
-	r
   __main__)__doc__r   r   r   r  r   r   r   r2  r   Ztest.supportr   rH   ImportErrorr   Ztest.test_asyncior   r   r	   ZTestCaser
   r   mainr   r   r   r   <module>   s6   
       N