diff options
author | Christian Tismer <tismer@stackless.com> | 2021-10-25 19:22:33 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2021-10-27 14:07:48 +0200 |
commit | c7c789b1822fe0b2e77e66e5c1a66a16b3c3c405 (patch) | |
tree | d299b5cce39f42335f03eb4711e5634e2e122aec /sources/shiboken6/tests | |
parent | 55eebea1a48cbf5c2caef5b89226ad5c1fb18971 (diff) |
PyPySide: fix quite a few tests using del or __del__
In PyPy, the __del__ method is only triggered
reliably by calling gc.collect()
Also, the del statement does a deletion from the namespace,
but the real deletion happens when gc.collent() is called.
This was applied to all tests which use del, regardless if
it has a visible effect on PyPy or not. It turned out to
save more 8 errors, which is great.
Task-number: PYSIDE-535
Change-Id: I6a58d90629c9eafec7307c17f021251113b3c7f2
Pick-to: 6.2
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6/tests')
18 files changed, 119 insertions, 23 deletions
diff --git a/sources/shiboken6/tests/otherbinding/otherderived_test.py b/sources/shiboken6/tests/otherbinding/otherderived_test.py index 9a68e2ad4..946f82121 100644 --- a/sources/shiboken6/tests/otherbinding/otherderived_test.py +++ b/sources/shiboken6/tests/otherbinding/otherderived_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -31,6 +31,7 @@ '''Test cases for OtherDerived class''' +import gc import os import sys import unittest @@ -75,6 +76,8 @@ class MultipleTest(unittest.TestCase): self.assertTrue(isinstance(o, Number)) self.assertTrue(isinstance(o, Derived)) del o + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def testMethodCall(self): o = Multiple() diff --git a/sources/shiboken6/tests/samplebinding/__del___test.py b/sources/shiboken6/tests/samplebinding/__del___test.py index 146e6e409..829aa3ec6 100644 --- a/sources/shiboken6/tests/samplebinding/__del___test.py +++ b/sources/shiboken6/tests/samplebinding/__del___test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -29,6 +29,7 @@ ## ############################################################################# +import gc import os import sys import unittest @@ -51,6 +52,8 @@ class TestDel(unittest.TestCase): def testIt(self): a = MyObject() del a + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertTrue(delCalled) if __name__ == '__main__': diff --git a/sources/shiboken6/tests/samplebinding/argumentmodifications_test.py b/sources/shiboken6/tests/samplebinding/argumentmodifications_test.py index 86d0a4731..8cdcc1d0d 100644 --- a/sources/shiboken6/tests/samplebinding/argumentmodifications_test.py +++ b/sources/shiboken6/tests/samplebinding/argumentmodifications_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -31,6 +31,7 @@ '''Test cases for method arguments modifications performed as described on typesystem.''' +import gc import os import sys import unittest @@ -50,6 +51,8 @@ class ArgumentModificationsTest(unittest.TestCase): def tearDown(self): del self.mods + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def testArgRemoval0(self): '''Tests argument removal modifications on Modifications.argRemoval0.''' diff --git a/sources/shiboken6/tests/samplebinding/child_return_test.py b/sources/shiboken6/tests/samplebinding/child_return_test.py index 4b9a18e7b..1f5fd809b 100644 --- a/sources/shiboken6/tests/samplebinding/child_return_test.py +++ b/sources/shiboken6/tests/samplebinding/child_return_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -31,6 +31,7 @@ '''The BlackBox class has cases of ownership transference between C++ and Python.''' +import gc import os import sys import unittest @@ -50,6 +51,8 @@ class ReturnOfChildTest(unittest.TestCase): o1 = ObjectType.createWithChild() child = o1.children()[0] del o1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, child.objectName) def testKillParentKeepingChild2(self): @@ -57,6 +60,8 @@ class ReturnOfChildTest(unittest.TestCase): o1 = ObjectType.createWithChild() child = o1.findChild("child") del o1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, child.objectName) if __name__ == '__main__': diff --git a/sources/shiboken6/tests/samplebinding/cyclic_test.py b/sources/shiboken6/tests/samplebinding/cyclic_test.py index 5a20216b6..11e346297 100644 --- a/sources/shiboken6/tests/samplebinding/cyclic_test.py +++ b/sources/shiboken6/tests/samplebinding/cyclic_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -29,6 +29,7 @@ ## ############################################################################# +import gc import os import sys import unittest @@ -50,8 +51,6 @@ class ObjTest(unittest.TestCase): only be removed by the garbage collector, and then invoke the garbage collector in a different thread. """ - import gc - class CyclicChildObject(ObjectType): def __init__(self, parent): super(CyclicChildObject, self).__init__(parent) @@ -74,7 +73,9 @@ class ObjTest(unittest.TestCase): cycle = CyclicObject() self.assertTrue(alive()) del cycle - self.assertTrue(alive()) + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: the semantics of gc.enable/gc.disable is different for PyPy + self.assertTrue(alive()) gc.collect() self.assertFalse(alive()) @@ -83,8 +84,6 @@ class ObjTest(unittest.TestCase): only be removed by the garbage collector, and then invoke the garbage collector in a different thread. """ - import gc - class CyclicChildObject(ObjectView): def __init__(self, model): super(CyclicChildObject, self).__init__(None) @@ -107,7 +106,9 @@ class ObjTest(unittest.TestCase): cycle = CyclicObject() self.assertTrue(alive()) del cycle - self.assertTrue(alive()) + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: the semantics of gc.enable/gc.disable is different for PyPy + self.assertTrue(alive()) gc.collect() self.assertFalse(alive()) diff --git a/sources/shiboken6/tests/samplebinding/modifications_test.py b/sources/shiboken6/tests/samplebinding/modifications_test.py index 3429ccd0f..f67614c98 100644 --- a/sources/shiboken6/tests/samplebinding/modifications_test.py +++ b/sources/shiboken6/tests/samplebinding/modifications_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -31,6 +31,7 @@ '''Test cases for method modifications performed as described on type system. ''' +import gc import os import sys import unittest @@ -64,6 +65,8 @@ class ModificationsTest(unittest.TestCase): def tearDown(self): del self.mods + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def testClassMembersAvailability(self): '''Test if Modified class really have the expected members.''' diff --git a/sources/shiboken6/tests/samplebinding/modifiedvirtualmethods_test.py b/sources/shiboken6/tests/samplebinding/modifiedvirtualmethods_test.py index b59e64a00..538488396 100644 --- a/sources/shiboken6/tests/samplebinding/modifiedvirtualmethods_test.py +++ b/sources/shiboken6/tests/samplebinding/modifiedvirtualmethods_test.py @@ -31,6 +31,7 @@ '''Test cases for modified virtual methods.''' +import gc import os import sys import unittest @@ -100,6 +101,8 @@ class VirtualMethodsTest(unittest.TestCase): def tearDown(self): del self.vm del self.evm + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def testModifiedVirtualMethod0(self): '''Renamed virtual method.''' diff --git a/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py b/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py index 10b2f0ca9..ff7a25ea4 100644 --- a/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py +++ b/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -31,6 +31,7 @@ '''Tests cases for ObjectTypeLayout class.''' +import gc import os import sys import unittest @@ -84,6 +85,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): p1.setLayout(layout) del p1 # This must kill c1, c2 and c3 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -106,6 +109,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): p1.setLayout(layout) del p1 # This must kill c1, c2 and c3 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -165,6 +170,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(l2.parent(), l1) del p1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -201,6 +208,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(l2.parent(), l1) del p1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -239,6 +248,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): p2.setLayout(l1) del p1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(c1.parent(), p2) self.assertEqual(c2.parent(), p2) @@ -248,6 +259,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(l2.parent(), l1) del p2 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -287,6 +300,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): p2.setLayout(l1) del p1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(c1.parent(), p2) self.assertEqual(c2.parent(), p2) @@ -296,6 +311,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(l2.parent(), l1) del p2 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) diff --git a/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_python_test.py b/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_python_test.py index 10535f272..d33e784f1 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_python_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_python_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -31,6 +31,7 @@ '''Tests for deleting a child object in python''' +import gc import os import random import string @@ -56,6 +57,8 @@ class DeleteChildInPython(unittest.TestCase): child.setObjectName(name) del child + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() new_child = parent.children()[0] self.assertEqual(new_child.objectName(), name) diff --git a/sources/shiboken6/tests/samplebinding/ownership_delete_parent_test.py b/sources/shiboken6/tests/samplebinding/ownership_delete_parent_test.py index 310bf08ee..4b20affda 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_delete_parent_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_delete_parent_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -31,6 +31,7 @@ '''Tests for destroying the parent''' +import gc import os import sys import unittest @@ -56,6 +57,8 @@ class DeleteParentTest(unittest.TestCase): refcount_before = sys.getrefcount(child) del parent + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, child.objectName) self.assertEqual(sys.getrefcount(child), refcount_before-1) @@ -69,6 +72,8 @@ class DeleteParentTest(unittest.TestCase): child.setParent(parent) del parent + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() for i, child in enumerate(children): self.assertRaises(RuntimeError, child.objectName) self.assertEqual(sys.getrefcount(child), 4) @@ -81,6 +86,8 @@ class DeleteParentTest(unittest.TestCase): grandchild = ObjectType(child) del parent + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, child.objectName) self.assertEqual(sys.getrefcount(child), 2) self.assertRaises(RuntimeError, grandchild.objectName) diff --git a/sources/shiboken6/tests/samplebinding/ownership_invalidate_child_test.py b/sources/shiboken6/tests/samplebinding/ownership_invalidate_child_test.py index 6ffa6629b..7d45462b6 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_invalidate_child_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_invalidate_child_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -31,6 +31,7 @@ '''Tests for invalidating a C++ created child that was already on the care of a parent.''' +import gc import os import sys import unittest @@ -67,6 +68,8 @@ class InvalidateChildTest(unittest.TestCase): self.assertEqual(parent.children(), []) del parent + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(child1.objectName(), 'child1') self.assertRaises(RuntimeError, child2.objectName) diff --git a/sources/shiboken6/tests/samplebinding/ownership_transference_test.py b/sources/shiboken6/tests/samplebinding/ownership_transference_test.py index 9d9492e29..541d2fca0 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_transference_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_transference_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -31,6 +31,7 @@ '''The BlackBox class has cases of ownership transference between C++ and Python.''' +import gc import os import sys import unittest @@ -65,6 +66,8 @@ class BlackBoxTest(unittest.TestCase): o2 = bb.retrieveObjectType(o2_ticket) self.assertEqual(sys.getrefcount(o2), o2_refcnt) del bb + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, o1.objectName) self.assertEqual(str(o2.objectName()), 'object2') self.assertEqual(sys.getrefcount(o2), o2_refcnt) diff --git a/sources/shiboken6/tests/samplebinding/protected_test.py b/sources/shiboken6/tests/samplebinding/protected_test.py index 096eb615d..aaac495cf 100644 --- a/sources/shiboken6/tests/samplebinding/protected_test.py +++ b/sources/shiboken6/tests/samplebinding/protected_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -31,6 +31,7 @@ '''Test cases for protected methods.''' +import gc import os import sys import unittest @@ -187,7 +188,11 @@ class ProtectedVirtualDtorTest(unittest.TestCase): dtor_called = ProtectedVirtualDestructor.dtorCalled() for i in range(1, 10): pvd = ProtectedVirtualDestructor() + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() del pvd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(ProtectedVirtualDestructor.dtorCalled(), dtor_called + i) def testVirtualProtectedDtorOnCppCreatedObject(self): @@ -196,6 +201,8 @@ class ProtectedVirtualDtorTest(unittest.TestCase): for i in range(1, 10): pvd = ProtectedVirtualDestructor.create() del pvd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(ProtectedVirtualDestructor.dtorCalled(), dtor_called + i) def testProtectedDtorOnDerivedClass(self): @@ -204,6 +211,8 @@ class ProtectedVirtualDtorTest(unittest.TestCase): for i in range(1, 10): pvd = ExtendedProtectedVirtualDestructor() del pvd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(ExtendedProtectedVirtualDestructor.dtorCalled(), dtor_called + i) @@ -282,6 +291,8 @@ class ProtectedPropertyTest(unittest.TestCase): def tearDown(self): del self.obj + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), 0) def testProtectedProperty(self): @@ -323,6 +334,8 @@ class ProtectedPropertyTest(unittest.TestCase): pointProperty = obj.protectedValueTypeProperty self.assertTrue(obj.protectedValueTypeProperty is pointProperty) del obj, point, pointProperty + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), cache_size) def testProtectedValueTypePointerProperty(self): diff --git a/sources/shiboken6/tests/samplebinding/typedealloc_test.py b/sources/shiboken6/tests/samplebinding/typedealloc_test.py index 32a15e300..10f66cba7 100644 --- a/sources/shiboken6/tests/samplebinding/typedealloc_test.py +++ b/sources/shiboken6/tests/samplebinding/typedealloc_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -52,6 +52,8 @@ class TypeDeallocTest(unittest.TestCase): def tearDown(self): del self.called + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def callback(self, *args): self.called = True diff --git a/sources/shiboken6/tests/samplebinding/virtualdtor_test.py b/sources/shiboken6/tests/samplebinding/virtualdtor_test.py index 8f29eca3c..7a94f21d2 100644 --- a/sources/shiboken6/tests/samplebinding/virtualdtor_test.py +++ b/sources/shiboken6/tests/samplebinding/virtualdtor_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -31,6 +31,7 @@ '''Test cases for virtual destructor.''' +import gc import os import sys import unittest @@ -58,6 +59,8 @@ class VirtualDtorTest(unittest.TestCase): for i in range(1, 10): vd = VirtualDtor() del vd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(VirtualDtor.dtorCalled(), dtor_called + i) def testVirtualDtorOnCppCreatedObject(self): @@ -66,6 +69,8 @@ class VirtualDtorTest(unittest.TestCase): for i in range(1, 10): vd = VirtualDtor.create() del vd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(VirtualDtor.dtorCalled(), dtor_called + i) def testDtorOnDerivedClass(self): @@ -74,6 +79,8 @@ class VirtualDtorTest(unittest.TestCase): for i in range(1, 10): evd = ExtendedVirtualDtor() del evd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(ExtendedVirtualDtor.dtorCalled(), dtor_called + i) diff --git a/sources/shiboken6/tests/samplebinding/virtualmethods_test.py b/sources/shiboken6/tests/samplebinding/virtualmethods_test.py index 1c842993c..67220071e 100644 --- a/sources/shiboken6/tests/samplebinding/virtualmethods_test.py +++ b/sources/shiboken6/tests/samplebinding/virtualmethods_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -31,6 +31,7 @@ '''Test cases for virtual methods.''' +import gc import os import sys import unittest @@ -88,6 +89,8 @@ class VirtualMethodsTest(unittest.TestCase): def tearDown(self): del self.prefix_from_codeinjection + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def testReimplementedVirtualMethod0(self): '''Test Python override of a virtual method with various different parameters is correctly called from C++.''' diff --git a/sources/shiboken6/tests/samplebinding/weakref_test.py b/sources/shiboken6/tests/samplebinding/weakref_test.py index 6ca031c0d..03d99979a 100644 --- a/sources/shiboken6/tests/samplebinding/weakref_test.py +++ b/sources/shiboken6/tests/samplebinding/weakref_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -31,6 +31,7 @@ '''Test weakref support''' +import gc import os import sys import unittest @@ -58,6 +59,8 @@ class WeakrefBasicTest(unittest.TestCase): obj = ObjectType() ref = weakref.ref(obj, self.cb) del obj + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertTrue(self.called) def testPrivateDtor(self): @@ -65,6 +68,8 @@ class WeakrefBasicTest(unittest.TestCase): obj = PrivateDtor.instance() ref = weakref.ref(obj, self.cb) del obj + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertTrue(self.called) diff --git a/sources/shiboken6/tests/smartbinding/smart_pointer_test.py b/sources/shiboken6/tests/smartbinding/smart_pointer_test.py index 1bdce333e..10e761149 100644 --- a/sources/shiboken6/tests/smartbinding/smart_pointer_test.py +++ b/sources/shiboken6/tests/smartbinding/smart_pointer_test.py @@ -3,7 +3,7 @@ # ############################################################################# ## -## Copyright (C) 2017 The Qt Company Ltd. +## Copyright (C) 2021 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -99,10 +99,14 @@ class SmartPointerTests(unittest.TestCase): # Delete the first shared pointer, object count should not change because the second # one still has a reference. del ptrToObj + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(objCount(), 1) # Delete the second smart pointer, object should be deleted. del ptrToObj2 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(objCount(), 0) self.assertEqual(integerCount(), 0) @@ -146,15 +150,21 @@ class SmartPointerTests(unittest.TestCase): # Delete the first shared pointer, integer count should not change because the second # one still has a reference. del ptrToInteger + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(integerCount(), 2) # Delete the second smart pointer, integer should be deleted. del ptrToInteger2 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(objCount(), 1) self.assertEqual(integerCount(), 1) # Delete the original object which was used to create the integer. del o + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(objCount(), 0) self.assertEqual(integerCount(), 0) @@ -199,6 +209,8 @@ class SmartPointerTests(unittest.TestCase): # clear and delete all objects in the list del ptrToObjList[:] # Python 2.7 lists have no clear method + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(len(ptrToObjList), 0) self.assertEqual(objCount(), 1) |