diff options
Diffstat (limited to 'sources/shiboken6/tests/samplebinding/objecttypelayout_test.py')
-rw-r--r-- | sources/shiboken6/tests/samplebinding/objecttypelayout_test.py | 77 |
1 files changed, 35 insertions, 42 deletions
diff --git a/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py b/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py index 76f028f51..677b89281 100644 --- a/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py +++ b/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py @@ -1,36 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $QT_BEGIN_LICENSE:GPL-EXCEPT$ -## Commercial License Usage -## Licensees holding valid commercial Qt licenses may use this file in -## accordance with the commercial license agreement provided with the -## Software or, alternatively, in accordance with the terms contained in -## a written agreement between you and The Qt Company. For licensing terms -## and conditions see https://www.qt.io/terms-conditions. For further -## information use the contact form at https://www.qt.io/contact-us. -## -## GNU General Public License Usage -## Alternatively, this file may be used under the terms of the GNU -## General Public License version 3 as published by the Free Software -## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -## included in the packaging of this file. Please review the following -## information to ensure the GNU General Public License requirements will -## be met: https://www.gnu.org/licenses/gpl-3.0.html. -## -## $QT_END_LICENSE$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests cases for ObjectTypeLayout class.''' +import gc import os import sys import unittest @@ -40,23 +14,23 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ObjectType, ObjectTypeLayout class ObjectTypeLayoutTest(unittest.TestCase): '''Test cases for ObjectTypeLayout class.''' + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testOwnershipOverride(self): - l = ObjectTypeLayout() + lt = ObjectTypeLayout() - o1 = ObjectType(l) + o1 = ObjectType(lt) o1.setObjectName('o1') self.assertEqual(sys.getrefcount(o1), 3) - l.takeChild('o1') + lt.takeChild('o1') self.assertEqual(sys.getrefcount(o1), 2) - def testSetNullLayout(self): '''ObjectType.setLayout(0).''' o2 = ObjectType() @@ -82,7 +56,9 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(c3.parent(), None) p1.setLayout(layout) - del p1 # This must kill c1, c2 and c3 + 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) @@ -104,7 +80,9 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(c3.parent(), None) p1.setLayout(layout) - del p1 # This must kill c1, c2 and c3 + 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) @@ -112,7 +90,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertRaises(RuntimeError, layout.objectName) def testObjectTypeLayoutTransference(self): - '''Transfer a layout from one ObjectType to another, so that all the items in the layout get reparented.''' + '''Transfer a layout from one ObjectType to another, so that all the items in + the layout get reparented.''' p1 = ObjectType() p2 = ObjectType() c1 = ObjectType() @@ -164,6 +143,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) @@ -173,7 +154,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertRaises(RuntimeError, l2.objectName) def testObjectTypeLayoutInsideAnotherLayoutAndEveryoneCreatedInCpp(self): - '''Adds one ObjectTypeLayout to another and sets the parent to an ObjectType. All the objects are created in C++.''' + '''Adds one ObjectTypeLayout to another and sets the parent to an ObjectType. + All the objects are created in C++.''' p1 = ObjectType.create() l1 = ObjectTypeLayout.create() @@ -200,6 +182,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) @@ -209,7 +193,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertRaises(RuntimeError, l2.objectName) def testTransferNestedLayoutsBetweenObjects(self): - '''Adds one ObjectTypeLayout to another, sets the parent to an ObjectType and then transfer it to another object.''' + '''Adds one ObjectTypeLayout to another, sets the parent to an ObjectType + and then transfer it to another object.''' p1 = ObjectType() p2 = ObjectType() @@ -238,6 +223,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) @@ -247,6 +234,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) @@ -256,8 +245,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertRaises(RuntimeError, l2.objectName) def testTransferNestedLayoutsBetweenObjectsAndEveryoneCreatedInCpp(self): - '''Adds one ObjectTypeLayout to another, sets the parent to an ObjectType and then transfer it to another object. - All the objects are created in C++.''' + '''Adds one ObjectTypeLayout to another, sets the parent to an ObjectType and then + transfer it to another object. All the objects are created in C++.''' p1 = ObjectType.create() p2 = ObjectType.create() @@ -286,6 +275,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) @@ -295,6 +286,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) @@ -303,6 +296,6 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertRaises(RuntimeError, l1.objectName) self.assertRaises(RuntimeError, l2.objectName) + if __name__ == '__main__': unittest.main() - |