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_trace.cpython-34.pyc

�
g f�9�@s�ddlZddlZddlZddlmZmZmZmZddlZddl	Z	ddl	m
Z
mZddlm
Z
dd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZGdd�de�ZGdd �d ej�ZGd!d"�d"ej�ZGd#d$�d$ej�ZGd%d&�d&ej�Z Gd'd(�d(ej�Z!Gd)d*�d*ej�Z"Gd+d,�d,ej�Z#e$d-kr�ej%�ndS).�N)�TESTFN�rmtree�unlink�captured_stdout)�CoverageResults�Trace)�testmodcCs&|jd�r"|dd�}n|S)z=Given a .pyc/.pyo filename converts it to the appropriate .py�.pyc�.pyoN�)r	r
���)�endswith)�filename�r�4/opt/alt/python34/lib64/python3.4/test/test_trace.py�
fix_ext_pysrcCs2tjjtjjt��d}tt�|fS)z4The .py file and module name of this file (__file__)r)�os�path�splitext�basename�__file__r)�modnamerrr�my_file_and_modnames"rcCs
|jjS)N)�__code__�co_firstlineno)�funcrrr�get_firstlinenosrcCs|}|}||}|S)Nr)�x�y�a�b�crrr�traced_func_linear$s
r"cCs+|}xtd�D]}||7}qW|S)N�)�range)rrr!�irrr�traced_func_loop*sr&cCs||tjd�S)Nr)rr)rrrrr�traced_func_importing0sr'cCst||�}||S)N)r")rr!rrr�traced_func_simple_caller3sr(cCs#t|�}|t||�7}|S)N)r(r')r�krrr�traced_func_importing_caller7sr*ccs*d}xt|�D]}||VqWdS)Nr#)r$)�numr!r%rrr�traced_func_generator<sr,cCs+d}xtd�D]}||7}qWdS)Nr�
)r,)r)r%rrr�traced_func_calling_generatorAsr.cCs|dS)N�r)r+rrr�traced_doublerFsr0cCs#d}dd�t|�D�}|S)Nr-cSsg|]}t|��qSr)r0)�.0r%rrr�
<listcomp>Ks	z4traced_caller_list_comprehension.<locals>.<listcomp>)r$)r)Zmylistrrr� traced_caller_list_comprehensionIsr3c@sXeZdZdd�Zdd�Zdd�Zedd��Zed	d
��Z	dS)�TracedClasscCs
||_dS)N)r)�selfrrrr�__init__PszTracedClass.__init__cCs|j|S)N)r)r5rrrr�inst_method_linearSszTracedClass.inst_method_linearcCs |j|�}|t||�S)N)r7r")r5rr!rrr�inst_method_callingVszTracedClass.inst_method_callingcCs|dS)Nr/r)�clsrrrr�class_method_linearZszTracedClass.class_method_linearcCs|dS)Nr/r)rrrr�static_method_linear^sz TracedClass.static_method_linearN)
�__name__�
__module__�__qualname__r6r7r8�classmethodr:�staticmethodr;rrrrr4Os
r4c@sjeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�TestLineCountsz/White-box testing of line-counting, via runfuncc	CsP|jtjtj��tdddddddd�|_tt�|_dS)N�countr�tracer�
countfuncs�countcallers)	�
addCleanup�sys�settrace�gettracer�tracerrr�my_py_filename)r5rrr�setUphs$zTestLineCounts.setUpcCs�|jjtdd�}|j|d�i}tt�}x.tdd�D]}d||j||f<qJW|j|jj�j|�dS)Nr/r#�r)	rJ�runfuncr"�assertEqualrr$rK�results�counts)r5�result�expected�firstlinenor%rrr�test_traced_func_linearmsz&TestLineCounts.test_traced_func_linearcCs�|jjtdd�tt�}id|j|df6d|j|df6d|j|df6d|j|df6}|j|jj�j|�dS)Nr/�r�r#�)rJrNr&rrKrOrPrQ)r5rTrSrrr�test_traced_func_loopysz$TestLineCounts.test_traced_func_loopcCs�|jjtdd�tt�}id|j|df6dttj�df6dttj�df6}|j|jj	�j
|�dS)Nr/r#rrV)rJrNr'rrKrrrrOrPrQ)r5rTrSrrr�test_traced_func_importing�sz)TestLineCounts.test_traced_func_importingcCs�|jjt�tt�}tt�}id|j|df6d|j|df6d|j|df6d|j|df6d|j|df6d|j|df6}|j|jj�j|�dS)Nr�r/r-rV)	rJrNr.rr,rKrOrPrQ)r5�firstlineno_callingZfirstlineno_genrSrrr�test_trace_func_generator�sz(TestLineCounts.test_trace_func_generatorcCs�|jjt�tt�}tt�}id|j|df6d|j|df6d|j|df6d|j|df6}|j|jj�j|�dS)Nr�r/rVr-)	rJrNr3rr0rKrOrPrQ)r5r\Zfirstlineno_calledrSrrr�test_trace_list_comprehension�sz,TestLineCounts.test_trace_list_comprehensionc
Cs�x�dgD]�}tdddddddd�}td�}t||�}|j|d	�t|�}id|j|df6}|j|j�j|�q
WdS)
Nr7rBrrCrrDrE��)	rr4�getattrrNrrKrOrPrQ)r5ZmethnamerJZ
traced_obj�methodrTrSrrr�test_linear_methods�s!z"TestLineCounts.test_linear_methodsN)r<r=r>�__doc__rLrUrYrZr]r_rdrrrrrAfsrAc@s.eZdZdZdd�Zdd�ZdS)�TestRunExecCountsz8A simple sanity test of line-counting, via runctx (exec)cCs,tt�|_|jtjtj��dS)N)rrrKrFrGrHrI)r5rrrrL�szTestRunExecCounts.setUpc	Cs�tdddddddd�|_d}t|td�}|jj|t�t��tt�}id|j	|df6d	|j	|d
f6d|j	|df6d|j	|d
f6}x8|j
�D]*}|j|jj�j
|||�q�WdS)NrBrrCrrDrEztraced_func_loop(2, 5)�execrWr/r#rVrX)rrJ�compilerZrunctx�globals�varsrr&rK�keysrOrPrQ)r5�coderTrSr)rrr�test_exec_counts�s$z"TestRunExecCounts.test_exec_countsN)r<r=r>rerLrmrrrrrf�srfc@smeZdZdZdd�Zdd�Zdd�Zeje	e
d�oTe
j�d	�d
d��ZdS)
�	TestFuncsz"White-box testing of funcs tracingcCsG|jtjtj��tdddddd�|_t�|_dS)NrBrrCrDr)rFrGrHrIrrJr�filemod)r5rrrrL�szTestFuncs.setUpcCsU|jjtd�id|jd6d|jd6}|j|jj�j|�dS)Nrr(r")ztraced_func_simple_caller)ztraced_func_linear)rJrNr(rorOrP�calledfuncs)r5rSrrr�test_simple_caller�s
zTestFuncs.test_simple_callercCs�|jjtd�id|jd6d|jd	6d|jd
6d|jd6dttj�ddf6}|j|jj�j	|�dS)Nrr(r"r*r'rr)ztraced_func_simple_caller)ztraced_func_linear)ztraced_func_importing_caller)ztraced_func_importing)
rJrNr*rorrrrOrPrp)r5rSrrr�test_loop_caller_importing�sz$TestFuncs.test_loop_caller_importingrIz3pre-existing trace function throws off measurementscCsrtd�}|jj|jd�id|jd6d|jd6d|jd6}|j|jj�j|�dS)	Nrar�TracedClass.inst_method_calling�TracedClass.inst_method_linearr")rs)rt)ztraced_func_linear)r4rJrNr8rorOrPrp)r5�objrSrrr�test_inst_method_calling�sz"TestFuncs.test_inst_method_callingN)
r<r=r>rerLrqrr�unittest�skipIf�hasattrrGrIrvrrrrrn�s	rnc@sUeZdZdZdd�Zejeed�o<ej	�d�dd��Z
dS)	�TestCallersz$White-box testing of callers tracingcCsG|jtjtj��tdddddd�|_t�|_dS)NrBrrCrEr)rFrGrHrIrrJrro)r5rrrrLszTestCallers.setUprIz3pre-existing trace function throws off measurementscCs�|jjtd�idtjjtj�ddddf|jdf6d|jd
|jdf6d|jd|jdf6d|jd|jdf6d|jdt	t
j�d
dff6}|j|jj�j
|�dS)Nrrz.pyrCz
Trace.runfuncr*r(r"r'rr)�traced_func_importing_caller)�traced_func_simple_caller)ztraced_func_linear)r{)r|)r{)�traced_func_importing)r})rJrNr*rrrrCrrorrrOrPZcallers)r5rSrrrrr
s4)z&TestCallers.test_loop_caller_importingN)r<r=r>rerLrwrxryrGrIrrrrrrrzsrzc@s[eZdZdd�Zdd�Zddd�Zdd	�Zd
d�Zdd
�ZdS)�TestCoveragecCs|jtjtj��dS)N)rFrGrHrI)r5rrrrL#szTestCoverage.setUpcCstt�tt�dS)N)rrr)r5rrr�tearDown&s
zTestCoverage.tearDownz_import test.support, test.test_pprint;test.support.run_unittest(test.test_pprint.QueryTestCase)cCs9|j|�|j�}|jdddddt�dS)NZshow_missingTZsummaryZcoverdir)ZrunrPZ
write_resultsr)r5rJ�cmd�rrrr�	_coverage*s
zTestCoverage._coveragec	Cs�tjdddd�}t��}|j|�WdQX|j�}|jd|k�|jd|k�tjt�}|jd|k�|jd|k�dS)	NrCrrBrz	pprint.pyzcase.pyzpprint.coverzunittest.case.cover)	rCrrr��getvalue�
assertTruer�listdirr)r5rJ�stdout�filesrrr�
test_coverage1szTestCoverage.test_coveragec	Cs�tjjtjjtj��}tjdtjtj	|gdddd�}t
��}|j|�WdQXtjjt
�r�tjt
�}|j|dg�ndS)NZ
ignoredirsrCrrBrz_importlib.cover)rr�normpath�dirnamerrCrrG�base_prefix�base_exec_prefixrr��existsrr�rO)r5ZlibpathrJr�r�rrr�test_coverage_ignore<s!z!TestCoverage.test_coverage_ignorec
Cstjdddd�}d}|tjkr:tj|=nd}t��}|j||�WdQX|jd�|j�i}xS|D]K}|j�dd�\}}}	t	|�t	|dd
��f||	<q�Wtj
tj|j�}|j||�|j
||d�dS)NrCrrBrztest.tracedmodules.testmodz<import test.tracedmodules.testmod as t;t.func(0); t.func2();rVr#�dr)r#r�)rCrrG�modulesrr��seek�readline�split�intZ_fullmodnamer�assertInrO)
r5rJrr�r�Zcoverage�line�linesZcov�modulerrr�test_issue9936Hs 



