Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_trace.cpython-38.pyc
U

>��g�O�@s�ddlZddlZddlmZmZmZmZmZmZddl	m
Z
mZddlZddl
Z
ddlZddlmZddlmZdd�Zdd	�Zd
d�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.d/�d/e
j"�Z(Gd0d1�d1e
j"�Z)Gd2d3�d3e
j"�Z*e+d4k�r�e
�,�dS)5�N)�TESTFN�TESTFN_UNICODE�FS_NONASCII�rmtree�unlink�captured_stdout��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�./opt/cppython/lib/python3.8/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_modnamesrcCs|jjS�N)�__code__�co_firstlineno��funcrrr�get_firstlinenosrcCs|}|}||}|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�)rr)r r!rrr�traced_func_importing0sr-cCst||�}||Sr�r%)r r$rrr�traced_func_simple_caller3s
r/cCst|�}|t||�7}|Sr)r/r-)r �krrr�traced_func_importing_caller7sr1ccs d}t|�D]}||VqdSr&r()�numr$r*rrr�traced_func_generator<sr3cCsd}td�D]}||7}qdS)Nr�
)r3)r0r*rrr�traced_func_calling_generatorAsr5cCs|dS�N�r)r2rrr�traced_doublerFsr8cOs||fSrr)�args�kwargsrrr�traced_capturerIsr;cCsd}dd�t|�D�}|S)Nr4cSsg|]}t|��qSr)r8)�.0r*rrr�
<listcomp>Nsz4traced_caller_list_comprehension.<locals>.<listcomp>r()r0Zmylistrrr� traced_caller_list_comprehensionLsr>cCs,dd�}dd�}||�dd���}|�dS)NcSs|Srr��frrr�
decorator1Rsz-traced_decorated_function.<locals>.decorator1cSsdd�}|S)NcSs|Srrr?rrr�
decorator2UszGtraced_decorated_function.<locals>.decorator_fabric.<locals>.decorator2r�rBrrr�decorator_fabricTsz3traced_decorated_function.<locals>.decorator_fabriccSsdSrrrrrrrXsz'traced_decorated_function.<locals>.funcr)rArDrrrr�traced_decorated_functionQsrEc@s<eZdZdd�Zdd�Zdd�Zedd��Zed	d
��Z	dS)�TracedClasscCs
||_dSr�r")�selfr rrr�__init__`szTracedClass.__init__cCs
|j|SrrG)rHr!rrr�inst_method_linearcs�TracedClass.inst_method_linearcCs|�|�}|t||�Sr)rJr%)rHr r$rrr�inst_method_callingfs
�TracedClass.inst_method_callingcCs|dSr6r)�clsr!rrr�class_method_linearjszTracedClass.class_method_linearcCs|dSr6r)r!rrr�static_method_linearnsz TracedClass.static_method_linearN)
�__name__�
__module__�__qualname__rIrJrL�classmethodrO�staticmethodrPrrrrrF_s
rFc@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�rHrrr�setUpxszTestLineCounts.setUpcCsb|j�tdd�}|�|d�i}tt�}tdd�D]}d||j||f<q2|�|j��j|�dS)Nr7r'�r,)	r`�runfuncr%�assertEqualrr)ra�results�counts)rH�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'�)r`rer+rrarfrgrh�rHrkrjrrr�test_traced_func_loop�s�z$TestLineCounts.test_traced_func_loopcCs^|j�tdd�tt�}|j|dfdttj�dfdttj�dfdi}|�|j�	�j
|�dS)Nr7r'r,rm)r`rer-rrarrrrfrgrhrprrr�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�rmr4)	r`rer5rr3rarfrgrh)rH�firstlineno_callingZfirstlineno_genrjrrr�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�rmr4)	r`rer>rr8rarfrgrh)rHrtZfirstlineno_calledrjrrr�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,r7rmror'rnrd��	r4rs)r`rerErrarfrgrhrprrr�test_traced_decorated_function�s4�
z-TestLineCounts.test_traced_decorated_functioncCshdD]^}tddddd�}td�}t||�}|�|d�t|�}|j|dfdi}|�|��j|�qdS)N)rJr,rrW��)	rrF�getattrrerrarfrgrh)rHZmethnamer`Z
traced_obj�methodrkrjrrr�test_linear_methods�s
�z"TestLineCounts.test_linear_methodsN)rQrRrS�__doc__rcrlrqrrrurwrzrrrrrrVvsrVc@s eZdZdZdd�Zdd�ZdS)�TestRunExecCountsz8A simple sanity test of line-counting, via runctx (exec)cCs tt�|_|�tjt���dSr)rrrar\r]r^r_rbrrrrc�s
zTestRunExecCounts.setUpc	Cs�tddddd�|_d}t|td�}|j�|t�t��tt�}|j	|dfd|j	|dfd|j	|dfd	|j	|d
fdi}|�
�D] }|�|j��j
|||�q�dS)Nr,rrWztraced_func_loop(2, 5)�execr7rnrmr'ro)rr`�compilerZrunctx�globals�varsrr+ra�keysrfrgrh)rH�coderkrjr0rrr�test_exec_counts�s �z"TestRunExecCounts.test_exec_countsN)rQrRrSr�rcr�rrrrr��sr�c@sbeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Ze	�
eed�oHe�
�d
�dd��Zdd�ZdS)�	TestFuncsz"White-box testing of funcs tracingcCs8|�tjt���tdddd�|_t�|_t��|_dS)Nrr,)rXrYrZ)	r\r]r^r_rr`r�filemod�_saved_tracefuncrbrrrrcszTestFuncs.setUpcCs|jdk	rt�|j�dSr)r�r]r^rbrrr�tearDowns
zTestFuncs.tearDowncCs>|j�td�|jdd|jddi}|�|j��j|�dS)Nr,�r/r.)r`rer/r�rfrg�calledfuncs�rHrjrrr�test_simple_callers�zTestFuncs.test_simple_callerc	Cs�|jjtddddd�}|�|dddd�f�|�t��|jjtdd�}W5QRX|�|dd	dif�|�t��|j��W5QRXdS)
Nr,r7rmro)rHr)r,r7)r�argrr�)r`rer;rfZassertWarns�DeprecationWarningZassertRaises�	TypeError)rH�resrrr�test_arg_errorsszTestFuncs.test_arg_errorscCsb|j�td�|jdd|jdd|jdd|jddttj�ddfdi}|�|j��j	|�dS)Nr,r�r.�r1�r-rr)
r`rer1r�rrrrfrgr�r�rrr�test_loop_caller_importings�z$TestFuncs.test_loop_caller_importingr_�3pre-existing trace function throws off measurementscCsRtd�}|j�|jd�|jdd|jdd|jddi}|�|j��j|�dS)Nr|r,)rM)rKr.)rFr`rerLr�rfrgr�)rH�objrjrrr�test_inst_method_calling)s�z"TestFuncs.test_inst_method_callingc
CsZ|j�t�|jdd|jdd|jdd|jdd|jddi}|�|j��j|�dS)N)rEr,)rDrC)rAr)r`rerEr�rfrgr�r�rrrrz6s�z(TestFuncs.test_traced_decorated_functionN)rQrRrSr�rcr�r�r�r��unittest�skipIf�hasattrr]r_r�rzrrrrr��s		�
r�c@s:eZdZdZdd�Ze�eed�o(e�	�d�dd��Z
dS)	�TestCallersz$White-box testing of callers tracingcCs.|�tjt���tdddd�|_t�|_dS)Nrr,)rXrYr[)r\r]r^r_rr`rr�rbrrrrcEszTestCallers.setUpr_r�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�.pyrYz
Trace.runfuncr�r�r.r�rr)r`rer1rrrrYrr�rrrfrgZcallersr�rrrr�Js.������z&TestCallers.test_loop_caller_importingN)rQrRrSr�rcr�r�r�r]r_r�rrrrr�Cs�r�c@s>eZdZdd�Zdd�Zddd�Zdd	�Zd
d�Zdd
�ZdS)�TestCoveragecCs|�tjt���dSr)r\r]r^r_rbrrrrc`szTestCoverage.setUpcCstt�tt�dSr)rrrrbrrrr�cszTestCoverage.tearDown�_import test.support, test.test_pprint;test.support.run_unittest(test.test_pprint.QueryTestCase)cCs&|�|�|��}|jddtd�dS)NT)Zshow_missingZsummaryZcoverdir)�runrgZ
write_resultsr)rHr`�cmd�rrrr�	_coveragegs
zTestCoverage._coveragec	Csptjddd�}t��}|�|�W5QRX|��}|�d|�|�d|�t�t�}|�d|�|�d|�dS)Nrr,�rYrXz	pprint.pyzcase.pyzpprint.coverzunittest.case.cover)	rYrrr��getvalue�assertInr�listdirr)rHr`�stdout�filesrrr�
test_coveragens
zTestCoverage.test_coveragec	Csttj�tj�tj��}tjtjtj	|gddd�}t
��}|�|�W5QRXtj�t
�rpt�t
�}|�|dg�dS)Nrr,)Z
ignoredirsrYrXz_importlib.cover)rr�normpath�dirnamerrYrr]�base_prefix�base_exec_prefixrr��existsrr�rf)rHZlibpathr`r�r�rrr�test_coverage_ignoreys��
z!TestCoverage.test_coverage_ignorec
	Cs�tjddd�}d}|tjkr$tj|=d}t��}|�||�W5QRX|�d�|��i}|D]6}|��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();rmr
)r'�d)rYrr]�modulesrr��seek�readline�split�intZ_fullmodnamerr�rf)
rHr`rr�r�Zcoverage�line�linesZcov�modulerrr�test_issue9936�s 

zTestCoverage.test_issue9936N)r�)	rQrRrSrcr�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�joinrYZ_Ignore�
assertTrue�names�assertFalse)rHZjn�ignorerrr�test_ignored�szTest_Ignore.test_ignoredN)rQrRrSr�rrrrr��sr�c@s4eZdZdZdZdd�Zdd�Zdd�Zd	d
�ZdS)�TestCoverageCommandLineOutputztmp.pyz	tmp.coverc	Cs0t|jddd��}|�t�d��W5QRXdS)N�w�iso-8859-15��encodingu�                # coding: iso-8859-15
                x = 'spœm'
                if []:
                    print('unreachable')
            )�open�codefile�write�textwrap�dedent)rHr@rrrrc�sz#TestCoverageCommandLineOutput.setUpcCst|j�t|j�dSr)rr��	coverfilerbrrrr��s
z&TestCoverageCommandLineOutput.tearDownc	Cs�tj�tj�tj��}tj�|d�}t|�d��|j	g}t
|�\}}}|�|d�|�tj�
|��|�tj�
|j��t|jdd��}|�|��d�W5QRXdS)Nztrace.coverz-m trace --count�r�r�u^       # coding: iso-8859-15
    1: x = 'spœm'
    1: if []:
           print('unreachable')
)rrr��abspathrYrr�rr�r�r	rfr�r�r�r�r��read)rHZtracedirZtracecoverpath�argv�statusr��stderrr@rrr�%test_cover_files_written_no_highlight�s
�zCTestCoverageCommandLineOutput.test_cover_files_written_no_highlightc	Csfd��|jg}t|�\}}}|�tj�|j��t|jdd��}|�	|�
�t�d��W5QRXdS)Nz-m trace --count --missingr�r�u�                       # coding: iso-8859-15
                    1: x = 'spœm'
                    1: if []:
                >>>>>>     print('unreachable')
            )
