SQLAlchemy 2.0.47__cp313-cp313t-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. sqlalchemy/__init__.py +283 -0
  2. sqlalchemy/connectors/__init__.py +18 -0
  3. sqlalchemy/connectors/aioodbc.py +184 -0
  4. sqlalchemy/connectors/asyncio.py +429 -0
  5. sqlalchemy/connectors/pyodbc.py +250 -0
  6. sqlalchemy/cyextension/__init__.py +6 -0
  7. sqlalchemy/cyextension/collections.cp313t-win32.pyd +0 -0
  8. sqlalchemy/cyextension/collections.pyx +409 -0
  9. sqlalchemy/cyextension/immutabledict.cp313t-win32.pyd +0 -0
  10. sqlalchemy/cyextension/immutabledict.pxd +8 -0
  11. sqlalchemy/cyextension/immutabledict.pyx +133 -0
  12. sqlalchemy/cyextension/processors.cp313t-win32.pyd +0 -0
  13. sqlalchemy/cyextension/processors.pyx +68 -0
  14. sqlalchemy/cyextension/resultproxy.cp313t-win32.pyd +0 -0
  15. sqlalchemy/cyextension/resultproxy.pyx +102 -0
  16. sqlalchemy/cyextension/util.cp313t-win32.pyd +0 -0
  17. sqlalchemy/cyextension/util.pyx +90 -0
  18. sqlalchemy/dialects/__init__.py +62 -0
  19. sqlalchemy/dialects/_typing.py +30 -0
  20. sqlalchemy/dialects/mssql/__init__.py +88 -0
  21. sqlalchemy/dialects/mssql/aioodbc.py +63 -0
  22. sqlalchemy/dialects/mssql/base.py +4093 -0
  23. sqlalchemy/dialects/mssql/information_schema.py +285 -0
  24. sqlalchemy/dialects/mssql/json.py +129 -0
  25. sqlalchemy/dialects/mssql/provision.py +185 -0
  26. sqlalchemy/dialects/mssql/pymssql.py +126 -0
  27. sqlalchemy/dialects/mssql/pyodbc.py +760 -0
  28. sqlalchemy/dialects/mysql/__init__.py +104 -0
  29. sqlalchemy/dialects/mysql/aiomysql.py +250 -0
  30. sqlalchemy/dialects/mysql/asyncmy.py +231 -0
  31. sqlalchemy/dialects/mysql/base.py +3949 -0
  32. sqlalchemy/dialects/mysql/cymysql.py +106 -0
  33. sqlalchemy/dialects/mysql/dml.py +225 -0
  34. sqlalchemy/dialects/mysql/enumerated.py +282 -0
  35. sqlalchemy/dialects/mysql/expression.py +146 -0
  36. sqlalchemy/dialects/mysql/json.py +91 -0
  37. sqlalchemy/dialects/mysql/mariadb.py +72 -0
  38. sqlalchemy/dialects/mysql/mariadbconnector.py +322 -0
  39. sqlalchemy/dialects/mysql/mysqlconnector.py +302 -0
  40. sqlalchemy/dialects/mysql/mysqldb.py +314 -0
  41. sqlalchemy/dialects/mysql/provision.py +153 -0
  42. sqlalchemy/dialects/mysql/pymysql.py +158 -0
  43. sqlalchemy/dialects/mysql/pyodbc.py +157 -0
  44. sqlalchemy/dialects/mysql/reflection.py +727 -0
  45. sqlalchemy/dialects/mysql/reserved_words.py +570 -0
  46. sqlalchemy/dialects/mysql/types.py +835 -0
  47. sqlalchemy/dialects/oracle/__init__.py +81 -0
  48. sqlalchemy/dialects/oracle/base.py +3802 -0
  49. sqlalchemy/dialects/oracle/cx_oracle.py +1555 -0
  50. sqlalchemy/dialects/oracle/dictionary.py +507 -0
  51. sqlalchemy/dialects/oracle/oracledb.py +941 -0
  52. sqlalchemy/dialects/oracle/provision.py +297 -0
  53. sqlalchemy/dialects/oracle/types.py +316 -0
  54. sqlalchemy/dialects/oracle/vector.py +365 -0
  55. sqlalchemy/dialects/postgresql/__init__.py +167 -0
  56. sqlalchemy/dialects/postgresql/_psycopg_common.py +189 -0
  57. sqlalchemy/dialects/postgresql/array.py +519 -0
  58. sqlalchemy/dialects/postgresql/asyncpg.py +1284 -0
  59. sqlalchemy/dialects/postgresql/base.py +5378 -0
  60. sqlalchemy/dialects/postgresql/dml.py +339 -0
  61. sqlalchemy/dialects/postgresql/ext.py +540 -0
  62. sqlalchemy/dialects/postgresql/hstore.py +406 -0
  63. sqlalchemy/dialects/postgresql/json.py +404 -0
  64. sqlalchemy/dialects/postgresql/named_types.py +524 -0
  65. sqlalchemy/dialects/postgresql/operators.py +129 -0
  66. sqlalchemy/dialects/postgresql/pg8000.py +669 -0
  67. sqlalchemy/dialects/postgresql/pg_catalog.py +326 -0
  68. sqlalchemy/dialects/postgresql/provision.py +183 -0
  69. sqlalchemy/dialects/postgresql/psycopg.py +862 -0
  70. sqlalchemy/dialects/postgresql/psycopg2.py +892 -0
  71. sqlalchemy/dialects/postgresql/psycopg2cffi.py +61 -0
  72. sqlalchemy/dialects/postgresql/ranges.py +1031 -0
  73. sqlalchemy/dialects/postgresql/types.py +313 -0
  74. sqlalchemy/dialects/sqlite/__init__.py +57 -0
  75. sqlalchemy/dialects/sqlite/aiosqlite.py +482 -0
  76. sqlalchemy/dialects/sqlite/base.py +3056 -0
  77. sqlalchemy/dialects/sqlite/dml.py +263 -0
  78. sqlalchemy/dialects/sqlite/json.py +92 -0
  79. sqlalchemy/dialects/sqlite/provision.py +229 -0
  80. sqlalchemy/dialects/sqlite/pysqlcipher.py +157 -0
  81. sqlalchemy/dialects/sqlite/pysqlite.py +756 -0
  82. sqlalchemy/dialects/type_migration_guidelines.txt +145 -0
  83. sqlalchemy/engine/__init__.py +62 -0
  84. sqlalchemy/engine/_py_processors.py +136 -0
  85. sqlalchemy/engine/_py_row.py +128 -0
  86. sqlalchemy/engine/_py_util.py +74 -0
  87. sqlalchemy/engine/base.py +3390 -0
  88. sqlalchemy/engine/characteristics.py +155 -0
  89. sqlalchemy/engine/create.py +893 -0
  90. sqlalchemy/engine/cursor.py +2298 -0
  91. sqlalchemy/engine/default.py +2394 -0
  92. sqlalchemy/engine/events.py +965 -0
  93. sqlalchemy/engine/interfaces.py +3471 -0
  94. sqlalchemy/engine/mock.py +134 -0
  95. sqlalchemy/engine/processors.py +61 -0
  96. sqlalchemy/engine/reflection.py +2102 -0
  97. sqlalchemy/engine/result.py +2399 -0
  98. sqlalchemy/engine/row.py +400 -0
  99. sqlalchemy/engine/strategies.py +16 -0
  100. sqlalchemy/engine/url.py +924 -0
  101. sqlalchemy/engine/util.py +167 -0
  102. sqlalchemy/event/__init__.py +26 -0
  103. sqlalchemy/event/api.py +220 -0
  104. sqlalchemy/event/attr.py +676 -0
  105. sqlalchemy/event/base.py +472 -0
  106. sqlalchemy/event/legacy.py +258 -0
  107. sqlalchemy/event/registry.py +390 -0
  108. sqlalchemy/events.py +17 -0
  109. sqlalchemy/exc.py +832 -0
  110. sqlalchemy/ext/__init__.py +11 -0
  111. sqlalchemy/ext/associationproxy.py +2027 -0
  112. sqlalchemy/ext/asyncio/__init__.py +25 -0
  113. sqlalchemy/ext/asyncio/base.py +281 -0
  114. sqlalchemy/ext/asyncio/engine.py +1471 -0
  115. sqlalchemy/ext/asyncio/exc.py +21 -0
  116. sqlalchemy/ext/asyncio/result.py +965 -0
  117. sqlalchemy/ext/asyncio/scoping.py +1599 -0
  118. sqlalchemy/ext/asyncio/session.py +1947 -0
  119. sqlalchemy/ext/automap.py +1701 -0
  120. sqlalchemy/ext/baked.py +570 -0
  121. sqlalchemy/ext/compiler.py +600 -0
  122. sqlalchemy/ext/declarative/__init__.py +65 -0
  123. sqlalchemy/ext/declarative/extensions.py +564 -0
  124. sqlalchemy/ext/horizontal_shard.py +478 -0
  125. sqlalchemy/ext/hybrid.py +1535 -0
  126. sqlalchemy/ext/indexable.py +364 -0
  127. sqlalchemy/ext/instrumentation.py +450 -0
  128. sqlalchemy/ext/mutable.py +1085 -0
  129. sqlalchemy/ext/mypy/__init__.py +6 -0
  130. sqlalchemy/ext/mypy/apply.py +324 -0
  131. sqlalchemy/ext/mypy/decl_class.py +515 -0
  132. sqlalchemy/ext/mypy/infer.py +590 -0
  133. sqlalchemy/ext/mypy/names.py +335 -0
  134. sqlalchemy/ext/mypy/plugin.py +303 -0
  135. sqlalchemy/ext/mypy/util.py +357 -0
  136. sqlalchemy/ext/orderinglist.py +439 -0
  137. sqlalchemy/ext/serializer.py +185 -0
  138. sqlalchemy/future/__init__.py +16 -0
  139. sqlalchemy/future/engine.py +15 -0
  140. sqlalchemy/inspection.py +174 -0
  141. sqlalchemy/log.py +288 -0
  142. sqlalchemy/orm/__init__.py +171 -0
  143. sqlalchemy/orm/_orm_constructors.py +2661 -0
  144. sqlalchemy/orm/_typing.py +179 -0
  145. sqlalchemy/orm/attributes.py +2845 -0
  146. sqlalchemy/orm/base.py +971 -0
  147. sqlalchemy/orm/bulk_persistence.py +2135 -0
  148. sqlalchemy/orm/clsregistry.py +571 -0
  149. sqlalchemy/orm/collections.py +1627 -0
  150. sqlalchemy/orm/context.py +3334 -0
  151. sqlalchemy/orm/decl_api.py +2004 -0
  152. sqlalchemy/orm/decl_base.py +2192 -0
  153. sqlalchemy/orm/dependency.py +1302 -0
  154. sqlalchemy/orm/descriptor_props.py +1092 -0
  155. sqlalchemy/orm/dynamic.py +300 -0
  156. sqlalchemy/orm/evaluator.py +379 -0
  157. sqlalchemy/orm/events.py +3252 -0
  158. sqlalchemy/orm/exc.py +237 -0
  159. sqlalchemy/orm/identity.py +302 -0
  160. sqlalchemy/orm/instrumentation.py +754 -0
  161. sqlalchemy/orm/interfaces.py +1496 -0
  162. sqlalchemy/orm/loading.py +1686 -0
  163. sqlalchemy/orm/mapped_collection.py +557 -0
  164. sqlalchemy/orm/mapper.py +4444 -0
  165. sqlalchemy/orm/path_registry.py +809 -0
  166. sqlalchemy/orm/persistence.py +1788 -0
  167. sqlalchemy/orm/properties.py +935 -0
  168. sqlalchemy/orm/query.py +3459 -0
  169. sqlalchemy/orm/relationships.py +3508 -0
  170. sqlalchemy/orm/scoping.py +2148 -0
  171. sqlalchemy/orm/session.py +5280 -0
  172. sqlalchemy/orm/state.py +1168 -0
  173. sqlalchemy/orm/state_changes.py +196 -0
  174. sqlalchemy/orm/strategies.py +3470 -0
  175. sqlalchemy/orm/strategy_options.py +2568 -0
  176. sqlalchemy/orm/sync.py +164 -0
  177. sqlalchemy/orm/unitofwork.py +796 -0
  178. sqlalchemy/orm/util.py +2403 -0
  179. sqlalchemy/orm/writeonly.py +674 -0
  180. sqlalchemy/pool/__init__.py +44 -0
  181. sqlalchemy/pool/base.py +1524 -0
  182. sqlalchemy/pool/events.py +375 -0
  183. sqlalchemy/pool/impl.py +588 -0
  184. sqlalchemy/py.typed +0 -0
  185. sqlalchemy/schema.py +69 -0
  186. sqlalchemy/sql/__init__.py +145 -0
  187. sqlalchemy/sql/_dml_constructors.py +132 -0
  188. sqlalchemy/sql/_elements_constructors.py +1872 -0
  189. sqlalchemy/sql/_orm_types.py +20 -0
  190. sqlalchemy/sql/_py_util.py +75 -0
  191. sqlalchemy/sql/_selectable_constructors.py +763 -0
  192. sqlalchemy/sql/_typing.py +482 -0
  193. sqlalchemy/sql/annotation.py +587 -0
  194. sqlalchemy/sql/base.py +2293 -0
  195. sqlalchemy/sql/cache_key.py +1057 -0
  196. sqlalchemy/sql/coercions.py +1404 -0
  197. sqlalchemy/sql/compiler.py +8081 -0
  198. sqlalchemy/sql/crud.py +1752 -0
  199. sqlalchemy/sql/ddl.py +1444 -0
  200. sqlalchemy/sql/default_comparator.py +551 -0
  201. sqlalchemy/sql/dml.py +1850 -0
  202. sqlalchemy/sql/elements.py +5589 -0
  203. sqlalchemy/sql/events.py +458 -0
  204. sqlalchemy/sql/expression.py +159 -0
  205. sqlalchemy/sql/functions.py +2158 -0
  206. sqlalchemy/sql/lambdas.py +1442 -0
  207. sqlalchemy/sql/naming.py +209 -0
  208. sqlalchemy/sql/operators.py +2623 -0
  209. sqlalchemy/sql/roles.py +323 -0
  210. sqlalchemy/sql/schema.py +6222 -0
  211. sqlalchemy/sql/selectable.py +7265 -0
  212. sqlalchemy/sql/sqltypes.py +3930 -0
  213. sqlalchemy/sql/traversals.py +1024 -0
  214. sqlalchemy/sql/type_api.py +2368 -0
  215. sqlalchemy/sql/util.py +1485 -0
  216. sqlalchemy/sql/visitors.py +1164 -0
  217. sqlalchemy/testing/__init__.py +96 -0
  218. sqlalchemy/testing/assertions.py +994 -0
  219. sqlalchemy/testing/assertsql.py +520 -0
  220. sqlalchemy/testing/asyncio.py +135 -0
  221. sqlalchemy/testing/config.py +434 -0
  222. sqlalchemy/testing/engines.py +483 -0
  223. sqlalchemy/testing/entities.py +117 -0
  224. sqlalchemy/testing/exclusions.py +476 -0
  225. sqlalchemy/testing/fixtures/__init__.py +28 -0
  226. sqlalchemy/testing/fixtures/base.py +384 -0
  227. sqlalchemy/testing/fixtures/mypy.py +332 -0
  228. sqlalchemy/testing/fixtures/orm.py +227 -0
  229. sqlalchemy/testing/fixtures/sql.py +482 -0
  230. sqlalchemy/testing/pickleable.py +155 -0
  231. sqlalchemy/testing/plugin/__init__.py +6 -0
  232. sqlalchemy/testing/plugin/bootstrap.py +51 -0
  233. sqlalchemy/testing/plugin/plugin_base.py +828 -0
  234. sqlalchemy/testing/plugin/pytestplugin.py +892 -0
  235. sqlalchemy/testing/profiling.py +329 -0
  236. sqlalchemy/testing/provision.py +603 -0
  237. sqlalchemy/testing/requirements.py +1945 -0
  238. sqlalchemy/testing/schema.py +198 -0
  239. sqlalchemy/testing/suite/__init__.py +19 -0
  240. sqlalchemy/testing/suite/test_cte.py +237 -0
  241. sqlalchemy/testing/suite/test_ddl.py +389 -0
  242. sqlalchemy/testing/suite/test_deprecations.py +153 -0
  243. sqlalchemy/testing/suite/test_dialect.py +776 -0
  244. sqlalchemy/testing/suite/test_insert.py +630 -0
  245. sqlalchemy/testing/suite/test_reflection.py +3557 -0
  246. sqlalchemy/testing/suite/test_results.py +504 -0
  247. sqlalchemy/testing/suite/test_rowcount.py +258 -0
  248. sqlalchemy/testing/suite/test_select.py +2010 -0
  249. sqlalchemy/testing/suite/test_sequence.py +317 -0
  250. sqlalchemy/testing/suite/test_types.py +2147 -0
  251. sqlalchemy/testing/suite/test_unicode_ddl.py +189 -0
  252. sqlalchemy/testing/suite/test_update_delete.py +139 -0
  253. sqlalchemy/testing/util.py +535 -0
  254. sqlalchemy/testing/warnings.py +52 -0
  255. sqlalchemy/types.py +74 -0
  256. sqlalchemy/util/__init__.py +162 -0
  257. sqlalchemy/util/_collections.py +712 -0
  258. sqlalchemy/util/_concurrency_py3k.py +288 -0
  259. sqlalchemy/util/_has_cy.py +40 -0
  260. sqlalchemy/util/_py_collections.py +541 -0
  261. sqlalchemy/util/compat.py +421 -0
  262. sqlalchemy/util/concurrency.py +110 -0
  263. sqlalchemy/util/deprecations.py +401 -0
  264. sqlalchemy/util/langhelpers.py +2203 -0
  265. sqlalchemy/util/preloaded.py +150 -0
  266. sqlalchemy/util/queue.py +322 -0
  267. sqlalchemy/util/tool_support.py +201 -0
  268. sqlalchemy/util/topological.py +120 -0
  269. sqlalchemy/util/typing.py +734 -0
  270. sqlalchemy-2.0.47.dist-info/METADATA +243 -0
  271. sqlalchemy-2.0.47.dist-info/RECORD +274 -0
  272. sqlalchemy-2.0.47.dist-info/WHEEL +5 -0
  273. sqlalchemy-2.0.47.dist-info/licenses/LICENSE +19 -0
  274. sqlalchemy-2.0.47.dist-info/top_level.txt +1 -0
