Your IP : 216.73.216.213


Current Path : /opt/alt/python38/lib64/python3.8/test/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/__pycache__/test_dummy_thread.cpython-38.opt-1.pyc

U

i�f�&�@s�ddlZddlZddlZddlZddlZddlmZddlmZdZ	Gdd�dej
�ZGdd�dej
�ZGdd	�d	ej
�Z
Gd
d�dej
�Zedkr�e��dS)
�N)�support)�mockc@szeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
e�d�dd��Zdd�ZdS)�	LockTestszTest lock objects.cCst��|_dS�N)�_thread�
allocate_lock�lock��self�r�;/opt/alt/python38/lib64/python3.8/test/test_dummy_thread.py�setUpszLockTests.setUpcCs|�|j��d�dS)Nz(Lock object is not initialized unlocked.)�assertFalser�lockedr	rrr�
test_initlocks�zLockTests.test_initlockcCs*|j��|j��|�|j��d�dS)Nz%Lock object did not release properly.)r�acquire�releaserrr	rrr�test_releases


�zLockTests.test_releasec	Cs*t���W5QRX|�|j��d�dS)NzAcquired Lock was not released)r�LockTyperrrr	rrr�test_LockType_context_managers


�z'LockTests.test_LockType_context_managercCs|�t|jj�dSr)�assertRaises�RuntimeErrorrrr	rrr�test_improper_release%szLockTests.test_improper_releasecCs|�|j�d�d�dS)Nrz)Conditional acquiring of the lock failed.)�
assertTruerrr	rrr�test_cond_acquire_success)s�z#LockTests.test_cond_acquire_successcCs$|j�d�|�|j�d�d�dS)Nrz=Conditional acquiring of a locked lock incorrectly succeeded.)rrrr	rrr�test_cond_acquire_fail.s�z LockTests.test_cond_acquire_failcCs |j��|�|j��d�dS)NzUncondional locking failed.)rrrrr	rrr�test_uncond_acquire_success5s
�z%LockTests.test_uncond_acquire_successcCs,|�|j�d�dd�|�|j��d�dS)N�Tz*Unconditional locking did not return True.)ZassertIsrrr	rrr�test_uncond_acquire_return_val;s�z(LockTests.test_uncond_acquire_return_valcCs�dd�}|j��tt���}t�||jtf�tj	rHt
�t
dt�|j��tt���}tj	rlt
d�|�||td�dS)NcSst�|�|��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�intr�	monotonicr�start_new_thread�DELAYr�verbose�printZassertGreaterEqual)r
r"Z
start_timeZend_timerrr�test_uncond_acquire_blockingAs 
�
�z&LockTests.test_uncond_acquire_blockingz
time.sleepcCs@|j��|jjddd�}|�|j�|�d�|�|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.rr)ZwaitflagZtimeoutFN)rrr�calledZassert_called_once_with�assertEqual)r
Z
mock_sleep�retvalrrr�test_acquire_timeoutVs


zLockTests.test_acquire_timeoutcCs<|j��|�dt|j��|j��|�dt|j��dS)Nr�unlocked)rr�assertIn�reprrr	rrr�test_lock_representationbs

z"LockTests.test_lock_representationN)�__name__�
__module__�__qualname__�__doc__r
rrrrrrrrr*r�patchr.r2rrrrrs
rc@s eZdZdZdd�Zdd�ZdS)�
RLockTestszTest dummy RLock objects.cCst��|_dSr)r�RLock�rlockr	rrrr
lszRLockTests.setUpcCs�|�dt|j��|j��|j��|�dt|j��|j��|�dt|j��|j��|�dt|j��|�t|jj�dS)Nr/r)r0r1r:rrrrr	rrr�test_multiple_acquireos



