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

�i�;�@sjddlmZddlZddlZddlZddlZddlZddlmZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZe�d�Zdd	�ZdLd
d�ZdLdd
�Zejdd��Zdd�Zifdd�ZGdd�dedd��Zejdd��ZGdd�dedd��ZGdd�dedd��Zdd �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%Gd/d0�d0e#�Z&Gd1d2�d2e#�Z'Gd3d4�d4e#�Z(Gd5d6�d6e#�Z)Gd7d8�d8e#�Z*Gd9d:�d:e#�Z+Gd;d<�d<e#�Z,Gd=d>�d>e#�Z-Gd?d@�d@e#�Z.GdAdB�dBe#�Z/GdCdD�dDe#�Z0GdEdF�dFedFdG��Z1e�2dH�GdIdJ�dJe#��Z3e4dKk�r3e�5�dSdS)M�)�
namedtupleN)�dedent)�support)�
import_helper)�
script_helperZ_xxsubinterpreterscCs>t��\}}|�dd�}td|�d|�d��}|t|dd�fS)N�
z
                z-
        import contextlib
        with open(zg, 'w', encoding="utf-8") as spipe:
            with contextlib.redirect_stdout(spipe):
                z	
        �utf-8��encoding)�os�pipe�replacer�open)�script�r�wZindented�wrapped�r�9/usr/local/lib/python3.10/test/test__xxsubinterpreters.py�_captured_scripts�
�rcCsJt|�\}}|�t�|||�|��Wd�S1swYdS�N)r�interpreters�
run_string�read)�interpZrequest�sharedrZrpiperrr�_run_output#s
$�rcCsX|durtj}t��}||}t�|�s*t��|krtd��t�d�t�|�rdSdS)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|ddd��
}|�d�Wd�n1s6wY|��dS)Ncst��td��d���dS)Nz7
            # wait for "signal"
            with open(zG, encoding="utf-8") as rpipe:
                rpipe.read()
            )rrrr�rrrr�run;s
�z_running.<locals>.run��targetrrr	�done)	rr�	threading�Thread�startr$r�write�join)rrr&�tZspiperr%r�_running8s��r0cKst|||�dSr)�_run_interp)�id�sourcerrrr�
run_interpWsr4cCsHt|�}t��}||krt��|krt�t||�dSt�|||�dSr)rr�get_main�get_currentr �execr)r2r3rZ_mainns�mainrrrr1[sr1cs*eZdZedd��Zd�fdd�	Z�ZS)�InterpretercCs$t||�r|St|t�r||�St�r)�
isinstance�str�NotImplementedError)�cls�rawrrr�from_rawis


zInterpreter.from_rawNcs�t��}||kr|s
d}n|dkrtd�|���|}n,|dur8|s$d}n|dkr,td��t|tj�s7t�|�}n|r>|dkrCd}|}nt��}t��|||�}|S)Nr8z)name mismatch (expected "main", got "{}")rz!name mismatch (unexpected "main"))	rr5�
ValueError�formatr:�
InterpreterID�create�super�__new__)r=�namer2r8�self��	__class__rrrErs.�
�zInterpreter.__new__�NN)�__name__�
__module__�__qualname__�classmethodr?rE�
__classcell__rrrHrr9gs
r9zname idccs&�zdVWdStjyYdSwr)r�ChannelClosedErrorrrrr�expect_channel_closed�s��rQcs6eZdZd
�fdd�	Zdd�Zdd�Zdd	�Z�ZS)�
ChannelActionNcs&|sd}|sd}t��||||�}|S)N�bothr8�rDrE)r=�action�endrrGrHrrrE�szChannelAction.__new__cOsb|jdkr|jdvrt|j��n|jdvr |jdvrt|j��nt|j��|jdvr/t|j��dS)N�use)�same�opposite�send�recv��close�force-close)rSrXrYrZr[)r8rX�other�extra)rUrVr@r)rG�args�kwargsrrr�__init__�s


�


�


�zChannelAction.__init__cCs.|jdkr|S|jdkr|dkrdSdS|jS)NrXrYrZr[�rV�rGrVrrr�resolve_end�s


zChannelAction.resolve_endcCst|jdkr|S|jdkr|durt�|S|jdkr!|durt�|S|jdkr8|jdkr-|S|r6|jdkr6|St�dS)NrXr_r`r8)rr rF)rGrr_r`rrr�resolve_interp�s"




