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

Method test_in_scalar_grouping

test/sql/test_operators.py:2393–2436  ·  view source on GitHub ↗

test for :ticket:`12987` Test that using in_() with a nested CompoundSelect works correctly. This occurs when a CompoundSelect is the first argument to another CompoundSelect.

(self)

Source from the content-addressed store, hash-verified

2391 )
2392
2393 def test_in_scalar_grouping(self):
2394 """test for :ticket:`12987`
2395
2396 Test that using in_() with a nested CompoundSelect works correctly.
2397 This occurs when a CompoundSelect is the first argument to another
2398 CompoundSelect.
2399
2400 """
2401
2402 t = self.table1
2403
2404 # Create nested compound selects
2405 inner_compound_stmt = union(
2406 select(t.c.myid).where(t.c.myid == 5),
2407 select(t.c.myid).where(t.c.myid == 6),
2408 )
2409 simple_stmt = select(t.c.myid).where(t.c.myid == 7)
2410
2411 # When simple statement is first, should work
2412 outer_compound_stmt = intersect(simple_stmt, inner_compound_stmt)
2413 self.assert_compile(
2414 select(t).where(t.c.myid.in_(outer_compound_stmt)),
2415 "SELECT mytable.myid FROM mytable "
2416 "WHERE mytable.myid IN ("
2417 "SELECT mytable.myid FROM mytable WHERE mytable.myid = :myid_1 "
2418 "INTERSECT (SELECT mytable.myid FROM mytable "
2419 "WHERE mytable.myid = :myid_2 "
2420 "UNION SELECT mytable.myid FROM mytable "
2421 "WHERE mytable.myid = :myid_3))",
2422 )
2423
2424 # When compound statement is first, previously raised
2425 # NotImplementedError
2426 outer_compound_stmt = intersect(inner_compound_stmt, simple_stmt)
2427 self.assert_compile(
2428 select(t).where(t.c.myid.in_(outer_compound_stmt)),
2429 "SELECT mytable.myid FROM mytable "
2430 "WHERE mytable.myid IN ("
2431 "(SELECT mytable.myid FROM mytable WHERE mytable.myid = :myid_1 "
2432 "UNION SELECT mytable.myid FROM mytable "
2433 "WHERE mytable.myid = :myid_2) "
2434 "INTERSECT SELECT mytable.myid FROM mytable "
2435 "WHERE mytable.myid = :myid_3)",
2436 )
2437
2438 @testing.combinations(True, False, argnames="is_in")
2439 @testing.combinations(True, False, argnames="negate")

Callers

nothing calls this directly

Calls 6

intersectFunction · 0.90
unionFunction · 0.85
selectFunction · 0.85
assert_compileMethod · 0.80
whereMethod · 0.45
in_Method · 0.45

Tested by

no test coverage detected