HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/test/__pycache__/test_trace.cpython-310.pyc
o

�i�Q�@s�ddlZddlmZddlZddlmZddlmZmZm	Z	ddl
mZmZddl
Z
ddlZddlZddlmZddlmZdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Z Gd$d%�d%e!�Z"Gd&d'�d'ej#�Z$Gd(d)�d)ej#�Z%Gd*d+�d+ej#�Z&Gd,d-�d-ej#�Z'Gd.d/�d/ej#�Z(Gd0d1�d1ej#�Z)Gd2d3�d3ej#�Z*Gd4d5�d5ej#�Z+e,d6kr�e�-�dSdS)7�N)�dump)�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�,/usr/local/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)r r!r$�irrr�traced_func_loop,s
r+cCs||t�d�S)N�)rr)r r!rrr�traced_func_importing2sr-cCst||�}||Sr�r%)r r$rrr�traced_func_simple_caller5s
r/cCst|�}|t||�7}|Sr)r/r-)r �krrr�traced_func_importing_caller9sr1ccs"�d}t|�D]}||VqdSr&r()�numr$r*rrr�traced_func_generator>s
��r3cCsd}td�D]}||7}qdS)Nr�
)r3)r0r*rrr�traced_func_calling_generatorCs
�r5cC�|dS�N�r)r2rrr�traced_doublerHrr9cOs||fSrr)�args�kwargsrrr�traced_capturerKrr<cCsd}dd�t|�D�}|S)Nr4cSsg|]}t|��qSr)r9)�.0r*rrr�
<listcomp>Psz4traced_caller_list_comprehension.<locals>.<listcomp>r()r0Zmylistrrr� traced_caller_list_comprehensionNsr?cCs,dd�}dd�}||�dd���}|�dS)NcS�|Srr��frrr�
decorator1T�z-traced_decorated_function.<locals>.decorator1cSsdd�}|S)NcSr@rrrArrr�
decorator2WrDzGtraced_decorated_function.<locals>.decorator_fabric.<locals>.decorator2r�rErrr�decorator_fabricVsz3traced_decorated_function.<locals>.decorator_fabriccSsdSrrrrrrrZsz'traced_decorated_function.<locals>.funcr)rCrGrrrr�traced_decorated_functionSs
rHc@s<eZdZdd�Zdd�Zdd�Zedd��Zed	d
��Z	dS)�TracedClasscCs
||_dSr�r")�selfr rrr�__init__b�
zTracedClass.__init__cCs
|j|SrrJ)rKr!rrr�inst_method_linearerM�TracedClass.inst_method_linearcCs|�|�}|t||�Sr)rNr%)rKr r$rrr�inst_method_callingh�
�TracedClass.inst_method_callingcCs|dSr7r)�clsr!rrr�class_method_linearl�zTracedClass.class_method_linearcCr6r7r)r!rrr�static_method_linearprUz TracedClass.static_method_linearN)
�__name__�
__module__�__qualname__rLrNrP�classmethodrT�staticmethodrVrrrrrIas
rIc@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�rKrrr�setUpzszTestLineCounts.setUpcCsb|j�tdd�}|�|d�i}tt�}tdd�D]}d||j||f<q|�|j��j|�dS)Nr8r'�r,)	rf�runfuncr%�assertEqualrr)rg�results�counts)rK�result�expected�firstlinenor*rrr�test_traced_func_linearsz&TestLineCounts.test_traced_func_linearc	Csl|j�tdd�tt�}|j|dfd|j|dfd|j|dfd|j|dfdi}|�|j��j|�dS)Nr8�r,�r'�)rfrkr+rrgrlrmrn�rKrqrprrr�test_traced_func_loop�s�z$TestLineCounts.test_traced_func_loopcCs^|j�tdd�tt�}|j|dfdttj�dfdttj�dfdi}|�|j�	�j
|�dS)Nr8r'r,rs)rfrkr-rrgrrrrlrmrnrvrrr�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,r8�rsr4)	rfrkr5rr3rgrlrmrn)rK�firstlineno_callingZfirstlineno_genrprrr�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,r8�rsr4)	rfrkr?rr9rgrlrmrn)rKrzZfirstlineno_calledrprrr�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,r8rsrur'rtrj��	r4ry)rfrkrHrrgrlrmrnrvrrr�test_traced_decorated_function�s�
z-TestLineCounts.test_traced_decorated_functioncCshdD]/}tddddd�}td�}t||�}|�|d�t|�}|j|dfdi}|�|��j|�qdS)N)rNr,rr]��)	r
rI�getattrrkrrgrlrmrn)rKZmethnamerfZ
traced_obj�methodrqrprrr�test_linear_methods�s
��z"TestLineCounts.test_linear_methodsN)rWrXrY�__doc__rirrrwrxr{r}r�r�rrrrr\xsr\c@s eZdZdZdd�Zdd�ZdS)�TestRunExecCountsz8A simple sanity test of line-counting, via runctx (exec)cCs tt�|_|�tjt���dSr)rrrgrbrcrdrerhrrrri�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)�execr8rtrsr'ru)r
rf�compilerZrunctx�globals�varsrr+rg�keysrlrmrn)rK�coderqrpr0rrr�test_exec_counts�s��z"TestRunExecCounts.test_exec_countsN)rWrXrYr�rir�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`)	rbrcrdrer
rfr�filemod�_saved_tracefuncrhrrrriszTestFuncs.setUpcCs|jdur
t�|j�dSdSr)r�rcrdrhrrr�tearDown	s
�zTestFuncs.tearDowncCs>|j�td�|jdd|jddi}|�|j��j|�dS)Nr,�r/r.)rfrkr/r�rlrm�calledfuncs�rKrprrr�test_simple_caller
s


