HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_dummy_thread.cpython-37.pyc
B

��g�&�@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	�2/usr/local/lib/python3.7/test/test_dummy_thread.py�setUpszLockTests.setUpcCs|�|j��d�dS)Nz(Lock object is not initialized unlocked.)�assertFalser�locked)rr	r	r
�
test_initlockszLockTests.test_initlockcCs*|j��|j��|�|j��d�dS)Nz%Lock object did not release properly.)r�acquire�releaserr
)rr	r	r
�test_releases

zLockTests.test_releasec	Cs*t���WdQRX|�|j��d�dS)NzAcquired Lock was not released)r�LockTyperrr
)rr	r	r
�test_LockType_context_managers

z'LockTests.test_LockType_context_managercCs|�t|jj�dS)N)�assertRaises�RuntimeErrorrr)rr	r	r
�test_improper_release%szLockTests.test_improper_releasecCs|�|j�d�d�dS)Nrz)Conditional acquiring of the lock failed.)�
assertTruerr)rr	r	r
�test_cond_acquire_success)sz#LockTests.test_cond_acquire_successcCs$|j�d�|�|j�d�d�dS)Nrz=Conditional acquiring of a locked lock incorrectly succeeded.)rrr)rr	r	r
�test_cond_acquire_fail.sz LockTests.test_cond_acquire_failcCs |j��|�|j��d�dS)NzUncondional locking failed.)rrrr
)rr	r	r
�test_uncond_acquire_success5s
z%LockTests.test_uncond_acquire_successcCs,|�|j�d�dd�|�|j��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�}|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�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�intrZ	monotonicr�start_new_thread�DELAYr�verbose�printZassertGreaterEqual)rr Z
start_timeZend_timer	r	r
�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)rZ
mock_sleep�retvalr	r	r
�test_acquire_timeoutVs


zLockTests.test_acquire_timeoutcCs<|j��|�dt|j��|j��|�dt|j��dS)Nr
�unlocked)rr�assertIn�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@s eZdZdZdd�Zdd�ZdS)�
RLockTestszTest dummy RLock objects.cCst��|_dS)N)r�RLock�rlock)rr	r	r
rlszRLockTests.setUpcCs�|�dt|j��|j��|j��|�dt|j��|j��|�dt|j��|j��|�dt|j��|�t|jj�dS)Nr,r
)r-r.r7rrrr)rr	r	r
�test_multiple_acquireos



z RLockTests.test_multiple_acquireN)r0r1r2r3rr8r	r	r	r
r5isr5c@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�	MiscTestszMiscellaneous tests.cCs|�ttj�dS)N)r�
SystemExitr�exit)rr	r	r
�	test_exit~szMiscTests.test_exitcCs&|�t��td�|�t��d�dS)Nz*_thread.get_ident() returned a non-integerr)�assertIsInstancer�	get_identr"Z
assertGreater)rr	r	r
�
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=rrr)rr	r	r
�
test_LockType�szMiscTests.test_LockTypecCs|�t��tjd�dS)Nz;_thread._set_sentinel() did not return a LockType instance.)r=r�
_set_sentinelr)rr	r	r
�test_set_sentinel�szMiscTests.test_set_sentinelcCs dd�}|�ttj|t��dS)NcSst��dS)N)r�interrupt_mainr	r	r	r
�call_interrupt�sz5MiscTests.test_interrupt_main.<locals>.call_interrupt)r�KeyboardInterruptrr#�tuple)rrDr	r	r
�test_interrupt_main�s
zMiscTests.test_interrupt_maincCs|�ttj�dS)N)rrErrC)rr	r	r
�test_interrupt_in_main�sz MiscTests.test_interrupt_in_maincCst�d�}|�|d�dS)Nr)r�
stack_sizer))rr*r	r	r
�test_stack_size_None�s
zMiscTests.test_stack_size_Nonec	Cs:|�tj��}t�d�WdQRX|�|jjdd�dS)N�rz'setting thread stack size not supported)rr�errorrIr)�	exception�args)r�cmr	r	r
�test_stack_size_not_None�sz"MiscTests.test_stack_size_not_NoneN)r0r1r2r3r<r?r@rBrGrHrJrPr	r	r	r
r9{sr9c@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)�queue�arg1�arg2r	r	r
�
arg_tester�sz0ThreadTests.test_arg_passing.<locals>.arg_testerrTrz7Argument passing for thread creation using tuple failed)rSrTrUz8Argument passing for thread creation using kwargs failedrUzGArgument passing for thread creation using both tuple and kwargs failed)FF)rS�Queuerr#�getrrF)rrV�
testing_queue�resultr	r	r
�test_arg_passing�s(


zThreadTests.test_arg_passingcCs�dd�}d}t�|�}tjr2t�tdt|f�x8t|�D],}trTtt��d�}nd}t	�
|||f�q<Wt�t�tjr�td�|�
|��|d|tf�dS)	NcSst�|�|�t���dS)N)rrrRrr>)rSrr	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.)rSrWrr%r&r$�range�round�randomrr#rrr)Zqsize)rr\Zthread_countrY�countZlocal_delayr	r	r
�test_multi_thread_creation�s&

z&ThreadTests.test_multi_thread_creationc	Cs>|�t��}t�t��g�WdQRX|�|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)rMrN)rrOr	r	r
�test_args_not_tuple�szThreadTests.test_args_not_tuplec	CsD|�t��}tjt��t�gd�WdQRX|�|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)
rrcrr#rrdrFr)rMrN)rrOr	r	r
�test_kwargs_not_dict�s z ThreadTests.test_kwargs_not_dictcCsDtjt�d�}yt�|t��Wntk
r>|�d�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)rrdr:rr#rFZfail)r�funcr	r	r
�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()
        )rhN)rrd�	Exceptionrr#rFrr()rZmock_print_excrir	r	r
�test_RaiseExceptionszThreadTests.test_RaiseExceptionN)r0r1r2r3r[rbrergrjrr4rlr	r	r	r
rQ�s!		rQ�__main__)Z
_dummy_threadrrrSr`ZunittestZtestrrr$ZTestCaserr5r9rQr0�mainr	r	r	r
�<module>s].j