Sindbad~EG File Manager

Current Path : /proc/2568807/root/usr/local/lib/python3.12/test/__pycache__/
Upload File :
Current File : //proc/2568807/root/usr/local/lib/python3.12/test/__pycache__/test_interpreters.cpython-312.pyc

�

'Μgq�����ddlZddlZddlZddlZddlZddlZddlmZddlZddl	Z	ddl
mZddlm
Z
ddlmZddlmZe
j d�Ze
j d�Zdd	lmZd
�Zd�Zd0d�Zej.d
��ZGd�dej2�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�Z Gd�de�Z!ejDd�Gd�d e��Z#Gd!�d"e�Z$Gd#�d$e�Z%Gd%�d&e�Z&Gd'�d(e�Z'Gd)�d*e�Z(Gd+�d,e�Z)Gd-�d.e�Z*e+d/k(rejX�yy)1�N)�dedent)�support)�
import_helper)�threading_helper)�	os_helper�_xxsubinterpreters�_xxinterpchannels)�interpretersc��tj�\}}|jdd�}td|�d|�d��}|t	|d��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�w�indented�wrappeds     �3/usr/local/lib/python3.12/test/test_interpreters.py�_captured_scriptrs^��
�7�7�9�D�A�q��~�~�d�$8�9�H����#���
�	�	�
�G��D��W�-�-�-�c��tj�D]#}|jdk(r�	|j��%y#t$rY�2wxYw�Nr)r
�list_all�id�close�RuntimeError��interps r�clean_up_interpretersr$ sE���'�'�)���9�9��>��	��L�L�N�	*��
�	��	�s�<�	A�Ac��t|�\}}|5|j||��|j�cddd�S#1swYyxYw)N��channels)r�run�read)r#�requestr'r�rpipes     r�_run_outputr,*s6��$�W�-�M�F�E�	��
�
�6�H�
�-��z�z�|�
���s	�#>�Ac#�"��K�tj�\�}��fd�}tj|��}|j	�d��t|d�5}|j
d�ddd�|j�y#1swY�xYw�w)Nc�B���jtd��d���y)Nz7
            # wait for "signal"
            with open(z5) as rpipe:
                rpipe.read()
            )r(r)r#rs��rr(z_running.<locals>.run4s*����
�
�6���c�
���	r��targetr�done)rr�	threading�Thread�startr�write�join)r#rr(�t�spipers`    @r�_runningr91se�����
�7�7�9�D�A�q��	����$�A��G�G�I�	�	
�a����
���F��
��F�F�H�
��s�AB�B�*B�B�Bc��eZdZd�Zd�Zy)�TestBasec�j���tj�\����fd�}|j|���fS)Nc���	tj��	tj��y#t$rY�"wxYw#t$rYywxYw�N)rr �	Exception)rrs��r�cleanupz!TestBase.os_pipe.<locals>.cleanupIsJ���
������
��������
��
���
��
�s�/�>�	;�;�	A
�	A
)rr�
addCleanup)�selfr@rrs  @@r�os_pipezTestBase.os_pipeGs.����w�w�y���1�	�	
���� ��!�t�rc��t�yr>)r$�rBs r�tearDownzTestBase.tearDownUs���rN)�__name__�
__module__�__qualname__rCrF�rrr;r;Es��� rr;c�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�CreateTestsc��tj�}|j|tj�|j	|tj
��yr>)r
�create�assertIsInstance�Interpreter�assertInr�rBr#s  r�test_in_mainzCreateTests.test_in_main[s=���$�$�&�����f�l�&>�&>�?��
�
�f�l�3�3�5�6rc�"���tj��d���fd�}tj|��}�5|j�ddd�|j	�|j�t
j��y#1swY�>xYw)Nc�n��tj���j��j�yr>)r
rN�acquire�release)r#�locks��r�fz%CreateTests.test_in_thread.<locals>.fcs#���!�(�(�*�F��L�L�N��L�L�Nrr/)r2�Lockr3r4r6rQr
r)rBrYr7r#rXs   @@r�test_in_threadzCreateTests.test_in_thread`sd����~�~�����	�

���A�&��
�
�G�G�I��	�����
�
�f�l�3�3�5�6��T�s�B�Bc��tj�\}tj�}t|t	d��}tj
t
|��}|jtj�|||g�y)Nz�
            from test.support import interpreters
            interp = interpreters.create()
            print(interp.id)
            )r
rrNr,rrP�int�assertEqual)rB�mainr#�out�interp2s     r�test_in_subinterpreterz"CreateTests.test_in_subinterpreternsn���%�%�'����$�$�&���&�&�*�#���
�*�*�3�s�8�4������.�.�0�4���2I�Jrc�d�ttj��}g}td�D]'}tj�}|j|��)|D]}|j
��tj�}|jttj��||hz�y�N�)�setr
r�rangerN�appendr r^)rB�before�
interp_lst�_�interpsr#s      r�test_after_destroy_allz"CreateTests.test_after_destroy_allys����\�*�*�,�-���
��q��A�"�)�)�+�G����g�&��!�F��L�L�N�!��$�$�&������\�2�2�4�5�v���7H�Irc��ttj��}tj�}tj�}tj�}|j	�|j	�tj�}|jttj��|||hz�yr>)rfr
rrNr r^)rBri�interp1ra�interp3r#s      r�test_after_destroy_somez#CreateTests.test_after_destroy_some�s����\�*�*�,�-���%�%�'���%�%�'���%�%�'���
�
���
�
���$�$�&������\�2�2�4�5�v��&�@Q�7Q�RrN)rGrHrIrSr[rbrmrqrJrrrLrLYs��7�
7�	K�J�SrrLc��eZdZd�Zd�Zy)�GetCurrentTestsc�x�tj�}tj�}|j||�yr>)r
�get_main�get_currentr^)rBr_�currents   r�	test_mainzGetCurrentTests.test_main�s.���$�$�&���*�*�,������$�'rc���tj�}tj�}t	|td��}tjt|��}|j||�y)Nz�
            from test.support import interpreters
            cur = interpreters.get_current()
            print(cur.id)
            )	�
_interpretersrur
rNr,rrPr]�assertNotEqual)rBr_r#r`rws     r�test_subinterpreterz#GetCurrentTests.test_subinterpreter�s\���%�%�'���$�$�&���&�&�*�#���
�*�*�3�s�8�4�����G�T�*rN)rGrHrIrxr|rJrrrsrs�s��(�
	+rrsc��eZdZd�Zd�Zd�Zy)�ListAllTestsc�b�tj�}|jdt|��y�N�)r
rr^�len)rBrls  r�test_initialzListAllTests.test_initial�s$���'�'�)������C��L�)rc�N�tj�}tj�}tj�}g}tj�D]}|j	|j
��|j
||j
|j
|j
g�yr>)r
rvrNrrhrr^�rBr_�first�second�idsr#s      r�test_after_creatingz ListAllTests.test_after_creating�sy���'�'�)���#�#�%���$�$�&����"�+�+�-�F��J�J�v�y�y�!�.�	
����t�w�w����&�)�)�<�=rc�X�tj�}tj�}tj�}|j�g}tj�D]}|j|j��|j||j|jg�yr>)r
rvrNr rrhrr^r�s      r�test_after_destroyingz"ListAllTests.test_after_destroying�s|���'�'�)���#�#�%���$�$�&��
���
���"�+�+�-�F��J�J�v�y�y�!�.�	
����t�w�w��	�	�2�3rN)rGrHrIr�r�r�rJrrr~r~�s��*�	>�
4rr~c���eZdZd�Zd�Zd�Zd�Zejd�d��Z	ejd�d��Z
d�Zejd�d	��Zd
�Z
d�Zd�Zy
)�TestInterpreterAttrsc�x�tj�}tj�}tj�}|j	|j
tj�|j	|j
tj�|j	|j
tj�yr>)r
rurvrNrOrrz�
InterpreterID)rBr_rwr#s    r�test_id_typez!TestInterpreterAttrs.test_id_type�sz���$�$�&���*�*�,���$�$�&�����d�g�g�}�'B�'B�C����g�j�j�-�*E�*E�F����f�i�i��)D�)D�Erc�d�tj�}|j|jd�yr)r
rur^r�rBr_s  r�test_main_idz!TestInterpreterAttrs.test_main_id�s$���$�$�&��������!�$rc���tjd�}|j|jd�|j	t
�5tjd�ddd�y#1swYyxYw�Nr��1)r
rPr^r�assertRaises�	TypeErrorrRs  r�test_custom_idz#TestInterpreterAttrs.test_custom_id�sN���)�)�!�,��������A�&�
�
�
�y�
)��$�$�S�)�*�
)�
)���A&�&A/c��tjd�}|jt�5d|_ddd�y#1swYyxYw�Nr��)r
rPr��AttributeErrorrrRs  r�test_id_readonlyz%TestInterpreterAttrs.test_id_readonly�s3���)�)�!�,��
�
�
�~�
.��F�I�/�
.�
.��	�<�Aznot ready yet (see bpo-32604)c�b�tj�}|j|j�yr>)r
ru�assertFalse�isolatedr�s  r�test_main_isolatedz'TestInterpreterAttrs.test_main_isolated�s"���$�$�&��������'rc�b�tj�}|j|j�yr>)r
rNr�r�rRs  r�$test_subinterpreter_isolated_defaultz9TestInterpreterAttrs.test_subinterpreter_isolated_default�s"���$�$�&��������)rc���tjd��}tjd��}|j|j�|j	|j�y)NT�r�F)r
rN�
assertTruer�r��rBroras   r�%test_subinterpreter_isolated_explicitz:TestInterpreterAttrs.test_subinterpreter_isolated_explicit�sH���%�%�t�4���%�%�u�5������(�(�)�����)�)�*rc�d�tjd�}|j|j�yr�)r
rPr�r�rRs  r�test_custom_isolated_defaultz1TestInterpreterAttrs.test_custom_isolated_default�s$���)�)�!�,��������)rc���tjdd��}tjdd��}|j|j�|j	|j�y)Nr�Tr�F)r
rPr�r�r�r�s   r�test_custom_isolated_explicitz2TestInterpreterAttrs.test_custom_isolated_explicit�sL���*�*�1�t�<���*�*�1�u�=������(�(�)�����)�)�*rc��tjd�}|jt�5d|_ddd�y#1swYyxYw)Nr�T)r
rPr�r�r�rRs  r�test_isolated_readonlyz+TestInterpreterAttrs.test_isolated_readonly�s3���)�)�!�,��
�
�
�~�
.�"�F�O�/�
.�
.�r�c��tj�}tj�}|j||�|j||�yr>)r
rNr^r{r�s   r�
test_equalityz"TestInterpreterAttrs.test_equalitys>���%�%�'���%�%�'������'�*����G�W�-rN)rGrHrIr�r�r�r��unittest�skipr�r�r�r�r�r�r�rJrrr�r��s���F�%�*��
�X�]�]�2�3�(�4�(��X�]�]�2�3�*�4�*�+��X�]�]�2�3�*�4�*�+�#�
.rr�c�f�eZdZd�Zej
d�d��Zd�Zd�Zd�Z	d�Z
d�Zd	�Zy
)�TestInterpreterIsRunningc�j�tj�}|j|j��yr>)r
rur��
is_runningr�s  rrxz"TestInterpreterIsRunning.test_main	s#���$�$�&��������)�*r�Fails on FreeBSDc�&�tj�}|j|j��t	|�5|j|j��ddd�|j|j��y#1swY�)xYwr>)r
rNr�r�r9r�rRs  rr|z,TestInterpreterIsRunning.test_subinterpreter
si���$�$�&������*�*�,�-�
�f�
��O�O�F�-�-�/�0������*�*�,�-��
�s� B�Bc��|j�\}}tj�}|jd|�d��|j	|j��|j
tj|d�d�y)Nz4if True:
            import os
            os.write(z, b'x')
            r��x)	rCr
