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,828 @@
1
+ # testing/plugin/plugin_base.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
+
10
+ from __future__ import annotations
11
+
12
+ import abc
13
+ from argparse import Namespace
14
+ import configparser
15
+ import logging
16
+ import os
17
+ from pathlib import Path
18
+ import re
19
+ import sys
20
+ from typing import Any
21
+
22
+ from sqlalchemy.testing import asyncio
23
+
24
+ """Testing extensions.
25
+
26
+ this module is designed to work as a testing-framework-agnostic library,
27
+ created so that multiple test frameworks can be supported at once
28
+ (mostly so that we can migrate to new ones). The current target
29
+ is pytest.
30
+
31
+ """
32
+
33
+ # flag which indicates we are in the SQLAlchemy testing suite,
34
+ # and not that of Alembic or a third party dialect.
35
+ bootstrapped_as_sqlalchemy = False
36
+
37
+ log = logging.getLogger("sqlalchemy.testing.plugin_base")
38
+
39
+ # late imports
40
+ fixtures = None
41
+ engines = None
42
+ exclusions = None
43
+ warnings = None
44
+ profiling = None
45
+ provision = None
46
+ assertions = None
47
+ requirements = None
48
+ config = None
49
+ testing = None
50
+ util = None
51
+ file_config = None
52
+
53
+ logging = None
54
+ include_tags = set()
55
+ exclude_tags = set()
56
+ options: Namespace = None # type: ignore
57
+
58
+
59
+ def setup_options(make_option):
60
+ make_option(
61
+ "--log-info",
62
+ action="callback",
63
+ type=str,
64
+ callback=_log,
65
+ help="turn on info logging for <LOG> (multiple OK)",
66
+ )
67
+ make_option(
68
+ "--log-debug",
69
+ action="callback",
70
+ type=str,
71
+ callback=_log,
72
+ help="turn on debug logging for <LOG> (multiple OK)",
73
+ )
74
+ make_option(
75
+ "--db",
76
+ action="append",
77
+ type=str,
78
+ dest="db",
79
+ help="Use prefab database uri. Multiple OK, "
80
+ "first one is run by default.",
81
+ )
82
+ make_option(
83
+ "--dbs",
84
+ action="callback",
85
+ zeroarg_callback=_list_dbs,
86
+ help="List available prefab dbs",
87
+ )
88
+ make_option(
89
+ "--dburi",
90
+ action="append",
91
+ type=str,
92
+ dest="dburi",
93
+ help="Database uri. Multiple OK, first one is run by default.",
94
+ )
95
+ make_option(
96
+ "--dbdriver",
97
+ action="append",
98
+ type=str,
99
+ dest="dbdriver",
100
+ help="Additional database drivers to include in tests. "
101
+ "These are linked to the existing database URLs by the "
102
+ "provisioning system.",
103
+ )
104
+ make_option(
105
+ "--dropfirst",
106
+ action="store_true",
107
+ dest="dropfirst",
108
+ help="Drop all tables in the target database first",
109
+ )
110
+ make_option(
111
+ "--disable-asyncio",
112
+ action="store_true",
113
+ help="disable test / fixtures / provisioning running in asyncio",
114
+ )
115
+ make_option(
116
+ "--backend-only",
117
+ action="callback",
118
+ zeroarg_callback=_set_tag_include("backend"),
119
+ help=(
120
+ "Run only tests marked with __backend__ or __sparse_backend__; "
121
+ "this is now equivalent to the pytest -m backend mark expression"
122
+ ),
123
+ )
124
+ make_option(
125
+ "--nomemory",
126
+ action="callback",
127
+ zeroarg_callback=_set_tag_exclude("memory_intensive"),
128
+ help="Don't run memory profiling tests; "
129
+ "this is now equivalent to the pytest -m 'not memory_intensive' "
130
+ "mark expression",
131
+ )
132
+ make_option(
133
+ "--notimingintensive",
134
+ action="callback",
135
+ zeroarg_callback=_set_tag_exclude("timing_intensive"),
136
+ help="Don't run timing intensive tests; "
137
+ "this is now equivalent to the pytest -m 'not timing_intensive' "
138
+ "mark expression",
139
+ )
140
+ make_option(
141
+ "--nomypy",
142
+ action="callback",
143
+ zeroarg_callback=_set_tag_exclude("mypy"),
144
+ help="Don't run mypy typing tests; "
145
+ "this is now equivalent to the pytest -m 'not mypy' mark expression",
146
+ )
147
+ make_option(
148
+ "--profile-sort",
149
+ type=str,
150
+ default="cumulative",
151
+ dest="profilesort",
152
+ help="Type of sort for profiling standard output",
153
+ )
154
+ make_option(
155
+ "--profile-dump",
156
+ type=str,
157
+ dest="profiledump",
158
+ help="Filename where a single profile run will be dumped",
159
+ )
160
+ make_option(
161
+ "--low-connections",
162
+ action="store_true",
163
+ dest="low_connections",
164
+ help="Use a low number of distinct connections - "
165
+ "i.e. for Oracle TNS",
166
+ )
167
+ make_option(
168
+ "--write-idents",
169
+ type=str,
170
+ dest="write_idents",
171
+ help="write out generated follower idents to <file>, "
172
+ "when -n<num> is used",
173
+ )
174
+ make_option(
175
+ "--requirements",
176
+ action="callback",
177
+ type=str,
178
+ callback=_requirements_opt,
179
+ help="requirements class for testing, overrides setup.cfg",
180
+ )
181
+ make_option(
182
+ "--include-tag",
183
+ action="callback",
184
+ callback=_include_tag,
185
+ type=str,
186
+ help="Include tests with tag <tag>; "
187
+ "legacy, use pytest -m 'tag' instead",
188
+ )
189
+ make_option(
190
+ "--exclude-tag",
191
+ action="callback",
192
+ callback=_exclude_tag,
193
+ type=str,
194
+ help="Exclude tests with tag <tag>; "
195
+ "legacy, use pytest -m 'not tag' instead",
196
+ )
197
+ make_option(
198
+ "--write-profiles",
199
+ action="store_true",
200
+ dest="write_profiles",
201
+ default=False,
202
+ help="Write/update failing profiling data.",
203
+ )
204
+ make_option(
205
+ "--force-write-profiles",
206
+ action="store_true",
207
+ dest="force_write_profiles",
208
+ default=False,
209
+ help="Unconditionally write/update profiling data.",
210
+ )
211
+ make_option(
212
+ "--dump-pyannotate",
213
+ type=str,
214
+ dest="dump_pyannotate",
215
+ help="Run pyannotate and dump json info to given file",
216
+ )
217
+ make_option(
218
+ "--mypy-extra-test-path",
219
+ type=str,
220
+ action="append",
221
+ default=[],
222
+ dest="mypy_extra_test_paths",
223
+ help="Additional test directories to add to the mypy tests. "
224
+ "This is used only when running mypy tests. Multiple OK",
225
+ )
226
+ # db specific options
227
+ make_option(
228
+ "--postgresql-templatedb",
229
+ type=str,
230
+ help="name of template database to use for PostgreSQL "
231
+ "CREATE DATABASE (defaults to current database)",
232
+ )
233
+ make_option(
234
+ "--oracledb-thick-mode",
235
+ action="store_true",
236
+ help="enables the 'thick mode' when testing with oracle+oracledb",
237
+ )
238
+
239
+
240
+ def configure_follower(follower_ident):
241
+ """Configure required state for a follower.
242
+
243
+ This invokes in the parent process and typically includes
244
+ database creation.
245
+
246
+ """
247
+ from sqlalchemy.testing import provision
248
+
249
+ provision.FOLLOWER_IDENT = follower_ident
250
+
251
+
252
+ def memoize_important_follower_config(dict_):
253
+ """Store important configuration we will need to send to a follower.
254
+
255
+ This invokes in the parent process after normal config is set up.
256
+
257
+ Hook is currently not used.
258
+
259
+ """
260
+
261
+
262
+ def restore_important_follower_config(dict_):
263
+ """Restore important configuration needed by a follower.
264
+
265
+ This invokes in the follower process.
266
+
267
+ Hook is currently not used.
268
+
269
+ """
270
+
271
+
272
+ def read_config(root_path):
273
+ global file_config
274
+ file_config = configparser.ConfigParser()
275
+ file_config.read(
276
+ [str(root_path / "setup.cfg"), str(root_path / "test.cfg")]
277
+ )
278
+
279
+
280
+ def pre_begin(opt):
281
+ """things to set up early, before coverage might be setup."""
282
+ global options
283
+ options = opt
284
+ for fn in pre_configure:
285
+ fn(options, file_config)
286
+
287
+
288
+ def set_coverage_flag(value):
289
+ options.has_coverage = value
290
+
291
+
292
+ def post_begin():
293
+ """things to set up later, once we know coverage is running."""
294
+ # Lazy setup of other options (post coverage)
295
+ for fn in post_configure:
296
+ fn(options, file_config)
297
+
298
+ # late imports, has to happen after config.
299
+ global util, fixtures, engines, exclusions, assertions, provision
300
+ global warnings, profiling, config, testing
301
+ from sqlalchemy import testing # noqa
302
+ from sqlalchemy.testing import fixtures, engines, exclusions # noqa
303
+ from sqlalchemy.testing import assertions, warnings, profiling # noqa
304
+ from sqlalchemy.testing import config, provision # noqa
305
+ from sqlalchemy import util # noqa
306
+
307
+ warnings.setup_filters()
308
+
309
+
310
+ def _log(opt_str, value, parser):
311
+ global logging
312
+ if not logging:
313
+ import logging
314
+
315
+ logging.basicConfig()
316
+
317
+ if opt_str.endswith("-info"):
318
+ logging.getLogger(value).setLevel(logging.INFO)
319
+ elif opt_str.endswith("-debug"):
320
+ logging.getLogger(value).setLevel(logging.DEBUG)
321
+
322
+
323
+ def _list_dbs(*args):
324
+ if file_config is None:
325
+ # assume the current working directory is the one containing the
326
+ # setup file
327
+ read_config(Path.cwd())
328
+ print("Available --db options (use --dburi to override)")
329
+ for macro in sorted(file_config.options("db")):
330
+ print("%20s\t%s" % (macro, file_config.get("db", macro)))
331
+ sys.exit(0)
332
+
333
+
334
+ def _requirements_opt(opt_str, value, parser):
335
+ _setup_requirements(value)
336
+
337
+
338
+ def _set_tag_include(tag):
339
+ def _do_include_tag(opt_str, value, parser):
340
+ _include_tag(opt_str, tag, parser)
341
+
342
+ return _do_include_tag
343
+
344
+
345
+ def _set_tag_exclude(tag):
346
+ def _do_exclude_tag(opt_str, value, parser):
347
+ _exclude_tag(opt_str, tag, parser)
348
+
349
+ return _do_exclude_tag
350
+
351
+
352
+ def _exclude_tag(opt_str, value, parser):
353
+ exclude_tags.add(value.replace("-", "_"))
354
+
355
+
356
+ def _include_tag(opt_str, value, parser):
357
+ include_tags.add(value.replace("-", "_"))
358
+
359
+
360
+ pre_configure = []
361
+ post_configure = []
362
+
363
+
364
+ def pre(fn):
365
+ pre_configure.append(fn)
366
+ return fn
367
+
368
+
369
+ def post(fn):
370
+ post_configure.append(fn)
371
+ return fn
372
+
373
+
374
+ @pre
375
+ def _setup_options(opt, file_config):
376
+ global options
377
+ options = opt
378
+
379
+
380
+ @pre
381
+ def _register_sqlite_numeric_dialect(opt, file_config):
382
+ from sqlalchemy.dialects import registry
383
+
384
+ registry.register(
385
+ "sqlite.pysqlite_numeric",
386
+ "sqlalchemy.dialects.sqlite.pysqlite",
387
+ "_SQLiteDialect_pysqlite_numeric",
388
+ )
389
+ registry.register(
390
+ "sqlite.pysqlite_dollar",
391
+ "sqlalchemy.dialects.sqlite.pysqlite",
392
+ "_SQLiteDialect_pysqlite_dollar",
393
+ )
394
+
395
+
396
+ @post
397
+ def __ensure_cext(opt, file_config):
398
+ if os.environ.get("REQUIRE_SQLALCHEMY_CEXT", "0") == "1":
399
+ from sqlalchemy.util import has_compiled_ext
400
+
401
+ try:
402
+ has_compiled_ext(raise_=True)
403
+ except ImportError as err:
404
+ raise AssertionError(
405
+ "REQUIRE_SQLALCHEMY_CEXT is set but can't import the "
406
+ "cython extensions"
407
+ ) from err
408
+
409
+
410
+ @post
411
+ def _init_symbols(options, file_config):
412
+ from sqlalchemy.testing import config
413
+
414
+ config._fixture_functions = _fixture_fn_class()
415
+
416
+
417
+ @pre
418
+ def _set_disable_asyncio(opt, file_config):
419
+ if opt.disable_asyncio:
420
+ asyncio.ENABLE_ASYNCIO = False
421
+
422
+
423
+ @post
424
+ def _engine_uri(options, file_config):
425
+ from sqlalchemy import testing
426
+ from sqlalchemy.testing import config
427
+ from sqlalchemy.testing import provision
428
+ from sqlalchemy.engine import url as sa_url
429
+
430
+ if options.dburi:
431
+ db_urls = list(options.dburi)
432
+ else:
433
+ db_urls = []
434
+
435
+ extra_drivers = options.dbdriver or []
436
+
437
+ if options.db:
438
+ for db_token in options.db:
439
+ for db in re.split(r"[,\s]+", db_token):
440
+ if db not in file_config.options("db"):
441
+ raise RuntimeError(
442
+ "Unknown URI specifier '%s'. "
443
+ "Specify --dbs for known uris." % db
444
+ )
445
+ else:
446
+ db_urls.append(file_config.get("db", db))
447
+
448
+ if not db_urls:
449
+ db_urls.append(file_config.get("db", "default"))
450
+
451
+ config._current = None
452
+
453
+ if options.write_idents and provision.FOLLOWER_IDENT:
454
+ for db_url in [sa_url.make_url(db_url) for db_url in db_urls]:
455
+ with open(options.write_idents, "a") as file_:
456
+ file_.write(
457
+ f"{provision.FOLLOWER_IDENT} "
458
+ f"{db_url.render_as_string(hide_password=False)}\n"
459
+ )
460
+
461
+ expanded_urls = list(provision.generate_db_urls(db_urls, extra_drivers))
462
+
463
+ for db_url in expanded_urls:
464
+ log.info("Adding database URL: %s", db_url)
465
+
466
+ cfg = provision.setup_config(
467
+ db_url, options, file_config, provision.FOLLOWER_IDENT
468
+ )
469
+ if not config._current:
470
+ cfg.set_as_current(cfg, testing)
471
+
472
+
473
+ @post
474
+ def _requirements(options, file_config):
475
+ requirement_cls = file_config.get("sqla_testing", "requirement_cls")
476
+ _setup_requirements(requirement_cls)
477
+
478
+
479
+ def _setup_requirements(argument):
480
+ from sqlalchemy.testing import config
481
+ from sqlalchemy import testing
482
+
483
+ modname, clsname = argument.split(":")
484
+
485
+ # importlib.import_module() only introduced in 2.7, a little
486
+ # late
487
+ mod = __import__(modname)
488
+ for component in modname.split(".")[1:]:
489
+ mod = getattr(mod, component)
490
+ req_cls = getattr(mod, clsname)
491
+
492
+ config.requirements = testing.requires = req_cls()
493
+
494
+ config.bootstrapped_as_sqlalchemy = bootstrapped_as_sqlalchemy
495
+
496
+
497
+ @post
498
+ def _prep_testing_database(options, file_config):
499
+ from sqlalchemy.testing import config
500
+
501
+ if options.dropfirst:
502
+ from sqlalchemy.testing import provision
503
+
504
+ for cfg in config.Config.all_configs():
505
+ provision.drop_all_schema_objects(cfg, cfg.db)
506
+
507
+
508
+ @post
509
+ def _post_setup_options(opt, file_config):
510
+ from sqlalchemy.testing import config
511
+
512
+ config.options = options
513
+ config.file_config = file_config
514
+
515
+
516
+ @post
517
+ def _setup_profiling(options, file_config):
518
+ from sqlalchemy.testing import profiling
519
+
520
+ profiling._profile_stats = profiling.ProfileStatsFile(
521
+ file_config.get("sqla_testing", "profile_file"),
522
+ sort=options.profilesort,
523
+ dump=options.profiledump,
524
+ )
525
+
526
+
527
+ def want_class(name, cls):
528
+ if not issubclass(cls, fixtures.TestBase):
529
+ return False
530
+ elif name.startswith("_"):
531
+ return False
532
+ else:
533
+ return True
534
+
535
+
536
+ def want_method(cls, fn):
537
+ if not fn.__name__.startswith("test_"):
538
+ return False
539
+ elif fn.__module__ is None:
540
+ return False
541
+ else:
542
+ return True
543
+
544
+
545
+ def generate_sub_tests(cls, module, markers):
546
+ if (
547
+ "backend" in markers
548
+ or "sparse_backend" in markers
549
+ or "sparse_driver_backend" in markers
550
+ ):
551
+ sparse = "sparse_backend" in markers
552
+ sparse_driver = "sparse_driver_backend" in markers
553
+ for cfg in _possible_configs_for_cls(
554
+ cls, sparse=sparse, sparse_driver=sparse_driver
555
+ ):
556
+ orig_name = cls.__name__
557
+
558
+ # we can have special chars in these names except for the
559
+ # pytest junit plugin, which is tripped up by the brackets
560
+ # and periods, so sanitize
561
+
562
+ alpha_name = re.sub(r"[_\[\]\.]+", "_", cfg.name)
563
+ alpha_name = re.sub(r"_+$", "", alpha_name)
564
+ name = "%s_%s" % (cls.__name__, alpha_name)
565
+ subcls = type(
566
+ name,
567
+ (cls,),
568
+ {"_sa_orig_cls_name": orig_name, "__only_on_config__": cfg},
569
+ )
570
+ setattr(module, name, subcls)
571
+ yield subcls
572
+ else:
573
+ yield cls
574
+
575
+
576
+ def start_test_class_outside_fixtures(cls):
577
+ _do_skips(cls)
578
+ _setup_engine(cls)
579
+
580
+
581
+ def stop_test_class(cls):
582
+ # close sessions, immediate connections, etc.
583
+ fixtures.stop_test_class_inside_fixtures(cls)
584
+
585
+ # close outstanding connection pool connections, dispose of
586
+ # additional engines
587
+ engines.testing_reaper.stop_test_class_inside_fixtures()
588
+
589
+
590
+ def stop_test_class_outside_fixtures(cls):
591
+ provision.stop_test_class_outside_fixtures(config, config.db, cls)
592
+ engines.testing_reaper.stop_test_class_outside_fixtures()
593
+ try:
594
+ if not options.low_connections:
595
+ assertions.global_cleanup_assertions()
596
+ finally:
597
+ _restore_engine()
598
+
599
+
600
+ def _restore_engine():
601
+ if config._current:
602
+ config._current.reset(testing)
603
+
604
+
605
+ def final_process_cleanup():
606
+ engines.testing_reaper.final_cleanup()
607
+ assertions.global_cleanup_assertions()
608
+ _restore_engine()
609
+
610
+
611
+ def _setup_engine(cls):
612
+ if getattr(cls, "__engine_options__", None):
613
+ opts = dict(cls.__engine_options__)
614
+ opts["scope"] = "class"
615
+ eng = engines.testing_engine(options=opts)
616
+ config._current.push_engine(eng, testing)
617
+
618
+
619
+ def before_test(test, test_module_name, test_class, test_name):
620
+ # format looks like:
621
+ # "test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause"
622
+
623
+ name = getattr(test_class, "_sa_orig_cls_name", test_class.__name__)
624
+
625
+ id_ = "%s.%s.%s" % (test_module_name, name, test_name)
626
+
627
+ profiling._start_current_test(id_)
628
+
629
+
630
+ def after_test(test):
631
+ fixtures.after_test()
632
+ engines.testing_reaper.after_test()
633
+
634
+
635
+ def after_test_fixtures(test):
636
+ engines.testing_reaper.after_test_outside_fixtures(test)
637
+
638
+
639
+ def _possible_configs_for_cls(
640
+ cls, reasons=None, sparse=False, sparse_driver=False
641
+ ):
642
+ all_configs = set(config.Config.all_configs())
643
+
644
+ if cls.__unsupported_on__:
645
+ spec = exclusions.db_spec(*cls.__unsupported_on__)
646
+ for config_obj in list(all_configs):
647
+ if spec(config_obj):
648
+ all_configs.remove(config_obj)
649
+
650
+ if getattr(cls, "__only_on__", None):
651
+ spec = exclusions.db_spec(*util.to_list(cls.__only_on__))
652
+ for config_obj in list(all_configs):
653
+ if not spec(config_obj):
654
+ all_configs.remove(config_obj)
655
+
656
+ if getattr(cls, "__only_on_config__", None):
657
+ all_configs.intersection_update([cls.__only_on_config__])
658
+
659
+ if hasattr(cls, "__requires__"):
660
+ requirements = config.requirements
661
+ for config_obj in list(all_configs):
662
+ for requirement in cls.__requires__:
663
+ check = getattr(requirements, requirement)
664
+
665
+ skip_reasons = check.matching_config_reasons(config_obj)
666
+ if skip_reasons:
667
+ all_configs.remove(config_obj)
668
+ if reasons is not None:
669
+ reasons.extend(skip_reasons)
670
+ break
671
+
672
+ warnings = check.matching_warnings(config_obj)
673
+ if warnings:
674
+ cls.__warnings__ = getattr(
675
+ cls, "__warnings__", ()
676
+ ) + tuple(warnings)
677
+
678
+ if hasattr(cls, "__prefer_requires__"):
679
+ non_preferred = set()
680
+ requirements = config.requirements
681
+ for config_obj in list(all_configs):
682
+ for requirement in cls.__prefer_requires__:
683
+ check = getattr(requirements, requirement)
684
+
685
+ if not check.enabled_for_config(config_obj):
686
+ non_preferred.add(config_obj)
687
+ if all_configs.difference(non_preferred):
688
+ all_configs.difference_update(non_preferred)
689
+
690
+ if sparse:
691
+ # pick only one config from each base dialect
692
+ # sorted so we get the same backend each time selecting the highest
693
+ # server version info.
694
+ per_dialect = {}
695
+
696
+ sorted_all_configs = reversed(
697
+ sorted(
698
+ all_configs,
699
+ key=lambda cfg: (
700
+ "z" if cfg.is_default_dialect else "a",
701
+ cfg.db.name,
702
+ cfg.db.driver,
703
+ cfg.db.dialect.server_version_info,
704
+ cfg.db.dialect.is_async,
705
+ ),
706
+ )
707
+ )
708
+
709
+ for cfg in sorted_all_configs:
710
+ db = cfg.db.name
711
+ if db not in per_dialect:
712
+ per_dialect[db] = cfg
713
+ return per_dialect.values()
714
+ elif sparse_driver:
715
+ # a more liberal form of "sparse" that will select for one driver,
716
+ # but still return for multiple database servers
717
+
718
+ dbs = {}
719
+
720
+ sorted_all_configs = list(
721
+ reversed(
722
+ sorted(
723
+ all_configs,
724
+ key=lambda cfg: (
725
+ cfg.db.name,
726
+ cfg.db.driver,
727
+ cfg.db.dialect.server_version_info,
728
+ cfg.db.dialect.is_async,
729
+ ),
730
+ )
731
+ )
732
+ )
733
+
734
+ for cfg in sorted_all_configs:
735
+ key = (cfg.db.name, cfg.db.dialect.server_version_info)
736
+ if key in dbs and dbs[key].is_default_dialect:
737
+ continue
738
+ else:
739
+ dbs[key] = cfg
740
+
741
+ chosen_cfgs = set(dbs.values())
742
+ return [cfg for cfg in sorted_all_configs if cfg in chosen_cfgs]
743
+
744
+ return all_configs
745
+
746
+
747
+ def _do_skips(cls):
748
+ reasons = []
749
+ all_configs = _possible_configs_for_cls(cls, reasons)
750
+
751
+ if getattr(cls, "__skip_if__", False):
752
+ for c in getattr(cls, "__skip_if__"):
753
+ if c():
754
+ config.skip_test(
755
+ "'%s' skipped by %s" % (cls.__name__, c.__name__)
756
+ )
757
+
758
+ if not all_configs:
759
+ msg = "'%s.%s' unsupported on any DB implementation %s%s" % (
760
+ cls.__module__,
761
+ cls.__name__,
762
+ ", ".join(
763
+ "'%s(%s)+%s'"
764
+ % (
765
+ config_obj.db.name,
766
+ ".".join(
767
+ str(dig)
768
+ for dig in exclusions._server_version(config_obj.db)
769
+ ),
770
+ config_obj.db.driver,
771
+ )
772
+ for config_obj in config.Config.all_configs()
773
+ ),
774
+ ", ".join(reasons),
775
+ )
776
+ config.skip_test(msg)
777
+ elif hasattr(cls, "__prefer_backends__"):
778
+ non_preferred = set()
779
+ spec = exclusions.db_spec(*util.to_list(cls.__prefer_backends__))
780
+ for config_obj in all_configs:
781
+ if not spec(config_obj):
782
+ non_preferred.add(config_obj)
783
+ if all_configs.difference(non_preferred):
784
+ all_configs.difference_update(non_preferred)
785
+
786
+ if config._current not in all_configs:
787
+ _setup_config(all_configs.pop(), cls)
788
+
789
+
790
+ def _setup_config(config_obj, ctx):
791
+ config._current.push(config_obj, testing)
792
+
793
+
794
+ class FixtureFunctions(abc.ABC):
795
+ @abc.abstractmethod
796
+ def skip_test_exception(self, *arg, **kw):
797
+ raise NotImplementedError()
798
+
799
+ @abc.abstractmethod
800
+ def combinations(self, *args, **kw):
801
+ raise NotImplementedError()
802
+
803
+ @abc.abstractmethod
804
+ def param_ident(self, *args, **kw):
805
+ raise NotImplementedError()
806
+
807
+ @abc.abstractmethod
808
+ def fixture(self, *arg, **kw):
809
+ raise NotImplementedError()
810
+
811
+ def get_current_test_name(self):
812
+ raise NotImplementedError()
813
+
814
+ @abc.abstractmethod
815
+ def mark_base_test_class(self) -> Any:
816
+ raise NotImplementedError()
817
+
818
+ @abc.abstractproperty
819
+ def add_to_marker(self):
820
+ raise NotImplementedError()
821
+
822
+
823
+ _fixture_fn_class = None
824
+
825
+
826
+ def set_fixture_functions(fixture_fn_class):
827
+ global _fixture_fn_class
828
+ _fixture_fn_class = fixture_fn_class