diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-06-15 12:42:44 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-06-15 14:32:53 -0400 |
| commit | 46c0fa56e904f6a00e56343302c4cb39955fa038 (patch) | |
| tree | 7417ab317303299916ed7f2a6843bc5ce5e1634a /lib/sqlalchemy/testing | |
| parent | 6d889b03dcd42b531001aeec2737949dca41d6d8 (diff) | |
| download | sqlalchemy-46c0fa56e904f6a00e56343302c4cb39955fa038.tar.gz | |
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
Diffstat (limited to 'lib/sqlalchemy/testing')
| -rw-r--r-- | lib/sqlalchemy/testing/suite/test_types.py | 57 |
1 files changed, 57 insertions, 0 deletions
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", |
