Use regex to compare SQL strings with IN

SQLAlchemy 1.4 will be changing the method by which it
renders an IN expression such that the bound parameters
are not fully rendered until the statement is executed,
rather than when the statement is compiled into its initial
string form [1].   Adjust tests which are asserting the presence
of IN expressions based on the compiled form to allow for an
arbitrary expression within the parenthesis.

[1] https://github.com/sqlalchemy/sqlalchemy/issues/4645

Change-Id: I8640ad0cbd96647ed74678631479190146bd908e
This commit is contained in:
Mike Bayer 2019-12-11 11:04:26 -05:00
parent 9ce6b030e7
commit fce052b2af

View File

@ -60,19 +60,19 @@ class ManufactureCriteriaTest(oslo_test_base.BaseTestCase):
specimen = MyModel(
y='y1', z=('z1', 'z2'),
)
self.assertEqual(
"my_table.y = :y_1 AND my_table.z IN (:z_1, :z_2)",
str(update_match.manufacture_entity_criteria(specimen).compile())
self.assertRegex(
str(update_match.manufacture_entity_criteria(specimen).compile()),
r"my_table.y = :y_1 AND my_table.z IN \(.+?\)",
)
def test_instance_criteria_tuples_wnone(self):
specimen = MyModel(
y='y1', z=('z1', 'z2', None),
)
self.assertEqual(
"my_table.y = :y_1 AND (my_table.z IS NULL OR "
"my_table.z IN (:z_1, :z_2))",
str(update_match.manufacture_entity_criteria(specimen).compile())
self.assertRegex(
str(update_match.manufacture_entity_criteria(specimen).compile()),
r"my_table.y = :y_1 AND \(my_table.z IS NULL OR "
r"my_table.z IN \(.+?\)\)",
)
def test_instance_criteria_none_list(self):