z RLockTests.test_multiple_acquireN)r3r4r5r6r
r;rrrrr8isr8c@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�	MiscTestszMiscellaneous tests.cCs|�ttj�dSr)r�
SystemExitr�exitr	rrr�	test_exit~szMiscTests.test_exitcCs&|�t��td�|�t��d�dS)Nz*_thread.get_ident() returned a non-integerr)�assertIsInstancer�	get_identr$Z
assertGreaterr	rrr�
test_ident�s�zMiscTests.test_identcCs|�t��tjd�dS)NzR_thread.LockType is not an instance of what is returned by _thread.allocate_lock())r@rrrr	rrr�
test_LockType�s�zMiscTests.test_LockTypecCs|�t��tjd�dS)Nz;_thread._set_sentinel() did not return a LockType instance.)r@r�
_set_sentinelrr	rrr�test_set_sentinel�s�zMiscTests.test_set_sentinelcCs dd�}|�ttj|t��dS)NcSst��dSr)r�interrupt_mainrrrr�call_interrupt�sz5MiscTests.test_interrupt_main.<locals>.call_interrupt)r�KeyboardInterruptrr&�tuple)r
rGrrr�test_interrupt_main�s�zMiscTests.test_interrupt_maincCs|�ttj�dSr)rrHrrFr	rrr�test_interrupt_in_main�sz MiscTests.test_interrupt_in_maincCst�d�}|�|d�dS)Nr)r�
stack_sizer,)r
r-rrr�test_stack_size_None�s
zMiscTests.test_stack_size_Nonec	Cs:|�tj��}t�d�W5QRX|�|jjdd�dS)N�rz'setting thread stack size not supported)rr�errorrLr,�	exception�args�r
�cmrrr�test_stack_size_not_None�s
�z"MiscTests.test_stack_size_not_NoneN)r3r4r5r6r?rBrCrErJrKrMrTrrrrr<{sr<c@sJeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Ze	�
d�d
d��ZdS)�ThreadTestszTest thread creation.cCs�ddd�}t�d�}t�||ddf�|��}|�|do@|dd�t�|t�|ddd��|��}|�|dox|dd	�t�||dfd
di�|��}|�|do�|dd�dS)
NFcSs|�||f�dS)z<Use to test _thread.start_new_thread() passes args properly.N)�put��queueZarg1�arg2rrr�
arg_tester�sz0ThreadTests.test_arg_passing.<locals>.arg_testerrTrz7Argument passing for thread creation using tuple failedrWz8Argument passing for thread creation using kwargs failedrYzGArgument passing for thread creation using both tuple and kwargs failed)FF)rX�Queuerr&�getrrI)r
rZ�
testing_queue�resultrrr�test_arg_passing�s2

�
����zThreadTests.test_arg_passingcCs�dd�}d}t�|�}tjr2t�tdt|f�t|�D],}trRtt��d�}nd}t	�
|||f�q:t�t�tjr�td�|�
|��|d|tf�dS)	NcSst�|�|�t���dSr)rr rVrrA)rXr!rrr�
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.)rXr[rr(r)r'�range�round�randomrr&rr r,Zqsize)r
r`Zthread_countr]�countZlocal_delayrrr�test_multi_thread_creation�s2
���
��z&ThreadTests.test_multi_thread_creationc	Cs>|�t��}t�t��g�W5QRX|�|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.
        rz2nd arg must be a tupleN)	r�	TypeErrorrr&r�Mockr,rPrQrRrrr�test_args_not_tuple�szThreadTests.test_args_not_tuplec	CsD|�t��}tjt��t�gd�W5QRX|�|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.
        )�kwargsrz3rd arg must be a dictN)
rrgrr&rrhrIr,rPrQrRrrr�test_kwargs_not_dict�s z ThreadTests.test_kwargs_not_dictcCsDtjt�d�}zt�|t��Wntk
r>|�d�YnXdS)z�
        Test invoking start_new_thread() with a function that raises
        SystemExit.
        The exception should be discarded.
        �Zside_effectz#start_new_thread raised SystemExit.N)rrhr=rr&rIZfail)r
�funcrrr�test_SystemExit�s
zThreadTests.test_SystemExitztraceback.print_exccCs*tjtd�}t�|t��|�|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()
        rlN)rrh�	Exceptionrr&rIrr+)r
Zmock_print_excrmrrr�test_RaiseExceptionszThreadTests.test_RaiseExceptionN)r3r4r5r6r_rfrirkrnrr7rprrrrrU�s!		rU�__main__)Z
_dummy_threadrrrXrdZunittestZtestrrr'ZTestCaserr8r<rUr3�mainrrrr�<module>s].j