summaryrefslogtreecommitdiff
path: root/test/sql/test_compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-10-24 14:29:52 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-10-24 14:29:52 -0400
commite656bf4f47cf3c06975c6207ea6e54131b292bf7 (patch)
tree2fc4badbd7155898bb43261fa68d281b758ba397 /test/sql/test_compiler.py
parentc859893cb8f22db3904ec1a6aa5c71d0925fb2e6 (diff)
downloadsqlalchemy-e656bf4f47cf3c06975c6207ea6e54131b292bf7.tar.gz
- move most/all operator specific tests into test_operator, convert fully to TOT
Diffstat (limited to 'test/sql/test_compiler.py')
-rw-r--r--test/sql/test_compiler.py208
1 files changed, 0 insertions, 208 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 0febf190f..bb819472a 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -19,8 +19,6 @@ from sqlalchemy import Integer, String, MetaData, Table, Column, select, \
Float, TIMESTAMP, Numeric, Date, Text, collate, union, except_,\
intersect, union_all, Boolean, distinct, join, outerjoin, asc, desc,\
over, subquery
-import datetime
-import operator
import decimal
from sqlalchemy import exc, sql, util, types, schema
from sqlalchemy.sql import table, column, label
@@ -857,212 +855,6 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL):
"SELECT count(DISTINCT mytable.myid) AS count_1 FROM mytable"
)
- def test_math_operators(self):
- for (py_op, sql_op) in ((operator.add, '+'), (operator.mul, '*'),
- (operator.sub, '-'),
- # Py3K
- #(operator.truediv, '/'),
- # Py2K
- (operator.div, '/'),
- # end Py2K
- ):
- for (lhs, rhs, res) in (
- (5, table1.c.myid, ':myid_1 %s mytable.myid'),
- (5, literal(5), ':param_1 %s :param_2'),
- (table1.c.myid, 'b', 'mytable.myid %s :myid_1'),
- (table1.c.myid, literal(2.7), 'mytable.myid %s :param_1'),
- (table1.c.myid, table1.c.myid, 'mytable.myid %s mytable.myid'),
- (literal(5), 8, ':param_1 %s :param_2'),
- (literal(6), table1.c.myid, ':param_1 %s mytable.myid'),
- (literal(7), literal(5.5), ':param_1 %s :param_2'),
- ):
- self.assert_compile(py_op(lhs, rhs), res % sql_op)
-
- def test_comparison_operators(self):
- dt = datetime.datetime.today()
- # exercise comparison operators
- for (py_op, fwd_op, rev_op) in ((operator.lt, '<', '>'),
- (operator.gt, '>', '<'),
- (operator.eq, '=', '='),
- (operator.ne, '!=', '!='),
- (operator.le, '<=', '>='),
- (operator.ge, '>=', '<=')):
- for (lhs, rhs, l_sql, r_sql) in (
- ('a', table1.c.myid, ':myid_1', 'mytable.myid'),
- ('a', literal('b'), ':param_2', ':param_1'), # note swap!
- (table1.c.myid, 'b', 'mytable.myid', ':myid_1'),
- (table1.c.myid, literal('b'), 'mytable.myid', ':param_1'),
- (table1.c.myid, table1.c.myid, 'mytable.myid', 'mytable.myid'),
- (literal('a'), 'b', ':param_1', ':param_2'),
- (literal('a'), table1.c.myid, ':param_1', 'mytable.myid'),
- (literal('a'), literal('b'), ':param_1', ':param_2'),
- (dt, literal('b'), ':param_2', ':param_1'),
- (literal('b'), dt, ':param_1', ':param_2'),
- ):
-
- # the compiled clause should match either (e.g.):
- # 'a' < 'b' -or- 'b' > 'a'.
- compiled = str(py_op(lhs, rhs))
- fwd_sql = "%s %s %s" % (l_sql, fwd_op, r_sql)
- rev_sql = "%s %s %s" % (r_sql, rev_op, l_sql)
-
- self.assert_(compiled == fwd_sql or compiled == rev_sql,
- "\n'" + compiled + "'\n does not match\n'" +
- fwd_sql + "'\n or\n'" + rev_sql + "'")
-
- def test_negate_operators_1(self):
- for (py_op, op) in (
- (operator.neg, '-'),
- (operator.inv, 'NOT '),
- ):
- for expr, expected in (
- (table1.c.myid, "mytable.myid"),
- (literal("foo"), ":param_1"),
- ):
- self.assert_compile(py_op(expr), "%s%s" % (op, expected))
-
- def test_negate_operators_2(self):
- self.assert_compile(
- table1.select((table1.c.myid != 12) & ~(table1.c.name == 'john')),
- "SELECT mytable.myid, mytable.name, mytable.description FROM "
- "mytable WHERE mytable.myid != :myid_1 AND mytable.name != :name_1"
- )
-
- def test_negate_operators_3(self):
- self.assert_compile(
- table1.select((table1.c.myid != 12) &
- ~(table1.c.name.between('jack', 'john'))),
- "SELECT mytable.myid, mytable.name, mytable.description FROM "
- "mytable WHERE mytable.myid != :myid_1 AND "\
- "NOT (mytable.name BETWEEN :name_1 AND :name_2)"
- )
-
- def test_negate_operators_4(self):
- self.assert_compile(
- table1.select((table1.c.myid != 12) &
- ~and_(table1.c.name == 'john',
- table1.c.name == 'ed',
- table1.c.name == 'fred')),
- "SELECT mytable.myid, mytable.name, mytable.description FROM "
- "mytable WHERE mytable.myid != :myid_1 AND "\
- "NOT (mytable.name = :name_1 AND mytable.name = :name_2 "
- "AND mytable.name = :name_3)"
- )
-
- def test_negate_operators_5(self):
- self.assert_compile(
- table1.select((table1.c.myid != 12) & ~table1.c.name),
- "SELECT mytable.myid, mytable.name, mytable.description FROM "
- "mytable WHERE mytable.myid != :myid_1 AND NOT mytable.name"
- )
-
- def test_commutative_operators(self):
- self.assert_compile(
- literal("a") + literal("b") * literal("c"),
- ":param_1 || :param_2 * :param_3"
- )
-
- def test_op_operators(self):
- self.assert_compile(
- table1.select(table1.c.myid.op('hoho')(12) == 14),
- "SELECT mytable.myid, mytable.name, mytable.description FROM "
- "mytable WHERE (mytable.myid hoho :myid_1) = :param_1"
- )
-
- def test_op_operators_comma_precedence(self):
- self.assert_compile(
- func.foo(table1.c.myid.op('hoho')(12)),
- "foo(mytable.myid hoho :myid_1)"
- )
-
- def test_op_operators_comparison_precedence(self):
- self.assert_compile(
- table1.c.myid.op('hoho')(12) == 5,
- "(mytable.myid hoho :myid_1) = :param_1"
- )
-
- def test_op_operators_custom_precedence(self):
- op1 = table1.c.myid.op('hoho', precedence=5)
- op2 = op1(5).op('lala', precedence=4)(4)
- op3 = op1(5).op('lala', precedence=6)(4)
-
- self.assert_compile(op2, "mytable.myid hoho :myid_1 lala :param_1")
- self.assert_compile(op3, "(mytable.myid hoho :myid_1) lala :param_1")
-
- def test_pickle_operators(self):
- clause = (table1.c.myid == 12) & table1.c.myid.between(15, 20) & \
- table1.c.myid.like('hoho')
- eq_(str(clause), str(util.pickle.loads(util.pickle.dumps(clause))))
-
- clause = tuple_(1, 2, 3)
- eq_(str(clause), str(util.pickle.loads(util.pickle.dumps(clause))))
-
- def test_like(self):
- for expr, check, dialect in [
- (
- table1.c.myid.like('somstr'),
- "mytable.myid LIKE :myid_1", None),
- (
- ~table1.c.myid.like('somstr'),
- "mytable.myid NOT LIKE :myid_1", None),
- (
- table1.c.myid.like('somstr', escape='\\'),
- "mytable.myid LIKE :myid_1 ESCAPE '\\'",
- None),
- (
- ~table1.c.myid.like('somstr', escape='\\'),
- "mytable.myid NOT LIKE :myid_1 ESCAPE '\\'",
- None),
- (
- table1.c.myid.ilike('somstr', escape='\\'),
- "lower(mytable.myid) LIKE lower(:myid_1) ESCAPE '\\'",
- None),
- (
- ~table1.c.myid.ilike('somstr', escape='\\'),
- "lower(mytable.myid) NOT LIKE lower(:myid_1) ESCAPE '\\'",
- None),
- (
- table1.c.myid.ilike('somstr', escape='\\'),
- "mytable.myid ILIKE %(myid_1)s ESCAPE '\\\\'",
- postgresql.dialect()),
- (
- ~table1.c.myid.ilike('somstr', escape='\\'),
- "mytable.myid NOT ILIKE %(myid_1)s ESCAPE '\\\\'",
- postgresql.dialect()),
- (
- table1.c.name.ilike('%something%'),
- "lower(mytable.name) LIKE lower(:name_1)", None),
- (
- table1.c.name.ilike('%something%'),
- "mytable.name ILIKE %(name_1)s", postgresql.dialect()),
- (
- ~table1.c.name.ilike('%something%'),
- "lower(mytable.name) NOT LIKE lower(:name_1)", None),
- (
- ~table1.c.name.ilike('%something%'),
- "mytable.name NOT ILIKE %(name_1)s",
- postgresql.dialect()),
- ]:
- self.assert_compile(expr, check, dialect=dialect)
-
- def test_match(self):
- for expr, check, dialect in [
- (table1.c.myid.match('somstr'),
- "mytable.myid MATCH ?", sqlite.dialect()),
- (table1.c.myid.match('somstr'),
- "MATCH (mytable.myid) AGAINST (%s IN BOOLEAN MODE)",
- mysql.dialect()),
- (table1.c.myid.match('somstr'),
- "CONTAINS (mytable.myid, :myid_1)",
- mssql.dialect()),
- (table1.c.myid.match('somstr'),
- "mytable.myid @@ to_tsquery(%(myid_1)s)",
- postgresql.dialect()),
- (table1.c.myid.match('somstr'),
- "CONTAINS (mytable.myid, :myid_1)",
- oracle.dialect()),
- ]:
- self.assert_compile(expr, check, dialect=dialect)
def test_multiple_col_binds(self):