From: Karol Gongola Date: Wed, 26 Feb 2025 10:06:16 +0000 (-0500) Subject: Add more `requires` to tests for easier dialect tests management X-Git-Tag: rel_2_0_39~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=efe7c6ed64835901583f27e228f8cf265f35370f;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add more `requires` to tests for easier dialect tests management ### Description I am just going through starrocks dialect tests. I have figured out that adding some requires for tests may be useful also for other dialects. So this is a proposal of adding them to sqlalchemy. Please let me know if it is aligned with your approach. ### Checklist This pull request is: - [x] A documentation / typographical / small typing error fix - Good to go, no issue or tests are needed - [ ] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #` in the commit message - please include tests. **Have a nice day!** Closes: #12362 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12362 Pull-request-sha: 932d341f5f16f0c5cadc39d3a67b0f10297177ce Change-Id: If9fa9f7477040620d131dcbe087fb4b50fd08a08 (cherry picked from commit 24b86ad6e50d4a6723a45b2580f416ca981bab55) --- diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py index bbf56a059a..93541dca70 100644 --- a/lib/sqlalchemy/testing/requirements.py +++ b/lib/sqlalchemy/testing/requirements.py @@ -1826,3 +1826,9 @@ class SuiteRequirements(Requirements): def supports_bitwise_shift(self): """Target database supports bitwise left or right shift""" return exclusions.closed() + + @property + def like_escapes(self): + """Target backend supports custom ESCAPE characters + with LIKE comparisons""" + return exclusions.open() diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py index 54d0d449a9..2837e9fe0a 100644 --- a/lib/sqlalchemy/testing/suite/test_reflection.py +++ b/lib/sqlalchemy/testing/suite/test_reflection.py @@ -220,6 +220,7 @@ class HasTableTest(OneConnectionTablesTest): class HasIndexTest(fixtures.TablesTest): __backend__ = True + __requires__ = ("index_reflection",) @classmethod def define_tables(cls, metadata): @@ -298,6 +299,7 @@ class BizarroCharacterFKResolutionTest(fixtures.TestBase): """tests for #10275""" __backend__ = True + __requires__ = ("foreign_key_constraint_reflection",) @testing.combinations( ("id",), ("(3)",), ("col%p",), ("[brack]",), argnames="columnname" @@ -474,11 +476,13 @@ class QuotedNameArgumentTest(fixtures.TablesTest): assert insp.get_pk_constraint(name) @quote_fixtures + @testing.requires.foreign_key_constraint_reflection def test_get_foreign_keys(self, name): insp = inspect(config.db) assert insp.get_foreign_keys(name) @quote_fixtures + @testing.requires.index_reflection def test_get_indexes(self, name): insp = inspect(config.db) assert insp.get_indexes(name) diff --git a/lib/sqlalchemy/testing/suite/test_select.py b/lib/sqlalchemy/testing/suite/test_select.py index 7eb5cd0055..b9e8b11efe 100644 --- a/lib/sqlalchemy/testing/suite/test_select.py +++ b/lib/sqlalchemy/testing/suite/test_select.py @@ -1541,6 +1541,7 @@ class LikeFunctionsTest(fixtures.TablesTest): col = self.tables.some_table.c.data self._test(col.startswith("ab%c"), {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) + @testing.requires.like_escapes def test_startswith_autoescape(self): col = self.tables.some_table.c.data self._test(col.startswith("ab%c", autoescape=True), {3}) @@ -1552,10 +1553,12 @@ class LikeFunctionsTest(fixtures.TablesTest): {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, ) + @testing.requires.like_escapes def test_startswith_escape(self): col = self.tables.some_table.c.data self._test(col.startswith("ab##c", escape="#"), {7}) + @testing.requires.like_escapes def test_startswith_autoescape_escape(self): col = self.tables.some_table.c.data self._test(col.startswith("ab%c", autoescape=True, escape="#"), {3}) @@ -1571,14 +1574,17 @@ class LikeFunctionsTest(fixtures.TablesTest): col.endswith(literal_column("'e%fg'")), {1, 2, 3, 4, 5, 6, 7, 8, 9} ) + @testing.requires.like_escapes def test_endswith_autoescape(self): col = self.tables.some_table.c.data self._test(col.endswith("e%fg", autoescape=True), {6}) + @testing.requires.like_escapes def test_endswith_escape(self): col = self.tables.some_table.c.data self._test(col.endswith("e##fg", escape="#"), {9}) + @testing.requires.like_escapes def test_endswith_autoescape_escape(self): col = self.tables.some_table.c.data self._test(col.endswith("e%fg", autoescape=True, escape="#"), {6}) @@ -1588,14 +1594,17 @@ class LikeFunctionsTest(fixtures.TablesTest): col = self.tables.some_table.c.data self._test(col.contains("b%cde"), {1, 2, 3, 4, 5, 6, 7, 8, 9}) + @testing.requires.like_escapes def test_contains_autoescape(self): col = self.tables.some_table.c.data self._test(col.contains("b%cde", autoescape=True), {3}) + @testing.requires.like_escapes def test_contains_escape(self): col = self.tables.some_table.c.data self._test(col.contains("b##cde", escape="#"), {7}) + @testing.requires.like_escapes def test_contains_autoescape_escape(self): col = self.tables.some_table.c.data self._test(col.contains("b%cd", autoescape=True, escape="#"), {3}) diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py index de3cd53e34..5f1bf75d50 100644 --- a/lib/sqlalchemy/testing/suite/test_types.py +++ b/lib/sqlalchemy/testing/suite/test_types.py @@ -299,6 +299,7 @@ class ArrayTest(_LiteralRoundTripFixture, fixtures.TablesTest): class BinaryTest(_LiteralRoundTripFixture, fixtures.TablesTest): __backend__ = True + __requires__ = ("binary_literals",) @classmethod def define_tables(cls, metadata): @@ -1483,6 +1484,7 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest): return datatype, compare_value, p_s + @testing.requires.legacy_unconditional_json_extract @_index_fixtures(False) def test_index_typed_access(self, datatype, value): data_table = self.tables.data_table @@ -1504,6 +1506,7 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest): eq_(roundtrip, compare_value) is_(type(roundtrip), type(compare_value)) + @testing.requires.legacy_unconditional_json_extract @_index_fixtures(True) def test_index_typed_comparison(self, datatype, value): data_table = self.tables.data_table @@ -1528,6 +1531,7 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest): # make sure we get a row even if value is None eq_(row, (compare_value,)) + @testing.requires.legacy_unconditional_json_extract @_index_fixtures(True) def test_path_typed_comparison(self, datatype, value): data_table = self.tables.data_table