MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_in_expressions

Method test_in_expressions

test/sql/test_lambdas.py:151–189  ·  view source on GitHub ↗

test #6397. we initially were going to use two different forms for "empty in" vs. regular "in", but instead we have an improved substitution for "empty in". regardless, as there's more going on with these, make sure lambdas work with them including caching.

(self, user_address_fixture, connection)

Source from the content-addressed store, hash-verified

149 eq_(result.all(), [(2,)])
150
151 def test_in_expressions(self, user_address_fixture, connection):
152 """test #6397. we initially were going to use two different
153 forms for "empty in" vs. regular "in", but instead we have an
154 improved substitution for "empty in". regardless, as there's more
155 going on with these, make sure lambdas work with them including
156 caching.
157
158 """
159 users, _ = user_address_fixture
160 data = [
161 {"id": 1, "name": "u1"},
162 {"id": 2, "name": "u2"},
163 {"id": 3, "name": "u3"},
164 ]
165 connection.execute(users.insert(), data)
166
167 def go(val):
168 stmt = lambdas.lambda_stmt(lambda: select(users.c.id))
169 stmt += lambda s: s.where(users.c.name.in_(val))
170 stmt += lambda s: s.order_by(users.c.id)
171 return connection.execute(stmt)
172
173 for case in [
174 [],
175 ["u1", "u2"],
176 ["u3"],
177 [],
178 ["u1", "u2"],
179 ]:
180 with testing.assertsql.assert_engine(testing.db) as asserter_:
181 result = go(case)
182 asserter_.assert_(
183 CompiledSQL(
184 "SELECT users.id FROM users WHERE users.name "
185 "IN (__[POSTCOMPILE_val_1]) ORDER BY users.id",
186 params={"val_1": case},
187 )
188 )
189 eq_(result.all(), [(e["id"],) for e in data if e["name"] in case])
190
191 def test_in_expr_compile(self, user_address_fixture):
192 users, _ = user_address_fixture

Callers

nothing calls this directly

Calls 7

CompiledSQLClass · 0.90
eq_Function · 0.90
goFunction · 0.50
executeMethod · 0.45
insertMethod · 0.45
assert_Method · 0.45
allMethod · 0.45

Tested by

no test coverage detected