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