summaryrefslogtreecommitdiff
path: root/test/dialect
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-10-23 11:26:45 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-12-29 11:43:53 -0500
commit9e3c8d0d71ae0aabe9f5abfae2db838cb80fe320 (patch)
treea63c2c87acb3b9ce40cfce839bbf808206af1d98 /test/dialect
parent3210348fd41d7efb7871afb24ee4e65a1f88f245 (diff)
downloadsqlalchemy-9e3c8d0d71ae0aabe9f5abfae2db838cb80fe320.tar.gz
replace Variant with direct feature inside of TypeEngine
The :meth:`_sqltypes.TypeEngine.with_variant` method now returns a copy of the original :class:`_sqltypes.TypeEngine` object, rather than wrapping it inside the ``Variant`` class, which is effectively removed (the import symbol remains for backwards compatibility with code that may be testing for this symbol). While the previous approach maintained in-Python behaviors, maintaining the original type allows for clearer type checking and debugging. Fixes: #6980 Change-Id: I158c7e56306b886b5b82b040205c428a5c4a242c
Diffstat (limited to 'test/dialect')
-rw-r--r--test/dialect/postgresql/test_types.py42
1 files changed, 25 insertions, 17 deletions
diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py
index 5f8a41d1f..a5797dc2f 100644
--- a/test/dialect/postgresql/test_types.py
+++ b/test/dialect/postgresql/test_types.py
@@ -50,7 +50,6 @@ from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import Session
from sqlalchemy.sql import operators
from sqlalchemy.sql import sqltypes
-from sqlalchemy.sql.type_api import Variant
from sqlalchemy.testing import fixtures
from sqlalchemy.testing.assertions import assert_raises
from sqlalchemy.testing.assertions import assert_raises_message
@@ -779,24 +778,33 @@ class EnumTest(fixtures.TestBase, AssertsExecutionResults):
connection.execute(t1.insert(), {"data": "two"})
eq_(connection.scalar(select(t1.c.data)), "twoHITHERE")
- def test_generic_w_pg_variant(self, metadata, connection):
+ @testing.combinations(
+ (
+ Enum(
+ "one",
+ "two",
+ "three",
+ native_enum=True # make sure this is True because
+ # it should *not* take effect due to
+ # the variant
+ ).with_variant(
+ postgresql.ENUM("four", "five", "six", name="my_enum"),
+ "postgresql",
+ )
+ ),
+ (
+ String(50).with_variant(
+ postgresql.ENUM("four", "five", "six", name="my_enum"),
+ "postgresql",
+ )
+ ),
+ argnames="datatype",
+ )
+ def test_generic_w_pg_variant(self, metadata, connection, datatype):
some_table = Table(
"some_table",
self.metadata,
- Column(
- "data",
- Enum(
- "one",
- "two",
- "three",
- native_enum=True # make sure this is True because
- # it should *not* take effect due to
- # the variant
- ).with_variant(
- postgresql.ENUM("four", "five", "six", name="my_enum"),
- "postgresql",
- ),
- ),
+ Column("data", datatype),
)
assert "my_enum" not in [
@@ -2134,7 +2142,7 @@ class ArrayRoundTripTest:
new_gen = gen(3)
- if isinstance(table.c.bar.type, Variant):
+ if not table.c.bar.type._variant_mapping:
# this is not likely to occur to users but we need to just
# exercise this as far as we can
expr = type_coerce(table.c.bar, ARRAY(type_))[1:3]