Your IP : 216.73.216.85


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



��Yf�$�@s�ddlZddlZddlZddlZddlZddlmZddlmZdZ	Gdd�dej
�ZGdd�dej
�ZGdd	�d	ej
�Z
dS)
�N)�support)�mockc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
ejd�dd��Zdd�ZdS)�	LockTestszTest lock objects.cCstj�|_dS)N)�_thread�
allocate_lock�lock)�self�r	�;/opt/alt/python35/lib64/python3.5/test/test_dummy_thread.py�setUpszLockTests.setUpcCs|j|jj�d�dS)Nz(Lock object is not initialized unlocked.)�assertFalser�locked)rr	r	r
�
test_initlockszLockTests.test_initlockcCs7|jj�|jj�|j|jj�d�dS)Nz%Lock object did not release properly.)r�acquire�releaserr
)rr	r	r
�test_releases

zLockTests.test_releasec
Cs1tj��WdQRX|j|jj�d�dS)NzAcquired Lock was not released)r�LockTyperrr
)rr	r	r
�test_LockType_context_managers
z'LockTests.test_LockType_context_managercCs|jt|jj�dS)N)�assertRaises�RuntimeErrorrr)rr	r	r
�test_improper_release%szLockTests.test_improper_releasecCs |j|jjd�d�dS)Nrz)Conditional acquiring of the lock failed.)�
assertTruerr)rr	r	r
�test_cond_acquire_success)sz#LockTests.test_cond_acquire_successcCs0|jjd�|j|jjd�d�dS)Nrz=Conditional acquiring of a locked lock incorrectly succeeded.)rrr)rr	r	r
�test_cond_acquire_fail.sz LockTests.test_cond_acquire_failcCs*|jj�|j|jj�d�dS)NzUncondional locking failed.)rrrr
)rr	r	r
�test_uncond_acquire_success5s
z%LockTests.test_uncond_acquire_successcCs<|j|jjd�dd�|j|jj�d�dS)N�Tz*Unconditional locking did not return True.)ZassertIsrr)rr	r	r
�test_uncond_acquire_return_val;sz(LockTests.test_uncond_acquire_return_valcCs�dd�}|jj�ttj��}tj||jtf�tjrbt	�t	dt�|jj�ttj��}tjr�t	d�|j
||td�dS)NcSstj|�|j�dS)z:Hold on to lock for a set amount of time before unlocking.N)�time�sleepr)Z	to_unlock�delayr	r	r
�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�printZassertGreaterEqual)rr Z
start_timeZend_timer	r	r
�test_uncond_acquire_blockingAs
	
	
z&LockTests.test_uncond_acquire_blockingz
time.sleepcCsY|jj�|jjdddd�}|j|j�|jd�|j|d�dS)z�Test invoking acquire() with a positive timeout when the lock is
        already acquired. Ensure that time.sleep() is invoked with the given
        timeout and that False is returned.ZwaitflagrZtimeoutrFN)rrr�calledZassert_called_once_with�assertEqual)rZ
mock_sleep�retvalr	r	r
�test_acquire_timeoutVs


zLockTests.test_acquire_timeoutcCsP|jj�|jdt|j��|jj�|jdt|j��dS)Nr
Zunlocked)rrZassertIn�reprr)rr	r	r
�test_lock_representationbs

z"LockTests.test_lock_representationN)�__name__�
__module__�__qualname__�__doc__rrrrrrrrrr'r�patchr+r-r	r	r	r
rsrc@sveZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�	MiscTestszMiscellaneous tests.cCs|jttj�dS)N)r�
SystemExitr�exit)rr	r	r
�	test_exitlszMiscTests.test_exitcCs6|jtj�td�|jtj�dd�dS)Nz*_thread.get_ident() returned a non-integerrz_thread.get_ident() returned 0)�assertIsInstancer�	get_identr"ZassertNotEqual)rr	r	r
�
test_identoszMiscTests.test_identcCs |jtj�tjd�dS)NzR_thread.LockType is not an instance of what is returned by _thread.allocate_lock())r7rrr)rr	r	r
�
test_LockTypeuszMiscTests.test_LockTypecCs |jtj�tjd�dS)Nz;_thread._set_sentinel() did not return a LockType instance.)r7r�
_set_sentinelr)rr	r	r
�test_set_sentinelzszMiscTests.test_set_sentinelcCs,dd�}|jttj|t��dS)NcSstj�dS)N)r�interrupt_mainr	r	r	r
�call_interrupt�sz5MiscTests.test_interrupt_main.<locals>.call_interrupt)r�KeyboardInterruptrr#�tuple)rr>r	r	r
�test_interrupt_mains
	zMiscTests.test_interrupt_maincCs|jttj�dS)N)rr?rr=)rr	r	r