�zChannelAction.resolve_interprJ)rKrLrMrErcrfrgrOrrrHrrR�s
rRzaction end interpcsBeZdZddd��fdd�Zdd�Zdd	�Zd
d�dd
�Z�ZS)�ChannelStaterF��closedcst��|||�}|SrrT)r=�pendingrjrGrHrrrE�szChannelState.__new__cCst|�|jd|jd�S�N�ri��typerkrj�rGrrr�incr��zChannelState.incrcCst|�|jd|jd�Srlrnrprrr�decr�rrzChannelState.decrT��forcecCs8|jr|r
|jdkr|St|�|rddd�S|jdd�S)NrTri)rjrkro)rGrurrrr]�s zChannelState.close)r)rKrLrMrErqrsr]rOrrrHrrh�s
rhzpending closedT��
hideclosedcCst|jr|dkr|dkr|jrd}nd}nd}z	t||||�}Wntjy3|s,|s,�|��}Y|Sw|r8d�|S)NrWr[FT.)rjrk�_run_actionrrPr])�cidrUrV�staterwZ
expectfail�resultrrr�
run_action�s 
�r|cCs�|dkr=|dkrt�|d�|��S|dkr9|js0z
t�|�Wtd��tjy/|YSwt�|�|��St|��|dkrXi}|dvrKd||<tj	|fi|��|�
�S|d	krwd
di}|dvrhd||<tj	|fi|��|j
dd�St|��)NrWrZ�spamr[zexpected ChannelEmptyErrorr]�r[rZTr^rurt)r�channel_sendrqrk�channel_recv�ChannelEmptyError�	Exceptionrsr@�
channel_closer])ryrUrVrzrbrrrrx�s:��
�rxc	Cs<t��D]}|dkrqzt�|�WqtyYqwdS)Nr)r�list_all�destroyr �r2rrr�clean_up_interpreterss��r�c	Cs4t��D]}zt�|�WqtjyYqwdSr)r�channel_list_all�channel_destroy�ChannelNotFoundError�ryrrr�clean_up_channels s��r�c@�eZdZdd�ZdS)�TestBasecC�t�t�dSr�r�r�rprrr�tearDown*�
zTestBase.tearDownN)rKrLrMr�rrrrr�(sr�c@�eZdZdd�Zdd�ZdS)�IsShareableTestsc	CsPgd�}|D]}|�|��|�t�|��Wd�n1s wYqdS)N)Nr}�spam�
i����)�subTest�
assertTruer�is_shareable)rGZ
shareables�objrrr�test_default_shareables4s	����z(IsShareableTests.test_default_shareablesc
Cs�Gdd�d�}Gdd�dt�}ddtdttt�t�d||d	�|d
�g}|D]!}|�t|���|�t�	|��Wd�n1sAwYq%dS)Nc@r�)z3IsShareableTests.test_not_shareable.<locals>.CheesecSs
||_dSr�rF)rGrFrrrrcE�
z<IsShareableTests.test_not_shareable.<locals>.Cheese.__init__cS�|jSrr�rprrr�__str__Gsz;IsShareableTests.test_not_shareable.<locals>.Cheese.__str__N)rKrLrMrcr�rrrr�CheeseDsr�c@seZdZdZdS)z5IsShareableTests.test_not_shareable.<locals>.SubByteszA subclass of a shareable type.N)rKrLrM�__doc__rrrr�SubBytesJsr�TF.gY@ZWensleydaler})
�bytes�NotImplementedro�objectr�r��repr�assertFalserr�)rGr�r�Znot_shareablesr�rrr�test_not_shareableCs.�����z#IsShareableTests.test_not_shareableN)rKrLrMr�r�rrrrr�2sr�cs`eZdZ�fdd�Z�fdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Z�ZS)�ShareableTypeTestsc�t���t��|_dSr)rD�setUpr�channel_createryrprHrrr�f�
zShareableTypeTests.setUpcst�|j�t���dSr)rr�ryrDr�rprHrrr�jszShareableTypeTests.tearDownc	Csr|D]4}|�|��%t�|j|�t�|j�}|�||�|�t|�t|��Wd�n1s1wYqdSr)r�rrryr��assertEqual�assertIsro)rG�valuesr��gotrrr�_assert_valuesns���z!ShareableTypeTests._assert_valuesc	Cs^dD]*}|�|��t�|j|�t�|j�}|�||�Wd�n1s'wYqdS)Nr)r�rrryr�r�)rGr�r�rrr�test_singletonsys���z"ShareableTypeTests.test_singletonscCs|�dd|jg�dS)Nr}i')r�ryrprrr�
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��rangerprrr�
test_bytes�s
�zShareableTypeTests.test_bytescCs|�gd��dS)N)zhello worldu你好世界�)r�rprrr�	test_strs��zShareableTypeTests.test_strscCs*|�t�tdd�tjtjdg��dS)Nr�r�rm)r��	itertools�chainr��sys�maxsizerprrr�test_int�s
�zShareableTypeTests.test_intc
Cs�tjdtjdddg}|D]3}|�|��$|�t��t�|j|�Wd�n1s/wYWd�n1s>wYqdS)Nrmr���)r�r�r��assertRaises�
OverflowErrorrrry)rGZintsr�rrr�test_non_shareable_int�s
������z)ShareableTypeTests.test_non_shareable_int)
rKrLrMr�r�r�r�r�r�r�r�r�rOrrrHrr�ds	r�c@s$eZdZdd�Zdd�Zdd�ZdS)�ListAllTestscCs"t��}t��}|�||g�dSr)rr5r�r�)rGr8�idsrrr�test_initial�szListAllTests.test_initialcCs6t��}t��}t��}t��}|�||||g�dSr)rr5rCr�r��rGr8�first�secondr�rrr�test_after_creating�s
z ListAllTests.test_after_creatingcCs>t��}t��}t��}t�|�t��}|�|||g�dSr)rr5rCr�r�r�r�rrr�test_after_destroying�s
z"ListAllTests.test_after_destroyingN)rKrLrMr�r�r�rrrrr��sr�c@r�)�GetCurrentTestscCs.t��}t��}|�||�|�|tj�dSr)rr5r6r��assertIsInstancerB)rGr8�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)
            )
rr5rCrr�int�stripr�r�ZassertNotEqual)rGr8r�outr��_�expectedrrr�test_subinterpreter�sz#GetCurrentTests.test_subinterpreterN)rKrLrMr�r�rrrrr���r�c@r�)�GetMainTestscCs0t��\}t��}|�||�|�|tj�dSr)rr�r5r�r�rB)rGr�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�rCrrr�r�r�)rGr�rr�r8rrr�test_from_subinterpreter�s

z%GetMainTests.test_from_subinterpreterN)rKrLrMr�r�rrrrr��r�r�c@sFeZdZdd�Ze�d�dd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dS)�IsRunningTestscCst��}|�t�|��dSr)rr5r�r)rGr8rrrr��szIsRunningTests.test_mainzFails on FreeBSDcCsdt��}|�t�|��t|��|�t�|��Wd�n1s#wY|�t�|��dSr)rrCr�rr0r��rGrrrrr��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)rrCrrr�r�)rGrr�rrrr��s
�z'IsRunningTests.test_from_subinterpretercCsLt��}t�|�|�t��t�|�Wd�dS1swYdSr)rrCr�r�r rr�rrr�test_already_destroyed�

