Uname:Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64

403WebShell
403Webshell
Server IP : 3.111.61.48  /  Your IP : 216.73.216.67
Web Server : Apache
System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.2.31
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.10/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.10/test/__pycache__/test__xxsubinterpreters.cpython-310.pyc
o

�9j�;�@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_helper�_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�w�indented�wrapped�r�3/usr/lib/python3.10/test/test__xxsubinterpreters.py�_captured_scripts�
�rcCsJt|�\}}|�t�|||�|��Wd�S1swYdS�N)r�interpreters�
run_string�read)�interp�request�sharedr�rpiperrr�_run_output#s
$�r cCsX|durtj}t��}||}t�|�s*t��|krtd��t�d�t�|�rdSdS)Nzinterp is not runningg{�G�z�?)r�
SHORT_TIMEOUT�time�	monotonicr�
is_running�RuntimeError�sleep)r�timeout�
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��targetrr	r
�done)	rr
�	threading�Thread�startr*r�write�join)rrr,�t�spiperr+r�_running8s��r7cKst|||�dSr)�_run_interp)�id�sourcerrrr�
run_interpWsr;cCsHt|�}t��}||krt��|krt�t||�dSt�|||�dSr)rr�get_main�get_currentr%�execr)r9r:r�_mainns�mainrrrr8[sr8cs*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)Nr@z)name mismatch (expected "main", got "{}")rz!name mismatch (unexpected "main"))	rr<�
ValueError�formatrB�
InterpreterID�create�super�__new__)rE�namer9r@�self��	__class__rrrMrs.�
�zInterpreter.__new__�NN)�__name__�
__module__�__qualname__�classmethodrGrM�
__classcell__rrrPrrAgs
rAzname idccs,�zdVWntjyYdSwJd��)NFzchannel not closed)r�ChannelClosedErrorrrrr�expect_channel_closed�s�
�rYcs6eZdZd
�fdd�	Zdd�Zdd�Zdd	�Z�ZS)�
ChannelActionNcs&|sd}|sd}t��||||�}|S)N�bothr@�rLrM)rE�action�endrrOrPrrrM�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)r[r`rarbrc)r@r`�other�extra)r]r^rHr)rO�args�kwargsrrr�__init__�s


�


�


�zChannelAction.__init__cCs.|jdkr|S|jdkr|dkrdSdS|jS)Nr`rarbrc�r^�rOr^rrr�resolve_end�s


zChannelAction.resolve_endcCst|jdkr|S|jdkr|durt�|S|jdkr!|durt�|S|jdkr8|jdkr-|S|r6|jdkr6|St�dS)Nr`rgrhr@)rr%rN)rOrrgrhrrr�resolve_interp�s"




