requirements.py 44 KB

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