MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_a_in_b

Method test_a_in_b

test/sql/test_defaults.py:904–951  ·  view source on GitHub ↗
(self, a, b, connection)

Source from the content-addressed store, hash-verified

902 argnames="a, b",
903 )
904 def test_a_in_b(self, a, b, connection):
905 q = self.tables.q
906 p = self.tables.p
907
908 conn = connection
909 if a == "delete":
910 conn.execute(q.insert().values(y=10, z=1))
911 cte = q.delete().where(q.c.z == 1).returning(q.c.z).cte("c")
912 expected = None
913 elif a == "insert":
914 cte = q.insert().values(z=1, y=10).returning(q.c.z).cte("c")
915 expected = (2, 10)
916 elif a == "update":
917 conn.execute(q.insert().values(x=5, y=10, z=1))
918 cte = (
919 q.update()
920 .where(q.c.z == 1)
921 .values(x=7)
922 .returning(q.c.z)
923 .cte("c")
924 )
925 expected = (7, 5)
926 elif a == "select":
927 conn.execute(q.insert().values(x=5, y=10, z=1))
928 cte = sa.select(q.c.z).cte("c")
929 expected = (5, 10)
930
931 if b == "select":
932 conn.execute(p.insert().values(s=1))
933 stmt = select(p.c.s, cte.c.z).where(p.c.s == cte.c.z)
934 elif b == "insert":
935 sel = select(1, cte.c.z)
936 stmt = (
937 p.insert().from_select(["s", "t"], sel).returning(p.c.s, p.c.t)
938 )
939 elif b == "delete":
940 stmt = p.insert().values(s=1, t=cte.c.z).returning(p.c.s, cte.c.z)
941 elif b == "update":
942 conn.execute(p.insert().values(s=1))
943 stmt = (
944 p.update()
945 .values(t=5)
946 .where(p.c.s == cte.c.z)
947 .returning(p.c.u, cte.c.z)
948 )
949 eq_(list(conn.execute(stmt)), [(1, 1)])
950
951 eq_(conn.execute(select(q.c.x, q.c.y)).first(), expected)
952
953
954class PKDefaultTest(fixtures.TestBase):

Callers

nothing calls this directly

Calls 13

selectFunction · 0.90
eq_Function · 0.90
from_selectMethod · 0.80
executeMethod · 0.45
valuesMethod · 0.45
insertMethod · 0.45
cteMethod · 0.45
returningMethod · 0.45
whereMethod · 0.45
deleteMethod · 0.45
updateMethod · 0.45
selectMethod · 0.45

Tested by

no test coverage detected