Files
sqlalchemy/test/sql/test_inspect.py
T
Mike Bayer f07e050c9c Implement new ClauseElement role and coercion system
A major refactoring of all the functions handle all detection of
Core argument types as well as perform coercions into a new class hierarchy
based on "roles", each of which identify a syntactical location within a
SQL statement.  In contrast to the ClauseElement hierarchy that identifies
"what" each object is syntactically, the SQLRole hierarchy identifies
the "where does it go" of each object syntactically.   From this we define
a consistent type checking and coercion system that establishes well
defined behviors.

This is a breakout of the patch that is reorganizing select()
constructs to no longer be in the FromClause hierarchy.

Also includes a rename of as_scalar() into scalar_subquery(); deprecates
automatic coercion to scalar_subquery().

Partially-fixes: #4617
Change-Id: I26f1e78898693c6b99ef7ea2f4e7dfd0e8e1a1bd
2019-05-18 17:46:10 -04:00

51 lines
1.4 KiB
Python

"""test the inspection registry system."""
from sqlalchemy import Column
from sqlalchemy import inspect
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import Table
from sqlalchemy.sql import ClauseElement
from sqlalchemy.testing import fixtures
from sqlalchemy.testing import is_
class TestCoreInspection(fixtures.TestBase):
def test_table(self):
t = Table("t", MetaData(), Column("x", Integer))
is_(inspect(t), t)
assert t.is_selectable
is_(t.selectable, t)
def test_select(self):
t = Table("t", MetaData(), Column("x", Integer))
s = t.select()
is_(inspect(s), s)
assert s.is_selectable
is_(s.selectable, s)
def test_column_expr(self):
c = Column("x", Integer)
is_(inspect(c), c)
assert not c.is_selectable
assert not hasattr(c, "selectable")
def test_no_clause_element_on_clauseelement(self):
# re [ticket:3802], there are in the wild examples
# of looping over __clause_element__, therefore the
# absence of __clause_element__ as a test for "this is the clause
# element" must be maintained
class Foo(ClauseElement):
pass
assert not hasattr(Foo(), "__clause_element__")
def test_col_now_has_a_clauseelement(self):
x = Column("foo", Integer)
assert hasattr(x, "__clause_element__")