1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
U
¸ý°dd9ã@sîddlmZddlZddlZddlmZddlmZddlmZddlmZdd    lm    Z    dd
l
m Z dd l mZdd l mZe e¡ZdZGd d„dƒZdd„Zdd„Zdd„Zdd„Zdd„Zejdd„ƒZdd„Zejdd„ƒZejdd „ƒZd!d"„Zd#d$„Z d%d&„Z!ejd'd(„ƒZ"ejd)d*„ƒZ#d+d,„Z$e %e$¡d-d.„ƒZ&ejd/d0„ƒZ'ejd1d2„ƒZ(ejd3d4„ƒZ)ejd5d6„ƒZ*d7d8„Z+ejd9d:„ƒZ,ejd;d<„ƒZ-ejd=d>„ƒZ.ejd?d@„ƒZ/ejdAdB„ƒZ0ejddCdDœdEdF„ƒZ1ejdGdH„ƒZ2dS)Ié)Ú annotationsNé)Úconfig)Úengines)Úutilé)Úexc)Úinspect)Úurl)Úddl©Úschemac@s>eZdZd dd„Zedd„ƒZedd„ƒZdd    „Zd
d „ZdS) ÚregisterNcCsi|_||_dS©N)ÚfnsÚ    decorator)Úselfr©rúSd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/testing/provision.pyÚ__init__szregister.__init__cCstƒ d¡|ƒS©NÚ*©rÚfor_db)ÚclsÚfnrrrÚinitsz register.initcCst|ƒ d¡Srr)rrrrrÚinit_decorator szregister.init_decoratorcs‡‡fdd„}|S)Ncs(ˆjrˆ |¡}ˆD]}|ˆj|<qˆSr)rr)rZdbname©ÚdbnamesrrrÚdecorate%s
 
 z!register.for_db.<locals>.decorater)rrr rrrr$szregister.for_dbcOsrt|tƒrt |¡}nt|tjƒr(|}n|jj}| ¡}||jkrX|j||f|ž|ŽS|jd|f|ž|ŽSdSr)    Ú
isinstanceÚstrÚsa_urlÚmake_urlÚURLÚdbr
Úget_backend_namer)rÚcfgÚargÚkwr
ÚbackendrrrÚ__call__.s
 
zregister.__call__)N)    Ú__name__Ú
__module__Ú __qualname__rÚ classmethodrrrr,rrrrrs
 
 
 
rcCs0tƒD]$}t d||jj¡t||j|ƒqdS)NzCREATE database %s, URI %r)Ú_configs_for_db_operationÚlogÚinfor&r
Ú    create_db©Úfollower_identr(rrrÚcreate_follower_db<s
r7cCsŽt |¡ ¡}| ¡|r$t||ƒ}i}t|||ƒd|d<t ||¡}t|||ƒ|     ¡ 
¡t j   ||||¡}|r||t _|rŠt||ƒ|S)NÚglobalZscope)r#r$Ú get_dialectÚload_provisioningÚfollower_url_from_mainÚupdate_db_optsrZtesting_engineÚpost_configure_engineÚconnectÚcloserÚConfigrÚidentÚconfigure_follower)Údb_urlÚoptionsZ file_configr6ÚdialectÚdb_optsÚengr(rrrÚ setup_configBs 
 
rHcCs0tƒD]$}t d||jj¡t||j|ƒqdS)NzDROP database %s, URI %r)r1r2r3r&r
Údrop_dbr5rrrÚdrop_follower_db^s
rJc csÂtƒ}t t¡}dd„dd„|DƒDƒ}|D]\}}||j |j¡q,i}|D]l\}}|j}| ¡||krŠt|ƒ ||¡||<}    n||}    t||    ƒD]}
|
|krªqœ| |
¡|
VqœqPdS)a&Generate a set of URLs to test given configured URLs plus additional
    driver names.
 
    Given::
 
        --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::
 
        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::
 
        --dburi postgresql://db1          --dbdriver=asyncpg?async_fallback=true
 
    cSsg|]}|| ¡f‘qSr)r9)Ú.0Úurl_objrrrÚ
