Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_capi.cpython-35.opt-2.pyc



���]�\�@s)ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
yddlZWnek
r�dZYnXyddlZWnek
r�dZYnXe	jd�Zeed�Zdd�ZGd	d
�d
�ZGdd�dej�Zejed
�Gdd�dej��ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�Zejed
�Gdd�dej��ZGdd�dej�Z e!dkr%ej"�dS)�N)�support)�MISSING_C_DOCSTRINGS)�assert_python_failure�	_testcapi�gettotalrefcountcCs|S)N�)�selfrr�./opt/alt/python35/lib64/python3.5/test_capi.py�testfunctionsr
c@s.eZdZeje�Zeje�ZdS)�InstanceMethodN)�__name__�
__module__�__qualname__rZinstancemethod�idr
rrrr	r"src@s�eZdZdd�Zejed�dd��Zdd�Zdd	�Z	eje
d
�dd��Zeje
d
�d
d��Zej
ed�dd��Zdd�Zdd�Zdd�Zdd�ZdS)�CAPITestcCs�t�}|jt|�|j��|j|j�|k�|j|jjtj�|jtjjtj�dtj_|jtjd�|jtt	|jdd�dS)N�test�	attribute)
r�assertEqualr�
assertTruer
�__doc__r�assertRaises�AttributeError�setattr)r�instrrr	�test_instancemethod(s	zCAPITest.test_instancemethodz!Threading required for this test.c
Cs�tj��2tjtjddgdtjdtj�}WdQRX|j�\}}|j|d�|j	|j
�jd��dS)Nz-cz4import _testcapi;_testcapi.crash_no_current_thread()�stdout�stderr�s8Fatal Python error: PyThreadState_Get: no current thread)rZSuppressCrashReport�
subprocess�Popen�sys�
executable�PIPE�communicaterr�rstrip�
startswith)r�p�out�errrrr	� test_no_FatalError_infinite_loop3s
		z)CAPITest.test_no_FatalError_infinite_loopcCs|jttj�dS)N)r�
ValueErrorrZ!make_memoryview_from_NULL_pointer)rrrr	�!test_memoryview_from_NULL_pointerBsz*CAPITest.test_memoryview_from_NULL_pointerc
Cs+td�}td�}y
|�Wn�tk
r}z�|j}tj�}tj|j|d�}tj�}tj|�}tj�}	|j|d|�|j	||j||f�|j	||�|j	|	|�|j	||j|df�|j	||�WYdd}~XnX|j
d�dS)N�5ZTEST�F)r*�	TypeError�
__traceback__r �exc_inforZset_exc_info�	__class__rZassertSequenceEqualr)
rZraised_exception�new_exc�e�tbZorig_sys_exc_infoZ
orig_exc_infoZnew_sys_exc_infoZnew_exc_infoZreset_sys_exc_inforrr	�
test_exc_infoEs$
	#zCAPITest.test_exc_infoz(_posixsubprocess required for this test.cCs�Gdd�dt�}|jttjd|�dddddd	d
