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__/util.cpython-310.pyc
o

���g�8�@s>ddlmZddlmZddlZddlZddlZddlmZddl	Z	ddl
Z
ddl
mZddlZddl
Z
ddlmZddlmZdd	lmZd
dlmZd
dlmZd
d
lmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dl m!Z!d
dl m"Z"d
dl m#Z#d
dl m$Z$e#s�dd�Z%e%Z&Z'nej(Z&dd�Z'dd�Z)dQdd �Z*d!d"�Z+Gd#d$�d$e,�Z-d%d&�Z.d'd(�Z/d)d*�Z0d+d,�Z1d-d.�Z2d/d0�Z3e!d1d2��Z4d3d4�Z5d5d6�Z6d7d8�Z7dRd:d;�Z8d<d=�Z9Gd>d?�d?e:�Z;d@dA�Z<		B	dSdCdD�Z=dEdF�Z>dGdH�Z?dIdJ�Z@ejAdBdTdOdP��ZBdS)U�)�annotations)�dequeN)�chain)�	getsizeof)�Any�)�config)�mock�)�inspect)�
Connection)�Column)�DropConstraint)�	DropTable)�ForeignKeyConstraint)�MetaData)�Table��schema)�Integer��	decorator)�defaultdict)�has_refcount_gc)�inspect_getfullargspeccGst��t��dS�N)�gc�collect)�args�r�B/usr/local/lib/python3.10/dist-packages/sqlalchemy/testing/util.py�non_refcount_gc_collect,sr!cCsdSrrrrrr �lazy_gc5sr"c#sT�t�}ddl}|�|�|D]�td|jd�D]
��j��fdd�fVqqdS)Nr���rcs��|��Sr)�dumps��d��pickle_�protocolrr �<lambda>Bszpicklers.<locals>.<lambda>)�set�pickle�add�range�HIGHEST_PROTOCOL�loads)�picklersr,rr'r r19s�
��r1cCstj||d�S)N)�k)�random�choices)�
populationr2rrr �random_choicesE�r6cCs<t|t�r
t||�S|t�dd|��tj�td|�S)N�1�0�
)�
isinstance�float�round�decimal�Decimal�to_integral�ROUND_FLOOR�pow)�value�precrrr �
round_decimalIs

