Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test__xxsubinterpreters.cpython-39.opt-2.pyc

a

��g<�@sZddlmZddlZddlZddlZddlZddlZddlmZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZe
�d�Zdd�ZdKd	d
�ZdLdd�Zejd
d��Zdd�Zifdd�ZGdd�dedd��Zejdd��ZGdd�dedd��ZGdd�dedd��Zdd�d d!�Zd"d#�Zd$d%�Zd&d'�Z Gd(d)�d)ej!�Z"Gd*d+�d+ej!�Z#Gd,d-�d-ej!�Z$Gd.d/�d/e"�Z%Gd0d1�d1e"�Z&Gd2d3�d3e"�Z'Gd4d5�d5e"�Z(Gd6d7�d7e"�Z)Gd8d9�d9e"�Z*Gd:d;�d;e"�Z+Gd<d=�d=e"�Z,Gd>d?�d?e"�Z-Gd@dA�dAe"�Z.GdBdC�dCe"�Z/GdDdE�dEedEdF��Z0e�1dG�GdHdI�dIe"��Z2e3dJk�rVe�4�dS)M�)�
namedtupleN)�dedent)�support)�
script_helperZ_xxsubinterpreterscCs:t��\}}|�dd�}td|�d|�d��}|t|�fS)N�
z
                z-
        import contextlib
        with open(zU, 'w') as spipe:
            with contextlib.redirect_stdout(spipe):
                z	
        )�os�pipe�replacer�open)�script�r�wZindented�wrapped�r�8/usr/local/lib/python3.9/test/test__xxsubinterpreters.py�_captured_scripts��
rcCsJt|�\}}|�&t�|||�|��Wd�S1s<0YdS�N)r�interpreters�
run_string�read)�interpZrequest�sharedrZrpiperrr�_run_output"srcCsL|durtj}t��}||}t�|�sHt��|kr<td��t�d�qdS)Nzinterp is not runningg{�G�z�?)rZ
SHORT_TIMEOUT�time�	monotonicr�
is_running�RuntimeError�sleep)r�timeoutZ
start_time�deadlinerrr�_wait_for_interp_to_run)s
r c#s|t��\�}��fdd�}tj|d�}|��t��dVt|d��}|�d�Wd�n1sf0Y|��dS)Ncst��td��d���dS)Nz7
            # wait for "signal"
            with open(z5) as rpipe:
                rpipe.read()
            )rrrr�rrrr�run:s
�z_running.<locals>.run��targetr
�done)	rr�	threading�Thread�startr r
�write�join)rr
r"�tZspiperr!r�_running7s(r,cKst|||�dSr)�_run_interp)�id�sourcerrrr�
run_interpVsr0cCsFt|�}t��}||kr4t��|kr(t�t||�nt�|||�dSr)rr�get_main�get_currentr�execr)r.r/rZ_mainns�mainrrrr-Zsr-cs*eZdZedd��Zd�fdd�	Z�ZS)�InterpretercCs(t||�r|St|t�r ||�St�dSr)�
isinstance�str�NotImplementedError)�cls�rawrrr�from_rawhs


zInterpreter.from_rawNcs�t��}||kr6|sd}n|dkr0td�|���|}nX|durp|sHd}n|dkrXtd��t|tj�s�t�|�}n|r||dkr�d}|}nt��}t��|||�}|S)Nr4z)name mismatch (expected "main", got "{}")rz!name mismatch (unexpected "main"))	rr1�
ValueError�formatr6�
InterpreterID�create�super�__new__)r9�namer.r4�self��	__class__rrrAqs,�zInterpreter.__new__)NN)�__name__�
__module__�__qualname__�classmethodr;rA�
__classcell__rrrDrr5fs
r5zname idccs$z
dVWntjyYn0dSr)r�ChannelClosedErrorrrrr�expect_channel_closed�s

rLcs6eZdZd
�fdd�	Zdd�Zdd�Zdd	�Z�ZS)�
ChannelActionNcs&|sd}|sd}t��||||�}|S)N�bothr4�r@rA)r9�action�endrrCrDrrrA�szChannelAction.__new__cOsb|jdkr |jdvrJt|j��n*|jdvr@|jdvrJt|j��n
t|j��|jdvr^t|j��dS)N�use)�same�opposite�send�recv��close�force-close)rNrSrTrUrV)r4rS�other�extra)rPrQr<r)rC�args�kwargsrrr�__init__�s





zChannelAction.__init__cCs2|jdkr|S|jdkr(|dkr$dSdS|jSdS)NrSrTrUrV�rQ�rCrQrrr�resolve_end�s


zChannelAction.resolve_endcCst|jdkr|S|jdkr(|dur$t�|S|jdkrB|dur>t�|S|jdkrp|jdkrZ|S|rl|jdkrl|St�dS)NrSrZr[r4)rrrB)rCrrZr[rrr�resolve_interp�s 




zChannelAction.resolve_interp)NN)rFrGrHrAr^rarbrJrrrDrrM�srMzaction end interpcsBeZdZddd��fdd�Zdd�Zdd	�Zd
d�dd
�Z�ZS)�ChannelStaterF��closedcst��|||�}|SrrO)r9�pendingrerCrDrrrA�szChannelState.__new__cCst|�|jd|jd�S�N�rd��typerfre�rCrrr�incr�szChannelState.incrcCst|�|jd|jd�Srgrirkrrr�decr�szChannelState.decrT��forcecCs2|jr|r|jdkr|St|�|r&dn|jdd�S)NrTrd)rerfrj)rCrorrrrX�szChannelState.close)r)rFrGrHrArlrmrXrJrrrDrrc�srczpending closedT��
hideclosedcCsr|jr(|dkr"|dkr"|jr"d}q,d}nd}zt||||�}Wn&tjyd|sX|sX�|��}Yn
0|rnd�|S)NrRrVFT.)rerf�_run_actionrrKrX)�cidrPrQ�staterqZ
expectfail�resultrrr�
run_action�srvcCs|dkr�|dkr$t�|d�|��S|dkrx|jsdzt�|�WntjyX|YS0td��q�t�|�|��Snt|��n~|dkr�i}|dvr�d||<tj	|fi|��|�
�S|d	k�r�d
di}|dvr�d||<tj	|fi|��|j
dd�St|��dS)NrRrU�spamrVzexpected ChannelEmptyErrorrX�rVrUTrYrorn)r�channel_sendrlrf�channel_recv�ChannelEmptyError�	Exceptionrmr<�
channel_closerX)rsrPrQrtr]rrrrr�s8





