Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/test_asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/test_asyncio/__pycache__/test_futures.cpython-35.opt-1.pyc



��Yf�L�@sCdZddlZddlZddlZddlZddlZddlmZddlZddlm	Z	yddl
mZWn"ek
r�ddlm
ZYnXdd�Zd	d
�Zdd�ZGd
d�d�ZGdd�de	j�ZGdd�de	j�ZGdd�de	j�Zedkr?ej�dS)zTests for futures.py.�N)�mock)�
test_utils)�support)�test_supportcCs|S)N�)�frr�C/opt/alt/python35/lib64/python3.5/test/test_asyncio/test_futures.py�	_fakefuncsr	cCsdS)Nrrrrr�first_cbsr
cCsdS)Nrrrrr�last_cbsrc@s�eZdZdZdZdZdZdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�ZdS)�
DuckFutureFNcCs|j�rdSd|_dS)NFT)�done�_DuckFuture__cancelled)�selfrrr�cancel%s	zDuckFuture.cancelcCs|jS)N)r)rrrr�	cancelled+szDuckFuture.cancelledcCs%|jp$|jdk	p$|jdk	S)N)r�_DuckFuture__result�_DuckFuture__exception)rrrrr
.s	zDuckFuture.donecCs|jdk	r|j�|jS)N)rr)rrrr�result3s	zDuckFuture.resultcCs|jS)N)r)rrrr�	exception9szDuckFuture.exceptioncCs
||_dS)N)r)rrrrr�
set_result=szDuckFuture.set_resultcCs
||_dS)N)r)rrrrr�
set_exceptionBszDuckFuture.set_exceptionccs$|j�sd|_|V|j�S)NT)r
�_asyncio_future_blockingr)rrrr�__iter__Gs	zDuckFuture.__iter__)�__name__�
__module__�__qualname__rrrrrrr
rrrrrrrrrrsrcs:eZdZ�fdd�Zdd�Zdd�Z�S)�	DuckTestscs3t�j�|j�|_|j|jj�dS)N)�super�setUp�
new_test_loop�loop�
addCleanup�close)r)�	__class__rrrQs
zDuckTests.setUpcCst�}tj|�}dS)N)r�asyncio�wrap_future)rr�grrr�test_wrap_futureVs	zDuckTests.test_wrap_futurecCst�}tj|�}dS)N)rr%Z
ensure_future)rrr'rrr�test_ensure_future[s	zDuckTests.test_ensure_future)rrrrr(r)rr)r$rrOsrcs�eZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zejd�dd��Zejd�dd��Zejd�d d!��Zejd�d"d#��Zejd�d$d%��Zejd�d&d'��Zejd�d(d)��Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zejd�d6d7��Zd8d9�Z d:d;�Z!d<d=�Z"�S)>�FutureTestscs3t�j�|j�|_|j|jj�dS)N)rrr r!r"r#)r)r$rrrcs
zFutureTests.setUpcCs�Gdd�d�}|jtj|��|jtj|���|jtjd��|jtjtj��|jtjtj���|jtjtjtj���tjd|j�}|jtj|��|j�dS)Nc@s"eZdZdZdd�ZdS)z+FutureTests.test_isfuture.<locals>.MyFutureNcSs
d|_dS)NF)r)rrrr�__init__lsz4FutureTests.test_isfuture.<locals>.MyFuture.__init__)rrrrr+rrrr�MyFutureisr,�r!)	�assertFalser%Zisfuture�
assertTrue�FuturerZMockr!r)rr,rrrr�
test_isfuturehs"zFutureTests.test_isfuturecCs\tjd|j�}|j|j��|j|j��|j�|j|j��dS)Nr!)r%r0r!r.rr
rr/)rrrrr�test_initial_states