��rEc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�	RandomSetcCs tt�|��}t�|�t|�Sr)�listr+�__iter__r3�shuffle�iter)�self�lrrr rHTs
zRandomSet.__iter__cCs4t�dt|�d�}tt�|��|}|�|�|S)Nrr)r3�randint�lenrGr+rH�remove)rK�index�itemrrr �popYs
z
RandomSet.popcC�tt�||��Sr)rFr+�union�rK�otherrrr rT_�zRandomSet.unioncCrSr)rFr+�
differencerUrrr rXbrWzRandomSet.differencecCrSr)rFr+�intersectionrUrrr rYerWzRandomSet.intersectioncCst|�Sr)rF�rKrrr �copyh�zRandomSet.copyN)	�__name__�
__module__�__qualname__rHrRrTrXrYr[rrrr rFSsrFcCs`tt�}|D]\}}||�|�qt|�D]\}}||d�D]}|||vr,dSq qdS)zATrue if the given sorting conforms to the given partial ordering.NFT)rr+r-�	enumerate)�tuples�sorted_elements�deps�parent�child�i�node�nrrr �conforms_partial_orderingls��rics>tt��|D]\}}�|�|�q��fdd��t�|��S)Nc3sb�t|�dkrt|�VdS|D]}t|��|g�}|��|�s.�|�D]}|g|Vq%qdS)Nr)rNrGr+rXrY)�elements�elem�subset�sub_ordering��_all_orderings�edgesrr ros���z-all_partial_orderings.<locals>._all_orderings)rr+r-rJ)rarjrdrerrnr �all_partial_orderingszs

rqc
Cs<z||_W|Styt�|j|j||j|j�}Y|Sw)acReturn a function with a given __name__.

    Will assign to __name__ and return the original function if possible on
    the Python implementation, otherwise a new function will be constructed.

    This function should be phased out as much as possible
    in favor of @decorator.   Tests that "generate" many named tests
    should be modernized.

    )r]�	TypeError�types�FunctionType�__code__�__globals__�__defaults__�__closure__)�fn�namerrr �function_named�s���r{cOsZ|��}z||g|�Ri|��}|�ddd�|WSt��}|j|�}|s)�|YS)aRun the given function under the given contextmanager,
    simulating the behavior of 'with' to support older
    Python versions.

    This is not necessary anymore as we have placed 2.6
    as minimum Python version, however some tests are still using
    this structure.

    N)�	__enter__�__exit__�sys�exc_info)�ctxry�arg�kw�obj�resultr�raise_rrr �run_as_contextmanager�s
r�cCsdd�|D�S)z�Converts the results of sql execution into a plain set of column tuples.

    Useful for asserting the results of an unordered query.
    cSsh|]}t|��qSr��tuple)�.0�rowrrr �	<setcomp>��zrowset.<locals>.<setcomp>r)�resultsrrr �rowset�sr�cCsJ|��rr)�msgrrr �fail�r\r�c	Os�ddlm}t��}|d}t|dd�}||_z*||i|��W|��|jj}|r8t	||�|�
���||_St	|tj
�||_S|��|jj}|r[t	||�|�
���||_wt	|tj
�||_w)ztProvide bound MetaData for a single test, dropping afterwards.

    Legacy; use the "metadata" pytest fixture.

    r)�fixturesr�metadataN)�r�rr�getattrr��close_all_sessions�base�_connection_fixture_connection�drop_all_tables_from_metadata�get_transaction�commitr�db)ryrr�r�r�rK�	prev_meta�cfcrrr �provide_metadata�s.	
��
�r�csTt��|D]}��|�qt���tj�fdd�|D�ddt��d���d��S)aqA facade around @testing.combinations() oriented towards boolean
    keyword-based arguments.

    Basically generates a nice looking identifier based on the keywords
    and also sets up the argument names.

    E.g.::

        @testing.flag_combinations(
            dict(lazy=False, passive=False),
            dict(lazy=True, passive=False),
            dict(lazy=False, passive=True),
            dict(lazy=False, passive=True, raiseload=True),
        )
        def test_fn(lazy, passive, raiseload): ...

    would result in::

        @testing.combinations(
            ("", False, False, False),
            ("lazy", True, False, False),
            ("lazy_passive", True, True, False),
            ("lazy_passive", True, True, True),
            id_="iaaa",
            argnames="lazy,passive,raiseload",
        )
        def test_fn(lazy, passive, raiseload): ...

    cs<g|]�d��fdd��D��ft�fdd��D���qS)�_c3s �|]}��|d�r|VqdS�FN��get�r�r2r%rr �	<genexpr>s�z/flag_combinations.<locals>.<listcomp>.<genexpr>c3s�|]	}��|d�VqdSr�r�r�r%rr r�s�)�joinr�)r���keysr%r �
<listcomp>s���z%flag_combinations.<locals>.<listcomp>rf�a�,)�id_�argnames)r+�update�sortedr�combinationsrNr�)r�r&rr�r �flag_combinations�s
��r�csPt��}�dd�|dD��}�fdd��tj�fdd�tt|��D�i|��S)NcSsg|]}t���qSr)r	�Mock�r�r�rrr r�&r�z'lambda_combinations.<locals>.<listcomp>rcs��fdd�}d�|_|S)Ncs�di|���S)Nrr�r�)�lambda_arg_sets�posrr �fixture)sz<lambda_combinations.<locals>.create_fixture.<locals>.fixturez
fixture_%3.3d)r])r�r�)r�)r�r �create_fixture(s
z+lambda_combinations.<locals>.create_fixturecsg|]}�|�f�qSrr)r�rf)r�rr r�0s)rrr�r.rN)r�r�r�arg_setsr)r�r�r �lambda_combinations#s��r�csNt|�d}�fdd�|D�}t|j�}|���t�|j|�}|di|��S)z�Given a no-arg lambda and a namespace, return a new lambda that
    has all the values filled in.

    This is used so that we can have module-level fixtures that
    refer to instance-level variables using lambdas.

    rcsi|]}|��|��qSr)rRr�r�rr �
<dictcomp>>sz"resolve_lambda.<locals>.<dictcomp>Nr)r�dictrvr�rsrtru)�__fnr��pos_args�
pass_pos_args�glb�new_fnrr�r �resolve_lambda4s	

r��functioncs�fdd�}|S)z&Provide MetaData for a pytest fixture.cs�fdd�}tj�d�|�S)Nc	3sN�t��}|_z�||�}|�tj�|VW|�tj�dS|�tj�wr)rrr��
create_allrr��drop_all)rKr�r��ryrr �run_ddlIs�
z3metadata_fixture.<locals>.decorate.<locals>.run_ddl)�scope)rr�)ryr���ddlr�r �decorateHsz"metadata_fixture.<locals>.decorater)r�r�rr�r �metadata_fixtureEsr�c�t�fdd��}|S)ziForce the given table names to be dropped after test complete,
    isolating for foreign key cycles

    cs@z||i|��Wttjttj��d�Sttjttj��d�w)N)�
include_names)�drop_all_tablesrr�r)ryrr���namesrr �go_s0zforce_drop_names.<locals>.gor)r�r�rr�r �force_drop_namesYsr�c@s$eZdZdZdd�Zdd�ZeZdS)�adictz,Dict keys available as attributes.  Shadows.cCs*z||WStyt�||�YSwr)�KeyErrorr��__getattribute__)rK�keyrrr r�ls

�zadict.__getattribute__cst�fdd�|D��S)Ncsg|]}�|�qSrr)r�r�rZrr r�sr�z"adict.__call__.<locals>.<listcomp>r�)rKr�rrZr �__call__rszadict.__call__N)r]r^r_�__doc__r�r��get_allrrrr r�is
r�csfddlm���fdd�}t|t�s-|���
}||�Wd�dS1s&wYdS||�dS)Nr)�enginescsl�j�|�|jjs/ddlm}|jddd����|�Wd�dS1s(wYdS��|�dS)Nr)�
assertionszCan't sort tablesF)�assert_)�testing_reaper�prepare_for_drop_tables�dialect�supports_alterr�r��expect_warningsr�)�
connectionr��r�r�rr r�{s�"�z)drop_all_tables_from_metadata.<locals>.go)r�r�r;r�begin)r��engine_or_connectionr�r�rr�r r�xs


"�r�rcCs2|durt|�}|dur|dksJd��|f}|���t}t|j|d��D]b\}}|rG|dur5|d|vr5q$|�tt|dt�|dd���q$|r�|jj	sNq$|D]5\}}	|dur_|d|vr_qPt|dt�t
dt�t
dt�|dd�}
|�tt
|
jjg|
jjg|	d	���qPq$Wd�dS1s�wYdS)
Nrz2consider_schemas and schema are mutually exclusive)�consider_schemasrrr�x�y)rz)r+r��reversed�%sort_tables_on_foreign_key_dependency�executerrrr�r�r
rrr�cr�r�)�engine�	inspectorrr�r��conn�	table_key�fkcs�t_key�fkc�tbrrr r��sX
�
���������"�r�cr�)Ncs$z||i|��W���S���wr)�_clear)ryr�r���	event_clsrr r��sz!teardown_events.<locals>.decorater)r�r�rr�r �teardown_events�sr�csLdd�}ttttttt|tttti�t��td������fdd���|�S)z�Returns the approximate memory footprint an object and all of its
    contents.

    source: https://code.activestate.com/recipes/577504/


    cSst�|���Sr)r�
from_iterable�itemsr%rrr �dict_handler�r7z total_size.<locals>.dict_handlerrcsdt|��vrdS��t|��t|��}���D]\}}t||�r/|tt�||���7}|Sq|S)Nr)�idr-rr�r;�sum�map)�o�s�typ�handler��all_handlers�default_size�seen�sizeofrr r�s

�ztotal_size.<locals>.sizeof)r�rJrGrr�r+�	frozensetr)r�r�rrr �
total_size�s	�r	cCsX|g}t�}d}|r*|�d�}||ur|d7}nt|t�r(|r(t|�|g|}|s
|S)z�given a cache key tuple, counts how many instances of actual
    tuples are found.

    used to alert large jumps in cache key complexity.

    rr)�objectrRr;r�rG)�tup�stack�sentinel�num_elementsrkrrr �count_cache_key_tuples�s


�r�secondsr<�cleanuprc
csl�t��}dVt��|}||kr4z|�Wt�d|d�d|�d��dSt�d|d�d|�d��wdS)Nztest took too long (z.4fz seconds > �))�timer�	skip_test)rr�now�secrrr �skip_if_timeouts����r)r)r�)NrN)rr<rr)C�
__future__r�collectionsr�
contextlibr>r�	itertoolsrr3r~rrrs�typingrr�rr	rr�rrr
rrrrr�sql�sql.sqltypesr�utilrrrrr!�
gc_collectr"rr1r6rEr+rFrirqr{r�r�r�r�r�r�r�r�r�r�r�r�r�r�r	r�contextmanagerrrrrr �<module>sz	


	
+1

�8&