requirements.py 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  1. # testing/requirements.py
  2. # Copyright (C) 2005-2022 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. """Global database feature support policy.
  8. Provides decorators to mark tests requiring specific feature support from the
  9. target database.
  10. External dialect test suites should subclass SuiteRequirements
  11. to provide specific inclusion/exclusions.
  12. """
  13. import platform
  14. import sys
  15. from . import exclusions
  16. from . import only_on
  17. from .. import util
  18. from ..pool import QueuePool
  19. class Requirements(object):
  20. pass
  21. class SuiteRequirements(Requirements):
  22. @property
  23. def create_table(self):
  24. """target platform can emit basic CreateTable DDL."""
  25. return exclusions.open()
  26. @property
  27. def drop_table(self):
  28. """target platform can emit basic DropTable DDL."""
  29. return exclusions.open()
  30. @property
  31. def table_ddl_if_exists(self):
  32. """target platform supports IF NOT EXISTS / IF EXISTS for tables."""
  33. return exclusions.closed()
  34. @property
  35. def index_ddl_if_exists(self):
  36. """target platform supports IF NOT EXISTS / IF EXISTS for indexes."""
  37. return exclusions.closed()
  38. @property
  39. def foreign_keys(self):
  40. """Target database must support foreign keys."""
  41. return exclusions.open()
  42. @property
  43. def table_value_constructor(self):
  44. """Database / dialect supports a query like::
  45. SELECT * FROM VALUES ( (c1, c2), (c1, c2), ...)
  46. AS some_table(col1, col2)
  47. SQLAlchemy generates this with the :func:`_sql.values` function.
  48. """
  49. return exclusions.closed()
  50. @property
  51. def standard_cursor_sql(self):
  52. """Target database passes SQL-92 style statements to cursor.execute()
  53. when a statement like select() or insert() is run.
  54. A very small portion of dialect-level tests will ensure that certain
  55. conditions are present in SQL strings, and these tests use very basic
  56. SQL that will work on any SQL-like platform in order to assert results.
  57. It's normally a given for any pep-249 DBAPI that a statement like
  58. "SELECT id, name FROM table WHERE some_table.id=5" will work.
  59. However, there are dialects that don't actually produce SQL Strings
  60. and instead may work with symbolic objects instead, or dialects that
  61. aren't working with SQL, so for those this requirement can be marked
  62. as excluded.
  63. """
  64. return exclusions.open()
  65. @property
  66. def on_update_cascade(self):
  67. """target database must support ON UPDATE..CASCADE behavior in
  68. foreign keys."""
  69. return exclusions.open()
  70. @property
  71. def non_updating_cascade(self):
  72. """target database must *not* support ON UPDATE..CASCADE behavior in
  73. foreign keys."""
  74. return exclusions.closed()
  75. @property
  76. def deferrable_fks(self):
  77. return exclusions.closed()
  78. @property
  79. def on_update_or_deferrable_fks(self):
  80. # TODO: exclusions should be composable,
  81. # somehow only_if([x, y]) isn't working here, negation/conjunctions
  82. # getting confused.
  83. return exclusions.only_if(
  84. lambda: self.on_update_cascade.enabled
  85. or self.deferrable_fks.enabled
  86. )
  87. @property
  88. def queue_pool(self):
  89. """target database is using QueuePool"""
  90. def go(config):
  91. return isinstance(config.db.pool, QueuePool)
  92. return exclusions.only_if(go)
  93. @property
  94. def self_referential_foreign_keys(self):
  95. """Target database must support self-referential foreign keys."""
  96. return exclusions.open()
  97. @property
  98. def foreign_key_ddl(self):
  99. """Target database must support the DDL phrases for FOREIGN KEY."""
  100. return exclusions.open()
  101. @property
  102. def named_constraints(self):
  103. """target database must support names for constraints."""
  104. return exclusions.open()
  105. @property
  106. def implicitly_named_constraints(self):
  107. """target database must apply names to unnamed constraints."""
  108. return exclusions.open()
  109. @property
  110. def subqueries(self):
  111. """Target database must support subqueries."""
  112. return exclusions.open()
  113. @property
  114. def offset(self):
  115. """target database can render OFFSET, or an equivalent, in a
  116. SELECT.
  117. """
  118. return exclusions.open()
  119. @property
  120. def bound_limit_offset(self):
  121. """target database can render LIMIT and/or OFFSET using a bound
  122. parameter
  123. """
  124. return exclusions.open()
  125. @property
  126. def sql_expression_limit_offset(self):
  127. """target database can render LIMIT and/or OFFSET with a complete
  128. SQL expression, such as one that uses the addition operator.
  129. parameter
  130. """
  131. return exclusions.open()
  132. @property
  133. def parens_in_union_contained_select_w_limit_offset(self):
  134. """Target database must support parenthesized SELECT in UNION
  135. when LIMIT/OFFSET is specifically present.
  136. E.g. (SELECT ...) UNION (SELECT ..)
  137. This is known to fail on SQLite.
  138. """
  139. return exclusions.open()
  140. @property
  141. def parens_in_union_contained_select_wo_limit_offset(self):
  142. """Target database must support parenthesized SELECT in UNION
  143. when OFFSET/LIMIT is specifically not present.
  144. E.g. (SELECT ... LIMIT ..) UNION (SELECT .. OFFSET ..)
  145. This is known to fail on SQLite. It also fails on Oracle
  146. because without LIMIT/OFFSET, there is currently no step that
  147. creates an additional subquery.
  148. """
  149. return exclusions.open()
  150. @property
  151. def boolean_col_expressions(self):
  152. """Target database must support boolean expressions as columns"""
  153. return exclusions.closed()
  154. @property
  155. def nullable_booleans(self):
  156. """Target database allows boolean columns to store NULL."""
  157. return exclusions.open()
  158. @property
  159. def nullsordering(self):
  160. """Target backends that support nulls ordering."""
  161. return exclusions.closed()
  162. @property
  163. def standalone_binds(self):
  164. """target database/driver supports bound parameters as column expressions
  165. without being in the context of a typed column.
  166. """
  167. return exclusions.closed()
  168. @property
  169. def standalone_null_binds_whereclause(self):
  170. """target database/driver supports bound parameters with NULL in the
  171. WHERE clause, in situations where it has to be typed.
  172. """
  173. return exclusions.open()
  174. @property
  175. def intersect(self):
  176. """Target database must support INTERSECT or equivalent."""
  177. return exclusions.closed()
  178. @property
  179. def except_(self):
  180. """Target database must support EXCEPT or equivalent (i.e. MINUS)."""
  181. return exclusions.closed()
  182. @property
  183. def window_functions(self):
  184. """Target database must support window functions."""
  185. return exclusions.closed()
  186. @property
  187. def ctes(self):
  188. """Target database supports CTEs"""
  189. return exclusions.closed()
  190. @property
  191. def ctes_with_update_delete(self):
  192. """target database supports CTES that ride on top of a normal UPDATE
  193. or DELETE statement which refers to the CTE in a correlated subquery.
  194. """
  195. return exclusions.closed()
  196. @property
  197. def ctes_on_dml(self):
  198. """target database supports CTES which consist of INSERT, UPDATE
  199. or DELETE *within* the CTE, e.g. WITH x AS (UPDATE....)"""
  200. return exclusions.closed()
  201. @property
  202. def autoincrement_insert(self):
  203. """target platform generates new surrogate integer primary key values
  204. when insert() is executed, excluding the pk column."""
  205. return exclusions.open()
  206. @property
  207. def fetch_rows_post_commit(self):
  208. """target platform will allow cursor.fetchone() to proceed after a
  209. COMMIT.
  210. Typically this refers to an INSERT statement with RETURNING which
  211. is invoked within "autocommit". If the row can be returned
  212. after the autocommit, then this rule can be open.
  213. """
  214. return exclusions.open()
  215. @property
  216. def group_by_complex_expression(self):
  217. """target platform supports SQL expressions in GROUP BY
  218. e.g.
  219. SELECT x + y AS somelabel FROM table GROUP BY x + y
  220. """
  221. return exclusions.open()
  222. @property
  223. def sane_rowcount(self):
  224. return exclusions.skip_if(
  225. lambda config: not config.db.dialect.supports_sane_rowcount,
  226. "driver doesn't support 'sane' rowcount",
  227. )
  228. @property
  229. def sane_multi_rowcount(self):
  230. return exclusions.fails_if(
  231. lambda config: not config.db.dialect.supports_sane_multi_rowcount,
  232. "driver %(driver)s %(doesnt_support)s 'sane' multi row count",
  233. )
  234. @property
  235. def sane_rowcount_w_returning(self):
  236. return exclusions.fails_if(
  237. lambda config: not (
  238. config.db.dialect.supports_sane_rowcount_returning
  239. ),
  240. "driver doesn't support 'sane' rowcount when returning is on",
  241. )
  242. @property
  243. def empty_inserts(self):
  244. """target platform supports INSERT with no values, i.e.
  245. INSERT DEFAULT VALUES or equivalent."""
  246. return exclusions.only_if(
  247. lambda config: config.db.dialect.supports_empty_insert
  248. or config.db.dialect.supports_default_values
  249. or config.db.dialect.supports_default_metavalue,
  250. "empty inserts not supported",
  251. )
  252. @property
  253. def empty_inserts_executemany(self):
  254. """target platform supports INSERT with no values, i.e.
  255. INSERT DEFAULT VALUES or equivalent, within executemany()"""
  256. return self.empty_inserts
  257. @property
  258. def insert_from_select(self):
  259. """target platform supports INSERT from a SELECT."""
  260. return exclusions.open()
  261. @property
  262. def full_returning(self):
  263. """target platform supports RETURNING completely, including
  264. multiple rows returned.
  265. """
  266. return exclusions.only_if(
  267. lambda config: config.db.dialect.full_returning,
  268. "%(database)s %(does_support)s 'RETURNING of multiple rows'",
  269. )
  270. @property
  271. def insert_executemany_returning(self):
  272. """target platform supports RETURNING when INSERT is used with
  273. executemany(), e.g. multiple parameter sets, indicating
  274. as many rows come back as do parameter sets were passed.
  275. """
  276. return exclusions.only_if(
  277. lambda config: config.db.dialect.insert_executemany_returning,
  278. "%(database)s %(does_support)s 'RETURNING of "
  279. "multiple rows with INSERT executemany'",
  280. )
  281. @property
  282. def returning(self):
  283. """target platform supports RETURNING for at least one row.
  284. .. seealso::
  285. :attr:`.Requirements.full_returning`
  286. """
  287. return exclusions.only_if(
  288. lambda config: config.db.dialect.implicit_returning,
  289. "%(database)s %(does_support)s 'RETURNING of a single row'",
  290. )
  291. @property
  292. def tuple_in(self):
  293. """Target platform supports the syntax
  294. "(x, y) IN ((x1, y1), (x2, y2), ...)"
  295. """
  296. return exclusions.closed()
  297. @property
  298. def tuple_in_w_empty(self):
  299. """Target platform tuple IN w/ empty set"""
  300. return self.tuple_in
  301. @property
  302. def duplicate_names_in_cursor_description(self):
  303. """target platform supports a SELECT statement that has
  304. the same name repeated more than once in the columns list."""
  305. return exclusions.open()
  306. @property
  307. def denormalized_names(self):
  308. """Target database must have 'denormalized', i.e.
  309. UPPERCASE as case insensitive names."""
  310. return exclusions.skip_if(
  311. lambda config: not config.db.dialect.requires_name_normalize,
  312. "Backend does not require denormalized names.",
  313. )
  314. @property
  315. def multivalues_inserts(self):
  316. """target database must support multiple VALUES clauses in an
  317. INSERT statement."""
  318. return exclusions.skip_if(
  319. lambda config: not config.db.dialect.supports_multivalues_insert,
  320. "Backend does not support multirow inserts.",
  321. )
  322. @property
  323. def implements_get_lastrowid(self):
  324. """target dialect implements the executioncontext.get_lastrowid()
  325. method without reliance on RETURNING.
  326. """
  327. return exclusions.open()
  328. @property
  329. def emulated_lastrowid(self):
  330. """target dialect retrieves cursor.lastrowid, or fetches
  331. from a database-side function after an insert() construct executes,
  332. within the get_lastrowid() method.
  333. Only dialects that "pre-execute", or need RETURNING to get last
  334. inserted id, would return closed/fail/skip for this.
  335. """
  336. return exclusions.closed()
  337. @property
  338. def emulated_lastrowid_even_with_sequences(self):
  339. """target dialect retrieves cursor.lastrowid or an equivalent
  340. after an insert() construct executes, even if the table has a
  341. Sequence on it.
  342. """
  343. return exclusions.closed()
  344. @property
  345. def dbapi_lastrowid(self):
  346. """target platform includes a 'lastrowid' accessor on the DBAPI
  347. cursor object.
  348. """
  349. return exclusions.closed()
  350. @property
  351. def views(self):
  352. """Target database must support VIEWs."""
  353. return exclusions.closed()
  354. @property
  355. def schemas(self):
  356. """Target database must support external schemas, and have one
  357. named 'test_schema'."""
  358. return only_on(lambda config: config.db.dialect.supports_schemas)
  359. @property
  360. def cross_schema_fk_reflection(self):
  361. """target system must support reflection of inter-schema
  362. foreign keys"""
  363. return exclusions.closed()
  364. @property
  365. def foreign_key_constraint_name_reflection(self):
  366. """Target supports refleciton of FOREIGN KEY constraints and
  367. will return the name of the constraint that was used in the
  368. "CONSTRAINT <name> FOREIGN KEY" DDL.
  369. MySQL prior to version 8 and MariaDB prior to version 10.5
  370. don't support this.
  371. """
  372. return exclusions.closed()
  373. @property
  374. def implicit_default_schema(self):
  375. """target system has a strong concept of 'default' schema that can
  376. be referred to implicitly.
  377. basically, PostgreSQL.
  378. """
  379. return exclusions.closed()
  380. @property
  381. def default_schema_name_switch(self):
  382. """target dialect implements provisioning module including
  383. set_default_schema_on_connection"""
  384. return exclusions.closed()
  385. @property
  386. def server_side_cursors(self):
  387. """Target dialect must support server side cursors."""
  388. return exclusions.only_if(
  389. [lambda config: config.db.dialect.supports_server_side_cursors],
  390. "no server side cursors support",
  391. )
  392. @property
  393. def sequences(self):
  394. """Target database must support SEQUENCEs."""
  395. return exclusions.only_if(
  396. [lambda config: config.db.dialect.supports_sequences],
  397. "no sequence support",
  398. )
  399. @property
  400. def no_sequences(self):
  401. """the opposite of "sequences", DB does not support sequences at
  402. all."""
  403. return exclusions.NotPredicate(self.sequences)
  404. @property
  405. def sequences_optional(self):
  406. """Target database supports sequences, but also optionally
  407. as a means of generating new PK values."""
  408. return exclusions.only_if(
  409. [
  410. lambda config: config.db.dialect.supports_sequences
  411. and config.db.dialect.sequences_optional
  412. ],
  413. "no sequence support, or sequences not optional",
  414. )
  415. @property
  416. def supports_lastrowid(self):
  417. """target database / driver supports cursor.lastrowid as a means
  418. of retrieving the last inserted primary key value.
  419. note that if the target DB supports sequences also, this is still
  420. assumed to work. This is a new use case brought on by MariaDB 10.3.
  421. """
  422. return exclusions.only_if(
  423. [lambda config: config.db.dialect.postfetch_lastrowid]
  424. )
  425. @property
  426. def no_lastrowid_support(self):
  427. """the opposite of supports_lastrowid"""
  428. return exclusions.only_if(
  429. [lambda config: not config.db.dialect.postfetch_lastrowid]
  430. )
  431. @property
  432. def reflects_pk_names(self):
  433. return exclusions.closed()
  434. @property
  435. def table_reflection(self):
  436. """target database has general support for table reflection"""
  437. return exclusions.open()
  438. @property
  439. def reflect_tables_no_columns(self):
  440. """target database supports creation and reflection of tables with no
  441. columns, or at least tables that seem to have no columns."""
  442. return exclusions.closed()
  443. @property
  444. def comment_reflection(self):
  445. return exclusions.closed()
  446. @property
  447. def view_column_reflection(self):
  448. """target database must support retrieval of the columns in a view,
  449. similarly to how a table is inspected.
  450. This does not include the full CREATE VIEW definition.
  451. """
  452. return self.views
  453. @property
  454. def view_reflection(self):
  455. """target database must support inspection of the full CREATE VIEW
  456. definition."""
  457. return self.views
  458. @property
  459. def schema_reflection(self):
  460. return self.schemas
  461. @property
  462. def primary_key_constraint_reflection(self):
  463. return exclusions.open()
  464. @property
  465. def foreign_key_constraint_reflection(self):
  466. return exclusions.open()
  467. @property
  468. def foreign_key_constraint_option_reflection_ondelete(self):
  469. return exclusions.closed()
  470. @property
  471. def fk_constraint_option_reflection_ondelete_restrict(self):
  472. return exclusions.closed()
  473. @property
  474. def fk_constraint_option_reflection_ondelete_noaction(self):
  475. return exclusions.closed()
  476. @property
  477. def foreign_key_constraint_option_reflection_onupdate(self):
  478. return exclusions.closed()
  479. @property
  480. def fk_constraint_option_reflection_onupdate_restrict(self):
  481. return exclusions.closed()
  482. @property
  483. def temp_table_reflection(self):
  484. return exclusions.open()
  485. @property
  486. def temp_table_reflect_indexes(self):
  487. return self.temp_table_reflection
  488. @property
  489. def temp_table_names(self):
  490. """target dialect supports listing of temporary table names"""
  491. return exclusions.closed()
  492. @property
  493. def temporary_tables(self):
  494. """target database supports temporary tables"""
  495. return exclusions.open()
  496. @property
  497. def temporary_views(self):
  498. """target database supports temporary views"""
  499. return exclusions.closed()
  500. @property
  501. def index_reflection(self):
  502. return exclusions.open()
  503. @property
  504. def index_reflects_included_columns(self):
  505. return exclusions.closed()
  506. @property
  507. def indexes_with_ascdesc(self):
  508. """target database supports CREATE INDEX with per-column ASC/DESC."""
  509. return exclusions.open()
  510. @property
  511. def indexes_with_expressions(self):
  512. """target database supports CREATE INDEX against SQL expressions."""
  513. return exclusions.closed()
  514. @property
  515. def unique_constraint_reflection(self):
  516. """target dialect supports reflection of unique constraints"""
  517. return exclusions.open()
  518. @property
  519. def check_constraint_reflection(self):
  520. """target dialect supports reflection of check constraints"""
  521. return exclusions.closed()
  522. @property
  523. def duplicate_key_raises_integrity_error(self):
  524. """target dialect raises IntegrityError when reporting an INSERT
  525. with a primary key violation. (hint: it should)
  526. """
  527. return exclusions.open()
  528. @property
  529. def unbounded_varchar(self):
  530. """Target database must support VARCHAR with no length"""
  531. return exclusions.open()
  532. @property
  533. def unicode_data(self):
  534. """Target database/dialect must support Python unicode objects with
  535. non-ASCII characters represented, delivered as bound parameters
  536. as well as in result rows.
  537. """
  538. return exclusions.open()
  539. @property
  540. def unicode_ddl(self):
  541. """Target driver must support some degree of non-ascii symbol
  542. names.
  543. """
  544. return exclusions.closed()
  545. @property
  546. def symbol_names_w_double_quote(self):
  547. """Target driver can create tables with a name like 'some " table'"""
  548. return exclusions.open()
  549. @property
  550. def datetime_literals(self):
  551. """target dialect supports rendering of a date, time, or datetime as a
  552. literal string, e.g. via the TypeEngine.literal_processor() method.
  553. """
  554. return exclusions.closed()
  555. @property
  556. def datetime(self):
  557. """target dialect supports representation of Python
  558. datetime.datetime() objects."""
  559. return exclusions.open()
  560. @property
  561. def datetime_timezone(self):
  562. """target dialect supports representation of Python
  563. datetime.datetime() with tzinfo with DateTime(timezone=True)."""
  564. return exclusions.closed()
  565. @property
  566. def time_timezone(self):
  567. """target dialect supports representation of Python
  568. datetime.time() with tzinfo with Time(timezone=True)."""
  569. return exclusions.closed()
  570. @property
  571. def datetime_implicit_bound(self):
  572. """target dialect when given a datetime object will bind it such
  573. that the database server knows the object is a datetime, and not
  574. a plain string.
  575. """
  576. return exclusions.open()
  577. @property
  578. def datetime_microseconds(self):
  579. """target dialect supports representation of Python
  580. datetime.datetime() with microsecond objects."""
  581. return exclusions.open()
  582. @property
  583. def timestamp_microseconds(self):
  584. """target dialect supports representation of Python
  585. datetime.datetime() with microsecond objects but only
  586. if TIMESTAMP is used."""
  587. return exclusions.closed()
  588. @property
  589. def timestamp_microseconds_implicit_bound(self):
  590. """target dialect when given a datetime object which also includes
  591. a microseconds portion when using the TIMESTAMP data type
  592. will bind it such that the database server knows
  593. the object is a datetime with microseconds, and not a plain string.
  594. """
  595. return self.timestamp_microseconds
  596. @property
  597. def datetime_historic(self):
  598. """target dialect supports representation of Python
  599. datetime.datetime() objects with historic (pre 1970) values."""
  600. return exclusions.closed()
  601. @property
  602. def date(self):
  603. """target dialect supports representation of Python
  604. datetime.date() objects."""
  605. return exclusions.open()
  606. @property
  607. def date_coerces_from_datetime(self):
  608. """target dialect accepts a datetime object as the target
  609. of a date column."""
  610. return exclusions.open()
  611. @property
  612. def date_historic(self):
  613. """target dialect supports representation of Python
  614. datetime.datetime() objects with historic (pre 1970) values."""
  615. return exclusions.closed()
  616. @property
  617. def time(self):
  618. """target dialect supports representation of Python
  619. datetime.time() objects."""
  620. return exclusions.open()
  621. @property
  622. def time_microseconds(self):
  623. """target dialect supports representation of Python
  624. datetime.time() with microsecond objects."""
  625. return exclusions.open()
  626. @property
  627. def binary_comparisons(self):
  628. """target database/driver can allow BLOB/BINARY fields to be compared
  629. against a bound parameter value.
  630. """
  631. return exclusions.open()
  632. @property
  633. def binary_literals(self):
  634. """target backend supports simple binary literals, e.g. an
  635. expression like::
  636. SELECT CAST('foo' AS BINARY)
  637. Where ``BINARY`` is the type emitted from :class:`.LargeBinary`,
  638. e.g. it could be ``BLOB`` or similar.
  639. Basically fails on Oracle.
  640. """
  641. return exclusions.open()
  642. @property
  643. def autocommit(self):
  644. """target dialect supports 'AUTOCOMMIT' as an isolation_level"""
  645. return exclusions.closed()
  646. @property
  647. def isolation_level(self):
  648. """target dialect supports general isolation level settings.
  649. Note that this requirement, when enabled, also requires that
  650. the get_isolation_levels() method be implemented.
  651. """
  652. return exclusions.closed()
  653. def get_isolation_levels(self, config):
  654. """Return a structure of supported isolation levels for the current
  655. testing dialect.
  656. The structure indicates to the testing suite what the expected
  657. "default" isolation should be, as well as the other values that
  658. are accepted. The dictionary has two keys, "default" and "supported".
  659. The "supported" key refers to a list of all supported levels and
  660. it should include AUTOCOMMIT if the dialect supports it.
  661. If the :meth:`.DefaultRequirements.isolation_level` requirement is
  662. not open, then this method has no return value.
  663. E.g.::
  664. >>> testing.requirements.get_isolation_levels()
  665. {
  666. "default": "READ_COMMITTED",
  667. "supported": [
  668. "SERIALIZABLE", "READ UNCOMMITTED",
  669. "READ COMMITTED", "REPEATABLE READ",
  670. "AUTOCOMMIT"
  671. ]
  672. }
  673. """
  674. @property
  675. def json_type(self):
  676. """target platform implements a native JSON type."""
  677. return exclusions.closed()
  678. @property
  679. def json_array_indexes(self):
  680. """target platform supports numeric array indexes
  681. within a JSON structure"""
  682. return self.json_type
  683. @property
  684. def json_index_supplementary_unicode_element(self):
  685. return exclusions.open()
  686. @property
  687. def legacy_unconditional_json_extract(self):
  688. """Backend has a JSON_EXTRACT or similar function that returns a
  689. valid JSON string in all cases.
  690. Used to test a legacy feature and is not needed.
  691. """
  692. return exclusions.closed()
  693. @property
  694. def precision_numerics_general(self):
  695. """target backend has general support for moderately high-precision
  696. numerics."""
  697. return exclusions.open()
  698. @property
  699. def precision_numerics_enotation_small(self):
  700. """target backend supports Decimal() objects using E notation
  701. to represent very small values."""
  702. return exclusions.closed()
  703. @property
  704. def precision_numerics_enotation_large(self):
  705. """target backend supports Decimal() objects using E notation
  706. to represent very large values."""
  707. return exclusions.closed()
  708. @property
  709. def precision_numerics_many_significant_digits(self):
  710. """target backend supports values with many digits on both sides,
  711. such as 319438950232418390.273596, 87673.594069654243
  712. """
  713. return exclusions.closed()
  714. @property
  715. def cast_precision_numerics_many_significant_digits(self):
  716. """same as precision_numerics_many_significant_digits but within the
  717. context of a CAST statement (hello MySQL)
  718. """
  719. return self.precision_numerics_many_significant_digits
  720. @property
  721. def implicit_decimal_binds(self):
  722. """target backend will return a selected Decimal as a Decimal, not
  723. a string.
  724. e.g.::
  725. expr = decimal.Decimal("15.7563")
  726. value = e.scalar(
  727. select(literal(expr))
  728. )
  729. assert value == expr
  730. See :ticket:`4036`
  731. """
  732. return exclusions.open()
  733. @property
  734. def nested_aggregates(self):
  735. """target database can select an aggregate from a subquery that's
  736. also using an aggregate
  737. """
  738. return exclusions.open()
  739. @property
  740. def recursive_fk_cascade(self):
  741. """target database must support ON DELETE CASCADE on a self-referential
  742. foreign key
  743. """
  744. return exclusions.open()
  745. @property
  746. def precision_numerics_retains_significant_digits(self):
  747. """A precision numeric type will return empty significant digits,
  748. i.e. a value such as 10.000 will come back in Decimal form with
  749. the .000 maintained."""
  750. return exclusions.closed()
  751. @property
  752. def infinity_floats(self):
  753. """The Float type can persist and load float('inf'), float('-inf')."""
  754. return exclusions.closed()
  755. @property
  756. def precision_generic_float_type(self):
  757. """target backend will return native floating point numbers with at
  758. least seven decimal places when using the generic Float type.
  759. """
  760. return exclusions.open()
  761. @property
  762. def floats_to_four_decimals(self):
  763. """target backend can return a floating-point number with four
  764. significant digits (such as 15.7563) accurately
  765. (i.e. without FP inaccuracies, such as 15.75629997253418).
  766. """
  767. return exclusions.open()
  768. @property
  769. def fetch_null_from_numeric(self):
  770. """target backend doesn't crash when you try to select a NUMERIC
  771. value that has a value of NULL.
  772. Added to support Pyodbc bug #351.
  773. """
  774. return exclusions.open()
  775. @property
  776. def text_type(self):
  777. """Target database must support an unbounded Text() "
  778. "type such as TEXT or CLOB"""
  779. return exclusions.open()
  780. @property
  781. def empty_strings_varchar(self):
  782. """target database can persist/return an empty string with a
  783. varchar.
  784. """
  785. return exclusions.open()
  786. @property
  787. def empty_strings_text(self):
  788. """target database can persist/return an empty string with an
  789. unbounded text."""
  790. return exclusions.open()
  791. @property
  792. def expressions_against_unbounded_text(self):
  793. """target database supports use of an unbounded textual field in a
  794. WHERE clause."""
  795. return exclusions.open()
  796. @property
  797. def selectone(self):
  798. """target driver must support the literal statement 'select 1'"""
  799. return exclusions.open()
  800. @property
  801. def savepoints(self):
  802. """Target database must support savepoints."""
  803. return exclusions.closed()
  804. @property
  805. def two_phase_transactions(self):
  806. """Target database must support two-phase transactions."""
  807. return exclusions.closed()
  808. @property
  809. def update_from(self):
  810. """Target must support UPDATE..FROM syntax"""
  811. return exclusions.closed()
  812. @property
  813. def delete_from(self):
  814. """Target must support DELETE FROM..FROM or DELETE..USING syntax"""
  815. return exclusions.closed()
  816. @property
  817. def update_where_target_in_subquery(self):
  818. """Target must support UPDATE (or DELETE) where the same table is
  819. present in a subquery in the WHERE clause.
  820. This is an ANSI-standard syntax that apparently MySQL can't handle,
  821. such as::
  822. UPDATE documents SET flag=1 WHERE documents.title IN
  823. (SELECT max(documents.title) AS title
  824. FROM documents GROUP BY documents.user_id
  825. )
  826. """
  827. return exclusions.open()
  828. @property
  829. def mod_operator_as_percent_sign(self):
  830. """target database must use a plain percent '%' as the 'modulus'
  831. operator."""
  832. return exclusions.closed()
  833. @property
  834. def percent_schema_names(self):
  835. """target backend supports weird identifiers with percent signs
  836. in them, e.g. 'some % column'.
  837. this is a very weird use case but often has problems because of
  838. DBAPIs that use python formatting. It's not a critical use
  839. case either.
  840. """
  841. return exclusions.closed()
  842. @property
  843. def order_by_col_from_union(self):
  844. """target database supports ordering by a column from a SELECT
  845. inside of a UNION
  846. E.g. (SELECT id, ...) UNION (SELECT id, ...) ORDER BY id
  847. """
  848. return exclusions.open()
  849. @property
  850. def order_by_label_with_expression(self):
  851. """target backend supports ORDER BY a column label within an
  852. expression.
  853. Basically this::
  854. select data as foo from test order by foo || 'bar'
  855. Lots of databases including PostgreSQL don't support this,
  856. so this is off by default.
  857. """
  858. return exclusions.closed()
  859. @property
  860. def order_by_collation(self):
  861. def check(config):
  862. try:
  863. self.get_order_by_collation(config)
  864. return False
  865. except NotImplementedError:
  866. return True
  867. return exclusions.skip_if(check)
  868. def get_order_by_collation(self, config):
  869. raise NotImplementedError()
  870. @property
  871. def unicode_connections(self):
  872. """Target driver must support non-ASCII characters being passed at
  873. all.
  874. """
  875. return exclusions.open()
  876. @property
  877. def graceful_disconnects(self):
  878. """Target driver must raise a DBAPI-level exception, such as
  879. InterfaceError, when the underlying connection has been closed
  880. and the execute() method is called.
  881. """
  882. return exclusions.open()
  883. @property
  884. def independent_connections(self):
  885. """
  886. Target must support simultaneous, independent database connections.
  887. """
  888. return exclusions.open()
  889. @property
  890. def skip_mysql_on_windows(self):
  891. """Catchall for a large variety of MySQL on Windows failures"""
  892. return exclusions.open()
  893. @property
  894. def ad_hoc_engines(self):
  895. """Test environment must allow ad-hoc engine/connection creation.
  896. DBs that scale poorly for many connections, even when closed, i.e.
  897. Oracle, may use the "--low-connections" option which flags this
  898. requirement as not present.
  899. """
  900. return exclusions.skip_if(
  901. lambda config: config.options.low_connections
  902. )
  903. @property
  904. def no_windows(self):
  905. return exclusions.skip_if(self._running_on_windows())
  906. def _running_on_windows(self):
  907. return exclusions.LambdaPredicate(
  908. lambda: platform.system() == "Windows",
  909. description="running on Windows",
  910. )
  911. @property
  912. def timing_intensive(self):
  913. return exclusions.requires_tag("timing_intensive")
  914. @property
  915. def memory_intensive(self):
  916. return exclusions.requires_tag("memory_intensive")
  917. @property
  918. def threading_with_mock(self):
  919. """Mark tests that use threading and mock at the same time - stability
  920. issues have been observed with coverage + python 3.3
  921. """
  922. return exclusions.skip_if(
  923. lambda config: util.py3k and config.options.has_coverage,
  924. "Stability issues with coverage + py3k",
  925. )
  926. @property
  927. def sqlalchemy2_stubs(self):
  928. def check(config):
  929. try:
  930. __import__("sqlalchemy-stubs.ext.mypy")
  931. except ImportError:
  932. return False
  933. else:
  934. return True
  935. return exclusions.only_if(check)
  936. @property
  937. def python2(self):
  938. return exclusions.skip_if(
  939. lambda: sys.version_info >= (3,),
  940. "Python version 2.xx is required.",
  941. )
  942. @property
  943. def python3(self):
  944. return exclusions.skip_if(
  945. lambda: sys.version_info < (3,), "Python version 3.xx is required."
  946. )
  947. @property
  948. def pep520(self):
  949. return self.python36
  950. @property
  951. def insert_order_dicts(self):
  952. return self.python37
  953. @property
  954. def python36(self):
  955. return exclusions.skip_if(
  956. lambda: sys.version_info < (3, 6),
  957. "Python version 3.6 or greater is required.",
  958. )
  959. @property
  960. def python37(self):
  961. return exclusions.skip_if(
  962. lambda: sys.version_info < (3, 7),
  963. "Python version 3.7 or greater is required.",
  964. )
  965. @property
  966. def dataclasses(self):
  967. return self.python37
  968. @property
  969. def python38(self):
  970. return exclusions.only_if(
  971. lambda: util.py38, "Python 3.8 or above required"
  972. )
  973. @property
  974. def cpython(self):
  975. return exclusions.only_if(
  976. lambda: util.cpython, "cPython interpreter needed"
  977. )
  978. @property
  979. def patch_library(self):
  980. def check_lib():
  981. try:
  982. __import__("patch")
  983. except ImportError:
  984. return False
  985. else:
  986. return True
  987. return exclusions.only_if(check_lib, "patch library needed")
  988. @property
  989. def non_broken_pickle(self):
  990. from sqlalchemy.util import pickle
  991. return exclusions.only_if(
  992. lambda: util.cpython
  993. and pickle.__name__ == "cPickle"
  994. or sys.version_info >= (3, 2),
  995. "Needs cPickle+cPython or newer Python 3 pickle",
  996. )
  997. @property
  998. def predictable_gc(self):
  999. """target platform must remove all cycles unconditionally when
  1000. gc.collect() is called, as well as clean out unreferenced subclasses.
  1001. """
  1002. return self.cpython
  1003. @property
  1004. def no_coverage(self):
  1005. """Test should be skipped if coverage is enabled.
  1006. This is to block tests that exercise libraries that seem to be
  1007. sensitive to coverage, such as PostgreSQL notice logging.
  1008. """
  1009. return exclusions.skip_if(
  1010. lambda config: config.options.has_coverage,
  1011. "Issues observed when coverage is enabled",
  1012. )
  1013. def _has_mysql_on_windows(self, config):
  1014. return False
  1015. def _has_mysql_fully_case_sensitive(self, config):
  1016. return False
  1017. @property
  1018. def sqlite(self):
  1019. return exclusions.skip_if(lambda: not self._has_sqlite())
  1020. @property
  1021. def cextensions(self):
  1022. return exclusions.skip_if(
  1023. lambda: not util.has_compiled_ext(), "C extensions not installed"
  1024. )
  1025. def _has_sqlite(self):
  1026. from sqlalchemy import create_engine
  1027. try:
  1028. create_engine("sqlite://")
  1029. return True
  1030. except ImportError:
  1031. return False
  1032. @property
  1033. def async_dialect(self):
  1034. """dialect makes use of await_() to invoke operations on the DBAPI."""
  1035. return exclusions.closed()
  1036. @property
  1037. def greenlet(self):
  1038. def go(config):
  1039. try:
  1040. import greenlet # noqa F401
  1041. except ImportError:
  1042. return False
  1043. else:
  1044. return True
  1045. return exclusions.only_if(go)
  1046. @property
  1047. def computed_columns(self):
  1048. "Supports computed columns"
  1049. return exclusions.closed()
  1050. @property
  1051. def computed_columns_stored(self):
  1052. "Supports computed columns with `persisted=True`"
  1053. return exclusions.closed()
  1054. @property
  1055. def computed_columns_virtual(self):
  1056. "Supports computed columns with `persisted=False`"
  1057. return exclusions.closed()
  1058. @property
  1059. def computed_columns_default_persisted(self):
  1060. """If the default persistence is virtual or stored when `persisted`
  1061. is omitted"""
  1062. return exclusions.closed()
  1063. @property
  1064. def computed_columns_reflect_persisted(self):
  1065. """If persistence information is returned by the reflection of
  1066. computed columns"""
  1067. return exclusions.closed()
  1068. @property
  1069. def supports_distinct_on(self):
  1070. """If a backend supports the DISTINCT ON in a select"""
  1071. return exclusions.closed()
  1072. @property
  1073. def supports_is_distinct_from(self):
  1074. """Supports some form of "x IS [NOT] DISTINCT FROM y" construct.
  1075. Different dialects will implement their own flavour, e.g.,
  1076. sqlite will emit "x IS NOT y" instead of "x IS DISTINCT FROM y".
  1077. .. seealso::
  1078. :meth:`.ColumnOperators.is_distinct_from`
  1079. """
  1080. return exclusions.skip_if(
  1081. lambda config: not config.db.dialect.supports_is_distinct_from,
  1082. "driver doesn't support an IS DISTINCT FROM construct",
  1083. )
  1084. @property
  1085. def identity_columns(self):
  1086. """If a backend supports GENERATED { ALWAYS | BY DEFAULT }
  1087. AS IDENTITY"""
  1088. return exclusions.closed()
  1089. @property
  1090. def identity_columns_standard(self):
  1091. """If a backend supports GENERATED { ALWAYS | BY DEFAULT }
  1092. AS IDENTITY with a standard syntax.
  1093. This is mainly to exclude MSSql.
  1094. """
  1095. return exclusions.closed()
  1096. @property
  1097. def regexp_match(self):
  1098. """backend supports the regexp_match operator."""
  1099. return exclusions.closed()
  1100. @property
  1101. def regexp_replace(self):
  1102. """backend supports the regexp_replace operator."""
  1103. return exclusions.closed()
  1104. @property
  1105. def fetch_first(self):
  1106. """backend supports the fetch first clause."""
  1107. return exclusions.closed()
  1108. @property
  1109. def fetch_percent(self):
  1110. """backend supports the fetch first clause with percent."""
  1111. return exclusions.closed()
  1112. @property
  1113. def fetch_ties(self):
  1114. """backend supports the fetch first clause with ties."""
  1115. return exclusions.closed()
  1116. @property
  1117. def fetch_no_order_by(self):
  1118. """backend supports the fetch first without order by"""
  1119. return exclusions.closed()
  1120. @property
  1121. def fetch_offset_with_options(self):
  1122. """backend supports the offset when using fetch first with percent
  1123. or ties. basically this is "not mssql"
  1124. """
  1125. return exclusions.closed()
  1126. @property
  1127. def fetch_expression(self):
  1128. """backend supports fetch / offset with expression in them, like
  1129. SELECT * FROM some_table
  1130. OFFSET 1 + 1 ROWS FETCH FIRST 1 + 1 ROWS ONLY
  1131. """
  1132. return exclusions.closed()
  1133. @property
  1134. def autoincrement_without_sequence(self):
  1135. """If autoincrement=True on a column does not require an explicit
  1136. sequence. This should be false only for oracle.
  1137. """
  1138. return exclusions.open()
  1139. @property
  1140. def generic_classes(self):
  1141. "If X[Y] can be implemented with ``__class_getitem__``. py3.7+"
  1142. return exclusions.only_if(lambda: util.py37)