summaryrefslogtreecommitdiff
path: root/test/ext
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-03-18 18:57:13 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-03-18 18:57:13 -0400
commitcd076470baf2fce0eebf5853e3145d96a9d48378 (patch)
treef060277c2bcf5acd2718dad2332bd0ae683489b0 /test/ext
parent138293c246fbf8c6693044a89fe788d0d0446113 (diff)
downloadsqlalchemy-cd076470baf2fce0eebf5853e3145d96a9d48378.tar.gz
- Loosened some restrictions that were added to ``@declared_attr``
objects, such that they were prevented from being called outside of the declarative process; this is related to the enhancements of #3150 which allow ``@declared_attr`` to return a value that is cached based on the current class as it's being configured. The exception raise has been removed, and the behavior changed so that outside of the declarative process, the function decorated by ``@declared_attr`` is called every time just like a regular ``@property``, without using any caching, as none is available at this stage. fixes #3331
Diffstat (limited to 'test/ext')
-rw-r--r--test/ext/declarative/test_mixin.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/ext/declarative/test_mixin.py b/test/ext/declarative/test_mixin.py
index 5cefe8d47..45b881671 100644
--- a/test/ext/declarative/test_mixin.py
+++ b/test/ext/declarative/test_mixin.py
@@ -1392,6 +1392,39 @@ class DeclaredAttrTest(DeclarativeTestBase, testing.AssertsCompiledSQL):
getattr, Mixin, "my_prop"
)
+ def test_non_decl_access(self):
+ counter = mock.Mock()
+
+ class Mixin(object):
+ @declared_attr
+ def __tablename__(cls):
+ counter(cls)
+ return "foo"
+
+ class Foo(Mixin, Base):
+ id = Column(Integer, primary_key=True)
+
+ @declared_attr
+ def x(cls):
+ cls.__tablename__
+
+ @declared_attr
+ def y(cls):
+ cls.__tablename__
+
+ eq_(
+ counter.mock_calls,
+ [mock.call(Foo)]
+ )
+
+ eq_(Foo.__tablename__, 'foo')
+ eq_(Foo.__tablename__, 'foo')
+
+ eq_(
+ counter.mock_calls,
+ [mock.call(Foo), mock.call(Foo), mock.call(Foo)]
+ )
+
def test_property_noncascade(self):
counter = mock.Mock()