Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/test_asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/test_asyncio/__pycache__/test_futures.cpython-34.pyc

�
f f�@�@sdZddlZddlZddlZddlZddlZddlmZddlZddlm	Z	yddl
mZWn"ek
r�ddlm
ZYnXdd�Zd	d
�Zdd�ZGd
d�de	j�ZGdd�de	j�Zedkrej�ndS)zTests for futures.py.�N)�mock)�
test_utils)�support)�test_supportcCs|S)N�)�frr�C/opt/alt/python34/lib64/python3.4/test/test_asyncio/test_futures.py�	_fakefuncsr	cCsdS)Nrrrrr�first_cbsr
cCsdS)Nrrrrr�last_cbsrc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zejd�dd��Zejd�dd��Zejd�dd��Zejd�d d!��Zejd�d"d#��Zejd�d$d%��Zd&d'�Zd(d)�Zejd*�d+d,��Zd-d.�Zd/d0�Zd1d2�Zejd�d3d4��Zd5d6�Zd7d8�Zd9d:�Z d;S)<�FutureTestscCs&|j�|_|j|jj�dS)N)�
new_test_loop�loopZ
addCleanup�close)�selfrrr�setUpszFutureTests.setUpcCs\tjd|j�}|j|j��|j|j��|j�|j|j��dS)Nr)�asyncio�Futurer�assertFalse�	cancelled�done�cancel�
assertTrue)rrrrr�test_initial_state"s

