summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2022-06-16 02:30:04 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2022-06-16 02:30:04 +0000
commitefd4e6dd8a73b956c860d796606f8e6ad652c292 (patch)
treefc4e387f37e421d54068310eab5a01facb5f91c8 /lib/sqlalchemy/testing
parent964c26feecc7607d6d3a66240c3f33f4ae9215d4 (diff)
parent46c0fa56e904f6a00e56343302c4cb39955fa038 (diff)
downloadsqlalchemy-efd4e6dd8a73b956c860d796606f8e6ad652c292.tar.gz
Merge "implement literal stringification for arrays" into main
Diffstat (limited to 'lib/sqlalchemy/testing')
-rw-r--r--lib/sqlalchemy/testing/suite/test_types.py57
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",