diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-09 13:36:34 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-09 13:36:34 -0500 |
| commit | 79bde753e47bd86f0199c4aa6a5c2ead1e4aec95 (patch) | |
| tree | e93e70057e6123d6871f3481d7a6c53c453149f5 /test/sql/test_query.py | |
| parent | 85c843bcc3ea1ca16be06fe85b03d99c4e519f3d (diff) | |
| download | sqlalchemy-79bde753e47bd86f0199c4aa6a5c2ead1e4aec95.tar.gz | |
Apply percent sign escaping to op(), custom_op()
Fixed bug where the "percent escaping" feature that occurs with dialects
that use the "format" or "pyformat" bound parameter styles was not enabled
for the :meth:`.Operations.op` and :meth:`.Operations.custom_op` methods,
for custom operators that use percent signs. The percent sign will now be
automatically doubled based on the paramstyle as necessary.
Fixes: #6016
Change-Id: I285c5fc082481c2ee989edf1b02a83a6087ea26a
Diffstat (limited to 'test/sql/test_query.py')
| -rw-r--r-- | test/sql/test_query.py | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/test/sql/test_query.py b/test/sql/test_query.py index 913b7f4d1..33245bfbc 100644 --- a/test/sql/test_query.py +++ b/test/sql/test_query.py @@ -34,6 +34,7 @@ from sqlalchemy.testing import fixtures from sqlalchemy.testing import is_ from sqlalchemy.testing.schema import Column from sqlalchemy.testing.schema import Table +from sqlalchemy.testing.util import resolve_lambda class QueryTest(fixtures.TablesTest): @@ -173,7 +174,34 @@ class QueryTest(fixtures.TablesTest): select(tuple_(users.c.user_id, users.c.user_name)), ) - def test_like_ops(self, connection): + @testing.combinations( + ( + lambda users: select(users.c.user_id).where( + users.c.user_name.startswith("apple") + ), + [(1,)], + ), + ( + lambda users: select(users.c.user_id).where( + users.c.user_name.contains("i % t") + ), + [(5,)], + ), + ( + lambda users: select(users.c.user_id).where( + users.c.user_name.endswith("anas") + ), + [(3,)], + ), + ( + lambda users: select(users.c.user_id).where( + users.c.user_name.contains("i % t", escape="&") + ), + [(5,)], + ), + argnames="expr,result", + ) + def test_like_ops(self, connection, expr, result): users = self.tables.users connection.execute( users.insert(), @@ -186,33 +214,8 @@ class QueryTest(fixtures.TablesTest): ], ) - for expr, result in ( - ( - select(users.c.user_id).where( - users.c.user_name.startswith("apple") - ), - [(1,)], - ), - ( - select(users.c.user_id).where( - users.c.user_name.contains("i % t") - ), - [(5,)], - ), - ( - select(users.c.user_id).where( - users.c.user_name.endswith("anas") - ), - [(3,)], - ), - ( - select(users.c.user_id).where( - users.c.user_name.contains("i % t", escape="&") - ), - [(5,)], - ), - ): - eq_(connection.execute(expr).fetchall(), result) + expr = resolve_lambda(expr, users=users) + eq_(connection.execute(expr).fetchall(), result) @testing.requires.mod_operator_as_percent_sign @testing.emits_warning(".*now automatically escapes.*") |
