diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-05-26 07:40:56 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-05-26 07:41:36 +0200 |
commit | 49c4d1f31014605c9355b1f6901e28e5762301d1 (patch) | |
tree | 8293343bf138ef2d53ab118b667fe1205d2b0bd7 /sources/pyside2/tests | |
parent | 10390cc16084c5f386163664f6e42d9e4d28b129 (diff) | |
parent | 6717d3540fac74c91d9381958a08e60f6532d402 (diff) |
Merge remote-tracking branch 'origin/5.14' into 5.15
Change-Id: I9c7163094bc934f481002adcea78ef4928ed26be
Diffstat (limited to 'sources/pyside2/tests')
-rw-r--r-- | sources/pyside2/tests/QtCore/qenum_test.py | 50 | ||||
-rw-r--r-- | sources/pyside2/tests/QtUiTools/loadUiType_test.py | 75 | ||||
-rw-r--r-- | sources/pyside2/tests/QtWidgets/qwidget_test.py | 4 | ||||
-rw-r--r-- | sources/pyside2/tests/registry/existence_test.py | 16 |
4 files changed, 141 insertions, 4 deletions
diff --git a/sources/pyside2/tests/QtCore/qenum_test.py b/sources/pyside2/tests/QtCore/qenum_test.py index dd91d1581..1edb8981a 100644 --- a/sources/pyside2/tests/QtCore/qenum_test.py +++ b/sources/pyside2/tests/QtCore/qenum_test.py @@ -30,15 +30,18 @@ '''Test cases for QEnum and QFlags''' +import gc import os import sys +import pickle import unittest sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from init_paths import init_test_paths init_test_paths(False) -from PySide2.QtCore import * +from PySide2.QtCore import Qt, QIODevice + class TestEnum(unittest.TestCase): @@ -73,6 +76,23 @@ class TestEnum(unittest.TestCase): with self.assertRaises(TypeError): a = k*2.0 + @unittest.skipUnless(getattr(sys, "getobjects", None), "requires debug build") + def testEnumNew_NoLeak(self): + gc.collect() + total = sys.gettotalrefcount() + for idx in range(1000): + ret = Qt.Key(42) + gc.collect() + delta = sys.gettotalrefcount() - total + print("delta total refcount =", delta) + if abs(delta) >= 10: + all = sys.getobjects(0) + all.sort(key=lambda x: sys.getrefcount(x), reverse=True) + for ob in all[:10]: + print(sys.getrefcount(ob), ob) + self.assertTrue(abs(delta) < 10) + + class TestQFlags(unittest.TestCase): def testToItn(self): om = QIODevice.NotOpen @@ -94,5 +114,33 @@ class TestQFlags(unittest.TestCase): except: pass + +# PYSIDE-15: Pickling of enums +class TestEnumPickling(unittest.TestCase): + def testPickleEnum(self): + + # Pickling of enums with different depth works. + ret = pickle.loads(pickle.dumps(QIODevice.Append)) + self.assertEqual(ret, QIODevice.Append) + + ret = pickle.loads(pickle.dumps(Qt.Key.Key_Asterisk)) + self.assertEqual(ret, Qt.Key.Key_Asterisk) + self.assertEqual(ret, Qt.Key(42)) + + # We can also pickle the whole enum class (built in): + ret = pickle.loads(pickle.dumps(QIODevice)) + + # This works also with nested classes for Python 3, after we + # introduced the correct __qualname__ attribute. + + # Note: For Python 2, we would need quite strange patches. + func = lambda: pickle.loads(pickle.dumps(Qt.Key)) + if sys.version_info[0] < 3: + with self.assertRaises(pickle.PicklingError): + func() + else: + func() + + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside2/tests/QtUiTools/loadUiType_test.py b/sources/pyside2/tests/QtUiTools/loadUiType_test.py new file mode 100644 index 000000000..9a3756376 --- /dev/null +++ b/sources/pyside2/tests/QtUiTools/loadUiType_test.py @@ -0,0 +1,75 @@ +############################################################################# +## +## Copyright (C) 2020 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$ +## +############################################################################# + +import os +import sys +import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths(False) + +from helper.usesqapplication import UsesQApplication + +from PySide2.QtWidgets import QWidget, QFrame, QPushButton +from PySide2.QtUiTools import loadUiType + +class loadUiTypeTester(UsesQApplication): + def testFunction(self): + filePath = os.path.join(os.path.dirname(__file__), "minimal.ui") + loaded = loadUiType(filePath) + self.assertNotEqual(loaded, None) + + # (<class '__main__.Ui_Form'>, <class 'PySide2.QtWidgets.QFrame'>) + generated, base = loaded + + # Generated class contains retranslateUi method + self.assertTrue("retranslateUi" in dir(generated)) + + # Base class instance will be QFrame for this example + self.assertTrue(isinstance(base(), QFrame)) + + anotherFileName = os.path.join(os.path.dirname(__file__), "test.ui") + another = loadUiType(anotherFileName) + self.assertNotEqual(another, None) + + generated, base = another + # Base class instance will be QWidget for this example + self.assertTrue(isinstance(base(), QWidget)) + + w = base() + ui = generated() + ui.setupUi(w) + + self.assertTrue(isinstance(ui.child_object, QFrame)) + self.assertTrue(isinstance(ui.grandson_object, QPushButton)) + + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/QtWidgets/qwidget_test.py b/sources/pyside2/tests/QtWidgets/qwidget_test.py index 74e97d7be..5e94a8248 100644 --- a/sources/pyside2/tests/QtWidgets/qwidget_test.py +++ b/sources/pyside2/tests/QtWidgets/qwidget_test.py @@ -61,7 +61,9 @@ class QWidgetTest(UsesQApplication): if sys.version_info[0] < 3: def testCallType_Issue_816(self): thing = type(QWidget).__new__(type(QWidget), "", (), {}) - self.assertEqual(repr(thing), "<class '__main__.'>") + # PYSIDE-1286: This works now like in Python 3 + #self.assertEqual(repr(thing), "<class '__main__.'>") + self.assertEqual(repr(thing), "<class '__main__.ObjectType'>") class QWidgetVisible(UsesQApplication): diff --git a/sources/pyside2/tests/registry/existence_test.py b/sources/pyside2/tests/registry/existence_test.py index 4bfd63cc3..b8a42058d 100644 --- a/sources/pyside2/tests/registry/existence_test.py +++ b/sources/pyside2/tests/registry/existence_test.py @@ -1,6 +1,6 @@ ############################################################################# ## -## Copyright (C) 2019 The Qt Company Ltd. +## Copyright (C) 2020 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of Qt for Python. @@ -67,6 +67,7 @@ List entry """ import os +import re import sys from textwrap import dedent import unittest @@ -144,8 +145,19 @@ class TestSignaturesExists(unittest.TestCase): name = key.rsplit(".", 1)[-1] if name in ("next", "__next__"): # ignore problematic cases continue + if "<" in key: + # Skip over remaining crap in "<...>" + continue + if key.startswith("sample.SampleNamespace"): + # We cannot work with sample namespaces after the change to __qualname__. + continue + if (key.startswith("smart.SharedPtr") or + re.match(r"PySide2\..*?\.QSharedPointer_", key)): + # These mangled names are not supported. + # We should fix them. + continue if key not in found_sigs: - warn("missing key: '{}'".format(key), stacklevel=3) + warn("missing key: '{} value={}'".format(key, value), stacklevel=3) else: found_val = found_sigs[key] if type(value) is list and ( |