
    	h8                    f   d dl mZ d dlmZ d dlmZ d dlZd dlZd dlZd dlm	Z	 d dl
Z
d dlZd dlZd dlmZ d dlZd dlZd dlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z# ddl"m$Z$ ddl"m%Z% ddl"m&Z& e%sd Z'e'xZ(Z)n
ej*        Z(d Z)d Z+d;dZ,d Z- G d d e.          Z/d! Z0d" Z1d# Z2d$ Z3d% Z4d& Z5e#d'             Z6d( Z7d) Z8d* Z9d<d,Z:d- Z; G d. d/e<          Z=d0 Z>	 	 	 d=d2Z?d3 Z@d4 ZAd5 ZBejC        d1d>d:            ZDdS )?    )annotations)deque)
namedtupleN)chain)	getsizeof)Any   )config)mock   )inspect)
Connection)Column)DropConstraint)	DropTable)ForeignKeyConstraint)MetaData)Tableschema)Integer	decorator)defaultdict)has_refcount_gc)inspect_getfullargspecc                 R    t          j                     t          j                     d S N)gccollect)argss    d/var/www/html/web-builder-api.evdpl.com/venv/lib/python3.11/site-packages/sqlalchemy/testing/util.pynon_refcount_gc_collectr#   .   s    



    c                     d S r    r&   r$   r"   lazy_gcr'   7   s    r$   c               #     K   t          dddg          } t          dt          j        dz             D ] | t          j        fd          V  d S )Npicklersloadsdumpsr	   c                .    t          j        |           S r   )pickler+   )dprotocols    r"   <lambda>zpicklers.<locals>.<lambda>?   s    a)B)B r$   )r   ranger.   HIGHEST_PROTOCOLr*   )ntr0   s    @r"   r)   r)   ;   sq      	J' 2	3	3B"f59:: D DbBBBBCCCCCCD Dr$   c                .    t          j        | |          S )N)k)randomchoices)
populationr6   s     r"   random_choicesr:   B   s    >*****r$   c                    t          | t                    rt          | |          S | t          j        dd|z  z             z                      t          j                  t          d|          z  S )N10
   )
isinstancefloatrounddecimalDecimalto_integralROUND_FLOORpow)valueprecs     r"   round_decimalrI   F   sl    % "UD!!! GOC#*$4555BB B r$   c                  2    e Zd Zd Zd Zd Zd Zd Zd ZdS )	RandomSetc                    t          t                              |                     }t          j        |           t          |          S r   )listset__iter__r7   shuffleiter)selfls     r"   rO   zRandomSet.__iter__Q   s6    d##$$qAwwr$   c                    t          j        dt          |           dz
            }t          t                              |                     |         }|                     |           |S )Nr   r	   )r7   randintlenrM   rN   rO   remove)rR   indexitems      r"   popzRandomSet.popV   sR    q#d))a-00CLL&&''.Dr$   c                R    t          t                              | |                    S r   )rK   rN   unionrR   others     r"   r\   zRandomSet.union\   s    4//000r$   c                R    t          t                              | |                    S r   )rK   rN   
differencer]   s     r"   r`   zRandomSet.difference_   s    e44555r$   c                R    t          t                              | |                    S r   )rK   rN   intersectionr]   s     r"   rb   zRandomSet.intersectionb   s     ))$66777r$   c                     t          |           S r   )rK   )rR   s    r"   copyzRandomSet.copye   s    r$   N)	__name__
__module____qualname__rO   rZ   r\   r`   rb   rd   r&   r$   r"   rK   rK   P   sn          
  1 1 16 6 68 8 8    r$   rK   c                    t          t                    }| D ] \  }}||                             |           !t          |          D ] \  }}||d         D ]}|||         v r  dS !dS )zATrue if the given sorting conforms to the given partial ordering.NFT)r   rN   add	enumerate)tuplessorted_elementsdepsparentchildinodens           r"   conforms_partial_orderingrs   i   s     sD    V_--  4 $ 	 	AtAwuuu 	 tr$   c                    t          t                    | D ] \  }}|                             |           !fdt           |                    S )Nc              3  
  K   t          |           dk    rt          |           V  d S | D ]V}t          |                               |g          }|                    |                   s |          D ]
}|g|z   V  Wd S )Nr	   )rV   rM   rN   r`   rb   )elementselemsubsetsub_ordering_all_orderingsedgess       r"   rz   z-all_partial_orderings.<locals>._all_orderings|   s      x==Ax..       4 4X114&99**5;77 4(6v(>(> 4 4#f|33333	4 4r$   )r   rN   ri   rQ   )rk   rv   rn   ro   rz   r{   s       @@r"   all_partial_orderingsr|   w   sw    E ! !e    4 4 4 4 4 4 x(()))r$   c                    	 || _         n<# t          $ r/ t          j        | j        | j        || j        | j                  } Y nw xY w| S )ac  Return 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.

    )re   	TypeErrortypesFunctionType__code____globals____defaults____closure__)fnnames     r"   function_namedr      s[    
 
 
 
