Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test__xxsubinterpreters.cpython-38.opt-1.pyc
U

>��g��@s`ddlmZddlZddlZddlZddlZddlZddlmZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZe
�d�Zdd�Zd	d
�ZdMdd�Zejd
d��Zdd�Zifdd�Zdd�ZGdd�dedd��Zejdd��ZGdd�dedd��ZGdd�dedd��Zd d!�d"d#�Zd$d%�Zd&d'�Z d(d)�Z!Gd*d+�d+ej"�Z#Gd,d-�d-ej"�Z$Gd.d/�d/ej"�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�dEe#�Z0GdFdG�dGedGdH��Z1e�2dI�GdJdK�dKe#��Z3e4dLk�r\e�5�dS)N�)�
namedtupleN)�dedent)�support)�
script_helperZ_xxsubinterpreterscs&tj��fdd�tt��d�D��S)Nc3s|]}t�|�VqdS�N)�combinations)�.0�r�Zsets��;/opt/cppython/lib/python3.8/test/test__xxsubinterpreters.py�	<genexpr>s�zpowerset.<locals>.<genexpr>�)�	itertools�chain�
from_iterable�range�lenr
rr
r�powersets�rcCs: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)�scriptr	�wZindented�wrappedrrr�_captured_scripts��
rc
Cs>t|�\}}|�$t�|||�|��W5QR�SQRXdSr)r�interpreters�
run_string�read)�interpZrequest�sharedrZrpiperrr�_run_output(sr#c	#s`t��\�}��fdd�}tj|d�}|��dVt|d��}|�d�W5QRX|��dS)Ncst��td��d���dS)Nz7
            # wait for "signal"
            with open(z5) as rpipe:
                rpipe.read()
            )rrrr�r!r	rr�run2s
�z_running.<locals>.run��targetr�done)rr�	threading�Thread�startr�write�join)r!rr%�tZspiperr$r�_running/sr/cKst|||�dSr)�_run_interp)�id�sourcer"rrr�
run_interpMsr3cCsFt|�}t��}||kr4t��|kr(t�t||�nt�|||�dSr)rr�get_main�get_current�RuntimeError�execr)r1r2r"Z_mainns�mainrrrr0Qsr0cs0���fdd�}tj|d�}|��|��dS)Ncst����dSr)Z_runr�r1r"r2rrr%^sz run_interp_threaded.<locals>.runr&)r)r*r+r-)r1r2r"r%r.rr9r�run_interp_threaded]sr:cs*eZdZedd��Zd�fdd�	Z�ZS)�InterpretercCs(t||�r|St|t�r ||�St�dSr)�
isinstance�str�NotImplementedError)�cls�rawrrr�from_rawgs


zInterpreter.from_rawNcs�t��}||kr6|sd}n|dkr0td�|���|}nX|dk	rp|sHd}n|dkrXtd��t|tj�s�t�|�}n|r||dkr�d}|}nt��}t��|||�}|S)Nr8z)name mismatch (expected "main", got "{}")r!z!name mismatch (unexpected "main"))	rr4�
ValueError�formatr<�
InterpreterID�create�super�__new__)r?�namer1r8�self��	__class__rrrGps,�zInterpreter.__new__)NN)�__name__�
__module__�__qualname__�classmethodrArG�
__classcell__rrrJrr;es
r;zname idccs&z
dVWntjk
r YnXdSr)r�ChannelClosedErrorrrrr�expect_channel_closed�s

rRcs6eZdZd
�fdd�	Zdd�Zdd�Zdd	�Z�ZS)�
ChannelActionNcs&|sd}|sd}t��||||�}|S)N�bothr8�rFrG)r?�action�endr!rIrJrrrG�szChannelAction.__new__cOsb|jdkr |jdkrJt|j��n*|jdkr@|jdkrJt|j��n
t|j��|jdkr^t|j��dS)N�use)�same�opposite�send�recv��close�force-close)rTrYrZr[r\)r8rY�other�extra)rVrWrBr!)rI�args�kwargsrrr�__init__�s





zChannelAction.__init__cCs2|jdkr|S|jdkr(|dkr$dSdS|jSdS)NrYrZr[r\�rW�rIrWrrr�resolve_end�s


zChannelAction.resolve_endcCst|jdkr|S|jdkr(|dkr$t�|S|jdkrB|dkr>t�|S|jdkrp|jdkrZ|S|rl|jdkrl|St�dS)NrYr`rar8)r!r6rH)rIr!r`rarrr�resolve_interp�s 




zChannelAction.resolve_interp)NN)rLrMrNrGrdrgrhrPrrrJrrS�srSzaction end interpcsBeZdZddd��fdd�Zdd�Zdd	�Zd
d�dd
�Z�ZS)�ChannelStaterF��closedcst��|||�}|SrrU)r?�pendingrkrIrJrrrG�szChannelState.__new__cCst|�|jd|jd�S�Nrrj��typerlrk�rIrrr�incr�szChannelState.incrcCst|�|jd|jd�Srmrnrprrr�decr�szChannelState.decrT��forcecCs2|jr|r|jdkr|St|�|r&dn|jdd�S)NrTrj)rkrlro)rIrtrrrr^�szChannelState.close)r)rLrMrNrGrqrrr^rPrrrJrri�srizpending closedT��
hideclosedcCst|jr(|dkr"|dkr"|jr"d}q,d}nd}zt||||�}Wn(tjk
rf|sZ|sZ�|��}Yn
X|rpd�|S)NrXr\FT.)rkrl�_run_actionrrQr^)�cidrVrW�statervZ
expectfail�resultrrr�
run_action�sr{cCs�|dkr�|dkr$t�|d�|��S|dkrz|jsfzt�|�Wntjk
rZ|YSXtd��q�t�|�|��Snt|��nt|dkr�i}|dkr�d||<tj	|f|�|�
�S|d	kr�d
di}|dkr�d||<tj	|f|�|j
dd�St|��dS)NrXr[�spamr\zexpected ChannelEmptyErrorr^�r\r[Tr_rtrs)r�channel_sendrqrl�channel_recv�ChannelEmptyError�	ExceptionrrrB�
channel_closer^)rxrVrWryrcrrrrw�s:




