summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-11-25 12:20:13 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-11-25 12:20:13 -0500
commit77f641429f019d06cc467ec4e57ae94f808d70bd (patch)
tree94ddacadb8915d19d3ee3cdf7a3771fa63ba0184 /test
parent5247c244ca6595f2685f1c0c271618eda7cb5e62 (diff)
downloadsqlalchemy-77f641429f019d06cc467ec4e57ae94f808d70bd.tar.gz
- Fixed operator precedence rules for multiple
chains of a single non-associative operator. I.e. "x - (y - z)" will compile as "x - (y - z)" and not "x - y - z". Also works with labels, i.e. "x - (y - z).label('foo')" [ticket:1984] - Single element tuple expressions inside an IN clause parenthesize correctly, also from [ticket:1984], added tests for PG - re-fix again importlater, [ticket:1983]
Diffstat (limited to 'test')
-rw-r--r--test/base/test_utils.py2
-rw-r--r--test/dialect/test_postgresql.py31
-rw-r--r--test/sql/test_compiler.py42
3 files changed, 70 insertions, 5 deletions
diff --git a/test/base/test_utils.py b/test/base/test_utils.py
index d083a8458..e7ecbec51 100644
--- a/test/base/test_utils.py
+++ b/test/base/test_utils.py
@@ -149,8 +149,6 @@ class ColumnCollectionTest(TestBase):
assert (cc1==cc2).compare(c1 == c2)
assert not (cc1==cc3).compare(c2 == c3)
-
-
class LRUTest(TestBase):
def test_lru(self):
diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py
index 150dacf18..92c089480 100644
--- a/test/dialect/test_postgresql.py
+++ b/test/dialect/test_postgresql.py
@@ -2046,3 +2046,34 @@ class MatchTest(TestBase, AssertsCompiledSQL):
matchtable.c.title.match('nutshells'
)))).order_by(matchtable.c.id).execute().fetchall()
eq_([1, 3, 5], [r.id for r in results])
+
+
+class TupleTest(TestBase):
+ __only_on__ = 'postgresql'
+
+ def test_tuple_containment(self):
+
+ for test, exp in [
+ ([('a', 'b')], True),
+ ([('a', 'c')], False),
+ ([('f', 'q'), ('a', 'b')], True),
+ ([('f', 'q'), ('a', 'c')], False)
+ ]:
+ eq_(
+ testing.db.execute(
+ select([
+ tuple_(
+ literal_column("'a'"),
+ literal_column("'b'")
+ ).\
+ in_([
+ tuple_(*[
+ literal_column("'%s'" % letter)
+ for letter in elem
+ ]) for elem in test
+ ])
+ ])
+ ).scalar(),
+ exp
+ )
+
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 338a5491e..93c0d6587 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -678,7 +678,7 @@ class SelectTest(TestBase, AssertsCompiledSQL):
select([func.count(distinct(table1.c.myid))]),
"SELECT count(DISTINCT mytable.myid) AS count_1 FROM mytable"
)
-
+
def test_operators(self):
for (py_op, sql_op) in ((operator.add, '+'), (operator.mul, '*'),
(operator.sub, '-'),
@@ -1293,7 +1293,7 @@ class SelectTest(TestBase, AssertsCompiledSQL):
self.assert_compile(
select([value_tbl.c.id], value_tbl.c.val1 / (value_tbl.c.val2 - value_tbl.c.val1) /value_tbl.c.val1 > 2.0),
- "SELECT values.id FROM values WHERE values.val1 / (values.val2 - values.val1) / values.val1 > :param_1"
+ "SELECT values.id FROM values WHERE (values.val1 / (values.val2 - values.val1)) / values.val1 > :param_1"
)
def test_collate(self):
@@ -1925,7 +1925,7 @@ class SelectTest(TestBase, AssertsCompiledSQL):
tuple_(table1.c.myid, table1.c.name).in_(
[tuple_(table2.c.otherid, table2.c.othername)]
),
- "(mytable.myid, mytable.name) IN (myothertable.otherid, myothertable.othername)"
+ "(mytable.myid, mytable.name) IN ((myothertable.otherid, myothertable.othername))"
)
self.assert_compile(
@@ -2044,6 +2044,42 @@ class SelectTest(TestBase, AssertsCompiledSQL):
self.assert_compile(table.select(between((table.c.field == table.c.field), False, True)),
"SELECT op.field FROM op WHERE (op.field = op.field) BETWEEN :param_1 AND :param_2")
+ def test_associativity(self):
+ f = column('f')
+ self.assert_compile( f - f, "f - f" )
+ self.assert_compile( f - f - f, "(f - f) - f" )
+
+ self.assert_compile( (f - f) - f, "(f - f) - f" )
+ self.assert_compile( (f - f).label('foo') - f, "(f - f) - f" )
+
+ self.assert_compile( f - (f - f), "f - (f - f)" )
+ self.assert_compile( f - (f - f).label('foo'), "f - (f - f)" )
+
+ # because - less precedent than /
+ self.assert_compile( f / (f - f), "f / (f - f)" )
+ self.assert_compile( f / (f - f).label('foo'), "f / (f - f)" )
+
+ self.assert_compile( f / f - f, "f / f - f" )
+ self.assert_compile( (f / f) - f, "f / f - f" )
+ self.assert_compile( (f / f).label('foo') - f, "f / f - f" )
+
+ # because / more precedent than -
+ self.assert_compile( f - (f / f), "f - f / f" )
+ self.assert_compile( f - (f / f).label('foo'), "f - f / f" )
+ self.assert_compile( f - f / f, "f - f / f" )
+ self.assert_compile( (f - f) / f, "(f - f) / f" )
+
+ self.assert_compile( ((f - f) / f) - f, "(f - f) / f - f")
+ self.assert_compile( (f - f) / (f - f), "(f - f) / (f - f)")
+
+ # higher precedence
+ self.assert_compile( (f / f) - (f / f), "f / f - f / f")
+
+ self.assert_compile( (f / f) - (f - f), "f / f - (f - f)")
+ self.assert_compile( (f / f) / (f - f), "(f / f) / (f - f)")
+ self.assert_compile( f / (f / (f - f)), "f / (f / (f - f))")
+
+
def test_delayed_col_naming(self):
my_str = Column(String)