summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2022-11-29 23:35:16 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2022-11-29 23:35:16 +0000
commit7857a1de32169858367446d11089c34f8daee957 (patch)
tree48a35acde7cfb298de8d52102f45a2afcdff312b /test/sql
parent78833af4e650d37e6257cfbb541e4db56e2a285f (diff)
parent0b239579f03c82f7669d77c238e4fda8638fb9c3 (diff)
downloadsqlalchemy-7857a1de32169858367446d11089c34f8daee957.tar.gz
Merge "Add value-level hooks for SQL type detection; apply to Range" into main
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_types.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/sql/test_types.py b/test/sql/test_types.py
index d1b32186e..91413ff35 100644
--- a/test/sql/test_types.py
+++ b/test/sql/test_types.py
@@ -3293,6 +3293,43 @@ class ExpressionTest(
],
)
+ @testing.variation("secondary_adapt", [True, False])
+ @testing.variation("expression_type", ["literal", "right_side"])
+ def test_value_level_bind_hooks(
+ self, connection, metadata, secondary_adapt, expression_type
+ ):
+ """test new feature added in #8884, allowing custom value objects
+ to indicate the SQL type they should resolve towards.
+
+ """
+
+ class MyFoobarType(types.UserDefinedType):
+ if secondary_adapt:
+
+ def _resolve_for_literal(self, value):
+ return String(value.length)
+
+ class Widget:
+ def __init__(self, length):
+ self.length = length
+
+ @property
+ def __sa_type_engine__(self):
+ return MyFoobarType()
+
+ if expression_type.literal:
+ expr = literal(Widget(52))
+ elif expression_type.right_side:
+ expr = (column("x", Integer) == Widget(52)).right
+ else:
+ assert False
+
+ if secondary_adapt:
+ is_(expr.type._type_affinity, String)
+ eq_(expr.type.length, 52)
+ else:
+ is_(expr.type._type_affinity, MyFoobarType)
+
def test_grouped_bind_adapt(self):
test_table = self.tables.test