SQLAlchemy 2.0.36__cp313-cp313-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 (273) hide show
  1. SQLAlchemy-2.0.36.dist-info/LICENSE +19 -0
  2. SQLAlchemy-2.0.36.dist-info/METADATA +243 -0
  3. SQLAlchemy-2.0.36.dist-info/RECORD +273 -0
  4. SQLAlchemy-2.0.36.dist-info/WHEEL +5 -0
  5. SQLAlchemy-2.0.36.dist-info/top_level.txt +1 -0
  6. sqlalchemy/__init__.py +294 -0
  7. sqlalchemy/connectors/__init__.py +18 -0
  8. sqlalchemy/connectors/aioodbc.py +174 -0
  9. sqlalchemy/connectors/asyncio.py +213 -0
  10. sqlalchemy/connectors/pyodbc.py +249 -0
  11. sqlalchemy/cyextension/__init__.py +6 -0
  12. sqlalchemy/cyextension/collections.cp313-win32.pyd +0 -0
  13. sqlalchemy/cyextension/collections.pyx +409 -0
  14. sqlalchemy/cyextension/immutabledict.cp313-win32.pyd +0 -0
  15. sqlalchemy/cyextension/immutabledict.pxd +8 -0
  16. sqlalchemy/cyextension/immutabledict.pyx +133 -0
  17. sqlalchemy/cyextension/processors.cp313-win32.pyd +0 -0
  18. sqlalchemy/cyextension/processors.pyx +68 -0
  19. sqlalchemy/cyextension/resultproxy.cp313-win32.pyd +0 -0
  20. sqlalchemy/cyextension/resultproxy.pyx +102 -0
  21. sqlalchemy/cyextension/util.cp313-win32.pyd +0 -0
  22. sqlalchemy/cyextension/util.pyx +91 -0
  23. sqlalchemy/dialects/__init__.py +61 -0
  24. sqlalchemy/dialects/_typing.py +25 -0
  25. sqlalchemy/dialects/mssql/__init__.py +88 -0
  26. sqlalchemy/dialects/mssql/aioodbc.py +64 -0
  27. sqlalchemy/dialects/mssql/base.py +4010 -0
  28. sqlalchemy/dialects/mssql/information_schema.py +254 -0
  29. sqlalchemy/dialects/mssql/json.py +133 -0
  30. sqlalchemy/dialects/mssql/provision.py +162 -0
  31. sqlalchemy/dialects/mssql/pymssql.py +126 -0
  32. sqlalchemy/dialects/mssql/pyodbc.py +745 -0
  33. sqlalchemy/dialects/mysql/__init__.py +101 -0
  34. sqlalchemy/dialects/mysql/aiomysql.py +333 -0
  35. sqlalchemy/dialects/mysql/asyncmy.py +337 -0
  36. sqlalchemy/dialects/mysql/base.py +3494 -0
  37. sqlalchemy/dialects/mysql/cymysql.py +84 -0
  38. sqlalchemy/dialects/mysql/dml.py +219 -0
  39. sqlalchemy/dialects/mysql/enumerated.py +244 -0
  40. sqlalchemy/dialects/mysql/expression.py +141 -0
  41. sqlalchemy/dialects/mysql/json.py +81 -0
  42. sqlalchemy/dialects/mysql/mariadb.py +32 -0
  43. sqlalchemy/dialects/mysql/mariadbconnector.py +277 -0
  44. sqlalchemy/dialects/mysql/mysqlconnector.py +180 -0
  45. sqlalchemy/dialects/mysql/mysqldb.py +303 -0
  46. sqlalchemy/dialects/mysql/provision.py +110 -0
  47. sqlalchemy/dialects/mysql/pymysql.py +137 -0
  48. sqlalchemy/dialects/mysql/pyodbc.py +138 -0
  49. sqlalchemy/dialects/mysql/reflection.py +677 -0
  50. sqlalchemy/dialects/mysql/reserved_words.py +571 -0
  51. sqlalchemy/dialects/mysql/types.py +774 -0
  52. sqlalchemy/dialects/oracle/__init__.py +67 -0
  53. sqlalchemy/dialects/oracle/base.py +3271 -0
  54. sqlalchemy/dialects/oracle/cx_oracle.py +1483 -0
  55. sqlalchemy/dialects/oracle/dictionary.py +507 -0
  56. sqlalchemy/dialects/oracle/oracledb.py +431 -0
  57. sqlalchemy/dialects/oracle/provision.py +220 -0
  58. sqlalchemy/dialects/oracle/types.py +287 -0
  59. sqlalchemy/dialects/postgresql/__init__.py +167 -0
  60. sqlalchemy/dialects/postgresql/_psycopg_common.py +187 -0
  61. sqlalchemy/dialects/postgresql/array.py +425 -0
  62. sqlalchemy/dialects/postgresql/asyncpg.py +1274 -0
  63. sqlalchemy/dialects/postgresql/base.py +5008 -0
  64. sqlalchemy/dialects/postgresql/dml.py +310 -0
  65. sqlalchemy/dialects/postgresql/ext.py +496 -0
  66. sqlalchemy/dialects/postgresql/hstore.py +397 -0
  67. sqlalchemy/dialects/postgresql/json.py +333 -0
  68. sqlalchemy/dialects/postgresql/named_types.py +509 -0
  69. sqlalchemy/dialects/postgresql/operators.py +129 -0
  70. sqlalchemy/dialects/postgresql/pg8000.py +662 -0
  71. sqlalchemy/dialects/postgresql/pg_catalog.py +300 -0
  72. sqlalchemy/dialects/postgresql/provision.py +175 -0
  73. sqlalchemy/dialects/postgresql/psycopg.py +772 -0
  74. sqlalchemy/dialects/postgresql/psycopg2.py +886 -0
  75. sqlalchemy/dialects/postgresql/psycopg2cffi.py +61 -0
  76. sqlalchemy/dialects/postgresql/ranges.py +1029 -0
  77. sqlalchemy/dialects/postgresql/types.py +303 -0
  78. sqlalchemy/dialects/sqlite/__init__.py +57 -0
  79. sqlalchemy/dialects/sqlite/aiosqlite.py +396 -0
  80. sqlalchemy/dialects/sqlite/base.py +2805 -0
  81. sqlalchemy/dialects/sqlite/dml.py +240 -0
  82. sqlalchemy/dialects/sqlite/json.py +92 -0
  83. sqlalchemy/dialects/sqlite/provision.py +198 -0
  84. sqlalchemy/dialects/sqlite/pysqlcipher.py +155 -0
  85. sqlalchemy/dialects/sqlite/pysqlite.py +756 -0
  86. sqlalchemy/dialects/type_migration_guidelines.txt +145 -0
  87. sqlalchemy/engine/__init__.py +62 -0
  88. sqlalchemy/engine/_py_processors.py +136 -0
  89. sqlalchemy/engine/_py_row.py +128 -0
  90. sqlalchemy/engine/_py_util.py +74 -0
  91. sqlalchemy/engine/base.py +3375 -0
  92. sqlalchemy/engine/characteristics.py +155 -0
  93. sqlalchemy/engine/create.py +875 -0
  94. sqlalchemy/engine/cursor.py +2181 -0
  95. sqlalchemy/engine/default.py +2365 -0
  96. sqlalchemy/engine/events.py +951 -0
  97. sqlalchemy/engine/interfaces.py +3403 -0
  98. sqlalchemy/engine/mock.py +131 -0
  99. sqlalchemy/engine/processors.py +61 -0
  100. sqlalchemy/engine/reflection.py +2098 -0
  101. sqlalchemy/engine/result.py +2382 -0
  102. sqlalchemy/engine/row.py +401 -0
  103. sqlalchemy/engine/strategies.py +19 -0
  104. sqlalchemy/engine/url.py +910 -0
  105. sqlalchemy/engine/util.py +167 -0
  106. sqlalchemy/event/__init__.py +25 -0
  107. sqlalchemy/event/api.py +225 -0
  108. sqlalchemy/event/attr.py +655 -0
  109. sqlalchemy/event/base.py +470 -0
  110. sqlalchemy/event/legacy.py +246 -0
  111. sqlalchemy/event/registry.py +386 -0
  112. sqlalchemy/events.py +17 -0
  113. sqlalchemy/exc.py +830 -0
  114. sqlalchemy/ext/__init__.py +11 -0
  115. sqlalchemy/ext/associationproxy.py +2013 -0
  116. sqlalchemy/ext/asyncio/__init__.py +25 -0
  117. sqlalchemy/ext/asyncio/base.py +279 -0
  118. sqlalchemy/ext/asyncio/engine.py +1466 -0
  119. sqlalchemy/ext/asyncio/exc.py +21 -0
  120. sqlalchemy/ext/asyncio/result.py +961 -0
  121. sqlalchemy/ext/asyncio/scoping.py +1614 -0
  122. sqlalchemy/ext/asyncio/session.py +1936 -0
  123. sqlalchemy/ext/automap.py +1691 -0
  124. sqlalchemy/ext/baked.py +574 -0
  125. sqlalchemy/ext/compiler.py +570 -0
  126. sqlalchemy/ext/declarative/__init__.py +65 -0
  127. sqlalchemy/ext/declarative/extensions.py +548 -0
  128. sqlalchemy/ext/horizontal_shard.py +481 -0
  129. sqlalchemy/ext/hybrid.py +1514 -0
  130. sqlalchemy/ext/indexable.py +341 -0
  131. sqlalchemy/ext/instrumentation.py +450 -0
  132. sqlalchemy/ext/mutable.py +1073 -0
  133. sqlalchemy/ext/mypy/__init__.py +6 -0
  134. sqlalchemy/ext/mypy/apply.py +320 -0
  135. sqlalchemy/ext/mypy/decl_class.py +515 -0
  136. sqlalchemy/ext/mypy/infer.py +590 -0
  137. sqlalchemy/ext/mypy/names.py +335 -0
  138. sqlalchemy/ext/mypy/plugin.py +303 -0
  139. sqlalchemy/ext/mypy/util.py +357 -0
  140. sqlalchemy/ext/orderinglist.py +416 -0
  141. sqlalchemy/ext/serializer.py +181 -0
  142. sqlalchemy/future/__init__.py +16 -0
  143. sqlalchemy/future/engine.py +15 -0
  144. sqlalchemy/inspection.py +174 -0
  145. sqlalchemy/log.py +288 -0
  146. sqlalchemy/orm/__init__.py +170 -0
  147. sqlalchemy/orm/_orm_constructors.py +2571 -0
  148. sqlalchemy/orm/_typing.py +179 -0
  149. sqlalchemy/orm/attributes.py +2835 -0
  150. sqlalchemy/orm/base.py +973 -0
  151. sqlalchemy/orm/bulk_persistence.py +2123 -0
  152. sqlalchemy/orm/clsregistry.py +571 -0
  153. sqlalchemy/orm/collections.py +1620 -0
  154. sqlalchemy/orm/context.py +3268 -0
  155. sqlalchemy/orm/decl_api.py +1883 -0
  156. sqlalchemy/orm/decl_base.py +2190 -0
  157. sqlalchemy/orm/dependency.py +1304 -0
  158. sqlalchemy/orm/descriptor_props.py +1076 -0
  159. sqlalchemy/orm/dynamic.py +300 -0
  160. sqlalchemy/orm/evaluator.py +379 -0
  161. sqlalchemy/orm/events.py +3261 -0
  162. sqlalchemy/orm/exc.py +228 -0
  163. sqlalchemy/orm/identity.py +302 -0
  164. sqlalchemy/orm/instrumentation.py +754 -0
  165. sqlalchemy/orm/interfaces.py +1474 -0
  166. sqlalchemy/orm/loading.py +1682 -0
  167. sqlalchemy/orm/mapped_collection.py +557 -0
  168. sqlalchemy/orm/mapper.py +4432 -0
  169. sqlalchemy/orm/path_registry.py +811 -0
  170. sqlalchemy/orm/persistence.py +1782 -0
  171. sqlalchemy/orm/properties.py +886 -0
  172. sqlalchemy/orm/query.py +3396 -0
  173. sqlalchemy/orm/relationships.py +3500 -0
  174. sqlalchemy/orm/scoping.py +2165 -0
  175. sqlalchemy/orm/session.py +5301 -0
  176. sqlalchemy/orm/state.py +1143 -0
  177. sqlalchemy/orm/state_changes.py +198 -0
  178. sqlalchemy/orm/strategies.py +3473 -0
  179. sqlalchemy/orm/strategy_options.py +2569 -0
  180. sqlalchemy/orm/sync.py +164 -0
  181. sqlalchemy/orm/unitofwork.py +796 -0
  182. sqlalchemy/orm/util.py +2424 -0
  183. sqlalchemy/orm/writeonly.py +678 -0
  184. sqlalchemy/pool/__init__.py +44 -0
  185. sqlalchemy/pool/base.py +1515 -0
  186. sqlalchemy/pool/events.py +370 -0
  187. sqlalchemy/pool/impl.py +581 -0
  188. sqlalchemy/py.typed +0 -0
  189. sqlalchemy/schema.py +70 -0
  190. sqlalchemy/sql/__init__.py +145 -0
  191. sqlalchemy/sql/_dml_constructors.py +140 -0
  192. sqlalchemy/sql/_elements_constructors.py +1850 -0
  193. sqlalchemy/sql/_orm_types.py +20 -0
  194. sqlalchemy/sql/_py_util.py +75 -0
  195. sqlalchemy/sql/_selectable_constructors.py +635 -0
  196. sqlalchemy/sql/_typing.py +460 -0
  197. sqlalchemy/sql/annotation.py +585 -0
  198. sqlalchemy/sql/base.py +2185 -0
  199. sqlalchemy/sql/cache_key.py +1057 -0
  200. sqlalchemy/sql/coercions.py +1405 -0
  201. sqlalchemy/sql/compiler.py +7818 -0
  202. sqlalchemy/sql/crud.py +1669 -0
  203. sqlalchemy/sql/ddl.py +1378 -0
  204. sqlalchemy/sql/default_comparator.py +552 -0
  205. sqlalchemy/sql/dml.py +1817 -0
  206. sqlalchemy/sql/elements.py +5499 -0
  207. sqlalchemy/sql/events.py +455 -0
  208. sqlalchemy/sql/expression.py +162 -0
  209. sqlalchemy/sql/functions.py +2055 -0
  210. sqlalchemy/sql/lambdas.py +1449 -0
  211. sqlalchemy/sql/naming.py +212 -0
  212. sqlalchemy/sql/operators.py +2579 -0
  213. sqlalchemy/sql/roles.py +323 -0
  214. sqlalchemy/sql/schema.py +6158 -0
  215. sqlalchemy/sql/selectable.py +7004 -0
  216. sqlalchemy/sql/sqltypes.py +3827 -0
  217. sqlalchemy/sql/traversals.py +1024 -0
  218. sqlalchemy/sql/type_api.py +2339 -0
  219. sqlalchemy/sql/util.py +1486 -0
  220. sqlalchemy/sql/visitors.py +1165 -0
  221. sqlalchemy/testing/__init__.py +96 -0
  222. sqlalchemy/testing/assertions.py +989 -0
  223. sqlalchemy/testing/assertsql.py +516 -0
  224. sqlalchemy/testing/asyncio.py +135 -0
  225. sqlalchemy/testing/config.py +427 -0
  226. sqlalchemy/testing/engines.py +472 -0
  227. sqlalchemy/testing/entities.py +117 -0
  228. sqlalchemy/testing/exclusions.py +435 -0
  229. sqlalchemy/testing/fixtures/__init__.py +28 -0
  230. sqlalchemy/testing/fixtures/base.py +366 -0
  231. sqlalchemy/testing/fixtures/mypy.py +312 -0
  232. sqlalchemy/testing/fixtures/orm.py +227 -0
  233. sqlalchemy/testing/fixtures/sql.py +503 -0
  234. sqlalchemy/testing/pickleable.py +155 -0
  235. sqlalchemy/testing/plugin/__init__.py +6 -0
  236. sqlalchemy/testing/plugin/bootstrap.py +51 -0
  237. sqlalchemy/testing/plugin/plugin_base.py +779 -0
  238. sqlalchemy/testing/plugin/pytestplugin.py +868 -0
  239. sqlalchemy/testing/profiling.py +324 -0
  240. sqlalchemy/testing/provision.py +496 -0
  241. sqlalchemy/testing/requirements.py +1818 -0
  242. sqlalchemy/testing/schema.py +224 -0
  243. sqlalchemy/testing/suite/__init__.py +19 -0
  244. sqlalchemy/testing/suite/test_cte.py +211 -0
  245. sqlalchemy/testing/suite/test_ddl.py +389 -0
  246. sqlalchemy/testing/suite/test_deprecations.py +153 -0
  247. sqlalchemy/testing/suite/test_dialect.py +740 -0
  248. sqlalchemy/testing/suite/test_insert.py +630 -0
  249. sqlalchemy/testing/suite/test_reflection.py +3225 -0
  250. sqlalchemy/testing/suite/test_results.py +502 -0
  251. sqlalchemy/testing/suite/test_rowcount.py +258 -0
  252. sqlalchemy/testing/suite/test_select.py +1999 -0
  253. sqlalchemy/testing/suite/test_sequence.py +317 -0
  254. sqlalchemy/testing/suite/test_types.py +2141 -0
  255. sqlalchemy/testing/suite/test_unicode_ddl.py +189 -0
  256. sqlalchemy/testing/suite/test_update_delete.py +139 -0
  257. sqlalchemy/testing/util.py +537 -0
  258. sqlalchemy/testing/warnings.py +52 -0
  259. sqlalchemy/types.py +76 -0
  260. sqlalchemy/util/__init__.py +160 -0
  261. sqlalchemy/util/_collections.py +715 -0
  262. sqlalchemy/util/_concurrency_py3k.py +288 -0
  263. sqlalchemy/util/_has_cy.py +40 -0
  264. sqlalchemy/util/_py_collections.py +541 -0
  265. sqlalchemy/util/compat.py +301 -0
  266. sqlalchemy/util/concurrency.py +108 -0
  267. sqlalchemy/util/deprecations.py +401 -0
  268. sqlalchemy/util/langhelpers.py +2218 -0
  269. sqlalchemy/util/preloaded.py +150 -0
  270. sqlalchemy/util/queue.py +322 -0
  271. sqlalchemy/util/tool_support.py +201 -0
  272. sqlalchemy/util/topological.py +120 -0
  273. sqlalchemy/util/typing.py +629 -0
