summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorSebastian Bank <sebastian.bank@uni-leipzig.de>2016-04-11 23:16:32 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-06-06 15:53:25 -0400
commit3351f5f93ca1968653becbed7f1ddef7afb96077 (patch)
tree0bc2a08dd5809522e23eed7a47b9f11bf95ad4b2 /test/sql
parenta5f92314edd45a2e411b0f5b3c4d4bec0c7d92f8 (diff)
downloadsqlalchemy-3351f5f93ca1968653becbed7f1ddef7afb96077.tar.gz
Add IS (NOT) DISTINCT FROM operators
None / True / False render as literals. For SQLite, "IS" is used as SQLite lacks "IS DISTINCT FROM" but its "IS" operator acts this way for NULL. Doctext-author: Mike Bayer <mike_mp@zzzcomputing.com> Change-Id: I9227b81f7207b42627a0349d14d40b46aa756cce Pull-request: https://github.com/zzzeek/sqlalchemy/pull/248
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_operators.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py
index 86286a9a3..5712d8f99 100644
--- a/test/sql/test_operators.py
+++ b/test/sql/test_operators.py
@@ -99,6 +99,18 @@ class DefaultColumnComparatorTest(fixtures.TestBase):
def test_notequals_true(self):
self._do_operate_test(operators.ne, True)
+ def test_is_distinct_from_true(self):
+ self._do_operate_test(operators.is_distinct_from, True)
+
+ def test_is_distinct_from_false(self):
+ self._do_operate_test(operators.is_distinct_from, False)
+
+ def test_is_distinct_from_null(self):
+ self._do_operate_test(operators.is_distinct_from, None)
+
+ def test_isnot_distinct_from_true(self):
+ self._do_operate_test(operators.isnot_distinct_from, True)
+
def test_is_true(self):
self._do_operate_test(operators.is_, True)
@@ -1527,6 +1539,60 @@ class OperatorAssociativityTest(fixtures.TestBase, testing.AssertsCompiledSQL):
self.assert_compile(f / (f / (f - f)), "f / (f / (f - f))")
+class IsDistinctFromTest(fixtures.TestBase, testing.AssertsCompiledSQL):
+ __dialect__ = 'default'
+
+ table1 = table('mytable',
+ column('myid', Integer),
+ )
+
+ def test_is_distinct_from(self):
+ self.assert_compile(self.table1.c.myid.is_distinct_from(1),
+ "mytable.myid IS DISTINCT FROM :myid_1")
+
+ def test_is_distinct_from_sqlite(self):
+ self.assert_compile(self.table1.c.myid.is_distinct_from(1),
+ "mytable.myid IS NOT ?",
+ dialect=sqlite.dialect())
+
+ def test_is_distinct_from_postgresql(self):
+ self.assert_compile(self.table1.c.myid.is_distinct_from(1),
+ "mytable.myid IS DISTINCT FROM %(myid_1)s",
+ dialect=postgresql.dialect())
+
+ def test_not_is_distinct_from(self):
+ self.assert_compile(~self.table1.c.myid.is_distinct_from(1),
+ "mytable.myid IS NOT DISTINCT FROM :myid_1")
+
+ def test_not_is_distinct_from_postgresql(self):
+ self.assert_compile(~self.table1.c.myid.is_distinct_from(1),
+ "mytable.myid IS NOT DISTINCT FROM %(myid_1)s",
+ dialect=postgresql.dialect())
+
+ def test_isnot_distinct_from(self):
+ self.assert_compile(self.table1.c.myid.isnot_distinct_from(1),
+ "mytable.myid IS NOT DISTINCT FROM :myid_1")
+
+ def test_isnot_distinct_from_sqlite(self):
+ self.assert_compile(self.table1.c.myid.isnot_distinct_from(1),
+ "mytable.myid IS ?",
+ dialect=sqlite.dialect())
+
+ def test_isnot_distinct_from_postgresql(self):
+ self.assert_compile(self.table1.c.myid.isnot_distinct_from(1),
+ "mytable.myid IS NOT DISTINCT FROM %(myid_1)s",
+ dialect=postgresql.dialect())
+
+ def test_not_isnot_distinct_from(self):
+ self.assert_compile(~self.table1.c.myid.isnot_distinct_from(1),
+ "mytable.myid IS DISTINCT FROM :myid_1")
+
+ def test_not_isnot_distinct_from_postgresql(self):
+ self.assert_compile(~self.table1.c.myid.isnot_distinct_from(1),
+ "mytable.myid IS DISTINCT FROM %(myid_1)s",
+ dialect=postgresql.dialect())
+
+
class InTest(fixtures.TestBase, testing.AssertsCompiledSQL):
__dialect__ = 'default'