Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_trace.cpython-39.pyc

a

��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�+/usr/local/lib/python3.9/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>N�z4traced_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�rCrrr�decorator_fabricTsz3traced_decorated_function.<locals>.decorator_fabriccSsdSrrrrrrrXsz'traced_decorated_function.<locals>.funcr)rBrErrrr�traced_decorated_functionQsrFc@s<eZdZdd�Zdd�Zdd�Zedd��Zed	d
��Z	dS)�TracedClasscCs
||_dSr�r")�selfr rrr�__init__`szTracedClass.__init__cCs
|j|SrrH)rIr!rrr�inst_method_linearcs�TracedClass.inst_method_linearcCs|�|�}|t||�Sr)rKr%)rIr 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__rJrKrM�classmethodrP�staticmethodrQrrrrrG_s
rGc@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�rIrrr�setUpxszTestLineCounts.setUpcCsb|j�tdd�}|�|d�i}tt�}tdd�D]}d||j||f<q2|�|j��j|�dS)Nr7r'�r,)	ra�runfuncr%�assertEqualrr)rb�results�counts)rI�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'�)rarfr+rrbrgrhri�rIrlrkrrr�test_traced_func_loop�s�z$TestLineCounts.test_traced_func_loopcCs^|j�tdd�tt�}|j|dfdttj�dfdttj�dfdi}|�|j�	�j
|�dS)Nr7r'r,rn)rarfr-rrbrrrrgrhrirqrrr�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�rnr4)	rarfr5rr3rbrgrhri)rI�firstlineno_callingZfirstlineno_genrkrrr�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�rnr4)	rarfr?rr8rbrgrhri)rIruZfirstlineno_calledrkrrr�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,r7rnrpr'rore��	r4rt)rarfrFrrbrgrhrirqrrr�test_traced_decorated_function�s�
z-TestLineCounts.test_traced_decorated_functioncCshdD]^}tddddd�}td�}t||�}|�|d�t|�}|j|dfdi}|�|��j|�qdS)N)rKr,rrX��)	rrG�getattrrfrrbrgrhri)rIZmethnameraZ
traced_obj�methodrlrkrrr�test_linear_methods�s
�z"TestLineCounts.test_linear_methodsN)rRrSrT�__doc__rdrmrrrsrvrxr{r�rrrrrWvsrWc@s eZdZdZdd�Zdd�ZdS)�TestRunExecCountsz8A simple sanity test of line-counting, via runctx (exec)cCs tt�|_|�tjt���dSr)rrrbr]r^r_r`rcrrrrd�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,rrXztraced_func_loop(2, 5)�execr7rornr'rp)rra�compilerZrunctx�globals�varsrr+rb�keysrgrhri)rI�coderlrkr0rrr�test_exec_counts�s�z"TestRunExecCounts.test_exec_countsN)rRrSrTr�rdr�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,)rYrZr[)	r]r^r_r`rrar�filemod�_saved_tracefuncrcrrrrdszTestFuncs.setUpcCs|jdurt�|j�dSr)r�r^r_rcrrr�tearDowns
zTestFuncs.tearDowncCs>|j�td�|jdd|jddi}|�|j��j|�dS)Nr,�r/r.)rarfr/r�rgrh�calledfuncs�rIrkrrr�test_simple_callers


�zTestFuncs.test_simple_callercCs�|jjtddddd�}|�|dddd�f�|�t�� |jjtdd�Wd�n1s\0Y|�t��|j��Wd�n1s�0YdS)Nr,r7rnrp)rIr)r,r7)r�arg)rarfr;rgZassertRaises�	TypeError)rI�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)
rarfr1r�rrrrgrhr�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,)rN)rLr.)rGrarfrMr�rgrhr�)rI�objrkrrr�test_inst_method_calling(s


�z"TestFuncs.test_inst_method_callingc
CsZ|j�t�|jdd|jdd|jdd|jdd|jddi}|�|j��j|�dS)N)rFr,)rErD)rBr)rarfrFr�rgrhr�r�rrrr{5s




�z(TestFuncs.test_traced_decorated_functionN)rRrSrTr�rdr�r�r�r��unittest�skipIf�hasattrr^r`r�r{rrrrr��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,)rYrZr\)r]r^r_r`rrarr�rcrrrrdDszTestCallers.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�.pyrZz
Trace.runfuncr�r�r.r�rr)rarfr1rrrrZrr�rrrgrhZcallersr�rrrr�Is.������z&TestCallers.test_loop_caller_importingN)rRrSrTr�rdr�r�r�r^r`r�rrrrr�Bs�r�c@s>eZdZdd�Zdd�Zddd�Zdd	�Zd
d�Zdd
�ZdS)�TestCoveragecCs|�tjt���dSr)r]r^r_r`rcrrrrd_szTestCoverage.setUpcCstt�tt�dSr)rrrrcrrrr�bszTestCoverage.tearDown�_import test.support, test.test_pprint;test.support.run_unittest(test.test_pprint.QueryTestCase)cCs&|�|�|��}|jddtd�dS)NT)Zshow_missingZsummaryZcoverdir)�runrhZ
write_resultsr)rIra�cmd�rrrr�	_coveragefs
zTestCoverage._coveragecCs�tjddd�}t��}|�|�Wd�n1s40Y|��}|�d|�|�d|�t�t�}|�d|�|�d|�dS)Nrr,�rZrYz	pprint.pyzcase.pyzpprint.coverzunittest.case.cover)	rZrrr��getvalue�assertInr�listdirr)rIra�stdout�filesrrr�
test_coveragems(
zTestCoverage.test_coveragecCs�tj�tj�tj��}tjtjtj	|gddd�}t
��}|�|�Wd�n1sV0Ytj�t
�r�t�t
�}|�|dg�dS)Nrr,)Z
ignoredirsrZrYz_importlib.cover)rr�normpath�dirnamerrZrr^�base_prefix�base_exec_prefixrr��existsrr�rg)rIZlibpathrar�r�rrr�test_coverage_ignorexs��(
z!TestCoverage.test_coverage_ignorec
Cs�tjddd�}d}|tjvr$tj|=d}t��}|�||�Wd�n1sP0Y|�d�|��i}|D]6}|��dd�\}}}	t	|�t	|dd��f||	<qtt�
tj|j�}|�||�|�
||d�dS)	Nrr,r�ztest.tracedmodules.testmodz<import test.tracedmodules.testmod as t;t.func(0); t.func2();rnr
)r'�d)rZrr^�modulesrr��seek�readline�split�intZ_fullmodnamerr�rg)
rIrarr�r�Zcoverage�line�linesZcov�modulerrr�test_issue9936�s 
*
zTestCoverage.test_issue9936N)r�)	rRrSrTrdr�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�joinrZZ_Ignore�
assertTrue�names�assertFalse)rIZjn�ignorerrr�test_ignored�szTest_Ignore.test_ignoredN)rRrSrTr�rrrrr��sr�c@s4eZdZdZdZdd�Zdd�Zdd�Zd	d
�ZdS)�TestCoverageCommandLineOutputztmp.pyz	tmp.covercCsDt|jddd�� }|�t�d��Wd�n1s60YdS)N�w�iso-8859-15��encodingu�                # coding: iso-8859-15
                x = 'spœm'
                if []:
                    print('unreachable')
            )�open�codefile�write�textwrap�dedent)rIrArrrrd�sz#TestCoverageCommandLineOutput.setUpcCst|j�t|j�dSr)rr��	coverfilercrrrr��s
z&TestCoverageCommandLineOutput.tearDowncCs�tj�tj�tj��}tj�|d�}t|�d��|j	g}t
|�\}}}|�|d�|�tj�
|��|�tj�
|j��t|jdd�� }|�|��d�Wd�n1s�0YdS)Nztrace.coverz-m trace --countr>r�r�u^       # coding: iso-8859-15
    1: x = 'spœm'
    1: if []:
           print('unreachable')
)rrr��abspathrZrr�rr�r�r	rgr�r�r�r�r��read)rIZtracedirZtracecoverpath�argv�statusr��stderrrArrr�%test_cover_files_written_no_highlight�s
�zCTestCoverageCommandLineOutput.test_cover_files_written_no_highlightcCszd��|jg}t|�\}}}|�tj�|j��t|jdd��&}|�	|�
�t�d��Wd�n1sl0YdS)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�rgr�r�r�)rIr�r�r�r�rArrr�'test_cover_files_written_with_highlight�s
zETestCoverageCommandLineOutput.test_cover_files_written_with_highlightN)	rRrSrTr�r�rdr�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�-mrZ)r
r�)rI�_errors�messager9�_r�rrr�
test_failures�szTestCommandLine.test_failurescCs�td}tj�t�}t|ddd��l}|�t|�|�d�tddd|dd	�\}}}|�	d
|�d|�d|�d
�}|�	|�
�|�Wd�n1s�0YdS)Nr�r��utf-8r�za = 1
r�rZr��ZPYTHONIOENCODINGsfunctions called:z
filename: z, modulename: z, funcname: <module>)rrrrr�r]rr�r	r��encode)rIr�
modulename�fdr�r�r�rkrrr�test_listfuncs_flag_success�s

�z+TestCommandLine.test_listfuncs_flag_successcCs�ttddd��0}|�tt�|�d�|�d�Wd�n1sD0Ytt�\}}}tdddtdd	�\}}}|�|��|�dS)
Nr�r�r�zimport sys
zprint(type(sys.argv))
r�rZr�r�)r�rr]rr�r	r��strip)rIr�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��8}|�t|�|�t|�|�t�	d��Wd�n1sl0Yt
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�rZz-csr�rzlines   cov%   module   (path)z6   100%   z   (�))rrrrr�r]rr�r�r�r	�decodergr�)rIrZ
coverfilenamer�r�r�r�r�rrr�test_count_and_summarys

.

�z&TestCommandLine.test_count_and_summarycCs(tddddddd�tddddd�dS)	Nr�rZr�z--moduleZtimeitz-n�1Znot_a_module_zzzrrcrrr�test_run_as_modulesz"TestCommandLine.test_run_as_moduleN)rRrSrTr�r�r�r�r�rrrrr��s

r��__main__)-rr^Ztest.supportrrrrrrZtest.support.script_helperr	r
r�r�rZrZtest.tracedmodulesrrrrr%r+r-r/r1r3r5r8r;r?rF�objectrGZTestCaserWr�r�r�r�r�r�r�rR�mainrrrr�<module>sB 
mC>
2C


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists