Your IP : 216.73.216.85


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.pyc



��Yf�\�@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)zsome doc�)�selfrr�3/opt/alt/python35/lib64/python3.5/test/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)rZinstrrr	�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
rr5rrrr	�Z_sr6r,�������	�
���
����c@s(eZdZdd�Zdd�ZdS)z1CAPITest.test_seq_bytes_to_charp_array.<locals>.ZcSstjS)N)r�maxsize)rrrr	r5fsz9CAPITest.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
rr5rIrrrr	r6es)r,r8)r,r8)�objectrr-�_posixsubprocess�	fork_exec�MemoryError)rr6rrr	�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	r5psz5CAPITest.test_subprocess_fork_exec.<locals>.Z.__len__N)rr
rr5rrrr	r6osr6�1r7r,r8r9r:r;r<r=r>r?r@rArBrCrDrE)r,r8)rJrr-rKrL)rr6rrr	�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_rr`rZreturn_result_with_errorrarb)rrcrdr&r'rerrr	�test_return_result_with_error�s	
z&CAPITest.test_return_result_with_errorcCstj�dS)N)r�test_buildvalue_N)rrrr	rh�szCAPITest.test_buildvalue_NN)rr
rr�unittest�
skipUnless�	threadingr(r*r4rKrNrPZskipIfrrRrZrfrgrhrrrr	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)rrn�nrorHr)rnr	�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�printrp�eventZis_setr)rrnrt�context�countrH�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rr8rcs.g|]$}tjd�jd�f��qS)�target�args)rk�Thread�pendingcalls_thread)�.0rH)rzrrr	�
<listcomp>&s	z?TestPendingCalls.test_pendingcalls_threaded.<locals>.<listcomp>)rJrnrt�nThreads�	nFinishedrkZLock�lockZEventryrprZ
start_threadsr})rrtZthreadsrr)rzrr	�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: )rurnrtr�r�rrwrxr�ry�set)rrzr�rrr	r�,s
	z$TestPendingCalls.pendingcalls_threadcCs0g}d}|j||�|j||�dS)N�@)rur})rrnrtrrr	�test_pendingcalls_non_threaded8sz/TestPendingCalls.test_pendingcalls_non_threaded)rr
rrur}r�r�r�rrrr	rl�s
rlc@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�wrc�fZretrrr	�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�hereZbasepathZexenameZextZexepathZexerrr	�setUp\s*
zEmbeddingTests.setUpcCstj|j�dS)N)r�r�r�)rrrr	�tearDownoszEmbeddingTests.tearDowncGs|jg}|j|�tj|dtjdtjdd�}|j�\}}|j|jdd|j|f�||fS)z'Runs a test in the embedded interpreterrrZuniversal_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�rrwrx)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�rrwrxr�
__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}	~	XnXdj||||�}
|j|||
�q4WdS)aB
        If this test failed, you probably added a new "format unit"
        in Python/getargs.c, but neglected to update our poor friend
        skipitem() in the same file.  (If so, shame on you!)

        With a few exceptions**, this function brute-force tests all
        printable ASCII*** characters (32 to 126 inclusive) as format units,
        checking to see that PyArg_ParseTupleAndKeywords() return consistent
        errors both when the unit is attempted to be used and when it is
        skipped.  If the format unit doesn't exist, we'll get one of two
        specific error messages (one for used, one for skipped); if it does
        exist we *won't* get that error--we'll get either no error or some
        other error.  If we get the specific "does not exist" error for one
        test and not for the other, there's a mismatch, and the test fails.

           ** Some format units have special funny semantics and it would
              be difficult to accommodate them here.  Since these are all
              well-established and properly skipped in skipitem() we can
              get away with not testing them--this test is really intended
              to catch *new* format units.

          *** Python C source files must be ASCII.  Therefore it's impossible
              to have non-ASCII format units.

        r�br,r|r~�z()e|$rHFz(argument 1 (impossible<bad format char>)N�|z!impossible<bad format char>: '{}'z�test_skipitem_parity: detected mismatch between convertsimple and skipitem for format unit '{}' ({}), not skipped {}, skipped {})r)	rp�chrr�parse_tuple_and_keywordsr-ra�RuntimeErrorr�ZassertIs)rZempty_tupleZtuple_1Zdict_b�keywordsrH�cr�Zwhen_not_skippedr2�sZoptional_formatZwhen_skipped�messagerrr	�
test_skipitem�s:


$


%zSkipitemTest.test_skipitemcCs�|jttjfidg�|jttjfidd�|jttjfiddgd�|jttjfiddg�dS)NrTr�)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|r8z|O|Or�z$$Oz$O$Oz$|Oz$O|Oz|Oz|OO)r,)r,r8)r,)r,)rr-r`rr�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)rmrk�	get_identr)�identsrr	ro,szCTestThreadState.test_thread_state.<locals>.target.<locals>.callbackr,r7z/Couldn't find main thread correctly in the list)rZ_test_thread_staterqrrrr{rkr�)ror|r�)r)r�r	r�)s


z1TestThreadState.test_thread_state.<locals>.targetr�)rkr��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�rsrrr\rqrirrZtest.supportrZtest.support.script_helperrrK�ImportErrorrk�
import_moduler�hasattrr[r
rZTestCaserrjrlr�r�r�r�r�r�r�mainrrrr	�<module>sD

�Obf