From ec264a5a2c810394ee4ebd7a78f83fc0ea785c1f Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Sun, 15 Nov 2020 16:58:46 +0100 Subject: Use ``re.search`` instead of ``re.match`` in sqlite Use python ``re.search()`` instead of ``re.match()`` as the operation used by the :meth:`Column.regexp_match` method when using sqlite. This matches the behavior of regular expressions on other databases as well as that of well-known SQLite plugins. Fixes: #5699 Change-Id: I14b2c7faf51fef172842aeb2dba2500f14544f24 --- lib/sqlalchemy/testing/suite/test_select.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'lib/sqlalchemy/testing') diff --git a/lib/sqlalchemy/testing/suite/test_select.py b/lib/sqlalchemy/testing/suite/test_select.py index e7b733261..f8d9b3d88 100644 --- a/lib/sqlalchemy/testing/suite/test_select.py +++ b/lib/sqlalchemy/testing/suite/test_select.py @@ -1125,11 +1125,6 @@ class LikeFunctionsTest(fixtures.TablesTest): self._test(col.contains("b%cd", autoescape=True, escape="#"), {3}) self._test(col.contains("b#cd", autoescape=True, escape="#"), {7}) - @testing.requires.regexp_match - def test_regexp_match(self): - col = self.tables.some_table.c.data - self._test(col.regexp_match("a.cde"), {1, 5, 6, 9}) - @testing.requires.regexp_match def test_not_regexp_match(self): col = self.tables.some_table.c.data @@ -1142,6 +1137,20 @@ class LikeFunctionsTest(fixtures.TablesTest): col.regexp_replace("a.cde", "FOO").contains("FOO"), {1, 5, 6, 9} ) + @testing.requires.regexp_match + @testing.combinations( + ("a.cde", {1, 5, 6, 9}), + ("abc", {1, 5, 6, 9, 10}), + ("^abc", {1, 5, 6, 9, 10}), + ("9cde", {8}), + ("^a", set(range(1, 11))), + ("(b|c)", set(range(1, 11))), + ("^(b|c)", set()), + ) + def test_regexp_match(self, text, expected): + col = self.tables.some_table.c.data + self._test(col.regexp_match(text), expected) + class ComputedColumnTest(fixtures.TablesTest): __backend__ = True -- cgit v1.2.1