MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_add_cte

Method test_add_cte

test/orm/test_core_compilation.py:629–653  ·  view source on GitHub ↗

test #10167

(self, stmt_type: testing.Variation)

Source from the content-addressed store, hash-verified

627
628 @testing.variation("stmt_type", ["core", "orm"])
629 def test_add_cte(self, stmt_type: testing.Variation):
630 """test #10167"""
631
632 if stmt_type.orm:
633 User = self.classes.User
634 cte_select = select(User.name).limit(1).cte()
635 cte_insert = insert(User).from_select(["name"], cte_select).cte()
636 elif stmt_type.core:
637 user_table = self.tables.users
638 cte_select = select(user_table.c.name).limit(1).cte()
639 cte_insert = (
640 insert(user_table).from_select(["name"], cte_select).cte()
641 )
642 else:
643 stmt_type.fail()
644
645 select_stmt = select(cte_select).add_cte(cte_insert)
646
647 self.assert_compile(
648 select_stmt,
649 "WITH anon_2 AS (SELECT users.name AS name FROM users LIMIT "
650 ":param_1), anon_1 AS (INSERT INTO users (name) "
651 "SELECT anon_2.name AS name FROM anon_2) "
652 "SELECT anon_2.name FROM anon_2",
653 )
654
655
656class ColumnsClauseFromsTest(QueryTest, AssertsCompiledSQL):

Callers

nothing calls this directly

Calls 8

selectFunction · 0.90
insertFunction · 0.90
from_selectMethod · 0.80
assert_compileMethod · 0.80
cteMethod · 0.45
limitMethod · 0.45
failMethod · 0.45
add_cteMethod · 0.45

Tested by

no test coverage detected