zFutureTests.test_initial_statecCs6tj|j�tj�}|j|j|j�dS)N)r%Zset_event_loopr!r0�assertIs�_loop)rrrrr�"test_init_constructor_default_loop�sz.FutureTests.test_init_constructor_default_loopcCs|jttjd�dS)N�*)�assertRaises�	TypeErrorr%r0)rrrr�test_constructor_positional�sz'FutureTests.test_constructor_positionalcCs�tjd|j�}|j|j��|j|j��|j|j��|jtj|j	�|jtj|j
�|jtj|jd�|jtj|j
d�|j|j��dS)Nr!)r%r0r!r/rrr
r7ZCancelledErrorrr�InvalidStateErrorrrr.)rrrrr�test_cancel�szFutureTests.test_cancelcCs�tjd|j�}|jtj|j�|jd�|j|j��|j	|j
��|j|j�d�|j|j�d�|jtj|jd�|jtj|j
d�|j|j��dS)Nr!r6)r%r0r!r7r:rrr.rr/r
�assertEqualrrr)rrrrr�test_result�s
zFutureTests.test_resultcCs�t�}tjd|j�}|jtj|j�|jtd|j	t
�|j	|�|j|j��|j
|j��|jt|j�|j|j�|�|jtj|jd�|jtj|j	d�|j|j��dS)Nr!z!StopIteration .* cannot be raised)�RuntimeErrorr%r0r!r7r:rZassertRaisesRegexr8r�
StopIterationr.rr/r
rr<rr)r�excrrrr�test_exception�s	

zFutureTests.test_exceptioncCs<tjd|j�}|jt�|j|j�t�dS)Nr!)r%r0r!rr>�assertIsInstancer)rrrrr�test_exception_class�s
z FutureTests.test_exception_classcs�tjd|j���fdd�}|�}|jt|�d�|jt|����jd�|jt|�d�|jt|�d	�dS)
Nr!c3s5dV�EdH}d|fV�EdH}d|fVdS)N�A�B�Cr)�x�y)rrr�fixture�s
z2FutureTests.test_yield_from_twice.<locals>.fixturerDr6rErF)rEr6)rFr6)r%r0r!r<�nextr)rrIr'r)rr�test_yield_from_twice�s	
z!FutureTests.test_yield_from_twicecCs�|jjd�tjd|j�}|jd}|jt|�d|d|df�|j�|jjd�tjd|j�}|jt|�d�|j�tjd|j�}|j�|jt|�d�tjd|j�}|jd	�|jt|�d
�|j|j	�d	�t
�}tjd|j�}|j|�|jt|�d�|j|j
�|�dd
�}tjd|j�}	|	jt�|t�}
|jt|	�d|
�|	j�|jt|	�d�tjd|j�}|jt�|jt�|t�}|t�}
|jt|�d||
f�tjd|j�}|jt�x!td�D]}|jt�q�W|jt�d||
f}|jt|�d|�|j�|jt|�d�dS)NTr!r-z!<Future pending created at %s:%s>rFz<Future pending>z<Future cancelled>�z<Future finished result=4>z*<Future finished exception=RuntimeError()>cSs8tj|�\}}d|j||f}tj|�S)Nz
%s() at %s:%s)rZget_function_sourcer�re�escape)�func�filename�lineno�textrrr�	func_repr�sz/FutureTests.test_future_repr.<locals>.func_reprz<Future pending cb=\[%s\]>z<Future pending cb=\[%s, %s\]>�z%s, <8 more>, %s���)r!�	set_debugr%r0�_source_tracebackr<�reprrrrr>rr3r�add_done_callbackr	�assertRegexr
r�range)rZf_pending_debug�frameZ	f_pending�f_cancelledZf_resultr@�f_exceptionrSZf_one_callbacksZ	fake_reprZf_two_callbacksZ
first_reprZ	last_reprZf_many_callbacks�iZcb_regexrrr�test_future_repr�sh




	







zFutureTests.test_future_reprcCsBddlm}tjd|j�}|jd�tjd|j�}|||�|j|j��|j|j	�d�tjd|j�}|j
t��tjd|j�}|||�|j|j��|jt|j	�tjd|j�}|j
�tjd|j�}|||�|j|j��dS)Nr)�_copy_future_stater!�
)Zasyncio.futuresrar%r0r!rr/r
r<rrr>r7rr)rrarZnewfr^Znewf_exceptionr]Znewf_cancelledrrr�test_copy_states$




zFutureTests.test_copy_statecsWtjd|j���fdd���fdd�}|jt|��j�dS)Nr!c3s
�EdHdS)Nrr)�futrr�coro.sz#FutureTests.test_iter.<locals>.corocs��\}}dS)Nr)Zarg1Zarg2)rerr�test1sz#FutureTests.test_iter.<locals>.test)r%r0r!r7�AssertionErrorr)rrfr)rerdr�	test_iter+s
zFutureTests.test_iterzasyncio.base_events.loggercCs/tjd|j�}~|j|jj�dS)Nr!)r%r0r!r.�error�called)r�m_logrdrrr�test_tb_logger_abandoned7sz$FutureTests.test_tb_logger_abandonedcCsItjd|j�}|jt��|j�~|j|jj�dS)Nr!)	r%r0r!r�	Exceptionrr.rirj)rrkrdrrr�&test_tb_logger_not_called_after_cancel=s

