diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/sql/test_cte.py | 27 | ||||
| -rw-r--r-- | test/sql/test_lateral.py | 16 | ||||
| -rw-r--r-- | test/sql/test_selectable.py | 13 | ||||
| -rw-r--r-- | test/sql/test_tablesample.py | 17 |
4 files changed, 73 insertions, 0 deletions
diff --git a/test/sql/test_cte.py b/test/sql/test_cte.py index ed2787b0f..7008bc1cc 100644 --- a/test/sql/test_cte.py +++ b/test/sql/test_cte.py @@ -4,12 +4,14 @@ from sqlalchemy.exc import CompileError from sqlalchemy.sql import and_ from sqlalchemy.sql import bindparam from sqlalchemy.sql import column +from sqlalchemy.sql import cte from sqlalchemy.sql import exists from sqlalchemy.sql import func from sqlalchemy.sql import literal from sqlalchemy.sql import select from sqlalchemy.sql import table from sqlalchemy.sql.elements import quoted_name +from sqlalchemy.sql.selectable import CTE from sqlalchemy.sql.visitors import cloned_traverse from sqlalchemy.testing import assert_raises_message from sqlalchemy.testing import AssertsCompiledSQL @@ -1126,3 +1128,28 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): "UPDATE products SET id=:id, price=:price FROM pd " "WHERE products.price = pd.price", ) + + def test_standalone_function(self): + a = table("a", column("x")) + a_stmt = select([a]) + + stmt = select([cte(a_stmt)]) + + self.assert_compile( + stmt, + "WITH anon_1 AS (SELECT a.x AS x FROM a) " + "SELECT anon_1.x FROM anon_1", + ) + + def test_no_alias_construct(self): + a = table("a", column("x")) + a_stmt = select([a]) + + assert_raises_message( + NotImplementedError, + "The CTE class is not intended to be constructed directly. " + r"Please use the cte\(\) standalone function", + CTE, + a_stmt, + "foo", + ) diff --git a/test/sql/test_lateral.py b/test/sql/test_lateral.py index ee43475c8..ee9b13d1d 100644 --- a/test/sql/test_lateral.py +++ b/test/sql/test_lateral.py @@ -1,14 +1,18 @@ from sqlalchemy import Column +from sqlalchemy import column from sqlalchemy import ForeignKey from sqlalchemy import Integer from sqlalchemy import join from sqlalchemy import lateral from sqlalchemy import String from sqlalchemy import Table +from sqlalchemy import table from sqlalchemy import true from sqlalchemy.engine import default from sqlalchemy.sql import func from sqlalchemy.sql import select +from sqlalchemy.sql.selectable import Lateral +from sqlalchemy.testing import assert_raises_message from sqlalchemy.testing import AssertsCompiledSQL from sqlalchemy.testing import fixtures @@ -150,3 +154,15 @@ class LateralTest(fixtures.TablesTest, AssertsCompiledSQL): "LATERAL generate_series(:generate_series_1, " "bookcases.bookcase_shelves) AS anon_1 ON true", ) + + def test_no_alias_construct(self): + a = table("a", column("x")) + + assert_raises_message( + NotImplementedError, + "The Lateral class is not intended to be constructed directly. " + r"Please use the lateral\(\) standalone", + Lateral, + a, + "foo", + ) diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index 04c0e6102..a4d3e1b40 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -28,6 +28,7 @@ from sqlalchemy import type_coerce from sqlalchemy import TypeDecorator from sqlalchemy import union from sqlalchemy import util +from sqlalchemy.sql import Alias from sqlalchemy.sql import column from sqlalchemy.sql import elements from sqlalchemy.sql import expression @@ -871,6 +872,18 @@ class SelectableTest( Table("t1", MetaData(), c1) eq_(c1._label, "t1_c1") + def test_no_alias_construct(self): + a = table("a", column("x")) + + assert_raises_message( + NotImplementedError, + "The Alias class is not intended to be constructed directly. " + r"Please use the alias\(\) standalone function", + Alias, + a, + "foo", + ) + class RefreshForNewColTest(fixtures.TestBase): def test_join_uninit(self): diff --git a/test/sql/test_tablesample.py b/test/sql/test_tablesample.py index d2c57c930..7e0600a66 100644 --- a/test/sql/test_tablesample.py +++ b/test/sql/test_tablesample.py @@ -1,12 +1,16 @@ from sqlalchemy import Column +from sqlalchemy import column from sqlalchemy import Integer from sqlalchemy import String from sqlalchemy import Table +from sqlalchemy import table from sqlalchemy import tablesample from sqlalchemy.engine import default from sqlalchemy.sql import func from sqlalchemy.sql import select from sqlalchemy.sql import text +from sqlalchemy.sql.selectable import TableSample +from sqlalchemy.testing import assert_raises_message from sqlalchemy.testing import AssertsCompiledSQL from sqlalchemy.testing import fixtures @@ -59,3 +63,16 @@ class TableSampleTest(fixtures.TablesTest, AssertsCompiledSQL): "SELECT alias.people_id FROM " "people AS alias TABLESAMPLE system(1)", ) + + def test_no_alias_construct(self): + a = table("a", column("x")) + + assert_raises_message( + NotImplementedError, + "The TableSample class is not intended to be constructed " + "directly. " + r"Please use the tablesample\(\) standalone", + TableSample, + a, + "foo", + ) |
