summaryrefslogtreecommitdiff
path: root/test/orm/inheritance/test_basic.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-07-14 15:41:31 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-07-14 15:41:31 -0400
commit800efc75256283770d5c28ddd99f26f341733698 (patch)
tree195206da35d9f2d434e9bd35596038ecaab1e832 /test/orm/inheritance/test_basic.py
parent6dad6332cd0b777e4d876f51fada4fdf31299c53 (diff)
downloadsqlalchemy-800efc75256283770d5c28ddd99f26f341733698.tar.gz
- [feature] *Very limited* support for
inheriting mappers to be GC'ed when the class itself is deferenced. The mapper must not have its own table (i.e. single table inh only) without polymorphic attributes in place. This allows for the use case of creating a temporary subclass of a declarative mapped class, with no table or mapping directives of its own, to be garbage collected when dereferenced by a unit test. [ticket:2526]
Diffstat (limited to 'test/orm/inheritance/test_basic.py')
-rw-r--r--test/orm/inheritance/test_basic.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py
index 0e647a66e..28aced07b 100644
--- a/test/orm/inheritance/test_basic.py
+++ b/test/orm/inheritance/test_basic.py
@@ -11,6 +11,7 @@ from test.lib import fixtures
from test.orm import _fixtures
from test.lib.schema import Table, Column
from sqlalchemy.ext.declarative import declarative_base
+from test.lib.util import gc_collect
class O2MTest(fixtures.MappedTest):
"""deals with inheritance and one-to-many relationships"""
@@ -1695,6 +1696,62 @@ class OptimizedLoadTest(fixtures.MappedTest):
),
)
+class TransientInheritingGCTest(fixtures.TestBase):
+ def _fixture(self):
+ Base = declarative_base()
+ class A(Base):
+ __tablename__ = 'a'
+ id = Column(Integer, primary_key=True, test_needs_pk=True)
+ data = Column(String(10))
+ self.A = A
+ return Base
+
+ def setUp(self):
+ self.Base = self._fixture()
+
+ def tearDown(self):
+ self.Base.metadata.drop_all(testing.db)
+ #clear_mappers()
+ self.Base = None
+
+ def _do_test(self, go):
+ B = go()
+ self.Base.metadata.create_all(testing.db)
+ sess = Session(testing.db)
+ sess.add(B(data='some b'))
+ sess.commit()
+
+ b1 = sess.query(B).one()
+ assert isinstance(b1, B)
+ sess.close()
+ del sess
+ del b1
+ del B
+
+ gc_collect()
+
+ eq_(
+ len(self.A.__subclasses__()),
+ 0)
+
+ def test_single(self):
+ def go():
+ class B(self.A):
+ pass
+ return B
+ self._do_test(go)
+
+ @testing.fails_if(lambda: True,
+ "not supported for joined inh right now.")
+ def test_joined(self):
+ def go():
+ class B(self.A):
+ __tablename__ = 'b'
+ id = Column(Integer, ForeignKey('a.id'),
+ primary_key=True)
+ return B
+ self._do_test(go)
+
class NoPKOnSubTableWarningTest(fixtures.TestBase):
def _fixture(self):