�rwc	Cs@t��D]2}|dkrqzt�|�Wqtk
r8YqXqdS)Nr)r�list_all�destroyr6�r1rrr�clean_up_interpreterssr�c	Cs8t��D]*}zt�|�Wqtjk
r0YqXqdSr)r�channel_list_all�channel_destroy�ChannelNotFoundError�rxrrr�clean_up_channelss
r�c@seZdZdd�ZdS)�TestBasecCst�t�dSr�r�r�rprrr�tearDown(szTestBase.tearDownN)rLrMrNr�rrrrr�&sr�c@seZdZdd�Zdd�ZdS)�IsShareableTestsc
CsBdddddg}|D]*}|�|��|�t�|��W5QRXqdS)Nr|�spam�
i����)�subTest�
assertTruer�is_shareable)rIZ
shareables�objrrr�test_default_shareables2s�	�z(IsShareableTests.test_default_shareablesc
Cs~Gdd�d�}Gdd�dt�}ddtdttt�t�d||d	�|d
�g}|D].}|�t|���|�t�	|��W5QRXqJdS)Nc@seZdZdd�Zdd�ZdS)z3IsShareableTests.test_not_shareable.<locals>.CheesecSs
||_dSr�rH)rIrHrrrrdCsz<IsShareableTests.test_not_shareable.<locals>.Cheese.__init__cSs|jSrr�rprrr�__str__Esz;IsShareableTests.test_not_shareable.<locals>.Cheese.__str__N)rLrMrNrdr�rrrr�CheeseBsr�c@seZdZdZdS)z5IsShareableTests.test_not_shareable.<locals>.SubByteszA subclass of a shareable type.N)rLrMrN�__doc__rrrr�SubBytesHsr�TF.gY@ZWensleydaler|)
�bytes�NotImplementedro�objectr�r��repr�assertFalserr�)rIr�r�Znot_shareablesr�rrr�test_not_shareableAs(��z#IsShareableTests.test_not_shareableN)rLrMrNr�r�rrrrr�0sr�cs`eZdZ�fdd�Z�fdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Z�ZS)�ShareableTypeTestscst���t��|_dSr)rF�setUpr�channel_createrxrprJrrr�ds
zShareableTypeTests.setUpcst�|j�t���dSr)rr�rxrFr�rprJrrr�hszShareableTypeTests.tearDownc
Cs^|D]T}|�|��@t�|j|�t�|j�}|�||�|�t|�t|��W5QRXqdSr)r�rr~rxr�assertEqual�assertIsro)rI�valuesr��gotrrr�_assert_valueslsz!ShareableTypeTests._assert_valuesc
CsJdD]@}|�|��,t�|j|�t�|j�}|�||�W5QRXqdS)Nr)r�rr~rxrr�)rIr�r�rrr�test_singletonsws
z"ShareableTypeTests.test_singletonscCs|�dd|jg�dS)Nr|i')r�rxrprrr�
test_types�s
�zShareableTypeTests.test_typescCs|�dd�tdd�D��dS)Ncss|]}|jdddd�VqdS)��littleT)�signedN)�to_bytes)r�irrrr
�s�z0ShareableTypeTests.test_bytes.<locals>.<genexpr>����)r�rrprrr�
test_bytes�s
�zShareableTypeTests.test_bytescCs|�dddg�dS)Nzhello worldu你好世界�)r�rprrr�	test_strs�szShareableTypeTests.test_strscCs*|�t�tdd�tjtjdg��dS)Nr�r�r)r�rrr�sys�maxsizerprrr�test_int�s�zShareableTypeTests.test_intcCsdtjdtjdddg}|D]>}|�|��*|�t��t�|j|�W5QRXW5QRXq dS)Nrr���)r�r�r��assertRaises�
OverflowErrorrr~rx)rIZintsr�rrr�test_non_shareable_int�s
�z)ShareableTypeTests.test_non_shareable_int)
rLrMrNr�r�r�r�r�r�r�r�r�rPrrrJrr�bs	r�c@s$eZdZdd�Zdd�Zdd�ZdS)�ListAllTestscCs"t��}t��}|�||g�dSr)rr4r�r�)rIr8�idsrrr�test_initial�szListAllTests.test_initialcCs6t��}t��}t��}t��}|�||||g�dSr)rr4rEr�r��rIr8�first�secondr�rrr�test_after_creating�s
z ListAllTests.test_after_creatingcCs>t��}t��}t��}t�|�t��}|�|||g�dSr)rr4rEr�r�r�r�rrr�test_after_destroying�s
z"ListAllTests.test_after_destroyingN)rLrMrNr�r�r�rrrrr��sr�c@seZdZdd�Zdd�ZdS)�GetCurrentTestscCs.t��}t��}|�||�|�|tj�dSr)rr4r5r��assertIsInstancerD)rIr8�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)
            )
