summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/testing')
-rw-r--r--lib/sqlalchemy/testing/requirements.py2
-rw-r--r--lib/sqlalchemy/testing/suite/test_cte.py36
-rw-r--r--lib/sqlalchemy/testing/suite/test_deprecations.py34
-rw-r--r--lib/sqlalchemy/testing/suite/test_dialect.py8
-rw-r--r--lib/sqlalchemy/testing/suite/test_insert.py26
-rw-r--r--lib/sqlalchemy/testing/suite/test_results.py26
-rw-r--r--lib/sqlalchemy/testing/suite/test_select.py172
7 files changed, 130 insertions, 174 deletions
diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py
index 4114137d4..302a02419 100644
--- a/lib/sqlalchemy/testing/requirements.py
+++ b/lib/sqlalchemy/testing/requirements.py
@@ -851,7 +851,7 @@ class SuiteRequirements(Requirements):
expr = decimal.Decimal("15.7563")
value = e.scalar(
- select([literal(expr)])
+ select(literal(expr))
)
assert value == expr
diff --git a/lib/sqlalchemy/testing/suite/test_cte.py b/lib/sqlalchemy/testing/suite/test_cte.py
index 1ee6cac10..4addca009 100644
--- a/lib/sqlalchemy/testing/suite/test_cte.py
+++ b/lib/sqlalchemy/testing/suite/test_cte.py
@@ -53,12 +53,12 @@ class CTETest(fixtures.TablesTest):
with config.db.connect() as conn:
cte = (
- select([some_table])
+ select(some_table)
.where(some_table.c.data.in_(["d2", "d3", "d4"]))
.cte("some_cte")
)
result = conn.execute(
- select([cte.c.data]).where(cte.c.data.in_(["d4", "d5"]))
+ select(cte.c.data).where(cte.c.data.in_(["d4", "d5"]))
)
eq_(result.fetchall(), [("d4",)])
@@ -67,7 +67,7 @@ class CTETest(fixtures.TablesTest):
with config.db.connect() as conn:
cte = (
- select([some_table])
+ select(some_table)
.where(some_table.c.data.in_(["d2", "d3", "d4"]))
.cte("some_cte", recursive=True)
)
@@ -77,10 +77,10 @@ class CTETest(fixtures.TablesTest):
# note that SQL Server requires this to be UNION ALL,
# can't be UNION
cte = cte.union_all(
- select([st1]).where(st1.c.id == cte_alias.c.parent_id)
+ select(st1).where(st1.c.id == cte_alias.c.parent_id)
)
result = conn.execute(
- select([cte.c.data])
+ select(cte.c.data)
.where(cte.c.data != "d2")
.order_by(cte.c.data.desc())
)
@@ -95,18 +95,18 @@ class CTETest(fixtures.TablesTest):
with config.db.connect() as conn:
cte = (
- select([some_table])
+ select(some_table)
.where(some_table.c.data.in_(["d2", "d3", "d4"]))
.cte("some_cte")
)
conn.execute(
some_other_table.insert().from_select(
- ["id", "data", "parent_id"], select([cte])
+ ["id", "data", "parent_id"], select(cte)
)
)
eq_(
conn.execute(
- select([some_other_table]).order_by(some_other_table.c.id)
+ select(some_other_table).order_by(some_other_table.c.id)
).fetchall(),
[(2, "d2", 1), (3, "d3", 1), (4, "d4", 3)],
)
@@ -120,12 +120,12 @@ class CTETest(fixtures.TablesTest):
with config.db.connect() as conn:
conn.execute(
some_other_table.insert().from_select(
- ["id", "data", "parent_id"], select([some_table])
+ ["id", "data", "parent_id"], select(some_table)
)
)
cte = (
- select([some_table])
+ select(some_table)
.where(some_table.c.data.in_(["d2", "d3", "d4"]))
.cte("some_cte")
)
@@ -136,7 +136,7 @@ class CTETest(fixtures.TablesTest):
)
eq_(
conn.execute(
- select([some_other_table]).order_by(some_other_table.c.id)
+ select(some_other_table).order_by(some_other_table.c.id)
).fetchall(),
[
(1, "d1", None),
@@ -156,12 +156,12 @@ class CTETest(fixtures.TablesTest):
with config.db.connect() as conn:
conn.execute(
some_other_table.insert().from_select(
- ["id", "data", "parent_id"], select([some_table])
+ ["id", "data", "parent_id"], select(some_table)
)
)
cte = (
- select([some_table])
+ select(some_table)
.where(some_table.c.data.in_(["d2", "d3", "d4"]))
.cte("some_cte")
)
@@ -172,7 +172,7 @@ class CTETest(fixtures.TablesTest):
)
eq_(
conn.execute(
- select([some_other_table]).order_by(some_other_table.c.id)
+ select(some_other_table).order_by(some_other_table.c.id)
).fetchall(),
[(1, "d1", None), (5, "d5", 3)],
)
@@ -186,26 +186,26 @@ class CTETest(fixtures.TablesTest):
with config.db.connect() as conn:
conn.execute(
some_other_table.insert().from_select(
- ["id", "data", "parent_id"], select([some_table])
+ ["id", "data", "parent_id"], select(some_table)
)
)
cte = (
- select([some_table])
+ select(some_table)
.where(some_table.c.data.in_(["d2", "d3", "d4"]))
.cte("some_cte")
)
conn.execute(
some_other_table.delete().where(
some_other_table.c.data
- == select([cte.c.data])
+ == select(cte.c.data)
.where(cte.c.id == some_other_table.c.id)
.scalar_subquery()
)
)
eq_(
conn.execute(
- select([some_other_table]).order_by(some_other_table.c.id)
+ select(some_other_table).order_by(some_other_table.c.id)
).fetchall(),
[(1, "d1", None), (5, "d5", 3)],
)
diff --git a/lib/sqlalchemy/testing/suite/test_deprecations.py b/lib/sqlalchemy/testing/suite/test_deprecations.py
index 8c25616a8..b36162fa5 100644
--- a/lib/sqlalchemy/testing/suite/test_deprecations.py
+++ b/lib/sqlalchemy/testing/suite/test_deprecations.py
@@ -38,8 +38,8 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest):
def test_plain_union(self, connection):
table = self.tables.some_table
- s1 = select([table]).where(table.c.id == 2)
- s2 = select([table]).where(table.c.id == 3)
+ s1 = select(table).where(table.c.id == 2)
+ s2 = select(table).where(table.c.id == 3)
u1 = union(s1, s2)
with testing.expect_deprecated(
@@ -59,8 +59,8 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest):
# it before.
def _dont_test_select_from_plain_union(self, connection):
table = self.tables.some_table
- s1 = select([table]).where(table.c.id == 2)
- s2 = select([table]).where(table.c.id == 3)
+ s1 = select(table).where(table.c.id == 2)
+ s2 = select(table).where(table.c.id == 3)
u1 = union(s1, s2).alias().select()
with testing.expect_deprecated(
@@ -75,18 +75,8 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest):
@testing.requires.parens_in_union_contained_select_w_limit_offset
def test_limit_offset_selectable_in_unions(self, connection):
table = self.tables.some_table
- s1 = (
- select([table])
- .where(table.c.id == 2)
- .limit(1)
- .order_by(table.c.id)
- )
- s2 = (
- select([table])
- .where(table.c.id == 3)
- .limit(1)
- .order_by(table.c.id)
- )
+ s1 = select(table).where(table.c.id == 2).limit(1).order_by(table.c.id)
+ s2 = select(table).where(table.c.id == 3).limit(1).order_by(table.c.id)
u1 = union(s1, s2).limit(2)
with testing.expect_deprecated(
@@ -100,8 +90,8 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest):
@testing.requires.parens_in_union_contained_select_wo_limit_offset
def test_order_by_selectable_in_unions(self, connection):
table = self.tables.some_table
- s1 = select([table]).where(table.c.id == 2).order_by(table.c.id)
- s2 = select([table]).where(table.c.id == 3).order_by(table.c.id)
+ s1 = select(table).where(table.c.id == 2).order_by(table.c.id)
+ s2 = select(table).where(table.c.id == 3).order_by(table.c.id)
u1 = union(s1, s2).limit(2)
with testing.expect_deprecated(
@@ -114,8 +104,8 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest):
def test_distinct_selectable_in_unions(self, connection):
table = self.tables.some_table
- s1 = select([table]).where(table.c.id == 2).distinct()
- s2 = select([table]).where(table.c.id == 3).distinct()
+ s1 = select(table).where(table.c.id == 2).distinct()
+ s2 = select(table).where(table.c.id == 3).distinct()
u1 = union(s1, s2).limit(2)
with testing.expect_deprecated(
@@ -129,7 +119,7 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest):
def test_limit_offset_aliased_selectable_in_unions(self, connection):
table = self.tables.some_table
s1 = (
- select([table])
+ select(table)
.where(table.c.id == 2)
.limit(1)
.order_by(table.c.id)
@@ -137,7 +127,7 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest):
.select()
)
s2 = (
- select([table])
+ select(table)
.where(table.c.id == 3)
.limit(1)
.order_by(table.c.id)
diff --git a/lib/sqlalchemy/testing/suite/test_dialect.py b/lib/sqlalchemy/testing/suite/test_dialect.py
index 8aa13a622..c5ede08c6 100644
--- a/lib/sqlalchemy/testing/suite/test_dialect.py
+++ b/lib/sqlalchemy/testing/suite/test_dialect.py
@@ -65,7 +65,7 @@ class ExceptionTest(fixtures.TablesTest):
# there's no way to make this happen with some drivers like
# mysqlclient, pymysql. this at least does produce a non-
# ascii error message for cx_oracle, psycopg2
- conn.execute(select([literal_column(u"méil")]))
+ conn.execute(select(literal_column(u"méil")))
assert False
except exc.DBAPIError as err:
err_str = str(err)
@@ -146,7 +146,7 @@ class AutocommitTest(fixtures.TablesTest):
trans.rollback()
eq_(
- conn.scalar(select([self.tables.some_table.c.id])),
+ conn.scalar(select(self.tables.some_table.c.id)),
1 if autocommit else None,
)
@@ -194,7 +194,7 @@ class EscapingTest(fixtures.TestBase):
eq_(
conn.scalar(
- select([t.c.data]).where(
+ select(t.c.data).where(
t.c.data == literal_column("'some % value'")
)
),
@@ -203,7 +203,7 @@ class EscapingTest(fixtures.TestBase):
eq_(
conn.scalar(
- select([t.c.data]).where(
+ select(t.c.data).where(
t.c.data == literal_column("'some %% other value'")
)
),
diff --git a/lib/sqlalchemy/testing/suite/test_insert.py b/lib/sqlalchemy/testing/suite/test_insert.py
index 5b8c343c4..74347cc77 100644
--- a/lib/sqlalchemy/testing/suite/test_insert.py
+++ b/lib/sqlalchemy/testing/suite/test_insert.py
@@ -55,7 +55,7 @@ class LastrowidTest(fixtures.TablesTest):
r = connection.execute(
self.tables.autoinc_pk.insert(), data="some data"
)
- pk = connection.scalar(select([self.tables.autoinc_pk.c.id]))
+ pk = connection.scalar(select(self.tables.autoinc_pk.c.id))
eq_(r.inserted_primary_key, (pk,))
@requirements.dbapi_lastrowid
@@ -64,7 +64,7 @@ class LastrowidTest(fixtures.TablesTest):
self.tables.autoinc_pk.insert(), data="some data"
)
lastrowid = r.lastrowid
- pk = connection.scalar(select([self.tables.autoinc_pk.c.id]))
+ pk = connection.scalar(select(self.tables.autoinc_pk.c.id))
eq_(lastrowid, pk)
@@ -178,7 +178,7 @@ class InsertBehaviorTest(fixtures.TablesTest):
result = connection.execute(
dest_table.insert().from_select(
("data",),
- select([src_table.c.data]).where(
+ select(src_table.c.data).where(
src_table.c.data.in_(["data2", "data3"])
),
)
@@ -187,7 +187,7 @@ class InsertBehaviorTest(fixtures.TablesTest):
eq_(result.inserted_primary_key, (None,))
result = connection.execute(
- select([dest_table.c.data]).order_by(dest_table.c.data)
+ select(dest_table.c.data).order_by(dest_table.c.data)
)
eq_(result.fetchall(), [("data2",), ("data3",)])
@@ -199,7 +199,7 @@ class InsertBehaviorTest(fixtures.TablesTest):
result = connection.execute(
dest_table.insert().from_select(
("data",),
- select([src_table.c.data]).where(
+ select(src_table.c.data).where(
src_table.c.data.in_(["data2", "data3"])
),
)
@@ -207,7 +207,7 @@ class InsertBehaviorTest(fixtures.TablesTest):
eq_(result.inserted_primary_key, (None,))
result = connection.execute(
- select([dest_table.c.data]).order_by(dest_table.c.data)
+ select(dest_table.c.data).order_by(dest_table.c.data)
)
eq_(result.fetchall(), [])
@@ -227,7 +227,7 @@ class InsertBehaviorTest(fixtures.TablesTest):
connection.execute(
table.insert(inline=True).from_select(
("id", "data"),
- select([table.c.id + 5, table.c.data]).where(
+ select(table.c.id + 5, table.c.data).where(
table.c.data.in_(["data2", "data3"])
),
)
@@ -235,7 +235,7 @@ class InsertBehaviorTest(fixtures.TablesTest):
eq_(
connection.execute(
- select([table.c.data]).order_by(table.c.data)
+ select(table.c.data).order_by(table.c.data)
).fetchall(),
[("data1",), ("data2",), ("data2",), ("data3",), ("data3",)],
)
@@ -255,7 +255,7 @@ class InsertBehaviorTest(fixtures.TablesTest):
connection.execute(
table.insert(inline=True).from_select(
("id", "data"),
- select([table.c.id + 5, table.c.data]).where(
+ select(table.c.id + 5, table.c.data).where(
table.c.data.in_(["data2", "data3"])
),
)
@@ -263,7 +263,7 @@ class InsertBehaviorTest(fixtures.TablesTest):
eq_(
connection.execute(
- select([table]).order_by(table.c.data, table.c.id)
+ select(table).order_by(table.c.data, table.c.id)
).fetchall(),
[
(1, "data1", 5, 4),
@@ -306,7 +306,7 @@ class ReturningTest(fixtures.TablesTest):
table.insert().returning(table.c.id), data="some data"
)
pk = r.first()[0]
- fetched_pk = connection.scalar(select([table.c.id]))
+ fetched_pk = connection.scalar(select(table.c.id))
eq_(fetched_pk, pk)
def test_explicit_returning_pk_no_autocommit(self, connection):
@@ -315,7 +315,7 @@ class ReturningTest(fixtures.TablesTest):
table.insert().returning(table.c.id), data="some data"
)
pk = r.first()[0]
- fetched_pk = connection.scalar(select([table.c.id]))
+ fetched_pk = connection.scalar(select(table.c.id))
eq_(fetched_pk, pk)
def test_autoincrement_on_insert_implicit_returning(self, connection):
@@ -328,7 +328,7 @@ class ReturningTest(fixtures.TablesTest):
r = connection.execute(
self.tables.autoinc_pk.insert(), data="some data"
)
- pk = connection.scalar(select([self.tables.autoinc_pk.c.id]))
+ pk = connection.scalar(select(self.tables.autoinc_pk.c.id))
eq_(r.inserted_primary_key, (pk,))
diff --git a/lib/sqlalchemy/testing/suite/test_results.py b/lib/sqlalchemy/testing/suite/test_results.py
index e6f6068c8..6d28a207e 100644
--- a/lib/sqlalchemy/testing/suite/test_results.py
+++ b/lib/sqlalchemy/testing/suite/test_results.py
@@ -87,10 +87,8 @@ class RowFetchTest(fixtures.TablesTest):
def test_row_with_dupe_names(self, connection):
result = connection.execute(
select(
- [
- self.tables.plain_pk.c.data,
- self.tables.plain_pk.c.data.label("data"),
- ]
+ self.tables.plain_pk.c.data,
+ self.tables.plain_pk.c.data.label("data"),
).order_by(self.tables.plain_pk.c.id)
)
row = result.first()
@@ -106,8 +104,8 @@ class RowFetchTest(fixtures.TablesTest):
"""
datetable = self.tables.has_dates
- s = select([datetable.alias("x").c.today]).scalar_subquery()
- s2 = select([datetable.c.id, s.label("somelabel")])
+ s = select(datetable.alias("x").c.today).scalar_subquery()
+ s2 = select(datetable.c.id, s.label("somelabel"))
row = connection.execute(s2).first()
eq_(row.somelabel, datetime.datetime(2006, 5, 12, 12, 0, 0))
@@ -256,21 +254,21 @@ class ServerSideCursorsTest(
@testing.combinations(
("global_string", True, "select 1", True),
("global_text", True, text("select 1"), True),
- ("global_expr", True, select([1]), True),
+ ("global_expr", True, select(1), True),
("global_off_explicit", False, text("select 1"), False),
(
"stmt_option",
False,
- select([1]).execution_options(stream_results=True),
+ select(1).execution_options(stream_results=True),
True,
),
(
"stmt_option_disabled",
True,
- select([1]).execution_options(stream_results=False),
+ select(1).execution_options(stream_results=False),
False,
),
- ("for_update_expr", True, select([1]).with_for_update(), True),
+ ("for_update_expr", True, select(1).with_for_update(), True),
("for_update_string", True, "SELECT 1 FOR UPDATE", True),
("text_no_ss", False, text("select 42"), False),
(
@@ -308,7 +306,7 @@ class ServerSideCursorsTest(
def test_stmt_enabled_conn_option_disabled(self):
engine = self._fixture(False)
- s = select([1]).execution_options(stream_results=True)
+ s = select(1).execution_options(stream_results=True)
# not this one
result = (
@@ -318,7 +316,7 @@ class ServerSideCursorsTest(
def test_aliases_and_ss(self):
engine = self._fixture(False)
- s1 = select([1]).execution_options(stream_results=True).alias()
+ s1 = select(1).execution_options(stream_results=True).alias()
with engine.begin() as conn:
result = conn.execute(s1)
assert self._is_server_side(result.cursor)
@@ -326,7 +324,7 @@ class ServerSideCursorsTest(
# s1's options shouldn't affect s2 when s2 is used as a
# from_obj.
- s2 = select([1], from_obj=s1)
+ s2 = select(1).select_from(s1)
with engine.begin() as conn:
result = conn.execute(s2)
assert not self._is_server_side(result.cursor)
@@ -368,7 +366,7 @@ class ServerSideCursorsTest(
connection.execute(test_table.delete())
eq_(
connection.scalar(
- select([func.count("*")]).select_from(test_table)
+ select(func.count("*")).select_from(test_table)
),
0,
)
diff --git a/lib/sqlalchemy/testing/suite/test_select.py b/lib/sqlalchemy/testing/suite/test_select.py
index 7e0337146..adcd7d8b9 100644
--- a/lib/sqlalchemy/testing/suite/test_select.py
+++ b/lib/sqlalchemy/testing/suite/test_select.py
@@ -67,7 +67,7 @@ class CollateTest(fixtures.TablesTest):
collation = testing.requires.get_order_by_collation(testing.config)
self._assert_result(
- select([self.tables.some_table]).order_by(
+ select(self.tables.some_table).order_by(
self.tables.some_table.c.data.collate(collation).asc()
),
[(1, "collate data1"), (2, "collate data2")],
@@ -115,44 +115,38 @@ class OrderByLabelTest(fixtures.TablesTest):
def test_plain(self):
table = self.tables.some_table
lx = table.c.x.label("lx")
- self._assert_result(select([lx]).order_by(lx), [(1,), (2,), (3,)])
+ self._assert_result(select(lx).order_by(lx), [(1,), (2,), (3,)])
def test_composed_int(self):
table = self.tables.some_table
lx = (table.c.x + table.c.y).label("lx")
- self._assert_result(select([lx]).order_by(lx), [(3,), (5,), (7,)])
+ self._assert_result(select(lx).order_by(lx), [(3,), (5,), (7,)])
def test_composed_multiple(self):
table = self.tables.some_table
lx = (table.c.x + table.c.y).label("lx")
ly = (func.lower(table.c.q) + table.c.p).label("ly")
self._assert_result(
- select([lx, ly]).order_by(lx, ly.desc()),
+ select(lx, ly).order_by(lx, ly.desc()),
[(3, util.u("q1p3")), (5, util.u("q2p2")), (7, util.u("q3p1"))],
)
def test_plain_desc(self):
table = self.tables.some_table
lx = table.c.x.label("lx")
- self._assert_result(
- select([lx]).order_by(lx.desc()), [(3,), (2,), (1,)]
- )
+ self._assert_result(select(lx).order_by(lx.desc()), [(3,), (2,), (1,)])
def test_composed_int_desc(self):
table = self.tables.some_table
lx = (table.c.x + table.c.y).label("lx")
- self._assert_result(
- select([lx]).order_by(lx.desc()), [(7,), (5,), (3,)]
- )
+ self._assert_result(select(lx).order_by(lx.desc()), [(7,), (5,), (3,)])
@testing.requires.group_by_complex_expression
def test_group_by_composed(self):
table = self.tables.some_table
expr = (table.c.x + table.c.y).label("lx")
stmt = (
- select([func.count(table.c.id), expr])
- .group_by(expr)
- .order_by(expr)
+ select(func.count(table.c.id), expr).group_by(expr).order_by(expr)
)
self._assert_result(stmt, [(1, 3), (1, 5), (1, 7)])
@@ -193,7 +187,7 @@ class LimitOffsetTest(fixtures.TablesTest):
def test_simple_limit(self):
table = self.tables.some_table
self._assert_result(
- select([table]).order_by(table.c.id).limit(2),
+ select(table).order_by(table.c.id).limit(2),
[(1, 1, 2), (2, 2, 3)],
)
@@ -201,7 +195,7 @@ class LimitOffsetTest(fixtures.TablesTest):
def test_simple_offset(self):
table = self.tables.some_table
self._assert_result(
- select([table]).order_by(table.c.id).offset(2),
+ select(table).order_by(table.c.id).offset(2),
[(3, 3, 4), (4, 4, 5)],
)
@@ -209,7 +203,7 @@ class LimitOffsetTest(fixtures.TablesTest):
def test_simple_limit_offset(self):
table = self.tables.some_table
self._assert_result(
- select([table]).order_by(table.c.id).limit(2).offset(1),
+ select(table).order_by(table.c.id).limit(2).offset(1),
[(2, 2, 3), (3, 3, 4)],
)
@@ -218,7 +212,7 @@ class LimitOffsetTest(fixtures.TablesTest):
"""test that 'literal binds' mode works - no bound params."""
table = self.tables.some_table
- stmt = select([table]).order_by(table.c.id).limit(2).offset(1)
+ stmt = select(table).order_by(table.c.id).limit(2).offset(1)
sql = stmt.compile(
dialect=config.db.dialect, compile_kwargs={"literal_binds": True}
)
@@ -230,7 +224,7 @@ class LimitOffsetTest(fixtures.TablesTest):
def test_bound_limit(self):
table = self.tables.some_table
self._assert_result(
- select([table]).order_by(table.c.id).limit(bindparam("l")),
+ select(table).order_by(table.c.id).limit(bindparam("l")),
[(1, 1, 2), (2, 2, 3)],
params={"l": 2},
)
@@ -239,7 +233,7 @@ class LimitOffsetTest(fixtures.TablesTest):
def test_bound_offset(self):
table = self.tables.some_table
self._assert_result(
- select([table]).order_by(table.c.id).offset(bindparam("o")),
+ select(table).order_by(table.c.id).offset(bindparam("o")),
[(3, 3, 4), (4, 4, 5)],
params={"o": 2},
)
@@ -248,7 +242,7 @@ class LimitOffsetTest(fixtures.TablesTest):
def test_bound_limit_offset(self):
table = self.tables.some_table
self._assert_result(
- select([table])
+ select(table)
.order_by(table.c.id)
.limit(bindparam("l"))
.offset(bindparam("o")),
@@ -260,7 +254,7 @@ class LimitOffsetTest(fixtures.TablesTest):
def test_expr_offset(self):
table = self.tables.some_table
self._assert_result(
- select([table])
+ select(table)
.order_by(table.c.id)
.offset(literal_column("1") + literal_column("2")),
[(4, 4, 5)],
@@ -270,7 +264,7 @@ class LimitOffsetTest(fixtures.TablesTest):
def test_expr_limit(self):
table = self.tables.some_table
self._assert_result(
- select([table])
+ select(table)
.order_by(table.c.id)
.limit(literal_column("1") + literal_column("2")),
[(1, 1, 2), (2, 2, 3), (3, 3, 4)],
@@ -280,7 +274,7 @@ class LimitOffsetTest(fixtures.TablesTest):
def test_expr_limit_offset(self):
table = self.tables.some_table
self._assert_result(
- select([table])
+ select(table)
.order_by(table.c.id)
.limit(literal_column("1") + literal_column("1"))
.offset(literal_column("1") + literal_column("1")),
@@ -291,7 +285,7 @@ class LimitOffsetTest(fixtures.TablesTest):
def test_simple_limit_expr_offset(self):
table = self.tables.some_table
self._assert_result(
- select([table])
+ select(table)
.order_by(table.c.id)
.limit(2)
.offset(literal_column("1") + literal_column("1")),
@@ -302,7 +296,7 @@ class LimitOffsetTest(fixtures.TablesTest):
def test_expr_limit_simple_offset(self):
table = self.tables.some_table
self._assert_result(
- select([table])
+ select(table)
.order_by(table.c.id)
.limit(literal_column("1") + literal_column("1"))
.offset(2),
@@ -347,7 +341,7 @@ class JoinTest(fixtures.TablesTest):
def test_inner_join_fk(self):
a, b = self.tables("a", "b")
- stmt = select([a, b]).select_from(a.join(b)).order_by(a.c.id, b.c.id)
+ stmt = select(a, b).select_from(a.join(b)).order_by(a.c.id, b.c.id)
self._assert_result(stmt, [(1, 1, 1), (1, 2, 1), (2, 4, 2), (3, 5, 3)])
@@ -355,7 +349,7 @@ class JoinTest(fixtures.TablesTest):
a, b = self.tables("a", "b")
stmt = (
- select([a, b])
+ select(a, b)
.select_from(a.join(b, true()))
.order_by(a.c.id, b.c.id)
)
@@ -375,7 +369,7 @@ class JoinTest(fixtures.TablesTest):
a, b = self.tables("a", "b")
stmt = (
- select([a, b])
+ select(a, b)
.select_from(a.join(b, false()))
.order_by(a.c.id, b.c.id)
)
@@ -386,7 +380,7 @@ class JoinTest(fixtures.TablesTest):
a, b = self.tables("a", "b")
stmt = (
- select([a, b])
+ select(a, b)
.select_from(a.outerjoin(b, false()))
.order_by(a.c.id, b.c.id)
)
@@ -405,7 +399,7 @@ class JoinTest(fixtures.TablesTest):
def test_outer_join_fk(self):
a, b = self.tables("a", "b")
- stmt = select([a, b]).select_from(a.join(b)).order_by(a.c.id, b.c.id)
+ stmt = select(a, b).select_from(a.join(b)).order_by(a.c.id, b.c.id)
self._assert_result(stmt, [(1, 1, 1), (1, 2, 1), (2, 4, 2), (3, 5, 3)])
@@ -441,8 +435,8 @@ class CompoundSelectTest(fixtures.TablesTest):
def test_plain_union(self):
table = self.tables.some_table
- s1 = select([table]).where(table.c.id == 2)
- s2 = select([table]).where(table.c.id == 3)
+ s1 = select(table).where(table.c.id == 2)
+ s2 = select(table).where(table.c.id == 3)
u1 = union(s1, s2)
self._assert_result(
@@ -451,8 +445,8 @@ class CompoundSelectTest(fixtures.TablesTest):
def test_select_from_plain_union(self):
table = self.tables.some_table
- s1 = select([table]).where(table.c.id == 2)
- s2 = select([table]).where(table.c.id == 3)
+ s1 = select(table).where(table.c.id == 2)
+ s2 = select(table).where(table.c.id == 3)
u1 = union(s1, s2).alias().select()
self._assert_result(
@@ -463,18 +457,8 @@ class CompoundSelectTest(fixtures.TablesTest):
@testing.requires.parens_in_union_contained_select_w_limit_offset
def test_limit_offset_selectable_in_unions(self):
table = self.tables.some_table
- s1 = (
- select([table])
- .where(table.c.id == 2)
- .limit(1)
- .order_by(table.c.id)
- )
- s2 = (
- select([table])
- .where(table.c.id == 3)
- .limit(1)
- .order_by(table.c.id)
- )
+ s1 = select(table).where(table.c.id == 2).limit(1).order_by(table.c.id)
+ s2 = select(table).where(table.c.id == 3).limit(1).order_by(table.c.id)
u1 = union(s1, s2).limit(2)
self._assert_result(
@@ -484,8 +468,8 @@ class CompoundSelectTest(fixtures.TablesTest):
@testing.requires.parens_in_union_contained_select_wo_limit_offset
def test_order_by_selectable_in_unions(self):
table = self.tables.some_table
- s1 = select([table]).where(table.c.id == 2).order_by(table.c.id)
- s2 = select([table]).where(table.c.id == 3).order_by(table.c.id)
+ s1 = select(table).where(table.c.id == 2).order_by(table.c.id)
+ s2 = select(table).where(table.c.id == 3).order_by(table.c.id)
u1 = union(s1, s2).limit(2)
self._assert_result(
@@ -494,8 +478,8 @@ class CompoundSelectTest(fixtures.TablesTest):
def test_distinct_selectable_in_unions(self):
table = self.tables.some_table
- s1 = select([table]).where(table.c.id == 2).distinct()
- s2 = select([table]).where(table.c.id == 3).distinct()
+ s1 = select(table).where(table.c.id == 2).distinct()
+ s2 = select(table).where(table.c.id == 3).distinct()
u1 = union(s1, s2).limit(2)
self._assert_result(
@@ -505,18 +489,8 @@ class CompoundSelectTest(fixtures.TablesTest):
@testing.requires.parens_in_union_contained_select_w_limit_offset
def test_limit_offset_in_unions_from_alias(self):
table = self.tables.some_table
- s1 = (
- select([table])
- .where(table.c.id == 2)
- .limit(1)
- .order_by(table.c.id)
- )
- s2 = (
- select([table])
- .where(table.c.id == 3)
- .limit(1)
- .order_by(table.c.id)
- )
+ s1 = select(table).where(table.c.id == 2).limit(1).order_by(table.c.id)
+ s2 = select(table).where(table.c.id == 3).limit(1).order_by(table.c.id)
# this necessarily has double parens
u1 = union(s1, s2).alias()
@@ -527,7 +501,7 @@ class CompoundSelectTest(fixtures.TablesTest):
def test_limit_offset_aliased_selectable_in_unions(self):
table = self.tables.some_table
s1 = (
- select([table])
+ select(table)
.where(table.c.id == 2)
.limit(1)
.order_by(table.c.id)
@@ -535,7 +509,7 @@ class CompoundSelectTest(fixtures.TablesTest):
.select()
)
s2 = (
- select([table])
+ select(table)
.where(table.c.id == 3)
.limit(1)
.order_by(table.c.id)
@@ -582,7 +556,7 @@ class PostCompileParamsTest(
def test_compile(self):
table = self.tables.some_table
- stmt = select([table.c.id]).where(
+ stmt = select(table.c.id).where(
table.c.x == bindparam("q", literal_execute=True)
)
@@ -596,7 +570,7 @@ class PostCompileParamsTest(
def test_compile_literal_binds(self):
table = self.tables.some_table
- stmt = select([table.c.id]).where(
+ stmt = select(table.c.id).where(
table.c.x == bindparam("q", 10, literal_execute=True)
)
@@ -610,7 +584,7 @@ class PostCompileParamsTest(
def test_execute(self):
table = self.tables.some_table
- stmt = select([table.c.id]).where(
+ stmt = select(table.c.id).where(
table.c.x == bindparam("q", literal_execute=True)
)
@@ -629,7 +603,7 @@ class PostCompileParamsTest(
def test_execute_expanding_plus_literal_execute(self):
table = self.tables.some_table
- stmt = select([table.c.id]).where(
+ stmt = select(table.c.id).where(
table.c.x.in_(bindparam("q", expanding=True, literal_execute=True))
)
@@ -649,7 +623,7 @@ class PostCompileParamsTest(
def test_execute_tuple_expanding_plus_literal_execute(self):
table = self.tables.some_table
- stmt = select([table.c.id]).where(
+ stmt = select(table.c.id).where(
tuple_(table.c.x, table.c.y).in_(
bindparam("q", expanding=True, literal_execute=True)
)
@@ -673,7 +647,7 @@ class PostCompileParamsTest(
def test_execute_tuple_expanding_plus_literal_heterogeneous_execute(self):
table = self.tables.some_table
- stmt = select([table.c.id]).where(
+ stmt = select(table.c.id).where(
tuple_(table.c.x, table.c.z).in_(
bindparam("q", expanding=True, literal_execute=True)
)
@@ -730,7 +704,7 @@ class ExpandingBoundInTest(fixtures.TablesTest):
table = self.tables.some_table
stmt = (
- select([table.c.id])
+ select(table.c.id)
.where(table.c.x.in_(bindparam("q", expanding=True)))
.where(table.c.y.in_(bindparam("p", expanding=True)))
.order_by(table.c.id)
@@ -743,7 +717,7 @@ class ExpandingBoundInTest(fixtures.TablesTest):
table = self.tables.some_table
stmt = (
- select([table.c.id])
+ select(table.c.id)
.where(
tuple_(table.c.x, table.c.z).in_(
bindparam("q", expanding=True)
@@ -759,7 +733,7 @@ class ExpandingBoundInTest(fixtures.TablesTest):
table = self.tables.some_table
stmt = (
- select([table.c.id])
+ select(table.c.id)
.where(
tuple_(table.c.x, table.c.y).in_(
bindparam("q", expanding=True)
@@ -774,7 +748,7 @@ class ExpandingBoundInTest(fixtures.TablesTest):
table = self.tables.some_table
stmt = (
- select([table.c.id])
+ select(table.c.id)
.where(table.c.x.in_(bindparam("q", expanding=True)))
.order_by(table.c.id)
)
@@ -786,7 +760,7 @@ class ExpandingBoundInTest(fixtures.TablesTest):
table = self.tables.some_table
stmt = (
- select([table.c.id])
+ select(table.c.id)
.where(
tuple_(table.c.x, table.c.y).in_(
bindparam("q", expanding=True)
@@ -804,7 +778,7 @@ class ExpandingBoundInTest(fixtures.TablesTest):
table = self.tables.some_table
stmt = (
- select([table.c.id])
+ select(table.c.id)
.where(
tuple_(table.c.x, table.c.z).in_(
bindparam("q", expanding=True)
@@ -835,7 +809,7 @@ class ExpandingBoundInTest(fixtures.TablesTest):
table = self.tables.some_table
stmt = (
- select([table.c.id])
+ select(table.c.id)
.where(table.c.x.in_(bindparam("q", expanding=True)))
.order_by(table.c.id)
)
@@ -846,7 +820,7 @@ class ExpandingBoundInTest(fixtures.TablesTest):
table = self.tables.some_table
stmt = (
- select([table.c.id])
+ select(table.c.id)
.where(table.c.x.notin_(bindparam("q", expanding=True)))
.order_by(table.c.id)
)
@@ -857,7 +831,7 @@ class ExpandingBoundInTest(fixtures.TablesTest):
table = self.tables.some_table
stmt = (
- select([table.c.id])
+ select(table.c.id)
.where(table.c.z.in_(bindparam("q", expanding=True)))
.order_by(table.c.id)
)
@@ -868,7 +842,7 @@ class ExpandingBoundInTest(fixtures.TablesTest):
table = self.tables.some_table
stmt = (
- select([table.c.id])
+ select(table.c.id)
.where(table.c.z.notin_(bindparam("q", expanding=True)))
.order_by(table.c.id)
)
@@ -877,19 +851,15 @@ class ExpandingBoundInTest(fixtures.TablesTest):
def test_null_in_empty_set_is_false(self, connection):
stmt = select(
- [
- case(
- [
- (
- null().in_(
- bindparam("foo", value=(), expanding=True)
- ),
- true(),
- )
- ],
- else_=false(),
- )
- ]
+ case(
+ [
+ (
+ null().in_(bindparam("foo", value=(), expanding=True)),
+ true(),
+ )
+ ],
+ else_=false(),
+ )
)
in_(connection.execute(stmt).fetchone()[0], (False, 0))
@@ -933,9 +903,7 @@ class LikeFunctionsTest(fixtures.TablesTest):
with config.db.connect() as conn:
rows = {
value
- for value, in conn.execute(
- select([some_table.c.id]).where(expr)
- )
+ for value, in conn.execute(select(some_table.c.id).where(expr))
}
eq_(rows, expected)
@@ -1047,7 +1015,7 @@ class ComputedColumnTest(fixtures.TablesTest):
def test_select_all(self):
with config.db.connect() as conn:
res = conn.execute(
- select([text("*")])
+ select(text("*"))
.select_from(self.tables.square)
.order_by(self.tables.square.c.id)
).fetchall()
@@ -1057,7 +1025,7 @@ class ComputedColumnTest(fixtures.TablesTest):
with config.db.connect() as conn:
res = conn.execute(
select(
- [self.tables.square.c.area, self.tables.square.c.perimeter]
+ self.tables.square.c.area, self.tables.square.c.perimeter
)
.select_from(self.tables.square)
.order_by(self.tables.square.c.id)
@@ -1110,14 +1078,14 @@ class IdentityColumnTest(fixtures.TablesTest):
def test_select_all(self, connection):
res = connection.execute(
- select([text("*")])
+ select(text("*"))
.select_from(self.tables.tbl_a)
.order_by(self.tables.tbl_a.c.id)
).fetchall()
eq_(res, [(42, "a"), (43, "b")])
res = connection.execute(
- select([text("*")])
+ select(text("*"))
.select_from(self.tables.tbl_b)
.order_by(self.tables.tbl_b.c.id)
).fetchall()
@@ -1126,7 +1094,7 @@ class IdentityColumnTest(fixtures.TablesTest):
def test_select_columns(self, connection):
res = connection.execute(
- select([self.tables.tbl_a.c.id]).order_by(self.tables.tbl_a.c.id)
+ select(self.tables.tbl_a.c.id).order_by(self.tables.tbl_a.c.id)
).fetchall()
eq_(res, [(42,), (43,)])
@@ -1192,7 +1160,7 @@ class DistinctOnTest(AssertsCompiledSQL, fixtures.TablesTest):
@testing.fails_if(testing.requires.supports_distinct_on)
def test_distinct_on(self):
- stm = select(["*"]).distinct(column("q")).select_from(table("foo"))
+ stm = select("*").distinct(column("q")).select_from(table("foo"))
with testing.expect_deprecated(
"DISTINCT ON is currently supported only by the PostgreSQL "
):