L i8`ddlmZddlmZddlmZddlZddlZddlZddlm Z ddl Z ddl Z ddl Z ddl m Z ddlZddlZddlmZdd lmZdd 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%d dl"m&Z&e%sdZ'e'xZ(Z)nejTZ(dZ)dZ+d6dZ,dZ-Gdd e.Z/d!Z0d"Z1d#Z2d$Z3d%Z4d&Z5e#d'Z6d(Z7d)Z8d*Z9d7d+Z:d,Z;Gd-d.e<Z=d/Z> d8d1Z?d2Z@d3ZAd4ZBejd0d9d5ZDy):) annotations)deque) namedtupleN)chain) getsizeof)Any)config)mock)inspect) Connection)Column)DropConstraint) DropTable)ForeignKeyConstraint)MetaData)Tableschema)Integer decorator) defaultdict)has_refcount_gc)inspect_getfullargspeccTtjtjyN)gccollect)argss ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/testing/util.pynon_refcount_gc_collectr#.s  cyrr&r$r"lazy_gcr'7s r$c#Ktdddg}tdtjdzD]|tjfd yw)Npicklersloadsdumpsr c0tj|Sr)pickler+)dprotocols r"zpicklers..?sa)Br$)rranger.HIGHEST_PROTOCOLr*)ntr0s @r"r)r);sM J' 2 3B"f559:DBCCDsAAc0tj||S)N)k)randomchoices) populationr6s r"random_choicesr:Bs >>* **r$ct|tr t||S|tjdd|zzzj tj td|z S)N10 ) isinstancefloatrounddecimalDecimal to_integral ROUND_FLOORpow)valueprecs r" round_decimalrIFs\%UD!! GOOC#*$45 5 B B  B  r$c0eZdZdZdZdZdZdZdZy) RandomSetc~ttj|}tj|t |Sr)listset__iter__r7shuffleiter)selfls r"rOzRandomSet.__iter__Qs* d# $qAwr$ctjdt|dz }ttj ||}|j ||S)Nrr )r7randintlenrMrNrOremove)rRindexitems r"popz RandomSet.popVsCq#d)a-0CLL&'. D r$c@ttj||Sr)rKrNunionrRothers r"r\zRandomSet.union\s4/00r$c@ttj||Sr)rKrN differencer]s r"r`zRandomSet.difference_se455r$c@ttj||Sr)rKrN intersectionr]s r"rbzRandomSet.intersectionbs))$677r$ct|Sr)rK)rRs r"copyzRandomSet.copyes r$N) __name__ __module__ __qualname__rOrZr\r`rbrdr&r$r"rKrKPs   168r$rKctt}|D]\}}||j|t|D]\}}||dD] }|||vs yy)zATrue if the given sorting conforms to the given partial ordering.NFT)rrNadd enumerate)tuplessorted_elementsdepsparentchildinodens r"conforms_partial_orderingrsist 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 )rVrMrNr`rb)elementselemsubset sub_ordering_all_orderingsedgess r"rzz-all_partial_orderings.._all_orderings|su x=A x.   4X114&9**5;7(6v(>4 #f|334 4s AA-A-)rrNrirQ)rkrvrnrorzr{s @@r"all_partial_orderingsr|wsI  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.0r6r/s r" z$flag_combinations..s9Aq%a9s""c3BK|]}j|dywrrrs r"rz$flag_combinations..s2AEE!UO2srpa,)id_argnames)rNupdatesortedr 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_setsrrps` r"lambda_combinationsr sx !/ 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&)rrZdictrrrrr)__fnrpos_argsr pass_pos_argsglbnew_fns r"resolve_lambdar1sw&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_ddlFsh'-'8 8Ht} -D(+##FII. !!&)),!!&)),sB,A, B,!B  B)scope)r r)rrddls` r"decoratez"metadata_fixture..decorateEs  -)v~~C(11r$r&)rrs` r"metadata_fixturerBs 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_namesrVs PP Ir$c eZdZdZdZdZeZy)adictz,Dict keys available as attributes. Shadows.cX ||S#t$rtj||cYSwxYwr)KeyErrorr__getattribute__)rRkeys r"rzadict.__getattribute__is3 49  4((s3 3 4s ))cDt|Dcgc]}|| c}Scc}wrr)rRrrs r"__call__zadict.__call__os40Cd3i0110s N)rerfrg__doc__rrget_allr&r$r"rrfs64 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..goxs{66zB!!00 $++#U, .!!*- . .   j )  . .s A99B)rrr?rbegin)rengine_or_connectionrrrs` @r"rrusR * *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_schemasr rrxy)r)rNrreversed%sort_tables_on_foreign_key_dependencyexecuterrrrrrrrrcrr) engine inspectorrrrconn table_keyfkcst_keyfkctbs r"rrs{ 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_eventsrs 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)idrirrr?summap)ostyphandler all_handlers default_sizeseensizeofs r"rztotal_size..sizeofs{ a5D= A a &(..0 LC!S!SVWQZ011  r$)rrQrMrrrN frozensetr)rrrrrrs @@@@r" total_sizer!sR. t d t l T4 L 5DQ ))timer skip_test)secondscleanupnowsecs r"skip_if_timeoutr1 s ))+C ))+ C W}  I   &s3i{7)1E     &s3i{7)1E s5BABA==B)r )function)NrN)r-r@r.r)E __future__r collectionsrr contextlibrBr itertoolsrr.r7rrr+rtypingrrr r r rrrrrrrrrsql sql.sqltypesrutilrrrrr# gc_collectr'r r)r:rIrNrKrsr|rrrrrrrrrrrrrrrr!r(contextmanagerr1r&r$r"r=s<#"   #)"")32JJ D+2 *$(2+ (" ("V.b"#"(  D !4  5p#L,   r$