z2FutureTests.test_tb_logger_not_called_after_cancelcCs<tjd|j�}|jd�~|j|jj�dS)Nr!r6)r%r0r!rr.rirj)rrkrdrrr�!test_tb_logger_result_unretrievedEs
z-FutureTests.test_tb_logger_result_unretrievedcCsFtjd|j�}|jd�|j�~|j|jj�dS)Nr!r6)r%r0r!rrr.rirj)rrkrdrrr�test_tb_logger_result_retrievedLs


z+FutureTests.test_tb_logger_result_retrievedcCs\tjd|j�}|jtd��~tj|j�tj�|j	|j
j�dS)Nr!�boom)r%r0r!rr>r�run_brieflyr�
gc_collectr/rirj)rrkrdrrr�$test_tb_logger_exception_unretrievedTs
z0FutureTests.test_tb_logger_exception_unretrievedcCsLtjd|j�}|jtd��|j�~|j|jj�dS)Nr!rq)	r%r0r!rr>rr.rirj)rrkrdrrr�"test_tb_logger_exception_retrieved]s

z.FutureTests.test_tb_logger_exception_retrievedcCsUtjd|j�}|jtd��|jt|j�~|j|jj	�dS)Nr!rq)
r%r0r!rr>r7rr.rirj)rrkrdrrr�)test_tb_logger_exception_result_retrievedes
z5FutureTests.test_tb_logger_exception_result_retrievedcCs�dd�}tjjd�}|j|d�}tj|d|j�}|jj|�\}}|j|tj	�|j
|d�|j|tj
��dS)NcSs|tj�fS)N)�	threading�	get_ident)�argrrr�runosz)FutureTests.test_wrap_future.<locals>.runr-�oir!)�
concurrent�futures�ThreadPoolExecutor�submitr%r&r!Zrun_until_completerBr0r<ZassertNotEqualrwrx)rrz�ex�f1�f2�resZidentrrrr(mszFutureTests.test_wrap_futurecCs8tjd|j�}tj|�}|j||�dS)Nr!)r%r0r!r&r3)rr�r�rrr�test_wrap_future_futureysz#FutureTests.test_wrap_future_futurec
s�tjd��q}�fdd�|_dd�}tjjd�}|j|d�}tj|�}�j	�j
|j�WdQRXdS)Nzasyncio.futures.eventscs�jS)N)r!r)rrr�<lambda>�sz>FutureTests.test_wrap_future_use_global_loop.<locals>.<lambda>cSs|tj�fS)N)rwrx)ryrrrrz�sz9FutureTests.test_wrap_future_use_global_loop.<locals>.runr-r{)r�patchZget_event_loopr|r}r~rr%r&r3r!r4)rZeventsrzr�r�r�r)rr� test_wrap_future_use_global_loop~sz,FutureTests.test_wrap_future_use_global_loopcCsktjj�}tj|d|j�}|j�tj|j�|j	|j
��|j	|j
��dS)Nr!)r|r}r0r%r&r!rrrrr/r)rr�r�rrr�test_wrap_future_cancel�s
z#FutureTests.test_wrap_future_cancelcCs�tjj�}tj|d|j�}|jd�|j�tj	|j�|j
|j��|j|j
�d�|j|j��dS)Nr!r6)r|r}r0r%r&r!rrrrrr.rr<rr/)rr�r�rrr�test_wrap_future_cancel2�s