ddd
ddddd�Gdd�dt�}|jttjd|�dddddd	d
ddd
ddddd�dS)Nc@seZdZdd�ZdS)z1CAPITest.test_seq_bytes_to_charp_array.<locals>.ZcSsdS)Nr-r)rrrr	�__len__`sz9CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__len__N)rr
rr6rrrr	�Z_sr7r-�������	�
���
����c@s(eZdZdd�Zdd�ZdS)z1CAPITest.test_seq_bytes_to_charp_array.<locals>.ZcSstjS)N)r �maxsize)rrrr	r6fsz9CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__len__cSsdS)N�xr)r�irrr	�__getitem__hsz=CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__getitem__N)rr
rr6rJrrrr	r7es)r-r9)r-r9)�objectrr.�_posixsubprocess�	fork_exec�MemoryError)rr7rrr	�test_seq_bytes_to_charp_array\s:z&CAPITest.test_seq_bytes_to_charp_arraycCsfGdd�dt�}|jttj|�dgddddd	d
ddd
dddddd�dS)Nc@seZdZdd�ZdS)z-CAPITest.test_subprocess_fork_exec.<locals>.ZcSsdS)Nr-r)rrrr	r6psz5CAPITest.test_subprocess_fork_exec.<locals>.Z.__len__N)rr
rr6rrrr	r7osr7�1r8r-r9r:r;r<r=r>r?r@rArBrCrDrErF)r-r9)rKrr.rLrM)rr7rrr	�test_subprocess_fork_execmsz"CAPITest.test_subprocess_fork_execz6Signature information for builtins requires docstringscCsd|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtj	jd�|jtj	jd�|jtj
jd�|jtj
jd�|jtjjd�|jtjjd�dS)Nz This docstring has no signature.z[docstring_with_invalid_signature($module, /, boo)

This docstring has an invalid signature.zedocstring_with_invalid_signature2($module, /, boo)

--

This docstring also has an invalid signature.z%This docstring has a valid signature.z($module, /, sig)z>
This docstring has a valid signature and some extra newlines.z($module, /, parameter))rrZno_docstringr�__text_signature__Zdocstring_emptyZdocstring_no_signatureZ docstring_with_invalid_signatureZ!docstring_with_invalid_signature2Zdocstring_with_signatureZ#docstring_with_signature_but_no_docZ+docstring_with_signature_and_extra_newlines)rrrr	� test_docstring_signature_parsingws.z)CAPITest.test_docstring_signature_parsingcCs�tj}|�}|�}|j||d||f�|j|dd|df�|jd|dd|f�|}||}|j|d||f�|}|d}|j|d|df�d}||}|j|dd|f�dS)N�matmul�*�imatmul)rZ
matmulTyper)r�M�m1�m2�orrr	�&test_c_type_with_matrix_multiplication�s			


z/CAPITest.test_c_type_with_matrix_multiplicationc
Cs�trLtjd�}td|�\}}}|j|jdd�d�n<|jt��}tj	�WdQRX|jt
|j�d�dS)Nz�
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_null_without_error()
            z-cs
rs�Fatal Python error: a function returned NULL without setting an error\nSystemError: <built-in function return_null_without_error> returned NULL without setting an error\n\nCurrent thread.*:\n  File .*", line 6 in <module>zBreturn_null_without_error.* returned NULL without setting an error)�Py_DEBUG�textwrap�dedentr�assertRegex�replacer�SystemErrorrZreturn_null_without_error�str�	exception)r�code�rcr'r(�cmrrr	�test_return_null_without_error�s	
	z'CAPITest.test_return_null_without_errorc
Cs�trLtjd�}td|�\}}}|j|jdd�d�n<|jt��}tj	�WdQRX|jt
|j�d�dS)Nz�
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_result_with_error()
            z-cs
rs*Fatal Python error: a function returned a result with an error set\nValueError\n\nDuring handling of the above exception, another exception occurred:\n\nSystemError: <built-in function return_result_with_error> returned a result with an error set\n\nCurrent thread.*:\n  File .*, line 6 in <module>z>return_result_with_error.* returned a result with an error set)r\r]r^rr_r`rrarZreturn_result_with_errorrbrc)rrdrer'r(rfrrr	�test_return_result_with_error�s	
z&CAPITest.test_return_result_with_errorcCstj�dS)N)r�test_buildvalue_N)rrrr	ri�szCAPITest.test_buildvalue_NN)rr
rr�unittest�
skipUnless�	threadingr)r+r5rLrOrQZskipIfrrSr[rgrhrirrrr	r&s
	* rz!Threading required for this test.c@sOeZdZdd�Zddd�Zdd�Zdd	�Zd
d�ZdS)�TestPendingCallscs[�fdd�}xBt|�D]4}tjtj�d�xtj|�r?Pq?WqWdS)Ncs�jd�dS)N)�appendr)�lrr	�callback�sz6TestPendingCalls.pendingcalls_submit.<locals>.callbackg{�G�z�?)�range�time�sleep�randomrZ_pending_threadfunc)rro�nrprIr)ror	�pendingcalls_submit�sz$TestPendingCalls.pendingcalls_submitNcCs�d}x�t|�|kr�drAtjrAtdt|�f�xtd�D]}||}qNW|r{|jj�r{q	|d7}|j|dkd|t|�f�q	Wdr�tjr�tdt|�f�dS)NrFz(%i)i�r-i'z(timeout waiting for %i callbacks, got %i)�lenr�verbose�printrq�event�is_setr)rroru�context�countrI�arrr	�pendingcalls_waits
z"TestPendingCalls.pendingcalls_waitcs�d}g}Gdd�dt�}|��g�_d�_|�j�_d�_tj��_tj��_	��fdd�t
�j�D�}tj|���j
�j|��WdQRXdS)N� c@seZdZdS)z8TestPendingCalls.test_pendingcalls_threaded.<locals>.fooN)rr
rrrrr	�foosr�r9rcs.g|]$}tjd�jd�f��qS)�target�args)rl�Thread�pendingcalls_thread)�.0rI)r|rrr	�
<listcomp>&s	z?TestPendingCalls.test_pendingcalls_threaded.<locals>.<listcomp>)rKroru�nThreads�	nFinishedrl�Lock�lock�EventrzrqrZ
start_threadsr)rru�threadsr�r)r|rr	�test_pendingcalls_threadeds				z+TestPendingCalls.test_pendingcalls_threadedcCs�z|j|j|j�Wd|j�9|jd7_|j}dr[tjr[td|�WdQRX||jkr~|j	j
�XdS)Nr-Fzfinished threads: )rvrorur�r�rrxryr�rz�set)rr|r�rrr	r�,s
	z$TestPendingCalls.pendingcalls_threadcCs0g}d}|j||�|j||�dS)N�@)rvr)rrorurrr	�test_pendingcalls_non_threaded8sz/TestPendingCalls.test_pendingcalls_non_threaded)rr
