HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/sqlalchemy/testing/__pycache__/profiling.cpython-310.pyc
o

���g�'�@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
ddlmZzddlZWneyGdZYnwdZ	da	d	d
�ZGdd�d�Zddd�Zejddd��ZdS)z�Profiling support for unit and performance tests.

These are special purpose profiling methods which operate
in a more fine-grained way than nose's profiling plugin.

�)�annotationsN�)�config)�
gc_collect�)�has_compiled_extcCs|atjrt��dSdS�N)�
_current_test�_profile_stats�force_write�reset_count)�id_�r�G/usr/local/lib/python3.10/dist-packages/sqlalchemy/testing/profiling.py�_start_current_test6s�rc@s^eZdZdZddd�Zedd��Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�ProfileStatsFilez�Store per-platform/fn profiling results in a file.

    There was no json module available when this was written, but now
    the file format which is very deterministically line oriented is kind of
    handy in any case for diffs and merges.

    �
cumulativeNcCs�tjduotjj|_|jptjduotjj|_tj�|�|_	tj�
|j	�d|_t�
dd��|_||_||_|��|jrC|��dSdS)N���cSs
t�t�Sr)�collections�defaultdict�dictrrrr�<lambda>Qs
z+ProfileStatsFile.__init__.<locals>.<lambda>)r�options�force_write_profilesr�write_profiles�write�os�path�abspath�fname�split�short_fnamerr�data�dump�sort�_read�_write)�self�filenamer$r#rrr�__init__Gs ����zProfileStatsFile.__init__cCs�tjjdtjj}tjjdkrtjj�tjj�r|d7}d�dd�tj	dd�D��}t
��t
���
�t
���
�||g}|�d	�t�}|�|rKd
pLd�d�|�S)N�_�sqlite�_file�.cS�g|]}t|��qSr��str)�.0�vrrr�
<listcomp>e�z1ProfileStatsFile.platform_key.<locals>.<listcomp>rr�dbapiunicode�cextensions�
nocextensions)r�db�name�driver�dialect�_is_url_file_db�url�join�sys�version_info�platform�machine�system�lower�python_implementation�appendr)r'�	dbapi_key�
py_version�platform_tokens�	_has_cextrrr�platform_key[s �

�

zProfileStatsFile.platform_keycCst}||jvo|j|j|vSr�r	r"rK)r'�test_keyrrr�	has_statsts�zProfileStatsFile.has_statsc	Cs�t}|j|}||j}d|vrg|d<}n|d}d|vr&d|d<}n|d}t|�|k}|sA|�|�|jr>|��d}n|d||f}|dd7<|S)N�counts�
current_countr�linenor)r	r"rK�lenrFrr&)	r'�	callcountrM�per_fn�per_platformrOrP�	has_count�resultrrrrWzs$


zProfileStatsFile.resultcCsTt}||jvr	dS|j|}|j|vrdS||j}d|vr(g|ddd�<dSdS)NrOrL)r'rMrTrUrrrr�s



�zProfileStatsFile.reset_countcCs`t}|j|}||j}|d}|d}|t|�kr!|||d<n||d<|jr.|��dSdS)NrOrPrr)r	r"rKrRrr&)r'rSrMrTrUrOrPrrr�replace�s

�zProfileStatsFile.replacecCs
d|jS)Na
# %s
# This file is written out on a per-environment basis.
# For each test in aaa_profiling, the corresponding function and 
# environment is located within this file.  If it doesn't exist,
# the test is skipped.
# If a callcount does exist, it is compared to what we received. 
# assertions are raised if the counts do not match.
# 
# To add a new callcount test, apply the function_call_count 
# decorator and re-run the tests using the --write-profiles 
# option - this file will be rewritten including the new count.
# 
)r)r'rrr�_header�s�zProfileStatsFile._headerc
Cs�zt|j�}Wn
tyYdSwt|�D]8\}}|��}|r%|�d�r&q|��\}}}|j|}||}dd�|�d�D�}	|	|d<|d|d<d|d	<q|��dS)
N�#cSr.r)�int�r1�countrrrr3�r4z*ProfileStatsFile._read.<locals>.<listcomp>�,rOrrQrrP)	�openr�OSError�	enumerate�strip�
startswithr r"�close)
r'�	profile_frQ�linerMrKrOrTrU�crrrr%�s"�

zProfileStatsFile._readcCs�td|j�t|jd�}|�|���t|j�D]/}|j|}|�d|�t|�D]}||}d�dd�|dD��}|�d|||f�q+q|��dS)	NzWriting profile file %s�wz
# TEST: %s

r^css�|]}t|�VqdSrr/r\rrr�	<genexpr>�s�z*ProfileStatsFile._write.<locals>.<genexpr>rOz	%s %s %s
)	�printrr_rrY�sortedr"r>rd)r'rerMrTrKrUrgrrrr&�s
�zProfileStatsFile._write)rN)�__name__�
__module__�__qualname__�__doc__r)�propertyrKrNrWrrXrYr%r&rrrrr>s



r皙�����?cs$ddlm}|���fdd��}|S)a�Assert a target for a test case's function call count.

    The main purpose of this assertion is to detect changes in
    callcounts for various functions - the actual number is not as important.
    Callcounts are stored in a file keyed to Python version and OS platform
    information.  This file is generated automatically for new tests,
    and versioned so that unexpected changes in callcounts will be detected.

    r)�	decoratorcsnt��D]	}||i|��qt��}t�d��|D]	}||i|��}q|Wd�S1s0wYdS)N)�variance)�range�count_functions)�fn�args�kw�warm�	timerange�time�rv��timesrs�warmuprr�wrap�s$�z!function_call_count.<locals>.wrap)�sqlalchemy.utilrr)rsr~rrrr�rr}r�function_call_count�s
r�c
cst�tdur
t�d��t��stjst�dtj�t�t�	�}|�
�dV|��tj
|tjd�}|j}t�|�}|durBd}n|\}}td||f�|jt�dtj��|��tjr�tj�tj�\}}t�d�d}	d||	|pud	f}
|�|
�td
|
�tjr�t�|�dS|r�t ||�}t!||�|k}|r�tjr�t�|�dSt"d||d|tj#f��dSdS)
NzcProfile is not installedz�No profiling stats available on this platform for this function.  Run tests with --write-profiles to add statistics to %s for this platform.)�streamzPstats calls: %d Expected %sz[, ]r-rz%s_%s%sz.profilezDumped stats to file %sz�Adjusted function call count %s not within %s%% of expected %s, platform %s. Rerun with --write-profiles to regenerate this callcount.�d)$�cProfiler�_skip_test_exceptionr
rNr�	skip_testr!r�Profile�enable�disable�pstats�Statsr?�stdout�total_callsrWrj�
sort_stats�rer r$�print_statsr#rr�splitextr	�
dump_statsrrXr[�abs�AssertionErrorrK)
rs�pr�statsrS�expected�expected_count�line_no�base�ext�	test_name�dumpfile�deviance�failedrrrrus`�
��

����ru)rqrr)rq)ro�
__future__rr�
contextlibrrAr�r�r?�r�utilrrr��ImportErrorr
r	rrr��contextmanagerrurrrr�<module>s6	�
&