Your IP : 216.73.216.196


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_interpreters.cpython-310.opt-1.pyc

o

0�i�Y�@sFddlZddlZddlZddlmZddlZddlZddlZddl	m
Z
dd�Zdd�Zd&dd	�Z
ejd
d��ZGdd
�d
ej�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGd d!�d!e�ZGd"d#�d#e�ZGd$d%�d%e�ZdS)'�N)�dedent)�interpreterscCs>t��\}}|�dd�}td|�d|�d��}|t|dd�fS)N�
z
                z-
        import contextlib
        with open(zg, 'w', encoding='utf-8') as spipe:
            with contextlib.redirect_stdout(spipe):
                z	
        �utf-8��encoding)�os�pipe�replacer�open)�script�r�wZindented�wrapped�r�=/opt/alt/python310/lib64/python3.10/test/test_interpreters.py�_captured_scripts�
�rc	Cs<t��D]}|jdkrqz|��WqtyYqwdS�Nr)r�list_all�id�close�RuntimeError��interprrr�clean_up_interpreterss
��rcCsJt|�\}}|�|j||d�|��Wd�S1swYdS)N��channels)r�run�read)rZrequestrrZrpiperrr�_run_output"s
$�rc#sv�t��\�}��fdd�}tj|d�}|��dVt|d��
}|�d�Wd�n1s0wY|��dS)Ncs��td��d���dS)Nz7
            # wait for "signal"
            with open(z5) as rpipe:
                rpipe.read()
            )rrr�rr
rrr,s�z_running.<locals>.run��targetrZdone)rr	�	threading�Thread�startr�write�join)rrr�tZspiperr r�_running)s��r)c@seZdZdd�ZdS)�TestBasecCs
t�dS�N)r��selfrrr�tearDown?�
zTestBase.tearDownN)�__name__�
__module__�__qualname__r.rrrrr*=sr*c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�CreateTestscCs*t��}|�|tj�|�|t���dSr+)r�create�assertIsInstance�Interpreter�assertInr�r-rrrr�test_in_mainEszCreateTests.test_in_maincsnt���d���fdd�}tj|d�}��|��Wd�n1s$wY|��|��t���dS)Ncst���������dSr+)rr4�acquire�releaser�r�lockrr�fMsz%CreateTests.test_in_thread.<locals>.fr!)r#ZLockr$r%r'r7rr�r-r>r(rr<r�test_in_threadJs
�zCreateTests.test_in_threadcCsHt��\}t��}t|td��}t�t|��}|�t��|||g�dS)Nz�
            from test.support import interpreters
            interp = interpreters.create()
            print(interp.id)
            )rrr4rrr6�int�assertEqual)r-�mainr�out�interp2rrr�test_in_subinterpreterXs

z"CreateTests.test_in_subinterpretercCshtt���}g}td�D]}t��}|�|�q|D]}|��qt��}|�tt���||hB�dS�N�)�setrr�ranger4�appendrrB)r-�beforeZ
interp_lst�_�interpsrrrr�test_after_destroy_allcs
z"CreateTests.test_after_destroy_allcCs\tt���}t��}t��}t��}|��|��t��}|�tt���|||hB�dSr+)rIrrr4rrB)r-rL�interp1rE�interp3rrrr�test_after_destroy_someqs z#CreateTests.test_after_destroy_someN)r0r1r2r9r@rFrOrRrrrrr3Csr3c@�eZdZdd�Zdd�ZdS)�GetCurrentTestscCs t��}t��}|�||�dSr+)r�get_main�get_currentrB)r-rC�currentrrr�	test_main�szGetCurrentTests.test_maincCs<t��}t��}t|td��}t�t|��}|�||�dS)Nz�
            from test.support import interpreters
            cur = interpreters.get_current()
            print(cur.id)
            )	�
_interpretersrUrr4rrr6rA�assertNotEqual)r-rCrrDrWrrr�test_subinterpreter�s
z#GetCurrentTests.test_subinterpreterN)r0r1r2rXr[rrrrrT�rTc@s$eZdZdd�Zdd�Zdd�ZdS)�ListAllTestscCst��}|�dt|��dS�N�)rrrB�len)r-rNrrr�test_initial�szListAllTests.test_initialcCsRt��}t��}t��}g}t��D]}|�|j�q|�||j|j|jg�dSr+)rrVr4rrKrrB�r-rC�first�secondZidsrrrr�test_after_creating�sz ListAllTests.test_after_creatingcCsVt��}t��}t��}|��g}t��D]}|�|j�q|�||j|jg�dSr+)rrVr4rrrKrrBrbrrr�test_after_destroying�sz"ListAllTests.test_after_destroyingN)r0r1r2rarerfrrrrr]�sr]c@s�eZdZdd�Zdd�Zdd�Zdd�Ze�d	�d
d��Z	e�d	�dd
��Z
dd�Ze�d	�dd��Zdd�Z
dd�Zdd�ZdS)�TestInterpreterAttrscCsLt��}t��}t��}|�|jtj�|�|jtj�|�|jtj�dSr+)rrUrVr4r5rrYZ
InterpreterID)r-rCrWrrrr�test_id_type�sz!TestInterpreterAttrs.test_id_typecCst��}|�|jd�dSr)rrUrBr�r-rCrrr�test_main_id��z!TestInterpreterAttrs.test_main_idcC�Rt�d�}|�|jd�|�t��t�d�Wd�dS1s"wYdS�Nr_�1)rr6rBr�assertRaises�	TypeErrorr8rrr�test_custom_id��

"�z#TestInterpreterAttrs.test_custom_idcC�@t�d�}|�t��d|_Wd�dS1swYdS�Nr_�)rr6ro�AttributeErrorrr8rrr�test_id_readonly��
"�z%TestInterpreterAttrs.test_id_readonlyznot ready yet (see bpo-32604)cC�t��}|�|j�dSr+)rrU�assertFalse�isolatedrirrr�test_main_isolated��z'TestInterpreterAttrs.test_main_isolatedcCryr+)rr4rzr{r8rrr�$test_subinterpreter_isolated_default�r}z9TestInterpreterAttrs.test_subinterpreter_isolated_defaultcCs4tjdd�}tjdd�}|�|j�|�|j�dS)NT�r{F)rr4�
assertTruer{rz�r-rPrErrr�%test_subinterpreter_isolated_explicit��z:TestInterpreterAttrs.test_subinterpreter_isolated_explicitcCst�d�}|�|j�dSr^)rr6rzr{r8rrr�test_custom_isolated_default�s
z1TestInterpreterAttrs.test_custom_isolated_defaultcCs8tjddd�}tjddd�}|�|j�|�|j�dS)Nr_TrF)rr6r�r{rzr�rrr�test_custom_isolated_explicit�sz2TestInterpreterAttrs.test_custom_isolated_explicitcCrs)Nr_T)rr6rorvr{r8rrr�test_isolated_readonly�rxz+TestInterpreterAttrs.test_isolated_readonlycCs,t��}t��}|�||�|�||�dSr+)rr4rBrZr�rrr�
test_equality�sz"TestInterpreterAttrs.test_equalityN)r0r1r2rhrjrqrw�unittest�skipr|r~r�r�r�r�r�rrrrrg�s


rgc@sFeZdZdd�Ze�d�dd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dS)�TestInterpreterIsRunningcCst��}|�|���dSr+)rrUr��
is_runningrirrrrX�rkz"TestInterpreterIsRunning.test_main�Fails on FreeBSDcCs^t��}|�|���t|��|�|���Wd�n1s!wY|�|���dSr+)rr4rzr�r)r�r8rrrr[�s
�z,TestInterpreterIsRunning.test_subinterpretercCs4t��}t|td|j�d���}|�|��d�dS)Nz`
            import _xxsubinterpreters as _interpreters
            if _interpreters.is_running(zZ):
                print(True)
            else:
                print(False)
            �True)rr4rrrrB�strip)r-rrDrrr�test_from_subinterpreters
�z1TestInterpreterIsRunning.test_from_subinterpretercCsHt��}|��|�t��
|��Wd�dS1swYdSr+)rr4rrorr�r8rrr�test_already_destroyed�

"�z/TestInterpreterIsRunning.test_already_destroyedcC�Bt�d�}|�t��
|��Wd�dS1swYdS�N�@B)rr6rorr�r8rrr�test_does_not_exist�

"�z,TestInterpreterIsRunning.test_does_not_existcCr��N���)rr6ro�
ValueErrorr�r8rrr�test_bad_idr�z$TestInterpreterIsRunning.test_bad_idN)r0r1r2rXr�r�r[r�r�r�r�rrrrr��s
r�c@sfeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Ze�
d�dd��ZdS)�TestInterpreterClosecCsbt��}t��}t��}t��}|�tt���||||h�|��|�tt���|||h�dSr+)rrUr4rBrIrr)r-rCrPrErQrrr�
test_basics
��zTestInterpreterClose.test_basiccCsttt���}t�}td�D]}t��}|�|�q
|�tt���||B�|D]}|��q'|�tt���|�dSrG)rIrrrJr4�addrBr)r-rLrNrMrrrr�test_all)s
zTestInterpreterClose.test_allcsjt��\���t�����Wd�n1swY��fdd�}tj|d�}|��|��dS)Ncs8��t��
���Wd�dS1swYdSr+)rorrr�rCr-rrr>9s
"�z)TestInterpreterClose.test_main.<locals>.fr!)	rrrorrr#r$r%r'r?rr�rrX4s

�zTestInterpreterClose.test_maincCsHt��}|��|�t��
|��Wd�dS1swYdSr+)rr4rrorr8rrrr�Ar�z+TestInterpreterClose.test_already_destroyedcCr�r�)rr6rorrr8rrrr�Gr�z(TestInterpreterClose.test_does_not_existcCr�r�)rr6ror�rr8rrrr�Lr�z TestInterpreterClose.test_bad_idcCsZt��\}t��}t|tdt|j��d���}|�|��d�|�t	t���||h�dS)Nza
            from test.support import interpreters
            interp = interpreters.Interpreter(z)
            try:
                interp.close()
            except RuntimeError:
                print('failed')
            Zfailed)
rrr4rrrArrBr�rI)r-rCrrDrrr�test_from_currentQs
�z&TestInterpreterClose.test_from_currentcCsht��\}t��}t��}|�tt���|||h�|�td|j�d���|�tt���||h�dS)Nzf
            from test.support import interpreters
            interp2 = interpreters.Interpreter(int(zs))
            interp2.close()
            interp3 = interpreters.create()
            interp3.close()
            )rrr4rBrIrrr)r-rCrPrErrr�test_from_sibling_s
��z&TestInterpreterClose.test_from_siblingcs4t����fdd�}tj|d�}|��|��dS)Ncs���dSr+)rrrrrr>psz6TestInterpreterClose.test_from_other_thread.<locals>.fr!)rr4r#r$r%r'r?rrr�test_from_other_threadns
z+TestInterpreterClose.test_from_other_threadr�c	Cs�t��\}t��}t|��)|�t��|��Wd�n1s"wY|�|���Wd�dS1s9wYdSr+)	rrr4r)rorrr�r�)r-rCrrrr�test_still_runningws


�"�z'TestInterpreterClose.test_still_runningN)r0r1r2r�r�rXr�r�r�r�r�r�r�r�r�rrrrr�s
	r�c@sheZdZdd�Zdd�Ze�eed�d�dd��Z	e�
d	�d
d��Zdd
�Zdd�Z
dd�Zdd�ZdS)�TestInterpreterRuncCsZt��}td�\}}|�|�|�|��}Wd�n1s wY|�|d�dS)N�print("it worked!", end="")�
it worked!)rr4rrrrB)r-rr�filerDrrr�test_success�s

�zTestInterpreterRun.test_successcszt���td�\�}|�!��fdd�}tj|d�}|��|��|��}Wd�n1s0wY|�|d�dS)Nr�cs����dSr+)rr�rrrrr>�sz,TestInterpreterRun.test_in_thread.<locals>.fr!r�)	rr4rr#r$r%r'rrB)r-r�r>r(rDrr�rr@�s
�	z!TestInterpreterRun.test_in_thread�forkztest needs os.fork()cCs�t��}ddl}|jddd��4}|�d�|��d}td|j�d|�d	��}|�|�|�	d�|�
�}|�||�Wd�dS1sFwYdS)
Nrzw+rr�zspam spam spam spam spamz�
                import os
                try:
                    os.fork()
                except RuntimeError:
                    with open('zE', 'w', encoding='utf-8') as out:
                        out.write('z')
                )rr4�tempfileZNamedTemporaryFiler&�flushr�namer�seekrrB)r-rr�r�ZexpectedrZcontentrrr�	test_fork�s 
�
�

"�zTestInterpreterRun.test_forkr�c	Cszt��}t|��+|�t��
|�d�Wd�n1swYWd�dSWd�dS1s6wYdS)N�
print("spam"))rr4r)rorrr8rrr�test_already_running�s
��"�z'TestInterpreterRun.test_already_runningcC�Dt�d�}|�t��|�d�Wd�dS1swYdS)Nr�r�)rr6rorrr8rrrr���
"�z&TestInterpreterRun.test_does_not_existcCr�)Nr�r�)rr6ror�rr8rrrr��r�zTestInterpreterRun.test_bad_idcC�Bt��}|�t��|�d�Wd�dS1swYdS)N�
�rr4rorprr8rrr�test_bad_script��"�z"TestInterpreterRun.test_bad_scriptcCr�)Ns
print("spam")r�r8rrr�test_bytes_for_script�r�z(TestInterpreterRun.test_bytes_for_scriptN)r0r1r2r�r@r�Z
skipUnless�hasattrrr�r�r�r�r�r�r�rrrrr��s	

r�c@rS)�TestIsShareablec	CsTgd�}|D]!}|�|��t�|�}|�|�Wd�n1s"wYqdS)N)N�spamZspamr�i����)�subTestr�is_shareabler�)r-Z
shareables�objZ	shareablerrr�test_default_shareables�s	
���z'TestIsShareable.test_default_shareablesc
Cs�Gdd�d�}Gdd�dt�}ddtdttt�t�d||d	�|d
�g}|D]!}|�t|���|�t�	|��Wd�n1sAwYq%dS)Nc@rS)z2TestIsShareable.test_not_shareable.<locals>.CheesecSs
||_dSr+�r�)r-r�rrr�__init__�r/z;TestIsShareable.test_not_shareable.<locals>.Cheese.__init__cSs|jSr+r�r,rrr�__str__�sz:TestIsShareable.test_not_shareable.<locals>.Cheese.__str__N)r0r1r2r�r�rrrr�Cheese�sr�c@seZdZdZdS)z4TestIsShareable.test_not_shareable.<locals>.SubByteszA subclass of a shareable type.N)r0r1r2�__doc__rrrr�SubBytes�sr�TF.gY@ZWensleydaler�)
�bytes�NotImplemented�type�object�	Exceptionr��reprrzrr�)r-r�r�Znot_shareablesr�rrr�test_not_shareable�s.�����z"TestIsShareable.test_not_shareableN)r0r1r2r�r�rrrrr��sr�c@rS)�TestChannelscCs,t��\}}|�|tj�|�|tj�dSr+)r�create_channelr5�RecvChannel�SendChannel)r-r
�srrr�test_createszTestChannels.test_createcCsR|�t��g�t�}td�D]}t��}|�|�qtt���}|�||�dSrG)rBrZlist_all_channelsrIrJr�r�)r-ZcreatedrM�chZafterrrr�
test_list_allszTestChannels.test_list_allN)r0r1r2r�r�rrrrr�r\r�c@�,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestRecvChannelAttrscCs t��\}}|�|jtj�dSr+�rr�r5rrYZ	ChannelID)r-�rchrMrrrrh�z!TestRecvChannelAttrs.test_id_typecCrlrm)rr�rBrrorp�r-r�rrrrqrrz#TestRecvChannelAttrs.test_custom_idcCrsrt)rr�rorvrr�rrrrwrxz%TestRecvChannelAttrs.test_id_readonlycCs4t��\}}t��\}}|�||�|�||�dSr+�rr�rBrZ)r-�ch1rM�ch2rrrr�$r�z"TestRecvChannelAttrs.test_equalityN�r0r1r2rhrqrwr�rrrrr��
r�c@r�)
�TestSendChannelAttrscCs t��\}}|�|jtj�dSr+r�)r-rM�schrrrrh-r�z!TestSendChannelAttrs.test_id_typecCrlrm)rr�rBrrorp�r-r�rrrrq1rrz#TestSendChannelAttrs.test_custom_idcCrsrt)rr�rorvrr�rrrrw8rxz%TestSendChannelAttrs.test_id_readonlycCs4t��\}}t��\}}|�||�|�||�dSr+r�)r-rMr�r�rrrr�=r�z"TestSendChannelAttrs.test_equalityNr�rrrrr�+r�r�c@s�eZdZdd�Zdd�Ze�d�dd��Zdd	�Zd
d�Z	dd
�Z
dd�Ze�d�dd��Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�TestSendRecvcC�>t��\}}d}|�|�|��}|�||�|�||�dS�Nr�)rr��send_nowait�recvrB�assertIsNot�r-r
r��origr�rrr�test_send_recv_mainF�
z TestSendRecv.test_send_recv_maincC�t��}|�td��dS)Na>
            from test.support import interpreters
            r, s = interpreters.create_channel()
            orig = b'spam'
            s.send_nowait(orig)
            obj = r.recv()
            assert obj == orig, 'expected: obj == orig'
            assert obj is not orig, 'expected: obj is not orig'
            �rr4rrr8rrr�test_send_recv_same_interpreterOrkz,TestSendRecv.test_send_recv_same_interpreterzbroken (see BPO-...)cC�|t��\}}t��\}}d}|�|�tt��tdt|��d��t||d�d�}|��}|�	|d�|�
t|�t|��dS)Nr�z�
                obj1 = r.recv()
                assert obj1 == b'spam', 'expected: obj1 == orig1'
                # When going to another interpreter we get a copy.
                assert id(obj1) != ��, 'expected: obj1 is not orig1'
                orig2 = b'eggs'
                print(id(orig2))
                s.send_nowait(orig2)
                �r
r�r�eggs)rr�r�rr4rr�dictr�rBrZrA�r-Zr1�s1Zr2�s2Zorig1rD�obj2rrr�%test_send_recv_different_interpreters[�
�
	�
z2TestSendRecv.test_send_recv_different_interpreterscsht��\����fdd�}tj|d�}|��d}��|�|�����}|�||�|�	||�dS)Ncs>	z���}Wntjyt�d�Ynwq��|�dS)NTg�������?)r�r�ChannelEmptyError�time�sleep�send)r�r�rrr>vs��z8TestSendRecv.test_send_recv_different_threads.<locals>.fr!r�)
rr�r#r$r%rr'r�rBr�)r-r>r(r�r�rr�r� test_send_recv_different_threadsss
z-TestSendRecv.test_send_recv_different_threadscCr�r�)rr�r��recv_nowaitrBr�r�rrr�test_send_recv_nowait_main�r�z'TestSendRecv.test_send_recv_nowait_maincCs$t��\}}|�d�}|�|�dSr+)rr�rZassertIsNone)r-r
rMr�rrr�'test_send_recv_nowait_main_with_default�s
z4TestSendRecv.test_send_recv_nowait_main_with_defaultcCr�)Na�
            from test.support import interpreters
            r, s = interpreters.create_channel()
            orig = b'spam'
            s.send_nowait(orig)
            obj = r.recv_nowait()
            assert obj == orig, 'expected: obj == orig'
            # When going back to the same interpreter we get the same object.
            assert obj is not orig, 'expected: obj is not orig'
            r�r8rrr�&test_send_recv_nowait_same_interpreter�rkz3TestSendRecv.test_send_recv_nowait_same_interpretercCr�)Nr�z�
                obj1 = r.recv_nowait()
                assert obj1 == b'spam', 'expected: obj1 == orig1'
                # When going to another interpreter we get a copy.
                assert id(obj1) != r�r�rr�)rr�r�rr4rrr�rrBrZrAr�rrr�,test_send_recv_nowait_different_interpreters�r�z9TestSendRecv.test_send_recv_nowait_different_interpreterscC�Dt�d�}|�tj��
|��Wd�dS1swYdSr�)rr�ro�ChannelNotFoundErrorr��r-r�rrr� test_recv_channel_does_not_exist��

"�z-TestSendRecv.test_recv_channel_does_not_existcC�Ft�d�}|�tj��|�d�Wd�dS1swYdS�Nr�r�)rr�rorrr	rrr� test_send_channel_does_not_exist��
"�z-TestSendRecv.test_send_channel_does_not_existcCrr�)rr�rorrr	rrr�'test_recv_nowait_channel_does_not_exist�rz4TestSendRecv.test_recv_nowait_channel_does_not_existcCrr
)rr�rorr�r	rrr�'test_send_nowait_channel_does_not_exist�rz4TestSendRecv.test_send_nowait_channel_does_not_existcCsFt��\}}|�tj��
|��Wd�dS1swYdSr+)rr�ror�r)r-r�rMrrr�test_recv_nowait_empty�s
"�z#TestSendRecv.test_recv_nowait_emptyc
Cs�t�}t��\}}|�|�}|�d�|�d�|�d�|�d�|�|�}|�|�}|��}|�|�}|�|�}	|�||�|�|d�|�|d�|�|d�|�|d�|�|	|�dS)Nr_r�r�)r�rr�rr�ZassertIsrB)
r-�defaultr�r�Zobj1r�Zobj3Zobj4Zobj5Zobj6rrr�test_recv_nowait_default�s$








z%TestSendRecv.test_recv_nowait_defaultN)r0r1r2r�r�r�r�r�rrrrrr
rrrrrrrrrr�Ds"	
	
r�r+)�
contextlibrr#�textwraprr�r�Z_xxsubinterpretersrYZtest.supportrrrr�contextmanagerr)ZTestCaser*r3rTr]rgr�r�r�r�r�r�r�r�rrrr�<module>s4


<A+eN2