"�z%IsRunningTests.test_already_destroyedcC�:|�t��t�d�Wd�dS1swYdS�Ni@B)r�r rrrprrr�test_does_not_exist�"�z"IsRunningTests.test_does_not_existcCr��Nr�)r�r@rrrprrr�test_bad_id
r�zIsRunningTests.test_bad_idN)rKrLrMr��unittest�skipr�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�Trt)rrBr�r��rGr2rrr�
test_with_intsz InterpreterIDTests.test_with_intcC�4Gdd�dt�}tj|�dd�}|�t|�d�dS)Nc@r�)z.InterpreterIDTests.test_coerce_id.<locals>.IntcS�dS�Nr�rrprrr�	__index__�z8InterpreterIDTests.test_coerce_id.<locals>.Int.__index__N�rKrLrMr�rrrr�Int�r�Trtr�)r;rrBr�r�)rGr�r2rrr�test_coerce_id�z!InterpreterIDTests.test_coerce_idcC�f|�ttjt��|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�dS�Ng$@�10s10r�l)r��	TypeErrorrrBr�r@r�rprrrr��zInterpreterIDTests.test_bad_idcCsJt��}|�t��t�t|�d�Wd�dS1swYdS�Nrm)rr�r�r rBr�r�rrrr�&s"�z&InterpreterIDTests.test_does_not_existcC�"tjddd�}|�t|�d�dS�Nr�Trtr�)rrBr�r;r�rrr�test_str+�zInterpreterIDTests.test_strcCr)Nr�TrtzInterpreterID(10))rrBr�r�r�rrr�	test_repr/rzInterpreterIDTests.test_reprcC�(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�)rrCrBr�r��floatr�r;�rG�id1�id2�id3rrr�
test_equality3�$z InterpreterIDTests.test_equalityN)
rKrLrMr�r�r�r�rrrrrrrr�sr�c@sNeZdZdd�Ze�d�dd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�ZdS)�CreateTestscCs*t��}|�|tj�|�|t���dSr)rrCr�rB�assertInr�r�rrr�test_in_mainLszCreateTests.test_in_mainz*enable this test when working on pystate.ccCsDt�}td�D]}t��}t�|�|�|�q|�t|�d�dS)N�d)�setr�rrCr��addr��len)rG�seenr�r2rrr�test_unique_idRs
zCreateTests.test_unique_idcsnt���d���fdd�}tj|d�}��|��Wd�n1s$wY|��|��t���dS)Ncst���������dSr)rrC�acquire�releaser�r2�lockrr�f_sz%CreateTests.test_in_thread.<locals>.fr')r*�Lockr+r,r.rrr��rGrr/rrr�test_in_thread\s
�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�rCrrr�r�r�r)rGr8r
r�rrrr�test_in_subinterpreterks

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
rrrr|sz6CreateTests.test_in_threaded_subinterpreter.<locals>.fr')	rr�rCr*r+r,r.r�r)rGr8rr/rr$r�test_in_threaded_subinterpreterxs
	z+CreateTests.test_in_threaded_subinterpretercCsjtt���}g}td�D]}t��}|�|�q|D]}t�|�qt��}|�tt���||hB�dS�N�)rrr�r�rC�appendr�r��rG�beforer�r�r2rrr�test_after_destroy_all�sz"CreateTests.test_after_destroy_allcCs`tt���}t��}t��}t��}t�|�t�|�t��}|�tt���|||hB�dSr)rrr�rCr�r�)rGr*r
rrr2rrr�test_after_destroy_some�s

 z#CreateTests.test_after_destroy_someN)rKrLrMrr�r�rr"r#r%r+r,rrrrrJs
	
rc@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)rrCrr�r��assertNotInrrrr�test_one�s
zDestroyTests.test_onecCsvtt���}t�}td�D]}t��}|�|�q
|�tt���||B�|D]}t�|�q'|�tt���|�dSr&)rrr�r�rCrr�r�r)rrr�test_all�szDestroyTests.test_allcslt��\���t��
t���Wd�n1swY��fdd�}tj|d�}|��|��dS)Ncs:��t��t���Wd�dS1swYdSr�r�r rr�r�r8rGrrr�r�z!DestroyTests.test_main.<locals>.fr')	rr�r�r r�r*r+r,r.r!rr2rr��s
�zDestroyTests.test_maincCsLt��}t�|�|�t��t�|�Wd�dS1swYdSr)rrCr�r�r r�rrrr��r�z#DestroyTests.test_already_destroyedcCr�r�r1rprrrr��r�z DestroyTests.test_does_not_existcCr�r�)r�r@rr�rprrrr��r�zDestroyTests.test_bad_idcCsJt��\}t��}td|�d��}t�||�|�tt���||h�dS)Nzo
            import _xxsubinterpreters as _interpreters
            try:
                _interpreters.destroy(zD)
            except RuntimeError:
                pass
            �rr�rCrrr�r)rGr8r2rrrr�test_from_current�s

�zDestroyTests.test_from_currentcCsRt��\}t��}t��}td|�d��}t�||�|�tt���||h�dS)NzZ
            import _xxsubinterpreters as _interpreters
            _interpreters.destroy(�)
            r3)rGr8r
rrrrr�test_from_sibling�s

�zDestroyTests.test_from_siblingcs4t����fdd�}tj|d�}|��|��dS)Ncst���dSr)rr�rr�rrr��z.DestroyTests.test_from_other_thread.<locals>.fr')rrCr*r+r,r.r!rr�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�n1s7wY|�t�|��Wd�dS1sOwYdS)NzInterp z& should be running before destruction.)�msgz%Should not be able to destroy interp z while it's still running.)	rr�rCr0r�rr�r r�)rGr8rrrr�test_still_running�s