�rrc	Cs>t��D]0}|dkrqzt�|�Wqty6Yq0qdS)Nr)r�list_all�destroyr�r.rrr�clean_up_interpreterssr�c	Cs6t��D](}zt�|�Wqtjy.Yq0qdSr)r�channel_list_all�channel_destroy�ChannelNotFoundError�rsrrr�clean_up_channelss
r�c@seZdZdd�ZdS)�TestBasecCst�t�dSr�r�r�rkrrr�tearDown)szTestBase.tearDownN)rFrGrHr�rrrrr�'sr�c@seZdZdd�Zdd�ZdS)�IsShareableTestsc	CsPgd�}|D]>}|�|�� |�t�|��Wd�q1s@0YqdS)N)Nrw�spam�
i����)�subTest�
assertTruer�is_shareable)rCZ
shareables�objrrr�test_default_shareables3s	�z(IsShareableTests.test_default_shareablesc
Cs�Gdd�d�}Gdd�dt�}ddtdttt�t�d||d	�|d
�g}|D]B}|�t|��� |�t�	|��Wd�qJ1s�0YqJdS)Nc@seZdZdd�Zdd�ZdS)z3IsShareableTests.test_not_shareable.<locals>.CheesecSs
||_dSr�rB)rCrBrrrr^Dsz<IsShareableTests.test_not_shareable.<locals>.Cheese.__init__cSs|jSrr�rkrrr�__str__Fsz;IsShareableTests.test_not_shareable.<locals>.Cheese.__str__N)rFrGrHr^r�rrrr�CheeseCsr�c@seZdZdS)z5IsShareableTests.test_not_shareable.<locals>.SubBytesN)rFrGrHrrrr�SubBytesIsr�TF.gY@ZWensleydalerw)
�bytes�NotImplementedrj�objectr|r��repr�assertFalserr�)rCr�r�Znot_shareablesr�rrr�test_not_shareableBs(��z#IsShareableTests.test_not_shareableN)rFrGrHr�r�rrrrr�1sr�cs`eZdZ�fdd�Z�fdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Z�ZS)�ShareableTypeTestscst���t��|_dSr)r@�setUpr�channel_creatersrkrDrrr�es
zShareableTypeTests.setUpcst�|j�t���dSr)rr�rsr@r�rkrDrrr�iszShareableTypeTests.tearDownc	Csr|D]h}|�|��Jt�|j|�t�|j�}|�||�|�t|�t|��Wd�q1sb0YqdSr)r�rryrsrz�assertEqual�assertIsrj)rC�valuesr��gotrrr�_assert_valuesmsz!ShareableTypeTests._assert_valuesc	Cs^dD]T}|�|��6t�|j|�t�|j�}|�||�Wd�q1sN0YqdS)Nr)r�rryrsrzr�)rCr�r�rrr�test_singletonsxs
z"ShareableTypeTests.test_singletonscCs|�dd|jg�dS)Nrwi')r�rsrkrrr�
test_types�s
�zShareableTypeTests.test_typescCs|�dd�tdd�D��dS)Ncss|]}|jdddd�VqdS)��littleT)�signedN)�to_bytes)�.0�irrr�	<genexpr>�s�z0ShareableTypeTests.test_bytes.<locals>.<genexpr>����)r��rangerkrrr�
test_bytes�s
�zShareableTypeTests.test_bytescCs|�gd��dS)N)zhello worldu你好世界�)r�rkrrr�	test_strs�szShareableTypeTests.test_strscCs*|�t�tdd�tjtjdg��dS)Nr�r�rh)r��	itertools�chainr��sys�maxsizerkrrr�test_int�s�zShareableTypeTests.test_intc
Cs�tjdtjdddg}|D]f}|�|��H|�t��t�|j|�Wd�n1s^0YWd�q 1s|0Yq dS)Nrhr���)r�r�r��assertRaises�
OverflowErrorrryrs)rCZintsr�rrr�test_non_shareable_int�s
�z)ShareableTypeTests.test_non_shareable_int)
rFrGrHr�r�r�r�r�r�r�r�r�rJrrrDrr�cs	r�c@s$eZdZdd�Zdd�Zdd�ZdS)�ListAllTestscCs"t��}t��}|�||g�dSr)rr1r~r�)rCr4�idsrrr�test_initial�szListAllTests.test_initialcCs6t��}t��}t��}t��}|�||||g�dSr)rr1r?r~r��rCr4�first�secondr�rrr�test_after_creating�s
z ListAllTests.test_after_creatingcCs>t��}t��}t��}t�|�t��}|�|||g�dSr)rr1r?rr~r�r�rrr�test_after_destroying�s
z"ListAllTests.test_after_destroyingN)rFrGrHr�r�r�rrrrr��sr�c@seZdZdd�Zdd�ZdS)�GetCurrentTestscCs.t��}t��}|�||�|�|tj�dSr)rr1r2r��assertIsInstancer>)rCr4�currrr�	test_main�szGetCurrentTests.test_maincCsRt��}t��}t|td��}t|���}t��\}}|�||�|�	||�dS)Nz�
            import _xxsubinterpreters as _interpreters
            cur = _interpreters.get_current()
            print(cur)
            assert isinstance(cur, _interpreters.InterpreterID)
            )
rr1r?rr�int�stripr~r�ZassertNotEqual)rCr4r�outr��_�expectedrrr�test_subinterpreter�sz#GetCurrentTests.test_subinterpreterN)rFrGrHr�r�rrrrr��sr�c@seZdZdd�Zdd�ZdS)�GetMainTestscCs0t��\}t��}|�||�|�|tj�dSr)rr~r1r�r�r>)rCr�r4rrr�test_from_main�s
zGetMainTests.test_from_maincCs<t��\}t��}t|td��}t|���}|�||�dS)Nz�
            import _xxsubinterpreters as _interpreters
            main = _interpreters.get_main()
            print(main)
            assert isinstance(main, _interpreters.InterpreterID)
            )rr~r?rrr�r�r�)rCr�rr�r4rrr�test_from_subinterpreter�s

z%GetMainTests.test_from_subinterpreterN)rFrGrHr�r�rrrrr��sr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�IsRunningTestscCst��}|�t�|��dSr)rr1r�r)rCr4rrrr��szIsRunningTests.test_maincCsdt��}|�t�|��t|�� |�t�|��Wd�n1sF0Y|�t�|��dSr)rr?r�rr,r��rCrrrrr��s

.z"IsRunningTests.test_subinterpretercCs2t��}t|td|�d���}|�|��d�dS)Nz`
            import _xxsubinterpreters as _interpreters
            if _interpreters.is_running(zZ):
                print(True)
            else:
                print(False)
            �True)rr?rrr�r�)rCrr�rrrr��s
