summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2021-11-18 16:11:35 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2021-11-18 16:11:35 +0000
commitc0b0bf8ab81ac966a8c5a428a45cddbafaaf6e18 (patch)
tree2b1e7c95d8c2f77cf7b387b95c32c3755ce3f680 /lib/sqlalchemy/testing
parent958f902b1fc528fed0be550bc573545de47ed854 (diff)
parentb2df5be7ee8b5ee7ae67323b5018ca37bbf0ce2a (diff)
downloadsqlalchemy-c0b0bf8ab81ac966a8c5a428a45cddbafaaf6e18.tar.gz
Merge "Deprecate create_engine.implicit_returning" into main
Diffstat (limited to 'lib/sqlalchemy/testing')
-rw-r--r--lib/sqlalchemy/testing/assertsql.py31
-rw-r--r--lib/sqlalchemy/testing/suite/test_insert.py24
2 files changed, 30 insertions, 25 deletions
diff --git a/lib/sqlalchemy/testing/assertsql.py b/lib/sqlalchemy/testing/assertsql.py
index ca0bc6726..9816c99b7 100644
--- a/lib/sqlalchemy/testing/assertsql.py
+++ b/lib/sqlalchemy/testing/assertsql.py
@@ -186,7 +186,9 @@ class CompiledSQL(SQLMatchRule):
self.is_consumed = True
self.errormessage = None
else:
- self.errormessage = self._failure_message(params) % {
+ self.errormessage = self._failure_message(
+ execute_observed, params
+ ) % {
"received_statement": _received_statement,
"received_parameters": _received_parameters,
}
@@ -203,7 +205,7 @@ class CompiledSQL(SQLMatchRule):
else:
return None
- def _failure_message(self, expected_params):
+ def _failure_message(self, execute_observed, expected_params):
return (
"Testing for compiled statement\n%r partial params %s, "
"received\n%%(received_statement)r with params "
@@ -223,7 +225,7 @@ class RegexSQL(CompiledSQL):
self.params = params
self.dialect = dialect
- def _failure_message(self, expected_params):
+ def _failure_message(self, execute_observed, expected_params):
return (
"Testing for compiled statement ~%r partial params %s, "
"received %%(received_statement)r with params "
@@ -263,11 +265,8 @@ class DialectSQL(CompiledSQL):
return received_stmt, execute_observed.context.compiled_parameters
- def _compare_sql(self, execute_observed, received_statement):
+ def _dialect_adjusted_statement(self, paramstyle):
stmt = re.sub(r"[\n\t]", "", self.statement)
- # convert our comparison statement to have the
- # paramstyle of the received
- paramstyle = execute_observed.context.dialect.paramstyle
if paramstyle == "pyformat":
stmt = re.sub(r":([\w_]+)", r"%(\1)s", stmt)
else:
@@ -280,9 +279,27 @@ class DialectSQL(CompiledSQL):
elif paramstyle == "numeric":
repl = None
stmt = re.sub(r":([\w_]+)", repl, stmt)
+ return stmt
+ def _compare_sql(self, execute_observed, received_statement):
+ paramstyle = execute_observed.context.dialect.paramstyle
+ stmt = self._dialect_adjusted_statement(paramstyle)
return received_statement == stmt
+ def _failure_message(self, execute_observed, expected_params):
+ paramstyle = execute_observed.context.dialect.paramstyle
+ return (
+ "Testing for compiled statement\n%r partial params %s, "
+ "received\n%%(received_statement)r with params "
+ "%%(received_parameters)r"
+ % (
+ self._dialect_adjusted_statement(paramstyle).replace(
+ "%", "%%"
+ ),
+ repr(expected_params).replace("%", "%%"),
+ )
+ )
+
class CountStatements(AssertRule):
def __init__(self, count):
diff --git a/lib/sqlalchemy/testing/suite/test_insert.py b/lib/sqlalchemy/testing/suite/test_insert.py
index 3c22f50b2..080bb486e 100644
--- a/lib/sqlalchemy/testing/suite/test_insert.py
+++ b/lib/sqlalchemy/testing/suite/test_insert.py
@@ -1,5 +1,3 @@
-from .. import config
-from .. import engines
from .. import fixtures
from ..assertions import eq_
from ..config import requirements
@@ -19,8 +17,6 @@ class LastrowidTest(fixtures.TablesTest):
__requires__ = "implements_get_lastrowid", "autoincrement_insert"
- __engine_options__ = {"implicit_returning": False}
-
@classmethod
def define_tables(cls, metadata):
Table(
@@ -30,6 +26,7 @@ class LastrowidTest(fixtures.TablesTest):
"id", Integer, primary_key=True, test_needs_autoincrement=True
),
Column("data", String(50)),
+ implicit_returning=False,
)
Table(
@@ -37,6 +34,7 @@ class LastrowidTest(fixtures.TablesTest):
metadata,
Column("id", Integer, primary_key=True, autoincrement=False),
Column("data", String(50)),
+ implicit_returning=False,
)
def _assert_round_trip(self, table, conn):
@@ -110,18 +108,10 @@ class InsertBehaviorTest(fixtures.TablesTest):
)
@requirements.autoincrement_insert
- def test_autoclose_on_insert(self):
- if requirements.returning.enabled:
- engine = engines.testing_engine(
- options={"implicit_returning": False}
- )
- else:
- engine = config.db
-
- with engine.begin() as conn:
- r = conn.execute(
- self.tables.autoinc_pk.insert(), dict(data="some data")
- )
+ def test_autoclose_on_insert(self, connection):
+ r = connection.execute(
+ self.tables.autoinc_pk.insert(), dict(data="some data")
+ )
assert r._soft_closed
assert not r.closed
assert r.is_insert
@@ -306,8 +296,6 @@ class ReturningTest(fixtures.TablesTest):
__requires__ = "returning", "autoincrement_insert"
__backend__ = True
- __engine_options__ = {"implicit_returning": True}
-
def _assert_round_trip(self, table, conn):
row = conn.execute(table.select()).first()
eq_(