�zChannelAction.resolve_interprR)rSrTrUrMrkrnrorWrrrPrrZ�s
rZzaction end interpcsBeZdZddd��fdd�Zdd�Zdd	�Zd
d�dd
�Z�ZS)�ChannelStaterF��closedcst��|||�}|Srr\)rE�pendingrrrOrPrrrM�szChannelState.__new__cCst|�|jd|jd�S�N�rq��typersrr�rOrrr�incr��zChannelState.incrcCst|�|jd|jd�Srtrvrxrrr�decr�rzzChannelState.decrT��forcecCs8|jr|r
|jdkr|St|�|rddd�S|jdd�S)NrTrq)rrrsrw)rOr}rrrre�s zChannelState.close)r)rSrTrUrMryr{rerWrrrPrrp�s
rpzpending closedT��
hideclosedcCst|jr|dkr|dkr|jrd}nd}nd}z	t||||�}Wntjy3|s,|s,�|��}Y|Sw|r8d�|S)Nr_rcFT.)rrrs�_run_actionrrXre)�cidr]r^�stater�
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|��)Nr_rb�spamrczexpected ChannelEmptyErrorre�rcrbTrfr}r|)r�channel_sendryrs�channel_recv�ChannelEmptyError�	Exceptionr{rH�
channel_closere)r�r]r^r�rjrrrr��s:��
�r�c	Cs<t��D]}|dkrqzt�|�WqtyYqwdS)Nr)r�list_all�destroyr%�r9rrr�clean_up_interpreterss��r�c	Cs4t��D]}zt�|�WqtjyYqwdSr)r�channel_list_all�channel_destroy�ChannelNotFoundError�r�rrr�clean_up_channels s��r�c@�eZdZdd�ZdS)�TestBasecC�t�t�dSr�r�r�rxrrr�tearDown*�
zTestBase.tearDownN)rSrTrUr�rrrrr�(sr�c@�eZdZdd�Zdd�ZdS)�IsShareableTestsc	CsPgd�}|D]}|�|��|�t�|��Wd�n1s wYqdS)N)Nr��spam�
i����)�subTest�
assertTruer�is_shareable)rO�
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�rN)rOrNrrrrkE�
z<IsShareableTests.test_not_shareable.<locals>.Cheese.__init__cS�|jSrr�rxrrr�__str__Gsz;IsShareableTests.test_not_shareable.<locals>.Cheese.__str__N)rSrTrUrkr�rrrr�CheeseDsr�c@seZdZdZdS)z5IsShareableTests.test_not_shareable.<locals>.SubByteszA subclass of a shareable type.N)rSrTrU�__doc__rrrr�SubBytesJsr�TF.gY@�Wensleydaler�)
�bytes�NotImplementedrw�objectr�r��repr�assertFalserr�)rOr�r��not_shareablesr�rrr�test_not_shareableCs.�����z#IsShareableTests.test_not_shareableN)rSrTrUr�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)rL�setUpr�channel_creater�rxrPrrr�f�
zShareableTypeTests.setUpcst�|j�t���dSr)rr�r�rLr�rxrPrrr�jszShareableTypeTests.tearDownc	Csr|D]4}|�|��%t�|j|�t�|j�}|�||�|�t|�t|��Wd�n1s1wYqdSr)r�rr�r�r��assertEqual�assertIsrw)rO�valuesr��gotrrr�_assert_valuesns���z!ShareableTypeTests._assert_valuesc	Cs^dD]*}|�|��t�|j|�t�|j�}|�||�Wd�n1s'wYqdS)Nr)r�rr�r�r�r�)rOr�r�rrr�test_singletonsys���z"ShareableTypeTests.test_singletonscCs|�dd|jg�dS)Nr�i')r�r�rxrrr�
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��rangerxrrr�
test_bytes�s
�zShareableTypeTests.test_bytescCs|�gd��dS)N)zhello worldu你好世界�)r�rxrrr�	test_strs��zShareableTypeTests.test_strscCs*|�t�tdd�tjtjdg��dS)Nr�r�ru)r��	itertools�chainr��sys�maxsizerxrrr�test_int�s
�zShareableTypeTests.test_intc
Cs�tjdtjdddg}|D]3}|�|��$|�t��t�|j|�Wd�n1s/wYWd�n1s>wYqdS)Nrur���)r�r�r��assertRaises�
OverflowErrorrr�r�)rO�intsr�rrr�test_non_shareable_int�s
������z)ShareableTypeTests.test_non_shareable_int)
rSrTrUr�r�r�r�r�r�r�r�r�rWrrrPrr�ds	r�c@s$eZdZdd�Zdd�Zdd�ZdS)�ListAllTestscCs"t��}t��}|�||g�dSr)rr<r�r�)rOr@�idsrrr�test_initial�szListAllTests.test_initialcCs6t��}t��}t��}t��}|�||||g�dSr)rr<rKr�r��rOr@�first�secondr�rrr�test_after_creating�s
z ListAllTests.test_after_creatingcCs>t��}t��}t��}t�|�t��}|�|||g�dSr)rr<rKr�r�r�r�rrr�test_after_destroying�s
z"ListAllTests.test_after_destroyingN)rSrTrUr�r�r�rrrrr��sr�c@r�)�GetCurrentTestscCs.t��}t��}|�||�|�|tj�dSr)rr<r=r��assertIsInstancerJ)rOr@�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)
            )
rr<rKr r�int�stripr�r��assertNotEqual)rOr@r�outr��_�expectedrrr�test_subinterpreter�sz#GetCurrentTests.test_subinterpreterN)rSrTrUr�r�rrrrr���r�c@r�)�GetMainTestscCs0t��\}t��}|�||�|�|tj�dSr)rr�r<r�r�rJ)rOr�r@rrr�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�rKr rr�r�r�)rOr�rr�r@rrr�test_from_subinterpreter�s