�z'IsRunningTests.test_from_subinterpretercCsJt��}t�|�|�t��t�|�Wd�n1s<0YdSr)rr?rr�rrr�rrr�test_already_destroyed�s
z%IsRunningTests.test_already_destroyedcCs8|�t��t�d�Wd�n1s*0YdS�Ni@B)r�rrrrkrrr�test_does_not_existsz"IsRunningTests.test_does_not_existcCs8|�t��t�d�Wd�n1s*0YdS�Nr�)r�r<rrrkrrr�test_bad_idszIsRunningTests.test_bad_idN)	rFrGrHr�r�r�r�r�r�rrrrr��sr�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�InterpreterIDTestscCs"tjddd�}|�t|�d�dS)Nr�Trn)rr>r�r��rCr.rrr�
test_with_intsz InterpreterIDTests.test_with_intcCs4Gdd�dt�}tj|�dd�}|�t|�d�dS)Nc@seZdZdd�ZdS)z.InterpreterIDTests.test_coerce_id.<locals>.IntcSsdS�Nr�rrkrrr�	__index__sz8InterpreterIDTests.test_coerce_id.<locals>.Int.__index__N�rFrGrHr�rrrr�Intsr�Trnr�)r7rr>r�r�)rCr�r.rrr�test_coerce_idsz!InterpreterIDTests.test_coerce_idcCsf|�ttjt��|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�dS�Ng$@�10s10r�l)r��	TypeErrorrr>r�r<r�rkrrrr�szInterpreterIDTests.test_bad_idcCsHt��}|�t��"t�t|�d�Wd�n1s:0YdS�Nrh)rr�r�rr>r�r�rrrr�$sz&InterpreterIDTests.test_does_not_existcCs"tjddd�}|�t|�d�dS�Nr�Trnr�)rr>r�r7r�rrr�test_str)szInterpreterIDTests.test_strcCs"tjddd�}|�t|�d�dS)Nr�TrnzInterpreterID(10))rr>r�r�r�rrr�	test_repr-szInterpreterIDTests.test_reprcCs(t��}t�t|��}t��}|�||k�|�||k�|�|t|�k�|�t|�|k�|�|tt|��k�|�tt|��|k�|�|tt|��dk�|�|tt|��k�|�|ddk�|�|td�k�|�|dk�|�||k�|�||k�|�||k�|�||k�dS�N皙�����?r�r��infr�)rr?r>r�r��floatr�r7�rC�id1�id2�id3rrr�
test_equality1s$z InterpreterIDTests.test_equalityN)
rFrGrHr�r�r�r�r�r�r�rrrrr�
sr�c@sNeZdZdd�Ze�d�dd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�ZdS)�CreateTestscCs*t��}|�|tj�|�|t���dSr)rr?r�r>�assertInr~r�rrr�test_in_mainJszCreateTests.test_in_mainz*enable this test when working on pystate.ccCsDt�}td�D] }t��}t�|�|�|�q|�t|�d�dS)N�d)�setr�rr?r�addr��len)rC�seenr�r.rrr�test_unique_idPs
zCreateTests.test_unique_idcsnt���d���fdd�}tj|d�}��|��Wd�n1sH0Y|��|��t���dS)Ncst���������dSr)rr?�acquire�releaser�r.�lockrr�f]sz%CreateTests.test_in_thread.<locals>.fr#)r&�Lockr'r(r*r�rr~�rCr�r+rr�r�test_in_threadZs&zCreateTests.test_in_threadcCsJt��\}t��}t|td��}t|���}|�tt���|||h�dS)Nz�
            import _xxsubinterpreters as _interpreters
            id = _interpreters.create()
            print(id)
            assert isinstance(id, _interpreters.InterpreterID)
            )	rr~r?rrr�r�r�r�)rCr4r�r�r�rrr�test_in_subinterpreteris

z"CreateTests.test_in_subinterpretercs^t��\}t���d���fdd�}tj|d�}|��|��|�tt���|��h�dS)Ncst�td��}t|����dS)Nz�
                import _xxsubinterpreters as _interpreters
                id = _interpreters.create()
                print(id)
                )rrr�r�)r��r�r�rrr�zsz6CreateTests.test_in_threaded_subinterpreter.<locals>.fr#)	rr~r?r&r'r(r*r�r�)rCr4r�r+rrr�test_in_threaded_subinterpretervs
	z+CreateTests.test_in_threaded_subinterpretercCsjtt���}g}td�D]}t��}|�|�q|D]}t�|�q4t��}|�tt���||hB�dS�N�)r�rr~r�r?�appendrr��rC�beforer�r�r.rrr�test_after_destroy_all�sz"CreateTests.test_after_destroy_allcCs`tt���}t��}t��}t��}t�|�t�|�t��}|�tt���|||hB�dSr)r�rr~r?rr�)rCr	r�r�r�r.rrr�test_after_destroy_some�s

z#CreateTests.test_after_destroy_someN)rFrGrHr��unittest�skipr�rrrr
rrrrrr�Hs
	
r�c@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�DestroyTestscCsft��}t��}t��}|�|t���t�|�|�|t���|�|t���|�|t���dSr)rr?r�r~r�assertNotInr�rrr�test_one�s
zDestroyTests.test_onecCsvtt���}t�}td�D]}t��}|�|�q|�tt���||B�|D]}t�|�qN|�tt���|�dSr)r�rr~r�r?r�r�rrrrr�test_all�szDestroyTests.test_allcslt��\���t��t���Wd�n1s40Y��fdd�}tj|d�}|��|��dS)Ncs8��t��t���Wd�n1s*0YdSr�r�rrrr�r4rCrrr��sz!DestroyTests.test_main.<locals>.fr#)	rr~r�rrr&r'r(r*rrrrr��s
(zDestroyTests.test_maincCsJt��}t�|�|�t��t�|�Wd�n1s<0YdSr)rr?rr�rr�rrrr��s
z#DestroyTests.test_already_destroyedcCs8|�t��t�d�Wd�n1s*0YdSr�rrkrrrr��sz DestroyTests.test_does_not_existcCs8|�t��t�d�Wd�n1s*0YdSr�)r�r<rrrkrrrr��szDestroyTests.test_bad_idcCsJt��\}t��}td|�d��}t�||�|�tt���||h�dS)Nzo
            import _xxsubinterpreters as _interpreters
            try:
                _interpreters.destroy(zD)
            except RuntimeError:
                pass
            �rr~r?rrr�r�)rCr4r.rrrr�test_from_current�s
�
zDestroyTests.test_from_currentcCsRt��\}t��}t��}td|�d��}t�||�|�tt���||h�dS)NzZ
            import _xxsubinterpreters as _interpreters
            _interpreters.destroy(�)
            r)rCr4r�r�rrrr�test_from_sibling�s
�
zDestroyTests.test_from_siblingcs4t����fdd�}tj|d�}|��|��dS)Ncst���dSr)rrrr�rrr��sz.DestroyTests.test_from_other_thread.<locals>.fr#)rr?r&r'r(r*rrr�r�test_from_other_thread�s
z#DestroyTests.test_from_other_threadc	Cs�t��\}t��}t|��||jt�|�d|�d�d�|jtd|�d�d��t�|�Wd�n1sn0Y|�t�|��Wd�n1s�0YdS)NzInterp z& should be running before destruction.)�msgz%Should not be able to destroy interp z while it's still running.)	rr~r?r,r�rr�rr)rCr4rrrr�test_still_running�s


�
�(zDestroyTests.test_still_runningN)
rFrGrHrrr�r�r�r�rrrrrrrrr�s

	rcseZdZed�ZdZ�fdd�Z�fdd�Zdd�Zd	d
�Z	dd�Z
e�e
ed
�d�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zejd5dd��Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Z d0d1�Z!e�"d2�d3d4��Z#�Z$S)6�RunStringTestszJ
        with open('{}', 'w') as out:
            out.write('{}')
        r�cst���t��|_d|_dSr)r@r�rr?r.�_fsrkrDrrr�s

zRunStringTests.setUpcs"|jdur|j��t���dSr)rrXr@r�rkrDrrr�s