zFutureTests.test_initial_statecCs6tj|j�tj�}|j|j|j�dS)N)rZset_event_looprr�assertIs�_loop)rrrrr�"test_init_constructor_default_loop)sz.FutureTests.test_init_constructor_default_loopcCs|jttjd�dS)N�*)�assertRaises�	TypeErrorrr)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)rrrrrrrrZCancelledError�result�	exception�InvalidStateError�
set_result�
set_exceptionr)rrrrr�test_cancel2szFutureTests.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)Nrr)rrrrr#r!r$rrrr�assertEqualr"r%r)rrrrr�test_result=s
zFutureTests.test_resultcCs�t�}tjd|j�}|jtj|j�|j|�|j|j	��|j
|j��|jt|j�|j
|j�|�|jtj|jd�|jtj|jd�|j|j��dS)Nr)�RuntimeErrorrrrrr#r"r%rrrrr!r'r$r)r�excrrrr�test_exceptionJs	
zFutureTests.test_exceptioncCs<tjd|j�}|jt�|j|j�t�dS)Nr)rrrr%r)�assertIsInstancer")rrrrr�test_exception_classXs
z FutureTests.test_exception_classcs�tjd|j���fdd�}|�}|jt|�d�|jt|����jd�|jt|�d�|jt|�d	�dS)
Nrc3s5dV�DdH}d|fV�DdH}d|fVdS)N�A�B�Cr)�x�y)rrr�fixture`s
z2FutureTests.test_yield_from_twice.<locals>.fixturer.rr/r0)r/r)r0r)rrrr'�nextr$)rr3�gr)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�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_source�__qualname__�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_debugrr�_source_tracebackr'�reprrr$r!r)r%rr"�add_done_callbackr	�assertRegexr
r�range)rZf_pending_debug�frameZ	f_pending�f_cancelledZf_resultr*�f_exceptionr@Zf_one_callbacksZ	fake_reprZf_two_callbacksZ
first_reprZ	last_reprZf_many_callbacks�iZcb_regexrrr�test_future_reprosh




	







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.futuresrNrrrr$rrr'r!r%r)rrr)rrNrZnewfrKZnewf_exceptionrJZnewf_cancelledrrr�test_copy_state�s$




zFutureTests.test_copy_statecsWtjd|j���fdd���fdd�}|jt|��j�dS)Nrc3s
�DdHdS)Nrr)�futrr�coro�sz#FutureTests.test_iter.<locals>.corocs��\}}dS)Nr)Zarg1Zarg2)rRrr�test�sz#FutureTests.test_iter.<locals>.test)rrrr�AssertionErrorr)rrSr)rRrQr�	test_iter�s
zFutureTests.test_iterzasyncio.base_events.loggercCs/tjd|j�}~|j|jj�dS)Nr)rrrr�error�called)r�m_logrQrrr�test_tb_logger_abandoned�sz$FutureTests.test_tb_logger_abandonedcCs<tjd|j�}|jd�~|j|jj�dS)Nrr)rrrr$rrVrW)rrXrQrrr�!test_tb_logger_result_unretrieved�s
z-FutureTests.test_tb_logger_result_unretrievedcCsFtjd|j�}|jd�|j�~|j|jj�dS)Nrr)rrrr$r!rrVrW)rrXrQrrr�test_tb_logger_result_retrieved�s


z+FutureTests.test_tb_logger_result_retrievedcCsRtjd|j�}|jtd��~tj|j�|j|jj	�dS)Nr�boom)
rrrr%r)r�run_brieflyrrVrW)rrXrQrrr�$test_tb_logger_exception_unretrieved�s
z0FutureTests.test_tb_logger_exception_unretrievedcCsLtjd|j�}|jtd��|j�~|j|jj�dS)Nrr\)	rrrr%r)r"rrVrW)rrXrQrrr�"test_tb_logger_exception_retrieved�s

z.FutureTests.test_tb_logger_exception_retrievedcCsUtjd|j�}|jtd��|jt|j�~|j|jj	�dS)Nrr\)
rrrr%r)rr!rrVrW)rrXrQrrr�)test_tb_logger_exception_result_retrieved�s
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�runsz)FutureTests.test_wrap_future.<locals>.runr7�oir)�
concurrent�futures�ThreadPoolExecutor�submitr�wrap_futurerZrun_until_completer,rr'ZassertNotEqualrarb)rrd�ex�f1�f2�resZidentrrr�test_wrap_futureszFutureTests.test_wrap_futurecCs8tjd|j�}tj|�}|j||�dS)Nr)rrrrjr)rrlrmrrr�test_wrap_future_futuresz#FutureTests.test_wrap_future_futurezasyncio.futures.eventscCs\dd�}tjjd�}|j|d�}tj|�}|j|jj|j	�dS)NcSs|tj�fS)N)rarb)rcrrrrdsz9FutureTests.test_wrap_future_use_global_loop.<locals>.runr7re)
rfrgrhrirrjrZget_event_loopZreturn_valuer)rZm_eventsrdrkrlrmrrr� test_wrap_future_use_global_loops
z,FutureTests.test_wrap_future_use_global_loopcCsktjj�}tj|d|j�}|j�tj|j�|j	|j
��|j	|j
��dS)Nr)rfrgrrrjrrrr]rr)rrlrmrrr�test_wrap_future_cancels
z#FutureTests.test_wrap_future_cancelcCs�tjj�}tj|d|j�}|jd�|j�tj	|j�|j
|j��|j|j
�d�|j|j��dS)Nrr)rfrgrrrjrr$rrr]rrr'r!r)rrlrmrrr�test_wrap_future_cancel2%s

z$FutureTests.test_wrap_future_cancel2cCsy|jjd�tjd|j�}tj�jd}|j|jt	�|j
|jddd�t|df�dS)NTrr7��test_future_source_tracebackrB)rrCrr�sys�	_getframe�f_linenor,rD�listr'�__file__)r�futurer>rrrru/sz(FutureTests.test_future_source_tracebackcCs�|jj|�dd�}|�}tjd|j�}|rL|j}n|j|�d}tj|j�tj	�t
jdkr�|r�|d}djdt
j|d	�d
|d�}nd}t|�||jf}	|jjtjd|	�n[|r:|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_errorrrtr8r7aD^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\)$r=rr>z[^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)rtr8rBrB)rrCrrrDr%rr]rZ
gc_collectrv�version_info�formatr:r;�type�
__traceback__rVZassert_called_once_withr�ANY�	call_argsrG�compile�DOTALL)r�debugrXr~r*r{Zsource_tracebackrIZregexr�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_debugsz7FutureTests.test_future_exception_never_retrieved_debugcCsVddlm}tjd|j�}|j�|j|d�|j|j��dS)Nr)rgr�)rrgrrrZ_set_result_unless_cancelledrr)rrgrQrrr� test_set_result_unless_cancelled�s

z,FutureTests.test_set_result_unless_cancelledN)!�__name__�
__module__r9rrrr r&r(r+r-r6rMrPrUrZpatchrYrZr[r^r_r`rorprqrrrsrur�r�r�r�rrrrrs8
A	
Brc@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�FutureDoneCallbackTestscCs|j�|_dS)N)r
r)rrrrr�szFutureDoneCallbackTests.setUpcCstj|j�dS)N)rr]r)rrrrr]�sz#FutureDoneCallbackTests.run_brieflycs��fdd�}|S)Ncs�j��dS)N)�append)r{)�bag�thingrr�bag_appender�sz<FutureDoneCallbackTests._make_callback.<locals>.bag_appenderr)rr�r�r�r)r�r�r�_make_callback�sz&FutureDoneCallbackTests._make_callbackcCstjd|j�S)Nr)rrr)rrrr�_new_future�sz#FutureDoneCallbackTests._new_futurecCs�g}|j�}|j|j|d��|j|j|d��|j|g�|jd�|j�|j|ddg�|j|j�d�dS)Nr��foo)r�rFr�r'r$r]r!)rr�rrrr�$test_callbacks_invoked_on_set_result�s

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�rFr�r'r)r%r]r")rr�rr*rrr�'test_callbacks_invoked_on_set_exception�s	

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)Nr7r�rtr��r�)	r�r�rFr'Zremove_done_callbackrHr$r]r!)rr�rZcb1Zcb2Zcb3rLrrr�test_remove_done_callback�s$




z1FutureDoneCallbackTests.test_remove_done_callbackN)
r�r�r9rr]r�r�r�r�r�rrrrr��sr��__main__)�__doc__Zconcurrent.futuresrfr:rvraZunittestrrrrSr�ImportErrorrr	r
rZTestCaserr�r��mainrrrr�<module>s(
�oO