Your IP : 216.73.216.213


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

�
f f��@s�dZddladdlZddlZddlZddlZddlmZda	Gdd�dej
�ZGdd�dej
�ZGdd	�d	ej
�Z
dd
d�Zedkr�e�ndS)
z�Generic thread tests.

Meant to be used by dummy_thread and thread.  To allow for different modules
to be used, test_main() can be called with the module to use as the thread
implementation as its sole argument.

�N)�supportc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�	LockTestszTest lock objects.cCstj�|_dS)N)�_thread�
allocate_lock�lock)�self�r�;/opt/alt/python34/lib64/python3.4/test/test_dummy_thread.py�setUpszLockTests.setUpcCs|j|jj�d�dS)Nz(Lock object is not initialized unlocked.)�
assertTruer�locked)rrrr	�
test_initlockszLockTests.test_initlockcCs8|jj�|jj�|j|jj�d�dS)Nz%Lock object did not release properly.)r�acquire�releaserr)rrrr	�test_releases

zLockTests.test_releasecCs|jt|jj�dS)N)�assertRaises�RuntimeErrorrr)rrrr	�test_improper_release%szLockTests.test_improper_releasecCs |j|jjd�d�dS)Nrz)Conditional acquiring of the lock failed.)rrr)rrrr	�test_cond_acquire_success)sz#LockTests.test_cond_acquire_successcCs1|jjd�|j|jjd�d�dS)Nrz=Conditional acquiring of a locked lock incorrectly succeeded.)rrr)rrrr	�test_cond_acquire_fail.sz LockTests.test_cond_acquire_failcCs*|jj�|j|jj�d�dS)NzUncondional locking failed.)rrrr)rrrr	�test_uncond_acquire_success5s
z%LockTests.test_uncond_acquire_successcCsB|j|jjd�dkd�|j|jj�dk�dS)N�Tz*Unconditional locking did not return True.)rrr)rrrr	�test_uncond_acquire_return_val;sz(LockTests.test_uncond_acquire_return_valcCs�dd�}|jj�ttj��}tj||jtf�tjret	�t	dt�n|jj�ttj��}tjr�t	d�n|j
||tkd�dS)NcSstj|�|j�dS)z:Hold on to lock for a set amount of time before unlocking.N)�time�sleepr)Z	to_unlock�delayrrr	�delay_unlockCs
z<LockTests.test_uncond_acquire_blocking.<locals>.delay_unlockz@*** Waiting for thread to release the lock (approx. %s sec.) ***�donez+Blocking by unconditional acquiring failed.)rr�intrr�start_new_thread�DELAYr�verbose�printr)rrZ
start_timeZend_timerrr	�test_uncond_acquire_blockingAs
	
	
z&LockTests.test_uncond_acquire_blockingN)
�__name__�
__module__�__qualname__�__doc__r
r
rrrrrrr#rrrr	rsrc@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�	MiscTestszMiscellaneous tests.cCs|jttj�dS)N)r�
SystemExitr�exit)rrrr	�	test_exitYszMiscTests.test_exitcCs9|jtj�td�|jtj�dkd�dS)Nz*_thread.get_ident() returned a non-integerrz_thread.get_ident() returned 0)�assertIsInstancer�	get_identrr)rrrr	�
test_ident]szMiscTests.test_identcCs |jtj�tjd�dS)NzR_thread.LockType is not an instance of what is returned by _thread.allocate_lock())r,rr�LockType)rrrr	�
test_LockTypedszMiscTests.test_LockTypecCs,dd�}|jttj|t��dS)NcSstj�dS)N)r�interrupt_mainrrrr	�call_interruptmsz5MiscTests.test_interrupt_main.<locals>.call_interrupt)r�KeyboardInterruptrr�tuple)rr2rrr	�test_interrupt_mainjszMiscTests.test_interrupt_maincCs|jttj�dS)N)rr3rr1)rrrr	�test_interrupt_in_mainrsz MiscTests.test_interrupt_in_mainN)	r$r%r&r'r+r.r0r5r6rrrr	r(Vsr(c@s.eZdZdZdd�Zdd�ZdS)�ThreadTestszTest thread creation.cCsdddd�}tjd�}tj||ddf�|j�}|j|do]|dd�tj|t�i|d6dd	6dd
6�|j�}|j|do�|dd�tj||dfidd
6�|j�}|j|do�|dd�dS)
NFcSs|j||f�dS)z<Use to test _thread.start_new_thread() passes args properly.N)�put)�queue�arg1�arg2rrr	�
arg_tester|sz0ThreadTests.test_arg_passing.<locals>.arg_testerrTrz7Argument passing for thread creation using tuple failedr9r:r;z8Argument passing for thread creation using kwargs failedzGArgument passing for thread creation using both tuple and kwargs failed)r9�Queuerr�getrr4)rr<�
testing_queue�resultrrr	�test_arg_passingzs zThreadTests.test_arg_passingcCs�dd�}d}tj|�}tjrHt�tdt|f�nxNt|�D]@}tryttj�d�}nd}t	j
|||f�qUWtjt�tjr�td�n|j
|j�|kd|tf�dS)	NcSs$tj|�|jtj��dS)z@Wait for ``delay`` seconds and then put something into ``queue``N)rrr8rr-)r9rrrr	�
queue_mark�s
z3ThreadTests.test_multi_creation.<locals>.queue_mark�zJ*** Testing multiple thread creation (will take approx. %s to %s sec.) ***rrrz2Not all %s threads executed properly after %s sec.)r9r=rr!r"r �range�round�randomrrrrrZqsize)rrBZthread_countr?�countZlocal_delayrrr	�test_multi_creation�s&		
	
zThreadTests.test_multi_creationN)r$r%r&r'rArHrrrr	r7wsr7cCsM|r|adantjr6t�tdt�ntjttt�dS)N�z"*** Using %s as _thread module ***)	rr rr!r"Zrun_unittestrr(r7)Zimported_modulerrr	�	test_main�s		rJ�__main__)r'Z
_dummy_threadrrr9rFZunittestZtestrr ZTestCaserr(r7rJr$rrrr	�<module>sD!4