zRunStringTests.tearDowncCsVtd�\}}|�&t�|j|�|��}Wd�n1s<0Y|�|d�dS)N�print("it worked!", end="")�
it worked!)rrrr.rr�)rCr�filer�rrr�test_successs
&zRunStringTests.test_successcsrtd�\�}|�B��fdd�}tj|d�}|��|��|��}Wd�n1sX0Y��|d�dS)Nrcst��j��dSr)rrr.r�rrCrrr�$sz(RunStringTests.test_in_thread.<locals>.fr#r)rr&r'r(r*rr�)rCrr�r+r�rr!rr!s&zRunStringTests.test_in_threadcCs`tjdd�}td�\}}|�$t�||�|��}Wd�n1sF0Y|�|d�dS)NF)�isolatedz�
            import threading
            def f():
                print('it worked!', end='')

            t = threading.Thread(target=f)
            t.start()
            t.join()
            r)rr?rrrr�)rCZ	subinterprrr�rrr�test_create_thread.s	&z!RunStringTests.test_create_thread�forkztest needs os.fork()cCs�ddl}|�d��j}|�d�|��d}td|j�d|�d��}t�|j|�|�	d�|�
�}|�||�Wd�n1s�0YdS)Nrzw+r�zspam spam spam spam spamz�
                import os
                try:
                    os.fork()
                except RuntimeError:
                    with open('z3', 'w') as out:
                        out.write('z')
                )�tempfile�NamedTemporaryFiler)�flushrrBrrr.�seekrr�)rCr%rr�rZcontentrrr�	test_fork?s
��

zRunStringTests.test_forkc	Csft|j��H|�t��t�|jd�Wd�n1s:0YWd�n1sX0YdS)N�
print("spam"))r,r.r�rrrrkrrr�test_already_runningUsz#RunStringTests.test_already_runningcCsTd}|t��vr|d7}q|�t��t�|d�Wd�n1sF0YdS)Nrrhr*)rr~r�rrr�rrrr�Zs

z"RunStringTests.test_does_not_existcCs:|�t��t�dd�Wd�n1s,0YdS)Nr�r*)r�r<rrrkrrr�
test_error_idaszRunStringTests.test_error_idcCs:|�t��t�dd�Wd�n1s,0YdS)Nr�r*)r�r�rrrkrrrr�eszRunStringTests.test_bad_idcCs<|�t��t�|jd�Wd�n1s.0YdSr��r�r�rrr.rkrrr�test_bad_scriptiszRunStringTests.test_bad_scriptcCs<|�t��t�|jd�Wd�n1s.0YdS)Ns
print("spam")r-rkrrr�test_bytes_for_scriptmsz$RunStringTests.test_bytes_for_scriptNccsz|�tj��}dVWd�n1s(0Y|dur\|�t|j��d�dt|��n|�t|j�d�||��dS)N�:rz{}: {})r�r�RunFailedErrorr�r7�	exception�splitr=)rC�exctyperZcaughtrrr�assert_run_failedqs$�
�z RunStringTests.assert_run_failedcCs<|�t��t�|jd�Wd�n1s.0YdS)Nzprint("spam")r5�SyntaxErrorrrr.rkrrr�test_invalid_syntax|sz"RunStringTests.test_invalid_syntaxcCs>|�td��t�|jd�Wd�n1s00YdS)Nr�zraise Exception("spam"))r5r|rrr.rkrrr�test_failure�szRunStringTests.test_failurecCs>|�td��t�|jd�Wd�n1s00YdS)N�42zraise SystemExit(42))r5�
SystemExitrrr.rkrrr�test_SystemExit�szRunStringTests.test_SystemExitcCs~|�t��"t�|jtd��Wd�n1s20Y|�td��"t�|jtd��Wd�n1sp0YdS)NzG
                import sys
                sys.exit()
                r9zI
                import sys
                sys.exit(42)
                )r5r:rrr.rrkrrr�
test_sys_exit�s0zRunStringTests.test_sys_exitcCs�t��\}}dddd�}td|�d��}t�|j||�t|d��}t�|�}Wd�n1sb0Y|�	|dd�|�	|d	d
�|�	|dd�|�
|d
�dS)N�hams-1)r��eggs�cheddarz�
            eggs = int(eggs)
            spam = 42
            result = spam + eggs

            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(�C, 'wb') as chan:
                pickle.dump(ns, chan)
            �rbr��*r>r�ru�)r?)rrrrrr.r
�pickle�loadr�ZassertIsNone�rCrr
rr�chan�nsrrr�test_with_shared�s��
(zRunStringTests.test_with_sharedcCs�t�|jtd��ddi}td�}t�|j||�t��\}}td|�d��}t�|j|�t|d��}t�|�}Wd�n1s�0Y|�	|ddd	�|�	|d
dd�|�	|dd�dS)Nzj
            spam = 'eggs'
            ns1 = dict(vars())
            del ns1['__builtins__']
            r�r=zL
            ns2 = dict(vars())
            del ns2['__builtins__']
        zr
            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(r@rA�ns1r>�ns2)
rrr.rrrr
rDrEr�)rCrrrr
rGrHrrr�test_shared_overwrites�s�
(z%RunStringTests.test_shared_overwritescCs|t��\}}ddi}td|�d��}t�|j||�t|d��}t�|�}Wd�n1s^0Y|�	|dd�dS)NrFsnot __main__z�
            spam = 42

            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(r@rA)
rrrrrr.r
rDrEr�rFrrr�#test_shared_overwrites_default_vars�s�
	(z2RunStringTests.test_shared_overwrites_default_varscCs�t��\}}t�|jtd|�d���t|d��}t�|�}Wd�n1sP0Yt��\}}t�|jtd|�d���t|d��}t�|�}Wd�n1s�0Y|�	d|�|�
d|�|�	d|�|�	d|�dS)Nz�
            spam = True

            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(zd, 'wb') as chan:
                pickle.dump(ns, chan)
            del ns, pickle, chan
            rAz�
            eggs = False

            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(r@r�r>)rrrrr.rr
rDrEr�r)rCrr
rGrJrKrrr�test_main_reused�s �
(�	(zRunStringTests.test_main_reusedc
Cs�t��\}}td|�d��}t�|j|�t|d��}t�|�}Wd�n1sT0Y|�	d�|�	d�|�
|diddddd��dS)	Nz�
            spam = 42

            ns = dict(vars())
            ns['__builtins__'] = str(ns['__builtins__'])
            import pickle
            with open(r@rA�__builtins__�
__loader__�__main__rB)rF�__annotations__�__doc__�__package__�__spec__r�)rrrrrr.r
rDrE�popr�)rCrr
rrGrHrrr� test_execution_namespace_is_mains"�
	(

�z/RunStringTests.test_execution_namespace_is_mainzblocking foreverc	Cs�td�}t���P}t�|d|�}t�|��}|��}Wd�n1sH0YWd�n1sf0Y|�|d�dS)Na�
        from textwrap import dedent
        import threading
        import _xxsubinterpreters as _interpreters
        id = _interpreters.create()
        def f():
            _interpreters.run_string(id, dedent('''
                import time
                # Give plenty of time for the main interpreter to finish.
                time.sleep(1_000_000)
                '''))

        t = threading.Thread(target=f)
        t.start()
        rr)rrZtemp_dirrZmake_scriptZspawn_python�waitr�)rCr�dirname�filename�proc�retcoderrr�test_still_running_at_exit s
Dz)RunStringTests.test_still_running_at_exit)N)%rFrGrHrZSCRIPTZFILENAMEr�r�r rr#rZ
skipUnless�hasattrrr)r+r�r,r�r.r/�
contextlib�contextmanagerr5r7r8r;r<rIrLrMrNrWr
r]rJrrrDrrs8