z$FutureTests.test_wrap_future_cancel2cCsy|jjd�tjd|j�}tj�jd}|j|jt	�|j
|jddd�t|df�dS)NTr!r-��test_future_source_tracebackrU)r!rVr%r0�sys�	_getframe�f_linenorBrW�listr<�__file__)r�futurerQrrrr��sz(FutureTests.test_future_source_tracebackcCs�|jj|�dd�}|�}tjd|j�}|rI|j}|j|�d}tj|j�tj	�t
jdkr�|r�|d}djdt
j|d	�d
|d�}nd}t|�||jf}	|jjtjd|	�n[|r7|d}d
jdt
j|d	�d
|d�}nd}|jjtjdd�|jjd	d	}
|j|
t
j|t
j��dS)NcSs=y
t��Wn)tk
r8}z	|SWYdd}~XnXdS)N)�MemoryError�
BaseException)r@rrr�memory_error�s
zHFutureTests.check_future_exception_never_retrieved.<locals>.memory_errorr!r�rLr-aD^Future exception was never retrieved\nfuture: <Future finished exception=MemoryError\(\) created at {filename}:{lineno}>\nsource_traceback: Object created at \(most recent call last\):\n  File.*\n  File "{filename}", line {lineno}, in check_future_exception_never_retrieved\n    future = asyncio\.Future\(loop=self\.loop\)$rPrrQz[^Future exception was never retrieved\nfuture: <Future finished exception=MemoryError\(\)>$�exc_infoa^Future/Task exception was never retrieved\nFuture/Task created at \(most recent call last\):\n  File.*\n  File "{filename}", line {lineno}, in check_future_exception_never_retrieved\n    future = asyncio\.Future\(loop=self\.loop\)\nTraceback \(most recent call last\):\n.*\nMemoryError$zb^Future/Task exception was never retrieved\nTraceback \(most recent call last\):\n.*\nMemoryError$F)r�rLrUrU)r!rVr%r0rWrrrrrrsr��version_info�formatrMrN�type�
__traceback__riZassert_called_once_withr�ANY�	call_argsrZ�compile�DOTALL)r�debugrkr�r@r�Zsource_tracebackr\Zregexr��messagerrr�&check_future_exception_never_retrieved�s8		


	

	
z2FutureTests.check_future_exception_never_retrievedcCs|jd�dS)NF)r�)rrrr�%test_future_exception_never_retrieved�sz1FutureTests.test_future_exception_never_retrievedcCs|jd�dS)NT)r�)rrrr�+test_future_exception_never_retrieved_debug�sz7FutureTests.test_future_exception_never_retrieved_debugcCsVddlm}tjd|j�}|j�|j|d�|j|j��dS)Nr)r}r!�)r%r}r0r!rZ_set_result_unless_cancelledr/r)rr}rdrrr� test_set_result_unless_cancelled�s

z,FutureTests.test_set_result_unless_cancelled)#rrrrr1r2r5r9r;r=rArCrKr`rcrhrr�rlrnrorprtrurvr(r�r�r�r�r�r�r�r�r�rr)r$rr*as<
A	

Br*csjeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	�S)�FutureDoneCallbackTestscs t�j�|j�|_dS)N)rrr r!)r)r$rrr�s
zFutureDoneCallbackTests.setUpcCstj|j�dS)N)rrrr!)rrrrrr�sz#FutureDoneCallbackTests.run_brieflycs��fdd�}|S)Ncs�j��dS)N)�append)r�)�bag�thingrr�bag_appendersz<FutureDoneCallbackTests._make_callback.<locals>.bag_appenderr)rr�r�r�r)r�r�r�_make_callback�sz&FutureDoneCallbackTests._make_callbackcCstjd|j�S)Nr!)r%r0r!)rrrr�_new_futuresz#FutureDoneCallbackTests._new_futurecCs�g}|j�}|j|j|d��|j|j|d��|j|g�|jd�|j�|j|ddg�|j|j�d�dS)Nr6��foo)r�rYr�r<rrrr)rr�rrrr�$test_callbacks_invoked_on_set_results

z<FutureDoneCallbackTests.test_callbacks_invoked_on_set_resultcCs�g}|j�}|j|j|d��|j|g�t�}|j|�|j�|j|dg�|j|j�|�dS)N�d)r�rYr�r<r>rrrr)rr�rr@rrr�'test_callbacks_invoked_on_set_exceptions	

z?FutureDoneCallbackTests.test_callbacks_invoked_on_set_exceptioncCs2g}|j�}|j|d�}|j|d�}|j|d�}|j|�|j|�|j|j|�d�|j|j|�d�|j|�x!td�D]}|j|�q�W|j|j|�d�|j|g�|jd�|j�|j|dg�|j|j�d�dS)Nr-r�r�r��r�)	r�r�rYr<Zremove_done_callbackr[rrrr)rr�rZcb1Zcb2Zcb3r_rrr�test_remove_done_callback#s$




z1FutureDoneCallbackTests.test_remove_done_callback)
rrrrrrr�r�r�r�r�rr)r$rr��sr��__main__)�__doc__Zconcurrent.futuresr|rMr�rwZunittestrr%rrfr�ImportErrorrr	r
rrZTestCaserr*r�r�mainrrrr�<module>s,
3��P