*zTestCoverage.test_issue9936N)	r<r=r>rLrr�r�r�r�rrrrr~"sr~c@seZdZdd�ZdS)�Test_IgnorecCs�tjj}tjddg|dd�g�}|j|jdd��|j|jdd��|j|jdd	��|j|j|ddd
�d��|j|j|dd�d
��|j|j|dd
�d��dS)Nrzy.z�fooZbarzx.pyzxy.pyZxyzy.pyrzbaz.pyZbazzz.py�z)rr�joinrCZ_Ignorer��namesZassertFalse)r5Zjn�ignorerrr�test_ignoredas$%"zTest_Ignore.test_ignoredN)r<r=r>r�rrrrr�`sr�c@speZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�TestDeprecatedMethodsc	CsItj�}|jt��tj|�WdQX|jd|j��dS)NzUsage:)�io�StringIO�assertWarns�DeprecationWarningrCZusager�r�)r5Zsiorrr�test_deprecated_usageosz+TestDeprecatedMethods.test_deprecated_usagecCs$|jt��tj�WdQXdS)N)r�r�rC�Ignore)r5rrr�test_deprecated_Ignoreusz,TestDeprecatedMethods.test_deprecated_IgnorecCs3|jt��|jdtjd��WdQXdS)N�spam)r�r�rOrCr)r5rrr�test_deprecated_modnameysz-TestDeprecatedMethods.test_deprecated_modnamecCs3|jt��|jdtjd��WdQXdS)Nr�)r�r�rOrCZfullmodname)r5rrr�test_deprecated_fullmodname}sz1TestDeprecatedMethods.test_deprecated_fullmodnamec
Cs<|jt��'dd�}tj|jdg�WdQXdS)NcSsdS)Nrrrrrr��szGTestDeprecatedMethods.test_deprecated_find_lines_from_code.<locals>.foo�eggs)r�r�rCZfind_lines_from_coder)r5r�rrr�$test_deprecated_find_lines_from_code�sz:TestDeprecatedMethods.test_deprecated_find_lines_from_codec
Cs<|jt��'dd�}tj|jdg�WdQXdS)NcSsdS)Nrrrrrr��sz=TestDeprecatedMethods.test_deprecated_find_lines.<locals>.foor�)r�r�rCZ
find_linesr)r5r�rrr�test_deprecated_find_lines�sz0TestDeprecatedMethods.test_deprecated_find_linescCsRttd��}|jtt�WdQX|jt��tj|j�WdQXdS)N�w)	�openrrFrr�r�rCZfind_strings�name)r5�fdrrr�test_deprecated_find_strings�sz2TestDeprecatedMethods.test_deprecated_find_stringscCsRttd��}|jtt�WdQX|jt��tj|j�WdQXdS)Nr�)	r�rrFrr�r�rCZfind_executable_linenosr�)r5r�rrr�'test_deprecated_find_executable_linenos�sz=TestDeprecatedMethods.test_deprecated_find_executable_linenosN)r<r=r>r�r�r�r�r�r�r�r�rrrrr�msr��__main__)&rr�rGZtest.supportrrrrrwrCrrZtest.tracedmodulesrrrrr"r&r'r(r*r,r.r0r3�objectr4ZTestCaserArfrnrzr~r�r�r<�mainrrrr�<module>s:"
Z*>
-