�
��"�zDestroyTests.test_still_runningN)
rKrLrMr/r0r�r�r�r�r4r6r8r:rrrrr-�s

	r-cs�eZdZ�fdd�Zdd�Zdd�Zdd�Ze�e	e
d	�d
�dd��Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zejd1dd��Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Ze�d.�d/d0��Z�Z S)2�RunStringTestscr�r)rDr�rrCr2rprHrrr�r�zRunStringTests.setUpcCsVtd�\}}|�t�|j|�|��}Wd�n1swY|�|d�dS)N�print("it worked!", end="")�
it worked!)rrrr2rr�)rGr�filer�rrr�test_successs
�zRunStringTests.test_successcsrtd�\�}|�!��fdd�}tj|d�}|��|��|��}Wd�n1s,wY��|d�dS)Nr<cst��j��dSr)rrr2r�rrGrrrr�z(RunStringTests.test_in_thread.<locals>.fr'r=)rr*r+r,r.rr�)rGr>rr/r�rr@rr"s
�	zRunStringTests.test_in_threadcCs`tjdd�}td�\}}|�t�||�|��}Wd�n1s#wY|�|d�dS)NF)�isolatedz�
            import threading
            def f():
                print('it worked!', end='')

            t = threading.Thread(target=f)
            t.start()
            t.join()
            r=)rrCrrrr�)rGZ	subinterprr>r�rrr�test_create_thread$s	
�z!RunStringTests.test_create_thread�forkztest needs os.fork()cCs�ddl}|jddd��6}|�d�|��d}td|j�d|�d	��}t�|j|�|�	d�|�
�}|�||�Wd�dS1sDwYdS)
Nrzw+rr	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')
                )�tempfile�NamedTemporaryFiler-�flushrrFrrr2�seekrr�)rGrDr>r�rZcontentrrr�	test_fork5s
�
�
"�zRunStringTests.test_forkc	Csxt|j��-|�t��t�|jd�Wd�n1swYWd�dSWd�dS1s5wYdS)N�
print("spam"))r0r2r�r rrrprrr�test_already_runningKs��"�z#RunStringTests.test_already_runningcCs`d}|t��vr|d7}|t��vs|�t��t�|d�Wd�dS1s)wYdS)NrrmrI)rr�r�r rr�rrrr�Ps�"�z"RunStringTests.test_does_not_existcC�<|�t��t�dd�Wd�dS1swYdS)Nr�rI)r�r@rrrprrr�
test_error_idW�"�zRunStringTests.test_error_idcCrK)Nr�rI)r�r�rrrprrrr�[rMzRunStringTests.test_bad_idcC�>|�t��t�|jd�Wd�dS1swYdSr��r�r�rrr2rprrr�test_bad_script_�"�zRunStringTests.test_bad_scriptcCrN)Ns
print("spam")rOrprrr�test_bytes_for_scriptcrQz$RunStringTests.test_bytes_for_scriptNccs~�|�tj��}dVWd�n1swY|dur0|�t|j��d�dt|��dS|�t|j�d�||��dS)N�:rz{}: {})r�r�RunFailedErrorr�r;�	exception�splitrA)rG�exctyper9Zcaughtrrr�assert_run_failedgs���
�z RunStringTests.assert_run_failedcCrN)Nzprint("spam")rX�SyntaxErrorrrr2rprrr�test_invalid_syntaxrs"�z"RunStringTests.test_invalid_syntaxcC�@|�td��t�|jd�Wd�dS1swYdS)Nr�zraise Exception("spam"))rXr�rrr2rprrr�test_failurew�"�zRunStringTests.test_failurecCr[)N�42zraise SystemExit(42))rX�
SystemExitrrr2rprrr�test_SystemExit{r]zRunStringTests.test_SystemExitcCs�|�t��t�|jtd��Wd�n1swY|�td��t�|jtd��Wd�dS1s9wYdS)NzG
                import sys
                sys.exit()
                r^zI
                import sys
                sys.exit(42)
                )rXr_rrr2rrprrr�
test_sys_exits�"�zRunStringTests.test_sys_exitcCs�t��\}}dddd�}td|�d��}t�|j||�t|d��
}t�|�}Wd�n1s1wY|�	|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��*rcr�r{�)rd)rrrrrr2r�pickle�loadr�ZassertIsNone�rGrrrr�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�n1sCwY|�	|ddd	�|�	|d
dd�|�	|dd�dS)Nzj
            spam = 'eggs'
            ns1 = dict(vars())
            del ns1['__builtins__']
            r�rbzL
            ns2 = dict(vars())
            del ns2['__builtins__']
        zr
            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(rerf�ns1rc�ns2)
rrr2rrrrrirjr�)rGrrrrrlrmrrr�test_shared_overwrites�s
��z%RunStringTests.test_shared_overwritescCs|t��\}}ddi}td|�d��}t�|j||�t|d��
}t�|�}Wd�n1s/wY|�	|dd�dS)NrKsnot __main__z�
            spam = 42

            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(rerf)
rrrrrr2rrirjr�rkrrr�#test_shared_overwrites_default_vars�s
�	�z2RunStringTests.test_shared_overwrites_default_varscCs�t��\}}t�|jtd|�d���t|d��
}t�|�}Wd�n1s(wYt��\}}t�|jtd|�d���t|d��
}t�|�}Wd�n1sUwY|�	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
            rfz�
            eggs = False

            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(rer�rc)rrrrr2rrrirjrr.)rGrrrlrorprrr�test_main_reused�s$�
��	�zRunStringTests.test_main_reusedc
Cs�t��\}}td|�d��}t�|j|�t|d��
}t�|�}Wd�n1s*wY|�	d�|�	d�|�
|diddddd��dS)	Nz�
            spam = 42

            ns = dict(vars())
            ns['__builtins__'] = str(ns['__builtins__'])
            import pickle
            with open(rerf�__builtins__�
__loader__�__main__rg)rK�__annotations__r��__package__�__spec__r�)rrrrrr2rrirj�popr�)rGrrrrlrmrrr� test_execution_namespace_is_main�s$
�	�

�z/RunStringTests.test_execution_namespace_is_mainzblocking foreverc	Cs�td�}t���(}t�|d|�}t�|��}|��}Wd�n1s$wYWd�n1s3wY|�|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�)rGr�dirname�filename�proc�retcoderrr�test_still_running_at_exits

���z)RunStringTests.test_still_running_at_exitr)!rKrLrMr�r?r"rBr�Z
skipUnless�hasattrrrHrJr�rLr�rPrR�
contextlib�contextmanagerrXrZr\r`rarnrqrrrsr{r�r�rOrrrHrr;	s4



!r;c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�ChannelIDTestscCs0tjddd�}|�t|�d�|�|jd�dS)Nr�TrtrS)r�_channel_idr�r�rV�rGryrrr�test_default_kwargs4sz"ChannelIDTests.test_default_kwargscCs�tjdddd�}|�|jd�tjddddd�}|�|jd�tjdddd�}|�|jd�tjddddd	�}|�|jd�tjddddd�}|�|jd
�dS)Nr�T�rZrurZF�rZr[ru�r[rur[)r[rZrurS)rr�r�rVr�rrr�test_with_kwargs:szChannelIDTests.test_with_kwargscCr�)Nc@r�)z*ChannelIDTests.test_coerce_id.<locals>.IntcSr�r�rrprrrr�Lr�z4ChannelIDTests.test_coerce_id.<locals>.Int.__index__Nr�rrrrr�Kr�r�Trtr�)r;rr�r�r�)rGr�ryrrrr�Jr�zChannelIDTests.test_coerce_idcCr�r�)r�r�rr�r�r@r�rprrrr�RrzChannelIDTests.test_bad_idcCs@|�t��tjdddd�Wd�dS1swYdS)Nr�F�rZr[)r�r@rr�rprrr�test_bad_kwargsZs"�zChannelIDTests.test_bad_kwargscCsLt��}|�tj��t�t|�d�Wd�dS1swYdSr)rr�r�r�r�r�r�rrrr�^s"�z"ChannelIDTests.test_does_not_existcCrr)rr�r�r;r�rrrrcrzChannelIDTests.test_strcCs�tjddd�}|�t|�d�tjdddd�}|�t|�d�tjdddd�}|�t|�d�tjddddd	�}|�t|�d�dS)
Nr�Trtz
ChannelID(10)r�zChannelID(10, send=True)r�zChannelID(10, recv=True)r�)rr�r�r�r�rrrrgszChannelIDTests.test_reprcCrr)rr�r�r�r�rr�r;)rG�cid1�cid2Zcid3rrrrtrzChannelIDTests.test_equalityN)rKrLrMr�r�r�r�r�r�rrrrrrrr�2s
r�c@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	ChannelIDr�rrr�test_create_cid��zChannelTests.test_create_cidcCsrt��}t��}t��}t��}t��}|�|t|�d�|�|t|�d�|�t|�t|�|||h�dSr)rr�r�r�r�r)rGr*r
rrZafterrrr�test_sequential_ids�s"z 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)
            rm)rrCrrr�r�r�)rGr
r�r�rr�rrr�test_ids_global�szChannelTests.test_ids_globalcCs@t��}tj|dd�}tj|dd�}|�|g�|�|g�dS)z=Test listing interpreters for a channel with no associations.T�rZFN)rr��channel_list_interpretersr�)rGry�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)z(Test basic listing channel interpreters.rZTr�F�e
            import _xxsubinterpreters as _interpreters
            obj = _interpreters.channel_recv(r5N)	rr5r�rr�r�rCrr)rG�interp0ryr�r��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�d	S)
z?Test listing interpreters for a channel with many associations.rZ�_
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_send(z, "send")
            r�r5Tr�FN)
rr5rCr�rrrr�r�r)rGr�r��interp2�interp3ryr�r�rrr�'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)z?Test listing channel interpreters with a destroyed interpreter.rZr�r5Tr�FN)
rr5rCr�rrrr�r�r��rGr�r�ryr�r�rrr�(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)z:Test listing channel interpreters with a released channel.�datar�r5Tr�Frmr�r�b
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_release(N)rr5rCr�rrrr�r�r�channel_release)rGr�r�r�ryr�r�rrr�'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�n1sOwY|�	tj
��tj|dd�Wd�dS1smwYdS)	z8Test listing channel interpreters with a closed channel.rZTr�FrmrrtN)rr5rCr�rr�r�rr�r�rPr�rrr�%test_channel_list_interpreters_closed*s�"�z2ChannelTests.test_channel_list_interpreters_closedcCsVt��}t��}t��}t�|d�tj|dd�}tj|dd�}|�t|�d�|�t|�d�tj|dd�|�	tj
��tj|dd�Wd�n1sOwYtj|dd�}|�t|�d�t|td|�d	���|�	tj
��tj|dd�Wd�n1s�wY|�	tj
��tj|dd�Wd�dS1s�wYdS)
zCTest listing channel interpreters with a channel's send end closed.rZTr�FrmrN�`
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_close(�, force=True)
            )
rr5rCr�rr�r�rr�r�rPrrr�rrr�.test_channel_list_interpreters_closed_send_end@s.���"�z;ChannelTests.test_channel_list_interpreters_closed_send_endcCs>t��}d}t�||�t�|�}|�||�|�||�dS�Nr})rr�rr�r�ZassertIsNot)rGryZorigr�rrr�test_send_recv_mainds
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
            )rrCrr)rGr
r�rrr�test_send_recv_same_interpretermr�z,ChannelTests.test_send_recv_same_interpretercCs@t��}t��}t|td|�d���}t�|�}|�|d�dS)Nr��, b'spam')
            r})rr�rCrrr�r�)rGryr
