summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-06-22 12:19:41 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-06-22 12:19:41 -0400
commiteba9d1b58f38577fb71d3374a2133d6e9159c277 (patch)
tree15f7dd663b8dcbf98adcc15c065a937d327e1a89 /test
parent38b54955118e6bb0f4e9664b50924a193f53e817 (diff)
downloadsqlalchemy-eba9d1b58f38577fb71d3374a2133d6e9159c277.tar.gz
Provided a new attribute for :class:`.TypeDecorator`
called :attr:`.TypeDecorator.coerce_to_is_types`, to make it easier to control how comparisons using ``==`` or ``!=`` to ``None`` and boolean types goes about producing an ``IS`` expression, or a plain equality expression with a bound parameter. [ticket:2744]
Diffstat (limited to 'test')
-rw-r--r--test/sql/test_types.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/test/sql/test_types.py b/test/sql/test_types.py
index dbb475b98..2a22224a2 100644
--- a/test/sql/test_types.py
+++ b/test/sql/test_types.py
@@ -1087,7 +1087,6 @@ class ExpressionTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled
expr = column('foo', CHAR) == "asdf"
eq_(expr.right.type.__class__, CHAR)
-
@testing.uses_deprecated
@testing.fails_on('firebird', 'Data type unknown on the parameter')
@testing.fails_on('mssql', 'int is unsigned ? not clear')
@@ -1130,6 +1129,39 @@ class ExpressionTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled
"BIND_INfooBIND_INhiBIND_OUT"
)
+ def test_typedec_is_adapt(self):
+ class CoerceNothing(TypeDecorator):
+ coerce_to_is_types = ()
+ impl = Integer
+ class CoerceBool(TypeDecorator):
+ coerce_to_is_types = (bool, )
+ impl = Boolean
+ class CoerceNone(TypeDecorator):
+ coerce_to_is_types = (type(None),)
+ impl = Integer
+
+ c1 = column('x', CoerceNothing())
+ c2 = column('x', CoerceBool())
+ c3 = column('x', CoerceNone())
+
+ self.assert_compile(
+ and_(c1 == None, c2 == None, c3 == None),
+ "x = :x_1 AND x = :x_2 AND x IS NULL"
+ )
+ self.assert_compile(
+ and_(c1 == True, c2 == True, c3 == True),
+ "x = :x_1 AND x = true AND x = :x_2"
+ )
+ self.assert_compile(
+ and_(c1 == 3, c2 == 3, c3 == 3),
+ "x = :x_1 AND x = :x_2 AND x = :x_3"
+ )
+ self.assert_compile(
+ and_(c1.is_(True), c2.is_(True), c3.is_(True)),
+ "x IS :x_1 AND x IS true AND x IS :x_2"
+ )
+
+
def test_typedec_righthand_coercion(self):
class MyTypeDec(types.TypeDecorator):
impl = String