z%GetMainTests.test_from_subinterpreterN)rSrTrUr�r�rrrrr��r�r�c@sFeZdZdd�Ze�d�dd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dS)�IsRunningTestscCst��}|�t�|��dSr)rr<r�r$)rOr@rrrr��szIsRunningTests.test_mainzFails on FreeBSDcCsdt��}|�t�|��t|��|�t�|��Wd�n1s#wY|�t�|��dSr)rrKr�r$r7r��rOrrrrr��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)rrKr rr�r�)rOrr�rrrr��s
�z'IsRunningTests.test_from_subinterpretercCsLt��}t�|�|�t��t�|�Wd�dS1swYdSr)rrKr�r�r%r$r�rrr�test_already_destroyed�

"�z%IsRunningTests.test_already_destroyedcC�:|�t��t�d�Wd�dS1swYdS�Ni@B)r�r%rr$rxrrr�test_does_not_exist�"�z"IsRunningTests.test_does_not_existcCr��Nr�)r�rHrr$rxrrr�test_bad_id
r�zIsRunningTests.test_bad_idN)rSrTrUr��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�Tr|)rrJr�r��rOr9rrr�
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�rrxrrr�	__index__�z8InterpreterIDTests.test_coerce_id.<locals>.Int.__index__N�rSrTrUrrrrr�Int�rTr|r�)rCrrJr�r�)rOrr9rrr�test_coerce_id�z!InterpreterIDTests.test_coerce_idcC�f|�ttjt��|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�dS�Ng$@�10s10r�l)r��	TypeErrorrrJr�rHr�rxrrrr��zInterpreterIDTests.test_bad_idcCsJt��}|�t��t�t|�d�Wd�dS1swYdS�Nru)rr�r�r%rJr�r�rrrr�&s"�z&InterpreterIDTests.test_does_not_existcC�"tjddd�}|�t|�d�dS�Nr�Tr|r)rrJr�rCr�rrr�test_str+�zInterpreterIDTests.test_strcCr)Nr�Tr|zInterpreterID(10))rrJr�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�)rrKrJr�r��floatr�rC�rO�id1�id2�id3rrr�
test_equality3�$z InterpreterIDTests.test_equalityN)
rSrTrUr�rr�r�rrrrrrrr�sr�c@sNeZdZdd�Ze�d�dd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�ZdS)�CreateTestscCs*t��}|�|tj�|�|t���dSr)rrKr�rJ�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�rrKr��addr��len)rO�seenr�r9rrr�test_unique_idRs
zCreateTests.test_unique_idcsnt���d���fdd�}tj|d�}��|��Wd�n1s$wY|��|��t���dS)Ncst���������dSr)rrK�acquire�releaser�r9�lockrr�f_sz%CreateTests.test_in_thread.<locals>.fr-)r0�Lockr1r2r4r!rr��rOr-r5rr+r�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�rKr rr�r�r�r$)rOr@rr�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)
                )r rr�r�)r��rrrrr-|sz6CreateTests.test_in_threaded_subinterpreter.<locals>.fr-)	rr�rKr0r1r2r4r�r$)rOr@r-r5rr2r�test_in_threaded_subinterpreterxs
	z+CreateTests.test_in_threaded_subinterpretercCsjtt���}g}td�D]}t��}|�|�q|D]}t�|�qt��}|�tt���||hB�dS�N�)r$rr�r�rK�appendr�r��rO�beforer�r�r9rrr�test_after_destroy_all�sz"CreateTests.test_after_destroy_allcCs`tt���}t��}t��}t��}t�|�t�|�t��}|�tt���|||hB�dSr)r$rr�rKr�r�)rOr8rrrr9rrr�test_after_destroy_some�s

 z#CreateTests.test_after_destroy_someN)rSrTrUr"r�r�r(r0r1r3r9r:rrrrr Js
	
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)rrKr!r�r��assertNotInrrrr�test_one�s
zDestroyTests.test_onecCsvtt���}t�}td�D]}t��}|�|�q
|�tt���||B�|D]}t�|�q'|�tt���|�dSr4)r$rr�r�rKr%r�r�r7rrr�test_all�szDestroyTests.test_allcslt��\���t��
t���Wd�n1swY��fdd�}tj|d�}|��|��dS)Ncs:��t��t���Wd�dS1swYdSr�r�r%rr�r�r@rOrrr-�r�z!DestroyTests.test_main.<locals>.fr-)	rr�r�r%r�r0r1r2r4r/rr@rr��s
�zDestroyTests.test_maincCsLt��}t�|�|�t��t�|�Wd�dS1swYdSr)rrKr�r�r%r�rrrr��r�z#DestroyTests.test_already_destroyedcCr�r�r?rxrrrr��r�z DestroyTests.test_does_not_existcCr�r�)r�rHrr�rxrrrr��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�rKrrr�r$)rOr@r9rrrr�test_from_current�s