@@ -0,0 +1,603 @@
1
+ # testing/provision.py
2
+ # Copyright (C) 2005-2026 the SQLAlchemy authors and contributors
3
+ # <see AUTHORS file>
4
+ #
5
+ # This module is part of SQLAlchemy and is released under
6
+ # the MIT License: https://www.opensource.org/licenses/mit-license.php
7
+ # mypy: ignore-errors
8
+
9
+ from __future__ import annotations
10
+
11
+ import collections
12
+ import contextlib
13
+ import logging
14
+
15
+ from . import config
16
+ from . import engines
17
+ from . import util
18
+ from .. import exc
19
+ from .. import inspect
20
+ from ..engine import Connection
21
+ from ..engine import Engine
22
+ from ..engine import url as sa_url
23
+ from ..schema import sort_tables_and_constraints
24
+ from ..sql import ddl
25
+ from ..sql import schema
26
+ from ..util import decorator
27
+
28
+
29
+ log = logging.getLogger(__name__)
30
+
31
+ FOLLOWER_IDENT = None
32
+
33
+
34
+ class register:
35
+ def __init__(self, decorator=None):
36
+ self.fns = {}
37
+ self.decorator = decorator
38
+
39
+ @classmethod
40
+ def init(cls, fn):
41
+ return register().for_db("*")(fn)
42
+
43
+ @classmethod
44
+ def init_decorator(cls, decorator):
45
+ return register(decorator).for_db("*")
46
+
47
+ def for_db(self, *dbnames):
48
+ def decorate(fn):
49
+ if self.decorator:
50
+ fn = self.decorator(fn)
51
+ for dbname in dbnames:
52
+ self.fns[dbname] = fn
53
+ return self
54
+
55
+ return decorate
56
+
57
+ def call_original(self, cfg, *arg, **kw):
58
+ return self.fns["*"](cfg, *arg, **kw)
59
+
60
+ def __call__(self, cfg, *arg, **kw):
61
+ if isinstance(cfg, str):
62
+ url = sa_url.make_url(cfg)
63
+ elif isinstance(cfg, sa_url.URL):
64
+ url = cfg
65
+ elif isinstance(cfg, (Engine, Connection)):
66
+ url = cfg.engine.url
67
+ else:
68
+ url = cfg.db.url
69
+ backend = url.get_backend_name()
70
+ if backend in self.fns:
71
+ return self.fns[backend](cfg, *arg, **kw)
72
+ else:
73
+ return self.fns["*"](cfg, *arg, **kw)
74
+
75
+
76
+ def create_follower_db(follower_ident):
77
+ for cfg in _configs_for_db_operation():
78
+ log.info("CREATE database %s, URI %r", follower_ident, cfg.db.url)
79
+ create_db(cfg, cfg.db, follower_ident)
80
+
81
+
82
+ def setup_config(db_url, options, file_config, follower_ident):
83
+ # load the dialect, which should also have it set up its provision
84
+ # hooks
85
+
86
+ dialect = sa_url.make_url(db_url).get_dialect()
87
+
88
+ dialect.load_provisioning()
89
+
90
+ if follower_ident:
91
+ db_url = follower_url_from_main(db_url, follower_ident)
92
+ db_opts = {}
93
+ update_db_opts(db_url, db_opts, options)
94
+ db_opts["scope"] = "global"
95
+ eng = engines.testing_engine(db_url, db_opts)
96
+
97
+ post_configure_engine(db_url, eng, follower_ident)
98
+
99
+ eng.connect().close()
100
+
101
+ cfg = config.Config.register(eng, db_opts, options, file_config)
102
+
103
+ # a symbolic name that tests can use if they need to disambiguate
104
+ # names across databases
105
+ if follower_ident:
106
+ config.ident = follower_ident
107
+
108
+ if follower_ident:
109
+ configure_follower(cfg, follower_ident)
110
+ return cfg
111
+
112
+
113
+ def drop_follower_db(follower_ident):
114
+ for cfg in _configs_for_db_operation():
115
+ log.info("DROP database %s, URI %r", follower_ident, cfg.db.url)
116
+ drop_db(cfg, cfg.db, follower_ident)
117
+
118
+
119
+ def generate_db_urls(db_urls, extra_drivers):
120
+ """Generate a set of URLs to test given configured URLs plus additional
121
+ driver names.
122
+
123
+ Given:
124
+
125
+ .. sourcecode:: text
126
+
127
+ --dburi postgresql://db1 \
128
+ --dburi postgresql://db2 \
129
+ --dburi postgresql://db2 \
130
+ --dbdriver=psycopg2 --dbdriver=asyncpg?async_fallback=true
131
+
132
+ Noting that the default postgresql driver is psycopg2, the output
133
+ would be:
134
+
135
+ .. sourcecode:: text
136
+
137
+ postgresql+psycopg2://db1
138
+ postgresql+asyncpg://db1
139
+ postgresql+psycopg2://db2
140
+ postgresql+psycopg2://db3
141
+
142
+ That is, for the driver in a --dburi, we want to keep that and use that
143
+ driver for each URL it's part of . For a driver that is only
144
+ in --dbdrivers, we want to use it just once for one of the URLs.
145
+ for a driver that is both coming from --dburi as well as --dbdrivers,
146
+ we want to keep it in that dburi.
147
+
148
+ Driver specific query options can be specified by added them to the
149
+ driver name. For example, to enable the async fallback option for
150
+ asyncpg::
151
+
152
+ .. sourcecode:: text
153
+
154
+ --dburi postgresql://db1 \
155
+ --dbdriver=asyncpg?async_fallback=true
156
+
157
+ """
158
+ urls = set()
159
+
160
+ backend_to_driver_we_already_have = collections.defaultdict(set)
161
+
162
+ urls_plus_dialects = [
163
+ (url_obj, url_obj.get_dialect())
164
+ for url_obj in [sa_url.make_url(db_url) for db_url in db_urls]
165
+ ]
166
+
167
+ for url_obj, dialect in urls_plus_dialects:
168
+ # use get_driver_name instead of dialect.driver to account for
169
+ # "_async" virtual drivers like oracledb and psycopg
170
+ driver_name = url_obj.get_driver_name()
171
+ backend_to_driver_we_already_have[dialect.name].add(driver_name)
172
+
173
+ backend_to_driver_we_need = {}
174
+
175
+ for url_obj, dialect in urls_plus_dialects:
176
+ backend = dialect.name
177
+ dialect.load_provisioning()
178
+
179
+ if backend not in backend_to_driver_we_need:
180
+ backend_to_driver_we_need[backend] = extra_per_backend = set(
181
+ extra_drivers
182
+ ).difference(backend_to_driver_we_already_have[backend])
183
+ else:
184
+ extra_per_backend = backend_to_driver_we_need[backend]
185
+
186
+ for driver_url in _generate_driver_urls(url_obj, extra_per_backend):
187
+ if driver_url in urls:
188
+ continue
189
+ urls.add(driver_url)
190
+ yield driver_url
191
+
192
+
193
+ def _generate_driver_urls(url, extra_drivers):
194
+ main_driver = url.get_driver_name()
195
+ extra_drivers.discard(main_driver)
196
+
197
+ url = generate_driver_url(url, main_driver, "")
198
+ yield url
199
+
200
+ for drv in list(extra_drivers):
201
+ if "?" in drv:
202
+ driver_only, query_str = drv.split("?", 1)
203
+
204
+ else:
205
+ driver_only = drv
206
+ query_str = None
207
+
208
+ new_url = generate_driver_url(url, driver_only, query_str)
209
+ if new_url:
210
+ extra_drivers.remove(drv)
211
+
212
+ yield new_url
213
+
214
+
215
+ @register.init
216
+ def is_preferred_driver(cfg, engine):
217
+ """Return True if the engine's URL is on the "default" driver, or
218
+ more generally the "preferred" driver to use for tests.
219
+
220
+ Backends can override this to make a different driver the "prefeferred"
221
+ driver that's not the default.
222
+
223
+ """
224
+ return (
225
+ engine.url._get_entrypoint()
226
+ is engine.url.set(
227
+ drivername=engine.url.get_backend_name()
228
+ )._get_entrypoint()
229
+ )
230
+
231
+
232
+ @register.init
233
+ def generate_driver_url(url, driver, query_str):
234
+ backend = url.get_backend_name()
235
+
236
+ new_url = url.set(
237
+ drivername="%s+%s" % (backend, driver),
238
+ )
239
+ if query_str:
240
+ new_url = new_url.update_query_string(query_str)
241
+
242
+ try:
243
+ new_url.get_dialect()
244
+ except exc.NoSuchModuleError:
245
+ return None
246
+ else:
247
+ return new_url
248
+
249
+
250
+ def _configs_for_db_operation():
251
+ hosts = set()
252
+
253
+ for cfg in config.Config.all_configs():
254
+ cfg.db.dispose()
255
+
256
+ for cfg in config.Config.all_configs():
257
+ url = cfg.db.url
258
+ backend = url.get_backend_name()
259
+ host_conf = (backend, url.username, url.host, url.database)
260
+
261
+ if host_conf not in hosts:
262
+ yield cfg
263
+ hosts.add(host_conf)
264
+
265
+ for cfg in config.Config.all_configs():
266
+ cfg.db.dispose()
267
+
268
+
269
+ @register.init
270
+ def drop_all_schema_objects_pre_tables(cfg, eng):
271
+ pass
272
+
273
+
274
+ @register.init
275
+ def drop_all_schema_objects_post_tables(cfg, eng):
276
+ pass
277
+
278
+
279
+ def drop_all_schema_objects(cfg, eng):
280
+ drop_all_schema_objects_pre_tables(cfg, eng)
281
+
282
+ drop_views(cfg, eng)
283
+
284
+ if config.requirements.materialized_views.enabled:
285
+ drop_materialized_views(cfg, eng)
286
+
287
+ inspector = inspect(eng)
288
+
289
+ consider_schemas = (None,)
290
+ if config.requirements.schemas.enabled_for_config(cfg):
291
+ consider_schemas += (cfg.test_schema, cfg.test_schema_2)
292
+ util.drop_all_tables(eng, inspector, consider_schemas=consider_schemas)
293
+
294
+ drop_all_schema_objects_post_tables(cfg, eng)
295
+
296
+ if config.requirements.sequences.enabled_for_config(cfg):
297
+ with eng.begin() as conn:
298
+ for seq in inspector.get_sequence_names():
299
+ conn.execute(ddl.DropSequence(schema.Sequence(seq)))
300
+ if config.requirements.schemas.enabled_for_config(cfg):
301
+ for schema_name in [cfg.test_schema, cfg.test_schema_2]:
302
+ for seq in inspector.get_sequence_names(
303
+ schema=schema_name
304
+ ):
305
+ conn.execute(
306
+ ddl.DropSequence(
307
+ schema.Sequence(seq, schema=schema_name)
308
+ )
309
+ )
310
+
311
+
312
+ def drop_views(cfg, eng):
313
+ inspector = inspect(eng)
314
+
315
+ try:
316
+ view_names = inspector.get_view_names()
317
+ except NotImplementedError:
318
+ pass
319
+ else:
320
+ with eng.begin() as conn:
321
+ for vname in view_names:
322
+ conn.execute(
323
+ ddl._DropView(schema.Table(vname, schema.MetaData()))
324
+ )
325
+
326
+ if config.requirements.schemas.enabled_for_config(cfg):
327
+ try:
328
+ view_names = inspector.get_view_names(schema=cfg.test_schema)
329
+ except NotImplementedError:
330
+ pass
331
+ else:
332
+ with eng.begin() as conn:
333
+ for vname in view_names:
334
+ conn.execute(
335
+ ddl._DropView(
336
+ schema.Table(
337
+ vname,
338
+ schema.MetaData(),
339
+ schema=cfg.test_schema,
340
+ )
341
+ )
342
+ )
343
+
344
+
345
+ def drop_materialized_views(cfg, eng):
346
+ inspector = inspect(eng)
347
+
348
+ mview_names = inspector.get_materialized_view_names()
349
+
350
+ with eng.begin() as conn:
351
+ for vname in mview_names:
352
+ conn.exec_driver_sql(f"DROP MATERIALIZED VIEW {vname}")
353
+
354
+ if config.requirements.schemas.enabled_for_config(cfg):
355
+ mview_names = inspector.get_materialized_view_names(
356
+ schema=cfg.test_schema
357
+ )
358
+ with eng.begin() as conn:
359
+ for vname in mview_names:
360
+ conn.exec_driver_sql(
361
+ f"DROP MATERIALIZED VIEW {cfg.test_schema}.{vname}"
362
+ )
363
+
364
+
365
+ @register.init
366
+ def create_db(cfg, eng, ident):
367
+ """Dynamically create a database for testing.
368
+
369
+ Used when a test run will employ multiple processes, e.g., when run
370
+ via `tox` or `pytest -n4`.
371
+ """
372
+ raise NotImplementedError(
373
+ "no DB creation routine for cfg: %s" % (eng.url,)
374
+ )
375
+
376
+
377
+ @register.init
378
+ def drop_db(cfg, eng, ident):
379
+ """Drop a database that we dynamically created for testing."""
380
+ raise NotImplementedError("no DB drop routine for cfg: %s" % (eng.url,))
381
+
382
+
383
+ def _adapt_update_db_opts(fn):
384
+ insp = util.inspect_getfullargspec(fn)
385
+ if len(insp.args) == 3:
386
+ return fn
387
+ else:
388
+ return lambda db_url, db_opts, _options: fn(db_url, db_opts)
389
+
390
+
391
+ @register.init_decorator(_adapt_update_db_opts)
392
+ def update_db_opts(db_url, db_opts, options):
393
+ """Set database options (db_opts) for a test database that we created."""
394
+
395
+
396
+ @register.init
397
+ def post_configure_engine(url, engine, follower_ident):
398
+ """Perform extra steps after configuring the main engine for testing.
399
+
400
+ (For the internal dialects, currently only used by sqlite, oracle, mssql)
401
+ """
402
+
403
+
404
+ @register.init
405
+ def post_configure_testing_engine(url, engine, options, scope):
406
+ """perform extra steps after configuring any engine within the
407
+ testing_engine() function.
408
+
409
+ this includes the main engine as well as most ad-hoc testing engines.
410
+
411
+ steps here should not get in the way of test cases that are looking
412
+ for events, etc.
413
+
414
+ """
415
+
416
+
417
+ @register.init
418
+ def follower_url_from_main(url, ident):
419
+ """Create a connection URL for a dynamically-created test database.
420
+
421
+ :param url: the connection URL specified when the test run was invoked
422
+ :param ident: the pytest-xdist "worker identifier" to be used as the
423
+ database name
424
+ """
425
+ url = sa_url.make_url(url)
426
+ return url.set(database=ident)
427
+
428
+
429
+ @register.init
430
+ def configure_follower(cfg, ident):
431
+ """Create dialect-specific config settings for a follower database."""
432
+ pass
433
+
434
+
435
+ @register.init
436
+ def run_reap_dbs(url, ident):
437
+ """Remove databases that were created during the test process, after the
438
+ process has ended.
439
+
440
+ This is an optional step that is invoked for certain backends that do not
441
+ reliably release locks on the database as long as a process is still in
442
+ use. For the internal dialects, this is currently only necessary for
443
+ mssql and oracle.
444
+ """
445
+
446
+
447
+ def reap_dbs(idents_file):
448
+ log.info("Reaping databases...")
449
+
450
+ urls = collections.defaultdict(set)
451
+ idents = collections.defaultdict(set)
452
+ dialects = {}
453
+
454
+ with open(idents_file) as file_:
455
+ for line in file_:
456
+ line = line.strip()
457
+ db_name, db_url = line.split(" ")
458
+ url_obj = sa_url.make_url(db_url)
459
+ if db_name not in dialects:
460
+ dialects[db_name] = url_obj.get_dialect()
461
+ dialects[db_name].load_provisioning()
462
+ url_key = (url_obj.get_backend_name(), url_obj.host)
463
+ urls[url_key].add(db_url)
464
+ idents[url_key].add(db_name)
465
+
466
+ for url_key in urls:
467
+ url = list(urls[url_key])[0]
468
+ ident = idents[url_key]
469
+ run_reap_dbs(url, ident)
470
+
471
+
472
+ @register.init
473
+ def temp_table_keyword_args(cfg, eng):
474
+ """Specify keyword arguments for creating a temporary Table.
475
+
476
+ Dialect-specific implementations of this method will return the
477
+ kwargs that are passed to the Table method when creating a temporary
478
+ table for testing, e.g., in the define_temp_tables method of the
479
+ ComponentReflectionTest class in suite/test_reflection.py
480
+ """
481
+ raise NotImplementedError(
482
+ "no temp table keyword args routine for cfg: %s" % (eng.url,)
483
+ )
484
+
485
+
486
+ @register.init
487
+ def prepare_for_drop_tables(config, connection):
488
+ pass
489
+
490
+
491
+ @register.init
492
+ def stop_test_class_outside_fixtures(config, db, testcls):
493
+ pass
494
+
495
+
496
+ @register.init
497
+ def get_temp_table_name(cfg, eng, base_name):
498
+ """Specify table name for creating a temporary Table.
499
+
500
+ Dialect-specific implementations of this method will return the
501
+ name to use when creating a temporary table for testing,
502
+ e.g., in the define_temp_tables method of the
503
+ ComponentReflectionTest class in suite/test_reflection.py
504
+
505
+ Default to just the base name since that's what most dialects will
506
+ use. The mssql dialect's implementation will need a "#" prepended.
507
+ """
508
+ return base_name
509
+
510
+
511
+ @register.init
512
+ def set_default_schema_on_connection(cfg, dbapi_connection, schema_name):
513
+ raise NotImplementedError(
514
+ "backend does not implement a schema name set function: %s"
515
+ % (cfg.db.url,)
516
+ )
517
+
518
+
519
+ @register.init
520
+ def upsert(
521
+ cfg,
522
+ table,
523
+ returning,
524
+ *,
525
+ set_lambda=None,
526
+ sort_by_parameter_order=False,
527
+ index_elements=None,
528
+ ):
529
+ """return the backends insert..on conflict / on dupe etc. construct.
530
+
531
+ while we should add a backend-neutral upsert construct as well, such as
532
+ insert().upsert(), it's important that we continue to test the
533
+ backend-specific insert() constructs since if we do implement
534
+ insert().upsert(), that would be using a different codepath for the things
535
+ we need to test like insertmanyvalues, etc.
536
+
537
+ """
538
+ raise NotImplementedError(
539
+ f"backend does not include an upsert implementation: {cfg.db.url}"
540
+ )
541
+
542
+
543
+ @register.init
544
+ def normalize_sequence(cfg, sequence):
545
+ """Normalize sequence parameters for dialect that don't start with 1
546
+ by default.
547
+
548
+ The default implementation does nothing
549
+ """
550
+ return sequence
551
+
552
+
553
+ @register.init
554
+ def allow_stale_update_impl(cfg):
555
+ return contextlib.nullcontext()
556
+
557
+
558
+ @decorator
559
+ def allow_stale_updates(fn, *arg, **kw):
560
+ """decorator around a test function that indicates the test will
561
+ be UPDATING rows that have been read and are now stale.
562
+
563
+ This normally doesn't require intervention except for mariadb 12
564
+ which now raises its own error for that, and we want to turn off
565
+ that setting just within the scope of the test that needs it
566
+ to be turned off (i.e. ORM stale version tests)
567
+
568
+ """
569
+ with allow_stale_update_impl(config._current):
570
+ return fn(*arg, **kw)
571
+
572
+
573
+ @register.init
574
+ def delete_from_all_tables(connection, cfg, metadata):
575
+ """an absolutely foolproof delete from all tables routine.
576
+
577
+ dialects should override this to add special instructions like
578
+ disable constraints etc.
579
+
580
+ """
581
+ savepoints = getattr(cfg.requirements, "savepoints", False)
582
+ if savepoints:
583
+ savepoints = savepoints.enabled
584
+
585
+ inspector = inspect(connection)
586
+
587
+ for table in reversed(
588
+ [
589
+ t
590
+ for (t, fks) in sort_tables_and_constraints(
591
+ metadata.tables.values()
592
+ )
593
+ if t is not None
594
+ # remember that inspector.get_table_names() is cached,
595
+ # so this emits SQL once per unique schema name
596
+ and t.name in inspector.get_table_names(schema=t.schema)
597
+ ]
598
+ ):
599
+ if savepoints:
600
+ with connection.begin_nested():
601
+ connection.execute(table.delete())
602
+ else:
603
+ connection.execute(table.delete())