rNr(r�r�r^rr))rBrrr#s    r�
test_finishedz&TestInterpreterIsRunning.test_finishedsr���|�|�~���1��$�$�&���
�
���S�
��	�	
����*�*�,�-��������A���-rc��tj�}t|td|j�d���}|j|j
�d�y)Nz`
            import _xxsubinterpreters as _interpreters
            if _interpreters.is_running(zZ):
                print(True)
            else:
                print(False)
            �True)r
rNr,rrr^�strip)rBr#r`s   r�test_from_subinterpreterz1TestInterpreterIsRunning.test_from_subinterpreter sS���$�$�&���&�&�.)�)/����4
�*�#���	
�������f�-rc��tj�}|j�|jt�5|j�ddd�y#1swYyxYwr>)r
rNr r�r!r�rRs  r�test_already_destroyedz/TestInterpreterIsRunning.test_already_destroyed+s?���$�$�&������
�
�
�|�
,�����-�
,�
,���A�Ac��tjd�}|jt�5|j	�ddd�y#1swYyxYw�N�@B)r
rPr�r!r�rRs  r�test_does_not_existz,TestInterpreterIsRunning.test_does_not_exist1s8���)�)�)�4��
�
�
�|�
,�����-�
,�
,���A�Ac��tjd�}|jt�5|j	�ddd�y#1swYyxYw�N���)r
rPr��
ValueErrorr�rRs  r�test_bad_idz$TestInterpreterIsRunning.test_bad_id6s8���)�)�"�-��
�
�
�z�
*�����+�
*�
*�r�c��|j�\}}|j�\}}d}d}tj�}|jd|�d|�d|�d|�d�	�|j	|j��t
j||�|jd�|jt
j|d	�|�y)
N�D�F�qif True:
            import os
            import threading

            def task():
                v = os.read(�!, 1)
                assert v == �
                os.write(�, �R)
            t = threading.Thread(target=task)
            t.start()
            �t.join()r�)
rCr
rNr(r�r�rr5r^r))rB�r_interp�w_interp�r_thread�w_thread�DONE�FINISHEDr#s        r�!test_with_only_background_threadsz:TestInterpreterIsRunning.test_with_only_background_threads;s���!�\�\�^���(�!�\�\�^���(������$�$�&���
�
��
&�J�'�!�H�%�"��2�h�\�2
�
�
	�	
����*�*�,�-�
����4� ��
�
�:���������1�-�x�8rN)
rGrHrIrxr�r�r|r�r�r�r�r�r�rJrrr�r�sE��+��X�]�]�%�&�.�'�.�.�	.� � �
 �
9rr�c�x�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zejd
�d��Zd�Zy
)�TestInterpreterClosec��tj�}tj�}tj�}tj�}|jt	tj
��||||h�|j
�|jt	tj
��|||h�yr>)r
rurNr^rfrr )rBr_rorarps     r�
test_basiczTestInterpreterClose.test_basicWs����$�$�&���%�%�'���%�%�'���%�%�'������\�2�2�4�5����'�:�	<��
�
������\�2�2�4�5����1�	3rc��ttj��}t�}td�D]'}tj�}|j|��)|j
ttj��||z�|D]}|j��|j
ttj��|�yrd)rfr
rrgrN�addr^r )rBrirlrkr#s     r�test_allzTestInterpreterClose.test_allbs����\�*�*�,�-���%���q��A�!�(�(�*�F��K�K����	
����\�2�2�4�5�v��7G�H��F��L�L�N������\�2�2�4�5�v�>rc� ���tj�\��jt�5�j	�ddd���fd�}tj|��}|j�|j�y#1swY�FxYw)Nc�z���jt�5�j�ddd�y#1swYyxYwr>)r�r!r )r_rBs��rrYz)TestInterpreterClose.test_main.<locals>.frs&����"�"�<�0��
�
��1�0�0�s�1�:r/)	r
rr�r!r r2r3r4r6)rBrYr7r_s`  @rrxzTestInterpreterClose.test_mainmsa����%�%�'���
�
�
�|�
,��J�J�L�-�	�
���A�&��	���	�	����-�
,�s�B�B
c��tj�}|j�|jt�5|j�ddd�y#1swYyxYwr>)r
rNr r�r!rRs  rr�z+TestInterpreterClose.test_already_destroyedzs<���$�$�&������
�
�
�|�
,��L�L�N�-�
,�
,�r�c��tjd�}|jt�5|j	�ddd�y#1swYyxYwr�)r
rPr�r!r rRs  rr�z(TestInterpreterClose.test_does_not_exist�s5���)�)�)�4��
�
�
�|�
,��L�L�N�-�
,�
,�r�c��tjd�}|jt�5|j	�ddd�y#1swYyxYwr�)r
rPr�r�r rRs  rr�z TestInterpreterClose.test_bad_id�s5���)�)�"�-��
�
�
�z�
*��L�L�N�+�
*�
*�r�c	�N�tj�\}tj�}t|t	dt|j��d���}|j|j�d�|jttj��||h�y)Nza
            from test.support import interpreters
            interp = interpreters.Interpreter(z)
            try:
                interp.close()
            except RuntimeError:
                print('failed')
            �failed)
r
rrNr,rr]rr^r�rf)rBr_r#r`s    r�test_from_currentz&TestInterpreterClose.test_from_current�s����%�%�'����$�$�&���&�&�./�/2�6�9�9�~�.>�?
�*�#���	
�������h�/�����\�2�2�4�5��f�~�Frc��tj�\}tj�}tj�}|jt	tj��|||h�|jt
d|j�d���|jt	tj��||h�y)Nzf
            from test.support import interpreters
            interp2 = interpreters.Interpreter(int(zs))
            interp2.close()
            interp3 = interpreters.create()
            interp3.close()
            )r