!rc@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�ChannelIDTestscCs0tjddd�}|�t|�d�|�|jd�dS)Nr�TrnrN)r�_channel_idr�r�rQ�rCrsrrr�test_default_kwargs>sz"ChannelIDTests.test_default_kwargscCs�tjdddd�}|�|jd�tjddddd�}|�|jd�tjdddd�}|�|jd�tjddddd	�}|�|jd�tjddddd�}|�|jd
�dS)Nr�T�rUrorUF�rUrVro�rVrorV)rVrUrorN)rrbr�rQrcrrr�test_with_kwargsDszChannelIDTests.test_with_kwargscCs4Gdd�dt�}tj|�dd�}|�t|�d�dS)Nc@seZdZdd�ZdS)z*ChannelIDTests.test_coerce_id.<locals>.IntcSsdSr�rrkrrrr�Vsz4ChannelIDTests.test_coerce_id.<locals>.Int.__index__Nr�rrrrr�Usr�Trnr�)r7rrbr�r�)rCr�rsrrrr�TszChannelIDTests.test_coerce_idcCsf|�ttjt��|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�dSr�)r�r�rrbr�r<r�rkrrrr�\szChannelIDTests.test_bad_idcCs>|�t�� tjdddd�Wd�n1s00YdS)Nr�F�rUrV)r�r<rrbrkrrr�test_bad_kwargsdszChannelIDTests.test_bad_kwargscCsJt��}|�tj��"t�t|�d�Wd�n1s<0YdSr�)rr�r�r�rbr�rcrrrr�hsz"ChannelIDTests.test_does_not_existcCs"tjddd�}|�t|�d�dSr�)rrbr�r7rcrrrr�mszChannelIDTests.test_strcCs�tjddd�}|�t|�d�tjdddd�}|�t|�d�tjdddd�}|�t|�d�tjddddd	�}|�t|�d�dS)
Nr�Trnz
ChannelID(10)rezChannelID(10, send=True)rgzChannelID(10, recv=True)rf)rrbr�r�rcrrrr�qszChannelIDTests.test_reprcCs(t��}t�t|��}t��}|�||k�|�||k�|�|t|�k�|�t|�|k�|�|tt|��k�|�tt|��|k�|�|tt|��dk�|�|tt|��k�|�|ddk�|�|td�k�|�|dk�|�||k�|�||k�|�||k�|�||k�dSr�)rr�rbr�r�r�r�r7)rC�cid1�cid2Zcid3rrrr�~s$zChannelIDTests.test_equalityN)rFrGrHrdrhr�r�rjr�r�r�r�rrrrra<s
rac@s>eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Ze�d)�d*d+��Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Z d:d;�Z!d<d=�Z"d>d?�Z#d@dA�Z$dBdC�Z%dDdE�Z&dFdG�Z'dHdI�Z(dJdK�Z)dLS)M�ChannelTestscCst��}|�|tj�dSr)rr�r�Z	ChannelIDrcrrr�test_create_cid�szChannelTests.test_create_cidcCsrt��}t��}t��}t��}t��}|�|t|�d�|�|t|�d�|�t|�t|�|||h�dSr�)rr�r�r�r�r�)rCr	r�r�r�Zafterrrr�test_sequential_ids�sz ChannelTests.test_sequential_idscCs\t��}t|td��}t|���}t��}t|td��}t|���}|�|t|�d�dS)Nz�
            import _xxsubinterpreters as _interpreters
            cid = _interpreters.channel_create()
            print(cid)
            rh)rr?rrr�r�r�)rCr�r�rkr�rlrrr�test_ids_global�szChannelTests.test_ids_globalcCs@t��}tj|dd�}tj|dd�}|�|g�|�|g�dS)NT�rUF)rr��channel_list_interpretersr�)rCrs�send_interps�recv_interpsrrr�#test_channel_list_interpreters_none�s
z0ChannelTests.test_channel_list_interpreters_nonecCs�t��}t��}t�|d�tj|dd�}tj|dd�}|�||g�|�|g�t��}t|td|�d���tj|dd�}tj|dd�}|�||g�|�||g�dS)NrUTrqF�e
            import _xxsubinterpreters as _interpreters
            obj = _interpreters.channel_recv(r)	rr1r�ryrrr�r?rr)rC�interp0rsrsrt�interp1rrr�$test_channel_list_interpreters_basic�s�z1ChannelTests.test_channel_list_interpreters_basiccCs�t��}t��}t��}t��}t��}t�|d�t|td|�d���t|td|�d���t|td|�d���tj|dd�}tj|dd�}|�t	|�||h�|�t	|�||h�dS)	NrU�_
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_send(z, "send")
            rvrTrqF)
