summaryrefslogtreecommitdiff
path: root/test/ext/declarative/test_basic.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2018-11-26 00:59:01 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2018-11-26 01:12:01 -0500
commit6ec40eca1a03a9156ee82f3ce75850778220b39e (patch)
treea70bd6198fdf64df2d29f7d6a715e260c94e8213 /test/ext/declarative/test_basic.py
parentb5cb68ac432bb7477642305504ddcfdb3edaf87f (diff)
downloadsqlalchemy-6ec40eca1a03a9156ee82f3ce75850778220b39e.tar.gz
Warn for lower-case column attribute on declarative
A warning is emitted in the case that a :func:`.column` object is applied to a declarative class, as it seems likely this intended to be a :class:`.Column` object. Fixes: #4374 Change-Id: I2e617ef65547162e3ba6587c168548ad0cf6203d
Diffstat (limited to 'test/ext/declarative/test_basic.py')
-rw-r--r--test/ext/declarative/test_basic.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/ext/declarative/test_basic.py b/test/ext/declarative/test_basic.py
index d2dc1a425..e8a9a140c 100644
--- a/test/ext/declarative/test_basic.py
+++ b/test/ext/declarative/test_basic.py
@@ -1,6 +1,7 @@
from sqlalchemy.testing import eq_, assert_raises, \
assert_raises_message, expect_warnings, is_
+from sqlalchemy.testing import assertions
from sqlalchemy.ext import declarative as decl
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy import exc
@@ -175,6 +176,62 @@ class DeclarativeTest(DeclarativeTestBase):
assert class_mapper(Bar).get_property('some_data').columns[0] \
is t.c.data
+ def test_lower_case_c_column_warning(self):
+ with assertions.expect_warnings(
+ r"Attribute 'x' on class <class .*Foo.* appears to be a "
+ r"non-schema 'sqlalchemy.sql.column\(\)' object; ",
+ ):
+ class Foo(Base):
+ __tablename__ = 'foo'
+
+ id = Column(Integer, primary_key=True)
+ x = sa.sql.expression.column(Integer)
+ y = Column(Integer)
+
+ class MyMixin(object):
+ x = sa.sql.expression.column(Integer)
+ y = Column(Integer)
+
+ with assertions.expect_warnings(
+ r"Attribute 'x' on class <class .*MyMixin.* appears to be a "
+ r"non-schema 'sqlalchemy.sql.column\(\)' object; ",
+ ):
+ class Foo2(MyMixin, Base):
+ __tablename__ = 'foo2'
+
+ id = Column(Integer, primary_key=True)
+
+ with assertions.expect_warnings(
+ r"Attribute 'x' on class <class .*Foo3.* appears to be a "
+ r"non-schema 'sqlalchemy.sql.column\(\)' object; ",
+ ):
+ class Foo3(Base):
+ __tablename__ = 'foo3'
+
+ id = Column(Integer, primary_key=True)
+
+ @declared_attr
+ def x(cls):
+ return sa.sql.expression.column(Integer)
+
+ y = Column(Integer)
+
+ with assertions.expect_warnings(
+ r"Attribute 'x' on class <class .*Foo4.* appears to be a "
+ r"non-schema 'sqlalchemy.sql.column\(\)' object; ",
+ ):
+ class MyMixin2(object):
+ @declared_attr
+ def x(cls):
+ return sa.sql.expression.column(Integer)
+
+ y = Column(Integer)
+
+ class Foo4(MyMixin2, Base):
+ __tablename__ = 'foo4'
+
+ id = Column(Integer, primary_key=True)
+
def test_column_named_twice(self):
def go():
class Foo(Base):