r�r�rrr�%test_send_recv_different_interpretersys�
z2ChannelTests.test_send_recv_different_interpreterscsVt����fdd�}tj|d�}|��t��d�|��t���}|�|d�dS)NcsB	zt���}Wntjyt�d�Ynwqt��|�dS)NTr	)rr�r�rr!r)r�r�rrr�s
��z8ChannelTests.test_send_recv_different_threads.<locals>.fr'r})	rr�r*r+r,rr.r�r��rGrr/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�ryr
r�rrr�s
�
�zIChannelTests.test_send_recv_different_interpreters_and_threads.<locals>.fr'r}�eggs)
rr�rCr*r+r,rr.r�r�r�rr�r�1test_send_recv_different_interpreters_and_threads�s
z>ChannelTests.test_send_recv_different_interpreters_and_threadscCs>|�tj��t�dd�Wd�dS1swYdS)Nr�r})r�rr�rrprrr�test_send_not_found�s"�z ChannelTests.test_send_not_foundcCs<|�tj��t�d�Wd�dS1swYdSr�)r�rr�r�rprrr�test_recv_not_found�s"�z ChannelTests.test_recv_not_foundcCsDt��}|�tj��t�|�Wd�dS1swYdSr)rr�r�r�r�r�rrr�test_recv_empty�s"�zChannelTests.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)Nrmr}r�)r�rr�r�rr�r�)	rG�defaultryZobj1�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�r}rZ)
rr�rCrr�dictrZr�r�r��rGryrr�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)Z_resolvez�
            import _xxsubinterpreters as _interpreters
            print(chan.id.end)
            _interpreters.channel_send(chan.id, b'spam')
            )rlr}rZ)rr�r�rCrrr�rZr�r�r�r�rrr�test_run_string_arg_resolved�s

�
z)ChannelTests.test_run_string_arg_resolvedcC�t��}t�|d�t�|�t�|�|�tj��t�|d�Wd�n1s+wY|�tj��t�|�Wd�dS1sGwYdS�Nr}r��rr�rr�r�r�rPr�rrr�test_close_single_user��

�"�z#ChannelTests.test_close_single_usercCst��}t��}t��}t�|td|�d���t�|td|�d���t�|�|�tj��}t�|td|�d���Wd�n1sFwY|�dt	|j
��|�tj��}t�|td|�d���Wd�n1sqwY|�dt	|j
��dS)Nr�r�z_
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_recv(r5z,
                _interpreters.channel_send(z, b'spam')
                rP)rr�rCrrr�r�rTrr;rU)rGryr
r�cmrrr�test_close_multiple_userss,
�
�

��
��z&ChannelTests.test_close_multiple_userscCsdt��}t�|d�t�|�t�|�|�tj��t�|�Wd�dS1s+wYdSr�r�r�rrr�test_close_multiple_timess

"�z&ChannelTests.test_close_multiple_timesc
Cs�gd�}|D]i\}}|�||f��Vt��}t�|d�t�|�tj|||d�|�tj��t�|d�Wd�n1s@wY|�tj��
t�|�Wd�n1s[wYWd�n1sjwYqdS)N))FF�TF)FT)TTr}r�r�)r�rr�rr�r�r�rP)rGZtestsrZr[ryrrr�test_close_empty's"
������zChannelTests.test_close_emptycCspt��}t�|d�t�|d�|�tj��
t�|�Wd�n1s&wYt�|�t�|d�dS)Nr}rbr��rr�rr�ZChannelNotEmptyErrorr�r�r�rrr�%test_close_defaults_with_unused_items:s�
z2ChannelTests.test_close_defaults_with_unused_itemscCs�t��}t�|d�t�|d�|�tj��tj|dd�Wd�n1s(wYt�|�t�|d�t�|�t�|�tj|dd�dS)Nr}rbT�r[r�r�r�rrr�*test_close_recv_with_unused_items_unforcedDs�


z7ChannelTests.test_close_recv_with_unused_items_unforcedcCs�t��}t�|d�t�|d�tj|dd�|�tj��t�|d�Wd�n1s.wYt�|�t�|�|�tj��t�|�Wd�dS1sTwYdS)Nr}rbTr�r��rr�rr�r�rPr�r�rrr�*test_close_send_with_unused_items_unforcedQs�

"�z7ChannelTests.test_close_send_with_unused_items_unforcedcCs�t��}t�|d�t�|d�|�tj��tj|ddd�Wd�n1s)wYt�|�t�|d�t�|�t�|�tj|dd�dS)Nr}rbTr~r�r�r�r�rrr�*test_close_both_with_unused_items_unforced^s�


z7ChannelTests.test_close_both_with_unused_items_unforcedcC�t��}t�|d�t�|d�tj|ddd�|�tj��t�|d�Wd�n1s/wY|�tj��t�|�Wd�dS1sKwYdS)Nr}rbTr�r�r�r�rrr�(test_close_recv_with_unused_items_forcedk��"�z5ChannelTests.test_close_recv_with_unused_items_forcedcCr�)Nr}rbTr�r�r�r�rrr�(test_close_send_with_unused_items_forcedvr�z5ChannelTests.test_close_send_with_unused_items_forcedcCs�t��}t�|d�t�|d�tj|dddd�|�tj��t�|d�Wd�n1s0wY|�tj��t�|�Wd�dS1sLwYdS)Nr}rbTr�r�r�r�rrr�(test_close_both_with_unused_items_forced�s�"�z5ChannelTests.test_close_both_with_unused_items_forcedcC�t��}t�|�|�tj��t�|d�Wd�n1s wY|�tj��t�|�Wd�dS1s<wYdSr�)rr�r�r�rPrr�r�rrr�test_close_never_used��
�"�z"ChannelTests.test_close_never_usedcCs�t��}t�|d�t��}t�|td|�d���|�tj��
t�|�Wd�n1s0wY|�tj��t�	|�Wd�dS1sLwYdS)Nr}r�r�)
rr�rrCrrr�rPr�r��rGryrrrr�!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�n1s9wY|�tj��t�|�Wd�dS1sUwYdS)Nr}Trtr�r�r�rrr�-test_close_used_multiple_times_by_single_user�s
�"�z:ChannelTests.test_close_used_multiple_times_by_single_usercCs�t��}|�tj��tjddd�Wd�n1swYt�|�|�tj��tj|dd�Wd�dS1s?wYdS)Nr�Tr�)rr�r�r�r�r�rPr�rrr�.test_channel_list_interpreters_invalid_channel�s�
"�z;ChannelTests.test_channel_list_interpreters_invalid_channelcCsBt��}|�t��t�|�Wd�dS1swYdSr)rr�r�r�r�r�rrr�+test_channel_list_interpreters_invalid_args�s"�z8ChannelTests.test_channel_list_interpreters_invalid_argsN)*rKrLrMr�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�r�r�r�r�r�r�r�rrrrr��sN	+$	
	



	