rr4rEr#r�int�stripr�r�ZassertNotEqual)rIr8r!�outr��_�expectedrrr�test_subinterpreter�sz#GetCurrentTests.test_subinterpreterN)rLrMrNr�r�rrrrr��sr�c@seZdZdd�Zdd�ZdS)�GetMainTestscCs0t��\}t��}|�||�|�|tj�dSr)rr�r4r�r�rD)rIr�r8rrr�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�rEr#rr�r�r�)rIr�r!r�r8rrr�test_from_subinterpreter�s

z%GetMainTests.test_from_subinterpreterN)rLrMrNr�r�rrrrr��sr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�IsRunningTestscCst��}|�t�|��dSr)rr4r��
is_running)rIr8rrrr��szIsRunningTests.test_mainc	CsPt��}|�t�|��t|��|�t�|��W5QRX|�t�|��dSr)rrEr�r�r/r��rIr!rrrr��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)rrEr#rr�r�)rIr!r�rrrr��s
�z'IsRunningTests.test_from_subinterpreterc	Cs6t��}t�|�|�t��t�|�W5QRXdSr)rrEr�r�r6r�r�rrr�test_already_destroyed�s
z%IsRunningTests.test_already_destroyedc	Cs$|�t��t�d�W5QRXdS�Ni@B)r�r6rr�rprrr�test_does_not_existsz"IsRunningTests.test_does_not_existc	Cs$|�t��t�d�W5QRXdS�Nr�)r�rBrr�rprrr�test_bad_idszIsRunningTests.test_bad_idN)	rLrMrNr�r�r�r�r�r�rrrrr��sr�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�InterpreterIDTestscCs"tjddd�}|�t|�d�dS)Nr�Trs)rrDr�r��rIr1rrr�
test_with_intsz InterpreterIDTests.test_with_intcCs4Gdd�dt�}tj|�dd�}|�t|�d�dS)Nc@seZdZdd�ZdS)z.InterpreterIDTests.test_coerce_id.<locals>.IntcSsdS�Nr�rrprrr�	__index__sz8InterpreterIDTests.test_coerce_id.<locals>.Int.__index__N�rLrMrNr�rrrr�Intsr�Trsr�)r=rrDr�r�)rIr�r1rrr�test_coerce_idsz!InterpreterIDTests.test_coerce_idcCsf|�ttjt��|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�dS�Ng$@�10s10r�l)r��	TypeErrorrrDr�rBr�rprrrr�szInterpreterIDTests.test_bad_idc	Cs4t��}|�t��t�t|�d�W5QRXdS�Nr)rr�r�r6rDr�r�rrrr�#sz&InterpreterIDTests.test_does_not_existcCs"tjddd�}|�t|�d�dS�Nr�Trsr�)rrDr�r=r�rrr�test_str(szInterpreterIDTests.test_strcCs"tjddd�}|�t|�d�dS)Nr�TrszInterpreterID(10))rrDr�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�)rrErDr�r��floatr�r=�rI�id1�id2�id3rrr�
test_equality0s$z InterpreterIDTests.test_equalityN)
rLrMrNr�r�r�r�r�r�r�rrrrr�sr�c@sNeZdZdd�Ze�d�dd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�ZdS)�CreateTestscCs*t��}|�|tj�|�|t���dSr)rrEr�rD�assertInr�r�rrr�test_in_mainIszCreateTests.test_in_mainz*enable this test when working on pystate.ccCsDt�}td�D] }t��}t�|�|�|�q|�t|�d�dS)N�d)�setrrrEr��addr�r)rI�seenr�r1rrr�test_unique_idOs
zCreateTests.test_unique_idc	sZt���d���fdd�}tj|d�}��|��W5QRX|��|��t���dS)Ncst���������dSr)rrE�acquire�releaser�r1�lockrr�f\sz%CreateTests.test_in_thread.<locals>.fr&)r)�Lockr*r+r-r�rr��rIr�r.rr�r�test_in_threadYs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�rEr#rr�r�r�r�)rIr8r�r�r�rrr�test_in_subinterpreterhs

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)
                )r#rr�r�)r��r�r�rrr�ysz6CreateTests.test_in_threaded_subinterpreter.<locals>.fr&)	rr�rEr)r*r+r-r�r�)rIr8r�r.rrr�test_in_threaded_subinterpreterus
	z+CreateTests.test_in_threaded_subinterpretercCsjtt���}g}td�D]}t��}|�|�q|D]}t�|�q4t��}|�tt���||hB�dS�N�)r�rr�rrE�appendr�r��rI�beforer�r�r1rrr�test_after_destroy_all�sz"CreateTests.test_after_destroy_allcCs`tt���}t��}t��}t��}t�|�t�|�t��}|�tt���|||hB�dSr)r�rr�rEr�r�)rIr
r�r�r�r1rrr�test_after_destroy_some�s

z#CreateTests.test_after_destroy_someN)rLrMrNr��unittest�skipr�rrrrrrrrrr�Gs
	
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)rrEr�r�r��assertNotInr�rrr�test_one�s
zDestroyTests.test_onecCsvtt���}t�}td�D]}t��}|�|�q|�tt���||B�|D]}t�|�qN|�tt���|�dSr)r�rr�rrEr�r�r�r	rrr�test_all�szDestroyTests.test_allc	sXt��\���t��t���W5QRX��fdd�}tj|d�}|��|��dS)Nc	s$��t��t���W5QRXdSr�r�r6rr�r�r8rIrrr��sz!DestroyTests.test_main.<locals>.fr&)	rr�r�r6r�r)r*r+r-rrrrr��s
zDestroyTests.test_mainc	Cs6t��}t�|�|�t��t�|�W5QRXdSr)rrEr�r�r6r�rrrr��s
z#DestroyTests.test_already_destroyedc	Cs$|�t��t�d�W5QRXdSr�rrprrrr��sz DestroyTests.test_does_not_existc	Cs$|�t��t�d�W5QRXdSr�)r�rBrr�rprrrr��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�rErrr�r�)rIr8r1rrrr�test_from_current�s
�
zDestroyTests.test_from_currentcCsRt��\}t��}t��}td|�d��}t�||�|�tt���||h�dS)NzZ
            import _xxsubinterpreters as _interpreters
            _interpreters.destroy(�)
            r)rIr8r�r�rrrr�test_from_sibling�s