@@ -0,0 +1,496 @@
1
+ # testing/provision.py
2
+ # Copyright (C) 2005-2024 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 logging
13
+
14
+ from . import config
15
+ from . import engines
16
+ from . import util
17
+ from .. import exc
18
+ from .. import inspect
19
+ from ..engine import url as sa_url
20
+ from ..sql import ddl
21
+ from ..sql import schema
22
+
23
+
24
+ log = logging.getLogger(__name__)
25
+
26
+ FOLLOWER_IDENT = None
27
+
28
+
29
+ class register:
30
+ def __init__(self, decorator=None):
31
+ self.fns = {}
32
+ self.decorator = decorator
33
+
34
+ @classmethod
35
+ def init(cls, fn):
36
+ return register().for_db("*")(fn)
37
+
38
+ @classmethod
39
+ def init_decorator(cls, decorator):
40
+ return register(decorator).for_db("*")
41
+
42
+ def for_db(self, *dbnames):
43
+ def decorate(fn):
44
+ if self.decorator:
45
+ fn = self.decorator(fn)
46
+ for dbname in dbnames:
47
+ self.fns[dbname] = fn
48
+ return self
49
+
50
+ return decorate
51
+
52
+ def __call__(self, cfg, *arg, **kw):
53
+ if isinstance(cfg, str):
54
+ url = sa_url.make_url(cfg)
55
+ elif isinstance(cfg, sa_url.URL):
56
+ url = cfg
57
+ else:
58
+ url = cfg.db.url
59
+ backend = url.get_backend_name()
60
+ if backend in self.fns:
61
+ return self.fns[backend](cfg, *arg, **kw)
62
+ else:
63
+ return self.fns["*"](cfg, *arg, **kw)
64
+
65
+
66
+ def create_follower_db(follower_ident):
67
+ for cfg in _configs_for_db_operation():
68
+ log.info("CREATE database %s, URI %r", follower_ident, cfg.db.url)
69
+ create_db(cfg, cfg.db, follower_ident)
70
+
71
+
72
+ def setup_config(db_url, options, file_config, follower_ident):
73
+ # load the dialect, which should also have it set up its provision
74
+ # hooks
75
+
76
+ dialect = sa_url.make_url(db_url).get_dialect()
77
+
78
+ dialect.load_provisioning()
79
+
80
+ if follower_ident:
81
+ db_url = follower_url_from_main(db_url, follower_ident)
82
+ db_opts = {}
83
+ update_db_opts(db_url, db_opts, options)
84
+ db_opts["scope"] = "global"
85
+ eng = engines.testing_engine(db_url, db_opts)
86
+ post_configure_engine(db_url, eng, follower_ident)
87
+ eng.connect().close()
88
+
89
+ cfg = config.Config.register(eng, db_opts, options, file_config)
90
+
91
+ # a symbolic name that tests can use if they need to disambiguate
92
+ # names across databases
93
+ if follower_ident:
94
+ config.ident = follower_ident
95
+
96
+ if follower_ident:
97
+ configure_follower(cfg, follower_ident)
98
+ return cfg
99
+
100
+
101
+ def drop_follower_db(follower_ident):
102
+ for cfg in _configs_for_db_operation():
103
+ log.info("DROP database %s, URI %r", follower_ident, cfg.db.url)
104
+ drop_db(cfg, cfg.db, follower_ident)
105
+
106
+
107
+ def generate_db_urls(db_urls, extra_drivers):
108
+ """Generate a set of URLs to test given configured URLs plus additional
109
+ driver names.
110
+
111
+ Given::
112
+
113
+ --dburi postgresql://db1 \
114
+ --dburi postgresql://db2 \
115
+ --dburi postgresql://db2 \
116
+ --dbdriver=psycopg2 --dbdriver=asyncpg?async_fallback=true
117
+
118
+ Noting that the default postgresql driver is psycopg2, the output
119
+ would be::
120
+
121
+ postgresql+psycopg2://db1
122
+ postgresql+asyncpg://db1
123
+ postgresql+psycopg2://db2
124
+ postgresql+psycopg2://db3
125
+
126
+ That is, for the driver in a --dburi, we want to keep that and use that
127
+ driver for each URL it's part of . For a driver that is only
128
+ in --dbdrivers, we want to use it just once for one of the URLs.
129
+ for a driver that is both coming from --dburi as well as --dbdrivers,
130
+ we want to keep it in that dburi.
131
+
132
+ Driver specific query options can be specified by added them to the
133
+ driver name. For example, to enable the async fallback option for
134
+ asyncpg::
135
+
136
+ --dburi postgresql://db1 \
137
+ --dbdriver=asyncpg?async_fallback=true
138
+
139
+ """
140
+ urls = set()
141
+
142
+ backend_to_driver_we_already_have = collections.defaultdict(set)
143
+
144
+ urls_plus_dialects = [
145
+ (url_obj, url_obj.get_dialect())
146
+ for url_obj in [sa_url.make_url(db_url) for db_url in db_urls]
147
+ ]
148
+
149
+ for url_obj, dialect in urls_plus_dialects:
150
+ # use get_driver_name instead of dialect.driver to account for
151
+ # "_async" virtual drivers like oracledb and psycopg
152
+ driver_name = url_obj.get_driver_name()
153
+ backend_to_driver_we_already_have[dialect.name].add(driver_name)
154
+
155
+ backend_to_driver_we_need = {}
156
+
157
+ for url_obj, dialect in urls_plus_dialects:
158
+ backend = dialect.name
159
+ dialect.load_provisioning()
160
+
161
+ if backend not in backend_to_driver_we_need:
162
+ backend_to_driver_we_need[backend] = extra_per_backend = set(
163
+ extra_drivers
164
+ ).difference(backend_to_driver_we_already_have[backend])
165
+ else:
166
+ extra_per_backend = backend_to_driver_we_need[backend]
167
+
168
+ for driver_url in _generate_driver_urls(url_obj, extra_per_backend):
169
+ if driver_url in urls:
170
+ continue
171
+ urls.add(driver_url)
172
+ yield driver_url
173
+
174
+
175
+ def _generate_driver_urls(url, extra_drivers):
176
+ main_driver = url.get_driver_name()
177
+ extra_drivers.discard(main_driver)
178
+
179
+ url = generate_driver_url(url, main_driver, "")
180
+ yield url
181
+
182
+ for drv in list(extra_drivers):
183
+ if "?" in drv:
184
+ driver_only, query_str = drv.split("?", 1)
185
+
186
+ else:
187
+ driver_only = drv
188
+ query_str = None
189
+
190
+ new_url = generate_driver_url(url, driver_only, query_str)
191
+ if new_url:
192
+ extra_drivers.remove(drv)
193
+
194
+ yield new_url
195
+
196
+
197
+ @register.init
198
+ def generate_driver_url(url, driver, query_str):
199
+ backend = url.get_backend_name()
200
+
201
+ new_url = url.set(
202
+ drivername="%s+%s" % (backend, driver),
203
+ )
204
+ if query_str:
205
+ new_url = new_url.update_query_string(query_str)
206
+
207
+ try:
208
+ new_url.get_dialect()
209
+ except exc.NoSuchModuleError:
210
+ return None
211
+ else:
212
+ return new_url
213
+
214
+
215
+ def _configs_for_db_operation():
216
+ hosts = set()
217
+
218
+ for cfg in config.Config.all_configs():
219
+ cfg.db.dispose()
220
+
221
+ for cfg in config.Config.all_configs():
222
+ url = cfg.db.url
223
+ backend = url.get_backend_name()
224
+ host_conf = (backend, url.username, url.host, url.database)
225
+
226
+ if host_conf not in hosts:
227
+ yield cfg
228
+ hosts.add(host_conf)
229
+
230
+ for cfg in config.Config.all_configs():
231
+ cfg.db.dispose()
232
+
233
+
234
+ @register.init
235
+ def drop_all_schema_objects_pre_tables(cfg, eng):
236
+ pass
237
+
238
+
239
+ @register.init
240
+ def drop_all_schema_objects_post_tables(cfg, eng):
241
+ pass
242
+
243
+
244
+ def drop_all_schema_objects(cfg, eng):
245
+ drop_all_schema_objects_pre_tables(cfg, eng)
246
+
247
+ drop_views(cfg, eng)
248
+
249
+ if config.requirements.materialized_views.enabled:
250
+ drop_materialized_views(cfg, eng)
251
+
252
+ inspector = inspect(eng)
253
+
254
+ consider_schemas = (None,)
255
+ if config.requirements.schemas.enabled_for_config(cfg):
256
+ consider_schemas += (cfg.test_schema, cfg.test_schema_2)
257
+ util.drop_all_tables(eng, inspector, consider_schemas=consider_schemas)
258
+
259
+ drop_all_schema_objects_post_tables(cfg, eng)
260
+
261
+ if config.requirements.sequences.enabled_for_config(cfg):
262
+ with eng.begin() as conn:
263
+ for seq in inspector.get_sequence_names():
264
+ conn.execute(ddl.DropSequence(schema.Sequence(seq)))
265
+ if config.requirements.schemas.enabled_for_config(cfg):
266
+ for schema_name in [cfg.test_schema, cfg.test_schema_2]:
267
+ for seq in inspector.get_sequence_names(
268
+ schema=schema_name
269
+ ):
270
+ conn.execute(
271
+ ddl.DropSequence(
272
+ schema.Sequence(seq, schema=schema_name)
273
+ )
274
+ )
275
+
276
+
277
+ def drop_views(cfg, eng):
278
+ inspector = inspect(eng)
279
+
280
+ try:
281
+ view_names = inspector.get_view_names()
282
+ except NotImplementedError:
283
+ pass
284
+ else:
285
+ with eng.begin() as conn:
286
+ for vname in view_names:
287
+ conn.execute(
288
+ ddl._DropView(schema.Table(vname, schema.MetaData()))
289
+ )
290
+
291
+ if config.requirements.schemas.enabled_for_config(cfg):
292
+ try:
293
+ view_names = inspector.get_view_names(schema=cfg.test_schema)
294
+ except NotImplementedError:
295
+ pass
296
+ else:
297
+ with eng.begin() as conn:
298
+ for vname in view_names:
299
+ conn.execute(
300
+ ddl._DropView(
301
+ schema.Table(
302
+ vname,
303
+ schema.MetaData(),
304
+ schema=cfg.test_schema,
305
+ )
306
+ )
307
+ )
308
+
309
+
310
+ def drop_materialized_views(cfg, eng):
311
+ inspector = inspect(eng)
312
+
313
+ mview_names = inspector.get_materialized_view_names()
314
+
315
+ with eng.begin() as conn:
316
+ for vname in mview_names:
317
+ conn.exec_driver_sql(f"DROP MATERIALIZED VIEW {vname}")
318
+
319
+ if config.requirements.schemas.enabled_for_config(cfg):
320
+ mview_names = inspector.get_materialized_view_names(
321
+ schema=cfg.test_schema
322
+ )
323
+ with eng.begin() as conn:
324
+ for vname in mview_names:
325
+ conn.exec_driver_sql(
326
+ f"DROP MATERIALIZED VIEW {cfg.test_schema}.{vname}"
327
+ )
328
+
329
+
330
+ @register.init
331
+ def create_db(cfg, eng, ident):
332
+ """Dynamically create a database for testing.
333
+
334
+ Used when a test run will employ multiple processes, e.g., when run
335
+ via `tox` or `pytest -n4`.
336
+ """
337
+ raise NotImplementedError(
338
+ "no DB creation routine for cfg: %s" % (eng.url,)
339
+ )
340
+
341
+
342
+ @register.init
343
+ def drop_db(cfg, eng, ident):
344
+ """Drop a database that we dynamically created for testing."""
345
+ raise NotImplementedError("no DB drop routine for cfg: %s" % (eng.url,))
346
+
347
+
348
+ def _adapt_update_db_opts(fn):
349
+ insp = util.inspect_getfullargspec(fn)
350
+ if len(insp.args) == 3:
351
+ return fn
352
+ else:
353
+ return lambda db_url, db_opts, _options: fn(db_url, db_opts)
354
+
355
+
356
+ @register.init_decorator(_adapt_update_db_opts)
357
+ def update_db_opts(db_url, db_opts, options):
358
+ """Set database options (db_opts) for a test database that we created."""
359
+
360
+
361
+ @register.init
362
+ def post_configure_engine(url, engine, follower_ident):
363
+ """Perform extra steps after configuring an engine for testing.
364
+
365
+ (For the internal dialects, currently only used by sqlite, oracle, mssql)
366
+ """
367
+
368
+
369
+ @register.init
370
+ def follower_url_from_main(url, ident):
371
+ """Create a connection URL for a dynamically-created test database.
372
+
373
+ :param url: the connection URL specified when the test run was invoked
374
+ :param ident: the pytest-xdist "worker identifier" to be used as the
375
+ database name
376
+ """
377
+ url = sa_url.make_url(url)
378
+ return url.set(database=ident)
379
+
380
+
381
+ @register.init
382
+ def configure_follower(cfg, ident):
383
+ """Create dialect-specific config settings for a follower database."""
384
+ pass
385
+
386
+
387
+ @register.init
388
+ def run_reap_dbs(url, ident):
389
+ """Remove databases that were created during the test process, after the
390
+ process has ended.
391
+
392
+ This is an optional step that is invoked for certain backends that do not
393
+ reliably release locks on the database as long as a process is still in
394
+ use. For the internal dialects, this is currently only necessary for
395
+ mssql and oracle.
396
+ """
397
+
398
+
399
+ def reap_dbs(idents_file):
400
+ log.info("Reaping databases...")
401
+
402
+ urls = collections.defaultdict(set)
403
+ idents = collections.defaultdict(set)
404
+ dialects = {}
405
+
406
+ with open(idents_file) as file_:
407
+ for line in file_:
408
+ line = line.strip()
409
+ db_name, db_url = line.split(" ")
410
+ url_obj = sa_url.make_url(db_url)
411
+ if db_name not in dialects:
412
+ dialects[db_name] = url_obj.get_dialect()
413
+ dialects[db_name].load_provisioning()
414
+ url_key = (url_obj.get_backend_name(), url_obj.host)
415
+ urls[url_key].add(db_url)
416
+ idents[url_key].add(db_name)
417
+
418
+ for url_key in urls:
419
+ url = list(urls[url_key])[0]
420
+ ident = idents[url_key]
421
+ run_reap_dbs(url, ident)
422
+
423
+
424
+ @register.init
425
+ def temp_table_keyword_args(cfg, eng):
426
+ """Specify keyword arguments for creating a temporary Table.
427
+
428
+ Dialect-specific implementations of this method will return the
429
+ kwargs that are passed to the Table method when creating a temporary
430
+ table for testing, e.g., in the define_temp_tables method of the
431
+ ComponentReflectionTest class in suite/test_reflection.py
432
+ """
433
+ raise NotImplementedError(
434
+ "no temp table keyword args routine for cfg: %s" % (eng.url,)
435
+ )
436
+
437
+
438
+ @register.init
439
+ def prepare_for_drop_tables(config, connection):
440
+ pass
441
+
442
+
443
+ @register.init
444
+ def stop_test_class_outside_fixtures(config, db, testcls):
445
+ pass
446
+
447
+
448
+ @register.init
449
+ def get_temp_table_name(cfg, eng, base_name):
450
+ """Specify table name for creating a temporary Table.
451
+
452
+ Dialect-specific implementations of this method will return the
453
+ name to use when creating a temporary table for testing,
454
+ e.g., in the define_temp_tables method of the
455
+ ComponentReflectionTest class in suite/test_reflection.py
456
+
457
+ Default to just the base name since that's what most dialects will
458
+ use. The mssql dialect's implementation will need a "#" prepended.
459
+ """
460
+ return base_name
461
+
462
+
463
+ @register.init
464
+ def set_default_schema_on_connection(cfg, dbapi_connection, schema_name):
465
+ raise NotImplementedError(
466
+ "backend does not implement a schema name set function: %s"
467
+ % (cfg.db.url,)
468
+ )
469
+
470
+
471
+ @register.init
472
+ def upsert(
473
+ cfg, table, returning, *, set_lambda=None, sort_by_parameter_order=False
474
+ ):
475
+ """return the backends insert..on conflict / on dupe etc. construct.
476
+
477
+ while we should add a backend-neutral upsert construct as well, such as
478
+ insert().upsert(), it's important that we continue to test the
479
+ backend-specific insert() constructs since if we do implement
480
+ insert().upsert(), that would be using a different codepath for the things
481
+ we need to test like insertmanyvalues, etc.
482
+
483
+ """
484
+ raise NotImplementedError(
485
+ f"backend does not include an upsert implementation: {cfg.db.url}"
486
+ )
487
+
488
+
489
+ @register.init
490
+ def normalize_sequence(cfg, sequence):
491
+ """Normalize sequence parameters for dialect that don't start with 1
492
+ by default.
493
+
494
+ The default implementation does nothing
495
+ """
496
+ return sequence