summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-04-21 13:35:38 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-04-21 13:35:38 -0400
commit920f77e3c17ec43382e60a992dc4dcec2ba173b8 (patch)
treef1bf8b09a0569a7f3e2c8e1fd35fc63c15bd0930 /test/sql
parentae3ffcf4ea2c131c720a584c29ae66444d929b77 (diff)
downloadsqlalchemy-920f77e3c17ec43382e60a992dc4dcec2ba173b8.tar.gz
Add _negate() to Label to negate inner element
Fixed the negation of a :class:`.Label` construct so that the inner element is negated correctly, when the :func:`.not_` modifier is applied to the labeled expression. Change-Id: Ia99917b2959bdfbff28689c962b4203911c57b85 Fixes: #3969
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_operators.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py
index ac05d3a81..c0637d225 100644
--- a/test/sql/test_operators.py
+++ b/test/sql/test_operators.py
@@ -11,7 +11,7 @@ import operator
from sqlalchemy import String, Integer, LargeBinary
from sqlalchemy import exc
from sqlalchemy.engine import default
-from sqlalchemy.sql.elements import _literal_as_text
+from sqlalchemy.sql.elements import _literal_as_text, Label
from sqlalchemy.schema import Column, Table, MetaData
from sqlalchemy.sql import compiler
from sqlalchemy.types import TypeEngine, TypeDecorator, UserDefinedType, \
@@ -2079,6 +2079,20 @@ class NegationTest(fixtures.TestBase, testing.AssertsCompiledSQL):
self.table1.c.myid.type,
)
+ def test_negate_operator_label(self):
+ orig_expr = or_(
+ self.table1.c.myid == 1, self.table1.c.myid == 2).label('foo')
+ expr = not_(orig_expr)
+ isinstance(expr, Label)
+ eq_(expr.name, 'foo')
+ is_not_(expr, orig_expr)
+ is_(expr._element.operator, operator.inv) # e.g. and not false_
+
+ self.assert_compile(
+ expr,
+ "NOT (mytable.myid = :myid_1 OR mytable.myid = :myid_2)"
+ )
+
class LikeTest(fixtures.TestBase, testing.AssertsCompiledSQL):
__dialect__ = 'default'