diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-02-20 15:00:09 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-02-21 11:18:19 -0500 |
commit | 4ca3092c0a89855cd740bafb4e0fb4c99051f89e (patch) | |
tree | e8a42e8391cf1b30f5b20ba10da1f3fa9f97e17c /test/sql/test_tablesample.py | |
parent | 7a4c40ff6b9d278529735c792c3ddfda60bd4a85 (diff) | |
download | sqlalchemy-4ca3092c0a89855cd740bafb4e0fb4c99051f89e.tar.gz |
Prevent __init__ from being called for Alias, subclasses
The :class:`.Alias` class and related subclasses :class:`.CTE`,
:class:`.Lateral` and :class:`.TableSample` have been reworked so that it is
not possible for a user to construct the objects directly. These constructs
require that the standalone construction function or selectable-bound method
be used to instantiate new objects.
Fixes: #4509
Change-Id: I74ae4786cb3ae625dab33b00bfd6bdc4e1219139
Diffstat (limited to 'test/sql/test_tablesample.py')
-rw-r--r-- | test/sql/test_tablesample.py | 17 |
1 files changed, 17 insertions, 0 deletions
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", + ) |