<listcomp>‰sÿz$generate_db_urls.<locals>.<listcomp>cSsg|]}t |¡‘qSr)r#r$)rKrCrrrrM‹sN)    ÚsetÚ collectionsÚ defaultdictÚnameÚaddÚdriverr:Ú
differenceÚ_generate_driver_urls) Zdb_urlsÚ extra_driversÚurlsZ!backend_to_driver_we_already_haveZurls_plus_dialectsrLrEZbackend_to_driver_we_needr+Zextra_per_backendZ
driver_urlrrrÚgenerate_db_urlsds.!
 þ  ÿþ
rXccsx| ¡}| |¡t||dƒ}|Vt|ƒD]F}d|krJ| dd¡\}}n|}d}t|||ƒ}|r,| |¡|Vq,dS)NÚú?r)Zget_driver_nameÚdiscardÚgenerate_driver_urlÚlistÚsplitÚremove)r
rVZ main_driverÚdrvZ driver_onlyÚ    query_strÚnew_urlrrrrU¥s
 
rUcCsX| ¡}|jd||fd}|r*| |¡}z | ¡Wntjk
rNYdSX|SdS)Nz%s+%s)Z
drivername)r'rNZupdate_query_stringr9rZNoSuchModuleError)r
rSrar+rbrrrr\½s
ÿ
 r\ccsˆtƒ}tj ¡D]}|j ¡qtj ¡D]>}|jj}| ¡}||j|j    |j
f}||kr*|V|  |¡q*tj ¡D]}|j ¡qtdSr) rNrr@Z all_configsr&Zdisposer
r'ÚusernameÚhostÚdatabaserR)Úhostsr(r
r+Z    host_confrrrr1Ïs  r1cCsdSrr©r(rGrrrÚ"drop_all_schema_objects_pre_tablesâsrhcCsdSrrrgrrrÚ#drop_all_schema_objects_post_tablesçsric Cst||ƒt||ƒtjjjr(t||ƒt|ƒ}d}tjj     |¡rR||j
|j f7}t j |||dt||ƒtjj     |¡rþ| ¡v}| ¡D]}| t t |¡¡¡qŒtjj     |¡rô|j
|j fD]0}|j|dD]}| t tj||d¡¡qÒqÂW5QRXdS)Nr)Úconsider_schemasr )rhÚ
drop_viewsrÚ requirementsZmaterialized_viewsZenabledÚdrop_materialized_viewsr    ÚschemasÚenabled_for_configÚ test_schemaZ test_schema_2rZdrop_all_tablesriÚ    sequencesÚbeginZget_sequence_namesÚexecuter Z DropSequencer ÚSequence)r(rGÚ    inspectorrjÚconnÚseqÚ schema_namerrrÚdrop_all_schema_objectsìs0
 
 
 
 
 
 ÿ
 ÿÿryc CsÞt|ƒ}z | ¡}Wntk
r(Yn<X| ¡,}|D] }| t t |t     ¡¡¡¡q8W5QRXt
j j   |¡rÚz|j|jd}Wntk
r˜YnBX| ¡2}|D]&}| t tj|t     ¡|jd¡¡q¨W5QRXdS)Nr )r    Zget_view_namesÚNotImplementedErrorrrrsr Z    _DropViewr ZTableZMetaDatarrlrnrorp)r(rGruZ
view_namesrvÚvnamerrrrks4 
ÿ
ýÿÿrkc    Cs”t|ƒ}| ¡}| ¡ }|D]}| d|›¡qW5QRXtjj |¡r|j|jd}| ¡(}|D]}| d|j›d|›¡qhW5QRXdS)NzDROP MATERIALIZED VIEW r Ú.)    r    Zget_materialized_view_namesrrZexec_driver_sqlrrlrnrorp)r(rGruZ mview_namesrvr{rrrrm/s
ÿ
ÿrmcCstd|jfƒ‚dS)z—Dynamically 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: %sN©rzr
©r(rGrArrrr4Cs
ÿr4cCstd|jfƒ‚dS)z8Drop a database that we dynamically created for testing.zno DB drop routine for cfg: %sNr}r~rrrrIOsrIcs,t ˆ¡}t|jƒdkrˆS‡fdd„SdS)Nécs
ˆ||ƒSrr)rCrFÚ_options©rrrÚ<lambda>Zóz'_adapt_update_db_opts.<locals>.<lambda>)rZinspect_getfullargspecÚlenÚargs)rZinsprrrÚ_adapt_update_db_optsUs
r†cCsdS)zCSet database options (db_opts) for a test database that we created.Nr)rCrFrDrrrr<]sr<cCsdS)z‰Perform extra steps after configuring an engine for testing.
 
    (For the internal dialects, currently only used by sqlite, oracle)
    Nr)r