�
zDestroyTests.test_from_siblingcs4t����fdd�}tj|d�}|��|��dS)Ncst���dSr)rr�rr�rrr��sz.DestroyTests.test_from_other_thread.<locals>.fr&)rrEr)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�|�W5QRX|�t�|��W5QRXdS)NzInterp z& should be running before destruction.)�msgz%Should not be able to destroy interp z while it's still running.)	rr�rEr/r�r�r�r6r�)rIr8r!rrr�test_still_running�s


�
�zDestroyTests.test_still_runningN)
rLrMrNrrr�r�r�r�rrrrrrrrr�s

	rcseZdZed�ZdZ�fdd�Z�fdd�Zedd��Z	d	d
�Z
dd�Zd
d�Ze
�eed�d�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zejd7d d!��Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Z d.d/�Z!d0d1�Z"d2d3�Z#e
�$d4�d5d6��Z%�Z&S)8�RunStringTestszJ
        with open('{}', 'w') as out:
            out.write('{}')
        r�cst���t��|_d|_dSr)rFr�rrEr1�_fsrprJrrr�s

zRunStringTests.setUpcs"|jdk	r|j��t���dSr)rr^rFr�rprJrrr�s

zRunStringTests.tearDowncCs|jdkrt|�|_|jSr)rZ	FSFixturerprrr�fss

