Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_capi.cpython-34.pyc

�
f f-H�@sddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
yddlZWnek
r�dZYnXyddl
Z
Wnek
r�dZ
YnXejd�Zdd�ZGdd�d�ZGd	d
�d
ej�Zeje
d�Gdd
�d
ej��ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�Zeje
d�Gdd�dej��ZGdd�dej�Zedkr�ej�ndS)�N)�support)�MISSING_C_DOCSTRINGS�	_testcapicCs|S)zsome doc�)�selfrr�3/opt/alt/python34/lib64/python3.4/test/test_capi.py�testfunctionsrc@s.eZdZeje�Zeje�ZdS)�InstanceMethodN)�__name__�
__module__�__qualname__rZinstancemethod�idrrrrrr	sr	c@s�eZdZdd�Zejed�dd��Zdd�Zdd	�Z	eje
d
�dd��Zeje
d
�d
d��Zej
ed�dd��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�}WdQX|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_loop.s
		z)CAPITest.test_no_FatalError_infinite_loopcCs|jttj�dS)N)r�
ValueErrorrZ!make_memoryview_from_NULL_pointer)rrrr�!test_memoryview_from_NULL_pointer=sz*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_info@s$
	#zCAPITest.test_exc_infoz(_posixsubprocess required for this test.cCs�Gdd�dt�}|jttjd|�dddgdddd	d
ddd
ddddd�Gdd�dt�}|jttjd|�dddgdddd	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
rrr3rrrr�ZZsr4r*�������	�
���
����c@s(eZdZdd�Zdd�ZdS)z1CAPITest.test_seq_bytes_to_charp_array.<locals>.ZcSstjS)N)r�maxsize)rrrrr3asz9CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__len__cSsdS)N�xr)r�irrr�__getitem__csz=CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__getitem__N)r
rrr3rGrrrrr4`s)�objectrr+�_posixsubprocess�	fork_exec�MemoryError)rr4rrr�test_seq_bytes_to_charp_arrayWs@z&CAPITest.test_seq_bytes_to_charp_arraycCslGdd�dt�}|jttj|�dgdddgddd	d
ddd
dddddd�dS)Nc@seZdZdd�ZdS)z-CAPITest.test_subprocess_fork_exec.<locals>.ZcSsdS)Nr*r)rrrrr3ksz5CAPITest.test_subprocess_fork_exec.<locals>.Z.__len__N)r
rrr3rrrrr4jsr4�1r5r*r6r7r8r9r:r;r<r=r>r?r@rArBrC)rHrr+rIrJ)rr4rrr�test_subprocess_fork_exechsz"CAPITest.test_subprocess_fork_execz6Signature information for builtins requires docstringscCs8|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtj	jd�|jtj	jd�|jtj
jd�|jtj
jd�dS)	N�z 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_and_extra_newlines)rrrr� test_docstring_signature_parsingrs(z)CAPITest.test_docstring_signature_parsingN)r
rrr�unittest�
skipUnless�	threadingr&r(r2rIrLrNZskipIfrrQrrrrr!s
	rz!Threading required for this test.c@sOeZdZdd�Zddd�Zdd�Zdd	�Zd
d�ZdS)�TestPendingCallscs^�fdd�}xEt|�D]7}tjtj�d�xtj|�r?Pq?q?WqWdS)Ncs�jd�dS)N)�appendr)�lrr�callback�sz6TestPendingCalls.pendingcalls_submit.<locals>.callbackg{�G�z�?)�range�time�sleep�randomrZ_pending_threadfunc)rrW�nrXrFr)rWr�pendingcalls_submit�sz$TestPendingCalls.pendingcalls_submitNcCs�d}x�t|�|kr�drDtjrDtdt|�f�nxtd�D]}||}qQW|r�|jj�r�q	n|d7}|j|dkd|t|�f�q	Wdr�tjr�tdt|�f�ndS)NrFz(%i)i�r*i'z(timeout waiting for %i callbacks, got %i)�lenr�verbose�printrY�eventZis_setr)rrWr]�context�countrF�arrr�pendingcalls_wait�s
z"TestPendingCalls.pendingcalls_waitcs�d}g}Gdd�dt�}|��g�_d�_|�j�_d�_tj��_tj��_	��fdd�t
�j�D�}tj|���j
�j|��WdQXdS)N� c@seZdZdS)z8TestPendingCalls.test_pendingcalls_threaded.<locals>.fooN)r
rrrrrr�foo�srhr6rcs.g|]$}tjd�jd�f��qS)�target�args)rT�Thread�pendingcalls_thread)�.0rF)rcrrr�
<listcomp>�s	z?TestPendingCalls.test_pendingcalls_threaded.<locals>.<listcomp>)rHrWr]�nThreads�	nFinishedrTZLock�lockZEventrbrYrZ
start_threadsrf)rr]Zthreadsrhr)rcrr�test_pendingcalls_threaded�s				z+TestPendingCalls.test_pendingcalls_threadedcCs�z|j|j|j�Wd|j�<|jd7_|j}dr^tjr^td|�nWdQX||jkr�|j	j
�nXdS)Nr*Fzfinished threads: )r^rWr]rqrprr`rarorb�set)rrcrprrrrl�s
	z$TestPendingCalls.pendingcalls_threadcCs0g}d}|j||�|j||�dS)N�@)r^rf)rrWr]rrr�test_pendingcalls_non_threaded�sz/TestPendingCalls.test_pendingcalls_non_threaded)r