Úenginer6rrrr=bsr=cCst |¡}|j|dS)zúCreate 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
    )re)r#r$rN©r
rArrrr;js
r;cCsdS)z@Create dialect-specific config settings for a follower database.Nr)r(rArrrrBvsrBcCsdS)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.
    NrrˆrrrÚ run_reap_dbs|sr‰c     CsÚt d¡t t¡}t t¡}i}t|ƒz}|D]n}| ¡}| d¡\}}t     |¡}||krt| 
¡||<||  ¡|  ¡|j f}    ||     |¡||     |¡q0W5QRX|D]&}    t||    ƒd}
||    } t|
| ƒq®dS)NzReaping databases...ú r)r2r3rOrPrNÚopenÚstripr^r#r$r9r:r'rdrRr]r‰) Z idents_filerWZidentsZdialectsÚfile_ÚlineZdb_namerCrLZurl_keyr
rArrrÚreap_dbsˆs&
 
 
 
 
  rcCstd|jfƒ‚dS)aOSpecify keyword arguments for creating a temporary Table.
 
    Dialect-specific implementations of this method will return the
    kwargs that are passed to the Table method when creating a temporary
    table for testing, e.g., in the define_temp_tables method of the
    ComponentReflectionTest class in suite/test_reflection.py
    z.no temp table keyword args routine for cfg: %sNr}rgrrrÚtemp_table_keyword_args¡s    
ÿrcCsdSrr)rÚ
connectionrrrÚprepare_for_drop_tables¯sr’cCsdSrr)rr&ZtestclsrrrÚ stop_test_class_outside_fixtures´sr“cCs|S)a¸Specify table name for creating a temporary Table.
 
    Dialect-specific implementations of this method will return the
    name to use when creating a temporary table for testing,
    e.g., in the define_temp_tables method of the
    ComponentReflectionTest class in suite/test_reflection.py
 
    Default to just the base name since that's what most dialects will
    use. The mssql dialect's implementation will need a "#" prepended.
    r)r(rGÚ    base_namerrrÚget_temp_table_name¹s r•cCstd|jjfƒ‚dS)Nz9backend does not implement a schema name set function: %s©rzr&r
)r(Zdbapi_connectionrxrrrÚ set_default_schema_on_connectionÈs
ÿÿr—F)Ú
set_lambdaÚsort_by_parameter_ordercCstd|jj›ƒ‚dS)a˜return the backends insert..on conflict / on dupe etc. construct.
 
    while we should add a backend-neutral upsert construct as well, such as
    insert().upsert(), it's important that we continue to test the
    backend-specific insert() constructs since if we do implement
    insert().upsert(), that would be using a different codepath for the things
    we need to test like insertmanyvalues, etc.
 
    z3backend does not include an upsert implementation: Nr–)r(ÚtableZ    returningr˜r™rrrÚupsertÐs  ÿr›cCs|S)zƒNormalize sequence parameters for dialect that don't start with 1
    by default.
 
    The default implementation does nothing
    r)r(ÚsequencerrrÚnormalize_sequenceâsr)3Ú
__future__rrOÚloggingrYrrrrr    r‡r
r#Zsqlr r Ú    getLoggerr-r2ZFOLLOWER_IDENTrr7rHrJrXrUrr\r1rhriryrkrmr4rIr†rr<r=r;rBr‰rrr’r“r•r—r›rrrrrÚ<module>sx         
%A
 
 
"!
 
 
 
 
 
 
 
 
 
 
 
ÿ