zRunStringTests.fsc	CsBtd�\}}|�t�|j|�|��}W5QRX|�|d�dS)N�print("it worked!", end="")�
it worked!�rrrr1r r��rIr�filer�rrr�test_successs
zRunStringTests.test_successc	s^td�\�}|�8��fdd�}tj|d�}|��|��|��}W5QRX��|d�dS)Nrcst��j��dSr)rrr1r�rrIrrr�)sz(RunStringTests.test_in_thread.<locals>.fr&r )rr)r*r+r-r r�)rIr#r�r.r�rr%rr&szRunStringTests.test_in_threadc	CsBtd�\}}|�t�|j|�|��}W5QRX|�|d�dS)Nz�
            import threading
            def f():
                print('it worked!', end='')

            t = threading.Thread(target=f)
            t.start()
            t.join()
            r r!r"rrr�test_create_thread3s
	z!RunStringTests.test_create_thread�forkztest needs os.fork()c	Cs|ddl}|�d��`}|�d�|��d}td|j�d|�d��}t�|j|�|�	d�|�
�}|�||�W5QRXdS)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,�flushrrHrrr1�seekr r�)rIr(r#r�rZcontentrrr�	test_forkCs
��

zRunStringTests.test_forkc
Cs>t|j��*|�t��t�|jd�W5QRXW5QRXdS)N�
print("spam"))r/r1r�r6rrrprrr�test_already_runningYsz#RunStringTests.test_already_runningc	Cs@d}|t��kr|d7}q|�t��t�|d�W5QRXdS)Nrrr-)rr�r�r6rr�rrrr�^s

z"RunStringTests.test_does_not_existc	Cs&|�t��t�dd�W5QRXdS)Nr�r-)r�rBrrrprrr�
test_error_ideszRunStringTests.test_error_idc	Cs&|�t��t�dd�W5QRXdS)Nr�r-)r�r�rrrprrrr�iszRunStringTests.test_bad_idc	Cs(|�t��t�|jd�W5QRXdSr��r�r�rrr1rprrr�test_bad_scriptmszRunStringTests.test_bad_scriptc	Cs(|�t��t�|jd�W5QRXdS)Ns
print("spam")r0rprrr�test_bytes_for_scriptqsz$RunStringTests.test_bytes_for_scriptNc	csf|�tj��}dVW5QRX|dkrH|�t|j��d�dt|��n|�t|j�d�||��dS)N�:rz{}: {})r�r�RunFailedErrorr�r=�	exception�splitrC)rI�exctyperZcaughtrrr�assert_run_failedus�
�z RunStringTests.assert_run_failedc	Cs(|�t��t�|jd�W5QRXdS)Nzprint("spam")r8�SyntaxErrorrrr1rprrr�test_invalid_syntax�sz"RunStringTests.test_invalid_syntaxc	Cs*|�td��t�|jd�W5QRXdS)Nr�zraise Exception("spam"))r8r�rrr1rprrr�test_failure�szRunStringTests.test_failurec	Cs*|�td��t�|jd�W5QRXdS)N�42zraise SystemExit(42))r8�
SystemExitrrr1rprrr�test_SystemExit�szRunStringTests.test_SystemExitc	CsV|�t��t�|jtd��W5QRX|�td��t�|jtd��W5QRXdS)NzG
                import sys
                sys.exit()
                r<zI
                import sys
                sys.exit(42)
                )r8r=rrr1rrprrr�
test_sys_exit�szRunStringTests.test_sys_exitc	Cs�t��\}}dddd�}td|�d��}t�|j||�t|d��}t�|�}W5QRX|�	|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��*rAr�rz�)rB)rrrrrr1r�pickle�loadr�ZassertIsNone�rIr	rr"r�chan�nsrrr�test_with_shared�s��
zRunStringTests.test_with_sharedc	Cs�t�|jtd��ddi}td�}t�|j||�t��\}}td|�d��}t�|j|�t|d��}t�|�}W5QRX|�	|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(rCrD�ns1rA�ns2)
rrr1rrrrrGrHr�)rIr"rr	rrJrKrrr�test_shared_overwrites�s�
z%RunStringTests.test_shared_overwritesc	Csht��\}}ddi}td|�d��}t�|j||�t|d��}t�|�}W5QRX|�	|dd�dS)NrLsnot __main__z�
            spam = 42

            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(rCrD)
rrrrrr1rrGrHr�rIrrr�#test_shared_overwrites_default_vars�s�
	z2RunStringTests.test_shared_overwrites_default_varsc	Cs�t��\}}t�|jtd|�d���t|d��}t�|�}W5QRXt��\}}t�|jtd|�d���t|d��}t�|�}W5QRX|�	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
            rDz�
            eggs = False

            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(rCr�rA)rrrrr1rrrGrHr�r)rIr	rrJrMrNrrr�test_main_reused�s �
�	zRunStringTests.test_main_reusedc
Cs|t��\}}td|�d��}t�|j|�t|d��}t�|�}W5QRX|�	d�|�	d�|�
|diddddd��dS)	Nz�
            spam = 42

            ns = dict(vars())
            ns['__builtins__'] = str(ns['__builtins__'])
            import pickle
            with open(rCrD�__builtins__�
__loader__�__main__rE)rL�__annotations__r��__package__�__spec__r�)rrrrrr1rrGrH�popr�)rIr	rrrJrKrrr� test_execution_namespace_is_mains"�
	

�z/RunStringTests.test_execution_namespace_is_mainzblocking foreverc
CsXtd�}t���2}t�|d|�}t�|��}|��}W5QRXW5QRX|�|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()
        r!r)rrZtemp_dirrZmake_scriptZspawn_python�waitr�)rIr�dirname�filename�proc�retcoderrr�test_still_running_at_exit$s
z)RunStringTests.test_still_running_at_exit)N)'rLrMrNrZSCRIPTZFILENAMEr�r��propertyrr$rr&r
Z
skipUnless�hasattrrr,r.r�r/r�r1r2�
contextlib�contextmanagerr8r:r;r>r?rLrOrPrQrYrr_rPrrrJrrs<




!rc@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�ChannelIDTestscCs0tjddd�}|�t|�d�|�|jd�dS)Nr�TrsrT)r�_channel_idr�r�rW�rIrxrrr�test_default_kwargsBsz"ChannelIDTests.test_default_kwargscCs�tjdddd�}|�|jd�tjddddd�}|�|jd�tjdddd�}|�|jd�tjddddd	�}|�|jd�tjddddd�}|�|jd
�dS)Nr�T�r[rtr[F�r[r\rt�r\rtr\)r\r[rtrT)rrer�rWrfrrr�test_with_kwargsHszChannelIDTests.test_with_kwargscCs4Gdd�dt�}tj|�dd�}|�t|�d�dS)Nc@seZdZdd�ZdS)z*ChannelIDTests.test_coerce_id.<locals>.IntcSsdSr�rrprrrr�Zsz4ChannelIDTests.test_coerce_id.<locals>.Int.__index__Nr�rrrrr�Ysr�Trsr�)r=rrer�r�)rIr�rxrrrr�XszChannelIDTests.test_coerce_idcCsf|�ttjt��|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�dSr�)r�r�rrer�rBr�rprrrr�`szChannelIDTests.test_bad_idc	Cs*|�t��tjdddd�W5QRXdS)Nr�F�r[r\)r�rBrrerprrr�test_bad_kwargshszChannelIDTests.test_bad_kwargsc	Cs6t��}|�tj��t�t|�d�W5QRXdSr�)rr�r�r�rer�rfrrrr�lsz"ChannelIDTests.test_does_not_existcCs"tjddd�}|�t|�d�dSr�)rrer�r=rfrrrr�qszChannelIDTests.test_strcCs�tjddd�}|�t|�d�tjdddd�}|�t|�d�tjdddd�}|�t|�d�tjddddd	�}|�t|�d�dS)
Nr�Trsz
ChannelID(10)rhzChannelID(10, send=True)rjzChannelID(10, recv=True)ri)rrer�r�rfrrrr�uszChannelIDTests.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�rer�r�r�r�r=)rI�cid1�cid2Zcid3rrrr��s$zChannelIDTests.test_equalityN)rLrMrNrgrkr�r�rmr�r�r�r�rrrrrd@s
rdc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Ze�d�dd��Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8S)9�ChannelTestscCst��}|�|tj�dSr)rr�r�Z	ChannelIDrfrrr�test_create_cid�szChannelTests.test_create_cidcCsrt��}t��}t��}t��}t��}|�|t|�d�|�|t|�d�|�t|�t|�|||h�dSr�)rr�r�r�r�r�)rIr
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)
            r)rrEr#rr�r�r�)rIr�r�rnr�rorrr�test_ids_global�szChannelTests.test_ids_globalcCs>t��}d}t�||�t�|�}|�||�|�||�dS�Nr|)rr�r~rr�ZassertIsNot)rIrxZorigr�rrr�test_send_recv_main�s
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
            )rrEr#r)rIr�r�rrr�test_send_recv_same_interpreter�sz,ChannelTests.test_send_recv_same_interpretercCs@t��}t��}t|td|�d���}t�|�}|�|d�dS)N�_
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_send(�, b'spam')
            r|)rr�rEr#rrr�)rIrxr�r�r�rrr�%test_send_recv_different_interpreters�s�
z2ChannelTests.test_send_recv_different_interpreterscsVt����fdd�}tj|d�}|��t��d�|��t���}|�|d�dS)NcsFzt���}Wq6Wqtjk
r2t�d�YqXqt��|�dS)Nr�)rrr��time�sleepr~)r�r�rrr��s
z8ChannelTests.test_send_recv_different_threads.<locals>.fr&r|)	rr�r)r*r+r~r-rr��rIr�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')
                )r#rr�rxr�r�rrr��s
��zIChannelTests.test_send_recv_different_interpreters_and_threads.<locals>.fr&r|�eggs)
rr�rEr)r*r+r~r-rr�r|rr~r�1test_send_recv_different_interpreters_and_threads�s
z>ChannelTests.test_send_recv_different_interpreters_and_threadsc	Cs(|�tj��t�dd�W5QRXdS)Nr�r|)r�rr�r~rprrr�test_send_not_foundsz ChannelTests.test_send_not_foundc	Cs&|�tj��t�d�W5QRXdSr�)r�rr�rrprrr�test_recv_not_foundsz ChannelTests.test_recv_not_foundc	Cs.t��}|�tj��t�|�W5QRXdSr)rr�r�r�rrfrrr�test_recv_emptyszChannelTests.test_recv_emptycCsRt��}t��}t|td�t|jd��}t�|�}|�|d�|�|�	�d�dS)Nz�
            import _xxsubinterpreters as _interpreters
            print(cid.end)
            _interpreters.channel_send(cid, b'spam')
            r�r|r[)
rr�rEr#r�dictr[rr�r��rIrxr!r�r�rrr�test_run_string_arg_unresolveds

�
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)Z_resolvez�
            import _xxsubinterpreters as _interpreters
            print(chan.id.end)
            _interpreters.channel_send(chan.id, b'spam')
            )rJr|r[)rr�rerEr#rr�r[rr�r�r�rrr�test_run_string_arg_resolved.s

�
z)ChannelTests.test_run_string_arg_resolvedc	Csrt��}t�|d�t�|�t�|�|�tj��t�|d�W5QRX|�tj��t�|�W5QRXdS�Nr|r�rr�r~rr�r�rQrfrrr�test_close_single_userAs

z#ChannelTests.test_close_single_userc	Cs�t��}t��}t��}t�|td|�d���t�|td|�d���t�|�|�tj��}t�|td|�d���W5QRX|�dt	|j
��|�tj��}t�|td|�d���W5QRX|�dt	|j
��dS)Nrwrxz_
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_recv(rz,
                _interpreters.channel_send(z, b'spam')
                rQ)rr�rErrr�r�r4r�r=r5)rIrxr�r��cmrrr�test_close_multiple_usersLs(
�
�

�
�z&ChannelTests.test_close_multiple_usersc	CsNt��}t�|d�t�|�t�|�|�tj��t�|�W5QRXdSrtr�rfrrr�test_close_multiple_timesds

z&ChannelTests.test_close_multiple_timescCs�ddddg}|D]�\}}|�||f��zt��}t�|d�t�|�tj|||d�|�tj��t�|d�W5QRX|�tj��t�|�W5QRXW5QRXqdS)N)FF�TF)FT)TTr|rlr)r�rr�r~rr�r�rQ)rIZtestsr[r\rxrrr�test_close_emptyms�
zChannelTests.test_close_emptyc	Cs\t��}t�|d�t�|d�|�tj��t�|�W5QRXt�|�t�|d�dS)Nr|r@r�rr�r~r�ZChannelNotEmptyErrorr�rrfrrr�%test_close_defaults_with_unused_items�s
z2ChannelTests.test_close_defaults_with_unused_itemsc	Cs�t��}t�|d�t�|d�|�tj��tj|dd�W5QRXt�|�t�|d�t�|�t�|�tj|dd�dS)Nr|r@T�r\rr�rfrrr�*test_close_recv_with_unused_items_unforced�s


z7ChannelTests.test_close_recv_with_unused_items_unforcedc	Cs�t��}t�|d�t�|d�tj|dd�|�tj��t�|d�W5QRXt�|�t�|�|�tj��t�|�W5QRXdS)Nr|r@T�r[r�rr�r~r�r�rQrrfrrr�*test_close_send_with_unused_items_unforced�s

z7ChannelTests.test_close_send_with_unused_items_unforcedc	Cs�t��}t�|d�t�|d�|�tj��tj|ddd�W5QRXt�|�t�|d�t�|�t�|�tj|dd�dS)Nr|r@Tr}rr�r�rfrrr�*test_close_both_with_unused_items_unforced�s


z7ChannelTests.test_close_both_with_unused_items_unforcedc	Cszt��}t�|d�t�|d�tj|ddd�|�tj��t�|d�W5QRX|�tj��t�|�W5QRXdS)Nr|r@Trjrr�rfrrr�(test_close_recv_with_unused_items_forced�sz5ChannelTests.test_close_recv_with_unused_items_forcedc	Cszt��}t�|d�t�|d�tj|ddd�|�tj��t�|d�W5QRX|�tj��t�|�W5QRXdS)Nr|r@Trhrr�rfrrr�(test_close_send_with_unused_items_forced�sz5ChannelTests.test_close_send_with_unused_items_forcedc	Cs|t��}t�|d�t�|d�tj|dddd�|�tj��t�|d�W5QRX|�tj��t�|�W5QRXdS)Nr|r@Trirr�rfrrr�(test_close_both_with_unused_items_forced�sz5ChannelTests.test_close_both_with_unused_items_forcedc	Cs\t��}t�|�|�tj��t�|d�W5QRX|�tj��t�|�W5QRXdSrt)rr�r�r�rQr~rrfrrr�test_close_never_used�s
z"ChannelTests.test_close_never_usedc	Cs|t��}t�|d�t��}t�|td|�d���|�tj��t�|�W5QRX|�tj��t�	|�W5QRXdS)Nr|z`
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_close(z, force=True)
            )