Kr
 

 Is   
 6AAc                    |                                  }	  ||g|R i |}|                     ddd           |S #  t          j                    } | j        | }|s |cY S xY w)a  Run 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)ctxr   argkwobjresultr   raise_s           r"   run_as_contextmanagerr      s     --//C
C$#$$$$$T4&&&<>>x( 	MMMs	   $; $A!c                    d | D             S )zConverts the results of sql execution into a plain set of column tuples.

    Useful for asserting the results of an unordered query.
    c                ,    h | ]}t          |          S r&   tuple).0rows     r"   	<setcomp>zrowset.<locals>.<setcomp>   s    ***3E#JJ***r$   r&   )resultss    r"   rowsetr      s     +*'****r$   c                    J |             r   r&   )msgs    r"   failr      s    #5r$   c                x   ddl m} t          j                    }|d         }t	          |dd          }||_        	  | |i ||                                 |j        j        }|r7t          ||           |
                                                                 nt          |t          j                   ||_        S # |                                 |j        j        }|r7t          ||           |
                                                                 nt          |t          j                   ||_        w xY w)ztProvide bound MetaData for a single test, dropping afterwards.

    Legacy; use the "metadata" pytest fixture.

    r	   )fixturesr   metadataN) r   r   r   getattrr   close_all_sessionsbase_connection_fixture_connectiondrop_all_tables_from_metadataget_transactioncommitr
   db)r   r!   r   r   r   rR   	prev_metacfcs           r"   provide_metadatar      sS      H7Dj$//IDM"r42 	##%%% m: 	? *(C888
 !!((****)(FI>>>!# 	##%%% m: 	? *(C888
 !!((****)(FI>>>!!!!!s   B= =A<D9c                     t                      | D ]}                    |           t                    t          j        fd| D             ddt                    z  z   d                              dS )aq  A 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): ...

    c                    g | ]@d                      fdD                       ft          fdD                       z   AS )_c              3  H   K   | ]}                     |d           |V  dS FNgetr   r6   r/   s     r"   	<genexpr>z/flag_combinations.<locals>.<listcomp>.<genexpr>  s4      99Aq%9a999999r$   c              3  D   K   | ]}                     |d           V  dS r   r   r   s     r"   r   z/flag_combinations.<locals>.<listcomp>.<genexpr>  s/      22AEE!UOO222222r$   )joinr   )r   r/   keyss    @r"   
<listcomp>z%flag_combinations.<locals>.<listcomp>  su     

 

 

  XX999999999;2222T222223

 

 

r$   rp   a,)id_argnames)rN   updatesortedr
   combinationsrV   r   )r   r/   r   s     @r"   flag_combinationsr      s    > 55D  A$<<D

 

 

 

 "

 

 


 3T?#$   r$   c                     t                     }  d |d         D              } fdt          j        fdt          t	          |                    D             i |S )Nc                4    g | ]}t          j                    S r&   )r   Mock)r   r   s     r"   r   z'lambda_combinations.<locals>.<listcomp>#  s     @ @ @ @ @ @r$   r   c                *      fd}d z  |_         |S )Nc                       di |          S )Nr&   r&   )r   lambda_arg_setsposs    r"   fixturez<lambda_combinations.<locals>.create_fixture.<locals>.fixture&  s    "?((R((--r$   zfixture_%3.3d)re   )r   r   r   s   ` r"   create_fixturez+lambda_combinations.<locals>.create_fixture%  s6    	. 	. 	. 	. 	. 	. +S0r$   c                (    g | ]} |          fS r&   r&   )r   rp   r   s     r"   r   z'lambda_combinations.<locals>.<listcomp>-  s&    	=	=	=1>>!
	=	=	=r$   )r   r
   r   r2   rV   )r   r   r!   arg_setsr   s   `   @r"   lambda_combinationsr      s    !/22D @ @Q @ @ @AH     	=	=	=	=c(mm(<(<	=	=	=AC  r$   c                    t          |           d         }fd|D             }t          | j                  }|                               t	          j        | j        |          } |di |S )zGiven 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.

    r   c                <    i | ]}|                     |          S r&   )rZ   )r   r   r   s     r"   
<dictcomp>z"resolve_lambda.<locals>.<dictcomp>;  s%    :::#S"&&++:::r$   r&   )r   dictr   r   r   r   r   )__fnr   pos_argspass_pos_argsglbnew_fns    `    r"   resolve_lambdar   1  sy     &d++A.H:::::::M
t
 
 CJJrNNNs33F6""M"""r$   functionc                      fd}|S )z&Provide MetaData for a pytest fixture.c                L      fd} t          j                  |          S )Nc              3  &  K   t          j                    x}| _        	  | |          }|                    t          j                   |V  |                    t          j                   d S # |                    t          j                   w xY wr   )r   r   r   
create_allr
   r   drop_all)rR   r   r   r   s      r"   run_ddlz3metadata_fixture.<locals>.decorate.<locals>.run_ddlF  s      '-'8'88Ht}-D(++##FI... !!&),,,,,!!&),,,,s   /A/ /!B)scope)r
   r   )r   r   ddls   ` r"   decoratez"metadata_fixture.<locals>.decorateE  s<    		- 		- 		- 		- 		- )v~C(((111r$   r&   )r   r   s   ` r"   metadata_fixturer   B  s#    2 2 2 2 2 Or$   c                 ,     t            fd            }|S )ziForce the given table names to be dropped after test complete,
    isolating for foreign key cycles

    c                    	  | |i |t          t          j        t          t          j                             S # t          t          j        t          t          j                             w xY w)N)include_names)drop_all_tablesr
   r   r   )r   r!   r   namess      r"   gozforce_drop_names.<locals>.go\  sc    	P2t?r??FIwvy'9'9OOOOOOFIwvy'9'9OOOOOs	   > 5A3r   )r   r   s   ` r"   force_drop_namesr   V  s4     P P P P YP Ir$   c                  "    e Zd ZdZd Zd ZeZdS )adictz,Dict keys available as attributes.  Shadows.c                j    	 | |         S # t           $ r t                              | |          cY S w xY wr   )KeyErrorr   __getattribute__)rR   keys     r"   r   zadict.__getattribute__i  sH    	49 	4 	4 	4((s33333	4s   
 %22c                :     t           fd|D                       S )Nc                     g | ]
}|         S r&   r&   )r   r   rR   s     r"   r   z"adict.__call__.<locals>.<listcomp>p  s    000Cd3i000r$   r   )rR   r   s   ` r"   __call__zadict.__call__o  s&    00004000111r$   N)re   rf   rg   __doc__r   r   get_allr&   r$   r"   r   r   f  s9        664 4 42 2 2 GGGr$   r   c                     ddl m  fd}t          |t                    s:|                                5 } ||           d d d            d S # 1 swxY w Y   d S  ||           d S )Nr	   )enginesc                   j                             |            | j        j        sMddlm} |                    dd          5                      |            d d d            d S # 1 swxY w Y   d S                     |            d S )Nr	   )
assertionszCan't sort tablesF)assert_)testing_reaperprepare_for_drop_tablesdialectsupports_alterr   r   expect_warningsr   )
connectionr   r   r   s     r"   r   z)drop_all_tables_from_metadata.<locals>.gox  s    66zBBB!0 	*$$$$$$++#U ,   . . !!*---. . . . . . . . . . . . . . . . . .
 j)))))s   A((A,/A,)r   r   r?   r   begin)r   engine_or_connectionr   r  r   s   `   @r"   r   r   u  s    * * * * * * *J77 !!'')) 	ZBzNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	     s   AAAr   c                4   |t          |          }||dk    s
J d            |f}|                                 5 }t          |                    |                    D ]\  }}|rX||d         |vr|                    t          t          |d         t                      |d                                        `|r| j        j	        so|D ]\  }}	||d         |vrt          |d         t                      t          dt                    t          dt                    |d                   }
|                    t          t          |
j        j        g|
j        j        g|		                                	 d d d            d S # 1 swxY w Y   d S )
Nr   z2consider_schemas and schema are mutually exclusive)consider_schemasr	   r   r   xy)r   )rN   r  reversed%sort_tables_on_foreign_key_dependencyexecuter   r   r   r   r   r   r   r   r   cr  r  )engine	inspectorr   r  r   conn	table_keyfkcst_keyfkctbs              r"   r   r     s6     M** $
 
 
 
?
 
 
 #9	 %4';;!1 <   
  
 $	 $	OIt
  !-!!M99ilHJJy|LLL    
  ~4 "&  JE3%1!!HM99 a 

sG,,sG,,$Qx  B LL&0"$&BDF8#NNN    A$	% % % % % % % % % % % % % % % % % %s   EFFFc                ,     t            fd            }|S )Nc                p    	  | |i |                                  S #                                   w xY wr   )_clear)r   r   r   	event_clss      r"   r   z!teardown_events.<locals>.decorate  sD    	2s>b>>Is    5r   )r  r   s   ` r"   teardown_eventsr    s-        Y Or$   c                    d }t           t          t          t          t          t          t          |t
          t          t          t          it                      t          d          fd |           S )zReturns the approximate memory footprint an object and all of its
    contents.

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


    c                N    t          j        |                                           S r   )r   from_iterableitems)r/   s    r"   dict_handlerz total_size.<locals>.dict_handler  s    "17799---r$   r   c           
     <   t          |           v rdS                     t          |                      t          |           }                                D ]@\  }}t	          | |          r+|t          t           ||                               z  } nA|S )Nr   )idri   r   r  r?   summap)ostyphandlerall_handlersdefault_sizeseensizeofs       r"   r)  ztotal_size.<locals>.sizeof  s    a55D==1Aa&&(..00 	 	LC!S!! SVWWQZZ00111 r$   )r   rQ   rM   r   r   rN   	frozensetr   )r"  r  r&  r'  r(  r)  s     @@@@r"   
total_sizer+    s    . . . 	tdtlT4L 55DQ<<L
 
 
 
 
 
 
 
 6!99r$   c                    | g}t                      }d}|rN|                    d          }||u r|dz  }n-t          |t                    r|rt	          |          |gz   |z   }|N|S )zgiven a cache key tuple, counts how many instances of actual
    tuples are found.

    used to alert large jumps in cache key complexity.

    r   r	   )objectrZ   r?   r   rM   )tupstacksentinelnum_elementsrw   s        r"   count_cache_key_tuplesr2    s     EExxHL
 8yy||8ALLe$$ 	8 8T

hZ/%7  8 r$   secondsr@   cleanupr   c           	   #    K   t          j                     }d V  t          j                     |z
  }|| k    rJ	  |             t          j        d|dd|  d           d S # t          j        d|dd|  d           w xY wd S )Nztest took too long (z.4fz seconds > ))timer
   	skip_test)r3  r4  nowsecs       r"   skip_if_timeoutr;    s       )++C	EEE
)++
C
W}}	GIIIEsEEE7EEE    FEsEEE7EEE   	 }s   
A A=)r	   )r   )Nr   N)r3  r@   r4  r   )E
__future__r   collectionsr   r   
contextlibrB   r   	itertoolsr   r.   r7   r   r   r7  r   typingr   r   r
   r   r   r  r   r   r   r   r   r   r   r   sqlsql.sqltypesr   utilr   r   r   r   r#   
gc_collectr'   r    r)   r:   rI   rN   rK   rs   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r+  r2  contextmanagerr;  r&   r$   r"   <module>rF     s   # " " " " "       " " " " " "      				         



                                             # # # # # #       ) ) ) ) ) )                   " " " " " "             " " " " " " ) ) ) ) ) )     32J J  D D D+ + + +         2  * * *$  (  2+ + +   (" (" ("V. . .b  "# # #"   (       D   ! ! !4 5 5 5 5p  # # #L  ,       r$   