diff options
Diffstat (limited to 'sources/pyside2/tests')
24 files changed, 354 insertions, 224 deletions
diff --git a/sources/pyside2/tests/CMakeLists.txt b/sources/pyside2/tests/CMakeLists.txt index 2386950e9..4289012a8 100644 --- a/sources/pyside2/tests/CMakeLists.txt +++ b/sources/pyside2/tests/CMakeLists.txt @@ -54,6 +54,7 @@ else() endif() add_subdirectory(registry) add_subdirectory(signals) + add_subdirectory(support) foreach(shortname IN LISTS all_module_shortnames) message(STATUS "preparing tests for module 'Qt${shortname}'") diff --git a/sources/pyside2/tests/QtCore/CMakeLists.txt b/sources/pyside2/tests/QtCore/CMakeLists.txt index 649e796cc..08e63d043 100644 --- a/sources/pyside2/tests/QtCore/CMakeLists.txt +++ b/sources/pyside2/tests/QtCore/CMakeLists.txt @@ -52,6 +52,7 @@ PYSIDE_TEST(qbytearray_concatenation_operator_test.py) PYSIDE_TEST(qbytearray_operator_iadd_test.py) PYSIDE_TEST(qbytearray_operator_test.py) PYSIDE_TEST(qbytearray_test.py) +PYSIDE_TEST(qcbor_test.py) PYSIDE_TEST(qcollator_test.py) PYSIDE_TEST(qcommandlineparser_test.py) PYSIDE_TEST(qcoreapplication_instance_test.py) @@ -67,6 +68,7 @@ PYSIDE_TEST(qfile_test.py) PYSIDE_TEST(qfileread_test.py) PYSIDE_TEST(qflags_test.py) PYSIDE_TEST(qinstallmsghandler_test.py) +PYSIDE_TEST(qjsondocument_test.py) PYSIDE_TEST(qlinef_test.py) PYSIDE_TEST(qlocale_test.py) PYSIDE_TEST(qlockfile_test.py) diff --git a/sources/pyside2/tests/QtCore/bug_826.py b/sources/pyside2/tests/QtCore/bug_826.py index 5e3a12146..b5701fc5a 100644 --- a/sources/pyside2/tests/QtCore/bug_826.py +++ b/sources/pyside2/tests/QtCore/bug_826.py @@ -46,8 +46,8 @@ class TestEvent(QEvent): class TestEnums(unittest.TestCase): def testUserTypesValues(self): - self.assertTrue(QEvent.User <= int(TestEvent.TestEventType) <= QEvent.MaxUser) - self.assertTrue(QEvent.User <= int(TEST_EVENT_TYPE) <= QEvent.MaxUser) + self.assertTrue(QEvent.User <= TestEvent.TestEventType <= QEvent.MaxUser) + self.assertTrue(QEvent.User <= TEST_EVENT_TYPE <= QEvent.MaxUser) def testUserTypesRepr(self): self.assertEqual(eval(repr(TestEvent.TestEventType)), TestEvent.TestEventType) diff --git a/sources/pyside2/tests/QtCore/qabstractitemmodel_test.py b/sources/pyside2/tests/QtCore/qabstractitemmodel_test.py index 70b610c34..fd8d01c99 100644 --- a/sources/pyside2/tests/QtCore/qabstractitemmodel_test.py +++ b/sources/pyside2/tests/QtCore/qabstractitemmodel_test.py @@ -34,14 +34,12 @@ from PySide2.QtCore import * class MyModel (QAbstractListModel): pass -class Foo: - pass class TestQModelIndexInternalPointer(unittest.TestCase): def testInternalPointer(self): m = MyModel() - foo = Foo() + foo = QObject() idx = m.createIndex(0,0, foo) check = m.checkIndex(idx, QAbstractItemModel.CheckIndexOption.IndexIsValid | QAbstractItemModel.CheckIndexOption.DoNotUseParent diff --git a/sources/pyside2/tests/QtCore/qcbor_test.py b/sources/pyside2/tests/QtCore/qcbor_test.py new file mode 100644 index 000000000..2ac46673a --- /dev/null +++ b/sources/pyside2/tests/QtCore/qcbor_test.py @@ -0,0 +1,74 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2018 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$ +## +############################################################################# + +'''Test cases for QCbor''' + +import unittest + +from PySide2.QtCore import (QByteArray, QCborStreamReader, QCborStreamWriter, + QCborValue) + +class TestCbor(unittest.TestCase): + def testReader(self): + ba = QByteArray() + writer = QCborStreamWriter(ba) + writer.append(42) + del writer + self.assertTrue(not ba.isEmpty()) + reader = QCborStreamReader(ba) + self.assertTrue(reader.hasNext()) + value = reader.toInteger() + self.assertEqual(value, 42) + + def testReader(self): + ba = QByteArray() + writer = QCborStreamWriter(ba) + writer.append("hello") + del writer + self.assertTrue(not ba.isEmpty()) + reader = QCborStreamReader(ba) + self.assertTrue(reader.hasNext()) + if (reader.isByteArray()): # Python 2 + value = reader.readByteArray() + self.assertTrue(value) + self.assertEqual(value.data, "hello") + else: + self.assertTrue(reader.isString()) + value = reader.readString() + self.assertTrue(value) + self.assertEqual(value.data, "hello") + + def testValue(self): + value = QCborValue('hello') + self.assertTrue(value.isString()) + self.assertEqual(value.toString(), 'hello') + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtCore/qenum_test.py b/sources/pyside2/tests/QtCore/qenum_test.py index eccbfac23..ada625f24 100644 --- a/sources/pyside2/tests/QtCore/qenum_test.py +++ b/sources/pyside2/tests/QtCore/qenum_test.py @@ -49,6 +49,24 @@ class TestEnum(unittest.TestCase): def testToIntInFunction(self): self.assertEqual(str(int(QIODevice.WriteOnly)), "2") + def testOperations(self): + k = Qt.Key.Key_1 + + # Integers + self.assertEqual(k + 2, 2 + k) + self.assertEqual(k - 2, -(2 - k)) + self.assertEqual(k * 2, 2 * k) + + # Floats + with self.assertRaises(TypeError): + a = k+2.0 + + with self.assertRaises(TypeError): + a = k-2.0 + + with self.assertRaises(TypeError): + a = k*2.0 + class TestQFlags(unittest.TestCase): def testToItn(self): om = QIODevice.NotOpen diff --git a/sources/pyside2/tests/QtCore/qjsondocument_test.py b/sources/pyside2/tests/QtCore/qjsondocument_test.py new file mode 100644 index 000000000..0cd4dc5b2 --- /dev/null +++ b/sources/pyside2/tests/QtCore/qjsondocument_test.py @@ -0,0 +1,56 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2018 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$ +## +############################################################################# + +'''Test cases for QJsonDocument/nullptr_t''' + +import unittest +from PySide2.QtCore import QJsonDocument +import py3kcompat as py3k + +class QJsonDocumentTest(unittest.TestCase): + + def testToVariant(self): + a = QJsonDocument.fromJson(b'{"test": null}') + self.assertIsInstance(a, QJsonDocument) + if py3k.IS_PY3K: + self.assertEqual(str(a.toVariant()), "{'test': None}") + else: + self.assertEqual(str(a.toVariant()), "{u'test': None}") + + b = QJsonDocument.fromJson(b'{"test": [null]}') + self.assertIsInstance(b, QJsonDocument) + if py3k.IS_PY3K: + self.assertEqual(str(b.toVariant()), "{'test': [None]}") + else: + self.assertEqual(str(b.toVariant()), "{u'test': [None]}") + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtCore/qmetaobject_test.py b/sources/pyside2/tests/QtCore/qmetaobject_test.py index 12b5312a6..73ab81c7c 100644 --- a/sources/pyside2/tests/QtCore/qmetaobject_test.py +++ b/sources/pyside2/tests/QtCore/qmetaobject_test.py @@ -78,6 +78,12 @@ class qmetaobject_test(unittest.TestCase): #self.assertTrue(slot_index != signal_index) + # PYSIDE-784, plain Qt objects should not have intermediary + # metaObjects. + def test_PlainQObject(self): + timer = QTimer() + self.assertEqual(timer.metaObject().superClass().className(), + "QObject") if __name__ == '__main__': unittest.main() diff --git a/sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py b/sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py index 875d2075c..a67bb380a 100644 --- a/sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py +++ b/sources/pyside2/tests/QtCore/qmodelindex_internalpointer_test.py @@ -33,6 +33,7 @@ import sys import unittest from PySide2.QtCore import * +from PySide2.support import VoidPtr class MyModel (QAbstractListModel): pass @@ -50,22 +51,22 @@ class TestQModelIndexInternalPointer(unittest.TestCase): def testInternalPointer(self): #Test QAbstractListModel.createIndex and - #QModelIndex.internalPointer with regular - #Python objects - idx = self.model.createIndex(0, 0, "Hello") - self.assertEqual("Hello", idx.internalPointer()) - a = [1, 2, 3] - idx = self.model.createIndex(0, 0, a) - self.assertEqual(a, idx.internalPointer()) + #QModelIndex.internalPointer + obj = QObject() + obj_ptr = VoidPtr(obj) + idx = self.model.createIndex(0, 0, obj) + i = idx.internalPointer() + self.assertEqual(int(obj_ptr), int(i)) def testReferenceCounting(self): #Test reference counting when retrieving data with #QModelIndex.internalPointer - a = [1, 2, 3] - a_refcnt = sys.getrefcount(a) - idx = self.model.createIndex(0, 0, a) + o = QObject() + o_refcnt = sys.getrefcount(o) + idx = self.model.createIndex(0, 0, o) ptr = idx.internalPointer() - self.assertEqual(sys.getrefcount(a), a_refcnt + 1) + self.assertEqual(sys.getrefcount(o), o_refcnt) + def testIndexForDefaultDataArg(self): #Test QAbstractListModel.createIndex with a default diff --git a/sources/pyside2/tests/QtCore/qrandomgenerator_test.py b/sources/pyside2/tests/QtCore/qrandomgenerator_test.py index 7d80510a7..2b732ad5e 100644 --- a/sources/pyside2/tests/QtCore/qrandomgenerator_test.py +++ b/sources/pyside2/tests/QtCore/qrandomgenerator_test.py @@ -3,7 +3,7 @@ ## Copyright (C) 2017 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## -## This file is part of the test suite of PySide2. +## This file is part of the test suite of Qt for Python. ## ## $QT_BEGIN_LICENSE:GPL-EXCEPT$ ## Commercial License Usage diff --git a/sources/pyside2/tests/QtGui/qmatrix_test.py b/sources/pyside2/tests/QtGui/qmatrix_test.py index cac8a7ab7..7cfe9ea60 100644 --- a/sources/pyside2/tests/QtGui/qmatrix_test.py +++ b/sources/pyside2/tests/QtGui/qmatrix_test.py @@ -29,7 +29,7 @@ import unittest from PySide2.QtCore import QPoint -from PySide2.QtGui import QMatrix, QMatrix4x4 +from PySide2.QtGui import QMatrix, QMatrix2x2, QMatrix4x4 def qpointTimesQMatrix(point, matrix): @@ -42,13 +42,26 @@ class QMatrixTest(unittest.TestCase): def testMatrix(self): matrix = QMatrix(11, 12, 21, 22, 100, 200) point = QPoint(3, 3) - self.assertEqual(point * matrix, qpointTimesQMatrix(point, matrix)) + self.assertEqual(matrix.map(point), qpointTimesQMatrix(point, matrix)) def testMatrixWithWrongType(self): matrix = QMatrix(11, 12, 21, 22, 100, 200) point = QPoint(3, 3) self.assertRaises(TypeError, matrix.__mul__, point) + def testMatrix2x2(self): + matrix = QMatrix2x2([1.0, 2.0, 3.0, 4.0]) + + expectedTransposed = QMatrix2x2([1.0, 3.0, 2.0, 4.0]) + self.assertEqual(matrix.transposed(), expectedTransposed) + + expectedMultiplied = QMatrix2x2([2.0, 4.0, 6.0, 8.0]) + matrix *= 2.0 + self.assertEqual(matrix, expectedMultiplied) + + matrix.setToIdentity() + self.assertTrue(matrix.isIdentity()) + def testMatrix4x4(self): self.assertRaises(TypeError, QMatrix4x4, [0.0, 1.0, 2.0, 3.0]) self.assertRaises(TypeError, QMatrix4x4, [0.0, 1.0, 2.0, 'I', diff --git a/sources/pyside2/tests/QtNetwork/CMakeLists.txt b/sources/pyside2/tests/QtNetwork/CMakeLists.txt index c14c19fa9..57c5266c8 100644 --- a/sources/pyside2/tests/QtNetwork/CMakeLists.txt +++ b/sources/pyside2/tests/QtNetwork/CMakeLists.txt @@ -3,6 +3,7 @@ PYSIDE_TEST(bug_1084.py) PYSIDE_TEST(accessManager_test.py) PYSIDE_TEST(dnslookup_test.py) # Qt5: QHttp is gone PYSIDE_TEST(http_test.py) +PYSIDE_TEST(qpassworddigestor_test.py) PYSIDE_TEST(tcpserver_test.py) PYSIDE_TEST(udpsocket_test.py) PYSIDE_TEST(qipv6address_test.py) diff --git a/sources/pyside2/tests/QtNetwork/qpassworddigestor_test.py b/sources/pyside2/tests/QtNetwork/qpassworddigestor_test.py new file mode 100644 index 000000000..503ffecdc --- /dev/null +++ b/sources/pyside2/tests/QtNetwork/qpassworddigestor_test.py @@ -0,0 +1,45 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2018 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$ +## +############################################################################# + +'''Test cases for QPasswordDigestor''' + +import unittest + +from PySide2.QtCore import QByteArray, QCryptographicHash +from PySide2.QtNetwork import QPasswordDigestor + +class TestPasswordDigestor(unittest.TestCase): + def test(self): + b = QPasswordDigestor.deriveKeyPbkdf1(QCryptographicHash.Sha1, + b'test', b'saltnpep', 10, 20) + self.assertEqual(b.size(), 20) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtWidgets/bug_493.py b/sources/pyside2/tests/QtWidgets/bug_493.py index 100959fbb..19cbb0023 100644 --- a/sources/pyside2/tests/QtWidgets/bug_493.py +++ b/sources/pyside2/tests/QtWidgets/bug_493.py @@ -32,7 +32,7 @@ from PySide2.QtWidgets import QApplication import unittest -class TestBug569(unittest.TestCase): +class TestBug493(unittest.TestCase): def testIt(self): # We need a qapp otherwise Qt will crash when trying to detect the @@ -42,10 +42,8 @@ class TestBug569(unittest.TestCase): ev2 = QKeyEvent(QEvent.KeyRelease, Qt.Key_Copy, Qt.NoModifier) ks = QKeySequence.Delete - self.assertEqual(ev1, ks) - self.assertEqual(ks, ev1) - self.assertNotEqual(ev2, ks) - self.assertNotEqual(ks, ev2) + self.assertTrue(ev1.matches(ks)) + self.assertFalse(ev2.matches(ks)) if __name__ == '__main__': unittest.main() diff --git a/sources/pyside2/tests/QtWidgets/python_properties_test.py b/sources/pyside2/tests/QtWidgets/python_properties_test.py index f5bcf5eb8..f4e46f2bd 100644 --- a/sources/pyside2/tests/QtWidgets/python_properties_test.py +++ b/sources/pyside2/tests/QtWidgets/python_properties_test.py @@ -39,6 +39,8 @@ class Properties(unittest.TestCase): p = QtWidgets.QStyleOptionViewItem() self.assertTrue(isinstance(p.locale, QtCore.QLocale)) + # PSYIDE-304, can assign to a "const QWidget *" field + p.widget = None if __name__ == '__main__': unittest.main() diff --git a/sources/pyside2/tests/QtWidgets/qlabel_test.py b/sources/pyside2/tests/QtWidgets/qlabel_test.py index 2c5616001..9d84b5c17 100644 --- a/sources/pyside2/tests/QtWidgets/qlabel_test.py +++ b/sources/pyside2/tests/QtWidgets/qlabel_test.py @@ -32,14 +32,7 @@ import unittest from PySide2.QtGui import QPixmap from PySide2.QtWidgets import QLabel -try: - # The normal import statement when PySide2 is installed. - from PySide2 import shiboken2 as shiboken -except ImportError: - # When running make test in shiboken build dir, or when running - # testrunner.py, shiboken2 is not part of the PySide2 module, - # so it needs to be imported as a standalone module. - import shiboken2 as shiboken +import shiboken2 as shiboken from helper import UsesQApplication diff --git a/sources/pyside2/tests/QtWidgets/qstandarditemmodel_test.py b/sources/pyside2/tests/QtWidgets/qstandarditemmodel_test.py index 7a34cf238..c07bd8705 100644 --- a/sources/pyside2/tests/QtWidgets/qstandarditemmodel_test.py +++ b/sources/pyside2/tests/QtWidgets/qstandarditemmodel_test.py @@ -31,14 +31,7 @@ import sys from PySide2.QtGui import QStandardItemModel, QStandardItem from PySide2.QtWidgets import QWidget -try: - # The normal import statement when PySide2 is installed. - from PySide2 import shiboken2 as shiboken -except ImportError: - # When running make test in shiboken build dir, or when running testrunner.py, - # shiboken2 is not part of the PySide2 module, so it needs to be imported as a standalone - # module. - import shiboken2 as shiboken +import shiboken2 as shiboken from helper import UsesQApplication diff --git a/sources/pyside2/tests/QtWidgets/qstyle_test.py b/sources/pyside2/tests/QtWidgets/qstyle_test.py index eb2a73d29..1dcce2737 100644 --- a/sources/pyside2/tests/QtWidgets/qstyle_test.py +++ b/sources/pyside2/tests/QtWidgets/qstyle_test.py @@ -26,6 +26,7 @@ ## ############################################################################# +import sys import unittest from helper import UsesQApplication @@ -78,6 +79,13 @@ class SetStyleTest(UsesQApplication): QApplication.instance().processEvents() self.assertTrue(proxyStyle.polished > 0) + def testSetStyleOwnership(self): + style = QStyleFactory.create(QStyleFactory.keys()[0]) + self.assertEqual(sys.getrefcount(style), 2) + QApplication.instance().setStyle(style) + self.assertEqual(sys.getrefcount(style), 3) + + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside2/tests/QtWidgets/qwidget_test.py b/sources/pyside2/tests/QtWidgets/qwidget_test.py index 1e8387d11..028751ba7 100644 --- a/sources/pyside2/tests/QtWidgets/qwidget_test.py +++ b/sources/pyside2/tests/QtWidgets/qwidget_test.py @@ -26,6 +26,7 @@ ## ############################################################################# +import sys import unittest from PySide2.QtWidgets import QWidget, QMainWindow @@ -35,6 +36,17 @@ class QWidgetInherit(QMainWindow): def __init__(self): QWidget.__init__(self) +class NativeEventTestWidget(QWidget): + + nativeEventCount = 0 + + def __init__(self): + QWidget.__init__(self) + + def nativeEvent(self, eventType, message): + self.nativeEventCount = self.nativeEventCount + 1 + return [False, 0] + class QWidgetTest(UsesQApplication): def testInheritance(self): @@ -44,12 +56,19 @@ class QWidgetVisible(UsesQApplication): def testBasic(self): # Also related to bug #244, on existence of setVisible''' - widget = QWidget() + widget = NativeEventTestWidget() self.assertTrue(not widget.isVisible()) widget.setVisible(True) self.assertTrue(widget.isVisible()) self.assertTrue(widget.winId() is not 0) - + # skip this test on macOS since no native events are received + if sys.platform == 'darwin': + return + for i in range(10): + if widget.nativeEventCount > 0: + break + self.app.processEvents() + self.assertTrue(widget.nativeEventCount > 0) if __name__ == '__main__': unittest.main() diff --git a/sources/pyside2/tests/pysidetest/CMakeLists.txt b/sources/pyside2/tests/pysidetest/CMakeLists.txt index c6d3bb13b..119553fad 100644 --- a/sources/pyside2/tests/pysidetest/CMakeLists.txt +++ b/sources/pyside2/tests/pysidetest/CMakeLists.txt @@ -3,9 +3,6 @@ project(testbinding) cmake_minimum_required(VERSION 3.1) -# On Windows, don't link to qtmain.lib for executables automatically. -cmake_policy(SET CMP0020 OLD) - set(QT_USE_QTCORE 1) # no more supported: include(${QT_USE_FILE}) add_definitions(${Qt5Core_DEFINITIONS}) @@ -69,7 +66,9 @@ make_path(testbinding_include_dirs ${pyside2_BINARY_DIR} make_path(testbinding_typesystem_path ${pyside2_SOURCE_DIR} ${pyside2_BINARY_DIR}) -add_custom_command(OUTPUT ${testbinding_SRC} +add_custom_command( +OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" +BYPRODUCTS ${testbinding_SRC} COMMAND ${SHIBOKEN_BINARY} ${GENERATOR_EXTRA_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/pysidetest_global.h --include-paths=${testbinding_include_dirs} @@ -119,6 +118,7 @@ target_link_libraries(testbinding ${SBK_PYTHON_LIBRARIES}) add_dependencies(testbinding pyside2 QtCore QtGui QtWidgets pysidetest) +create_generator_target(testbinding) PYSIDE_TEST(decoratedslot_test.py) # Will always crash when built against Qt 5.6, no point in running it. diff --git a/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py b/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py index 960f675ea..54b81acae 100644 --- a/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py +++ b/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py @@ -32,17 +32,16 @@ import sys import os import unittest -import PySide2.QtCore +from PySide2 import * +for modname, mod in sys.modules.items(): + # Python 2 leaves "None" in the dict. + if modname.startswith("PySide2.") and mod is not None: + print("importing", modname) + exec("import " + modname) # This test tests the existence and callability of the newly existing functions, # after the inheritance was made complete in the course of PYSIDE-331. -def warn_essential(modname): - print(80 * "*") - print("*** Warning: '{}' is an essential module! Are you sure to skip it?" - .format(modname)) - print(80 * "*") - new_functions = """ PySide2.QtCore.QAbstractItemModel().parent() PySide2.QtCore.QAbstractListModel().parent() @@ -52,85 +51,67 @@ new_functions = """ PySide2.QtCore.QSortFilterProxyModel().parent() PySide2.QtCore.QTemporaryFile(tfarg).open(openMode) """ -try: - modname = "PySide2.QtGui" - exec("import " + modname) - new_functions += """ - PySide2.QtGui.QBitmap().transformed(qMatrix,transformationMode) - PySide2.QtGui.QStandardItemModel().insertColumn(int,qModelIndex) - PySide2.QtGui.QStandardItemModel().parent() - # PySide2.QtGui.QTextList(qTextDocument).setFormat(qTextFormat) # Segmentation fault: 11 - # PySide2.QtGui.QTextTable(qTextDocument).setFormat(qTextFormat) # Segmentation fault: 11 - """ -except ImportError: - warn_essential(modname) -try: - modname = "PySide2.QtWidgets" - exec("import " + modname) - new_functions += """ - PySide2.QtWidgets.QAbstractItemView().update() - PySide2.QtWidgets.QApplication.palette() - PySide2.QtWidgets.QApplication.setFont(qFont) - PySide2.QtWidgets.QApplication.setPalette(qPalette) - PySide2.QtWidgets.QBoxLayout(direction).addWidget(qWidget) - PySide2.QtWidgets.QColorDialog().open() - PySide2.QtWidgets.QDirModel().index(int,int,qModelIndex) - PySide2.QtWidgets.QDirModel().parent() - PySide2.QtWidgets.QFileDialog().open() - PySide2.QtWidgets.QFileSystemModel().index(int,int,qModelIndex) - PySide2.QtWidgets.QFileSystemModel().parent() - PySide2.QtWidgets.QFontDialog().open() - PySide2.QtWidgets.QGestureEvent([]).accept() - PySide2.QtWidgets.QGestureEvent([]).ignore() - PySide2.QtWidgets.QGestureEvent([]).isAccepted() - PySide2.QtWidgets.QGestureEvent([]).setAccepted(bool) - # PySide2.QtWidgets.QGraphicsView().render(qPaintDevice,qPoint,qRegion,renderFlags) # QPaintDevice: NotImplementedError - PySide2.QtWidgets.QGridLayout().addWidget(qWidget) - PySide2.QtWidgets.QHeaderView(orientation).initStyleOption(qStyleOptionFrame) - PySide2.QtWidgets.QInputDialog().open() - PySide2.QtWidgets.QLineEdit().addAction(qAction) - PySide2.QtWidgets.QListWidget().closePersistentEditor(qModelIndex) - PySide2.QtWidgets.QListWidget().openPersistentEditor(qModelIndex) - PySide2.QtWidgets.QMessageBox().open() - PySide2.QtWidgets.QPlainTextEdit.find(quintptr) - PySide2.QtWidgets.QProgressDialog().open() - PySide2.QtWidgets.QStackedLayout().widget() - # PySide2.QtWidgets.QStylePainter().begin(qPaintDevice) # QPaintDevice: NotImplementedError - PySide2.QtWidgets.QTableWidget().closePersistentEditor(qModelIndex) - PySide2.QtWidgets.QTableWidget().openPersistentEditor(qModelIndex) - PySide2.QtWidgets.QTextEdit.find(quintptr) - PySide2.QtWidgets.QTreeWidget().closePersistentEditor(qModelIndex) - PySide2.QtWidgets.QTreeWidget().openPersistentEditor(qModelIndex) - """ -except ImportError: - warn_essential(modname) -try: - modname = "PySide2.QtPrintSupport" - exec("import " + modname) - new_functions += """ - # PySide2.QtPrintSupport.QPageSetupDialog().open() # Segmentation fault: 11 - # PySide2.QtPrintSupport.QPrintDialog().open() # opens the dialog, but works - PySide2.QtPrintSupport.QPrintDialog().printer() - PySide2.QtPrintSupport.QPrintPreviewDialog().open() # note: this prints something, but really shouldn't ;-) - """ -except ImportError: - warn_essential(modname) -try: - import PySide2.QtHelp - new_functions += """ - PySide2.QtHelp.QHelpContentModel().parent() - # PySide2.QtHelp.QHelpIndexModel().createIndex(int,int,quintptr) # returned NULL without setting an error - # PySide2.QtHelp.QHelpIndexModel().createIndex(int,int,object()) # returned NULL without setting an error - """ -except ImportError: - pass -try: - import PySide2.QtQuick - new_functions += """ - PySide2.QtQuick.QQuickPaintedItem().update() - """ -except ImportError: - pass + +new_functions += """ + PySide2.QtGui.QBitmap().transformed(qMatrix,transformationMode) + PySide2.QtGui.QStandardItemModel().insertColumn(int,qModelIndex) + PySide2.QtGui.QStandardItemModel().parent() + # PySide2.QtGui.QTextList(qTextDocument).setFormat(qTextFormat) # Segmentation fault: 11 + # PySide2.QtGui.QTextTable(qTextDocument).setFormat(qTextFormat) # Segmentation fault: 11 +""" if "PySide2.QtGui" in sys.modules else "" + +new_functions += """ + PySide2.QtWidgets.QAbstractItemView().update() + PySide2.QtWidgets.QApplication.palette() + PySide2.QtWidgets.QApplication.setFont(qFont) + PySide2.QtWidgets.QApplication.setPalette(qPalette) + PySide2.QtWidgets.QBoxLayout(direction).addWidget(qWidget) + PySide2.QtWidgets.QColorDialog().open() + PySide2.QtWidgets.QDirModel().index(int,int,qModelIndex) + PySide2.QtWidgets.QDirModel().parent() + PySide2.QtWidgets.QFileDialog().open() + PySide2.QtWidgets.QFileSystemModel().index(int,int,qModelIndex) + PySide2.QtWidgets.QFileSystemModel().parent() + PySide2.QtWidgets.QFontDialog().open() + PySide2.QtWidgets.QGestureEvent([]).accept() + PySide2.QtWidgets.QGestureEvent([]).ignore() + PySide2.QtWidgets.QGestureEvent([]).isAccepted() + PySide2.QtWidgets.QGestureEvent([]).setAccepted(bool) + # PySide2.QtWidgets.QGraphicsView().render(qPaintDevice,qPoint,qRegion,renderFlags) # QPaintDevice: NotImplementedError + PySide2.QtWidgets.QGridLayout().addWidget(qWidget) + PySide2.QtWidgets.QHeaderView(orientation).initStyleOption(qStyleOptionFrame) + PySide2.QtWidgets.QInputDialog().open() + PySide2.QtWidgets.QLineEdit().addAction(qAction) + PySide2.QtWidgets.QListWidget().closePersistentEditor(qModelIndex) + PySide2.QtWidgets.QListWidget().openPersistentEditor(qModelIndex) + PySide2.QtWidgets.QMessageBox().open() + PySide2.QtWidgets.QPlainTextEdit.find(quintptr) + PySide2.QtWidgets.QProgressDialog().open() + PySide2.QtWidgets.QStackedLayout().widget() + # PySide2.QtWidgets.QStylePainter().begin(qPaintDevice) # QPaintDevice: NotImplementedError + PySide2.QtWidgets.QTableWidget().closePersistentEditor(qModelIndex) + PySide2.QtWidgets.QTableWidget().openPersistentEditor(qModelIndex) + PySide2.QtWidgets.QTextEdit.find(quintptr) + PySide2.QtWidgets.QTreeWidget().closePersistentEditor(qModelIndex) + PySide2.QtWidgets.QTreeWidget().openPersistentEditor(qModelIndex) +""" if "PySide2.QtWidgets" in sys.modules else "" + +new_functions += """ + # PySide2.QtPrintSupport.QPageSetupDialog().open() # Segmentation fault: 11 + # PySide2.QtPrintSupport.QPrintDialog().open() # opens the dialog, but works + PySide2.QtPrintSupport.QPrintDialog().printer() + PySide2.QtPrintSupport.QPrintPreviewDialog().open() # note: this prints something, but really shouldn't ;-) +""" if "PySide2.QtPrintSupport" in sys.modules else "" + +new_functions += """ + PySide2.QtHelp.QHelpContentModel().parent() + # PySide2.QtHelp.QHelpIndexModel().createIndex(int,int,quintptr) # returned NULL without setting an error + # PySide2.QtHelp.QHelpIndexModel().createIndex(int,int,object()) # returned NULL without setting an error +""" if "PySide2.QtHelp" in sys.modules else "" + +new_functions += """ + PySide2.QtQuick.QQuickPaintedItem().update() +""" if "PySide2.QtQuick" in sys.modules else "" class MainTest(unittest.TestCase): diff --git a/sources/pyside2/tests/registry/existence_test.py b/sources/pyside2/tests/registry/existence_test.py index 6e870385d..0d8014ad8 100644 --- a/sources/pyside2/tests/registry/existence_test.py +++ b/sources/pyside2/tests/registry/existence_test.py @@ -130,7 +130,7 @@ class TestSignaturesExists(unittest.TestCase): warn(msgMultiSignatureCount(key, found_sigs[key], value)) self.assertTrue(check_warnings()) -tested_versions = (5, 6), (5, 9), (5, 11) +tested_versions = (5, 6), (5, 9), (5, 11) #, (5, 12) # activate this, soon! if not have_refmodule and is_ci and qtVersion()[:2] in tested_versions: class TestFor_CI_Init(unittest.TestCase): diff --git a/sources/pyside2/tests/registry/init_platform.py b/sources/pyside2/tests/registry/init_platform.py index 03d0ed133..ded8ba81c 100644 --- a/sources/pyside2/tests/registry/init_platform.py +++ b/sources/pyside2/tests/registry/init_platform.py @@ -55,8 +55,8 @@ from textwrap import dedent all_modules = list("PySide2." + x for x in PySide2.__all__) -from PySide2.support.signature import inspect from PySide2.QtCore import __version__ +from PySide2.support.signature.lib.enum_sig import SimplifyingEnumerator is_py3 = sys.version_info[0] == 3 is_ci = os.environ.get("QTEST_ENVIRONMENT", "") == "ci" @@ -114,7 +114,7 @@ class Formatter(object): Formatter is formatting the signature listing of an enumerator. It is written as context managers in order to avoid many callbacks. - The division in formatter and enumerator is done to keep the + The separation in formatter and enumerator is done to keep the unrelated tasks of enumeration and formatting apart. """ def __init__(self, outfile): @@ -134,7 +134,7 @@ class Formatter(object): self.print(" })") @contextmanager - def klass(self, class_name): + def klass(self, class_name, class_str): self.class_name = class_name self.print() self.print(" # class {}.{}:".format(self.mod_name, class_name)) @@ -142,7 +142,10 @@ class Formatter(object): @contextmanager def function(self, func_name, signature): - key = viskey = "{}.{}".format(self.class_name, func_name) + if self.class_name is None: + key = viskey = "{}".format(func_name) + else: + key = viskey = "{}.{}".format(self.class_name, func_name) if key.endswith("lY"): # Some classes like PySide2.QtGui.QContextMenuEvent have functions # globalX and the same with Y. The gerrit robot thinks that this @@ -152,89 +155,6 @@ class Formatter(object): yield key -class ExactEnumerator(object): - """ - ExactEnumerator enumerates all signatures in a module as they are. - - This class is used for generating complete listings of all signatures. - An appropriate formatter should be supplied, if printable output - is desired. - """ - def __init__(self, formatter, result_type=dict): - self.fmt = formatter - self.result_type = result_type - - def module(self, mod_name): - __import__(mod_name) - with self.fmt.module(mod_name): - module = sys.modules[mod_name] - members = inspect.getmembers(module, inspect.isclass) - ret = self.result_type() - for class_name, klass in members: - ret.update(self.klass(class_name, klass)) - return ret - - def klass(self, class_name, klass): - with self.fmt.klass(class_name): - ret = self.function("__init__", klass) - # class_members = inspect.getmembers(klass) - # gives us also the inherited things. - class_members = sorted(list(klass.__dict__.items())) - for func_name, func in class_members: - ret.update(self.function(func_name, func)) - return ret - - def function(self, func_name, func): - ret = self.result_type() - signature = getattr(func, '__signature__', None) - if signature is not None: - with self.fmt.function(func_name, signature) as key: - ret[key] = signature - return ret - - -def simplify(signature): - if isinstance(signature, list): - # remove duplicates which still sometimes occour: - ret = set(simplify(sig) for sig in signature) - return sorted(ret) if len(ret) > 1 else list(ret)[0] - ret = [] - for pv in signature.parameters.values(): - txt = str(pv) - if txt == "self": - continue - txt = txt[txt.index(":") + 1:] - if "=" in txt: - txt = txt[:txt.index("=")] - quote = txt[0] - if quote in ("'", '"') and txt[-1] == quote: - txt = txt[1:-1] - ret.append(txt) - return tuple(ret) - - -class SimplifyingEnumerator(ExactEnumerator): - """ - SimplifyingEnumerator enumerates all signatures in a module filtered. - - There are no default values, no variable - names and no self parameter. Only types are present after simplification. - The functions 'next' resp. '__next__' are removed - to make the output identical for Python 2 and 3. - An appropriate formatter should be supplied, if printable output - is desired. - """ - - def function(self, func_name, func): - ret = self.result_type() - signature = getattr(func, '__signature__', None) - sig = simplify(signature) if signature is not None else None - if sig is not None and func_name not in ("next", "__next__"): - with self.fmt.function(func_name, sig) as key: - ret[key] = sig - return ret - - def enum_all(): fmt = Formatter(None) enu = SimplifyingEnumerator(fmt) @@ -258,8 +178,9 @@ def generate_all(): This file contains the simplified signatures for all functions in PySide for module '{}'. There are no default values, no variable names and no self parameter. Only types are present after simplification. - The functions 'next' resp. '__next__' are removed - to make the output identical for Python 2 and 3. + The functions 'next' resp. '__next__' are removed to make the output + identical for Python 2 and 3. '__div__' is also removed, + since it exists in Python 2, only. """ '''.format(module))) fmt.print("import sys") diff --git a/sources/pyside2/tests/support/voidptr_test.py b/sources/pyside2/tests/support/voidptr_test.py index 8179407e5..330788c63 100644 --- a/sources/pyside2/tests/support/voidptr_test.py +++ b/sources/pyside2/tests/support/voidptr_test.py @@ -27,7 +27,7 @@ ############################################################################# import unittest -from PySide2 import shiboken2 +import shiboken2 as shiboken from PySide2.support import VoidPtr from PySide2.QtCore import QByteArray @@ -40,7 +40,7 @@ class PySide2Support(unittest.TestCase): # or another VoidPtr object. ba = QByteArray(b"Hello world") voidptr = VoidPtr(ba) - self.assertIsInstance(voidptr, shiboken2.VoidPtr) + self.assertIsInstance(voidptr, shiboken.VoidPtr) if __name__ == '__main__': unittest.main() |