L in9tddlmZddlZddlZddlmZddlmZddlmZddlmZdd lm Z dd l m Z dd l mZdd l mZej eZdZGd dZdZdZdZdZdZej4dZdZej4dZej4dZdZdZ dZ!ej4dZ"ej4dZ#dZ$ejKe$dZ&ej4dZ'ej4d Z(ej4d!Z)ej4d"Z*d#Z+ej4d$Z,ej4d%Z-ej4d&Z.ej4d'Z/ej4d(Z0ej4dd)d*d+Z1ej4d,Z2y)-) annotationsN)config)engines)util)exc)inspect)url)ddlschemac@eZdZddZedZedZdZdZy)registerNc i|_||_yN)fns decorator)selfrs b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/testing/provision.py__init__zregister.__init__s"c@tjd|SN*rfor_db)clsfns rinitz register.init"s%xz  %b))rc6t|jdSrr)rrs rinit_decoratorzregister.init_decorator&s "))#..rcfd}|S)Ncnjrj|}D]}|j|<Sr)rr)rdbnamedbnamesrs rdecoratez!register.for_db..decorate+s:~~^^B'! &#%  &Kr)rr&r's`` rrzregister.for_db*s rcTt|trtj|}n3t|tjr|}n|j j }|j}||jvr|j||g|i|S|jd|g|i|Sr) isinstancestrsa_urlmake_urlURLdbr get_backend_namer)rcfgargkwr backends r__call__zregister.__call__4s c3 //#&C VZZ (C&&**C&&( dhh $488G$S535"5 5 488C=1s1b1 1rr) __name__ __module__ __qualname__r classmethodr r"rr5r(rrrrs9#**// 2rrctD]D}tjd||jjt ||j|Fy)NzCREATE database %s, URI %r)_configs_for_db_operationloginfor/r create_dbfollower_identr1s rcreate_follower_dbrABs=(*/ -~svvzzJ#svv~./rctj|j}|j|r t ||}i}t |||d|d<t j||}t||||jjtjj||||}|r |t_|r t|||S)Nglobalscope)r,r- get_dialectload_provisioningfollower_url_from_mainupdate_db_optsrtesting_enginepost_configure_engineconnectcloserConfigridentconfigure_follower)db_urloptions file_configr@dialectdb_optsengr1s r setup_configrVHsoof%113G '?G67G,GG   1C&#~6KKM -- gw DC% 3/ JrctD]D}tjd||jjt ||j|Fy)NzDROP database %s, URI %r)r;r<r=r/r drop_dbr?s rdrop_follower_dbrYes=(*- +^SVVZZHSVV^,-rc#TKt}tjt}|Dcgc]}tj|c}Dcgc]}||j f}}|D]3\}}|j }||jj|5i} |D]x\}}|j} |j| | vr#t|j|| x| | <} n| | } t|| D]} | |vr|j| | zycc}wcc}ww)arGenerate a set of URLs to test given configured URLs plus additional driver names. Given: .. sourcecode:: text --dburi postgresql://db1 --dburi postgresql://db2 --dburi postgresql://db2 --dbdriver=psycopg2 --dbdriver=asyncpg?async_fallback=true Noting that the default postgresql driver is psycopg2, the output would be: .. sourcecode:: text postgresql+psycopg2://db1 postgresql+asyncpg://db1 postgresql+psycopg2://db2 postgresql+psycopg2://db3 That is, for the driver in a --dburi, we want to keep that and use that driver for each URL it's part of . For a driver that is only in --dbdrivers, we want to use it just once for one of the URLs. for a driver that is both coming from --dburi as well as --dbdrivers, we want to keep it in that dburi. Driver specific query options can be specified by added them to the driver name. For example, to enable the async fallback option for asyncpg:: .. sourcecode:: text --dburi postgresql://db1 --dbdriver=asyncpg?async_fallback=true N) set collections defaultdictr,r-rEget_driver_namenameaddrF difference_generate_driver_urls) db_urls extra_driversurls!backend_to_driver_we_already_haverPurl_objurls_plus_dialectsrS driver_namebackend_to_driver_we_needr4extra_per_backend driver_urls rgenerate_db_urlsrmksVN 5D(3(?(?(D%?FFF/F  '%%'( /I--/ )',,7;;KH I !#.,,!!# 3 3EHFj:7CD E %g .1B!:' B /9JK JT! HHZ    Gs(D(DD( D#$CD(c#K|j}|j|t||d}|t|D]E}d|vr|j dd\}}n|}d}t|||}|s1|j ||Gyw)N?r)r^discardgenerate_driver_urllistsplitremove)r rd main_driverdrv driver_only query_strnew_urls rrbrbs%%'K+& c; 3C IM"  #:%(YYsA%6 "KKI%c; B    %M s A.B 1B c|j}|j|d|}|r|j|} |j|S#tj $rYywxYw)N+) drivername)r0r[update_query_stringrEr NoSuchModuleError)r driverryr4rzs rrrrrsr""$Ggg%v.G--i8  sAA$#A$c#"Kt}tjjD]}|jj tjjD]f}|jj }|j}||j|j|jf}||vsR||j|htjjD]}|jj ywr) r[rrM all_configsr/disposer r0usernamehostdatabaser`)hostsr1r r4 host_confs rr;r;s EE}}((* }}((*!ffjj&&(cllCHHcllC E !I IIi !}}((* s B7D:ADcyrr(r1rUs r"drop_all_schema_objects_pre_tablesrrcyrr(rs r#drop_all_schema_objects_post_tablesrrrc t||t||tjjj r t ||t|}d}tjjj|r||j|jfz }tj|||t||tjjj|r|j!5}|j#D]9}|j%t'j(t+j,|;tjjj|rm|j|jfD]R}|j#|D];}|j%t'j(t+j,||=Tdddyy#1swYyxYw)Nr)consider_schemasr )r drop_viewsr requirementsmaterialized_viewsenableddrop_materialized_viewsr schemasenabled_for_config test_schema test_schema_2rdrop_all_tablesr sequencesbeginget_sequence_namesexecuter DropSequencerSequence)r1rU inspectorrconnseq schema_names rdrop_all_schema_objectsrs&sC0sC --55S) I ""55c:S__c.?.?@@i:JK'S1 $$77< YY[ D 335 E S--fooc.BCD E""**==cB$'OOS5F5F#GK(;;* <  ,, &K H  =  s 7C#G$$G-c t|} |j}|j5}|D]L}|jt j t j|t jN dddtjjj|r |j|j}|j5}|D]X}|jt j t j|t j|jZ dddyy#1swYxYw#t$rYwxYw#1swYyxYw#t$rYywxYw)Nr )r get_view_namesrrr _DropViewrTableMetaDataNotImplementedErrorrrrrr)r1rUr view_namesrvnames rrrsJ I --/ YY[ D#  MM&,,ufoo6G"HI   ""55c: "111IJ ' ELL "LL % & 1'*    ;         #   s<EAE2E.AE"E EE"E+. E:9E:ct|}|j}|j5}|D]}|jd| dddtj j j|r_|j|j}|j5}|D]#}|jd|jd|% dddyy#1swYxYw#1swYyxYw)NzDROP MATERIALIZED VIEW r .) r get_materialized_view_namesrexec_driver_sqlrrrrr)r1rUr mview_namesrrs rrr<s I779K D  DE  #:5'!B C DD""55c:;;??< YY[ D$ $$-coo->awG    ; DD  sC&)C&C#&C/c2td|j)zDynamically create a database for testing. Used when a test run will employ multiple processes, e.g., when run via `tox` or `pytest -n4`. z no DB creation routine for cfg: rr r1rUrNs rr>r>Ps 039 rc2td|j)z8Drop a database that we dynamically created for testing.zno DB drop routine for cfg: rrs rrXrX\s #''K LLrcltj}t|jdk(rSfdS)Nc||Srr()rPrT_optionsrs rz'_adapt_update_db_opts..gsFG1Dr)rinspect_getfullargspeclenargs)rinsps` r_adapt_update_db_optsrbs.  & &r *D 499~ DDrcy)zCSet database options (db_opts) for a test database that we created.Nr()rPrTrQs rrHrHjrcy)zPerform extra steps after configuring an engine for testing. (For the internal dialects, currently only used by sqlite, oracle, mssql) Nr()r enginer@s rrJrJorrcPtj|}|j|S)zCreate a connection URL for a dynamically-created test database. :param url: the connection URL specified when the test run was invoked :param ident: the pytest-xdist "worker identifier" to be used as the database name )r)r,r-r[r rNs rrGrGws# //# C 77E7 ""rcy)z@Create dialect-specific config settings for a follower database.Nr()r1rNs rrOrOs rcy)a[Remove databases that were created during the test process, after the process has ended. This is an optional step that is invoked for certain backends that do not reliably release locks on the database as long as a process is still in use. For the internal dialects, this is currently only necessary for mssql and oracle. Nr(rs r run_reap_dbsrrrctjdtjt}tjt}i}t |5}|D]}|j }|jd\}}tj|}||vr&|j||<||j|j|jf} || j||| j| ddd|D]$} t|| d} || } t!| | &y#1swY3xYw)NzReaping databases... r)r<r=r\r]r[openstriprtr,r-rErFr0rr`rsr) idents_filereidentsdialectsfile_linedb_namerPrgurl_keyr rNs rreap_dbsrs*HH #$  " "3 'D  $ $S )FH k  )e )D::rXrr"rHrJrGrOrrrrrrrrrr(rrrs1#"g!"2"2J/ :- GT, "&      BB(  MM E ./N0N  ##    !2              )-u" r