r�r�r	r�rrr�r�r�rfr�r�r�)rHr�r�r�r�r@rrr�'test_cover_files_written_with_highlight�s
zETestCoverageCommandLineOutput.test_cover_files_written_with_highlightN)	rQrRrSr�r�rcr�r�r�rrrrr��s	r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�TestCommandLinecCs4d}|D]&^}}td|���^}}|�||�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�-mrY)r�rY)r
r�)rH�_errors�messager9�_r�rrr�
test_failures�szTestCommandLine.test_failuresc	Cs�td}tj�t�}t|ddd��b}|�t|�|�d�tddd|dd	�\}}}|�	d
|�d|�d|�d
�}|�	|�
�|�W5QRXdS)Nr�r��utf-8r�za = 1
r�rYr�)ZPYTHONIOENCODINGsfunctions called:z
filename: z, modulename: z, funcname: <module>)rrrrr�r\rr�r	r��encode)rHr�
modulename�fdr�r�r�rjrrr�test_listfuncs_flag_success�s

�z+TestCommandLine.test_listfuncs_flag_successc	Cspttddd��&}|�tt�|�d�|�d�W5QRXtt�\}}}tdddt�\}}}|�|��|�dS)	Nr�r�r�zimport sys
zprint(type(sys.argv))
r�rYr�)r�rr\rr�r	r��strip)rHr�r�Z
direct_stdoutr�Ztrace_stdoutrrr�test_sys_argv_list�s
z"TestCommandLine.test_sys_argv_listc	Cs�t�d�}t�d�}tj�t�}t|ddd��.}|�t|�|�t|�|�t�	d��W5QRXt
ddd	|�\}}}|��}|�|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�rYz-csrzlines   cov%   module   (path)z6   100%   z   (�))rrrrr�r\rr�r�r�r	�decoderfr�)rHrZ
coverfilenamer�r�r�r�r�rrr�test_count_and_summarys


z&TestCommandLine.test_count_and_summarycCs(tddddddd�tddddd�dS)	Nr�rYr�z--moduleZtimeitz-n�1Znot_a_module_zzzrrbrrr�test_run_as_modulesz"TestCommandLine.test_run_as_moduleN)rQrRrSr�r�r�r�r�rrrrr��s


r��__main__)-rr]Ztest.supportrrrrrrZtest.support.script_helperr	r
r�r�rYrZtest.tracedmodulesrrrrr%r+r-r/r1r3r5r8r;r>rE�objectrFZTestCaserVr�r�r�r�r�r�r�rQ�mainrrrr�<module>sB 
mD>
2A


F1le Man4ger