�zDestroyTests.test_from_currentcCsRt��\}t��}t��}td|�d��}t�||�|�tt���||h�dS)NzZ
            import _xxsubinterpreters as _interpreters
            _interpreters.destroy(�)
            rA)rOr@rrrrrr�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-)rrKr0r1r2r4r/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�rKr7r�r$r�r%r�)rOr@rrrr�test_still_running�s


�
��"�zDestroyTests.test_still_runningN)
rSrTrUr=r>r�r�r�r�rBrDrFrHrrrrr;�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)rLr�rrKr9rxrPrrr�r�zRunStringTests.setUpcCsVtd�\}}|�t�|j|�|��}Wd�n1swY|�|d�dS)N�print("it worked!", end="")�
it worked!)rrrr9rr�)rOr�filer�rrr�test_successs
�zRunStringTests.test_successcsrtd�\�}|�!��fdd�}tj|d�}|��|��|��}Wd�n1s,wY��|d�dS)NrJcst��j��dSr)rrr9r�rrOrrr-r�z(RunStringTests.test_in_thread.<locals>.fr-rK)rr0r1r2r4rr�)rOrLr-r5r�rrNrr0s
�	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()
            rK)rrKrrrr�)rO�	subinterprrLr�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+r	r
r�zspam spam spam spam spamz�
                import os
                try:
                    os.fork()
                except RuntimeError:
                    with open('zE', 'w', encoding='utf-8') as out:
                        out.write('z')
                )�tempfile�NamedTemporaryFiler3�flushrrNrrr9�seekrr�)rOrSrLr�r�contentrrr�	test_fork5s
�
�
"�zRunStringTests.test_forkc	Csxt|j��-|�t��t�|jd�Wd�n1swYWd�dSWd�dS1s5wYdS)N�
print("spam"))r7r9r�r%rrrxrrr�test_already_runningKs��"�z#RunStringTests.test_already_runningcCs`d}|t��vr|d7}|t��vs|�t��t�|d�Wd�dS1s)wYdS)NrrurY)rr�r�r%rr�rrrr�Ps�"�z"RunStringTests.test_does_not_existcC�<|�t��t�dd�Wd�dS1swYdS)Nr�rY)r�rHrrrxrrr�
test_error_idW�"�zRunStringTests.test_error_idcCr[)Nr�rY)r�r
rrrxrrrr�[r]zRunStringTests.test_bad_idcC�>|�t��t�|jd�Wd�dS1swYdSr�r�r
rrr9rxrrr�test_bad_script_�"�zRunStringTests.test_bad_scriptcCr^)Ns
print("spam")r_rxrrr�test_bytes_for_scriptcraz$RunStringTests.test_bytes_for_scriptNccs~�|�tj��}dVWd�n1swY|dur0|�t|j��d�dt|��dS|�t|j�d�||��dS)N�:rz{}: {})r�r�RunFailedErrorr�rC�	exception�splitrI)rO�exctyperG�caughtrrr�assert_run_failedgs���
�z RunStringTests.assert_run_failedcCr^)Nzprint("spam")ri�SyntaxErrorrrr9rxrrr�test_invalid_syntaxrs"�z"RunStringTests.test_invalid_syntaxcC�@|�td��t�|jd�Wd�dS1swYdS)Nr�zraise Exception("spam"))rir�rrr9rxrrr�test_failurew�"�zRunStringTests.test_failurecCrl)N�42zraise SystemExit(42))ri�
SystemExitrrr9rxrrr�test_SystemExit{rnzRunStringTests.test_SystemExitcCs�|�t��t�|jtd��Wd�n1swY|�td��t�|jtd��Wd�dS1s9wYdS)NzG
                import sys
                sys.exit()
                rozI
                import sys
                sys.exit(42)
                )rirprrr9rrxrrr�
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��*rtr�r��)ru)rr
rrrr9r�pickle�loadr��assertIsNone�rOrrrr�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�rszL
            ns2 = dict(vars())
            del ns2['__builtins__']
        zr
            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(rvrw�ns1rt�ns2)
