summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_deprecations.py12
-rw-r--r--test/sql/test_roles.py33
-rw-r--r--test/sql/test_selectable.py2
3 files changed, 46 insertions, 1 deletions
diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py
index 8e8591aec..90646c41d 100644
--- a/test/sql/test_deprecations.py
+++ b/test/sql/test_deprecations.py
@@ -486,6 +486,18 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL):
is_true(stmt.compare(select([table1.c.myid]).scalar_subquery()))
+ def test_fromclause_subquery(self):
+ stmt = select([table1.c.myid])
+ with testing.expect_deprecated(
+ "Implicit coercion of SELECT and textual SELECT constructs "
+ "into FROM clauses is deprecated"
+ ):
+ coerced = coercions.expect(
+ roles.StrictFromClauseRole, stmt, allow_select=True
+ )
+
+ is_true(coerced.compare(stmt.subquery()))
+
class TextTest(fixtures.TestBase, AssertsCompiledSQL):
__dialect__ = "default"
diff --git a/test/sql/test_roles.py b/test/sql/test_roles.py
index 81934de24..0d819c13d 100644
--- a/test/sql/test_roles.py
+++ b/test/sql/test_roles.py
@@ -195,6 +195,39 @@ class RoleTest(fixtures.TestBase):
d1 = DDL("hi")
is_(expect(roles.CoerceTextStatementRole, d1), d1)
+ def test_strict_from_clause_role(self):
+ stmt = select([t]).subquery()
+ is_true(
+ expect(roles.StrictFromClauseRole, stmt).compare(
+ select([t]).subquery()
+ )
+ )
+
+ def test_strict_from_clause_role_disallow_select(self):
+ stmt = select([t])
+ assert_raises_message(
+ exc.ArgumentError,
+ r"FROM expression, such as a Table or alias\(\) "
+ "object expected, got .*Select",
+ expect,
+ roles.StrictFromClauseRole,
+ stmt,
+ )
+
+ def test_anonymized_from_clause_role(self):
+ is_true(expect(roles.AnonymizedFromClauseRole, t).compare(t.alias()))
+
+ # note the compare for subquery().alias(), even if it is two
+ # plain Alias objects (which it won't be once we introduce the
+ # Subquery class), still compares based on alias() being present
+ # twice, that is, alias().alias() builds an alias of an alias, rather
+ # than just replacing the outer alias.
+ is_true(
+ expect(
+ roles.AnonymizedFromClauseRole, select([t]).subquery()
+ ).compare(select([t]).subquery().alias())
+ )
+
def test_statement_coercion_sequence(self):
s1 = Sequence("hi")
is_(expect(roles.CoerceTextStatementRole, s1), s1)
diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py
index f88243fc2..186fb3d9e 100644
--- a/test/sql/test_selectable.py
+++ b/test/sql/test_selectable.py
@@ -1711,7 +1711,7 @@ class ReduceTest(fixtures.TestBase, AssertsExecutionResults):
{
"BaseItem": base_item_table.select(
base_item_table.c.child_name == "BaseItem"
- ),
+ ).subquery(),
"Item": base_item_table.join(item_table),
},
None,