rrvrr�r�r�rrrr	rm�s
rmc@seZdZdd�ZdS)�SubinterpreterTestcCs�ddl}tj�\}}dj|�}t|d��g}tj|�}|j|d�|jt	j
|�ttj
��|jt	j
|�t|��WdQRXdS)Nrz�if 1:
            import sys, builtins, pickle
            with open({:d}, "wb") as f:
                pickle.dump(id(sys.modules), f)
                pickle.dump(id(builtins), f)
            �rb)�builtins�os�pipe�format�openrZrun_in_subinterprZassertNotEqual�pickle�loadrr �modules)rr��r�wrd�f�retrrr	�test_subinterpsEs"z"SubinterpreterTest.test_subinterpsN)rr
rr�rrrr	r�Csr�c@seZdZdd�ZdS)�Test6012cCs |jtjdd�d�dS)NZHelloZWorldr-)rrZ
argparsing)rrrr	rWsz
Test6012.testN)rr
rrrrrr	r�Vsr�c@s^eZdZdd�Zdd�Zdd�Zdd�Zed	d
��Zdd�Z	d
S)�EmbeddingTestscCs	tjjt�}tjjtjjtjj|���}d}tjjd�r�dtjkridndd}||7}tjjtj�}ntjj	|d�}tjj	||�|_
}tjj|�s�|jd|�tj
�|_tj|�dS)NZ
_testembed�winZ_d�z.exeZProgramsz%r doesn't exist)r��path�abspath�__file__�dirnamer �platformr%r!�join�test_exe�existsZskipTest�getcwd�oldcwd�chdir)r�hereZbasepathZexename�extZexepathZexerrr	�setUp\s*
zEmbeddingTests.setUpcCstj|j�dS)N)r�r�r�)rrrr	�tearDownoszEmbeddingTests.tearDowncGs|jg}|j|�tj|dtjdtjdd�}|j�\}}|j|jdd|j|f�||fS)Nrr�universal_newlinesTrzbad returncode %d, stderr is %r)r��extendrrr"r#r�
returncode)rr��cmdr&r'r(rrr	�run_embedded_interpreterrs
			z'EmbeddingTests.run_embedded_interpretercCs:|j�\}}tjr6t�t|�t|�dS)N)r�rrxry)rr'r(rrr	r��s
	
zEmbeddingTests.test_subinterpscCsPtj�\}}z)tj|d��}|j}WdQRXWdtj|�X|S)Nr�)r�r��fdopen�encoding�close)ZrpZwpr�Zdefault_pipe_encodingrrr	�_get_default_pipe_encoding�sz)EmbeddingTests._get_default_pipe_encodingcCs�|jd�\}}tjr9t�t|�t|�tjj}tjj}|j	�}dj
ddddddd	dd
dddd
dddddddddddg�}|jd|d|d|�}d|_|j
|j�|�dS)NZforced_io_encoding�
z--- Use defaults ---zExpected encoding: defaultzExpected errors: defaultzstdin: {in_encoding}:{errors}zstdout: {out_encoding}:{errors}z'stderr: {out_encoding}:backslashreplacez--- Set errors only ---zExpected errors: ignorezstdin: {in_encoding}:ignorezstdout: {out_encoding}:ignorez--- Set encoding only ---zExpected encoding: latin-1zstdin: latin-1:{errors}zstdout: latin-1:{errors}z stderr: latin-1:backslashreplacez--- Set encoding and errors ---zExpected errors: replacezstdin: latin-1:replacezstdout: latin-1:replaceZin_encodingZout_encoding�errors)r�rrxryr �
__stdout__r��	__stdin__r�r�r�r�ZmaxDiffr�strip)rr'r(Zexpected_errorsZexpected_stdin_encodingZexpected_pipe_encodingZexpected_outputrrr	�test_forced_io_encoding�sN	

			z&EmbeddingTests.test_forced_io_encodingN)