rrr9rrr
rrzr{r�)rOrrrrr~rrrr�test_shared_overwrites�s
��z%RunStringTests.test_shared_overwritescCs|t��\}}ddi}td|�d��}t�|j||�t|d��
}t�|�}Wd�n1s/wY|�	|dd�dS)NrSsnot __main__z�
            spam = 42

            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(rvrw)
rr
rrrr9rrzr{r�r}rrr�#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
            rwz�
            eggs = False

            ns = dict(vars())
            del ns['__builtins__']
            import pickle
            with open(rvr�rt)rr
rrr9rrrzr{r!r<)rOrrr~r�r�rrr�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(rvrw�__builtins__�
__loader__�__main__rx)rS�__annotations__r��__package__�__spec__r�)rr
rrrr9rrzr{�popr�)rOrrrr~rrrr� 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)rr�temp_dirr�make_script�spawn_python�waitr�)rOr�dirname�filename�proc�retcoderrr�test_still_running_at_exits

���z)RunStringTests.test_still_running_at_exitr)!rSrTrUr�rMr0rQr��
skipUnless�hasattrrrXrZr�r\r�r`rb�
contextlib�contextmanagerrirkrmrqrrr�r�r�r�r�r�r�rWrrrPrrI	s4



!rIc@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�ChannelIDTestscCs0tjddd�}|�t|�d�|�|jd�dS)Nr�Tr|r[)r�_channel_idr�r�r^�rOr�rrr�test_default_kwargs4sz"ChannelIDTests.test_default_kwargscCs�tjdddd�}|�|jd�tjddddd�}|�|jd�tjdddd�}|�|jd�tjddddd	�}|�|jd�tjddddd�}|�|jd
�dS)Nr�T�rbr}rbF�rbrcr}�rcr}rc)rcrbr}r[)rr�r�r^r�rrr�test_with_kwargs:szChannelIDTests.test_with_kwargscCr)Nc@r�)z*ChannelIDTests.test_coerce_id.<locals>.IntcSrrrrxrrrrLrz4ChannelIDTests.test_coerce_id.<locals>.Int.__index__NrrrrrrKrrTr|r�)rCrr�r�r�)rOrr�rrrrJr	zChannelIDTests.test_coerce_idcCr
r)r�r
rr�r�rHr�rxrrrr�RrzChannelIDTests.test_bad_idcCs@|�t��tjdddd�Wd�dS1swYdS)Nr�F�rbrc)r�rHrr�rxrrr�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�rCr�rrrrcrzChannelIDTests.test_strcCs�tjddd�}|�t|�d�tjdddd�}|�t|�d�tjdddd�}|�t|�d�tjddddd	�}|�t|�d�dS)
Nr�Tr|z
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�rC)rO�cid1�cid2�cid3rrrrtrzChannelIDTests.test_equalityN)rSrTrUr�r�rr�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��	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$)rOr8rrr�afterrrr�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)
            ru)rrKr rr�r�r�)rOrr�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�rbFN)rr��channel_list_interpretersr�)rOr��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.rbTr�F�e
            import _xxsubinterpreters as _interpreters
            obj = _interpreters.channel_recv(rCN)	rr<r�r�r�r�rKr r)rO�interp0r�r�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.rb�_
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_send(z, "send")
            r�rCTr�FN)
rr<rKr�r�r rr�r�r$)rOr�r��interp2�interp3r�r�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.rbr�rCTr�FN)
rr<rKr�r�r rr�r�r��rOr�r�r�r�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�rCTr�Frur�r�b
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_release(N)rr<rKr�r�r rr�r�r&�channel_release)rOr�r�r�r�r�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.rbTr�Frurr|N)rr<rKr�r�r�r�r&r�r�rXr�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.rbTr�FrurN�`
            import _xxsubinterpreters as _interpreters
            _interpreters.channel_close(�, force=True)
            )
