MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_comparison_op

Method test_comparison_op

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

Source from the content-addressed store, hash-verified

2950 id_="naa",
2951 )
2952 def test_comparison_op(self, py_op, fwd_op, rev_op):
2953 dt = datetime.datetime(2012, 5, 10, 15, 27, 18)
2954 for lhs, rhs, l_sql, r_sql in (
2955 ("a", self.table1.c.myid, ":myid_1", "mytable.myid"),
2956 ("a", literal("b"), ":param_2", ":param_1"), # note swap!
2957 (self.table1.c.myid, "b", "mytable.myid", ":myid_1"),
2958 (self.table1.c.myid, literal("b"), "mytable.myid", ":param_1"),
2959 (
2960 self.table1.c.myid,
2961 self.table1.c.myid,
2962 "mytable.myid",
2963 "mytable.myid",
2964 ),
2965 (literal("a"), "b", ":param_1", ":param_2"),
2966 (literal("a"), self.table1.c.myid, ":param_1", "mytable.myid"),
2967 (literal("a"), literal("b"), ":param_1", ":param_2"),
2968 (dt, literal("b"), ":param_2", ":param_1"),
2969 (literal("b"), dt, ":param_1", ":param_2"),
2970 ):
2971 # the compiled clause should match either (e.g.):
2972 # 'a' < 'b' -or- 'b' > 'a'.
2973 compiled = str(py_op(lhs, rhs))
2974 fwd_sql = "%s %s %s" % (l_sql, fwd_op, r_sql)
2975 rev_sql = "%s %s %s" % (r_sql, rev_op, l_sql)
2976
2977 self.assert_(
2978 compiled == fwd_sql or compiled == rev_sql,
2979 "\n'"
2980 + compiled
2981 + "'\n does not match\n'"
2982 + fwd_sql
2983 + "'\n or\n'"
2984 + rev_sql
2985 + "'",
2986 )
2987
2988
2989class 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