MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_in_scalar_grouping

Method test_in_scalar_grouping

test/sql/test_operators.py:2559–2602  ·  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

2557 )
2558
2559 def test_in_scalar_grouping(self):
2560 """test for :ticket:`12987`
2561
2562 Test that using in_() with a nested CompoundSelect works correctly.
2563 This occurs when a CompoundSelect is the first argument to another
2564 CompoundSelect.
2565
2566 """
2567
2568 t = self.table1
2569
2570 # Create nested compound selects
2571 inner_compound_stmt = union(
2572 select(t.c.myid).where(t.c.myid == 5),
2573 select(t.c.myid).where(t.c.myid == 6),
2574 )
2575 simple_stmt = select(t.c.myid).where(t.c.myid == 7)
2576
2577 # When simple statement is first, should work
2578 outer_compound_stmt = intersect(simple_stmt, inner_compound_stmt)
2579 self.assert_compile(
2580 select(t).where(t.c.myid.in_(outer_compound_stmt)),
2581 "SELECT mytable.myid FROM mytable "
2582 "WHERE mytable.myid IN ("
2583 "SELECT mytable.myid FROM mytable WHERE mytable.myid = :myid_1 "
2584 "INTERSECT (SELECT mytable.myid FROM mytable "
2585 "WHERE mytable.myid = :myid_2 "
2586 "UNION SELECT mytable.myid FROM mytable "
2587 "WHERE mytable.myid = :myid_3))",
2588 )
2589
2590 # When compound statement is first, previously raised
2591 # NotImplementedError
2592 outer_compound_stmt = intersect(inner_compound_stmt, simple_stmt)
2593 self.assert_compile(
2594 select(t).where(t.c.myid.in_(outer_compound_stmt)),
2595 "SELECT mytable.myid FROM mytable "
2596 "WHERE mytable.myid IN ("
2597 "(SELECT mytable.myid FROM mytable WHERE mytable.myid = :myid_1 "
2598 "UNION SELECT mytable.myid FROM mytable "
2599 "WHERE mytable.myid = :myid_2) "
2600 "INTERSECT SELECT mytable.myid FROM mytable "
2601 "WHERE mytable.myid = :myid_3)",
2602 )
2603
2604 @testing.combinations(True, False, argnames="is_in")
2605 @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