MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_comparison_op

Method test_comparison_op

test/sql/test_operators.py:2778–2812  ·  view source on GitHub ↗
(self, py_op, fwd_op, rev_op)

Source from the content-addressed store, hash-verified

2776 id_="naa",
2777 )
2778 def test_comparison_op(self, py_op, fwd_op, rev_op):
2779 dt = datetime.datetime(2012, 5, 10, 15, 27, 18)
2780 for lhs, rhs, l_sql, r_sql in (
2781 ("a", self.table1.c.myid, ":myid_1", "mytable.myid"),
2782 ("a", literal("b"), ":param_2", ":param_1"), # note swap!
2783 (self.table1.c.myid, "b", "mytable.myid", ":myid_1"),
2784 (self.table1.c.myid, literal("b"), "mytable.myid", ":param_1"),
2785 (
2786 self.table1.c.myid,
2787 self.table1.c.myid,
2788 "mytable.myid",
2789 "mytable.myid",
2790 ),
2791 (literal("a"), "b", ":param_1", ":param_2"),
2792 (literal("a"), self.table1.c.myid, ":param_1", "mytable.myid"),
2793 (literal("a"), literal("b"), ":param_1", ":param_2"),
2794 (dt, literal("b"), ":param_2", ":param_1"),
2795 (literal("b"), dt, ":param_1", ":param_2"),
2796 ):
2797 # the compiled clause should match either (e.g.):
2798 # 'a' < 'b' -or- 'b' > 'a'.
2799 compiled = str(py_op(lhs, rhs))
2800 fwd_sql = "%s %s %s" % (l_sql, fwd_op, r_sql)
2801 rev_sql = "%s %s %s" % (r_sql, rev_op, l_sql)
2802
2803 self.assert_(
2804 compiled == fwd_sql or compiled == rev_sql,
2805 "\n'"
2806 + compiled
2807 + "'\n does not match\n'"
2808 + fwd_sql
2809 + "'\n or\n'"
2810 + rev_sql
2811 + "'",
2812 )
2813
2814
2815class NonZeroTest(fixtures.TestBase):

Callers

nothing calls this directly

Calls 3

literalFunction · 0.90
datetimeMethod · 0.45
assert_Method · 0.45

Tested by

no test coverage detected