Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 18.118.205.21
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_trace.cpython-310.pyc
o

ab�O�@s�ddlZddlZddlmZddlmZmZmZddlm	Z	m
Z
ddlZddlZddl
Z
ddl
mZddlmZdd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�ZGd#d$�d$e�Z Gd%d&�d&ej!�Z"Gd'd(�d(ej!�Z#Gd)d*�d*ej!�Z$Gd+d,�d,ej!�Z%Gd-d.�d.ej!�Z&Gd/d0�d0ej!�Z'Gd1d2�d2ej!�Z(Gd3d4�d4ej!�Z)e*d5kr�e�+�dSdS)6�N)�captured_stdout)�TESTFN�rmtree�unlink��assert_python_ok�assert_python_failure)�Trace)�testmodcCs|�d�r|dd�}|S)z8Given a .pyc filename converts it to the appropriate .pyz.pycN���)�endswith)�filename�r�8/usr/local/python-3.10/lib/python3.10/test/test_trace.py�
fix_ext_pys
rcCs$tj�tj�t��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_firstlineno�rcCs|}|}||}|Srr)�x�y�a�b�crrr�traced_func_linear%sr$cCs|}td�D]}||7}q|S�N���range)rr r#�irrr�traced_func_loop+s
r*cCs||t�d�S)N�)r
r)rr rrr�traced_func_importing1sr,cCst||�}||Sr�r$)rr#rrr�traced_func_simple_caller4s
r.cCst|�}|t||�7}|Sr)r.r,)r�krrr�traced_func_importing_caller8sr0ccs"�d}t|�D]}||VqdSr%r')�numr#r)rrr�traced_func_generator=s
��r2cCsd}td�D]}||7}qdS)Nr�
)r2)r/r)rrr�traced_func_calling_generatorBs
�r4cC�|dS�N�r)r1rrr�traced_doublerGrr8cOs||fSrr)�args�kwargsrrr�traced_capturerJrr;cCsd}dd�t|�D�}|S)Nr3cSsg|]}t|��qSr)r8)�.0r)rrr�
<listcomp>Osz4traced_caller_list_comprehension.<locals>.<listcomp>r')r/Zmylistrrr� traced_caller_list_comprehensionMsr>cCs,dd�}dd�}||�dd���}|�dS)NcS�|Srr��frrr�
decorator1S�z-traced_decorated_function.<locals>.decorator1cSsdd�}|S)NcSr?rrr@rrr�
decorator2VrCzGtraced_decorated_function.<locals>.decorator_fabric.<locals>.decorator2r�rDrrr�decorator_fabricUsz3traced_decorated_function.<locals>.decorator_fabriccSsdSrrrrrrrYsz'traced_decorated_function.<locals>.funcr)rBrFrrrr�traced_decorated_functionRs
rGc@s<eZdZdd�Zdd�Zdd�Zedd��Zed	d
��Z	dS)�TracedClasscCs
||_dSr�r!)�selfrrrr�__init__a�
zTracedClass.__init__cCs
|j|SrrI)rJr rrr�inst_method_lineardrL�TracedClass.inst_method_linearcCs|�|�}|t||�Sr)rMr$)rJrr#rrr�inst_method_callingg�
�TracedClass.inst_method_callingcCs|dSr6r)�clsr rrr�class_method_lineark�zTracedClass.class_method_linearcCr5r6r)r rrr�static_method_linearorTz TracedClass.static_method_linearN)
�__name__�
__module__�__qualname__rKrMrO�classmethodrS�staticmethodrUrrrrrH`s
rHc@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�TestLineCountsz/White-box testing of line-counting, via runfunccCs2|�tjt���tddddd�|_tt�|_dS)Nr+r��count�trace�
countfuncs�countcallers)	�
addCleanup�sys�settrace�gettracer	�tracerrr�my_py_filename�rJrrr�setUpyszTestLineCounts.setUpcCsb|j�tdd�}|�|d�i}tt�}tdd�D]}d||j||f<q|�|j��j|�dS)Nr7r&�r+)	re�runfuncr$�assertEqualrr(rf�results�counts)rJ�result�expected�firstlinenor)rrr�test_traced_func_linear~sz&TestLineCounts.test_traced_func_linearc	Csl|j�tdd�tt�}|j|dfd|j|dfd|j|dfd|j|dfdi}|�|j��j|�dS)Nr7�r+�r&�)rerjr*rrfrkrlrm�rJrprorrr�test_traced_func_loop�s�z$TestLineCounts.test_traced_func_loopcCs^|j�tdd�tt�}|j|dfdttj�dfdttj�dfdi}|�|j�	�j
|�dS)Nr7r&r+rr)rerjr,rrfrr
rrkrlrmrurrr�test_traced_func_importing�s�z)TestLineCounts.test_traced_func_importingc
Cs�|j�t�tt�}tt�}|j|dfd|j|dfd|j|dfd|j|dfd|j|dfd|j|dfdi}|�|j��j|�dS)Nr+r7�rrr3)	rerjr4rr2rfrkrlrm)rJ�firstlineno_callingZfirstlineno_genrorrr�test_trace_func_generator�s�z(TestLineCounts.test_trace_func_generatorc	Csp|j�t�tt�}tt�}|j|dfd|j|dfd|j|dfd|j|dfdi}|�|j��j|�dS)Nr+r7�rrr3)	rerjr>rr8rfrkrlrm)rJryZfirstlineno_calledrorrr�test_trace_list_comprehension�s�z,TestLineCounts.test_trace_list_comprehensioncCs�|j�t�tt�}|j|dfd|j|dfd|j|dfd|j|dfd|j|dfd|j|dfd|j|dfd|j|dfd|j|d	fd|j|d
fd|j|dfdi}|�|j��j|�dS)Nr+r7rrrtr&rsri��	r3rx)rerjrGrrfrkrlrmrurrr�test_traced_decorated_function�s�
z-TestLineCounts.test_traced_decorated_functioncCshdD]/}tddddd�}td�}t||�}|�|d�t|�}|j|dfdi}|�|��j|�qdS)N)rMr+rr\��)	r	rH�getattrrjrrfrkrlrm)rJZmethnamereZ
traced_obj�methodrprorrr�test_linear_methods�s
��z"TestLineCounts.test_linear_methodsN)rVrWrX�__doc__rhrqrvrwrzr|rr�rrrrr[wsr[c@s eZdZdZdd�Zdd�ZdS)�TestRunExecCountsz8A simple sanity test of line-counting, via runctx (exec)cCs tt�|_|�tjt���dSr)rrrfrarbrcrdrgrrrrh�s
zTestRunExecCounts.setUpc	Cs�tddddd�|_d}t|td�}|j�|t�t��tt�}|j	|dfd|j	|dfd|j	|dfd	|j	|d
fdi}|�
�D]}|�|j��j
|||�qAdS)Nr+rr\ztraced_func_loop(2, 5)�execr7rsrrr&rt)r	re�compilerZrunctx�globals�varsrr*rf�keysrkrlrm)rJ�coderpror/rrr�test_exec_counts�s��z"TestRunExecCounts.test_exec_countsN)rVrWrXr�rhr�rrrrr��sr�c@sbeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Ze	�
eed�o$e�
�d
�dd��Zdd�ZdS)�	TestFuncsz"White-box testing of funcs tracingcCs8|�tjt���tdddd�|_t�|_t��|_dS)Nrr+)r]r^r_)	rarbrcrdr	rer�filemod�_saved_tracefuncrgrrrrhszTestFuncs.setUpcCs|jdur
t�|j�dSdSr)r�rbrcrgrrr�tearDowns
�zTestFuncs.tearDowncCs>|j�td�|jdd|jddi}|�|j��j|�dS)Nr+�r.r-)rerjr.r�rkrl�calledfuncs�rJrorrr�test_simple_callers


�zTestFuncs.test_simple_callercCs�|jjtddddd�}|�|dddd�f�|�t��|jjtdd�Wd�n1s.wY|�t��|j��Wd�dS1sIwYdS)Nr+r7rrrt)rJr)r+r7)r�arg)rerjr;rkZassertRaises�	TypeError)rJ�resrrr�test_arg_errorss�"�zTestFuncs.test_arg_errorscCsb|j�td�|jdd|jdd|jdd|jddttj�ddfdi}|�|j��j	|�dS)Nr+r�r-�r0�r,r
r)
rerjr0r�rr
rrkrlr�r�rrr�test_loop_caller_importings



�z$TestFuncs.test_loop_caller_importingrd�3pre-existing trace function throws off measurementscCsRtd�}|j�|jd�|jdd|jdd|jddi}|�|j��j|�dS)Nr�r+)rQ)rNr-)rHrerjrOr�rkrlr�)rJ�objrorrr�test_inst_method_calling)s


�z"TestFuncs.test_inst_method_callingc
CsZ|j�t�|jdd|jdd|jdd|jdd|jddi}|�|j��j|�dS)N)rGr+)rFrE)rBr)rerjrGr�rkrlr�r�rrrr6s




�z(TestFuncs.test_traced_decorated_functionN)rVrWrXr�rhr�r�r�r��unittest�skipIf�hasattrrbrdr�rrrrrr�s	�
r�c@s:eZdZdZdd�Ze�eed�oe�	�d�dd��Z
dS)	�TestCallersz$White-box testing of callers tracingcCs.|�tjt���tdddd�|_t�|_dS)Nrr+)r]r^r`)rarbrcrdr	rerr�rgrrrrhEszTestCallers.setUprdr�cCs�|j�td�tj�tj�ddddf|jdfd|jd|jdfd|jd|jdfd|jd|jd	fd|jd	t	t
j�d
dffdi}|�|j��j
|�dS)Nr+r�.pyr^z
Trace.runfuncr�r�r-r�r
r)rerjr0rrrr^rr�rr
rkrlZcallersr�rrrr�Js.������z&TestCallers.test_loop_caller_importingN)rVrWrXr�rhr�r�r�rbrdr�rrrrr�Cs�r�c@s@eZdZdd�Zdd�Z	ddd�Zdd	�Zd
d�Zdd
�ZdS)�TestCoveragecCs|�tjt���dSr)rarbrcrdrgrrrrh`szTestCoverage.setUpcCstt�tt�dSr)rrrrgrrrr�cszTestCoverage.tearDown�_import test.support, test.test_pprint;test.support.run_unittest(test.test_pprint.QueryTestCase)cCs&|�|�|��}|jddtd�dS)NT)Zshow_missingZsummaryZcoverdir)�runrlZ
write_resultsr)rJre�cmd�rrrr�	_coveragegs
zTestCoverage._coveragecCs�tjddd�}t��
}|�|�Wd�n1swY|��}|�d|�|�d|�t�t�}|�d|�|�d|�dS)Nrr+�r^r]z	pprint.pyzcase.pyzpprint.coverzunittest.case.cover)	r^r	rr��getvalue�assertInr�listdirr)rJre�stdout�filesrrr�
test_coveragens�
zTestCoverage.test_coveragecCs�tj�tj�tj��}tjtjtj	|gddd�}t
��
}|�|�Wd�n1s+wYtj�t
�rDt�t
�}|�|dg�dSdS)Nrr+)Z
ignoredirsr^r]z_importlib.cover)rr�normpath�dirnamerr^r	rb�base_prefix�base_exec_prefixrr��existsrr�rk)rJZlibpathrer�r�rrr�test_coverage_ignoreys���
�z!TestCoverage.test_coverage_ignorec
Cs�tjddd�}d}|tjvrtj|=d}t��}|�||�Wd�n1s(wY|�d�|��i}|D]}|��dd�\}}}	t	|�t	|dd��f||	<q:t�
tj|j�}|�||�|�
||d�dS)	Nrr+r�ztest.tracedmodules.testmodz<import test.tracedmodules.testmod as t;t.func(0); t.func2();rrr)r&�d)r^r	rb�modulesrr��seek�readline�split�intZ_fullmodnamerr�rk)
rJrerr�r�Zcoverage�line�linesZcov�modulerrr�test_issue9936�s"
�
zTestCoverage.test_issue9936N)r�)	rVrWrXrhr�r�r�r�r�rrrrr�_s
�r�c@seZdZdd�ZdS)�Test_IgnorecCs�tjj}t�ddg|dd�g�}|�|�dd��|�|�dd��|�|�dd	��|�|�|ddd
�d��|�|�|dd�d
��|�|�|dd
�d��dS)Nrzy.zZfooZbarzx.pyzxy.pyZxyzy.pyr zbaz.pyZbazzz.py�z)rr�joinr^Z_Ignore�
assertTrue�names�assertFalse)rJZjn�ignorerrr�test_ignored�szTest_Ignore.test_ignoredN)rVrWrXr�rrrrr��sr�c@s4eZdZdZdZdd�Zdd�Zdd�Zd	d
�ZdS)�TestCoverageCommandLineOutputztmp.pyz	tmp.covercCsFt|jddd��}|�t�d��Wd�dS1swYdS)N�w�iso-8859-15��encodingu�                # coding: iso-8859-15
                x = 'spœm'
                if []:
                    print('unreachable')
            )�open�codefile�write�textwrap�dedent)rJrArrrrh�s"�z#TestCoverageCommandLineOutput.setUpcCst|j�t|j�dSr)rr��	coverfilergrrrr��rPz&TestCoverageCommandLineOutput.tearDowncCs�tj�tj�tj��}tj�|d�}t|�d��|j	g}t
|�\}}}|�|d�|�tj�
|��|�tj�
|j��t|jdd��}|�|��d�Wd�dS1sYwYdS)Nztrace.coverz-m trace --count�r�r�u^       # coding: iso-8859-15
    1: x = 'spœm'
    1: if []:
           print('unreachable')
)rrr��abspathr^rr�rr�r�rrkr�r�r�r�r��read)rJZtracedirZtracecoverpath�argv�statusr��stderrrArrr�%test_cover_files_written_no_highlight�s
�"�zCTestCoverageCommandLineOutput.test_cover_files_written_no_highlightcCs|d��|jg}t|�\}}}|�tj�|j��t|jdd��}|�	|�
�t�d��Wd�dS1s7wYdS)Nz-m trace --count --missingr�r�u�                       # coding: iso-8859-15
                    1: x = 'spœm'
                    1: if []:
                >>>>>>     print('unreachable')
            )
r�r�rr�rrr�r�r�rkr�r�r�)rJr�r�r�r�rArrr�'test_cover_files_written_with_highlight�s"�zETestCoverageCommandLineOutput.test_cover_files_written_with_highlightN)	rVrWrXr�r�rhr�r�r�rrrrr��s	r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�TestCommandLinecCs:d}|D]^}}tddg|�R��^}}|�||�qdS)N))s3progname is missing: required with the main options�-lz-T)s8cannot specify both --listfuncs and (--trace or --count)z-lc)s>argument -R/--no-report: not allowed with argument -r/--reportz-rR)sLmust specify one of --trace, --count, --report, --listfuncs, or --trackcallsz-g)s-r/--report requires -f/--filez-r)s3--summary can only be used with --count or --reportz-sT)sunrecognized arguments: -yz-y�-mr^)rr�)rJ�_errors�messager9�_r�rrr�
test_failures�s
�zTestCommandLine.test_failurescCs�td}tj�t�}t|ddd��7}|�t|�|�d�tddd|dd	�\}}}|�	d
|�d|�d|�d
�}|�	|�
�|�Wd�dS1sKwYdS)Nr�r��utf-8r�za = 1
r�r^r��ZPYTHONIOENCODINGsfunctions called:z
filename: z, modulename: z, funcname: <module>)rrrrr�rarr�rr��encode)rJr
�
modulename�fdr�r�r�rorrr�test_listfuncs_flag_success�s

�"�z+TestCommandLine.test_listfuncs_flag_successcCs�ttddd��}|�tt�|�d�|�d�Wd�n1s"wYtt�\}}}tdddtdd	�\}}}|�|��|�dS)
Nr�r�r�zimport sys
zprint(type(sys.argv))
r�r^r�r�)r�rrarr�rr��strip)rJr�r�Z
direct_stdoutr�Ztrace_stdoutrrr�test_sys_argv_list�s
�
�z"TestCommandLine.test_sys_argv_listcCs�t�d�}t�d�}tj�t�}t|ddd��}|�t|�|�t|�|�t�	d��Wd�n1s6wYt
ddd	|dd
�\}}}|��}|�|d�|�
d|�|�
d
|�d|�d�|�dS)Nr�z.coverr�r�r�z�                x = 1
                y = 2

                def f():
                    return x + y

                for i in range(10):
                    f()
            r�r^z-csr�rzlines   cov%   module   (path)z6   100%   z   (�))rrrrr�rarr�r�r�r�decoderkr�)rJr
Z
coverfilenamer�r�r�r�r�rrr�test_count_and_summarys

�

�z&TestCommandLine.test_count_and_summarycCs(tddddddd�tddddd�dS)	Nr�r^r�z--moduleZtimeitz-n�1Znot_a_module_zzzrrgrrr�test_run_as_modulesz"TestCommandLine.test_run_as_moduleN)rVrWrXr�r�r�r�r�rrrrr��s
r��__main__),rrbZtest.supportrZtest.support.os_helperrrrZtest.support.script_helperrrr�r�r^r	Ztest.tracedmodulesr
rrrr$r*r,r.r0r2r4r8r;r>rG�objectrHZTestCaser[r�r�r�r�r�r�r�rV�mainrrrr�<module>sH
mC>
2C�
© 2025 GrazzMean