rr
rr�r�r�r��staticmethodr�r�rrrr	r�[s
r�c@s4eZdZdd�Zdd�Zdd�ZdS)�SkipitemTestc"Cs�f}d}ddi}ddg}xdtdd�D]S}t|�}|dkrUq4|d}y tj||||�d	}Wngtk
r�}	zd
}
t|	�|
k}WYdd}	~	Xn+tk
r�}	zd	}WYdd}	~	XnXd|}y tj||||�d	}WnFtk
r[}	z&dj|�}
t|	�|
k}WYdd}	~	XnXd
j||||�}
|j|||
�q4WdS)Nr�br-r~r��z()e|$rIFz(argument 1 (impossible<bad format char>)�|z!impossible<bad format char>: '{}'z�test_skipitem_parity: detected mismatch between convertsimple and skipitem for format unit '{}' ({}), not skipped {}, skipped {})r)	rq�chrr�parse_tuple_and_keywordsr.rb�RuntimeErrorr�ZassertIs)rZempty_tupleZtuple_1Zdict_b�keywordsrI�cr�Zwhen_not_skippedr3�sZoptional_formatZwhen_skipped�messagerrr	�
test_skipitem�s:


$


%zSkipitemTest.test_skipitemcCs�|jttjfidg�|jttjfidd�|jttjfiddgd�|jttjfiddg�dS)NrUr�)rr.rr�r*)rrrr	�test_parse_tuple_and_keywordssz*SkipitemTest.test_parse_tuple_and_keywordscCst|jttftjd
iddg�|jttftjdidddg�|jttftjfddiddg�|jttftjfddddidddg�|jttftjfddid	dg�|jttftjfddddid
ddg�|jttftjdidddg�|jttftjdiddg�dS)Nr-z||Or~r9z|O|Or�z$$Oz$O$Oz$|Oz$O|Oz|Oz|OO)r-)r-r9)r-)r-)rr.rarr�r�)rrrr	�test_bad_uses ""zSkipitemTest.test_bad_useN)rr
rr�r�r�rrrr	r��sDr�c@s%eZdZejdd��ZdS)�TestThreadStatecsC�fdd�}|�tjd|�}|j�|j�dS)Ncsbg��fdd�}tj|�|}}tjd��j�jtj��dd�dS)Ncs�jtj��dS)N)rnrl�	get_identr)�identsrr	rp,szCTestThreadState.test_thread_state.<locals>.target.<locals>.callbackr-r8z/Couldn't find main thread correctly in the list)rZ_test_thread_staterrrsrr}rlr�)rpr~r�)r)r�r	r�)s


z1TestThreadState.test_thread_state.<locals>.targetr�)rlr��startr�)rr��tr)rr	�test_thread_state&s


z!TestThreadState.test_thread_stateN)rr
rrZreap_threadsr�rrrr	r�#sr�c@seZdZdd�ZdS)�
Test_testcapicCs]xVtt�D]H}|jd�r
|jdd|��tt|�}|�WdQRXq
WdS)NZtest_Zinternal�name)�dirrr%ZsubTest�getattr)rr�rrrr	�test__testcapi<s
zTest_testcapi.test__testcapiN)rr
rr�rrrr	r�;sr��__main__)#r�r�rtrr r]rrrjrrZtest.supportrZtest.support.script_helperrrL�ImportErrorrl�
import_moduler�hasattrr\r
rZTestCaserrkrmr�r�r�r�r�r�r�mainrrrr	�<module>sD

�Obf