rr1r?r�ryrrrrr�r�)rCrwrx�interp2�interp3rsrsrtrrr�'test_channel_list_interpreters_multiple�s&���z4ChannelTests.test_channel_list_interpreters_multiplecCs�t��}t��}t��}t�|d�t|td|�d���tj|dd�}tj|dd�}|�||g�|�||g�t�	|�tj|dd�}tj|dd�}|�||g�|�|g�dS)NrUrvrTrqF)
rr1r?r�ryrrrrr�r�rCrwrxrsrsrtrrr�(test_channel_list_interpreters_destroyed�s �
z5ChannelTests.test_channel_list_interpreters_destroyedcCs>t��}t��}t��}t��}t�|d�t|td|�d���t�|d�t|td|�d���tj|dd�}tj|dd�}|�t	|�d�|�t	|�d�tj
|dd�tj|dd�}tj|dd�}|�t	|�d	�|�t	|�d�t|td
|�d���tj|dd�}tj|dd�}|�t	|�d	�|�||g�dS)N�datarvrTrqFrhr�r�b
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_release()rr1r?r�ryrrrrr�r��channel_release)rCrwrxr{rsrsrtrrr�'test_channel_list_interpreters_released	s8���z4ChannelTests.test_channel_list_interpreters_releasedcCs�t��}t��}t��}t�|d�tj|dd�}tj|dd�}|�t|�d�|�t|�d�tj|dd�|�	tj
��tj|dd�Wd�n1s�0Y|�	tj
��tj|dd�Wd�n1s�0YdS)NrUTrqFrhrrn)rr1r?r�ryrrr�r�r}r�rKr~rrr�%test_channel_list_interpreters_closed4s,z2ChannelTests.test_channel_list_interpreters_closedcCsXt��}t��}t��}t�|d�tj|dd�}tj|dd�}|�t|�d�|�t|�d�tj|dd�|�	tj
��tj|dd�Wd�n1s�0Ytj|dd�}|�t|�d�t|td|�d���|�	tj
��tj|dd�Wd�n1�s0Y|�	tj
��tj|dd�Wd�n1�sJ0YdS)	NrUTrqFrhr�`
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_close(�, force=True)
            )
rr1r?r�ryrrr�r�r}r�rKrrr~rrr�.test_channel_list_interpreters_closed_send_endJs(,�.z;ChannelTests.test_channel_list_interpreters_closed_send_endcCs>t��}d}t�||�t�|�}|�||�|�||�dS�Nrw)rr�ryrzr�ZassertIsNot)rCrsZorigr�rrr�test_send_recv_mainns
z ChannelTests.test_send_recv_maincCst��}t|td��}dS)Na6
            import _xxsubinterpreters as _interpreters
            cid = _interpreters.channel_create()
            orig = b'spam'
            _interpreters.channel_send(cid, orig)
            obj = _interpreters.channel_recv(cid)
            assert obj is not orig
            assert obj == orig
            )rr?rr)rCr�r�rrr�test_send_recv_same_interpreterwsz,ChannelTests.test_send_recv_same_interpretercCs@t��}t��}t|td|�d���}t�|�}|�|d�dS)Nrz�, b'spam')
            rw)rr�r?rrrzr�)rCrsr�r�r�rrr�%test_send_recv_different_interpreters�s�
z2ChannelTests.test_send_recv_different_interpreterscsVt����fdd�}tj|d�}|��t��d�|��t���}|�|d�dS)NcsDzt���}Wq4Wqtjy0t�d�Yq0qt��|�dS)Nr�)rrzr{rrry)r�r�rrr��s
z8ChannelTests.test_send_recv_different_threads.<locals>.fr#rw)	rr�r&r'r(ryr*rzr��rCr�r+r�rr�r� test_send_recv_different_threads�s
z-ChannelTests.test_send_recv_different_threadscsft���t���d����fdd�}tj|d�}|��t��d�|��t���}|�	|d�dS)Ncs t�td��d��d����dS)Nz�
                import time
                import _xxsubinterpreters as _interpreters
                while True:
                    try:
                        obj = _interpreters.channel_recv(z�)
                        break
                    except _interpreters.ChannelEmptyError:
                        time.sleep(0.1)
                assert(obj == b'spam')
                _interpreters.channel_send(z, b'eggs')
                )rrr�rsr�r�rrr��s
�
�zIChannelTests.test_send_recv_different_interpreters_and_threads.<locals>.fr#rw�eggs)
rr�r?r&r'r(ryr*rzr�r�rr�r�1test_send_recv_different_interpreters_and_threads�s
z>ChannelTests.test_send_recv_different_interpreters_and_threadscCs<|�tj��t�dd�Wd�n1s.0YdS)Nr�rw)r�rr�ryrkrrr�test_send_not_found�sz ChannelTests.test_send_not_foundcCs:|�tj��t�d�Wd�n1s,0YdSr�)r�rr�rzrkrrr�test_recv_not_found�sz ChannelTests.test_recv_not_foundcCsBt��}|�tj��t�|�Wd�n1s40YdSr)rr�r�r{rzrcrrr�test_recv_empty�szChannelTests.test_recv_emptyc	Cs�t�}t��}t�||�}t�|d�t�|d�t�|d�t�|d�t�||�}t�||�}t�|�}t�||�}t�||�}|�||�|�|d�|�|d�|�|d�|�|d�|�||�dS)Nrhrwr�)r�rr�rzryr�r�)	rC�defaultrsZobj1�obj2Zobj3Zobj4Zobj5Zobj6rrr�test_recv_default�s$
zChannelTests.test_recv_defaultcCsRt��}t��}t|td�t|jd��}t�|�}|�|d�|�|�	�d�dS)Nz�
            import _xxsubinterpreters as _interpreters
            print(cid.end)
            _interpreters.channel_send(cid, b'spam')
            r�rwrU)
rr�r?rr�dictrUrzr�r��rCrsrr�r�rrr�test_run_string_arg_unresolved�s

�
z+ChannelTests.test_run_string_arg_unresolvedz(disabled until high-level channels existcCs`t��}tj|dd�}t��}t|td�t|jd��}t�|�}|�	|d�|�	|�
�d�dS)NT)�_resolvez�
            import _xxsubinterpreters as _interpreters
            print(chan.id.end)
            _interpreters.channel_send(chan.id, b'spam')
            )rGrwrU)rr�rbr?rrr�rUrzr�r�r�rrr�test_run_string_arg_resolved�s

�
z)ChannelTests.test_run_string_arg_resolvedcCs�t��}t�|d�t�|�t�|�|�tj��t�|d�Wd�n1sV0Y|�tj��t�|�Wd�n1s�0YdS�Nrwr��rr�ryrzr}r�rKrcrrr�test_close_single_users

*z#ChannelTests.test_close_single_usercCst��}t��}t��}t�|td|�d���t�|td|�d���t�|�|�tj��(}t�|td|�d���Wd�n1s�0Y|�dt	|j
��|�tj��(}t�|td|�d���Wd�n1s�0Y|�dt	|j
��dS)Nrzr�z_
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_recv(rz,
                _interpreters.channel_send(z, b'spam')
                rK)rr�r?rrr}r�r1r�r7r2)rCrsr�r��cmrrr�test_close_multiple_userss(
�
�

�*
�*z&ChannelTests.test_close_multiple_userscCsbt��}t�|d�t�|�t�|�|�tj��t�|�Wd�n1sT0YdSr�r�rcrrr�test_close_multiple_times(s

z&ChannelTests.test_close_multiple_timesc
Cs�gd�}|D]�\}}|�||f���t��}t�|d�t�|�tj|||d�|�tj��t�|d�Wd�n1s�0Y|�tj��t�|�Wd�n1s�0YWd�q1s�0YqdS)N))FF�TF)FT)TTrwrir�)r�rr�ryrzr}r�rK)rCZtestsrUrVrsrrr�test_close_empty1s
*zChannelTests.test_close_emptycCspt��}t�|d�t�|d�|�tj��t�|�Wd�n1sL0Yt�|�t�|d�dS)Nrwr=r��rr�ryr�ZChannelNotEmptyErrorr}rzrcrrr�%test_close_defaults_with_unused_itemsDs(
z2ChannelTests.test_close_defaults_with_unused_itemscCs�t��}t�|d�t�|d�|�tj��tj|dd�Wd�n1sP0Yt�|�t�|d�t�|�t�|�tj|dd�dS)Nrwr=T�rVr�r�rcrrr�*test_close_recv_with_unused_items_unforcedNs,


z7ChannelTests.test_close_recv_with_unused_items_unforcedcCs�t��}t�|d�t�|d�tj|dd�|�tj��t�|d�Wd�n1s\0Yt�|�t�|�|�tj��t�|�Wd�n1s�0YdS)Nrwr=Trqr��rr�ryr}r�rKrzrcrrr�*test_close_send_with_unused_items_unforced[s*

z7ChannelTests.test_close_send_with_unused_items_unforcedcCs�t��}t�|d�t�|d�|�tj�� tj|ddd�Wd�n1sR0Yt�|�t�|d�t�|�t�|�tj|dd�dS)Nrwr=Trxr�r�r�rcrrr�*test_close_both_with_unused_items_unforcedhs.