rrr^rfrrrlrurrrrrU�s
rUc@seZdZdd�ZdS)�SubinterpreterTestcCs�ddl}tj�\}}dj|�}t|d��g}tj|�}|j|d�|jt	j
|�ttj
��|jt	j
|�t|��WdQXdS)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�loadr
r�modules)rrx�r�w�code�fZretrrr�test_subinterps�s"z"SubinterpreterTest.test_subinterpsN)r
rrr�rrrrrv�srvc@seZdZdd�ZdS)�Test6012cCs |jtjdd�d�dS)NZHelloZWorldr*)rrZ
argparsing)rrrrr�sz
Test6012.testN)r
rrrrrrrr��s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|�ntj
�|_tj|�dS)NZ
_testembed�winZ_drOz.exe�Modulesz%r doesn't exist)ry�path�abspath�__file__�dirnamer�platformr"r�join�test_exe�existsZskipTest�getcwd�oldcwd�chdir)r�hereZbasepathZexenameZextZexepathZexerrr�setUps*
zEmbeddingTests.setUpcCstj|j�dS)N)ryr�r�)rrrr�tearDownszEmbeddingTests.tearDowncGs�|jg}|j|�tj|dtjdtj�}|j�\}}|j|jdd|j|f�|jd�|jd�fS)z'Runs a test in the embedded interpreterrrrzbad returncode %d, stderr is %r�latin1)	r��extendrrrr r�
returncode�decode)rrj�cmdr#r$r%rrr�run_embedded_interpreters
	z'EmbeddingTests.run_embedded_interpretercCs=|j�\}}tjr9t�t|�t|�ndS)N)r�rr`ra)rr$r%rrrr�&s
	
zEmbeddingTests.test_subinterpscCsOtj�\}}z(tj|d��}|j}WdQXWdtj|�X|S)Nr�)ryrz�fdopen�encoding�close)ZrpZwpr�Zdefault_pipe_encodingrrr�_get_default_pipe_encoding.sz)EmbeddingTests._get_default_pipe_encodingcCs�|jd�\}}tjr<t�t|�t|�ntjj}|j�}tj	j
ddddddddd	d
dddd
dddddd
d	dddg�j||�}d|_|j
|j�|�dS)NZforced_io_encodingz--- Use defaults ---zExpected encoding: defaultzExpected errors: defaultzstdin: {0}:strictzstdout: {1}:strictzstderr: {1}:backslashreplacez--- Set errors only ---z Expected errors: surrogateescapezstdin: {0}:surrogateescapezstdout: {1}:surrogateescapez--- Set encoding only ---zExpected encoding: latin-1zstdin: latin-1:strictzstdout: latin-1:strictz stderr: latin-1:backslashreplacez--- Set encoding and errors ---zstdin: latin-1:surrogateescapezstdout: latin-1:surrogateescape)r�rr`rar�	__stdin__r�r�ry�linesepr�r{ZmaxDiffr�strip)rr$r%Zexpected_stdin_encodingZexpected_pipe_encodingZexpected_outputrrr�test_forced_io_encoding8sF	

			z&EmbeddingTests.test_forced_io_encodingN)
r
rrr�r�r�r��staticmethodr�r�rrrrr�s

r�c@s(eZdZdd�Zdd�ZdS)�SkipitemTestc"Cs�f}d}idd6}ddg}xytdd�D]h}t|�}|dkrYq5n|d}y)tj|||jd	�|�d
}Wngtk
r�}	zd}
t|	�|
k}WYdd}	~	Xn+tk
r�}	zd
}WYdd}	~	XnXd
|}y)tj|||jd	�|�d
}WnFtk
rq}	z&dj|�}
t|	�|
k}WYdd}	~	XnXdj||||�}
|j	|||
�q5WdS)aA
        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 accomodate 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.

        rr*�brerg�z()e|$rF�asciiFz7argument 1 must be impossible<bad format char>, not intN�|z!impossible<bad format char>: '{}'z�test_skipitem_parity: detected mismatch between convertsimple and skipitem for format unit '{}' ({}), not skipped {}, skipped {})r)
rY�chrr�parse_tuple_and_keywords�encoder+�str�RuntimeErrorr{ZassertIs)rZempty_tupleZtuple_1Zdict_b�keywordsrF�cr{Zwhen_not_skippedr0�sZoptional_formatZwhen_skipped�messagerrr�
test_skipitemas:


$

%zSkipitemTest.test_skipitemcCs�|jttjfidg�|jttjfidd�|jttjfiddgd�|jttjfiddg�dS)N�*rrO)rr+rr�r')rrrr�test_parse_tuple_and_keywords�sz*SkipitemTest.test_parse_tuple_and_keywordsN)r
rrr�r�rrrrr�_sEr�c@s%eZdZejdd��ZdS)�TestThreadStatecsC�fdd�}|�tjd|�}|j�|j�dS)Ncsbg��fdd�}tj|�|}}tjd��j�jtj��dd�dS)Ncs�jtj��dS)N)rVrT�	get_identr)�identsrrrX�szCTestThreadState.test_thread_state.<locals>.target.<locals>.callbackr*r5z/Couldn't find main thread correctly in the list)rZ_test_thread_staterZr[rrdrTr�)rXrer�)r)r�rri�s


z1TestThreadState.test_thread_state.<locals>.targetri)rTrk�startr�)rri�tr)rr�test_thread_state�s


z!TestThreadState.test_thread_stateN)r
rrrZreap_threadsr�rrrrr��sr�c@seZdZdd�ZdS)�
Test_testcapicCs_xXtt�D]J}|jd�r
|jdd|��tt|�}|�WdQXq
q
WdS)NZtest_Zinternal�name)�dirrr"ZsubTest�getattr)rr�rrrr�test__testcapi�s
zTest_testcapi.test__testcapiN)r
rrr�rrrrr��sr��__main__)ryr}r\rrrZrRrrZtest.supportrrI�ImportErrorrT�
import_modulerrr	ZTestCaserrSrUrvr�r�r�r�r�r
�mainrrrr�<module>s>

yO]R