rr<rKr�r�r�r�r&r�r�rXr rr�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�r�r�r��assertIsNot)rOr��origr�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
            )rrKr r)rOrr�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�rKr rr�r�)rOr�rr�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�r"r&r�)r�r�rrr-�s
��z8ChannelTests.test_send_recv_different_threads.<locals>.fr-r�)	rr�r0r1r2r�r4r�r��rOr-r5r�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�r�rr�rrr-�s
�
�zIChannelTests.test_send_recv_different_interpreters_and_threads.<locals>.fr-r��eggs)
rr�rKr0r1r2r�r4r�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�r�rxrrr�test_send_not_found�s"�z ChannelTests.test_send_not_foundcCs<|�tj��t�d�Wd�dS1swYdSr)r�rr�r�rxrrr�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)Nrur�r�)r�rr�r�r�r�r�)	rO�defaultr��obj1�obj2�obj3�obj4�obj5�obj6rrr�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�rb)
rr�rKr r�dictrbr�r�r��rOr�rr�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')
            )r~r�rb)rr�r�rKr rr�rbr�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�r�r�r�r�rXr�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(rCz,
                _interpreters.channel_send(z, b'spam')
                rX)rr�rKrrr�r�rdr!rCre)rOr�rr�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�r�r�r�r�rX)rO�testsrbrcr�rrr�test_close_empty's"
������zChannelTests.test_close_emptycCspt��}t�|d�t�|d�|�tj��
t�|�Wd�n1s&wYt�|�t�|d�dS)Nr�rsr��rr�r�r��ChannelNotEmptyErrorr�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�rsT�rcr�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�rsTr�r��rr�r�r�r�rXr�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�rsTr�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�rsTr�r�r�r�rrr�(test_close_recv_with_unused_items_forcedk��"�z5ChannelTests.test_close_recv_with_unused_items_forcedcCr�)Nr�rsTr�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�rsTr�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�rXr�r�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�r�rKrrr�rXr�r��rOr�rrrr�!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�Tr|r�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�rXr�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)*rSrTrUr�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�rrrrrrr��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�r�r�r�r�rXr�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(rCzb'spam')rr�rKrrr r�r�)rOr�rrr�rrr�test_multiple_users�s
���
�z'ChannelReleaseTests.test_multiple_userscCr�r�rr�rrr�test_no_kwargsr�z"ChannelReleaseTests.test_no_kwargscCspt��}t�|d�t�|�tj|ddd�|�tj��tj|ddd�Wd�dS1s1wYdS)Nr�Tr�rr�rrr�test_multiple_timess
"�z'ChannelReleaseTests.test_multiple_timescCslt��}t�|d�t�|d�tj|ddd�|�tj��t�|�Wd�dS1s/wYdS)Nr�rsTr�)rr�r�r�r�rXr�r�rrr�test_with_unused_itemss"�z*ChannelReleaseTests.test_with_unused_itemscCr�r�)rr�r�r�rXr�r�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�rCr�)rr�r�rKrrr�r�r�rXr�)rOr�rr�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(rC)rr�rKrrr�rXr�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�r�r�r�r�)rOr�r�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�dS1sVwYdSrrr�rrr�'test_used_multiple_times_by_single_userXs
�"�z;ChannelReleaseTests.test_used_multiple_times_by_single_userN)rSrTrUr�rrrrr	r
rrr
rrrrrr�s			
rcszeZdZdZ�fdd�Zedd��Zedd��Zdd	�Zddd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Z�ZS)�ChannelCloseFixtureFcs�|dvsJ�|jri}nt�|�}t�|�}t�|�}|j||j||j|i}|s*d}t��||||||�}t�|_t�|_	||_
|S)Nr�r`)�QUICKrArGrNrLrMr$�_preppedrp�_state�_known)rEr^rrgrh�creator�knownrOrPrrrMms"


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

z#ChannelCloseFixture.get_interpreterNcCs2|dur|j}|dkr|jjdkrdSt|jj�S)NrcrbF)r^r�rr�boolrmrrr�expect_closed_error�s
z'ChannelCloseFixture.expect_closed_errorcCs|�|�dSr)rr�rrr�prep_interpreter�rEz$ChannelCloseFixture.prep_interpretercCs
||_dSrr)rOr]r�rrr�
record_action�r�z!ChannelCloseFixture.record_actioncCr�rr�rxrrr�clean_up�r�zChannelCloseFixture.clean_upcCs@|jdkr	t��St��}t|jd|�d��t�|�|_|jS)Nr@a
                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
                )rNrr�r;r9r�r)rOr�chrrrr�s

�z ChannelCloseFixture._new_channelcCsf|dvr|jS|dkr|jS|dkr|jS|}z|j|}W|Sty2t|�}|j|<Y|Sw)N)r`rrgrh)rrgrhr�KeyErrorrA)rOrrNrrrr�s��z$ChannelCloseFixture._get_interpretercCsF|j|jvrdS|j�|j�|jdkrdSt|jd|j�d��dS)Nr@a
            import _xxsubinterpreters as interpreters
            import test.test__xxsubinterpreters as helpers
            ChannelState = helpers.ChannelState
            try:
                cid
            except NameError:
                cid = interpreters._channel_id(rC)r9rr%rNr;r�r�rrrr�s