rrNr^rfr(rr)rBr_roras    r�test_from_siblingz&TestInterpreterClose.test_from_sibling�s����%�%�'����%�%�'���%�%�'������\�2�2�4�5����1�	3����F� 4�4;�J�J�<�@
���	�	
����\�2�2�4�5��g��Grc���tj���fd�}tj|��}|j	�|j�y)Nc�&���j�yr>)r r"s�rrYz6TestInterpreterClose.test_from_other_thread.<locals>.f�s����L�L�Nrr/)r
rNr2r3r4r6)rBrYr7r#s   @r�test_from_other_threadz+TestInterpreterClose.test_from_other_thread�s:����$�$�&��	�
���A�&��	���	�	���rr�c�J�tj�\}tj�}t|�5|j	t
�5|j
�ddd�|j|j��ddd�y#1swY�1xYw#1swYyxYwr>)	r
rrNr9r�r!r r�r�)rBr_r#s   r�test_still_runningz'TestInterpreterClose.test_still_running�sq���%�%�'����$�$�&��
�f�
��"�"�<�0�����1��O�O�F�-�-�/�0��
�0�0���
�s#�B�B
�'B�
B	�B�B"c��|j�\}}|j�\}}d}tj�}|jd|�d|�d��|j	�|jt
j|d�|�y)Nr�a�if True:
            import os
            import threading
            import time

            done = False

            def notify_fini():
                global done
                done = True
                t.join()
            threading._register_atexit(notify_fini)

            def task():
                while not done:
                    time.sleep(0.1)
                os.write(r�r�r�)rCr