r�c@sdeZdZdZ		dd�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
    cCs�t��}t�|d�t�|�tj|ddd�|�tj��t�|d�Wd�n1s.wY|�tj��t�|�Wd�dS1sJwYdS�Nr}Tr�r��rr�rr�r�r�rPr�rrr�test_single_user�s
�"�z$ChannelReleaseTests.test_single_usercCsxt��}t��}t��}t�|td|�d���t|td|�d|�d���}t�|td|�d���|�|��d�dS)	Nr�r�r�z,)
            _interpreters.channel_release(z+)
            print(repr(obj))
            z+
            _interpreters.channel_release(r5zb'spam')rr�rCrrrr�r�)rGryr
rr�rrr�test_multiple_users�s
���
�z'ChannelReleaseTests.test_multiple_userscCr�r�r�r�rrr�test_no_kwargsr�z"ChannelReleaseTests.test_no_kwargscCspt��}t�|d�t�|�tj|ddd�|�tj��tj|ddd�Wd�dS1s1wYdS)Nr}Tr�r�r�rrr�test_multiple_timess
"�z'ChannelReleaseTests.test_multiple_timescCslt��}t�|d�t�|d�tj|ddd�|�tj��t�|�Wd�dS1s/wYdS)Nr}rbTr�)rr�rr�r�rPr�r�rrr�test_with_unused_itemss"�z*ChannelReleaseTests.test_with_unused_itemscCr�r�)rr�r�r�rPrr�r�rrr�test_never_used(r�z#ChannelReleaseTests.test_never_usedcCs�t��}t�|d�t��}t�|td|�d���t�|�}t�|�|�tj	��t�|d�Wd�n1s;wY|�
|d�dS)Nr}r�r5r�)rr�rrCrrr�r�r�rPr�)rGryrr�rrr�test_by_unassociated_interp1s
�

�z/ChannelReleaseTests.test_by_unassociated_interpc	Csjt��}t��}t�|td|�d|�d���|�tj��t�|�Wd�dS1s.wYdS)Nze
            import _xxsubinterpreters as _interpreters
            obj = _interpreters.channel_send(z5, b'spam')
            _interpreters.channel_release(r5)rr�rCrrr�rPr�r�rrr�test_close_if_unassociated@s
��"�z.ChannelReleaseTests.test_close_if_unassociatedcCsRt��}t�|d�t�|�t�|d�tj|dd�t�|�}|�|d�dS)Nr}Tr�)rr�rr�r�r�)rGryr�rrr�test_partiallyMs

z"ChannelReleaseTests.test_partiallycCs�t��}t�|d�t�|d�t�|d�t�|�tj|ddd�|�tj��t�|d�Wd�n1s:wY|�tj��t�|�Wd�dS1sVwYdSr�r�r�rrr�'test_used_multiple_times_by_single_userXs
�"�z;ChannelReleaseTests.test_used_multiple_times_by_single_userN)rKrLrMr�r�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|jri}nt�|�}t�|�}t�|�}|j||j||j|i}|s$d}t��||||||�}t�|_t�|_	||_
|S)NrX)�QUICKr9r?rFrDrEr�_preppedrh�_state�_known)r=rVrr_r`�creatorZknownrGrHrrrEms 


�zChannelCloseFixture.__new__cCr�r�r�rprrrrz�szChannelCloseFixture.statecCs:z|jWSty|�|j�}|�|�|_|jYSwr)�_cid�AttributeError�_get_interpreterr��_new_channel)rGr�rrrry�s
�zChannelCloseFixture.cidcCs|�|�}|�|�|Sr)r��_prep_interpreterr�rrr�get_interpreter�s

z#ChannelCloseFixture.get_interpreterNcCs2|dur|j}|dkr|jjdkrdSt|jj�S)Nr[rZF)rVrzrj�boolrerrr�expect_closed_error�s
z'ChannelCloseFixture.expect_closed_errorcCs|�|�dSr)r�r�rrr�prep_interpreter�r7z$ChannelCloseFixture.prep_interpretercCs
||_dSrr�)rGrUr{rrr�
record_action�r�z!ChannelCloseFixture.record_actioncCr�rr�rprrr�clean_up�r�zChannelCloseFixture.clean_upcCs@|jdkr	t��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
                )rFrr�r4r2r�r�)rGr�Zchrrrr��s

�z ChannelCloseFixture._new_channelcCsf|dvr|jS|dkr|jS|dkr|jS|}z|j|}W|Sty2t|�}|j|<Y|Sw)N)rXrr_r`)rr_r`r��KeyErrorr9)rGrrFrrrr��s��z$ChannelCloseFixture._get_interpretercCsF|j|jvrdS|j�|j�|jdkrdSt|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(r5)r2r�rrFr4ryr�rrrr��s
�z%ChannelCloseFixture._prep_interpreterr)rKrLrMr�rE�propertyrzryr�r�r�r�r�r�r�r�rOrrrHrr�fs


r�zend interp other extra creatorz%these tests take several hours to runc@s�eZdZdZ		dd�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]}||Vqq
|�dd�D]}|V|��D]}||Vq+q"|�dd�D]=}|V|�dd�D]}||}|V|��D]}||VqRqE|�dd�D]}||}|V|��D]}||Vqnqaq:|�dd�D]=}|V|�dd�D]}||}|V|��D]}||Vq�q�|�dd�D]}||}|V|��D]}||Vq�q�q~dS)NrXr_r`)�_iter_close_action_sets�_iter_post_close_action_sets�_iter_use_action_sets)rGZcloseactionsZpostactionsZ
useactions�actionsrrr�iter_action_setssV����������z'ExhaustiveChannelTests.iter_action_setsccs�||f}tdd|�gVtdd|�gVtdd|�tdd|�gVtdd|�gVtdd|�gVtdd|�tdd|�gV|D]}|D]}|D]}tdd|�tdd|�tdd|�gVqIqEqA|D](}|D]#}|D]}|D]}tdd|�tdd|�tdd|�tdd|�gVqnqjqfqbdS)NrWr[rZ�rR)rGr�r��interpsr�Zinterp4rrrr/sL�
�
�

