summaryrefslogtreecommitdiff
path: root/test/sql/test_operators.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-03-14 12:00:56 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-03-14 17:01:07 -0400
commitf3b6f4f8da5223fae0a1dd948d4266b2e49e317c (patch)
tree9cae69a0b1680161a5e6604371a17b5766c3dc34 /test/sql/test_operators.py
parent596e322543df6ff380243c9cb0cf9997252329f6 (diff)
downloadsqlalchemy-f3b6f4f8da5223fae0a1dd948d4266b2e49e317c.tar.gz
Add "empty in" strategies; default to "static"
The longstanding behavior of the :meth:`.Operators.in_` and :meth:`.Operators.not_in_` operators emitting a warning when the right-hand condition is an empty sequence has been revised; a new flag :paramref:`.create_engine.empty_in_strategy` allows an empty "IN" expression to generate a simple boolean expression, or to invoke the previous behavior of dis-equating the expression to itself, with or without a warning. The default behavior is now to emit the simple boolean expression, allowing an empty IN to be evaulated without any performance penalty. Change-Id: I65cc37f2d7cf65a59bf217136c42fee446929352 Fixes: #3907
Diffstat (limited to 'test/sql/test_operators.py')
-rw-r--r--test/sql/test_operators.py60
1 files changed, 49 insertions, 11 deletions
diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py
index 0bdebab58..0e0a8b29c 100644
--- a/test/sql/test_operators.py
+++ b/test/sql/test_operators.py
@@ -1638,6 +1638,11 @@ class InTest(fixtures.TestBase, testing.AssertsCompiledSQL):
column('othername', String)
)
+ def _dialect(self, empty_in_strategy="static"):
+ return default.DefaultDialect(
+ empty_in_strategy=empty_in_strategy
+ )
+
def test_in_1(self):
self.assert_compile(self.table1.c.myid.in_(['a']),
"mytable.myid IN (:myid_1)")
@@ -1751,11 +1756,6 @@ class InTest(fixtures.TestBase, testing.AssertsCompiledSQL):
"FROM myothertable)"
)
- @testing.emits_warning('.*empty sequence.*')
- def test_in_23(self):
- self.assert_compile(self.table1.c.myid.in_([]),
- "mytable.myid != mytable.myid")
-
def test_in_24(self):
self.assert_compile(
select([self.table1.c.myid.in_(select([self.table2.c.otherid]))]),
@@ -1812,15 +1812,53 @@ class InTest(fixtures.TestBase, testing.AssertsCompiledSQL):
"mytable.myid IN (NULL)"
)
- @testing.emits_warning('.*empty sequence.*')
- def test_in_29(self):
+ def test_empty_in_dynamic_1(self):
+ self.assert_compile(self.table1.c.myid.in_([]),
+ "mytable.myid != mytable.myid",
+ dialect=self._dialect("dynamic"))
+
+ def test_empty_in_dynamic_2(self):
+ self.assert_compile(self.table1.c.myid.notin_([]),
+ "mytable.myid = mytable.myid",
+ dialect=self._dialect("dynamic"))
+
+ def test_empty_in_dynamic_3(self):
+ self.assert_compile(~self.table1.c.myid.in_([]),
+ "mytable.myid = mytable.myid",
+ dialect=self._dialect("dynamic"))
+
+ def test_empty_in_dynamic_warn_1(self):
+ with testing.expect_warnings(
+ "The IN-predicate was invoked with an empty sequence."):
+ self.assert_compile(self.table1.c.myid.in_([]),
+ "mytable.myid != mytable.myid",
+ dialect=self._dialect("dynamic_warn"))
+
+ def test_empty_in_dynamic_warn_2(self):
+ with testing.expect_warnings(
+ "The IN-predicate was invoked with an empty sequence."):
+ self.assert_compile(self.table1.c.myid.notin_([]),
+ "mytable.myid = mytable.myid",
+ dialect=self._dialect("dynamic_warn"))
+
+ def test_empty_in_dynamic_warn_3(self):
+ with testing.expect_warnings(
+ "The IN-predicate was invoked with an empty sequence."):
+ self.assert_compile(~self.table1.c.myid.in_([]),
+ "mytable.myid = mytable.myid",
+ dialect=self._dialect("dynamic_warn"))
+
+ def test_empty_in_static_1(self):
+ self.assert_compile(self.table1.c.myid.in_([]),
+ "1 != 1")
+
+ def test_empty_in_static_2(self):
self.assert_compile(self.table1.c.myid.notin_([]),
- "mytable.myid = mytable.myid")
+ "1 = 1")
- @testing.emits_warning('.*empty sequence.*')
- def test_in_30(self):
+ def test_empty_in_static_3(self):
self.assert_compile(~self.table1.c.myid.in_([]),
- "mytable.myid = mytable.myid")
+ "1 = 1")
class MathOperatorTest(fixtures.TestBase, testing.AssertsCompiledSQL):