�zTestFuncs.test_simple_callercCs�|jjtddddd�}|�|dddd�f�|�t��|jjtdd�Wd�n1s.wY|�t��|j��Wd�dS1sIwYdS)Nr,r8rsru)rKr)r,r8)r�arg)rfrkr<rlZassertRaises�	TypeError)rK�resrrr�test_arg_errorss�"�zTestFuncs.test_arg_errorscCsb|j�td�|jdd|jdd|jdd|jddttj�ddfdi}|�|j��j	|�dS)Nr,r�r.�r1�r-rr)
rfrkr1r�rrrrlrmr�r�rrr�test_loop_caller_importings



�z$TestFuncs.test_loop_caller_importingre�3pre-existing trace function throws off measurementscCsRtd�}|j�|jd�|jdd|jdd|jddi}|�|j��j|�dS)Nr�r,)rR)rOr.)rIrfrkrPr�rlrmr�)rK�objrprrr�test_inst_method_calling*s


�z"TestFuncs.test_inst_method_callingc
CsZ|j�t�|jdd|jdd|jdd|jdd|jddi}|�|j��j|�dS)N)rHr,)rGrF)rCr)rfrkrHr�rlrmr�r�rrrr�7s




�z(TestFuncs.test_traced_decorated_functionN)rWrXrYr�rir�r�r�r��unittest�skipIf�hasattrrcrer�r�rrrrr�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_ra)rbrcrdrer
rfrr�rhrrrriFszTestCallers.setUprer�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�rr)rfrkr1rrrr_rr�rrrlrm�callersr�rrrr�Ks.������z&TestCallers.test_loop_caller_importingN)rWrXrYr�rir�r�r�rcrer�rrrrr�Ds�r�c@sHeZdZdd�Zdd�Z	ddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)�TestCoveragecCs|�tjt���dSr)rbrcrdrerhrrrriaszTestCoverage.setUpcCstt�tt�dSr)rrrrhrrrr�dszTestCoverage.tearDown�_import test.support, test.test_pprint;test.support.run_unittest(test.test_pprint.QueryTestCase)cCs&|�|�|��}|jddtd�dS)NT)Zshow_missingZsummaryZcoverdir)�runrmZ
write_resultsr)rKrf�cmd�rrrr�	_coveragehs
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)rKrf�stdout�filesrrr�
test_coverageos�
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
rc�base_prefix�base_exec_prefixrr��existsrr�rl)rKZlibpathrfr�r�rrr�test_coverage_ignorezs���
�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();rsr)r'�d)r_r
rc�modulesrr��seek�readline�split�intZ_fullmodnamerr�rl)
rKrfrr�r�Zcoverage�line�linesZcov�modulerrr�test_issue9936�s"
�
zTestCoverage.test_issue9936cCs|td}t|d��}tiiddif|dd�Wd�n1s wY|�t|�t�ii|i�}|�|jddi�dS)Nz-infile�wbZcallerr,)�protocol)	r�openrrbrr_ZCoverageResultsrlr�)rKZinfilerBrmrrr�test_coverageresults_update�s�z(TestCoverage.test_coverageresults_updateN)r�)
rWrXrYrir�r�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)Nr zy.zZfooZbarzx.pyzxy.pyZxyzy.pyr!zbaz.pyZbazzz.py�z)rr�joinr_Z_Ignore�
assertTrue�names�assertFalse)rKZjn�ignorerrr�test_ignored�szTest_Ignore.test_ignoredN)rWrXrYr�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')
            )r��codefile�write�textwrap�dedent)rKrBrrrri�s"�z#TestCoverageCommandLineOutput.setUpcCst|j�t|j�dSr)rr��	coverfilerhrrrr��rQz&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�rrlr�r�r�r�r��read)rKZtracedirZtracecoverpath�argv�statusr��stderrrBrrr�%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�rlr�r�r�)rKr�r�r�r�rBrrr�'test_cover_files_written_with_highlight�s"�zETestCoverageCommandLineOutput.test_cover_files_written_with_highlightN)	rWrXrYr�r�rir�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_)r	r�)rK�_errors�messager:�_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�rbrr�rr��encode)rKr�
modulename�fdr�r�r�rprrr�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�rrbrr�rr��strip)rKr�r�Z
direct_stdoutr�Ztrace_stdoutrrr�test_sys_argv_lists
�
�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�rbrr�r�r�r�decoderlr�)rKrZ
coverfilenamer�r�r�r�r�rrr�test_count_and_summarys

�

�z&TestCommandLine.test_count_and_summarycCs(tddddddd�tddddd�dS)	Nr�r_r�z--moduleZtimeitz-n�1Znot_a_module_zzzrrhrrr�test_run_as_module$sz"TestCommandLine.test_run_as_moduleN)rWrXrYr�r�r�r�r�rrrrr��s
r��__main__).r�picklerrcZtest.supportrZtest.support.os_helperrrrZtest.support.script_helperrr	r�r�r_r
Ztest.tracedmodulesrrrrr%r+r-r/r1r3r5r9r<r?rH�objectrIZTestCaser\r�r�r�r�r�r�r�rW�mainrrrr�<module>sJ
mCG
2C