z7ChannelTests.test_close_both_with_unused_items_unforcedcCs�t��}t�|d�t�|d�tj|ddd�|�tj��t�|d�Wd�n1s^0Y|�tj��t�|�Wd�n1s�0YdS)Nrwr=Trgr�r�rcrrr�(test_close_recv_with_unused_items_forcedus*z5ChannelTests.test_close_recv_with_unused_items_forcedcCs�t��}t�|d�t�|d�tj|ddd�|�tj��t�|d�Wd�n1s^0Y|�tj��t�|�Wd�n1s�0YdS)Nrwr=Trer�r�rcrrr�(test_close_send_with_unused_items_forced�s*z5ChannelTests.test_close_send_with_unused_items_forcedcCs�t��}t�|d�t�|d�tj|dddd�|�tj��t�|d�Wd�n1s`0Y|�tj��t�|�Wd�n1s�0YdS)Nrwr=Trfr�r�rcrrr�(test_close_both_with_unused_items_forced�s*z5ChannelTests.test_close_both_with_unused_items_forcedcCs�t��}t�|�|�tj��t�|d�Wd�n1s@0Y|�tj��t�|�Wd�n1sv0YdSr�)rr�r}r�rKryrzrcrrr�test_close_never_used�s
*z"ChannelTests.test_close_never_usedcCs�t��}t�|d�t��}t�|td|�d���|�tj��t�|�Wd�n1s`0Y|�tj��t�	|�Wd�n1s�0YdS)Nrwr�r�)
rr�ryr?rrr�rKrzr}�rCrsrrrr�!test_close_by_unassociated_interp�s
�(z.ChannelTests.test_close_by_unassociated_interpcCs�t��}t�|d�t�|d�t�|d�t�|�tj|dd�|�tj��t�|d�Wd�n1sr0Y|�tj��t�|�Wd�n1s�0YdS)NrwTrnr�r�rcrrr�-test_close_used_multiple_times_by_single_user�s
*z:ChannelTests.test_close_used_multiple_times_by_single_usercCs�t��}|�tj��tjddd�Wd�n1s80Yt�|�|�tj��tj|dd�Wd�n1s|0YdS)Nr�Trq)rr�r�r�rrr}rKrcrrr�.test_channel_list_interpreters_invalid_channel�s,
z;ChannelTests.test_channel_list_interpreters_invalid_channelcCs@t��}|�t��t�|�Wd�n1s20YdSr)rr�r�r�rrrcrrr�+test_channel_list_interpreters_invalid_args�sz8ChannelTests.test_channel_list_interpreters_invalid_argsN)*rFrGrHrnrorpruryr}rr�r�r�r�r�r�r�r�r�r�r�r�r�rr
r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrm�sL	+$	
	



	

rmc@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�ChannelReleaseTestscCs�t��}t�|d�t�|�tj|ddd�|�tj��t�|d�Wd�n1s\0Y|�tj��t�|�Wd�n1s�0YdS�NrwTrir��rr�ryrzr�r�rKrcrrr�test_single_user�s
*z$ChannelReleaseTests.test_single_usercCsxt��}t��}t��}t�|td|�d���t|td|�d|�d���}t�|td|�d���|�|��d�dS)	Nrzr�rvz,)
            _interpreters.channel_release(z+)
            print(repr(obj))
            z+
            _interpreters.channel_release(rzb'spam')rr�r?rrrr�r�)rCrsr�r�r�rrr�test_multiple_userss
���
�z'ChannelReleaseTests.test_multiple_userscCs�t��}t�|d�t�|�t�|�|�tj��t�|d�Wd�n1sV0Y|�tj��t�|�Wd�n1s�0YdSr�r�rcrrr�test_no_kwargss

*z"ChannelReleaseTests.test_no_kwargscCsnt��}t�|d�t�|�tj|ddd�|�tj�� tj|ddd�Wd�n1s`0YdS)NrwTrir�rcrrr�test_multiple_times s
z'ChannelReleaseTests.test_multiple_timescCsjt��}t�|d�t�|d�tj|ddd�|�tj��t�|�Wd�n1s\0YdS)Nrwr=Tri)rr�ryr�r�rKrzrcrrr�test_with_unused_items)sz*ChannelReleaseTests.test_with_unused_itemscCs�t��}t�|�|�tj��t�|d�Wd�n1s@0Y|�tj��t�|�Wd�n1sv0YdSr�)rr�r�r�rKryrzrcrrr�test_never_used2s
*z#ChannelReleaseTests.test_never_usedcCs�t��}t�|d�t��}t�|td|�d���t�|�}t�|�|�tj	��t�|d�Wd�n1sv0Y|�
|d�dS)Nrwr�rr�)rr�ryr?rrrzr�r�rKr�)rCrsrr�rrr�test_by_unassociated_interp;s
�

*z/ChannelReleaseTests.test_by_unassociated_interpc	Csht��}t��}t�|td|�d|�d���|�tj��t�|�Wd�n1sZ0YdS)Nze
            import _xxsubinterpreters as _interpreters
            obj = _interpreters.channel_send(z5, b'spam')
            _interpreters.channel_release(r)rr�r?rrr�rKrzr�rrr�test_close_if_unassociatedJs
��z.ChannelReleaseTests.test_close_if_unassociatedcCsRt��}t�|d�t�|�t�|d�tj|dd�t�|�}|�|d�dS)NrwTrq)rr�ryrzr�r�)rCrsr�rrr�test_partiallyWs

z"ChannelReleaseTests.test_partiallycCs�t��}t�|d�t�|d�t�|d�t�|�tj|ddd�|�tj��t�|d�Wd�n1st0Y|�tj��t�|�Wd�n1s�0YdSr�r�rcrrr�'test_used_multiple_times_by_single_userbs
*z;ChannelReleaseTests.test_used_multiple_times_by_single_userN)
rFrGrHr�r�r�r�r�r�r�r�r�r�rrrrr��s+			
r�cszeZdZdZ�fdd�Zedd��Zedd��Zdd	�Zddd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Z�ZS)�ChannelCloseFixtureFcsx|jri}n4t�|�}t�|�}t�|�}|j||j||j|i}|sHd}t��||||||�}t�|_t�|_	||_
|S)NrS)�QUICKr5r;rBr@rAr��_preppedrc�_state�_known)r9rQrrZr[�creatorZknownrCrDrrrAws 


�zChannelCloseFixture.__new__cCs|jSr�r�rkrrrrt�szChannelCloseFixture.statecCs>z|jWSty8|�|j�}|�|�|_|jYS0dSr)�_cid�AttributeError�_get_interpreterr��_new_channel)rCr�rrrrs�szChannelCloseFixture.cidcCs|�|�}|�|�|Sr)r��_prep_interpreterr�rrr�get_interpreter�s

z#ChannelCloseFixture.get_interpreterNcCs2|dur|j}|dkr&|jjdkr&dSt|jj�S)NrVrUF)rQrtre�boolr`rrr�expect_closed_error�s
z'ChannelCloseFixture.expect_closed_errorcCs|�|�dSr)r�r�rrr�prep_interpreter�sz$ChannelCloseFixture.prep_interpretercCs
||_dSrr�)rCrPrurrr�
record_action�sz!ChannelCloseFixture.record_actioncCst�t�dSrr�rkrrr�clean_up�szChannelCloseFixture.clean_upcCs@|jdkrt��St��}t|jd|�d��t�|�|_|jS)Nr4a
                import _xxsubinterpreters
                cid = _xxsubinterpreters.channel_create()
                # We purposefully send back an int to avoid tying the
                # channel to the other interpreter.
                _xxsubinterpreters.channel_send(zC, int(cid))
                del _xxsubinterpreters
                )rBrr�r0r.rzr�)rCr�Zchrrrr��s
