SQLAlchemy 2.1.0b2__cp313-cp313t-win_arm64.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 (270) hide show
  1. sqlalchemy/__init__.py +298 -0
  2. sqlalchemy/connectors/__init__.py +18 -0
  3. sqlalchemy/connectors/aioodbc.py +171 -0
  4. sqlalchemy/connectors/asyncio.py +476 -0
  5. sqlalchemy/connectors/pyodbc.py +250 -0
  6. sqlalchemy/dialects/__init__.py +62 -0
  7. sqlalchemy/dialects/_typing.py +30 -0
  8. sqlalchemy/dialects/mssql/__init__.py +89 -0
  9. sqlalchemy/dialects/mssql/aioodbc.py +63 -0
  10. sqlalchemy/dialects/mssql/base.py +4166 -0
  11. sqlalchemy/dialects/mssql/information_schema.py +285 -0
  12. sqlalchemy/dialects/mssql/json.py +140 -0
  13. sqlalchemy/dialects/mssql/mssqlpython.py +220 -0
  14. sqlalchemy/dialects/mssql/provision.py +196 -0
  15. sqlalchemy/dialects/mssql/pymssql.py +126 -0
  16. sqlalchemy/dialects/mssql/pyodbc.py +698 -0
  17. sqlalchemy/dialects/mysql/__init__.py +106 -0
  18. sqlalchemy/dialects/mysql/_mariadb_shim.py +312 -0
  19. sqlalchemy/dialects/mysql/aiomysql.py +226 -0
  20. sqlalchemy/dialects/mysql/asyncmy.py +214 -0
  21. sqlalchemy/dialects/mysql/base.py +3877 -0
  22. sqlalchemy/dialects/mysql/cymysql.py +106 -0
  23. sqlalchemy/dialects/mysql/dml.py +279 -0
  24. sqlalchemy/dialects/mysql/enumerated.py +277 -0
  25. sqlalchemy/dialects/mysql/expression.py +146 -0
  26. sqlalchemy/dialects/mysql/json.py +92 -0
  27. sqlalchemy/dialects/mysql/mariadb.py +67 -0
  28. sqlalchemy/dialects/mysql/mariadbconnector.py +330 -0
  29. sqlalchemy/dialects/mysql/mysqlconnector.py +296 -0
  30. sqlalchemy/dialects/mysql/mysqldb.py +312 -0
  31. sqlalchemy/dialects/mysql/provision.py +153 -0
  32. sqlalchemy/dialects/mysql/pymysql.py +157 -0
  33. sqlalchemy/dialects/mysql/pyodbc.py +156 -0
  34. sqlalchemy/dialects/mysql/reflection.py +724 -0
  35. sqlalchemy/dialects/mysql/reserved_words.py +570 -0
  36. sqlalchemy/dialects/mysql/types.py +845 -0
  37. sqlalchemy/dialects/oracle/__init__.py +85 -0
  38. sqlalchemy/dialects/oracle/base.py +3977 -0
  39. sqlalchemy/dialects/oracle/cx_oracle.py +1601 -0
  40. sqlalchemy/dialects/oracle/dictionary.py +507 -0
  41. sqlalchemy/dialects/oracle/json.py +158 -0
  42. sqlalchemy/dialects/oracle/oracledb.py +909 -0
  43. sqlalchemy/dialects/oracle/provision.py +288 -0
  44. sqlalchemy/dialects/oracle/types.py +367 -0
  45. sqlalchemy/dialects/oracle/vector.py +368 -0
  46. sqlalchemy/dialects/postgresql/__init__.py +171 -0
  47. sqlalchemy/dialects/postgresql/_psycopg_common.py +229 -0
  48. sqlalchemy/dialects/postgresql/array.py +534 -0
  49. sqlalchemy/dialects/postgresql/asyncpg.py +1323 -0
  50. sqlalchemy/dialects/postgresql/base.py +5789 -0
  51. sqlalchemy/dialects/postgresql/bitstring.py +327 -0
  52. sqlalchemy/dialects/postgresql/dml.py +360 -0
  53. sqlalchemy/dialects/postgresql/ext.py +593 -0
  54. sqlalchemy/dialects/postgresql/hstore.py +423 -0
  55. sqlalchemy/dialects/postgresql/json.py +408 -0
  56. sqlalchemy/dialects/postgresql/named_types.py +521 -0
  57. sqlalchemy/dialects/postgresql/operators.py +130 -0
  58. sqlalchemy/dialects/postgresql/pg8000.py +670 -0
  59. sqlalchemy/dialects/postgresql/pg_catalog.py +344 -0
  60. sqlalchemy/dialects/postgresql/provision.py +184 -0
  61. sqlalchemy/dialects/postgresql/psycopg.py +799 -0
  62. sqlalchemy/dialects/postgresql/psycopg2.py +860 -0
  63. sqlalchemy/dialects/postgresql/psycopg2cffi.py +61 -0
  64. sqlalchemy/dialects/postgresql/ranges.py +1002 -0
  65. sqlalchemy/dialects/postgresql/types.py +388 -0
  66. sqlalchemy/dialects/sqlite/__init__.py +57 -0
  67. sqlalchemy/dialects/sqlite/aiosqlite.py +321 -0
  68. sqlalchemy/dialects/sqlite/base.py +3063 -0
  69. sqlalchemy/dialects/sqlite/dml.py +279 -0
  70. sqlalchemy/dialects/sqlite/json.py +100 -0
  71. sqlalchemy/dialects/sqlite/provision.py +229 -0
  72. sqlalchemy/dialects/sqlite/pysqlcipher.py +161 -0
  73. sqlalchemy/dialects/sqlite/pysqlite.py +754 -0
  74. sqlalchemy/dialects/type_migration_guidelines.txt +145 -0
  75. sqlalchemy/engine/__init__.py +62 -0
  76. sqlalchemy/engine/_processors_cy.cp313t-win_arm64.pyd +0 -0
  77. sqlalchemy/engine/_processors_cy.py +92 -0
  78. sqlalchemy/engine/_result_cy.cp313t-win_arm64.pyd +0 -0
  79. sqlalchemy/engine/_result_cy.py +633 -0
  80. sqlalchemy/engine/_row_cy.cp313t-win_arm64.pyd +0 -0
  81. sqlalchemy/engine/_row_cy.py +232 -0
  82. sqlalchemy/engine/_util_cy.cp313t-win_arm64.pyd +0 -0
  83. sqlalchemy/engine/_util_cy.py +136 -0
  84. sqlalchemy/engine/base.py +3354 -0
  85. sqlalchemy/engine/characteristics.py +155 -0
  86. sqlalchemy/engine/create.py +877 -0
  87. sqlalchemy/engine/cursor.py +2421 -0
  88. sqlalchemy/engine/default.py +2402 -0
  89. sqlalchemy/engine/events.py +965 -0
  90. sqlalchemy/engine/interfaces.py +3495 -0
  91. sqlalchemy/engine/mock.py +134 -0
  92. sqlalchemy/engine/processors.py +82 -0
  93. sqlalchemy/engine/reflection.py +2100 -0
  94. sqlalchemy/engine/result.py +1966 -0
  95. sqlalchemy/engine/row.py +397 -0
  96. sqlalchemy/engine/strategies.py +16 -0
  97. sqlalchemy/engine/url.py +922 -0
  98. sqlalchemy/engine/util.py +156 -0
  99. sqlalchemy/event/__init__.py +26 -0
  100. sqlalchemy/event/api.py +220 -0
  101. sqlalchemy/event/attr.py +674 -0
  102. sqlalchemy/event/base.py +472 -0
  103. sqlalchemy/event/legacy.py +258 -0
  104. sqlalchemy/event/registry.py +390 -0
  105. sqlalchemy/events.py +17 -0
  106. sqlalchemy/exc.py +922 -0
  107. sqlalchemy/ext/__init__.py +11 -0
  108. sqlalchemy/ext/associationproxy.py +2072 -0
  109. sqlalchemy/ext/asyncio/__init__.py +29 -0
  110. sqlalchemy/ext/asyncio/base.py +281 -0
  111. sqlalchemy/ext/asyncio/engine.py +1487 -0
  112. sqlalchemy/ext/asyncio/exc.py +21 -0
  113. sqlalchemy/ext/asyncio/result.py +994 -0
  114. sqlalchemy/ext/asyncio/scoping.py +1679 -0
  115. sqlalchemy/ext/asyncio/session.py +2007 -0
  116. sqlalchemy/ext/automap.py +1701 -0
  117. sqlalchemy/ext/baked.py +559 -0
  118. sqlalchemy/ext/compiler.py +600 -0
  119. sqlalchemy/ext/declarative/__init__.py +65 -0
  120. sqlalchemy/ext/declarative/extensions.py +560 -0
  121. sqlalchemy/ext/horizontal_shard.py +481 -0
  122. sqlalchemy/ext/hybrid.py +1877 -0
  123. sqlalchemy/ext/indexable.py +364 -0
  124. sqlalchemy/ext/instrumentation.py +450 -0
  125. sqlalchemy/ext/mutable.py +1081 -0
  126. sqlalchemy/ext/orderinglist.py +439 -0
  127. sqlalchemy/ext/serializer.py +185 -0
  128. sqlalchemy/future/__init__.py +16 -0
  129. sqlalchemy/future/engine.py +15 -0
  130. sqlalchemy/inspection.py +174 -0
  131. sqlalchemy/log.py +283 -0
  132. sqlalchemy/orm/__init__.py +176 -0
  133. sqlalchemy/orm/_orm_constructors.py +2694 -0
  134. sqlalchemy/orm/_typing.py +179 -0
  135. sqlalchemy/orm/attributes.py +2868 -0
  136. sqlalchemy/orm/base.py +976 -0
  137. sqlalchemy/orm/bulk_persistence.py +2152 -0
  138. sqlalchemy/orm/clsregistry.py +582 -0
  139. sqlalchemy/orm/collections.py +1568 -0
  140. sqlalchemy/orm/context.py +3471 -0
  141. sqlalchemy/orm/decl_api.py +2280 -0
  142. sqlalchemy/orm/decl_base.py +2309 -0
  143. sqlalchemy/orm/dependency.py +1306 -0
  144. sqlalchemy/orm/descriptor_props.py +1183 -0
  145. sqlalchemy/orm/dynamic.py +307 -0
  146. sqlalchemy/orm/evaluator.py +379 -0
  147. sqlalchemy/orm/events.py +3386 -0
  148. sqlalchemy/orm/exc.py +237 -0
  149. sqlalchemy/orm/identity.py +302 -0
  150. sqlalchemy/orm/instrumentation.py +746 -0
  151. sqlalchemy/orm/interfaces.py +1589 -0
  152. sqlalchemy/orm/loading.py +1684 -0
  153. sqlalchemy/orm/mapped_collection.py +557 -0
  154. sqlalchemy/orm/mapper.py +4411 -0
  155. sqlalchemy/orm/path_registry.py +829 -0
  156. sqlalchemy/orm/persistence.py +1789 -0
  157. sqlalchemy/orm/properties.py +973 -0
  158. sqlalchemy/orm/query.py +3528 -0
  159. sqlalchemy/orm/relationships.py +3570 -0
  160. sqlalchemy/orm/scoping.py +2232 -0
  161. sqlalchemy/orm/session.py +5403 -0
  162. sqlalchemy/orm/state.py +1175 -0
  163. sqlalchemy/orm/state_changes.py +196 -0
  164. sqlalchemy/orm/strategies.py +3492 -0
  165. sqlalchemy/orm/strategy_options.py +2562 -0
  166. sqlalchemy/orm/sync.py +164 -0
  167. sqlalchemy/orm/unitofwork.py +798 -0
  168. sqlalchemy/orm/util.py +2438 -0
  169. sqlalchemy/orm/writeonly.py +694 -0
  170. sqlalchemy/pool/__init__.py +41 -0
  171. sqlalchemy/pool/base.py +1522 -0
  172. sqlalchemy/pool/events.py +375 -0
  173. sqlalchemy/pool/impl.py +582 -0
  174. sqlalchemy/py.typed +0 -0
  175. sqlalchemy/schema.py +74 -0
  176. sqlalchemy/sql/__init__.py +156 -0
  177. sqlalchemy/sql/_annotated_cols.py +397 -0
  178. sqlalchemy/sql/_dml_constructors.py +132 -0
  179. sqlalchemy/sql/_elements_constructors.py +2164 -0
  180. sqlalchemy/sql/_orm_types.py +20 -0
  181. sqlalchemy/sql/_selectable_constructors.py +840 -0
  182. sqlalchemy/sql/_typing.py +487 -0
  183. sqlalchemy/sql/_util_cy.cp313t-win_arm64.pyd +0 -0
  184. sqlalchemy/sql/_util_cy.py +127 -0
  185. sqlalchemy/sql/annotation.py +590 -0
  186. sqlalchemy/sql/base.py +2699 -0
  187. sqlalchemy/sql/cache_key.py +1066 -0
  188. sqlalchemy/sql/coercions.py +1373 -0
  189. sqlalchemy/sql/compiler.py +8327 -0
  190. sqlalchemy/sql/crud.py +1815 -0
  191. sqlalchemy/sql/ddl.py +1928 -0
  192. sqlalchemy/sql/default_comparator.py +654 -0
  193. sqlalchemy/sql/dml.py +1977 -0
  194. sqlalchemy/sql/elements.py +6033 -0
  195. sqlalchemy/sql/events.py +458 -0
  196. sqlalchemy/sql/expression.py +172 -0
  197. sqlalchemy/sql/functions.py +2305 -0
  198. sqlalchemy/sql/lambdas.py +1443 -0
  199. sqlalchemy/sql/naming.py +209 -0
  200. sqlalchemy/sql/operators.py +2897 -0
  201. sqlalchemy/sql/roles.py +332 -0
  202. sqlalchemy/sql/schema.py +6703 -0
  203. sqlalchemy/sql/selectable.py +7553 -0
  204. sqlalchemy/sql/sqltypes.py +4093 -0
  205. sqlalchemy/sql/traversals.py +1042 -0
  206. sqlalchemy/sql/type_api.py +2446 -0
  207. sqlalchemy/sql/util.py +1495 -0
  208. sqlalchemy/sql/visitors.py +1157 -0
  209. sqlalchemy/testing/__init__.py +96 -0
  210. sqlalchemy/testing/assertions.py +1007 -0
  211. sqlalchemy/testing/assertsql.py +519 -0
  212. sqlalchemy/testing/asyncio.py +128 -0
  213. sqlalchemy/testing/config.py +440 -0
  214. sqlalchemy/testing/engines.py +483 -0
  215. sqlalchemy/testing/entities.py +117 -0
  216. sqlalchemy/testing/exclusions.py +476 -0
  217. sqlalchemy/testing/fixtures/__init__.py +30 -0
  218. sqlalchemy/testing/fixtures/base.py +384 -0
  219. sqlalchemy/testing/fixtures/mypy.py +247 -0
  220. sqlalchemy/testing/fixtures/orm.py +227 -0
  221. sqlalchemy/testing/fixtures/sql.py +538 -0
  222. sqlalchemy/testing/pickleable.py +155 -0
  223. sqlalchemy/testing/plugin/__init__.py +6 -0
  224. sqlalchemy/testing/plugin/bootstrap.py +51 -0
  225. sqlalchemy/testing/plugin/plugin_base.py +828 -0
  226. sqlalchemy/testing/plugin/pytestplugin.py +892 -0
  227. sqlalchemy/testing/profiling.py +329 -0
  228. sqlalchemy/testing/provision.py +613 -0
  229. sqlalchemy/testing/requirements.py +1978 -0
  230. sqlalchemy/testing/schema.py +198 -0
  231. sqlalchemy/testing/suite/__init__.py +19 -0
  232. sqlalchemy/testing/suite/test_cte.py +237 -0
  233. sqlalchemy/testing/suite/test_ddl.py +420 -0
  234. sqlalchemy/testing/suite/test_dialect.py +776 -0
  235. sqlalchemy/testing/suite/test_insert.py +630 -0
  236. sqlalchemy/testing/suite/test_reflection.py +3557 -0
  237. sqlalchemy/testing/suite/test_results.py +660 -0
  238. sqlalchemy/testing/suite/test_rowcount.py +258 -0
  239. sqlalchemy/testing/suite/test_select.py +2112 -0
  240. sqlalchemy/testing/suite/test_sequence.py +317 -0
  241. sqlalchemy/testing/suite/test_table_via_select.py +686 -0
  242. sqlalchemy/testing/suite/test_types.py +2271 -0
  243. sqlalchemy/testing/suite/test_unicode_ddl.py +189 -0
  244. sqlalchemy/testing/suite/test_update_delete.py +139 -0
  245. sqlalchemy/testing/util.py +535 -0
  246. sqlalchemy/testing/warnings.py +52 -0
  247. sqlalchemy/types.py +76 -0
  248. sqlalchemy/util/__init__.py +158 -0
  249. sqlalchemy/util/_collections.py +688 -0
  250. sqlalchemy/util/_collections_cy.cp313t-win_arm64.pyd +0 -0
  251. sqlalchemy/util/_collections_cy.pxd +8 -0
  252. sqlalchemy/util/_collections_cy.py +516 -0
  253. sqlalchemy/util/_has_cython.py +46 -0
  254. sqlalchemy/util/_immutabledict_cy.cp313t-win_arm64.pyd +0 -0
  255. sqlalchemy/util/_immutabledict_cy.py +240 -0
  256. sqlalchemy/util/compat.py +299 -0
  257. sqlalchemy/util/concurrency.py +322 -0
  258. sqlalchemy/util/cython.py +79 -0
  259. sqlalchemy/util/deprecations.py +401 -0
  260. sqlalchemy/util/langhelpers.py +2320 -0
  261. sqlalchemy/util/preloaded.py +152 -0
  262. sqlalchemy/util/queue.py +304 -0
  263. sqlalchemy/util/tool_support.py +201 -0
  264. sqlalchemy/util/topological.py +120 -0
  265. sqlalchemy/util/typing.py +711 -0
  266. sqlalchemy-2.1.0b2.dist-info/METADATA +269 -0
  267. sqlalchemy-2.1.0b2.dist-info/RECORD +270 -0
  268. sqlalchemy-2.1.0b2.dist-info/WHEEL +5 -0
  269. sqlalchemy-2.1.0b2.dist-info/licenses/LICENSE +19 -0
  270. sqlalchemy-2.1.0b2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,613 @@
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
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 a sample option the asyncpg:
150
+
151
+ .. sourcecode:: text
152
+
153
+ --dburi postgresql://db1 \
154
+ --dbdriver=asyncpg?some_option=a_value
155
+
156
+ """
157
+ urls = set()
158
+
159
+ backend_to_driver_we_already_have = collections.defaultdict(set)
160
+
161
+ urls_plus_dialects = [
162
+ (url_obj, url_obj.get_dialect())
163
+ for url_obj in [sa_url.make_url(db_url) for db_url in db_urls]
164
+ ]
165
+
166
+ for url_obj, dialect in urls_plus_dialects:
167
+ # use get_driver_name instead of dialect.driver to account for
168
+ # "_async" virtual drivers like oracledb and psycopg
169
+ driver_name = url_obj.get_driver_name()
170
+ backend_to_driver_we_already_have[dialect.name].add(driver_name)
171
+
172
+ backend_to_driver_we_need = {}
173
+
174
+ for url_obj, dialect in urls_plus_dialects:
175
+ backend = dialect.name
176
+ dialect.load_provisioning()
177
+
178
+ if backend not in backend_to_driver_we_need:
179
+ backend_to_driver_we_need[backend] = extra_per_backend = set(
180
+ extra_drivers
181
+ ).difference(backend_to_driver_we_already_have[backend])
182
+ else:
183
+ extra_per_backend = backend_to_driver_we_need[backend]
184
+
185
+ for driver_url in _generate_driver_urls(url_obj, extra_per_backend):
186
+ if driver_url in urls:
187
+ continue
188
+ urls.add(driver_url)
189
+ yield driver_url
190
+
191
+
192
+ def _generate_driver_urls(url, extra_drivers):
193
+ main_driver = url.get_driver_name()
194
+ extra_drivers.discard(main_driver)
195
+
196
+ url = generate_driver_url(url, main_driver, "")
197
+ yield url
198
+
199
+ for drv in list(extra_drivers):
200
+ if "?" in drv:
201
+ driver_only, query_str = drv.split("?", 1)
202
+
203
+ else:
204
+ driver_only = drv
205
+ query_str = None
206
+
207
+ new_url = generate_driver_url(url, driver_only, query_str)
208
+ if new_url:
209
+ extra_drivers.remove(drv)
210
+
211
+ yield new_url
212
+
213
+
214
+ @register.init
215
+ def is_preferred_driver(cfg, engine):
216
+ """Return True if the engine's URL is on the "default" driver, or
217
+ more generally the "preferred" driver to use for tests.
218
+
219
+ Backends can override this to make a different driver the "prefeferred"
220
+ driver that's not the default.
221
+
222
+ """
223
+ return (
224
+ engine.url._get_entrypoint()
225
+ is engine.url.set(
226
+ drivername=engine.url.get_backend_name()
227
+ )._get_entrypoint()
228
+ )
229
+
230
+
231
+ @register.init
232
+ def generate_driver_url(url, driver, query_str):
233
+ backend = url.get_backend_name()
234
+
235
+ new_url = url.set(
236
+ drivername="%s+%s" % (backend, driver),
237
+ )
238
+ if query_str:
239
+ new_url = new_url.update_query_string(query_str)
240
+
241
+ try:
242
+ new_url.get_dialect()
243
+ except exc.NoSuchModuleError:
244
+ return None
245
+ else:
246
+ return new_url
247
+
248
+
249
+ def _configs_for_db_operation():
250
+ hosts = set()
251
+
252
+ for cfg in config.Config.all_configs():
253
+ cfg.db.dispose()
254
+
255
+ for cfg in config.Config.all_configs():
256
+ url = cfg.db.url
257
+ backend = url.get_backend_name()
258
+ host_conf = (backend, url.username, url.host, url.database)
259
+
260
+ if host_conf not in hosts:
261
+ yield cfg
262
+ hosts.add(host_conf)
263
+
264
+ for cfg in config.Config.all_configs():
265
+ cfg.db.dispose()
266
+
267
+
268
+ @register.init
269
+ def drop_all_schema_objects_pre_tables(cfg, eng):
270
+ pass
271
+
272
+
273
+ @register.init
274
+ def drop_all_schema_objects_post_tables(cfg, eng):
275
+ pass
276
+
277
+
278
+ def drop_all_schema_objects(cfg, eng):
279
+ drop_all_schema_objects_pre_tables(cfg, eng)
280
+
281
+ drop_views(cfg, eng)
282
+
283
+ if config.requirements.materialized_views.enabled:
284
+ drop_materialized_views(cfg, eng)
285
+
286
+ inspector = inspect(eng)
287
+
288
+ consider_schemas = (None,)
289
+ if config.requirements.schemas.enabled_for_config(cfg):
290
+ consider_schemas += (cfg.test_schema, cfg.test_schema_2)
291
+ util.drop_all_tables(eng, inspector, consider_schemas=consider_schemas)
292
+
293
+ drop_all_schema_objects_post_tables(cfg, eng)
294
+
295
+ if config.requirements.sequences.enabled_for_config(cfg):
296
+ with eng.begin() as conn:
297
+ for seq in inspector.get_sequence_names():
298
+ conn.execute(ddl.DropSequence(schema.Sequence(seq)))
299
+ if config.requirements.schemas.enabled_for_config(cfg):
300
+ for schema_name in [cfg.test_schema, cfg.test_schema_2]:
301
+ for seq in inspector.get_sequence_names(
302
+ schema=schema_name
303
+ ):
304
+ conn.execute(
305
+ ddl.DropSequence(
306
+ schema.Sequence(seq, schema=schema_name)
307
+ )
308
+ )
309
+
310
+
311
+ def drop_views(cfg, eng):
312
+ inspector = inspect(eng)
313
+
314
+ try:
315
+ view_names = inspector.get_view_names()
316
+ except NotImplementedError:
317
+ pass
318
+ else:
319
+ with eng.begin() as conn:
320
+ for vname in view_names:
321
+ conn.execute(
322
+ ddl.DropView(schema.Table(vname, schema.MetaData()))
323
+ )
324
+
325
+ if config.requirements.schemas.enabled_for_config(cfg):
326
+ try:
327
+ view_names = inspector.get_view_names(schema=cfg.test_schema)
328
+ except NotImplementedError:
329
+ pass
330
+ else:
331
+ with eng.begin() as conn:
332
+ for vname in view_names:
333
+ conn.execute(
334
+ ddl.DropView(
335
+ schema.Table(
336
+ vname,
337
+ schema.MetaData(),
338
+ schema=cfg.test_schema,
339
+ )
340
+ )
341
+ )
342
+
343
+
344
+ def drop_materialized_views(cfg, eng):
345
+ inspector = inspect(eng)
346
+
347
+ mview_names = inspector.get_materialized_view_names()
348
+
349
+ with eng.begin() as conn:
350
+ for vname in mview_names:
351
+ conn.exec_driver_sql(f"DROP MATERIALIZED VIEW {vname}")
352
+
353
+ if config.requirements.schemas.enabled_for_config(cfg):
354
+ mview_names = inspector.get_materialized_view_names(
355
+ schema=cfg.test_schema
356
+ )
357
+ with eng.begin() as conn:
358
+ for vname in mview_names:
359
+ conn.exec_driver_sql(
360
+ f"DROP MATERIALIZED VIEW {cfg.test_schema}.{vname}"
361
+ )
362
+
363
+
364
+ @register.init
365
+ def create_db(cfg, eng, ident):
366
+ """Dynamically create a database for testing.
367
+
368
+ Used when a test run will employ multiple processes, e.g., when run
369
+ via `tox` or `pytest -n4`.
370
+ """
371
+ raise NotImplementedError(
372
+ "no DB creation routine for cfg: %s" % (eng.url,)
373
+ )
374
+
375
+
376
+ @register.init
377
+ def drop_db(cfg, eng, ident):
378
+ """Drop a database that we dynamically created for testing."""
379
+ raise NotImplementedError("no DB drop routine for cfg: %s" % (eng.url,))
380
+
381
+
382
+ def _adapt_update_db_opts(fn):
383
+ insp = util.inspect_getfullargspec(fn)
384
+ if len(insp.args) == 3:
385
+ return fn
386
+ else:
387
+ return lambda db_url, db_opts, _options: fn(db_url, db_opts)
388
+
389
+
390
+ @register.init_decorator(_adapt_update_db_opts)
391
+ def update_db_opts(db_url, db_opts, options):
392
+ """Set database options (db_opts) for a test database that we created."""
393
+
394
+
395
+ @register.init
396
+ def post_configure_engine(url, engine, follower_ident):
397
+ """Perform extra steps after configuring the main engine for testing.
398
+
399
+ (For the internal dialects, currently only used by sqlite, oracle, mssql)
400
+ """
401
+
402
+
403
+ @register.init
404
+ def post_configure_testing_engine(url, engine, options, scope):
405
+ """perform extra steps after configuring any engine within the
406
+ testing_engine() function.
407
+
408
+ this includes the main engine as well as most ad-hoc testing engines.
409
+
410
+ steps here should not get in the way of test cases that are looking
411
+ for events, etc.
412
+
413
+ """
414
+
415
+
416
+ @register.init
417
+ def follower_url_from_main(url, ident):
418
+ """Create a connection URL for a dynamically-created test database.
419
+
420
+ :param url: the connection URL specified when the test run was invoked
421
+ :param ident: the pytest-xdist "worker identifier" to be used as the
422
+ database name
423
+ """
424
+ url = sa_url.make_url(url)
425
+ return url.set(database=ident)
426
+
427
+
428
+ @register.init
429
+ def configure_follower(cfg, ident):
430
+ """Create dialect-specific config settings for a follower database."""
431
+ pass
432
+
433
+
434
+ @register.init
435
+ def run_reap_dbs(url, ident):
436
+ """Remove databases that were created during the test process, after the
437
+ process has ended.
438
+
439
+ This is an optional step that is invoked for certain backends that do not
440
+ reliably release locks on the database as long as a process is still in
441
+ use. For the internal dialects, this is currently only necessary for
442
+ mssql and oracle.
443
+ """
444
+
445
+
446
+ def reap_dbs(idents_file):
447
+ log.info("Reaping databases...")
448
+
449
+ urls = collections.defaultdict(set)
450
+ idents = collections.defaultdict(set)
451
+ dialects = {}
452
+
453
+ with open(idents_file) as file_:
454
+ for line in file_:
455
+ line = line.strip()
456
+ db_name, db_url = line.split(" ")
457
+ url_obj = sa_url.make_url(db_url)
458
+ if db_name not in dialects:
459
+ dialects[db_name] = url_obj.get_dialect()
460
+ dialects[db_name].load_provisioning()
461
+ url_key = (url_obj.get_backend_name(), url_obj.host)
462
+ urls[url_key].add(db_url)
463
+ idents[url_key].add(db_name)
464
+
465
+ for url_key in urls:
466
+ url = list(urls[url_key])[0]
467
+ ident = idents[url_key]
468
+ run_reap_dbs(url, ident)
469
+
470
+
471
+ @register.init
472
+ def temp_table_keyword_args(cfg, eng):
473
+ """Specify keyword arguments for creating a temporary Table.
474
+
475
+ Dialect-specific implementations of this method will return the
476
+ kwargs that are passed to the Table method when creating a temporary
477
+ table for testing, e.g., in the define_temp_tables method of the
478
+ ComponentReflectionTest class in suite/test_reflection.py
479
+ """
480
+ raise NotImplementedError(
481
+ "no temp table keyword args routine for cfg: %s" % (eng.url,)
482
+ )
483
+
484
+
485
+ @register.init
486
+ def prepare_for_drop_tables(config, connection):
487
+ pass
488
+
489
+
490
+ @register.init
491
+ def stop_test_class_outside_fixtures(config, db, testcls):
492
+ pass
493
+
494
+
495
+ @register.init
496
+ def get_temp_table_name(cfg, eng, base_name):
497
+ """Specify table name for creating a temporary Table.
498
+
499
+ Dialect-specific implementations of this method will return the
500
+ name to use when creating a temporary table for testing,
501
+ e.g., in the define_temp_tables method of the
502
+ ComponentReflectionTest class in suite/test_reflection.py
503
+
504
+ Default to just the base name since that's what most dialects will
505
+ use. The mssql dialect's implementation will need a "#" prepended.
506
+ """
507
+ return base_name
508
+
509
+
510
+ @register.init
511
+ def set_default_schema_on_connection(cfg, dbapi_connection, schema_name):
512
+ raise NotImplementedError(
513
+ "backend does not implement a schema name set function: %s"
514
+ % (cfg.db.url,)
515
+ )
516
+
517
+
518
+ @register.init
519
+ def upsert(
520
+ cfg,
521
+ table,
522
+ returning,
523
+ *,
524
+ set_lambda=None,
525
+ sort_by_parameter_order=False,
526
+ index_elements=None,
527
+ ):
528
+ """return the backends insert..on conflict / on dupe etc. construct.
529
+
530
+ while we should add a backend-neutral upsert construct as well, such as
531
+ insert().upsert(), it's important that we continue to test the
532
+ backend-specific insert() constructs since if we do implement
533
+ insert().upsert(), that would be using a different codepath for the things
534
+ we need to test like insertmanyvalues, etc.
535
+
536
+ """
537
+ raise NotImplementedError(
538
+ f"backend does not include an upsert implementation: {cfg.db.url}"
539
+ )
540
+
541
+
542
+ @register.init
543
+ def normalize_sequence(cfg, sequence):
544
+ """Normalize sequence parameters for dialect that don't start with 1
545
+ by default.
546
+
547
+ The default implementation does nothing
548
+ """
549
+ return sequence
550
+
551
+
552
+ @register.init
553
+ def allow_stale_update_impl(cfg):
554
+ return contextlib.nullcontext()
555
+
556
+
557
+ @decorator
558
+ def allow_stale_updates(fn, *arg, **kw):
559
+ """decorator around a test function that indicates the test will
560
+ be UPDATING rows that have been read and are now stale.
561
+
562
+ This normally doesn't require intervention except for mariadb 12
563
+ which now raises its own error for that, and we want to turn off
564
+ that setting just within the scope of the test that needs it
565
+ to be turned off (i.e. ORM stale version tests)
566
+
567
+ """
568
+ with allow_stale_update_impl(config._current):
569
+ return fn(*arg, **kw)
570
+
571
+
572
+ @register.init
573
+ def delete_from_all_tables(connection, cfg, metadata):
574
+ """an absolutely foolproof delete from all tables routine.
575
+
576
+ dialects should override this to add special instructions like
577
+ disable constraints etc.
578
+
579
+ """
580
+ savepoints = getattr(cfg.requirements, "savepoints", False)
581
+ if savepoints:
582
+ savepoints = savepoints.enabled
583
+
584
+ inspector = inspect(connection)
585
+
586
+ for table in reversed(
587
+ [
588
+ t
589
+ for (t, fks) in sort_tables_and_constraints(
590
+ metadata.tables.values()
591
+ )
592
+ if t is not None
593
+ # remember that inspector.get_table_names() is cached,
594
+ # so this emits SQL once per unique schema name
595
+ and t.name in inspector.get_table_names(schema=t.schema)
596
+ ]
597
+ ):
598
+ if savepoints:
599
+ with connection.begin_nested():
600
+ connection.execute(table.delete())
601
+ else:
602
+ connection.execute(table.delete())
603
+
604
+
605
+ @register.init
606
+ def dbapi_error(cfg, cls, message):
607
+ """create a DBAPI error
608
+
609
+ :param cls: the DBAPI class, like ``dialect.dbapi.OperationalError``
610
+ :param message: message for the error
611
+
612
+ """
613
+ return cls(message)