rNr(r r^rr))rBr�r�r�r�r�r#s       r�test_subthreads_still_runningz2TestInterpreterClose.test_subthreads_still_running�s���!�\�\�^���(�!�\�\�^���(����$�$�&���
�
�� #��2�h�\�2
�!�	�(	�����������1�-�x�8rN)rGrHrIr�r�rxr�r�r�r�r�r�r�r�r�r�rJrrr�r�UsV��	3�	?����
�
G�
H���X�]�]�%�&�1�'�1�9rr�c��eZdZd�Zd�Zej�d��Zejd�d��Z
d�Zd�Zd�Z
d	�Zd
�Zy)�TestInterpreterRunc���tj�}td�\}}|5|j|�|j	�}ddd�|jd�y#1swY�xYw)N�print("it worked!", end="")�
it worked!)r
rNrr(r)r^)rBr#r�filer`s     r�test_successzTestInterpreterRun.test_success�sX���$�$�&��'�(E�F����
��J�J�v���)�)�+�C��	
����l�+�	�T�s�"A"�"A+c�6���tj��td�\�}|5��fd�}tj|��}|j�|j
�|j�}ddd�|jd�y#1swY�xYw)Nr�c�(���j��yr>)r()r#rs��rrYz,TestInterpreterRun.test_in_thread.<locals>.f�s����
�
�6�"rr/r�)	r
rNrr2r3r4r6r)r^)rBr�rYr7r`r#rs     @@rr[z!TestInterpreterRun.test_in_thread�sv����$�$�&��'�(E�F����
�
#�� � ��*�A�
�G�G�I�
�F�F�H��)�)�+�C��	
����l�+��T�s�A
B�Bc��tj�}ddl}|jdd��5}|j	d�|j�d}t
d|j�d|�d	��}|j|�|jd�|j�}|j||�ddd�y#1swYyxYw)
Nrzw+r
r�zspam spam spam spam spamz�
                import os
                try:
                    os.fork()
                except RuntimeError:
                    with open('zE', 'w', encoding='utf-8') as out:
                        out.write('z')
                )r
rN�tempfile�NamedTemporaryFiler5�flushr�namer(�seekr)r^)rBr#rr��expectedr�contents       r�	test_forkzTestInterpreterRun.test_fork�s����$�$�&���
�
(�
(���
(�
@�D��J�J�r�N��J�J�L�1�H��! �
!%�	�	�{�+$�$,�:�.�
��F�
�J�J�v���I�I�a�L��i�i�k�G����W�h�/�#A�
@�
@�s�BB9�9Cr�c���tj�}t|�5|jt�5|jd�ddd�ddd�y#1swY�xYw#1swYyxYw)N�
print("spam"))r
rNr9r�r!r(rRs  r�test_already_runningz'TestInterpreterRun.test_already_running	sO���$�$�&��
�f�
��"�"�<�0��
�
�?�+�1��
�0�0���
�s"�A%�A�A%�A"	�A%�%A.c��tjd�}|jt�5|j	d�ddd�y#1swYyxYw)Nr�r)r
rPr�r!r(rRs  rr�z&TestInterpreterRun.test_does_not_exists8���)�)�)�4��
�
�
�|�
,��J�J��'�-�
,�
,���A�Ac��tjd�}|jt�5|j	d�ddd�y#1swYyxYw)Nr�r)r
rPr�r�r(rRs  rr�zTestInterpreterRun.test_bad_ids8���)�)�"�-��
�
�
�z�
*��J�J��'�+�
*�
*�rc��tj�}|jt�5|j	d�ddd�y#1swYyxYw)N�
�r
rNr�r�r(rRs  r�test_bad_scriptz"TestInterpreterRun.test_bad_scripts5���$�$�&��
�
�
�y�
)��J�J�r�N�*�
)�
)���A�Ac��tj�}|jt�5|j	d�ddd�y#1swYyxYw)Ns
print("spam")rrRs  r�test_bytes_for_scriptz(TestInterpreterRun.test_bytes_for_scripts7���$�$�&��
�
�
�y�
)��J�J�'�(�*�
)�
)�rc�.�|j�\}}|j�\}}d}d}d}tj�}|jd|�d|�d|�d|�d|�d|�d	�
�|jd
|�d|�d	��t	j
||�|jd�|j
t	j|d�|�|j
t	j|d�|�|j
t	j|d�|�y)
N�Rr�r�r�r�r�r�z[)
            t = threading.Thread(target=task)
            t.start()
            os.write(z)
            zif True:
            os.write(r�r�)rCr
rNr(rr5r^r))	rBr�r�r�r��RANr�r�r#s	         r�*test_with_background_threads_still_runningz=TestInterpreterRun.test_with_background_threads_still_running$s"��!�\�\�^���(�!�\�\�^���(��������$�$�&���
�
��
&�J�'�!�H�%�"��2�h�\�2��Z�r�#��)
��	�	�
�
���Z�r�#��)
��	�	����4� ��
�
�:���������1�-�s�3��������1�-�s�3��������1�-�x�8rN)rGrHrIr�r[r�
requires_forkr
r�r�r
r�r�rrrrJrrr�r��sd��,�,��W����0��0�,�X�]�]�%�&�,�'�,�(�
(�
�
)�
9rr�zNthese are crashing, likely just due just to _xxsubinterpreters (see gh-105699)c�l�eZdZejd�d��Zejd�d��Zy)�StressTests�cpuc�r�g}td�D]'}tj�}|j|��)y)N�d)rgr
rNrh)rB�aliverkr#s    r�test_create_many_sequentialz'StressTests.test_create_many_sequentialLs/�����s��A�!�(�(�*�F��L�L�� �rc����g��fd���fd�td�D�}tj|�5	ddd�y#1swYyxYw)Nc�P��tj�}�j|�yr>)r
rNrh)r#r"s �r�taskz3StressTests.test_create_many_threaded.<locals>.taskVs���!�(�(�*�F��L�L�� rc3�J�K�|]}tj������y�w)r/N)r2r3)�.0rkr&s  �r�	<genexpr>z8StressTests.test_create_many_threaded.<locals>.<genexpr>Ys �����E�*�Q�9�#�#�4�0�0�*�s� #��)rgr�
start_threads)rB�threadsr"r&s  @@r�test_create_many_threadedz%StressTests.test_create_many_threadedSs;�����	!�F�%��*�E��
�
+�
+�G�
4��5�
4�
4�s	�>�AN)rGrHrIr�requires_resourcer#r-rJrrrrFsD���W���u�%�!�&�!��W���u�%��&�rrc���eZdZdZej
�fd��Zdd�d�ZdZdZ	d�Z
d�Zd	�Ze
j�dd
�d��Zd�Z�xZS)
�StartupTestsrc'��K�t�|�|�5}|xjdz
c_	|��|jr(|jdk(rt	dd��nt	d�d|_	ddd�y#|jr/|jdk(rt	dd��d|_wt	d�d|_wxYw#1swYyxYw�w)Nr�z### end subtest debug ###r)�endF)�super�subTest�_subtest_count�_debugged_in_subtest�print)rB�args�ctx�	__class__s   �rr4zStartupTests.subTestes������
�W�_�d�
#�s����1�$��

2��	��,�,��*�*�a�/��9�r�B��9�:�,1��)�$�
#��
�,�,��*�*�a�/��9�r�B�-2��)��9�:�,1��)��$�
#�s3�
C�B7�A0�;B7�'	C�0AB4�4B7�7C�<CN��headerc�X�|r�|jd|�d��|rn|jtj�r-|j|dt	tj��n"|j|�|jd�|jd�y|j|�y)Nz--- z ---z<no newline>�------)�_debug�endswithr�linesepr�)rB�msgr<s   r�debugzStartupTests.debugus|����K�K�$�v�h�d�+�,���<�<��
�
�+��K�K��$5�c�"�*�*�o�%5� 6�7��K�K��$��K�K��/��K�K��!��K�K��rFc���|jst�d|_|j�+	|jsd|_td�t|�yt|�y)NTz### start subtest debug ###)�	_debuggedr7�_subtestr6)rBrBs  rr?zStartupTests._debug�sJ���~�~��G�!�D�N��=�=�$���0�0�04�D�-��7�8��c�
��#�Jrc��ddl}|jd��}tjj	|�}|jtj|�|S)Nr�test_interpreters_)�prefix)r�mkdtempr�path�realpathrAr�rmtree)rBr�tmps   r�create_temp_dirzStartupTests.create_temp_dir�sF������&:��;���g�g���s�#�����	�(�(�#�.��
rc�*�tjj|�}tjj|�}|rtj|d��t|dd��5}|j
t|��ddd�|S#1swY|SxYw)NT)�exist_okrr
r)rrKr6�dirname�makedirsrr5r)rB�textrK�filenamerR�outfiles      r�write_scriptzStartupTests.write_script�sj���7�7�<�<��&���'�'�/�/�(�+����K�K��$�/�
�(�C�'�
2�g��M�M�&��,�'�3���3���s�#B�B��cwdc��ddl}ddl}t|t�r|j	|�}t
jg|�}	|j||dd��}|j dk(s |j"dk7sJ|j ��|j"dk7rqt$j&ra|jd	|j|d
d��d��|j|j(d�
�|j|j d�
�|j+|j"d�|j+|j d�|j(S#t$r�}|jd|j|����t|t�rL|js@tjj|d�rd}nd}|j|d�d|����d}~wwxYw)NrT)rY�capture_outputrTz# cmd: �existszdoes not exist� rz
# python3 r�z failed:�stdoutr;�stderr)�shlex�
subprocess�
isinstance�str�split�sys�
executabler(r?rCr6�FileNotFoundErrorrUrrKr\r_�
returncoder�verboser^r^)rB�argvrYr`ra�proc�excr\s        r�
run_pythonzStartupTests.run_python�s���	���d�C� ��;�;�t�$�D����&��&��	��>�>���#��	"��D��{�{�b� �D�O�O�q�$8�E�$�+�+�E�8��?�?�a��G�O�O��J�J��E�J�J�t�A�B�x�$8�#9��B�C��J�J�t�{�{�8�J�4��J�J�t�{�{�8�J�4�������!�,�������b�)��{�{���!�	��J�J�����D�!1� 2�3�4��#�0�1�#�,�,��7�7�>�>�$�q�'�*�%�F�-�F��
�
�d�1�g�Y�a��x�0�1���	�s�E�	G�BG�Gc��d}|j�}|j|ddd��|j|dd|��|j|dd|��|j|d|��d|fd|fd	|fd
|fdg}|D]x\}}|jd|���5|j||�
�}t	j
|�}|d|d}	}|j
|	|�|j
|	|�ddd��zy#1swY��xYw)Na�
            import sys
            from test.support import interpreters

            orig = sys.path[0]

            interp = interpreters.create()
            interp.run(f"""if True:
                import json
                import sys
                print(json.dumps({{
                    'main': {orig!r},
                    'sub': sys.path[0],
                }}, indent=4), flush=True)
                """)
            �pkgz__init__.pyr)rTz__main__.pyz	script.pyz	-m scriptz-m pkgz