rr�r~rErrr�rQrr��rIrxr!rrr�!test_close_by_unassociated_interp�s
�z.ChannelTests.test_close_by_unassociated_interpc	Cs�t��}t�|d�t�|d�t�|d�t�|�tj|dd�|�tj��t�|d�W5QRX|�tj��t�|�W5QRXdS)Nr|Trsrr�rfrrr�-test_close_used_multiple_times_by_single_user�s
z:ChannelTests.test_close_used_multiple_times_by_single_userN) rLrMrNrqrrrsrurvryr}r�r�r�r�r�r
rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrp�s8	
	



	
rpc@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�ChannelReleaseTestsa�
    - main / interp / other
    - run in: current thread / new thread / other thread / different threads
    - end / opposite
    - force / no force
    - used / not used  (associated / not associated)
    - empty / emptied / never emptied / partly emptied
    - closed / not closed
    - released / not released
    - creator (interp) / other
    - associated interpreter not running
    - associated interpreter destroyed
    c	Csxt��}t�|d�t�|�tj|ddd�|�tj��t�|d�W5QRX|�tj��t�|�W5QRXdS�Nr|Trlr�rr�r~r�channel_releaser�rQrfrrr�test_single_user!s
z$ChannelReleaseTests.test_single_usercCsxt��}t��}t��}t�|td|�d���t|td|�d|�d���}t�|td|�d���|�|��d�dS)	Nrwrxze
            import _xxsubinterpreters as _interpreters
            obj = _interpreters.channel_recv(z,)
            _interpreters.channel_release(z+)
            print(repr(obj))
            z+
            _interpreters.channel_release(rzb'spam')rr�rErrr#r�r�)rIrxr�r�r�rrr�test_multiple_users,s
���
�z'ChannelReleaseTests.test_multiple_usersc	Csrt��}t�|d�t�|�t�|�|�tj��t�|d�W5QRX|�tj��t�|�W5QRXdSr�r�rfrrr�test_no_kwargs@s

z"ChannelReleaseTests.test_no_kwargsc	CsZt��}t�|d�t�|�tj|ddd�|�tj��tj|ddd�W5QRXdS)Nr|Trlr�rfrrr�test_multiple_timesKs
z'ChannelReleaseTests.test_multiple_timesc	CsVt��}t�|d�t�|d�tj|ddd�|�tj��t�|�W5QRXdS)Nr|r@Trl)rr�r~r�r�rQrrfrrr�test_with_unused_itemsTsz*ChannelReleaseTests.test_with_unused_itemsc	Cs\t��}t�|�|�tj��t�|d�W5QRX|�tj��t�|�W5QRXdSrt)rr�r�r�rQr~rrfrrr�test_never_used]s
z#ChannelReleaseTests.test_never_usedc	Cs|t��}t�|d�t��}t�|td|�d���t�|�}t�|�|�tj	��t�|d�W5QRX|�
|d�dS)Nr|zb
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_release(rr)rr�r~rErrrr�r�rQr�)rIrxr!r�rrr�test_by_unassociated_interpfs
�

z/ChannelReleaseTests.test_by_unassociated_interpc	CsTt��}t��}t�|td|�d|�d���|�tj��t�|�W5QRXdS)Nze
            import _xxsubinterpreters as _interpreters
            obj = _interpreters.channel_send(z5, b'spam')
            _interpreters.channel_release(r)rr�rErrr�rQrr�rrr�test_close_if_unassociatedus
��z.ChannelReleaseTests.test_close_if_unassociatedcCsRt��}t�|d�t�|�t�|d�tj|dd�t�|�}|�|d�dS)Nr|Tr�)rr�r~rr�r�)rIrxr�rrr�test_partially�s

z"ChannelReleaseTests.test_partiallyc	Cs�t��}t�|d�t�|d�t�|d�t�|�tj|ddd�|�tj��t�|d�W5QRX|�tj��t�|�W5QRXdSr�r�rfrrr�'test_used_multiple_times_by_single_user�s
z;ChannelReleaseTests.test_used_multiple_times_by_single_userN)rLrMrNr�r�r�r�r�r�r�r�r�r�r�rrrrr��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)NrY)�QUICKr;rArHrFrGr��_preppedri�_state�_known)r?rWr!r`ra�creatorZknownrIrJrrrG�s&


�zChannelCloseFixture.__new__cCs|jSr�r�rprrrry�szChannelCloseFixture.statecCs@z|jWStk
r:|�|j�}|�|�|_|jYSXdSr)�_cid�AttributeError�_get_interpreterr��_new_channel)rIr�rrrrx�szChannelCloseFixture.cidcCs|�|�}|�|�|Sr)r��_prep_interpreterr�rrr�get_interpreter�s

z#ChannelCloseFixture.get_interpreterNcCs2|dkr|j}|dkr&|jjdkr&dSt|jj�S)Nr\r[F)rWryrk�boolrfrrr�expect_closed_error�s
z'ChannelCloseFixture.expect_closed_errorcCs|�|�dSr)r�r�rrr�prep_interpreter�sz$ChannelCloseFixture.prep_interpretercCs
||_dSrr�)rIrVrzrrr�
record_action�sz!ChannelCloseFixture.record_actioncCst�t�dSrr�rprrr�clean_up�szChannelCloseFixture.clean_upcCs@|jdkrt��St��}t|jd|�d��t�|�|_|jS)Nr8a
                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
                )rHrr�r3r1rr�)rIr�Zchrrrr��s
�
z ChannelCloseFixture._new_channelcCsl|dkr|jS|dkr|jS|dkr*|jS|}z|j|}Wn&tk
rbt|�}|j|<YnX|SdS)N)rYr!r`ra)r!r`rar��KeyErrorr;)rIr!rHrrrr��sz$ChannelCloseFixture._get_interpretercCsF|j|jkrdS|j�|j�|jdkr,dSt|jd|j�d��dS)Nr8a
            import _xxsubinterpreters as interpreters
            import test.test__xxsubinterpreters as helpers
            ChannelState = helpers.ChannelState
            try:
                cid
            except NameError:
                cid = interpreters._channel_id(r)r1r�r�rHr3rxr�rrrr��s
�z%ChannelCloseFixture._prep_interpreter)N)rLrMrNr�rGr`ryrxr�r�r�r�r�r�r�r�rPrrrJrr��s


