From 7d1307d6d954380b1181309ecc73f1e3a2f8e003 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Sat, 22 Apr 2017 16:43:25 +0200 Subject: =?UTF-8?q?Support=20Gentoo=E2=80=99s=20minimalism:=20Optional=20M?= =?UTF-8?q?odules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It has been reported that Gentoo is quite minimalistic and adheres strictly to Qt5’s definition of optional modules. Because I once used the Qt5 essential modules as the minimum requirement, the Gentoo maintainers had to always patch out makefiles This patch removes this restriction. But instead simply removing, I added an option “essential” to the ‘CHECK_PACKAGE_FOUND’ macro. When an essential module is omitted, the macro generates a warning that maybe not all tests are working. This way, we don’t have to check all tests at once for missing imports. Update: application_test now correctly moved. Explicit warning for essential modules. Corrections, tested with QtCore, only. Task-number: PYSIDE-502 Change-Id: I6e63c74c80173e0f4bcb5100458b37963f71e4f9 Reviewed-by: Alexandru Croitor --- PySide2/CMakeLists.txt | 18 +-- tests/QtCore/bug_PYSIDE-42.py | 1 - tests/QtWidgets/CMakeLists.txt | 1 + tests/QtWidgets/application_test.py | 51 +++++++ tests/pysidetest/CMakeLists.txt | 3 +- tests/pysidetest/application_test.py | 51 ------- tests/pysidetest/new_inherited_functions_test.py | 173 ++++++++++++++--------- tests/pysidetest/typesystem_pysidetest.xml | 2 - 8 files changed, 169 insertions(+), 131 deletions(-) create mode 100644 tests/QtWidgets/application_test.py delete mode 100644 tests/pysidetest/application_test.py diff --git a/PySide2/CMakeLists.txt b/PySide2/CMakeLists.txt index db602c0e..8679929e 100644 --- a/PySide2/CMakeLists.txt +++ b/PySide2/CMakeLists.txt @@ -54,6 +54,9 @@ macro(CHECK_PACKAGE_FOUND name) else() if("${ARGN}" STREQUAL "opt") message(STATUS "optional module ${name} skipped") + elseif("${ARGN}" STREQUAL "essential") + message(STATUS "skipped optional module ${name} is essential!\n" + " We do not guarantee that all tests are working.") else() message(FATAL_ERROR "module ${name} MISSING") endif() @@ -116,19 +119,18 @@ macro(skip_missing_classes sources) endmacro() CHECK_PACKAGE_FOUND(Qt5Core) -CHECK_PACKAGE_FOUND(Qt5Concurrent) -CHECK_PACKAGE_FOUND(Qt5Gui) -CHECK_PACKAGE_FOUND(Qt5Widgets) -CHECK_PACKAGE_FOUND(Qt5PrintSupport) +CHECK_PACKAGE_FOUND(Qt5Concurrent essential) +CHECK_PACKAGE_FOUND(Qt5Gui essential) +CHECK_PACKAGE_FOUND(Qt5Widgets essential) +CHECK_PACKAGE_FOUND(Qt5PrintSupport essential) CHECK_PACKAGE_FOUND(Qt5Xml) CHECK_PACKAGE_FOUND(Qt5XmlPatterns opt) CHECK_PACKAGE_FOUND(Qt5Svg opt) -CHECK_PACKAGE_FOUND(Qt5PrintSupport) -CHECK_PACKAGE_FOUND(Qt5Sql) +CHECK_PACKAGE_FOUND(Qt5Sql essential) CHECK_PACKAGE_FOUND(Qt5Designer opt) CHECK_PACKAGE_FOUND(Qt5UiTools opt) -CHECK_PACKAGE_FOUND(Qt5Test) -CHECK_PACKAGE_FOUND(Qt5Network) +CHECK_PACKAGE_FOUND(Qt5Test essential) +CHECK_PACKAGE_FOUND(Qt5Network essential) CHECK_PACKAGE_FOUND(Qt5WebKit opt) CHECK_PACKAGE_FOUND(Qt5WebKitWidgets opt) CHECK_PACKAGE_FOUND(Qt5Script opt) diff --git a/tests/QtCore/bug_PYSIDE-42.py b/tests/QtCore/bug_PYSIDE-42.py index 1e3f0f1d..15b6fead 100644 --- a/tests/QtCore/bug_PYSIDE-42.py +++ b/tests/QtCore/bug_PYSIDE-42.py @@ -27,7 +27,6 @@ ############################################################################# from PySide2.QtCore import * -from PySide2.QtWidgets import * import unittest class TestBugPYSIDE42 (unittest.TestCase): diff --git a/tests/QtWidgets/CMakeLists.txt b/tests/QtWidgets/CMakeLists.txt index c70715d8..3c31b1d7 100644 --- a/tests/QtWidgets/CMakeLists.txt +++ b/tests/QtWidgets/CMakeLists.txt @@ -3,6 +3,7 @@ PYSIDE_TEST(action_clear.py) PYSIDE_TEST(add_action_test.py) PYSIDE_TEST(api2_test.py) +PYSIDE_TEST(application_test.py) PYSIDE_TEST(bug_172.py) PYSIDE_TEST(bug_243.py) PYSIDE_TEST(bug_307.py) diff --git a/tests/QtWidgets/application_test.py b/tests/QtWidgets/application_test.py new file mode 100644 index 00000000..78628a55 --- /dev/null +++ b/tests/QtWidgets/application_test.py @@ -0,0 +1,51 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $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 unittest +from testbinding import TestObject +from PySide2.QtWidgets import QApplication + +class QApplicationInstance(unittest.TestCase): + + def appDestroyed(self): + sefl.assertTrue(False) + + def testInstanceObject(self): + TestObject.createApp() + app1 = QApplication.instance() + app2 = QApplication.instance() + app1.setObjectName("MyApp") + self.assertEqual(app1, app2) + self.assertEqual(app2.objectName(), app1.objectName()) + app1.destroyed.connect(self.appDestroyed) + +if __name__ == '__main__': + unittest.main() + diff --git a/tests/pysidetest/CMakeLists.txt b/tests/pysidetest/CMakeLists.txt index 91bac030..3a5437e6 100644 --- a/tests/pysidetest/CMakeLists.txt +++ b/tests/pysidetest/CMakeLists.txt @@ -98,9 +98,8 @@ target_link_libraries(testbinding ${Qt5Widgets_LIBRARIES} ${SBK_PYTHON_LIBRARIES}) -add_dependencies(testbinding pyside2 QtCore QtGui QtWidgets libpyside pysidetest) +add_dependencies(testbinding pyside2 QtCore libpyside pysidetest) -PYSIDE_TEST(application_test.py) PYSIDE_TEST(decoratedslot_test.py) PYSIDE_TEST(delegatecreateseditor_test.py) PYSIDE_TEST(enum_test.py) diff --git a/tests/pysidetest/application_test.py b/tests/pysidetest/application_test.py deleted file mode 100644 index 78628a55..00000000 --- a/tests/pysidetest/application_test.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/python - -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of PySide2. -## -## $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 unittest -from testbinding import TestObject -from PySide2.QtWidgets import QApplication - -class QApplicationInstance(unittest.TestCase): - - def appDestroyed(self): - sefl.assertTrue(False) - - def testInstanceObject(self): - TestObject.createApp() - app1 = QApplication.instance() - app2 = QApplication.instance() - app1.setObjectName("MyApp") - self.assertEqual(app1, app2) - self.assertEqual(app2.objectName(), app1.objectName()) - app1.destroyed.connect(self.appDestroyed) - -if __name__ == '__main__': - unittest.main() - diff --git a/tests/pysidetest/new_inherited_functions_test.py b/tests/pysidetest/new_inherited_functions_test.py index 3c758202..bd5db766 100644 --- a/tests/pysidetest/new_inherited_functions_test.py +++ b/tests/pysidetest/new_inherited_functions_test.py @@ -33,13 +33,16 @@ import os import unittest import PySide2.QtCore -import PySide2.QtGui -import PySide2.QtWidgets -import PySide2.QtPrintSupport # 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() @@ -48,50 +51,70 @@ new_functions = """ m = PySide2.QtCore.QMutex(); m.tryLock(); m.unlock() # prevent a message "QMutex: destroying locked mutex" PySide2.QtCore.QSortFilterProxyModel().parent() PySide2.QtCore.QTemporaryFile(tfarg).open(openMode) - PySide2.QtGui.QBitmap().transformed(qMatrix,transformationMode) - PySide2.QtGui.QStandardItemModel().insertColumn(int,qModelIndex) - PySide2.QtGui.QStandardItemModel().insertRow(int,qModelIndex) - PySide2.QtGui.QStandardItemModel().parent() - # PySide2.QtGui.QTextList(qTextDocument).setFormat(qTextFormat) # Segmentation fault: 11 - # PySide2.QtGui.QTextTable(qTextDocument).setFormat(qTextFormat) # Segmentation fault: 11 - 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) - # 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 ;-) """ +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 += """ @@ -116,30 +139,43 @@ class MainTest(unittest.TestCase): """ Run all new method signarures """ - qApp = (PySide2.QtWidgets.QApplication.instance() or - PySide2.QtWidgets.QApplication([])) - openMode = PySide2.QtCore.QIODevice.OpenMode(PySide2.QtCore.QIODevice.ReadOnly) + for app in "QtWidgets.QApplication", "QtGui.QGuiApplication", "QtCore.QCoreApplication": + try: + exec("qApp = PySide2.{0}([]) or PySide2.{0}.instance()".format(app)) + break + except AttributeError: + continue + bool = True + int = 42 qint64 = 42 + tfarg = os.path.join(PySide2.QtCore.QDir.tempPath(), "XXXXXX.tmp") + orientation = PySide2.QtCore.Qt.Orientation() + openMode = PySide2.QtCore.QIODevice.OpenMode(PySide2.QtCore.QIODevice.ReadOnly) qModelIndex = PySide2.QtCore.QModelIndex() - qMatrix = PySide2.QtGui.QMatrix() transformationMode = PySide2.QtCore.Qt.TransformationMode() - qTextDocument = PySide2.QtGui.QTextDocument() - qTextFormat = PySide2.QtGui.QTextFormat() - int = 42 - quintptr = long(42) if sys.version_info[0] < 3 else 42 - qFont = PySide2.QtGui.QFont() - qPalette = PySide2.QtGui.QPalette() - direction = PySide2.QtWidgets.QBoxLayout.Direction() - qWidget = PySide2.QtWidgets.QWidget() - orientation = PySide2.QtCore.Qt.Orientation() - qStyleOptionFrame = PySide2.QtWidgets.QStyleOptionFrame() - bool = True qObject = PySide2.QtCore.QObject() - qAction = PySide2.QtWidgets.QAction(qObject) - #qPaintDevice = PySide2.QtGui.QPaintDevice() # NotImplementedError qPoint = PySide2.QtCore.QPoint() - renderFlags = PySide2.QtWidgets.QWidget.RenderFlags - tfarg = os.path.join(PySide2.QtCore.QDir.tempPath(), "XXXXXX.tmp") + try: + PySide2.QtGui + #qPaintDevice = PySide2.QtGui.QPaintDevice() # NotImplementedError + qMatrix = PySide2.QtGui.QMatrix() + qTextDocument = PySide2.QtGui.QTextDocument() + qTextFormat = PySide2.QtGui.QTextFormat() + quintptr = long(42) if sys.version_info[0] < 3 else 42 + qFont = PySide2.QtGui.QFont() + qPalette = PySide2.QtGui.QPalette() + except AttributeError: + pass + try: + PySide2.QtWidgets + direction = PySide2.QtWidgets.QBoxLayout.Direction() + qWidget = PySide2.QtWidgets.QWidget() + qStyleOptionFrame = PySide2.QtWidgets.QStyleOptionFrame() + qAction = PySide2.QtWidgets.QAction(qObject) + renderFlags = PySide2.QtWidgets.QWidget.RenderFlags + except AttributeError: + pass + for func in new_functions.splitlines(): func = func.strip() if func.startswith("#"): @@ -158,8 +194,11 @@ class MainTest(unittest.TestCase): Verify that qApp.palette owns three signatures, especially palette() without argument. """ - qApp = (PySide2.QtWidgets.QApplication.instance() or - PySide2.QtWidgets.QApplication([])) + try: + qApp = (PySide2.QtWidgets.QApplication.instance() or + PySide2.QtWidgets.QApplication([])) + except AttributeError: + unittest.TestCase().skipTest("this test makes only sense if QtWidgets is available.") try: PySide2.QtWidgets.QApplication.palette(42) # raises except TypeError as e: diff --git a/tests/pysidetest/typesystem_pysidetest.xml b/tests/pysidetest/typesystem_pysidetest.xml index ea3a5bd8..4053b7b7 100644 --- a/tests/pysidetest/typesystem_pysidetest.xml +++ b/tests/pysidetest/typesystem_pysidetest.xml @@ -1,8 +1,6 @@ - -