From 79bde753e47bd86f0199c4aa6a5c2ead1e4aec95 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 9 Mar 2021 13:36:34 -0500 Subject: 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 --- test/sql/test_query.py | 59 ++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 28 deletions(-) (limited to 'test/sql/test_query.py') 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.*") -- cgit v1.2.1