r�zend interp other extra creatorz%these tests take several hours to runc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�dd�Z	dd�Z
dd�Zd"dd�Zdd�Z
d#dd�Zdd�Zdd�Zd d!�ZdS)$�ExhaustiveChannelTestsa�
    - main / interp / other
    - run in: current thread / new thread / other thread / different threads
    - end / opposite
    - force / no force
    - used / not used  (associated / not associated)
    - empty / emptied / never emptied / partly emptied
    - closed / not closed
    - released / not released
    - creator (interp) / other
    - associated interpreter not running
    - associated interpreter destroyed

    - close after unbound
    ccs�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)NrYr`ra)�_iter_close_action_sets�_iter_post_close_action_sets�_iter_use_action_sets)rIZcloseactionsZpostactionsZ
useactions�actionsrrr�iter_action_sets7sB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)NrXr\r[�rS)rI�interp1�interp2�interpsZinterp3Zinterp4rrrr�ds>
�
�

�
�
�

�


�



�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)Nr}r�r_r^r]r\r[r�)
rIr�r�Zendsr�rt�opr!rWZrecvopZsendopr\r[rrrr��s
�

�z.ExhaustiveChannelTests._iter_close_action_setsccs.dD]$}tdd|�gVtdd|�gVqdS)N)rYrar`rXr\r[r�r�rrrr��s

�
�z3ExhaustiveChannelTests._iter_post_close_action_setscCs|D]}|�||�qdSr)r{)rI�fixr�rVrrr�run_actions�sz"ExhaustiveChannelTests.run_actionsTrucCs�|�|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)Nr8ruzB
                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�)rlrk)rgrWrhr!r`rar�rHr{rxrVryr�rr�r3r1r�rir��
from_bytesrr�)rIr�rVrvrWr!rzr�rrrr{�sB

��������
�z!ExhaustiveChannelTests.run_actionc	csFddddg}|D]0\}}}dD] }dD]}t|||||�Vq&qqdS)N)r8r!ra)r!r8ra)r�r�ra)r�r�r8)rYr`r�rl)r�)rIrr!r`rar�rWrrr�
iter_fixtures�s�z$ExhaustiveChannelTests.iter_fixturesc	Cs`|rdnd}t||jd�}|��s4|j||dd�n(|�tj��|j||dd�W5QRXdS)Nr_r^rYFru)rSrWr�r{r�rrQ)rIr�rtr�r^rrr�_close�szExhaustiveChannelTests._closeNc	Cs�|dks|jdkr�|�tj��t�|j�W5QRX|�tj��t�|jd�W5QRX|�tj��t�|j�W5QRX|�tj��tj|jdd�W5QRXn0t|j	d�t|j	d�t|j	d�t|j	d�dS)	Nr8r|Trszz
                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)
                )
rHr�rrQrrxr~r�r3r1)rIr�r!rrr�_assert_closed_in_interp�sz/ExhaustiveChannelTests._assert_closed_in_interpcCs||�|jj�t|jj�D]}t�|j�q|�|�dD]&}|�	|�}|j
dkrTq:|�||�q:|�	d�}|�||�dS)N)rYr`r8Zfresh)r�ryrkrrlrrrxr�r�rH)rIr�r�r!rrr�_assert_closeds



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)Nrrr��z({} actions)� r�re�.z---)r��printr�rCrr��stdoutr*)rI�verboser�r�r�rrr�_iter_close_testss&

z(ExhaustiveChannelTests._iter_close_testscCsdt_|��D]
\}}}qdS)NT)r�r�r��rIr�r�r�rrr�_skim_close_tests-sz(ExhaustiveChannelTests._skim_close_testsc
Csp|��D]b\}}}|�d�|||���6|�|j�|�||�|j|dd�|�|�W5QRX|��qdS)N�	{} {}  {}Frs�	r�r�rCr�r!r�r�r�r�r�rrr�
test_close2sz!ExhaustiveChannelTests.test_closec
Csp|��D]b\}}}|�d�|||���6|�|j�|�||�|j|dd�|�|�W5QRX|��qdS)Nr�Trsr�r�rrr�test_force_close>sz'ExhaustiveChannelTests.test_force_close)N)F)rLrMrNr�r�r�r�r�r�r{r�r�r�r�r�r�r�r�rrrrr�s(-1	 
	

r�rT)N)6�collectionsrrbrrrGr��textwraprr)rzr
�testrZtest.supportr�
import_modulerrrr#rcr/r3r0r:r;rRrSrir{rwr�r�ZTestCaser�r�r�r�r�r�r�r�r�rrrdrpr�r�rr�rLr8rrrr�<module>sr


&
	3$

2?(;]b<Y_&�q@


F1le Man4ger