summaryrefslogtreecommitdiff
path: root/test/sql/test_compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-04-17 15:37:12 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-04-17 15:37:12 -0400
commit69dcd805d2c6ed92adf81da443c5c06d23d3423a (patch)
tree9368e15176efa0d6b5a04164ff0558c7d9ae0ae1 /test/sql/test_compiler.py
parentfbcfd079debf27665f23a996853903aa3b2ef23a (diff)
downloadsqlalchemy-69dcd805d2c6ed92adf81da443c5c06d23d3423a.tar.gz
- Added explicit true()/false() constructs to expression
lib - coercion rules will intercept "False"/"True" into these constructs. In 0.6, the constructs were typically converted straight to string, which was no longer accepted in 0.7. [ticket:2117]
Diffstat (limited to 'test/sql/test_compiler.py')
-rw-r--r--test/sql/test_compiler.py65
1 files changed, 64 insertions, 1 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 678411fe2..7e95f83ef 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -3,7 +3,7 @@ import datetime, re, operator, decimal
from sqlalchemy import *
from sqlalchemy import exc, sql, util
from sqlalchemy.sql import table, column, label, compiler
-from sqlalchemy.sql.expression import ClauseList
+from sqlalchemy.sql.expression import ClauseList, _literal_as_text
from sqlalchemy.engine import default
from sqlalchemy.databases import *
from test.lib import *
@@ -2812,3 +2812,66 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL):
"INSERT INTO remote_owner.remotetable (rem_id, datatype_id, value) VALUES "
"(:rem_id, :datatype_id, :value)")
+
+class CoercionTest(fixtures.TestBase, AssertsCompiledSQL):
+ __dialect__ = 'default'
+
+ def _fixture(self):
+ m = MetaData()
+ return Table('foo', m,
+ Column('id', Integer))
+
+ def test_null_constant(self):
+ t = self._fixture()
+ self.assert_compile(_literal_as_text(None), "NULL")
+
+ def test_false_constant(self):
+ t = self._fixture()
+ self.assert_compile(_literal_as_text(False), "false")
+
+ def test_true_constant(self):
+ t = self._fixture()
+ self.assert_compile(_literal_as_text(True), "true")
+
+ def test_val_and_false(self):
+ t = self._fixture()
+ self.assert_compile(and_(t.c.id == 1, False),
+ "foo.id = :id_1 AND false")
+
+ def test_val_and_true_coerced(self):
+ t = self._fixture()
+ self.assert_compile(and_(t.c.id == 1, True),
+ "foo.id = :id_1 AND true")
+
+ def test_val_is_null_coerced(self):
+ t = self._fixture()
+ self.assert_compile(and_(t.c.id == None),
+ "foo.id IS NULL")
+
+ def test_val_and_None(self):
+ # current convention is None in and_() or
+ # other clauselist is ignored. May want
+ # to revise this at some point.
+ t = self._fixture()
+ self.assert_compile(and_(t.c.id == 1, None),
+ "foo.id = :id_1")
+
+ def test_None_and_val(self):
+ # current convention is None in and_() or
+ # other clauselist is ignored. May want
+ # to revise this at some point.
+ t = self._fixture()
+ self.assert_compile(and_(t.c.id == 1, None),
+ "foo.id = :id_1")
+
+ def test_None_and_nothing(self):
+ # current convention is None in and_()
+ # returns None May want
+ # to revise this at some point.
+ assert and_(None) is None
+
+ def test_val_and_null(self):
+ t = self._fixture()
+ self.assert_compile(and_(t.c.id == 1, null()),
+ "foo.id = :id_1 AND NULL")
+