-m pkg.script)z-c "import script"rzpython3 rXr_�sub)rOrWr4rm�json�loadsr^)
rBrrY�casesrjrr`�data�sp0_main�sp0_subs
          r�test_sys_path_0zStartupTests.test_sys_path_0�s ����,�"�"�$�����#�u�m�"��=����#�u�m�&��A����#�u�k���?����#�{���8��#��
�#��
�s�O�
�c�"�&�
��$�N�D�(�������/�0��o�o�d��o�4���z�z�#���$(��L�$�u�+�'��� � ��(�3�� � ��(�3�1�0�$�0�0�s
�AC3�3C<	)rGrHrIr5�
contextlib�contextmanagerr4rCrEr6r?rOrWr�requires_subprocessrmrw�
__classcell__)r:s@rr0r0^sp���
�N����
2��
2�$(���I� �����!�W� � �"�&*��#��B+4rr0c��eZdZd�Zy)�FinalizationTestsc��ddl}tjddg}|j|dd��}|j	d|j
�|jdk(r`tjrPt�td�td|j���td	|j
���td
�|j|jd�y)Nrz-cz�if True:
            import _xxsubinterpreters as _interpreters
            interpid = _interpreters.create()
            raise Exception
            T)r[rT�	Tracebackz --- cmd unexpected succeeded ---zstdout:
zstderr:
r>r�)rarerfr(rQr_rhrrir7r^r^)rBrarjrks    r�test_gh_109793z FinalizationTests.test_gh_109793�s��������'���
�~�~�d�4�d�~�C���
�
�k�4�;�;�/��?�?�a��G�O�O��G��4�5��I�d�k�k�]�+�,��I�d�k�k�]�+�,��(�O�������!�,rN)rGrHrIr�rJrrr}r}�s��-rr}c��eZdZd�Zd�Zy)�TestIsShareablec��gd�}|D]B}|j|�5tj|�}|j|�ddd��Dy#1swY�OxYw)N)N�spam�spamri����)r4r
�is_shareabler�)rB�
shareables�obj�	shareables    r�test_default_shareablesz'TestIsShareable.test_default_shareablessL���
��C����c�"�(�5�5�c�:�	����	�*�#�"��"�"�s�'A
�
A	c�V�Gd�d�}Gd�dt�}ddtdttt�t	�d||d	�|d
�g}|D]I}|jt
|��5|jtj|��ddd��Ky#1swY�VxYw)Nc��eZdZd�Zd�Zy)�2TestIsShareable.test_not_shareable.<locals>.Cheesec��||_yr>�r)rBrs  r�__init__z;TestIsShareable.test_not_shareable.<locals>.Cheese.__init__s	�� ��	rc��|jSr>r�rEs r�__str__z:TestIsShareable.test_not_shareable.<locals>.Cheese.__str__s���y�y� rN)rGrHrIr�r�rJrr�Cheeser�s��
!�
!rr�c��eZdZdZy)�4TestIsShareable.test_not_shareable.<locals>.SubByteszA subclass of a shareable type.N)rGrHrI�__doc__rJrr�SubBytesr�s��1rr�TF.gY@�Wensleydaler�)
�bytes�NotImplemented�type�objectr?r4�reprr�r
r�)rBr�r��not_shareablesr�s     r�test_not_shareablez"TestIsShareable.test_not_shareables���	!�	!�	2�u�	2�
�������������}�%���!���""�C����d�3�i�(�� � � �-�-�c�2�4�)�(�"�(�(�s�/%B�B(	N)rGrHrIr�r�rJrrr�r�s��
+�4rr�c��eZdZd�Zd�Zy)�TestChannelsc��tj�\}}|j|tj�|j|tj�yr>)r
�create_channelrO�RecvChannel�SendChannel)rBr�ss   r�test_createzTestChannels.test_create9s@���*�*�,���1����a��!9�!9�:����a��!9�!9�:rc�(�|jtj�g�t�}t	d�D]'}tj
�}|j
|��)ttj��}|j||�yrd)r^r
�list_all_channelsrfrgr�r�)rB�createdrk�ch�afters     r�
test_list_allzTestChannels.test_list_all>sn������7�7�9�2�>��%���q��A��,�,�.�B��K�K��O���L�2�2�4�5�������(rN)rGrHrIr�r�rJrrr�r�7s��;�
)rr�c�$�eZdZd�Zd�Zd�Zd�Zy)�TestRecvChannelAttrsc��tj�\}}|j|jtj
�yr>�r
r�rOr�	_channels�	ChannelID)rB�rchrks   rr�z!TestRecvChannelAttrs.test_id_typeJs.���,�,�.���Q����c�f�f�i�&9�&9�:rc���tjd�}|j|jd�|j	t
�5tjd�ddd�y#1swYyxYwr�)r
r�r^rr�r��rBr�s  rr�z#TestRecvChannelAttrs.test_custom_idN�N���&�&�q�)���������#�
�
�
�y�
)��$�$�S�)�*�
)�
)�r�c��tjd�}|jt�5d|_ddd�y#1swYyxYwr�)r
r�r�r�rr�s  rr�z%TestRecvChannelAttrs.test_id_readonlyU�3���&�&�q�)��
�
�
�~�
.��C�F�/�
.�
.�r�c��tj�\}}tj�\}}|j||�|j||�yr>�r
r�r^r{)rB�ch1rk�ch2s    rr�z"TestRecvChannelAttrs.test_equalityZsF���,�,�.���Q��,�,�.���Q�����c�"����C��%rN�rGrHrIr�r�r�r�rJrrr�r�H���;�*��
&rr�c�$�eZdZd�Zd�Zd�Zd�Zy)�TestSendChannelAttrsc��tj�\}}|j|jtj
�yr>r�)rBrk�schs   rr�z!TestSendChannelAttrs.test_id_typecs.���,�,�.���3����c�f�f�i�&9�&9�:rc���tjd�}|j|jd�|j	t
�5tjd�ddd�y#1swYyxYwr�)r
r�r^rr�r��rBr�s  rr�z#TestSendChannelAttrs.test_custom_idgr�r�c��tjd�}|jt�5d|_ddd�y#1swYyxYwr�)r
r�r�r�rr�s  rr�z%TestSendChannelAttrs.test_id_readonlynr�r�c��tj�\}}tj�\}}|j||�|j||�yr>r�)rBrkr�r�s    rr�z"TestSendChannelAttrs.test_equalityssF���,�,�.���3��,�,�.���3�����c�"����C��%rNr�rJrrr�r�ar�rr�c��eZdZd�Zd�Zejd�d��Zd�Zd�Z	d�Z
d�Zejd�d	��Zd
�Z
d�Zd�Zd
�Zd�Zd�Zy)�TestSendRecvc��tj�\}}d}|j|�|j�}|j	||�|j||�y�Nr�)r
r��send_nowait�recvr^�assertIsNot�rBrr��origr�s     r�test_send_recv_mainz TestSendRecv.test_send_recv_main|sP���*�*�,���1���	�
�
�d���f�f�h������d�#�����d�#rc�`�tj�}|jtd��y)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'
            �r