�z%ChannelCloseFixture._prep_interpreterr)rSrTrUrrM�propertyr�r�rrrr r!rrrrWrrrPrrfs


rzend 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)Nr`rgrh)�_iter_close_action_sets�_iter_post_close_action_sets�_iter_use_action_sets)rO�closeactions�postactions�
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)Nr_rcrb�rZ)rOr�r��interpsr��interp4rrrr(/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�rfrerdrcrbr.)
rOr�r��endsr/r}�oprr^�recvop�sendoprcrbrrrr&`s,�
���

�����z.ExhaustiveChannelTests._iter_close_action_setsccs0�dD]}tdd|�gVtdd|�gVqdS)N)r`rhrgr_rcrbr.r�rrrr'ss�
�
��z3ExhaustiveChannelTests._iter_post_close_action_setscCs|D]}|�||�qdSr)r�)rO�fixr,r]rrr�run_actions|s�z"ExhaustiveChannelTests.run_actionsTr~cCs�|�|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)Nr@r~zB
                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�)rsrr)rnr^rorrgrhrrNr�r�r]r�r rr�r;r9r�rpr��
from_bytesr�r)rOr5r]rr^rr�rrrrr��sB

�������	
��z!ExhaustiveChannelTests.run_actionc	csD�gd�}|D]\}}}dD]}dD]}t|||||�VqqqdS)N))r@rrh)rr@rh)r�r�rh)r�r�r@)r`rgrr�)r)rOrrrgrhrr^rrr�
iter_fixtures�s����z$ExhaustiveChannelTests.iter_fixturescCsx|rdnd}t||jd�}|��s|j||dd�dS|�tj��|j||dd�Wd�dS1s5wYdS)Nrfrer`Fr~)rZr^rr�r�rrX)rOr5r}r2rerrr�_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)	Nr@r�Tr|zz
                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)
                )
rNr�rrXr�r�r�r�r;r9)rOr5rrrr�_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)r`rgr@�fresh)r�r�rrr�rsrr�r�r:rrN)rOr5r�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)Nrrur��z({} actions)� r�rl�.z---)r-�printr8rIr&r��stdoutrU)rO�verboser�r,r5rrr�_iter_close_tests�s(��
z(ExhaustiveChannelTests._iter_close_testscCsdt_|��D]\}}}qdS)NT)rrrC�rOr�r5r,rrr�_skim_close_tests�s�z(ExhaustiveChannelTests._skim_close_testsc	C�|��D];\}}}|�d�|||��� |�|j�|�||�|j|dd�|�|�Wd�n1s6wY|��qdS)N�	{} {}  {}Fr|�	rCr�rIrrr6r9r<r!rDrrr�
test_close���
�z!ExhaustiveChannelTests.test_closec	CrF)NrGTr|rHrDrrr�test_force_close		rJz'ExhaustiveChannelTests.test_force_closer)F)rSrTrUr�r-r(r&r'r6r�r8r9r:r<rCrErIrKrrrrr%�s$-1	 
	
r%r�r)6�collectionsrr�r�rrzr��textwraprr0r"r��testr�test.supportrr�
import_modulerrr r*r�r7r;r8rArYrZrpr�r�r�r��TestCaser�r�r�r�r�r�r�r�r r;rIr�r�rrr�r%rSr@rrrr�<module>sz



&
	3$

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

Youez - 2016 - github.com/yon3zu
LinuXploit