�
z ChannelCloseFixture._new_channelcCsj|dvr|jS|dkr|jS|dkr*|jS|}z|j|}Wn$ty`t|�}|j|<Yn0|SdS)N)rSrrZr[)rrZr[r��KeyErrorr5)rCrrBrrrr��sz$ChannelCloseFixture._get_interpretercCsF|j|jvrdS|j�|j�|jdkr,dSt|jd|j�d��dS)Nr4a
            import _xxsubinterpreters as interpreters
            import test.test__xxsubinterpreters as helpers
            ChannelState = helpers.ChannelState
            try:
                cid
            except NameError:
                cid = interpreters._channel_id(r)r.r�r�rBr0rsr�rrrr��s
�z%ChannelCloseFixture._prep_interpreter)N)rFrGrHr�rA�propertyrtrsr�r�r�r�r�r�r�r�rJrrrDrr�ps


r�zend interp other extra creatorz%these tests take several hours to runc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�d
d�Zdd�Z	dd�Z
d!dd�Zdd�Zd"dd�Z
dd�Zdd�Zdd �ZdS)#�ExhaustiveChannelTestsccs�gV|�dd�D]"}|V|��D]}||Vq$q|�dd�D]"}|V|��D]}||VqTqB|�dd�D]z}|V|�dd�D]*}||}|V|��D]}||Vq�q�|�dd�D]*}||}|V|��D]}||Vq�q�qr|�dd�D]�}|V|�dd�D].}||}|V|��D]}||V�q*�q|�dd�D].}||}|V|��D]}||V�qf�qLq�dS)NrSrZr[)�_iter_close_action_sets�_iter_post_close_action_sets�_iter_use_action_sets)rCZcloseactionsZpostactionsZ
useactions�actionsrrr�iter_action_setssBz'ExhaustiveChannelTests.iter_action_setsccs||f}tdd|�gVtdd|�gVtdd|�tdd|�gVtdd|�gVtdd|�gVtdd|�tdd|�gV|D]<}|D]2}|D](}tdd|�tdd|�tdd|�gVq�q�q�|D]P}|D]F}|D]<}|D]2}tdd|�tdd|�tdd|�tdd|�gVq�q�q�q�dS)NrRrVrU�rM)rCrxr{�interpsr|Zinterp4rrrr�9s>
�
�

�
�
�

�


�



�z,ExhaustiveChannelTests._iter_use_action_setsc
	cs�d}||f}dD]4}|rdnd}|D]}|D]}t|||�gVq,q$qdD]<}	dD]2}
|D](}|D]}t|	d|�t|
d|�gVqbqZqRqJdS)Nrxr�rYrXrWrVrUr�)
rCrxr{Zendsr�ro�oprrQZrecvopZsendoprVrUrrrr�js
�

�z.ExhaustiveChannelTests._iter_close_action_setsccs.dD]$}tdd|�gVtdd|�gVqdS)N)rSr[rZrRrVrUr�r�rrrr�}s

�
�z3ExhaustiveChannelTests._iter_post_close_action_setscCs|D]}|�||�qdSr)rv)rC�fixr�rPrrr�run_actions�sz"ExhaustiveChannelTests.run_actionsTrpcCs�|�|j�}|�|j|j|j�}|�|�|jdkrZt|j	|j
||j|d�}|�||�n�t
��}t|jd|j	�dt|j
��dt|��dt|j��d|�d|�d|�d��tt�t
�|�d	�tt
�|��d
�}|�||�dS)Nr4rpzB
                result = helpers.run_action(
                    z,
                    z!,
                    hideclosed=zB,
                    )
                interpreters.channel_send(zR, result.pending.to_bytes(1, 'little'))
                interpreters.channel_send(z2, b'X' if result.closed else b'')
                r�)rfre)rarQrbrrZr[r�rBrvrsrPrtr�rr�r0r.r�rcr��
from_bytesrzr�)rCr�rPrqrQrrur�rrrrv�sB

�������	�
�z!ExhaustiveChannelTests.run_actionc	csBgd�}|D]0\}}}dD] }dD]}t|||||�Vq"qqdS)N))r4rr[)rr4r[)rxr{r[)rxr{r4)rSrZr�ri)r�)rCrrrZr[r�rQrrr�
iter_fixtures�s
z$ExhaustiveChannelTests.iter_fixturescCst|rdnd}t||jd�}|��s4|j||dd�n<|�tj�� |j||dd�Wd�n1sf0YdS)NrYrXrSFrp)rMrQr�rvr�rrK)rCr�ror�rXrrr�_close�szExhaustiveChannelTests._closeNcCs.|dus|jdkr�|�tj��t�|j�Wd�n1s@0Y|�tj��t�|jd�Wd�n1sz0Y|�tj��t�|j�Wd�n1s�0Y|�tj�� tj|jdd�Wd�n1s�0Yn0t|j	d�t|j	d�t|j	d�t|j	d�dS)	Nr4rwTrnzz
                with helpers.expect_channel_closed():
                    interpreters.channel_recv(cid)
                z�
                with helpers.expect_channel_closed():
                    interpreters.channel_send(cid, b'spam')
                z{
                with helpers.expect_channel_closed():
                    interpreters.channel_close(cid)
                z�
                with helpers.expect_channel_closed():
                    interpreters.channel_close(cid, force=True)
                )
rBr�rrKrzrsryr}r0r.)rCr�rrrr�_assert_closed_in_interp�s*,*0z/ExhaustiveChannelTests._assert_closed_in_interpcCs||�|jj�t|jj�D]}t�|j�q|�|�dD]&}|�	|�}|j
dkrTq:|�||�q:|�	d�}|�||�dS)N)rSrZr4Zfresh)r�rtrer�rfrrzrsr�r�rB)rCr�r�rrrr�_assert_closed�s



z%ExhaustiveChannelTests._assert_closedFc	cs�d}|��D]�}t�|��D]�}|d7}|dkr:dS|rl|dddkrTt�t||d�t|���n2|dddkr�tddd�td	dd�tj��|||fVq|rtd
�qt�dS)Nrrhr��z({} actions)� r�r_�.z---)r��printr�r=r�r��stdoutr')rC�verboser�r�r�rrr�_iter_close_tests�s$
z(ExhaustiveChannelTests._iter_close_testscCsdt_|��D]
\}}}qdS)NT)r�r�r��rCr�r�r�rrr�_skim_close_tests	sz(ExhaustiveChannelTests._skim_close_testsc	Cs�|��D]v\}}}|�d�|||���@|�|j�|�||�|j|dd�|�|�Wd�n1sl0Y|��qdS)N�	{} {}  {}Frn�	r�r�r=r�rr�r�r�r�r�rrr�
test_close	s(z!ExhaustiveChannelTests.test_closec	Cs�|��D]v\}}}|�d�|||���@|�|j�|�||�|j|dd�|�|�Wd�n1sl0Y|��qdS)Nr�Trnr�r�rrr�test_force_close	s(z'ExhaustiveChannelTests.test_force_close)N)F)rFrGrHr�r�r�r�r�rvr�r�r�r�r�r�r�r�rrrrr��s+-1	 
	

r�rQ)N)N)5�collectionsrr_r�rrDr��textwraprr&rr�testrZtest.supportr�
import_modulerrrr r`r,r0r-r5rLrMrcrvrrr�r�ZTestCaser�r�r�r�r�r�r�r�r�rrrarmr�r�r
r�rFr4rrrr�<module>st



&
	3$

2?(;]b7Y:&�q@


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