rNr(rrRs  r�test_send_recv_same_interpreterz,TestSendRecv.test_send_recv_same_interpreter�s(���$�$�&���
�
�6���	rzbroken (see BPO-...)c	��tj�\}}tj�\}}d}|j|�ttj�tdt
|��d��t||����}|j�}|j|d�|jt
|�t|��y)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)
                �rr�r&�eggs)r
r�r�r,rNrr�dictr�r^r{r]�rB�r1�s1�r2�s2�orig1r`�obj2s        r�%test_send_recv_different_interpretersz2TestSendRecv.test_send_recv_different_interpreters�s����,�,�.���B��,�,�.���B���
���u������!��$�%'�u�I�;�/�	�
��B�"�%����w�w�y������w�'����B�t�H�c�#�h�/rc�<���tj�\����fd�}tj|��}|j	�d}�j|�|j
��j�}|j||�|j||�y)Nc���		�j�}	�j|�y#tj$rtjd�YnwxYw�S)Ng�������?)r�r
�ChannelEmptyError�time�sleep�send)r�rr�s ��rrYz8TestSendRecv.test_send_recv_different_threads.<locals>.f�sM����$��&�&�(�C��
�F�F�3�K��$�5�5�$��J�J�s�O�$��	s�'�(A�Ar/r�)
r
r�r2r3r4r�r6r�r^r�)rBrYr7r�r�rr�s     @@r� test_send_recv_different_threadsz-TestSendRecv.test_send_recv_different_threads�sy����*�*�,���1�	�
���A�&��	���	���	���t��	�����f�f�h������d�#�����d�#rc��tj�\}}d}|j|�|j�}|j	||�|j||�yr�)r
r�r��recv_nowaitr^r�r�s     r�test_send_recv_nowait_mainz'TestSendRecv.test_send_recv_nowait_main�sP���*�*�,���1���	�
�
�d���m�m�o������d�#�����d�#rc�v�tj�\}}|jd�}|j|�yr>)r
r�r��assertIsNone)rBrrkr�s    r�'test_send_recv_nowait_main_with_defaultz4TestSendRecv.test_send_recv_nowait_main_with_default�s0���*�*�,���1��m�m�D�!�����#�rc�`�tj�}|jtd��y)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�rRs  r�&test_send_recv_nowait_same_interpreterz3TestSendRecv.test_send_recv_nowait_same_interpreter�s(���$�$�&���
�
�6�	�	�		rc	��tj�\}}tj�\}}d}|j|�ttj�tdt
|��d��t||����}|j�}|j|d�|jt
|�t|��y)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�r&r�)r
r�r�r,rNrrr�r�r^r{r]r�s        r�,test_send_recv_nowait_different_interpretersz9TestSendRecv.test_send_recv_nowait_different_interpreters�s����,�,�.���B��,�,�.���B���
���u������!��$�%'�u�I�;�/�	�
��B�"�%����~�~�������w�'����B�t�H�c�#�h�/rc��tjd�}|jtj�5|j	�ddd�y#1swYyxYwr�)r
r�r��ChannelNotFoundErrorr��rBr�s  r� test_recv_channel_does_not_existz-TestSendRecv.test_recv_channel_does_not_exist�s<��
�
%�
%�i�
0��
�
�
�|�@�@�
A��G�G�I�B�
A�
A���A�Ac��tjd�}|jtj�5|j	d�ddd�y#1swYyxYw�Nr�r�)r
r�r�r�r�r�s  r� test_send_channel_does_not_existz-TestSendRecv.test_send_channel_does_not_exist�s?��
�
%�
%�i�
0��
�
�
�|�@�@�
A��G�G�G��B�
A�
A���A�Ac��tjd�}|jtj�5|j	�ddd�y#1swYyxYwr�)r
r�r�r�r�r�s  r�'test_recv_nowait_channel_does_not_existz4TestSendRecv.test_recv_nowait_channel_does_not_exist�s=��
�
%�
%�i�
0��
�
�
�|�@�@�
A��N�N��B�
A�
A�r�c��tjd�}|jtj�5|j	d�ddd�y#1swYyxYwr�)r
r�r�r�r�r�s  r�'test_send_nowait_channel_does_not_existz4TestSendRecv.test_send_nowait_channel_does_not_exists?��
�
%�
%�i�
0��
�
�
�|�@�@�
A��N�N�7�#�B�
A�
A�r�c��tj�\}}|jtj�5|j	�ddd�y#1swYyxYwr>)r
r�r�r�r�)rBr�rks   r�test_recv_nowait_emptyz#TestSendRecv.test_recv_nowait_emptys>���+�+�-���A�
�
�
�|�=�=�
>��N�N��?�
>�
>�s�A�Ac�p�t�}tj�\}}|j|�}|j	d�|j	d�|j	d�|j	d�|j|�}|j|�}|j�}|j|�}|j|�}	|j||�|j|d�|j
|d�|j
|d�|j
|d�|j|	|�y)Nr�r�r�)r�r
r�r�r��assertIsr^)
rB�defaultr�r��obj1r��obj3�obj4�obj5�obj6s
          r�test_recv_nowait_defaultz%TestSendRecv.test_recv_nowait_defaults����(���.�.�0���S����w�'���������������� ����� ����w�'�����w�'����� �����w�'�����w�'���
�
�d�G�$��
�
�d�D�!�����q�!�����w�'�����w�'��
�
�d�G�$rN)rGrHrIr�r�r�r�r�r�r�r�r�r�r�r�r�r�rr
rJrrr�r�zs~��$�
��X�]�]�)�*�0�+�0�.$�,$����X�]�]�)�*�0�+�0�.�
�
�
$�
�
%rr��__main__r>)-rxrqr�os.pathrer2�textwraprr�r��testr�test.supportrrr�
import_modulerzr�r
rr$r,ryr9�TestCaser;rLrsr~r�r�r�r�r�rr0r}r�r�r�r�r�rGr_rJrr�<module>rs�����	��
������&�)�"�+�
�+�+�,@�A�
�'�M�'�'�(;�<�	�%�	.������
��
�& �x� � � �(9S�(�9S�x+�h�+�&4�8�4�<>.�8�>.�BK9�x�K9�\A9�8�A9�Hh9��h9�Z����_�`��(��a��.P4�8�P4�f-��-�(/4�h�/4�d)�8�)�"&�8�&�2&�8�&�2e%�8�e%�P�z���H�M�M�O�r

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists