g8LddlmZddlmZddlZddlZddlZddlmZddl Z ddl Z ddl m Z ddl Z ddl Z ddlmZddlmZdd lmZd d lmZd 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#sdZ%e%xZ&Z'nejPZ&dZ'dZ)d5dZ*dZ+Gdde,Z-d Z.d!Z/d"Z0d#Z1d$Z2d%Z3e!d&Z4d'Z5d(Z6d)Z7d6d*Z8d+Z9Gd,d-e:Z;d.Z< d7d0Z=d1Z>d2Z?d3Z@ejd/d8d4ZBy)9) annotations)dequeN)chain) getsizeof)Any)config)mock)inspect) Connection)Column)DropConstraint) DropTable)ForeignKeyConstraint)MetaData)Tableschema)Integer decorator) defaultdict)has_refcount_gc)inspect_getfullargspeccTtjtjyN)gccollect)argss H/opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/testing/util.pynon_refcount_gc_collectr",s  cyrr%r#r!lazy_gcr&5s r#c#Kt}ddl}|j||D]4td|jdzD]j fdf6yw)Nrrc(j|Sr)dumps)dpickle_protocols r!zpicklers..Bs7==H+Er#)setpickleaddrangeHIGHEST_PROTOCOLloads)picklersr0r,r-s @@r!r5r59sUuH LLb&"9"9A"=>H--!EE E?sAAc0tj||S)N)k)randomchoices) populationr7s r!random_choicesr;Es >>* **r#ct|tr t||S|tjdd|zzzj tj td|z S)N10 ) isinstancefloatrounddecimalDecimal to_integral ROUND_FLOORpow)valueprecs r! round_decimalrJIs\%UD!! GOOC#*$45 5 B B  B  r#c0eZdZdZdZdZdZdZdZy) RandomSetc~ttj|}tj|t |Sr)listr/__iter__r8shuffleiter)selfls r!rOzRandomSet.__iter__Ts* d# $qAwr#ctjdt|dz }ttj ||}|j ||S)Nrr)r8randintlenrNr/rOremove)rRindexitems r!popz RandomSet.popYsCq#d)a-0CLL&'. D r#c@ttj||Sr)rLr/unionrRothers r!r\zRandomSet.union_s4/00r#c@ttj||Sr)rLr/ differencer]s r!r`zRandomSet.differencebse455r#c@ttj||Sr)rLr/ intersectionr]s r!rbzRandomSet.intersectiones))$677r#ct|Sr)rL)rRs r!copyzRandomSet.copyhs r#N) __name__ __module__ __qualname__rOrZr\r`rbrdr%r#r!rLrLSs   168r#rLctt}|D]\}}||j|t|D]\}}||dD] }|||vs yy)zATrue if the given sorting conforms to the given partial ordering.NFT)rr/r1 enumerate)tuplessorted_elementsdepsparentchildinodens r!conforms_partial_orderingrrlse s D  V  _-4 $AtAw%. r#ctt|D]\}}|j|fdt|S)Nc3Kt|dk(rt|y|D]G}t|j|g}|j |r3|D] }|g|z Iyw)Nr)rVrNr/r`rb)elementselemsubset sub_ordering_all_orderingsedgess r!ryz-all_partial_orderings.._all_orderingssk x=A x.  X114&9**5;7(6v(> #f|33)?!s AA-A-)rr/r1rQ)rjrurmrnryrzs @@r!all_partial_orderingsr{zsD  E  e   4 x( ))r#c ||_|S#t$rEtj|j|j ||j |j}Y|SwxYw)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. )re TypeErrortypes FunctionType__code__ __globals__ __defaults__ __closure__)fnnames r!function_namedrsX  I     KKr  I  s A AAc|j} ||g|i|}|jddd|S#tj}|j|}|s|cYSxYw)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__sysexc_info)ctxrargkwobjresultrraise_s r!run_as_contextmanagerrsj --/C C$#$$ T4& <<>x( Ms 3*Ac>|Dchc] }t|c}Scc}w)zConverts the results of sql execution into a plain set of column tuples. Useful for asserting the results of an unordered query. tuple)resultsrows r!rowsetrs #* *'3E#J' ** *scJ|rr%)msgs r!failrs #5r#cpddlm}tj}|d}t |dd}||_ ||i||j |jj}|r2t|||jj||_St|tj||_S#|j |jj}|r2t|||jj||_wt|tj||_wxYw)ztProvide bound MetaData for a single test, dropping afterwards. Legacy; use the "metadata" pytest fixture. r)fixturesrmetadataN)rrrgetattrrclose_all_sessionsbase_connection_fixture_connectiondrop_all_tables_from_metadataget_transactioncommitr db)rr rrrrR prev_metacfcs r!provide_metadatars  H 7Dj$/IDM"42 ##%mm::  *(C 8    ! ( ( *"  *(FII >! # ##%mm::  *(C 8    ! ( ( *"  *(FII >! s B88A=D5c Jt}|D]|jt|}tj|Dcgc]2dj fd|Dft fd|Dz4c}ddt|zzdj |dScc}w)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): ... _c3HK|]}j|ds|ywFNget.0r7r+s r! z$flag_combinations..s9Aq%as""c3BK|]}j|dywrrrs r!rz$flag_combinations..s2TAEE!UOTsroa,)id_argnames)r/updatesortedr combinationsjoinrrV)rkeysr+s `r!flag_combinationsrs> 5D  A $.create_fixture..fixture)s"(R(- -r#z fixture_%3.3d)re)rrrs` r!create_fixturez+lambda_combinations..create_fixture(s .+S0r#)rr Mockr rr2rV)rrr rarg_setsrros` r!lambda_combinationsr#s !/ 2DQ @ @AH   (-c(m(< =(<1>!  (< = AC !A >s A6A;c t|d}|Dcic]}||j|}}t|j}|j |t j |j|}|di|Scc}w)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. rr%)rrZdictrrr~rr)__fnrpos_argsr pass_pos_argsglbnew_fns r!resolve_lambdar4sx&d+A.H19:#S"&&+%M: t CJJrN    s 3F  "M "" ;sA<cfd}|S)z&Provide MetaData for a pytest fixture.cHfd}tj|S)Nc3$Ktjx}|_ ||}|jtj ||j tj y#|j tj wxYwwr)rrr create_allr rdrop_all)rRrrrs r!run_ddlz3metadata_fixture..decorate..run_ddlIsh'-'8 8Ht} -D(+##FII. !!&)),!!&)),sB,A, B,!B  B)scope)r r)rrddls` r!decoratez"metadata_fixture..decorateHs  -)v~~C(11r#r%)rrs` r!metadata_fixturerEs 2 Or#c$tfd}|S)ziForce the given table names to be dropped after test complete, isolating for foreign key cycles c ||i|ttjttjS#ttjttjwxYw)N) include_names)drop_all_tablesr rr )rr rnamess r!gozforce_drop_names..go_sG Pt?r? FIIwvyy'9 OOFIIwvyy'9 Os >5A3r)rrs` r!force_drop_namesrYs PP Ir#c eZdZdZdZdZeZy)adictz,Dict keys available as attributes. Shadows.cX ||S#t$rtj||cYSwxYwr)KeyErrorr__getattribute__)rRkeys r!rzadict.__getattribute__ls3 49  4((s3 3 4s ))cDt|Dcgc]}|| c}Scc}wrr)rRrrs r!__call__zadict.__call__rs#404Cd3i40110s N)rerfrg__doc__rrget_allr%r#r!rris64 2Gr#rcddlmfd}t|ts"|j 5}||dddy||y#1swYyxYw)Nr)enginesc jj||jjs4ddlm}|j dd5j|dddyj|y#1swYyxYw)Nr) assertionszCan't sort tablesF)assert_)testing_reaperprepare_for_drop_tablesdialectsupports_alterrrexpect_warningsr) connectionrrrs r!rz)drop_all_tables_from_metadata..go{sv66zB!!00 $++#U,!!*-   j ) s A99B)rrr@r begin)rengine_or_connectionrrrs` @r!rrxsI * *J 7 ! ' ' )Z zN* )  * )s A  Arc | t|}||dk(sJd|f}|j5}t|j|D]\}}|r?||d|vr|j t t |dt|dG|sJ|jjsa|D]\}} ||d|vrt |dttdttdt|d} |j tt| jjg| jj g|  dddy#1swYyxYw) Nrz2consider_schemas and schema are mutually exclusive)consider_schemasrrrxy)r)r/rreversed%sort_tables_on_foreign_key_dependencyexecuterrrrrrrrrcrr) engine inspectorrrrconn table_keyfkcst_keyfkctbs r!rrsf M*  $   @ ? @ #9 4'  ; ;!1 <  OIt !-!! M9 ilHJy|L ~~44"&JE3%1!!HM9 a sG,sG,$Qx BLL&0"$$&&BDDFF8#N#''  sA%EB8EE c$tfd}|S)Nc` ||i|jS#jwxYwr)_clear)rrr event_clss r!rz!teardown_events..decorates, s>b>    I   s-r)r rs` r!teardown_eventsr s Or#c d}ttttttt|t tt tit tdfd|S)zReturns the approximate memory footprint an object and all of its contents. source: https://code.activestate.com/recipes/577504/ cHtj|jSr)r from_iterableitems)r+s r! dict_handlerz total_size..dict_handlers""1779--r#rc t|vryjt|t|}jD]2\}}t ||s|t t ||z }|S|S)Nr)idr1rrr@summap)ostyphandler all_handlers default_sizeseensizeofs r!rztotal_size..sizeofsv a5D= A a &(..0LC!S!SVWQZ011 1r#)rrQrNrrr/ frozensetr)rrrrrrs @@@@r! total_sizer sR. t d t l T4 L 5DQ ))timer skip_test)secondscleanupnowsecs r!skip_if_timeoutr0s ))+C ))+ C W}  I   &s3i{7)1E     &s3i{7)1E s5BABA==B)r)function)NrN)r,rAr-r)C __future__r collectionsr contextlibrCr itertoolsrr8rrr*r~typingrrr r r rr rrrrrrrsql sql.sqltypesrutilrrrrr" gc_collectr&rr5r;rJr/rLrrr{rrrrrrrrrrrrrrr r r'contextmanagerr0r%r#r!r<s6#   #)"")32JJ  F+2 *$(2+ (" ("V.b"#"(  D !4  5p#L,   r#