From 46c0fa56e904f6a00e56343302c4cb39955fa038 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 15 Jun 2022 12:42:44 -0400 Subject: implement literal stringification for arrays as we already implement stringification for the contents, provide a bracketed syntax for default and ARRAY literal for PG specifically. ARRAY literal seems much simpler to render than their quoted syntax which requires double quotes for strings. also open up testing for pg8000 which has likely been fine with arrays for awhile now, bump the version pin also. Fixes: #8138 Change-Id: Id85b052b0a9564d6aa1489160e58b7359f130fdd --- lib/sqlalchemy/testing/suite/test_types.py | 57 ++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'lib/sqlalchemy/testing') diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py index 391379956..9461298b9 100644 --- a/lib/sqlalchemy/testing/suite/test_types.py +++ b/lib/sqlalchemy/testing/suite/test_types.py @@ -17,6 +17,7 @@ from ..config import requirements from ..schema import Column from ..schema import Table from ... import and_ +from ... import ARRAY from ... import BigInteger from ... import bindparam from ... import Boolean @@ -222,6 +223,61 @@ class UnicodeTextTest(_UnicodeFixture, fixtures.TablesTest): self._test_null_strings(connection) +class ArrayTest(_LiteralRoundTripFixture, fixtures.TablesTest): + """Add ARRAY test suite, #8138. + + This only works on PostgreSQL right now. + + """ + + __requires__ = ("array_type",) + __backend__ = True + + @classmethod + def define_tables(cls, metadata): + Table( + "array_table", + metadata, + Column( + "id", Integer, primary_key=True, test_needs_autoincrement=True + ), + Column("single_dim", ARRAY(Integer)), + Column("multi_dim", ARRAY(String, dimensions=2)), + ) + + def test_array_roundtrip(self, connection): + array_table = self.tables.array_table + + connection.execute( + array_table.insert(), + { + "id": 1, + "single_dim": [1, 2, 3], + "multi_dim": [["one", "two"], ["thr'ee", "réve🐍 illé"]], + }, + ) + row = connection.execute( + select(array_table.c.single_dim, array_table.c.multi_dim) + ).first() + eq_(row, ([1, 2, 3], [["one", "two"], ["thr'ee", "réve🐍 illé"]])) + + def test_literal_simple(self, literal_round_trip): + literal_round_trip( + ARRAY(Integer), + ([1, 2, 3],), + ([1, 2, 3],), + support_whereclause=False, + ) + + def test_literal_complex(self, literal_round_trip): + literal_round_trip( + ARRAY(String, dimensions=2), + ([["one", "two"], ["thr'ee", "réve🐍 illé"]],), + ([["one", "two"], ["thr'ee", "réve🐍 illé"]],), + support_whereclause=False, + ) + + class BinaryTest(_LiteralRoundTripFixture, fixtures.TablesTest): __requires__ = ("binary_literals",) __backend__ = True @@ -1779,6 +1835,7 @@ class NativeUUIDTest(UuidTest): __all__ = ( + "ArrayTest", "BinaryTest", "UnicodeVarcharTest", "UnicodeTextTest", -- cgit v1.2.1