Fix storing subclass wrapper in a C++ library and later getting it back with the original wrapper preserved.
This commit is contained in:
1 parent
a579744742
commit
1ee738f731
2 files changed
+95
-44
No files matched your search
@@ -228,6 +228,7 @@ class TestFoo(unittest.TestCase):
|
||||
|
||||
## now get the object back from the C side..
|
||||
obj = foo.take_some_object()
|
||||
self.assertEqual(obj.get_prefix(), "xxx")
|
||||
|
||||
del obj
|
||||
while gc.collect():
|
||||
@@ -269,5 +270,29 @@ class TestFoo(unittest.TestCase):
|
||||
self.assertEqual(foo.SomeObject.instance_count, count_before)
|
||||
|
||||
|
||||
def test_subclassed_store_and_take_back(self):
|
||||
class Test(foo.SomeObject):
|
||||
pass
|
||||
|
||||
while gc.collect():
|
||||
pass
|
||||
count_before = foo.SomeObject.instance_count
|
||||
obj1 = Test("xxx")
|
||||
obj1.attribute = 123
|
||||
foo.store_some_object(obj1)
|
||||
|
||||
## now get the object back from the C side..
|
||||
obj2 = foo.take_some_object()
|
||||
|
||||
self.assert_(obj2 is obj1)
|
||||
self.assertEqual(obj2.attribute, 123)
|
||||
self.assertEqual(obj2.get_prefix(), "xxx")
|
||||
|
||||
del obj1, obj2
|
||||
while gc.collect():
|
||||
pass
|
||||
## check that SomeObject was finally deleted
|
||||
self.assertEqual(foo.SomeObject.instance_count, count_before)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user