�
�
�

�


���	



�����z,ExhaustiveChannelTests._iter_use_action_setsc
	cs��d}||f}dD]}|rdnd}|D]}|D]
}t|||�gVqqq	dD]}	dD]}
|D]}|D]}t|	d|�t|
d|�gVq2q.q*q&dS)Nr~r�r^r]r\r[rZr)
rGr�r�Zendsrru�oprrVZrecvopZsendopr[rZrrrr`s,�
���

�����z.ExhaustiveChannelTests._iter_close_action_setsccs0�dD]}tdd|�gVtdd|�gVqdS)N)rXr`r_rWr[rZrr�rrrrss�
�
��z3ExhaustiveChannelTests._iter_post_close_action_setscCs|D]}|�||�qdSr)r|)rG�fixrrUrrr�run_actions|s�z"ExhaustiveChannelTests.run_actionsTrvcCs�|�|j�}|�|j|j|j�}|�|�|jdkr.t|j	|j
||j|d�}|�||�dSt
��}t|jd|j	�dt|j
��dt|��dt|j��d|�d|�d|�d��tt�t
�|�d	�tt
�|��d
�}|�||�dS)Nr8rvzB
                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�)rkrj)rfrVrgrr_r`r�rFr|ryrUrzr�rr�r4r2r�rhr��
from_bytesr�r�)rGr	rUrwrVrr{r�rrrr|�sB

�������	
��z!ExhaustiveChannelTests.run_actionc	csD�gd�}|D]\}}}dD]}dD]}t|||||�VqqqdS)N))r8rr`)rr8r`)r�r�r`)r�r�r8)rXr_r�r�)r�)rGrrr_r`r�rVrrr�
iter_fixtures�s����z$ExhaustiveChannelTests.iter_fixturescCsx|rdnd}t||jd�}|��s|j||dd�dS|�tj��|j||dd�Wd�dS1s5wYdS)Nr^r]rXFrv)rRrVr�r|r�rrP)rGr	rurr]rrr�_close�s"�zExhaustiveChannelTests._closeNcCs2|dus	|jdkr|�tj��t�|j�Wd�n1s wY|�tj��t�|jd�Wd�n1s=wY|�tj��t�|j�Wd�n1sYwY|�tj��tj|jdd�Wd�dS1sxwYdSt|j	d�t|j	d�t|j	d�t|j	d�dS)	Nr8r}Trtzz
                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)
                )
rFr�rrPr�ryrr�r4r2)rGr	rrrr�_assert_closed_in_interp�s"���"�z/ExhaustiveChannelTests._assert_closed_in_interpcCs||�|jj�t|jj�D]}t�|j�q
|�|�dD]}|�	|�}|j
dkr*q|�||�q|�	d�}|�||�dS)N)rXr_r8Zfresh)r�rzrjr�rkrr�ryrr�rF)rGr	r�rrrr�_assert_closed�s



z%ExhaustiveChannelTests._assert_closedFc	cs��d}|��D]V}t�|��D]F}|d7}|dkrdS|r7|dddkr+t�t||d�t|���n|dddkrEtddd�td	dd�tj��|||fVq|r]td
�qt�dS)Nrrmr��z({} actions)� r�rd�.z---)r�printrrArr��stdoutrF)rG�verboser�rr	rrr�_iter_close_tests�s(��
z(ExhaustiveChannelTests._iter_close_testscCsdt_|��D]\}}}qdS)NT)r�r�r�rGr�r	rrrr�_skim_close_tests�s�z(ExhaustiveChannelTests._skim_close_testsc	C�|��D];\}}}|�d�|||��� |�|j�|�||�|j|dd�|�|�Wd�n1s6wY|��qdS)N�	{} {}  {}Frt�	rr�rAr�rr
r
rr�rrrr�
test_close���
�z!ExhaustiveChannelTests.test_closec	Cr)NrTrtrrrrr�test_force_close		rz'ExhaustiveChannelTests.test_force_closer)F)rKrLrMr�rrrrr
r|rr
rrrrrrrrrrr�s$-1	 
	
rrvr)6�collectionsrr�r�rrir��textwraprr*rr��testrZtest.supportrr�
import_modulerrrr$r�r0r4r1r9rQrRrhr|rxr�r�ZTestCaser�r�r�r�r�r�r�r�rr-r;r�r�r�r�r�rrKr8rrrr�<module>sz



&
	3$

2?);]b+Y:&�q
@