�test_interrupt_in_main�sz MiscTests.test_interrupt_in_maincCs#tjd�}|j|d�dS)Nr)r�
stack_sizer))rr*r	r	r
�test_stack_size_None�szMiscTests.test_stack_size_Nonec
CsG|jtj��}tjd�WdQRX|j|jjdd�dS)N�rz'setting thread stack size not supported)rr�errorrCr)�	exception�args)r�cmr	r	r
�test_stack_size_not_None�sz"MiscTests.test_stack_size_not_NoneN)r.r/r0r1r6r9r:r<rArBrDrJr	r	r	r
r3isr3c@smeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Ze	j
d�d
d��ZdS)�ThreadTestszTest thread creation.c	Csdddd�}tjd�}tj||ddf�|j�}|j|do]|dd�tj|t�d|d	dd
di�|j�}|j|do�|dd�tj||dfd
di�|j�}|j|do�|dd�dS)
NFcSs|j||f�dS)z<Use to test _thread.start_new_thread() passes args properly.N)�put)�queue�arg1�arg2r	r	r
�
arg_tester�sz0ThreadTests.test_arg_passing.<locals>.arg_testerrTrz7Argument passing for thread creation using tuple failedrMrNrOz8Argument passing for thread creation using kwargs failedzGArgument passing for thread creation using both tuple and kwargs failed)rM�Queuerr#�getrr@)rrP�
testing_queue�resultr	r	r
�test_arg_passing�s(	
zThreadTests.test_arg_passingcCs�dd�}d}tj|�}tjrEt�tdt|f�xNt|�D]@}trvttj�d�}nd}t	j
|||f�qRWtjt�tjr�td�|j
|j�|d|tf�dS)	NcSs$tj|�|jtj��dS)N)rrrLrr8)rMrr	r	r
�
queue_mark�s
z:ThreadTests.test_multi_thread_creation.<locals>.queue_mark�zJ*** Testing multiple thread creation (will take approx. %s to %s sec.) ***rrr!z2Not all %s threads executed properly after %s sec.)rMrQrr%r&r$�range�round�randomrr#rrr)Zqsize)rrVZthread_countrS�countZlocal_delayr	r	r
�test_multi_thread_creation�s&		
	
z&ThreadTests.test_multi_thread_creationc
CsM|jt��}tjtj�g�WdQRX|j|jjdd�dS)z�
        Test invoking start_new_thread() with a non-tuple value for "args".
        Expect TypeError with a meaningful error message to be raised.
        Nrz2nd arg must be a tuple)	r�	TypeErrorrr#r�Mockr)rGrH)rrIr	r	r
�test_args_not_tuple�szThreadTests.test_args_not_tuplecCsV|jt��&}tjtj�t�dg�WdQRX|j|jj	dd�dS)z�
        Test invoking start_new_thread() with a non-dict value for "kwargs".
        Expect TypeError with a meaningful error message to be raised.
        �kwargsNrz3rd arg must be a dict)
rr]rr#rr^r@r)rGrH)rrIr	r	r
�test_kwargs_not_dict�s&z ThreadTests.test_kwargs_not_dictcCsRtjdt��}ytj|t��Wntk
rM|jd�YnXdS)z�
        Test invoking start_new_thread() with a function that raises
        SystemExit.
        The exception should be discarded.
        �side_effectz#start_new_thread raised SystemExit.N)rr^r4rr#r@Zfail)r�funcr	r	r
�test_SystemExit�s

zThreadTests.test_SystemExitztraceback.print_exccCs9tjdt�}tj|t��|j|j�dS)z�
        Test invoking start_new_thread() with a function that raises exception.

        The exception should be discarded and the traceback should be printed
        via traceback.print_exc()
        rbN)rr^�	Exceptionrr#r@rr()rZmock_print_excrcr	r	r
�test_RaiseException�szThreadTests.test_RaiseExceptionN)r.r/r0r1rUr\r_rardrr2rfr	r	r	r
rK�s!		rK)Z
_dummy_threadrrrMrZZunittestZtestrrr$ZTestCaserr3rKr	r	r	r
�<module>s]/