diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-11-02 16:11:52 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-11-02 16:12:04 +0000 |
commit | 25180730194bec25f915f32ab846ea583fb1493f (patch) | |
tree | 9a73e0336ecf21e085d99d6a651c5547b9eb99f8 /sources/pyside6/tests/QtWidgets | |
parent | 6e3e7b9ca0548430aaa5e2555d6e02c64625fa3f (diff) |
Rename PySide2 to PySide6
Adapt CMake files, build scripts, tests and examples.
Task-number: PYSIDE-904
Change-Id: I845f7b006e9ad274fed5444ec4c1f9dbe176ff88
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6/tests/QtWidgets')
138 files changed, 10027 insertions, 0 deletions
diff --git a/sources/pyside6/tests/QtWidgets/CMakeLists.txt b/sources/pyside6/tests/QtWidgets/CMakeLists.txt new file mode 100644 index 000000000..afa5eae0a --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/CMakeLists.txt @@ -0,0 +1,138 @@ +#Keep this in alphabetical sort + +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) +PYSIDE_TEST(bug_324.py) +PYSIDE_TEST(bug_338.py) +PYSIDE_TEST(bug_389.py) +PYSIDE_TEST(bug_400.py) +PYSIDE_TEST(bug_429.py) +PYSIDE_TEST(bug_430.py) +PYSIDE_TEST(bug_433.py) +PYSIDE_TEST(bug_467.py) +PYSIDE_TEST(bug_493.py) +PYSIDE_TEST(bug_512.py) +PYSIDE_TEST(bug_525.py) +PYSIDE_TEST(bug_546.py) +PYSIDE_TEST(bug_547.py) +PYSIDE_TEST(bug_549.py) +PYSIDE_TEST(bug_569.py) +PYSIDE_TEST(bug_575.py) +PYSIDE_TEST(bug_576.py) +PYSIDE_TEST(bug_585.py) +PYSIDE_TEST(bug_589.py) +PYSIDE_TEST(bug_635.py) +PYSIDE_TEST(bug_640.py) +PYSIDE_TEST(bug_653.py) +PYSIDE_TEST(bug_662.py) +PYSIDE_TEST(bug_667.py) +PYSIDE_TEST(bug_668.py) +PYSIDE_TEST(bug_674.py) +PYSIDE_TEST(bug_675.py) +PYSIDE_TEST(bug_688.py) +PYSIDE_TEST(bug_693.py) +PYSIDE_TEST(bug_696.py) +PYSIDE_TEST(bug_711.py) +PYSIDE_TEST(bug_722.py) +PYSIDE_TEST(bug_728.py) +PYSIDE_TEST(bug_736.py) +PYSIDE_TEST(bug_750.py) +PYSIDE_TEST(bug_778.py) +PYSIDE_TEST(bug_785.py) +PYSIDE_TEST(bug_793.py) +PYSIDE_TEST(bug_811.py) +PYSIDE_TEST(bug_834.py) +PYSIDE_TEST(bug_836.py) +PYSIDE_TEST(bug_844.py) +PYSIDE_TEST(bug_854.py) +PYSIDE_TEST(bug_860.py) +PYSIDE_TEST(bug_862.py) +PYSIDE_TEST(bug_871.py) +PYSIDE_TEST(bug_879.py) +PYSIDE_TEST(bug_919.py) +PYSIDE_TEST(bug_921.py) +PYSIDE_TEST(bug_941.py) +PYSIDE_TEST(bug_964.py) +PYSIDE_TEST(bug_967.py) +PYSIDE_TEST(bug_972.py) +PYSIDE_TEST(bug_979.py) +PYSIDE_TEST(bug_988.py) +PYSIDE_TEST(bug_998.py) +PYSIDE_TEST(bug_1002.py) +PYSIDE_TEST(bug_1006.py) +PYSIDE_TEST(bug_1048.py) +PYSIDE_TEST(bug_1077.py) +PYSIDE_TEST(customproxywidget_test.py) +PYSIDE_TEST(event_filter_test.py) +PYSIDE_TEST(grandparent_method_test.py) +PYSIDE_TEST(hashabletype_test.py) +PYSIDE_TEST(keep_reference_test.py) +PYSIDE_TEST(missing_symbols_test.py) +PYSIDE_TEST(paint_event_test.py) +PYSIDE_TEST(parent_method_test.py) +PYSIDE_TEST(private_mangle_test.py) +PYSIDE_TEST(python_properties_test.py) +PYSIDE_TEST(qabstracttextdocumentlayout_test.py) +PYSIDE_TEST(qaction_test.py) +PYSIDE_TEST(qapp_issue_585.py) +PYSIDE_TEST(qapp_test.py) +PYSIDE_TEST(qapplication_test.py) +PYSIDE_TEST(qapplication_exit_segfault_test.py) +PYSIDE_TEST(qbrush_test.py) +PYSIDE_TEST(qdynamic_signal.py) +# TODO: This passes, but requires manual button clicking (at least on mac) +#PYSIDE_TEST(qfontdialog_test.py) +PYSIDE_TEST(qformlayout_test.py) +PYSIDE_TEST(qgraphicsitem_test.py) +PYSIDE_TEST(qgraphicsitem_isblocked_test.py) +PYSIDE_TEST(qgraphicsobjectreimpl_test.py) +PYSIDE_TEST(qgraphicsproxywidget_test.py) +PYSIDE_TEST(qgraphicsscene_test.py) +PYSIDE_TEST(qimage_test.py) +PYSIDE_TEST(qinputdialog_get_test.py) +PYSIDE_TEST(qkeysequenceedit_test.py) +PYSIDE_TEST(qlabel_test.py) +PYSIDE_TEST(qlayout_ref_test.py) +PYSIDE_TEST(qlayout_test.py) +PYSIDE_TEST(qlcdnumber_test.py) +PYSIDE_TEST(qlistwidget_test.py) +PYSIDE_TEST(qlistwidgetitem_test.py) +PYSIDE_TEST(qmainwindow_test.py) +PYSIDE_TEST(qmenu_test.py) +PYSIDE_TEST(qmenuadd_test.py) +PYSIDE_TEST(qobject_mi_test.py) +PYSIDE_TEST(qpen_test.py) +PYSIDE_TEST(qpicture_test.py) +PYSIDE_TEST(qpixmap_constructor.py) +PYSIDE_TEST(qpushbutton_test.py) +PYSIDE_TEST(qshortcut_test.py) +PYSIDE_TEST(qsplitter_test.py) +PYSIDE_TEST(qstandarditemmodel_test.py) +PYSIDE_TEST(qstring_qkeysequence_test.py) +PYSIDE_TEST(qstyle_test.py) +PYSIDE_TEST(qtableview_test.py) +PYSIDE_TEST(qtabwidget_test.py) +PYSIDE_TEST(qtabwidgetclear_test.py) +PYSIDE_TEST(qtextedit_test.py) +PYSIDE_TEST(qtextedit_signal_test.py) +PYSIDE_TEST(qtreeview_test.py) +PYSIDE_TEST(qtreewidget_test.py) +PYSIDE_TEST(qtreewidgetitem_test.py) +PYSIDE_TEST(qtoolbar_test.py) +PYSIDE_TEST(qtoolbox_test.py) +PYSIDE_TEST(qvariant_test.py) +PYSIDE_TEST(qwidget_setlayout_test.py) +PYSIDE_TEST(qwidget_test.py) +PYSIDE_TEST(qcolormap_test.py) +PYSIDE_TEST(reference_count_test.py) +PYSIDE_TEST(signature_test.py) +PYSIDE_TEST(standardpixmap_test.py) +PYSIDE_TEST(test_module_template.py) +PYSIDE_TEST(virtual_protected_inheritance_test.py) +PYSIDE_TEST(virtual_pure_override_test.py) +PYSIDE_TEST(wrong_return_test.py) diff --git a/sources/pyside6/tests/QtWidgets/action_clear.py b/sources/pyside6/tests/QtWidgets/action_clear.py new file mode 100644 index 000000000..b476b068a --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/action_clear.py @@ -0,0 +1,80 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys +import unittest +import weakref + +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 PySide6.QtWidgets import QMenu, QWidget, QMenuBar, QToolBar +from helper.usesqapplication import UsesQApplication + + +class TestQActionLifeCycle(UsesQApplication): + def actionDestroyed(self, act): + self._actionDestroyed = True + + def testMenu(self): + self._actionDestroyed = False + w = QWidget() + menu = QMenu(w) + act = menu.addAction("MENU") + _ref = weakref.ref(act, self.actionDestroyed) + act = None + self.assertFalse(self._actionDestroyed) + menu.clear() + self.assertTrue(self._actionDestroyed) + + def testMenuBar(self): + self._actionDestroyed = False + w = QWidget() + menuBar = QMenuBar(w) + act = menuBar.addAction("MENU") + _ref = weakref.ref(act, self.actionDestroyed) + act = None + self.assertFalse(self._actionDestroyed) + menuBar.clear() + self.assertTrue(self._actionDestroyed) + + def testToolBar(self): + self._actionDestroyed = False + w = QWidget() + toolBar = QToolBar(w) + act = toolBar.addAction("MENU") + _ref = weakref.ref(act, self.actionDestroyed) + act = None + self.assertFalse(self._actionDestroyed) + toolBar.clear() + self.assertTrue(self._actionDestroyed) + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/add_action_test.py b/sources/pyside6/tests/QtWidgets/add_action_test.py new file mode 100644 index 000000000..a719b960a --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/add_action_test.py @@ -0,0 +1,78 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''Tests for QMenuBar.addAction(identifier, callback) calls''' + +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 PySide6.QtCore import SLOT +from PySide6.QtGui import QAction +from PySide6.QtWidgets import QMenuBar, QPushButton + +from helper.usesqapplication import UsesQApplication + + +class AddActionTest(UsesQApplication): + '''QMenuBar addAction''' + + def tearDown(self): + try: + del self.called + except AttributeError: + pass + super(AddActionTest, self).tearDown() + + def _callback(self): + self.called = True + + def testBasic(self): + '''QMenuBar.addAction(id, callback)''' + menubar = QMenuBar() + action = menubar.addAction("Accounts", self._callback) + action.activate(QAction.Trigger) + self.assertTrue(self.called) + + def testWithCppSlot(self): + '''QMenuBar.addAction(id, object, slot)''' + menubar = QMenuBar() + widget = QPushButton() + widget.setCheckable(True) + widget.setChecked(False) + action = menubar.addAction("Accounts", widget, SLOT("toggle()")) + action.activate(QAction.Trigger) + self.assertTrue(widget.isChecked()) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/api2_test.py b/sources/pyside6/tests/QtWidgets/api2_test.py new file mode 100644 index 000000000..90450dca4 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/api2_test.py @@ -0,0 +1,94 @@ +# -*- 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$ +## +############################################################################# + +'''Test cases for PySide API2 support''' + + +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 PySide6.QtGui import QIntValidator, QValidator +from PySide6.QtWidgets import QWidget, QSpinBox, QApplication + +from helper.usesqapplication import UsesQApplication + +class WidgetValidatorQInt(QWidget, QIntValidator): + def __init__(self, parent=None): + QWidget.__init__(self, parent) + QIntValidator.__init__(self, parent) + +class WidgetValidatorQSpinBox(QSpinBox): + def __init__(self, parent=None): + QSpinBox.__init__(self, parent) + + def fixup(self, text): + print("It was called!") + +class DoubleQObjectInheritanceTest(UsesQApplication): + + def testDouble(self): + '''Double inheritance from QObject classes''' + + obj = WidgetValidatorQInt() + + #QIntValidator methods + state, string, number = obj.validate('Test', 0) + self.assertEqual(state, QValidator.Invalid) + state, string, number = obj.validate('33', 0) + self.assertEqual(state, QValidator.Acceptable) + + def testQSpinBox(self): + obj = WidgetValidatorQSpinBox() + + obj.setRange(1, 10) + obj.setValue(0) + self.assertEqual(obj.value(), 1) + +class QClipboardTest(UsesQApplication): + + def testQClipboard(self): + #skip this test on MacOS because the clipboard is not available during the ssh session + #this cause problems in the buildbot + if sys.platform == 'darwin': + return + clip = QApplication.clipboard() + clip.setText("Testing this thing!") + + text, subtype = clip.text("") + self.assertEqual(subtype, "plain") + self.assertEqual(text, "Testing this thing!") + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/application_test.py b/sources/pyside6/tests/QtWidgets/application_test.py new file mode 100644 index 000000000..a76cbb9ae --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/application_test.py @@ -0,0 +1,65 @@ +#!/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 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(True) + +from testbinding import TestObject +from PySide6.QtWidgets import QApplication +from PySide6 import __all__ as all + +class QApplicationInstance(unittest.TestCase): + + def appDestroyed(self): + self.assertTrue(False) + + def testInstanceObject(self): + self.assertEqual(type(qApp), type(None)) + TestObject.createApp() + app1 = QApplication.instance() + app2 = QApplication.instance() + app1.setObjectName("MyApp") + self.assertEqual(app1, app2) + self.assertEqual(app2.objectName(), app1.objectName()) + # We no longer support qApp when embedding + # if len(all) > 3: + # # an import triggers qApp initialization + # __import__("PySide6." + all[-1]) + # self.assertEqual(app1, qApp) + app1.destroyed.connect(self.appDestroyed) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/bug_1002.py b/sources/pyside6/tests/QtWidgets/bug_1002.py new file mode 100644 index 000000000..b7549c7f7 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_1002.py @@ -0,0 +1,53 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QWidget, QPushButton + +from helper.usesqapplication import UsesQApplication + +class TestBug1002 (UsesQApplication): + def testReturnWindow(self): + widget = QWidget() + button = QPushButton(widget) + self.assertEqual(sys.getrefcount(widget), 2) + window = button.window() + self.assertEqual(sys.getrefcount(widget), 3) + self.assertEqual(sys.getrefcount(window), 3) + + del widget + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_1006.py b/sources/pyside6/tests/QtWidgets/bug_1006.py new file mode 100644 index 000000000..ac84c4a36 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_1006.py @@ -0,0 +1,116 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys +import unittest +import weakref + +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 PySide6.QtCore import Qt +from PySide6.QtWidgets import QDialog, QLabel, QGridLayout, QHBoxLayout, QWidget + +from helper.timedqapplication import TimedQApplication + +class LabelWindow(QDialog): + def __init__(self, parent): + super(LabelWindow, self).__init__(parent) + + self.test_layout = QGridLayout() + label = QLabel("Label") + self.test_layout.addWidget(label, 0, 0) + self.setLayout(self.test_layout) + self._destroyCalled = False + + + def replace(self, unit): + old_item = self.test_layout.itemAtPosition(0, 0) + old_label = old_item.widget() + ref = weakref.ref(old_item, self._destroyed) + + self.test_layout.removeWidget(old_label) + unit.assertRaises(RuntimeError, old_item.widget) + del old_item + + label = QLabel("Label New") + old_label.deleteLater() + label.setAlignment(Qt.AlignCenter) + self.test_layout.addWidget(label, 0, 0) + + def _destroyed(self, obj): + self._destroyCalled = True + +class TestBug1006 (TimedQApplication): + + def testLayoutItemLifeTime(self): + window = LabelWindow(None) + window.replace(self) + self.assertTrue(window._destroyCalled) + self.app.exec_() + + def testParentLayout(self): + def createLayout(): + label = QLabel() + layout = QHBoxLayout() + layout.addWidget(label) + + widget = QWidget() + widget.setLayout(layout) + return (layout, widget) + (layout, widget) = createLayout() + item = layout.itemAt(0) + self.assertTrue(isinstance(item.widget(), QWidget)) + + def testRemoveOrphanWidget(self): + widget = QLabel() + layout = QHBoxLayout() + layout.addWidget(widget) + self.assertEqual(sys.getrefcount(widget), 3) + + layout.removeWidget(widget) + widget.setObjectName("MyWidget") + self.assertEqual(sys.getrefcount(widget), 2) + + def testRemoveChildWidget(self): + parent = QLabel() + widget = QLabel(parent) + self.assertEqual(sys.getrefcount(widget), 3) + + layout = QHBoxLayout() + layout.addWidget(widget) + self.assertEqual(sys.getrefcount(widget), 3) + + layout.removeWidget(widget) + widget.setObjectName("MyWidget") + self.assertEqual(sys.getrefcount(widget), 3) + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_1048.py b/sources/pyside6/tests/QtWidgets/bug_1048.py new file mode 100644 index 000000000..05d956a1d --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_1048.py @@ -0,0 +1,44 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6 import QtWidgets + +a = QtWidgets.QApplication([]) + +w = QtWidgets.QWidget() +l = QtWidgets.QGridLayout(w) + +l.itemAtPosition(0, 0) diff --git a/sources/pyside6/tests/QtWidgets/bug_1077.py b/sources/pyside6/tests/QtWidgets/bug_1077.py new file mode 100644 index 000000000..4dc9628a3 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_1077.py @@ -0,0 +1,54 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +''' unit test for BUG #1077 ''' + +import os +import sys +import time + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6 import QtCore, QtGui, QtWidgets + + +class Highlighter(QtGui.QSyntaxHighlighter): + def __init__(self, parent, mode): + QtGui.QSyntaxHighlighter.__init__(self, parent) + self.tstamp = time.time() + +if __name__ == "__main__": + app = QtWidgets.QApplication([]) + python = QtWidgets.QTextEdit() + python.setWindowTitle("python") + hl = Highlighter(python.document(), "python") + python.show() + text = hl.document() diff --git a/sources/pyside6/tests/QtWidgets/bug_172.py b/sources/pyside6/tests/QtWidgets/bug_172.py new file mode 100644 index 000000000..6b943061f --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_172.py @@ -0,0 +1,49 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6.QtWidgets import * + +if __name__ == '__main__': + app = QApplication([]) + + wdg = QWidget() + + hbox = QHBoxLayout() + + vbox = QVBoxLayout() + vbox.addLayout(hbox) + + wdg.setLayout(vbox) diff --git a/sources/pyside6/tests/QtWidgets/bug_243.py b/sources/pyside6/tests/QtWidgets/bug_243.py new file mode 100644 index 000000000..4f4526691 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_243.py @@ -0,0 +1,50 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +''' Test bug 243: http://bugs.openbossa.org/show_bug.cgi?id=243''' + +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 PySide6.QtWidgets import QApplication, QMainWindow, QLayout + +class QAppPresence(unittest.TestCase): + + def testBug(self): + app = QApplication(sys.argv) + window = QMainWindow() + l = window.layout() + self.assertTrue(isinstance(l, QLayout)) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_307.py b/sources/pyside6/tests/QtWidgets/bug_307.py new file mode 100644 index 000000000..914227de5 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_307.py @@ -0,0 +1,60 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import colorsys +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 PySide6.QtCore import SIGNAL +from PySide6.QtWidgets import QPushButton, QApplication + + +class Test (QApplication) : + def __init__(self, argv) : + super(Test, self).__init__(argv) + self._called = False + + def called(self): + self._called = True + + +class QApplicationSignalsTest(unittest.TestCase): + def testQuit(self): + app = Test([]) + button = QPushButton("BUTTON") + app.connect(button, SIGNAL("clicked()"), app.called) + button.click() + self.assertTrue(app._called) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_324.py b/sources/pyside6/tests/QtWidgets/bug_324.py new file mode 100644 index 000000000..16130f895 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_324.py @@ -0,0 +1,65 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +''' Test bug 324: http://bugs.openbossa.org/show_bug.cgi?id=324''' + +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 PySide6.QtCore import * +from PySide6.QtWidgets import * + +class QBug( QObject ): + def __init__(self, parent = None): + QObject.__init__(self, parent) + + def check(self): + self.done.emit("abc") + + done = Signal(str) + +class Bug324(unittest.TestCase): + + def on_done(self, val): + self.value = val + + def testBug(self): + app = QApplication([]) + bug = QBug() + self.value = '' + bug.done.connect(self.on_done) + bug.check() + self.assertEqual(self.value, 'abc') + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_338.py b/sources/pyside6/tests/QtWidgets/bug_338.py new file mode 100644 index 000000000..f46508cbe --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_338.py @@ -0,0 +1,60 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +''' Test bug 338: http://bugs.openbossa.org/show_bug.cgi?id=338''' + +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 PySide6 import QtCore, QtWidgets + +class DiagramItem(QtWidgets.QGraphicsPolygonItem): + def __init__(self, parent=None, scene=None): + super(DiagramItem, self).__init__(parent, scene) + + def itemChange(self, change, value): + return value + + +class BugTest(unittest.TestCase): + def test(self): + app = QtWidgets.QApplication(sys.argv) + scene = QtWidgets.QGraphicsScene() + item = DiagramItem() + item2 = DiagramItem() + #this cause segfault + scene.addItem(item) + scene.addItem(item2) + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_389.py b/sources/pyside6/tests/QtWidgets/bug_389.py new file mode 100644 index 000000000..87758ee4e --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_389.py @@ -0,0 +1,49 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +''' Test bug 389: http://bugs.openbossa.org/show_bug.cgi?id=389''' + +import sys +import os +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 PySide6 import QtCore, QtGui, QtWidgets + +class BugTest(UsesQApplication): + def testCase(self): + s = QtWidgets.QWidget().style() + i = s.standardIcon(QtWidgets.QStyle.SP_TitleBarMinButton) + self.assertEqual(type(i), QtGui.QIcon) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_400.py b/sources/pyside6/tests/QtWidgets/bug_400.py new file mode 100644 index 000000000..96beaec5b --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_400.py @@ -0,0 +1,61 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +''' Test bug 400: http://bugs.openbossa.org/show_bug.cgi?id=400''' + +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 PySide6.QtWidgets import QTreeWidgetItemIterator, QTreeWidgetItem, QTreeWidget + +class BugTest(UsesQApplication): + def testCase(self): + treeWidget = QTreeWidget() + treeWidget.setColumnCount(1) + items = [] + for i in range(10): + items.append(QTreeWidgetItem(None, ["item: %i" % i])) + + treeWidget.insertTopLevelItems(0, items); + _iter = QTreeWidgetItemIterator(treeWidget) + index = 0 + while(_iter.value()): + item = _iter.value() + self.assertTrue(item is items[index]) + index += 1 + _iter += 1 + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_429.py b/sources/pyside6/tests/QtWidgets/bug_429.py new file mode 100644 index 000000000..fe81266a1 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_429.py @@ -0,0 +1,46 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6.QtCore import * +from PySide6.QtWidgets import * + + +app = QApplication(sys.argv) +scene = QGraphicsScene() +label = QLabel("hello world") +label.show() +QTimer.singleShot(0, label.close) +exit(app.exec_()) diff --git a/sources/pyside6/tests/QtWidgets/bug_430.py b/sources/pyside6/tests/QtWidgets/bug_430.py new file mode 100644 index 000000000..fc96d6ab3 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_430.py @@ -0,0 +1,49 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6.QtCore import * +from PySide6.QtWidgets import * + +class ListModel(QAbstractListModel): + def rowCount(self, parent = QModelIndex()): + return 0 + +app = QApplication([]) +model = ListModel() +v = QListView() +v.setModel(model) +QTimer.singleShot(0, v.close) +app.exec_() diff --git a/sources/pyside6/tests/QtWidgets/bug_433.py b/sources/pyside6/tests/QtWidgets/bug_433.py new file mode 100644 index 000000000..53ec18582 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_433.py @@ -0,0 +1,49 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6 import QtCore, QtWidgets + +class Test(QtWidgets.QGraphicsView): + def __init__(self, parent=None): + super(Test, self).__init__(parent) + self.s = QtWidgets.QGraphicsScene() + self.setScene(self.s) + +a = QtWidgets.QApplication(sys.argv) +t = Test() +t.show() +QtCore.QTimer.singleShot(0, t.close) +sys.exit(a.exec_()) diff --git a/sources/pyside6/tests/QtWidgets/bug_467.py b/sources/pyside6/tests/QtWidgets/bug_467.py new file mode 100644 index 000000000..ce178bfef --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_467.py @@ -0,0 +1,54 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +''' Test bug 367: http://bugs.openbossa.org/show_bug.cgi?id=467''' + +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 PySide6.QtWidgets import QMainWindow, QApplication + +class MyWidget(QMainWindow): + def __init__(self, parent = None): + QMainWindow.__init__(self, parent) + + +class BugTest(UsesQApplication): + def testCase(self): + w = MyWidget() + widgets = QApplication.allWidgets() + self.assertTrue(w in widgets) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_493.py b/sources/pyside6/tests/QtWidgets/bug_493.py new file mode 100644 index 000000000..559d71f60 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_493.py @@ -0,0 +1,56 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import Qt, QEvent +from PySide6.QtGui import QKeyEvent, QKeySequence +from PySide6.QtWidgets import QApplication + + +class TestBug493(unittest.TestCase): + + def testIt(self): + # We need a qapp otherwise Qt will crash when trying to detect the + # current platform + app = QApplication([]) + ev1 = QKeyEvent(QEvent.KeyRelease, Qt.Key_Delete, Qt.NoModifier) + ev2 = QKeyEvent(QEvent.KeyRelease, Qt.Key_Copy, Qt.NoModifier) + ks = QKeySequence.Delete + + self.assertTrue(ev1.matches(ks)) + self.assertFalse(ev2.matches(ks)) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_512.py b/sources/pyside6/tests/QtWidgets/bug_512.py new file mode 100644 index 000000000..3474aa32b --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_512.py @@ -0,0 +1,57 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +''' Test bug 512: http://bugs.openbossa.org/show_bug.cgi?id=512''' + +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 PySide6.QtCore import * +from PySide6.QtWidgets import * + +class BugTest(UsesQApplication): + def testCase(self): + w = QWidget(None) + lbl = QLabel("Hello", w); + g = QGridLayout() + g.addWidget(lbl, 0, 0) + w.setLayout(g) + w.show() + + t = g.getItemPosition(0) + self.assertEqual(type(t), tuple) + self.assertEqual(t, (0,0,1,1)) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_525.py b/sources/pyside6/tests/QtWidgets/bug_525.py new file mode 100644 index 000000000..c3863207c --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_525.py @@ -0,0 +1,56 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QApplication +from PySide6.QtWidgets import QMenu + +class M2(QMenu): + def __init__(self,parent=None): + super(M2,self).__init__(parent) + self.setTitle(self.tr("M2")) + +class TestMenuDerivedClass(unittest.TestCase): + def aboutToShowHandler(self): + pass + + def testConnectSignal(self): + app = QApplication([]) + m2 = M2() + # Test if the aboutToShow signal was translated to correct type + m2.aboutToShow.connect(self.aboutToShowHandler) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_546.py b/sources/pyside6/tests/QtWidgets/bug_546.py new file mode 100644 index 000000000..91c8d4637 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_546.py @@ -0,0 +1,49 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import * + +class TestBug546(unittest.TestCase): + + """Test to check a crash at exit""" + def testIt(self): + app = QApplication([]) + textEdit = QPlainTextEdit() + completer = QCompleter(("foo", "bar"), textEdit) + completer.setWidget(textEdit) + +if __name__=='__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_547.py b/sources/pyside6/tests/QtWidgets/bug_547.py new file mode 100644 index 000000000..d232aba8e --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_547.py @@ -0,0 +1,91 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +""" Unittest for bug #547 """ +""" http://bugs.openbossa.org/show_bug.cgi?id=547 """ + +import sys +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 PySide6 import QtWidgets + +class MyMainWindow(unittest.TestCase): + app = QtWidgets.QApplication(sys.argv) + def testCase1(self): + self._tree = QtWidgets.QTreeWidget() + self._tree.setColumnCount(2) + self._i1 = None + self._i11 = None + + self._updateTree() + self.assertEqual(sys.getrefcount(self._i1), 3) + self.assertEqual(sys.getrefcount(self._i11), 3) + + self._i11.parent().setExpanded(True) + self._i11.setExpanded(True) + + self._updateTree() + self.assertEqual(sys.getrefcount(self._i1), 3) + self.assertEqual(sys.getrefcount(self._i11), 3) + + def testCase2(self): + self._tree = QtWidgets.QTreeWidget() + self._tree.setColumnCount(2) + self._i1 = None + self._i11 = None + + self._updateTree() + self.assertEqual(sys.getrefcount(self._i1), 3) + self.assertEqual(sys.getrefcount(self._i11), 3) + + self._i11.parent().setExpanded(True) + self._i11.setExpanded(True) + + self.assertEqual(sys.getrefcount(self._i1), 3) + self.assertEqual(sys.getrefcount(self._i11), 3) + + def _updateTree(self): + self._tree.clear() + if self._i1 and self._i11: + self.assertEqual(sys.getrefcount(self._i1), 2) + self.assertEqual(sys.getrefcount(self._i11), 2) + + self._i1 = QtWidgets.QTreeWidgetItem(self._tree, ['1', ]) + self.assertEqual(sys.getrefcount(self._i1), 3) + self._i11 = QtWidgets.QTreeWidgetItem(self._i1, ['11', ]) + self.assertEqual(sys.getrefcount(self._i11), 3) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/bug_549.py b/sources/pyside6/tests/QtWidgets/bug_549.py new file mode 100644 index 000000000..a000c8df4 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_549.py @@ -0,0 +1,50 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import * + +class TestBug549(unittest.TestCase): + def testBug(self): + app = QApplication([]) + w = QGraphicsWidget() + w.setContentsMargins(1, 2, 3, 4) + self.assertEqual(w.getContentsMargins(), (1, 2, 3, 4)) + w.setWindowFrameMargins(5, 6, 7, 8) + self.assertEqual(w.getWindowFrameMargins(), (5, 6, 7, 8)) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/bug_569.py b/sources/pyside6/tests/QtWidgets/bug_569.py new file mode 100644 index 000000000..3e53ccca3 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_569.py @@ -0,0 +1,54 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import * +from PySide6.QtWidgets import * + + +class TestBug569(unittest.TestCase): + + def testIt(self): + types = (QTableWidgetItem, QListWidgetItem, QTreeWidgetItem) + for t in types: + a = t() + a.__lt__ = lambda other : True + b = t() + b.__lt__ = lambda other : False + self.assertTrue(a < b) + self.assertFalse(b < a) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_575.py b/sources/pyside6/tests/QtWidgets/bug_575.py new file mode 100644 index 000000000..a6f0c006a --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_575.py @@ -0,0 +1,56 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +""" Unittest for bug #575 """ +""" http://bugs.openbossa.org/show_bug.cgi?id=575 """ + +import sys +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 PySide6.QtWidgets import QApplication, QPlainTextEdit, QTextEdit + + +class Bug575(unittest.TestCase): + def testPropertyValues(self): + app = QApplication(sys.argv) + textEdit = QPlainTextEdit() + textEdit.insertPlainText("PySide INdT") + selection = QTextEdit.ExtraSelection() + selection.cursor = textEdit.textCursor() + selection.cursor.setPosition(2) + self.assertEqual(selection.cursor.position(), 2) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/bug_576.py b/sources/pyside6/tests/QtWidgets/bug_576.py new file mode 100644 index 000000000..9bd36e5f8 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_576.py @@ -0,0 +1,68 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +""" Unittest for bug #576 """ +""" http://bugs.openbossa.org/show_bug.cgi?id=576 """ + +import sys +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 PySide6 import QtCore, QtWidgets + +class Bug576(unittest.TestCase): + def onButtonDestroyed(self, button): + self._destroyed = True + self.assertTrue(isinstance(button, QtWidgets.QPushButton)) + + def testWidgetParent(self): + self._destroyed = False + app = QtWidgets.QApplication(sys.argv) + w = QtWidgets.QWidget() + + b = QtWidgets.QPushButton("test") + b.destroyed[QtCore.QObject].connect(self.onButtonDestroyed) + self.assertEqual(sys.getrefcount(b), 2) + b.setParent(w) + self.assertEqual(sys.getrefcount(b), 3) + b.parent() + self.assertEqual(sys.getrefcount(b), 3) + b.setParent(None) + self.assertEqual(sys.getrefcount(b), 2) + del b + self.assertTrue(self._destroyed) + + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/bug_585.py b/sources/pyside6/tests/QtWidgets/bug_585.py new file mode 100644 index 000000000..9b489fd29 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_585.py @@ -0,0 +1,59 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''Test bug 585: http://bugs.openbossa.org/show_bug.cgi?id=585''' + +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 PySide6 import QtCore, QtWidgets + +class Bug585(unittest.TestCase): + def testCase(self): + app = QtWidgets.QApplication([]) + self._tree = QtWidgets.QTreeWidget() + self._tree.setColumnCount(2) + i1 = QtWidgets.QTreeWidgetItem(self._tree, ['1', ]) + i2 = QtWidgets.QTreeWidgetItem(self._tree, ['2', ]) + refCount = sys.getrefcount(i1) + + # this function return None + # because the topLevelItem does not has a parent item + # but still have a TreeWidget as a parent + self._tree.topLevelItem(0).parent() + + self.assertEqual(refCount, sys.getrefcount(i1)) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/bug_589.py b/sources/pyside6/tests/QtWidgets/bug_589.py new file mode 100644 index 000000000..4a535d388 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_589.py @@ -0,0 +1,54 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +# trimmed down diagramscene.py to demonstrate crash in sizeHint() + +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 PySide6 import QtCore, QtWidgets + + +class CustomWidget(QtWidgets.QGraphicsProxyWidget): + def itemChange(self, eventType, value): + QtWidgets.QGraphicsProxyWidget.itemChange(self, eventType, value) + +class Bug589(unittest.TestCase): + def testCase(self): + widget = QtWidgets.QGraphicsProxyWidget() + custom = CustomWidget() + custom.setParentItem(widget) + +if __name__ == "__main__": + app = QtWidgets.QApplication(sys.argv) + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_635.py b/sources/pyside6/tests/QtWidgets/bug_635.py new file mode 100644 index 000000000..d410d4e28 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_635.py @@ -0,0 +1,64 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +''' Test bug 635: http://bugs.openbossa.org/show_bug.cgi?id=635''' + +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 PySide6.QtGui import QIcon +from PySide6.QtWidgets import QApplication, QToolBar + + +class testQToolBar(unittest.TestCase): + def callback(self): + self._called = True + + def testAddAction(self): + bar = QToolBar() + self._called = False + a = bar.addAction("act1", self.callback) + a.trigger() + self.assertTrue(self._called) + + def testAddActionWithIcon(self): + bar = QToolBar() + self._called = False + icon = QIcon() + a = bar.addAction(icon, "act1", self.callback) + a.trigger() + self.assertTrue(self._called) + +if __name__ == '__main__': + app = QApplication(sys.argv) + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_640.py b/sources/pyside6/tests/QtWidgets/bug_640.py new file mode 100644 index 000000000..00ba7fc69 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_640.py @@ -0,0 +1,46 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import * + + +class Bug640(unittest.TestCase): + def testIt(self): + option = QStyleOptionGraphicsItem() + a = option.state # crash!? + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_653.py b/sources/pyside6/tests/QtWidgets/bug_653.py new file mode 100644 index 000000000..4f7dcf85c --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_653.py @@ -0,0 +1,52 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import * +from PySide6.QtWidgets import * + +class TestBug653(unittest.TestCase): + """Crash after calling QWizardPage.wizard()""" + def testIt(self): + app = QApplication([]) + + wizard = QWizard() + page = QWizardPage() + wizard.addPage(page) + page.wizard() # crash here if the bug still exists due to a circular dependency + wizard.show() + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_662.py b/sources/pyside6/tests/QtWidgets/bug_662.py new file mode 100644 index 000000000..19070f584 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_662.py @@ -0,0 +1,63 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +''' Test bug 662: http://bugs.openbossa.org/show_bug.cgi?id=662''' + +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 PySide6.QtGui import QTextCharFormat +from PySide6.QtWidgets import QTextEdit, QApplication +import sys + +class testQTextBlock(unittest.TestCase): + def tesIterator(self): + edit = QTextEdit() + cursor = edit.textCursor() + fmt = QTextCharFormat() + frags = [] + for i in range(10): + fmt.setFontPointSize(i+10) + frags.append("block%d"%i) + cursor.insertText(frags[i], fmt) + + doc = edit.document() + block = doc.begin() + + index = 0 + for i in block: + self.assertEqual(i.fragment().text(), frags[index]) + index += 1 + +if __name__ == '__main__': + app = QApplication(sys.argv) + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_667.py b/sources/pyside6/tests/QtWidgets/bug_667.py new file mode 100644 index 000000000..8a94fd173 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_667.py @@ -0,0 +1,59 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6.QtCore import QTimer, QPointF +from PySide6.QtWidgets import QApplication, QGraphicsView, QGraphicsScene, QGraphicsEllipseItem + +class Ball(QGraphicsEllipseItem): + def __init__(self, d, parent=None): + super(Ball, self).__init__(0, 0, d, d, parent) + self.vel = QPointF(0,0) #commenting this out prevents the crash + +class Foo(QGraphicsView): + def __init__(self): + super(Foo, self).__init__(None) + self.scene = QGraphicsScene(self.rect()) + self.setScene(self.scene) + self.scene.addItem(Ball(10)) + + +if __name__ == "__main__": + app = QApplication(sys.argv) + w = Foo() + w.show() + w.raise_() + QTimer.singleShot(0, w.close) + sys.exit(app.exec_()) diff --git a/sources/pyside6/tests/QtWidgets/bug_668.py b/sources/pyside6/tests/QtWidgets/bug_668.py new file mode 100644 index 000000000..cd5b95e0a --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_668.py @@ -0,0 +1,59 @@ +# 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$ +## +############################################################################# + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6.QtCore import * +from PySide6.QtWidgets import * + + +class A(QMainWindow): + def __init__(self, parent=None): + super(A, self).__init__(parent) + a = QFileSystemModel(self) + a.setRootPath(QDir.homePath()) + + v = QTreeView(self) + v.setModel(a) + self.setCentralWidget(v) + # Test index() method (see PYSIDE-570, PYSIDE-331) + index = a.index(0, 0, QModelIndex()) + +app = QApplication([]) +m = A() +m.show() +QTimer.singleShot(0, m.close) +app.exec_() diff --git a/sources/pyside6/tests/QtWidgets/bug_674.py b/sources/pyside6/tests/QtWidgets/bug_674.py new file mode 100644 index 000000000..d9aed3b6c --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_674.py @@ -0,0 +1,58 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import * +from PySide6.QtWidgets import * + + +class TestBug679(unittest.TestCase): + '''QGraphicsScene::clear() is missing''' + def testIt(self): + app = QApplication([]) + + scene = QGraphicsScene() + hello = scene.addText("Hello") + scene.addText("World") + + self.assertEqual(sys.getrefcount(hello), 3) + scene.clear() + self.assertEqual(sys.getrefcount(hello), 2) + self.assertEqual(len(scene.items()), 0) + self.assertRaises(RuntimeError, hello.isVisible) # the C++ object was deleted + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/bug_675.py b/sources/pyside6/tests/QtWidgets/bug_675.py new file mode 100644 index 000000000..b5b3af617 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_675.py @@ -0,0 +1,51 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6.QtCore import * +from PySide6.QtWidgets import * + +app = QApplication([]) + +scene = QGraphicsScene() + +# don't segfault due to lack of keepReferenceCall +textEdit = scene.addWidget(QTextEdit()) + +layout = QGraphicsLinearLayout() +layout.addItem(textEdit) + +view = QGraphicsView(scene) +view.show() diff --git a/sources/pyside6/tests/QtWidgets/bug_688.py b/sources/pyside6/tests/QtWidgets/bug_688.py new file mode 100644 index 000000000..21dbcabb2 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_688.py @@ -0,0 +1,123 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +''' Test bug 688: http://bugs.openbossa.org/show_bug.cgi?id=688''' + +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 PySide6.QtGui import QTextFrame, QTextCursor, QTextCharFormat, QFont, QTextFrameFormat +from PySide6.QtWidgets import QTextEdit + +class BugTest(UsesQApplication): + def testCase(self): + editor = QTextEdit() + cursor = QTextCursor(editor.textCursor()) + cursor.movePosition(QTextCursor.Start) + + mainFrame = cursor.currentFrame() + + plainCharFormat = QTextCharFormat() + boldCharFormat = QTextCharFormat() + boldCharFormat.setFontWeight(QFont.Bold); + cursor.insertText(""" + Text documents are represented by the + QTextDocument class, rather than by QString objects. + Each QTextDocument object contains information about + the document's internal representation, its structure, + and keeps track of modifications to provide undo/redo + facilities. This approach allows features such as the + layout management to be delegated to specialized + classes, but also provides a focus for the framework.""", + plainCharFormat) + + frameFormat = QTextFrameFormat() + frameFormat.setMargin(32) + frameFormat.setPadding(8) + frameFormat.setBorder(4) + cursor.insertFrame(frameFormat) + + cursor.insertText(""" + Documents are either converted from external sources + or created from scratch using Qt. The creation process + can done by an editor widget, such as QTextEdit, or by + explicit calls to the Scribe API.""", + boldCharFormat) + + cursor = mainFrame.lastCursorPosition() + cursor.insertText(""" + There are two complementary ways to visualize the + contents of a document: as a linear buffer that is + used by editors to modify the contents, and as an + object hierarchy containing structural information + that is useful to layout engines. In the hierarchical + model, the objects generally correspond to visual + elements such as frames, tables, and lists. At a lower + level, these elements describe properties such as the + style of text used and its alignment. The linear + representation of the document is used for editing and + manipulation of the document's contents.""", + plainCharFormat) + + + frame = cursor.currentFrame() + + items = [] + + #test iterator + for i in frame: + items.append(i) + + #test __iadd__ + b = frame.begin() + i = 0 + while not b.atEnd(): + self.assertEqual(b, items[i]) + self.assertTrue(b.parentFrame(), items[i].parentFrame()) + b.__iadd__(1) + i += 1 + + #test __isub__ + b = frame.end() + i = 0 + while i > 0: + self.assertEqual(b, items[i]) + self.assertTrue(b.parentFrame(), items[i].parentFrame()) + b.__isub__(1) + i -= 1 + + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_693.py b/sources/pyside6/tests/QtWidgets/bug_693.py new file mode 100644 index 000000000..6d2b89be3 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_693.py @@ -0,0 +1,66 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import * +from PySide6.QtWidgets import * + + +class MyModel (QAbstractListModel): + + stupidLine = QLine(0, 0, 10, 10) + + def rowCount(self, parent): + return 1 + + def data(self, index, role): + return self.stupidLine + +class TestBug693(unittest.TestCase): + def testIt(self): + app = QApplication([]) + model = MyModel() + view = QListView() + view.setModel(model) + view.show() + + # This must NOT throw the exception: + # RuntimeError: Internal C++ object (PySide6.QtCore.QLine) already deleted. + MyModel.stupidLine.isNull() + + + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_696.py b/sources/pyside6/tests/QtWidgets/bug_696.py new file mode 100644 index 000000000..11bab1e3c --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_696.py @@ -0,0 +1,60 @@ +#!/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$ +## +############################################################################# + +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 PySide6.QtWidgets import QMainWindow, QMenu, QApplication + +class MainWindow(QMainWindow): + def __init__(self, *args): + self._menu = QMenu(self.dontexist) # attribute called with invalid C++ object + +class MainWindow2(QMainWindow): + def __init__(self): + self.show() + +class Bug696(UsesQApplication): + def testContructorInitialization(self): + self.assertRaises(AttributeError, MainWindow) + + def testContructorInitializationAndCPPFunction(self): + self.assertRaises(RuntimeError, MainWindow2) + + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/bug_711.py b/sources/pyside6/tests/QtWidgets/bug_711.py new file mode 100644 index 000000000..bf6516a0a --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_711.py @@ -0,0 +1,61 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtGui import QAction +from PySide6.QtWidgets import QToolBar, QApplication, QToolButton + +try: + xrange +except NameError: + xrange = range # py3k + +class TestLabelPixmap(unittest.TestCase): + def testReference(self): + toolbar = QToolBar() + + for i in xrange(20): + toolbar.addAction(QAction("Action %d" % i, None)) + + buttons = toolbar.findChildren(QToolButton, "") + toolbar.clear() + + for b in buttons: + self.assertRaises(RuntimeError, b.objectName) + +if __name__ == '__main__': + app = QApplication([]) + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/bug_722.py b/sources/pyside6/tests/QtWidgets/bug_722.py new file mode 100644 index 000000000..c833533ff --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_722.py @@ -0,0 +1,58 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QDoubleSpinBox, QGraphicsBlurEffect + +class TestSignalConnection(UsesQApplication): + def testFloatSignal(self): + foo1 = QDoubleSpinBox() + foo2 = QDoubleSpinBox() + foo1.valueChanged[float].connect(foo2.setValue) + foo2.valueChanged[float].connect(foo1.setValue) + foo1.setValue(0.42) + self.assertEqual(foo1.value(), foo2.value()) + + def testQRealSignal(self): + foo1 = QDoubleSpinBox() + effect = QGraphicsBlurEffect() + effect.blurRadiusChanged['qreal'].connect(foo1.setValue) # check if qreal is a valid type + effect.setBlurRadius(0.42) + self.assertAlmostEqual(foo1.value(), effect.blurRadius()) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_728.py b/sources/pyside6/tests/QtWidgets/bug_728.py new file mode 100644 index 000000000..694e21ded --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_728.py @@ -0,0 +1,59 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6.QtWidgets import * +from PySide6.QtCore import * + +# Periodically check for the file dialog to appear and close it +dialog = None +def timerHandler(): + global dialog + if dialog is not None: + dialog.reject() + else: + for widget in QApplication.topLevelWidgets(): + if isinstance(widget, QDialog) and widget.isVisible(): + dialog = widget + +app = QApplication([]) +QTimer.singleShot(30000, app.quit) # emergency +timer = QTimer() +timer.setInterval(50) +timer.timeout.connect(timerHandler) +timer.start() + +# This test for a dead lock in QFileDialog.getOpenFileNames, the test fail with a timeout if the dead lock exists. +QFileDialog.getOpenFileNames(None, "caption", QDir.homePath(), None, "", QFileDialog.DontUseNativeDialog) diff --git a/sources/pyside6/tests/QtWidgets/bug_736.py b/sources/pyside6/tests/QtWidgets/bug_736.py new file mode 100644 index 000000000..439dd69f4 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_736.py @@ -0,0 +1,53 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import * +from PySide6.QtWidgets import * + +class TestBug736 (unittest.TestCase): + + def testIt(self): + app = QApplication([]) + slider = QSlider(Qt.Horizontal) + slider2 = QSlider(Qt.Horizontal) + + slider2.setMaximum(10) + slider.valueChanged[int].connect(slider2.setMaximum) + slider.valueChanged[int].emit(100) + self.assertEqual(slider2.maximum(), 100) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_750.py b/sources/pyside6/tests/QtWidgets/bug_750.py new file mode 100644 index 000000000..4c63d77f1 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_750.py @@ -0,0 +1,60 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import QTimer +from PySide6.QtGui import QPainter, QFont, QFontInfo +from PySide6.QtWidgets import QWidget + +class MyWidget(QWidget): + def paintEvent(self, e): + p = QPainter(self) + self._info = p.fontInfo() + self._app.quit() + + +class TestQPainter(UsesQApplication): + def testFontInfo(self): + w = MyWidget() + w._app = self.app + w._info = None + QTimer.singleShot(300, w.show) + self.app.exec_() + self.assertTrue(w._info) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_778.py b/sources/pyside6/tests/QtWidgets/bug_778.py new file mode 100644 index 000000000..9816c4c35 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_778.py @@ -0,0 +1,56 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QTreeWidget, QTreeWidgetItem, QTreeWidgetItemIterator + +class QTreeWidgetItemIteratorTest(UsesQApplication): + def testWidgetIterator(self): + treeWidget = QTreeWidget() + treeWidget.setColumnCount(1) + items = [] + for i in range(10): + items.append(QTreeWidgetItem(None, ['item: %d' % i])) + treeWidget.insertTopLevelItems(0, items) + + index = 0 + for it in QTreeWidgetItemIterator(treeWidget): + self.assertEqual(it.value().text(0), 'item: %d' % index) + index += 1 + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_785.py b/sources/pyside6/tests/QtWidgets/bug_785.py new file mode 100644 index 000000000..36cac24cd --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_785.py @@ -0,0 +1,63 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import QItemSelection +from PySide6.QtGui import QStandardItemModel, QStandardItem +from PySide6.QtWidgets import QApplication +class Bug324(unittest.TestCase): + def testOperators(self): + model = QStandardItemModel() + for i in range(100): + model.appendRow(QStandardItem("Item: %d"%i)) + + first = model.index(0, 0) + second = model.index(10, 0) + third = model.index(20, 0) + fourth = model.index(30, 0) + + sel = QItemSelection(first, second) + sel2 = QItemSelection() + sel2.select(third, fourth) + + sel3 = sel + sel2 #check operator + + self.assertEqual(len(sel3), 2) + sel4 = sel + sel4 += sel2 #check operator += + self.assertEqual(len(sel4), 2) + self.assertEqual(sel4, sel3) + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_793.py b/sources/pyside6/tests/QtWidgets/bug_793.py new file mode 100644 index 000000000..d1080d93f --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_793.py @@ -0,0 +1,64 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import QTimer +from PySide6.QtWidgets import QWidget, QApplication + +class TestW1(QWidget): + def __init__(self, parent = None): + super(TestW1, self).__init__(parent) + TestW2(parent, self) + +class TestW2(QWidget): + def __init__(self, ancestor, parent = None): + super(TestW2, self).__init__(parent) + self.ancestor_ref = ancestor + +class Test(QWidget): + def __init__(self): + super(Test, self).__init__() + TestW1(self) + +class TestQApplicationDestrcutor(unittest.TestCase): + def testDestructor(self): + w = Test() + w.show() + QTimer.singleShot(0, w.close) + +if __name__ == '__main__': + app = QApplication(sys.argv) + unittest.main() + sys.exit(app.exec_()) diff --git a/sources/pyside6/tests/QtWidgets/bug_811.py b/sources/pyside6/tests/QtWidgets/bug_811.py new file mode 100644 index 000000000..671c3bcbb --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_811.py @@ -0,0 +1,66 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys +import unittest +import weakref + +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 PySide6.QtGui import QTextBlockUserData, QTextCursor +from PySide6.QtWidgets import QTextEdit + +class TestUserData(QTextBlockUserData): + def __init__(self, data): + super(TestUserData, self).__init__() + self.data = data + +class TestUserDataRefCount(UsesQApplication): + def testRefcount(self): + textedit = QTextEdit() + textedit.setReadOnly(True) + doc = textedit.document() + cursor = QTextCursor(doc) + cursor.insertText("PySide Rocks") + ud = TestUserData({"Life": 42}) + self.assertEqual(sys.getrefcount(ud), 2) + cursor.block().setUserData(ud) + self.assertEqual(sys.getrefcount(ud), 3) + ud2 = cursor.block().userData() + self.assertEqual(sys.getrefcount(ud), 4) + self.udata = weakref.ref(ud, None) + del ud, ud2 + self.assertEqual(sys.getrefcount(self.udata()), 2) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_834.py b/sources/pyside6/tests/QtWidgets/bug_834.py new file mode 100644 index 000000000..2cac4b496 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_834.py @@ -0,0 +1,54 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6 import QtCore, QtWidgets + +class Window(QtWidgets.QMainWindow): + def childEvent(self, event): + super(Window, self).childEvent(event) + +app = QtWidgets.QApplication([]) +window = Window() + +dock1 = QtWidgets.QDockWidget() +dock2 = QtWidgets.QDockWidget() +window.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dock1) +window.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dock2) +window.tabifyDockWidget(dock1, dock2) + +window.show() +QtCore.QTimer.singleShot(0, window.close) +app.exec_() diff --git a/sources/pyside6/tests/QtWidgets/bug_836.py b/sources/pyside6/tests/QtWidgets/bug_836.py new file mode 100644 index 000000000..6106cd838 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_836.py @@ -0,0 +1,64 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6.QtCore import * +from PySide6.QtWidgets import * + +class Mixin1(object): + pass + +class Mixin2(object): + pass + +class Mixin3(object): + pass + +class MainWindow(Mixin1, Mixin2, Mixin3, QFrame): + def __init__(self): + super(MainWindow, self).__init__() + +def main(): + app = QApplication([]) + # if it doesn't crash it should pass + w = MainWindow() + w.show() + QTimer.singleShot(0, w.close) + app.exec_() + +if __name__ == "__main__": + main() + + diff --git a/sources/pyside6/tests/QtWidgets/bug_844.py b/sources/pyside6/tests/QtWidgets/bug_844.py new file mode 100644 index 000000000..b17a6df14 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_844.py @@ -0,0 +1,54 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import sys +import os + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6.QtWidgets import * +from PySide6.QtCore import * + +class QtKeyPressListener(QObject): + def __init__(self, obj): + QObject.__init__(self) + obj.installEventFilter(self) + + def eventFilter(self, obj, event): + # This used to crash here due to a misbehaviour of type discovery! + return QObject.eventFilter(self, obj, event) + +app = QApplication([]) +key_listener = QtKeyPressListener(app) +w = QLabel('Hello') +w.show() +QTimer.singleShot(0, w.close) +app.exec_() diff --git a/sources/pyside6/tests/QtWidgets/bug_854.py b/sources/pyside6/tests/QtWidgets/bug_854.py new file mode 100644 index 000000000..218691312 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_854.py @@ -0,0 +1,75 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QTableView, QVBoxLayout, QApplication +from PySide6.QtCore import QAbstractItemModel + +from helper.usesqapplication import UsesQApplication + + +class VirtualList(QAbstractItemModel): + def __getitem__(self, index): + self._getItemCalled = True + pass + + def rowCount(self, parent): + return 5000 + + def columnCount(self, parent): + return 3 + + def index(self, row, column, parent): + return self.createIndex(row, column) + + def parent(self, index): + return QModelIndex() + + def data(self, index, role): + return "(%i, %i)" % (index.row(), index.column()) + + +class TestQAbstractItemModel(UsesQApplication): + def testSetModel(self): + model = VirtualList() + model._getItemCalled = False + table = QTableView() + table.setModel(model) + table.show() + self.assertFalse(model._getItemCalled) + +if __name__ == "__main__": + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/bug_860.py b/sources/pyside6/tests/QtWidgets/bug_860.py new file mode 100644 index 000000000..6fb511762 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_860.py @@ -0,0 +1,68 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import QSignalMapper +from PySide6.QtWidgets import QCheckBox + +from helper.usesqapplication import UsesQApplication + +class MultipleSlotTest(UsesQApplication): + def cb_changed(self, i): + self._changed = True + + def cb_changedVoid(self): + self._changed = True + + def testSignalMapper(self): + checkboxMapper = QSignalMapper() + box = QCheckBox('check me') + box.stateChanged.connect(checkboxMapper.map) + + checkboxMapper.setMapping(box, box.text()) + checkboxMapper.mappedString[str].connect(self.cb_changed) + self._changed = False + box.setChecked(True) + self.assertTrue(self._changed) + + def testSimpleSignal(self): + box = QCheckBox('check me') + box.stateChanged[int].connect(self.cb_changedVoid) + self._changed = False + box.setChecked(True) + self.assertTrue(self._changed) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_862.py b/sources/pyside6/tests/QtWidgets/bug_862.py new file mode 100644 index 000000000..9bbc84844 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_862.py @@ -0,0 +1,97 @@ +############################################################################# +## +## 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$ +## +############################################################################# + + +# +# Test for bug 862, original description was: +# +# print seems to be broken at least for QGraphicsItems-derived objects. The +# attached code shows: +# +# <__main__.MyQObject object at 0xf99f38> +# <__main__.MyQWidget object at 0xf99f38> +# <PySide.QtGui.MyQGraphicsObject (this = 0x11c0d60 , parent = 0x0 , pos = +# QPointF(0, 0) , z = 0 , flags = ( ) ) at 0xf99f38> +# <PySide.QtGui.QGraphicsItem (this = 0x11c2e60 , parent = 0x0 , pos = QPointF(0, +# 0) , z = 0 , flags = ( ) ) at 0xf99f38> +# +# Where it should be showing something like: +# +# <__main__.MyQObject object at 0x7f55cf226c20> +# <__main__.MyQWidget object at 0x7f55cf226c20> +# <__main__.MyQGraphicsObject object at 0x7f55cf226c20> +# <__main__.MyQGraphicsItem object at 0x7f55cf226c20> +# + +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 PySide6.QtCore import QObject +from PySide6.QtWidgets import * +import PySide6.QtCore + + +class MyQObject(QObject): + def __init__(self): + QObject.__init__(self) + +class MyQWidget(QWidget): + def __init__(self): + QWidget.__init__(self) + +class MyQGraphicsObject(QGraphicsObject): + def __init__(self): + QGraphicsObject.__init__(self) + +class MyQGraphicsItem(QGraphicsItem): + def __init__(self): + QGraphicsItem.__init__(self) + +class TestRepr (unittest.TestCase): + + def testIt(self): + + app = QApplication([]) + + self.assertEqual("<__main__.MyQObject(0x", repr(MyQObject())[:22]) + self.assertEqual("<__main__.MyQWidget(0x", repr(MyQWidget())[:22]) + self.assertEqual("<__main__.MyQGraphicsObject(0x", repr(MyQGraphicsObject())[:30]) + self.assertEqual("<__main__.MyQGraphicsItem(0x", repr(MyQGraphicsItem())[:28]) + + self.assertEqual("<PySide6.QtCore.QObject(0x", repr(QObject())[:26]) + self.assertEqual("<PySide6.QtCore.QObject(0x", repr(PySide6.QtCore.QObject())[:26]) + self.assertEqual("<PySide6.QtWidgets.QWidget(0x", repr(QWidget())[:29]) + self.assertEqual("<PySide6.QtWidgets.QGraphicsWidget(0x", repr(QGraphicsWidget())[:37]) + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_871.py b/sources/pyside6/tests/QtWidgets/bug_871.py new file mode 100644 index 000000000..9f2481d8e --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_871.py @@ -0,0 +1,77 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtGui import QValidator, QIntValidator +from PySide6.QtWidgets import QLineEdit + +'''Bug #871 - http://bugs.pyside.org/show_bug.cgi?id=871''' + + +class BlankIntValidator(QIntValidator): + def validate(self,input,pos): + if input == '': + return QValidator.Acceptable, input, pos + else: + return QIntValidator.validate(self,input,pos) + + +class Bug871Test(UsesQApplication): + def testWithoutValidator(self): + edit = QLineEdit() + self.assertEqual(edit.text(), '') + edit.insert('1') + self.assertEqual(edit.text(), '1') + edit.insert('a') + self.assertEqual(edit.text(), '1a') + edit.insert('2') + self.assertEqual(edit.text(), '1a2') + + def testWithIntValidator(self): + edit = QLineEdit() + edit.setValidator(BlankIntValidator(edit)) + self.assertEqual(edit.text(), '') + edit.insert('1') + self.assertEqual(edit.text(), '1') + edit.insert('a') + self.assertEqual(edit.text(), '1') + edit.insert('2') + self.assertEqual(edit.text(), '12') + + +if __name__ == "__main__": + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/bug_879.py b/sources/pyside6/tests/QtWidgets/bug_879.py new file mode 100644 index 000000000..17c6013af --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_879.py @@ -0,0 +1,64 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import QCoreApplication, QTimer, QEvent, Qt +from PySide6.QtWidgets import QApplication, QSpinBox +from PySide6.QtGui import QKeyEvent + +class MySpinBox(QSpinBox): + + def validate(self,text,pos): + return QSpinBox.validate(self,text,pos) + +class TestBug879 (unittest.TestCase): + + def testIt(self): + app = QApplication([]) + self.box = MySpinBox() + self.box.show() + + QTimer.singleShot(0, self.sendKbdEvent) + QTimer.singleShot(100, app.quit) + app.exec_() + + self.assertEqual(self.box.text(), '0') + + def sendKbdEvent(self): + ev = QKeyEvent(QEvent.KeyPress, Qt.Key_A, Qt.NoModifier, 'a') + QCoreApplication.sendEvent(self.box, ev) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_919.py b/sources/pyside6/tests/QtWidgets/bug_919.py new file mode 100644 index 000000000..10767e778 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_919.py @@ -0,0 +1,72 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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.timedqapplication import TimedQApplication +from PySide6.QtCore import Signal, QTimer +from PySide6.QtGui import QPainter +from PySide6.QtWidgets import QPushButton, QStyleOptionButton, QApplication, QStyle + +class MyWidget(QPushButton): + def __init__(self, parent = None): + QPushButton.__init__(self, parent) + self._painted = False + + def _emitPainted(self): + self.paintReceived.emit() + + def paintEvent(self, e): + p = QPainter(self) + style = QApplication.style() + option = QStyleOptionButton() + style.drawControl(QStyle.CE_PushButton, option, p) + self._painted = True + QTimer.singleShot(0, self._emitPainted) + + paintReceived = Signal() + +class TestBug919(TimedQApplication): + def setUp(self): + TimedQApplication.setUp(self, 2000) + + def testFontInfo(self): + w = MyWidget() + w.paintReceived.connect(self.app.quit) + w.show() + self.app.exec_() + self.assertTrue(w._painted) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_921.py b/sources/pyside6/tests/QtWidgets/bug_921.py new file mode 100644 index 000000000..fd095cd2b --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_921.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python + +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6 import QtCore, QtWidgets + +from helper.timedqapplication import TimedQApplication + +class Signaller(QtCore.QObject): + s1 = QtCore.Signal() + s2 = QtCore.Signal() + s3 = QtCore.Signal() + +class Window(object): + + def __init__(self, s): + self._window = QtWidgets.QMainWindow() + self._window.setAttribute(QtCore.Qt.WA_DeleteOnClose, True) + self._window.setWindowTitle("Demo!") + + self._s = s + self._s.s1.connect(self._on_signal) + self._s.s2.connect(self._on_signal) + + def show(self): + self._window.show() + + def _on_signal(self): + self._window.setWindowTitle("Signaled!") + +class TestTimedApp(TimedQApplication): + def testSignals(self): + s = Signaller() + w = Window(s) + w.show() + + def midleFunction(): + def internalFunction(): + pass + s.s3.connect(internalFunction) + + midleFunction() + self.app.exec_() + del w + + s.s1.emit() + s.s2.emit() + s.s3.emit() + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_941.py b/sources/pyside6/tests/QtWidgets/bug_941.py new file mode 100644 index 000000000..0b540e8ec --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_941.py @@ -0,0 +1,52 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import * +from PySide6.QtWidgets import * + +def foo(a, b): + pass + +class TestBug941 (unittest.TestCase): + + def testIt(self): + app = QApplication([]) + view = QHeaderView(Qt.Horizontal) + self.assertTrue(view.sortIndicatorChanged.connect(foo)) + view.sortIndicatorChanged.emit(0, Qt.Vertical) # this can't raise an exception! + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_964.py b/sources/pyside6/tests/QtWidgets/bug_964.py new file mode 100644 index 000000000..32bc584ef --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_964.py @@ -0,0 +1,54 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import * +from PySide6.QtGui import * +from PySide6.QtWidgets import * + +class TestBug964 (unittest.TestCase): + + def testIt(self): + app = QApplication([]) + model = QStringListModel(["1", "2"]) + view = QListView() + view.setModel(model) + view.setCurrentIndex(model.index(0,0)) + newCursor = view.moveCursor(QAbstractItemView.MoveDown, Qt.NoModifier) + self.assertEqual(newCursor.row(), 1) + self.assertEqual(newCursor.column(), 0) + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_967.py b/sources/pyside6/tests/QtWidgets/bug_967.py new file mode 100644 index 000000000..6ee4fed99 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_967.py @@ -0,0 +1,53 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import * + +class TestBug967 (unittest.TestCase): + + def callback(self, arg): + self.arg = arg + + def testIt(self): + self.arg = None + app = QApplication([]) + obj = QComboBox() + obj.currentIndexChanged.connect(self.callback) + obj.currentIndexChanged.emit(5) + self.assertEqual(self.arg, 5) + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_972.py b/sources/pyside6/tests/QtWidgets/bug_972.py new file mode 100644 index 000000000..686bd2ecc --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_972.py @@ -0,0 +1,74 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import QSizeF +from PySide6.QtWidgets import QGraphicsProxyWidget, QSizePolicy, QPushButton, QGraphicsScene, QGraphicsView + +from helper.timedqapplication import TimedQApplication + +def createItem(minimum, preferred, maximum, name): + w = QGraphicsProxyWidget() + + w.setWidget(QPushButton(name)) + w.setMinimumSize(minimum) + w.setPreferredSize(preferred) + w.setMaximumSize(maximum) + w.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) + + return w + +class TestBug972 (TimedQApplication): + + # Test if the function QGraphicsProxyWidget.setWidget have the correct behavior + def testIt(self): + scene = QGraphicsScene() + + minSize = QSizeF(30, 100) + prefSize = QSizeF(210, 100) + maxSize = QSizeF(300, 100) + + a = createItem(minSize, prefSize, maxSize, "A") + b = createItem(minSize, prefSize, maxSize, "B") + c = createItem(minSize, prefSize, maxSize, "C") + d = createItem(minSize, prefSize, maxSize, "D") + + view = QGraphicsView(scene) + view.show() + self.app.exec_() + + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_979.py b/sources/pyside6/tests/QtWidgets/bug_979.py new file mode 100644 index 000000000..b98ce6918 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_979.py @@ -0,0 +1,45 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6.QtWidgets import QDialog +from import_test import PysideImportTest2 + +class PysideImportTest1(QDialog, PysideImportTest2): + pass + +if __name__ == '__main__': + quit() + diff --git a/sources/pyside6/tests/QtWidgets/bug_988.py b/sources/pyside6/tests/QtWidgets/bug_988.py new file mode 100644 index 000000000..e362f1fb3 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_988.py @@ -0,0 +1,53 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import * + +class TestBug988 (unittest.TestCase): + + def callback(self, arg): + self.arg = arg + + def testIt(self): + self.arg = None + app = QApplication([]) + obj = QTabWidget() + obj.currentChanged.connect(self.callback) + obj.currentChanged.emit(5) + self.assertEqual(self.arg, 5) + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/bug_998.py b/sources/pyside6/tests/QtWidgets/bug_998.py new file mode 100644 index 000000000..f72092945 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/bug_998.py @@ -0,0 +1,45 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QApplication + +class TestBug998 (unittest.TestCase): + def testNoFocusWindow(self): + widget = QApplication.focusWidget() + self.assertTrue(widget == None) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/customproxywidget_test.py b/sources/pyside6/tests/QtWidgets/customproxywidget_test.py new file mode 100644 index 000000000..c605dd91f --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/customproxywidget_test.py @@ -0,0 +1,68 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import Qt, QTimer +from PySide6.QtGui import QPainter +from PySide6.QtWidgets import QLabel +from PySide6.QtWidgets import QGraphicsScene, QGraphicsView, QGraphicsItem, QGraphicsProxyWidget + +class CustomProxy(QGraphicsProxyWidget): + def __init__(self, parent=None, wFlags=0): + QGraphicsProxyWidget.__init__(self, parent, wFlags) + +class CustomProxyWidgetTest(UsesQApplication): + def testCustomProxyWidget(self): + scene = QGraphicsScene() + + proxy = CustomProxy(None, Qt.Window) + widget = QLabel('Widget') + proxy.setWidget(widget) + proxy.setCacheMode(QGraphicsItem.DeviceCoordinateCache) + scene.addItem(proxy) + scene.setSceneRect(scene.itemsBoundingRect()) + + view = QGraphicsView(scene) + view.setRenderHints(QPainter.Antialiasing|QPainter.SmoothPixmapTransform) + view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate) + view.show() + + timer = QTimer.singleShot(100, self.app.quit) + self.app.exec_() + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/event_filter_test.py b/sources/pyside6/tests/QtWidgets/event_filter_test.py new file mode 100644 index 000000000..8e9932cc0 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/event_filter_test.py @@ -0,0 +1,72 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import QObject, QEvent +from PySide6.QtWidgets import QWidget + +class MyFilter(QObject): + def eventFilter(self, obj, event): + if event.type() == QEvent.KeyPress: + pass + return QObject.eventFilter(self, obj, event) + + +class EventFilter(UsesQApplication): + def testRefCount(self): + o = QObject() + filt = MyFilter() + o.installEventFilter(filt) + self.assertEqual(sys.getrefcount(o), 2) + + o.installEventFilter(filt) + self.assertEqual(sys.getrefcount(o), 2) + + o.removeEventFilter(filt) + self.assertEqual(sys.getrefcount(o), 2) + + def testObjectDestructorOrder(self): + w = QWidget() + filt = MyFilter() + filt.app = self.app + w.installEventFilter(filt) + w.show() + w.close() + w = None + self.assertTrue(True) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/grandparent_method_test.py b/sources/pyside6/tests/QtWidgets/grandparent_method_test.py new file mode 100644 index 000000000..a3c5a1e07 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/grandparent_method_test.py @@ -0,0 +1,56 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''Tests for calling methods further than the direct parent''' + +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 PySide6.QtWidgets import QPushButton, QWidget + +from helper.usesqapplication import UsesQApplication + +class Dummy(QPushButton): + + def show(self): + QWidget.show(self) + self.called = True + +class GrandParentMethod(UsesQApplication): + def testMethod(self): + obj = Dummy() + obj.show() + self.assertTrue(obj.called) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/hashabletype_test.py b/sources/pyside6/tests/QtWidgets/hashabletype_test.py new file mode 100644 index 000000000..c443d0505 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/hashabletype_test.py @@ -0,0 +1,52 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''Test cases for __hash__''' + +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 PySide6.QtWidgets import QTreeWidgetItem +from helper.usesqapplication import UsesQApplication + +class HashableTest(UsesQApplication): + + def testQTreeWidgetItemHash(self): + h = {} + obj = QTreeWidgetItem() + h[obj] = 2 + self.assertTrue(h.get(obj), 2) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/import_test.py b/sources/pyside6/tests/QtWidgets/import_test.py new file mode 100644 index 000000000..0b60241f0 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/import_test.py @@ -0,0 +1,2 @@ +class PysideImportTest2(object): + pass diff --git a/sources/pyside6/tests/QtWidgets/keep_reference_test.py b/sources/pyside6/tests/QtWidgets/keep_reference_test.py new file mode 100644 index 000000000..1c634c396 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/keep_reference_test.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python + +############################################################################# +## +## 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$ +## +############################################################################# + +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 sys import getrefcount +from helper.usesqapplication import UsesQApplication +from PySide6.QtCore import * +from PySide6.QtWidgets import QTableView + +class TestModel(QAbstractTableModel): + def __init__(self, parent=None): + QAbstractTableModel.__init__(self, parent) + def rowCount(self, parent): + return 0 + def columnCount(self, parent): + return 0 + def data(self, index, role): + return None + +class KeepReferenceTest(UsesQApplication): + + def testModelWithoutParent(self): + view = QTableView() + model = TestModel() + view.setModel(model) + samemodel = view.model() + self.assertEqual(model, samemodel) + + def testModelWithParent(self): + view = QTableView() + model = TestModel(None) + view.setModel(model) + samemodel = view.model() + self.assertEqual(model, samemodel) + + def testReferenceCounting(self): + '''Tests reference count of model object referred by view objects.''' + model1 = TestModel() + refcount1 = getrefcount(model1) + view1 = QTableView() + view1.setModel(model1) + self.assertEqual(getrefcount(view1.model()), refcount1 + 1) + + view2 = QTableView() + view2.setModel(model1) + self.assertEqual(getrefcount(view2.model()), refcount1 + 2) + + model2 = TestModel() + view2.setModel(model2) + self.assertEqual(getrefcount(view1.model()), refcount1 + 1) + + def testReferenceCountingWhenDeletingReferrer(self): + '''Tests reference count of model object referred by deceased view object.''' + model = TestModel() + refcount1 = getrefcount(model) + view = QTableView() + view.setModel(model) + self.assertEqual(getrefcount(view.model()), refcount1 + 1) + + del view + self.assertEqual(getrefcount(model), refcount1) + + def testReferreedObjectSurvivalAfterContextEnd(self): + '''Model object assigned to a view object must survive after getting out of context.''' + def createModelAndSetToView(view): + model = TestModel() + model.setObjectName('created model') + view.setModel(model) + view = QTableView() + createModelAndSetToView(view) + model = view.model() + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/missing_symbols_test.py b/sources/pyside6/tests/QtWidgets/missing_symbols_test.py new file mode 100644 index 000000000..a51fbfa27 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/missing_symbols_test.py @@ -0,0 +1,64 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''(Very) Simple test case for missing names from QtGui and QtWidgets''' + +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 PySide6 import QtGui +from PySide6 import QtWidgets + +class MissingClasses(unittest.TestCase): + def testQDrag(self): # Bug 222 + getattr(QtGui, 'QDrag') + + def testQDropEvent(self): # Bug 255 + getattr(QtGui, 'QDropEvent') + +class MissingMembers(unittest.TestCase): + + def testQFontMetricsSize(self): # Bug 223 + QtGui.QFontMetrics.size + + def testQLayoutSetSpacing(self): # Bug 231 + QtWidgets.QLayout.setSpacing + + def testQImageLoad(self): # Bug 257 + QtGui.QImage.load + + def testQStandardItemModelinsertRow(self): # Bug 227 + QtGui.QStandardItemModel.insertRow + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/paint_event_test.py b/sources/pyside6/tests/QtWidgets/paint_event_test.py new file mode 100644 index 000000000..115f14b4a --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/paint_event_test.py @@ -0,0 +1,104 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''Test paint event override in python''' + +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 PySide6.QtCore import QTimerEvent +from PySide6.QtWidgets import QApplication, QWidget + +from helper.usesqapplication import UsesQApplication + +class MyWidget(QWidget): + '''Sample widget''' + + def __init__(self, app=None): + #Creates a new widget + if app is None: + app = QApplication([]) + + super(MyWidget, self).__init__() + self.app = app + self.runs = 0 + self.max_runs = 5 + self.paint_event_called = False + + def timerEvent(self, event): + #Timer event method + self.runs += 1 + + if self.runs == self.max_runs: + self.app.quit() + + if not isinstance(event, QTimerEvent): + raise TypeError('Invalid event type. Must be QTimerEvent') + + def paintEvent(self, event): + #Empty paint event method + # XXX: should be using super here, but somehow PyQt4 + # complains about paintEvent not present in super + QWidget.paintEvent(self, event) + self.paint_event_called = True + + +class PaintEventOverride(UsesQApplication): + '''Test case for overriding QWidget.paintEvent''' + + qapplication = True + + def setUp(self): + #Acquire resources + super(PaintEventOverride, self).setUp() + self.widget = MyWidget(self.app) + + def tearDown(self): + #Release resources + del self.widget + super(PaintEventOverride, self).tearDown() + + def testPaintEvent(self): + #Test QWidget.paintEvent override + timer_id = self.widget.startTimer(100) + self.widget.show() + self.app.exec_() + + self.widget.killTimer(timer_id) + + self.assertTrue(self.widget.paint_event_called) + self.assertEqual(self.widget.runs, 5) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/parent_method_test.py b/sources/pyside6/tests/QtWidgets/parent_method_test.py new file mode 100644 index 000000000..455ec46ee --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/parent_method_test.py @@ -0,0 +1,58 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import QObject, QTimer, QThread +from PySide6.QtWidgets import * + +class Foo(QTableView): + def __init__(self, parent=None): + QTableView.__init__(self, parent) + +from helper.usesqapplication import UsesQApplication + +class TestParentType(UsesQApplication): + + def testParentType(self): + # Test the problem with calling QObject.parent from a QWidget + # when the parent is a python class derived from a QWidget-derived + # class. The method was returning the last C++ class in the hierarchy + parent = Foo() + w2 = QWidget(parent) + self.assertTrue(isinstance(w2.parentWidget(), Foo)) + self.assertTrue(isinstance(w2.parent(), Foo)) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/private_mangle_test.py b/sources/pyside6/tests/QtWidgets/private_mangle_test.py new file mode 100644 index 000000000..d1520a44f --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/private_mangle_test.py @@ -0,0 +1,128 @@ +############################################################################# +## +## Copyright (C) 2018 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of Qt for Python. +## +## $QT_BEGIN_LICENSE:LGPL$ +## 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 Lesser General Public License Usage +## Alternatively, this file may be used under the terms of the GNU Lesser +## General Public License version 3 as published by the Free Software +## Foundation and appearing in the file LICENSE.LGPL3 included in the +## packaging of this file. Please review the following information to +## ensure the GNU Lesser General Public License version 3 requirements +## will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 2.0 or (at your option) the GNU General +## Public license version 3 or any later version approved by the KDE Free +## Qt Foundation. The licenses are as published by the Free Software +## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +## 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-2.0.html and +## https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +""" +This is the example from https://bugreports.qt.io/browse/PYSIDE-772 +with no interaction as a unittest. +""" + +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 PySide6.QtCore import Signal +from PySide6.QtWidgets import QApplication, QWidget +from PySide6 import QtWidgets + +class Harness(QWidget): + clicked = Signal() + + def __init__(self): + QWidget.__init__(self) + self.clicked.connect(self.method) + self.clicked.connect(self._method) + self.clicked.connect(self.__method) + + def method(self): # Public method + self.method_result = self.sender() + + def _method(self): # Private method + self.method__result = self.sender() + + def __method(self): # Name mangled method + self.method___result = self.sender() + + +class _Under(QWidget): + clicked = Signal() + + def __init__(self): + QWidget.__init__(self) + self.clicked.connect(self.method) + self.clicked.connect(self._method) + self.clicked.connect(self.__method) + + def method(self): # Public method + self.method_result = self.sender() + + def _method(self): # Private method + self.method__result = self.sender() + + def __method(self): # Name mangled method + self.method___result = self.sender() + + +class TestMangle(unittest.TestCase): + + def setUp(self): + QApplication() + + def tearDown(self): + qApp.shutdown() + + def testPrivateMangle(self): + harness = Harness() + harness.clicked.emit() + self.assertEqual(harness.method_result, harness) + self.assertEqual(harness.method__result, harness) + self.assertEqual(harness.method___result, harness) + self.assertTrue("method" in type(harness).__dict__) + self.assertTrue("_method" in type(harness).__dict__) + self.assertFalse("__method" in type(harness).__dict__) + self.assertTrue("_Harness__method" in type(harness).__dict__) + + def testPrivateMangleUnder(self): + harness = _Under() + harness.clicked.emit() + self.assertEqual(harness.method_result, harness) + self.assertEqual(harness.method__result, harness) + self.assertEqual(harness.method___result, harness) + # make sure that we skipped over the underscore in "_Under" + self.assertTrue("method" in type(harness).__dict__) + self.assertTrue("_method" in type(harness).__dict__) + self.assertFalse("__method" in type(harness).__dict__) + self.assertTrue("_Under__method" in type(harness).__dict__) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/python_properties_test.py b/sources/pyside6/tests/QtWidgets/python_properties_test.py new file mode 100644 index 000000000..f37881c2a --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/python_properties_test.py @@ -0,0 +1,52 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6 import QtCore, QtWidgets + +class Properties(unittest.TestCase): + + def testStaticProperty(self): + self.assertEqual(QtWidgets.QGraphicsItem.UserType, 65536) + + def testInstanceProperty(self): + 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/pyside6/tests/QtWidgets/qabstracttextdocumentlayout_test.py b/sources/pyside6/tests/QtWidgets/qabstracttextdocumentlayout_test.py new file mode 100644 index 000000000..212cff0ff --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qabstracttextdocumentlayout_test.py @@ -0,0 +1,80 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import QSizeF, QTimer +from PySide6.QtGui import QTextFormat, QTextCharFormat, QPyTextObject +from PySide6.QtWidgets import QTextEdit +from helper.usesqapplication import UsesQApplication + +class Foo(QPyTextObject): + called = False + + def intrinsicSize(self, doc, posInDocument, format): + Foo.called = True + return QSizeF(10, 10) + + def drawObject(self, painter, rect, doc, posInDocument, format): + pass + +class QAbstractTextDocumentLayoutTest(UsesQApplication): + + objectType = QTextFormat.UserObject + 1 + + def foo(self): + fmt = QTextCharFormat() + fmt.setObjectType(QAbstractTextDocumentLayoutTest.objectType) + + cursor = self.textEdit.textCursor() + cursor.insertText(chr(0xfffc), fmt) + self.textEdit.setTextCursor(cursor) + self.textEdit.close() + + def testIt(self): + + self.textEdit = QTextEdit() + self.textEdit.show() + + interface = Foo() + self.textEdit.document().documentLayout().registerHandler(QAbstractTextDocumentLayoutTest.objectType, interface) + + QTimer.singleShot(0, self.foo) + self.app.exec_() + + self.assertTrue(Foo.called) + +if __name__ == "__main__": + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qaction_test.py b/sources/pyside6/tests/QtWidgets/qaction_test.py new file mode 100644 index 000000000..558295adc --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qaction_test.py @@ -0,0 +1,76 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtGui import QAction +from PySide6.QtWidgets import QWidget +from helper.usesqapplication import UsesQApplication + +class QPainterDrawText(UsesQApplication): + + def _cb(self): + self._called = True + + def testSignal(self): + o = QWidget() + act = QAction(o) + self._called = False + act.triggered.connect(self._cb) + act.trigger() + self.assertTrue(self._called) + + def testNewCtor(self): + o = QWidget() + self._called = False + myAction = QAction("&Quit", o, triggered=self._cb) + myAction.trigger() + self.assertTrue(self._called) + + +class SetShortcutTest(UsesQApplication): + + def testSetShortcut(self): + # Somehow an exception was leaking from the constructor + # and appearing in setShortcut. + o = QWidget() + action = QAction('aaaa', o) + shortcut = 'Ctrl+N' + action.setShortcut(shortcut) + s2 = action.shortcut() + self.assertEqual(s2, shortcut) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qapp_issue_585.py b/sources/pyside6/tests/QtWidgets/qapp_issue_585.py new file mode 100644 index 000000000..1c86a1cc3 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qapp_issue_585.py @@ -0,0 +1,76 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +""" +The bug was caused by this commit: +"Support the qApp macro correctly, final version incl. debug" +e30e0c161b2b4d50484314bf006e9e5e8ff6b380 +2017-10-27 + +The bug was first solved by this commit: +"Fix qApp macro refcount" +b811c874dedd14fd8b072bc73761d39255216073 +2018-03-21 + +This test triggers the refcounting bug of qApp, issue PYSIDE-585. +Finally, the real patch included more changes, because another error +was in the ordering of shutdown calls. It was found using the following +Python configuration: + + In Python 3.6 create a directory 'debug' and cd into it. + + ../configure --with-pydebug --prefix=$HOME/pydebug/ --enable-shared + +Then a lot more refcounting errors show up, which are due to a bug in +the code position of the shutdown procedure. +The reason for the initial refcount bug was that the shutdown code is once +more often called than the creation of the qApp wrapper. +Finally, it was easiest and more intuitive to simply make the refcount of +qApp_content equal to that of Py_None, which is also not supposed to be +garbage-collected. + +For some reason, the test does not work as a unittest because it creates +no crash. We leave it this way. +""" + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6.QtCore import QTimer +from PySide6 import QtWidgets + +app_instance = QtWidgets.QApplication([]) +# If the following line is commented, application doesn't crash on exit anymore. +app_instance2 = app_instance +QTimer.singleShot(0, qApp.quit) +app_instance.exec_() diff --git a/sources/pyside6/tests/QtWidgets/qapp_test.py b/sources/pyside6/tests/QtWidgets/qapp_test.py new file mode 100644 index 000000000..edff491e1 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qapp_test.py @@ -0,0 +1,52 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +''' Test the presence of qApp Macro''' + +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 PySide6.QtWidgets import * + +class QAppPresence(unittest.TestCase): + + def testQApp(self): + #QtGui.qApp variable is instance of QApplication + self.assertTrue(isinstance(qApp, QApplication)) + +def main(): + app = QApplication([]) + unittest.main() + +if __name__ == '__main__': + main() diff --git a/sources/pyside6/tests/QtWidgets/qapplication_exit_segfault_test.py b/sources/pyside6/tests/QtWidgets/qapplication_exit_segfault_test.py new file mode 100644 index 000000000..951fc3193 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qapplication_exit_segfault_test.py @@ -0,0 +1,49 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QApplication, QPushButton, QWidget, QSpinBox + +class QApplicationDelete(unittest.TestCase): + '''Test for segfault when deleting a QApplication before a QWidget''' + + def testQPushButton(self): + #QApplication deleted before QPushButton + a = QApplication([]) + b = QPushButton('aaaa') + del a + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qapplication_test.py b/sources/pyside6/tests/QtWidgets/qapplication_test.py new file mode 100644 index 000000000..49b216043 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qapplication_test.py @@ -0,0 +1,46 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QApplication + +class TestQApplication(unittest.TestCase): + def testNoArguments(self): + app = QApplication() + self.assertIsInstance(app, QApplication) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qbrush_test.py b/sources/pyside6/tests/QtWidgets/qbrush_test.py new file mode 100644 index 000000000..6d568da42 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qbrush_test.py @@ -0,0 +1,58 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''Test cases for QBrush''' + +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 PySide6.QtCore import Qt +from PySide6.QtGui import QColor, QBrush +from PySide6.QtWidgets import QApplication + +from helper.usesqapplication import UsesQApplication + +class Constructor(UsesQApplication): + '''Test case for constructor of QBrush''' + + def testQColor(self): + #QBrush(QColor) constructor + color = QColor('black') + obj = QBrush(color) + self.assertEqual(obj.color(), color) + + obj = QBrush(Qt.blue) + self.assertEqual(obj.color(), Qt.blue) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qcolormap_test.py b/sources/pyside6/tests/QtWidgets/qcolormap_test.py new file mode 100644 index 000000000..bbde8357e --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qcolormap_test.py @@ -0,0 +1,49 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QColormap +from helper.usesqapplication import UsesQApplication + + +class QColormapTest(UsesQApplication): + + def testQColormap(self): + qc = QColormap.instance() + self.assertEqual(qc.size(), -1) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qdynamic_signal.py b/sources/pyside6/tests/QtWidgets/qdynamic_signal.py new file mode 100644 index 000000000..5fec6836a --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qdynamic_signal.py @@ -0,0 +1,61 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import QObject +from PySide6.QtWidgets import QInputDialog + +from helper.usesqapplication import UsesQApplication + +class DynamicSignalTest(UsesQApplication): + + def cb(self, obj): + self._called = True + + def testQDialog(self): + dlg = QInputDialog() + dlg.setInputMode(QInputDialog.TextInput) + lst = dlg.children() + self.assertTrue(len(lst)) + obj = lst[0] + self._called = False + obj.destroyed[QObject].connect(self.cb) + obj = None + del dlg + self.assertTrue(self._called) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qfontdialog_test.py b/sources/pyside6/tests/QtWidgets/qfontdialog_test.py new file mode 100644 index 000000000..8473854ec --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qfontdialog_test.py @@ -0,0 +1,56 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6 import QtCore +from PySide6 import QtGui +from PySide6 import QtWidgets + +from helper.timedqapplication import TimedQApplication + +class TestFontDialog(TimedQApplication): + + def testGetFont(self): + QtWidgets.QFontDialog.getFont() + + def testGetFontQDialog(self): + QtWidgets.QFontDialog.getFont(QtGui.QFont("FreeSans",10)) + + def testGetFontQDialogQString(self): + QtWidgets.QFontDialog.getFont(QtGui.QFont("FreeSans",10), None, "Select font") + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qformlayout_test.py b/sources/pyside6/tests/QtWidgets/qformlayout_test.py new file mode 100644 index 000000000..87bff138e --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qformlayout_test.py @@ -0,0 +1,91 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QFormLayout, QWidget + +from helper.usesqapplication import UsesQApplication + +class QFormLayoutTest(UsesQApplication): + + def testGetItemPosition(self): + formlayout = QFormLayout() + row, role = formlayout.getItemPosition(0) + self.assertTrue(isinstance(row, int)) + self.assertTrue(isinstance(role, QFormLayout.ItemRole)) + self.assertEqual(row, -1) + + widget = QWidget() + formlayout.addRow(widget) + row, role = formlayout.getItemPosition(0) + self.assertTrue(isinstance(row, int)) + self.assertTrue(isinstance(role, QFormLayout.ItemRole)) + self.assertEqual(row, 0) + self.assertEqual(role, QFormLayout.SpanningRole) + + def testGetWidgetPosition(self): + formlayout = QFormLayout() + widget = QWidget() + row, role = formlayout.getWidgetPosition(widget) + self.assertTrue(isinstance(row, int)) + self.assertTrue(isinstance(role, QFormLayout.ItemRole)) + self.assertEqual(row, -1) + + formlayout.addRow(widget) + row, role = formlayout.getWidgetPosition(widget) + self.assertTrue(isinstance(row, int)) + self.assertTrue(isinstance(role, QFormLayout.ItemRole)) + self.assertEqual(row, 0) + self.assertEqual(role, QFormLayout.SpanningRole) + + def testGetLayoutPosition(self): + formlayout = QFormLayout() + layout = QFormLayout() + row, role = formlayout.getLayoutPosition(layout) + self.assertTrue(isinstance(row, int)) + self.assertTrue(isinstance(role, QFormLayout.ItemRole)) + self.assertEqual(row, -1) + + formlayout.addRow(layout) + row, role = formlayout.getLayoutPosition(layout) + self.assertTrue(isinstance(row, int)) + self.assertTrue(isinstance(role, QFormLayout.ItemRole)) + self.assertEqual(row, 0) + self.assertEqual(role, QFormLayout.SpanningRole) + + +if __name__ == "__main__": + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qgraphicsitem_isblocked_test.py b/sources/pyside6/tests/QtWidgets/qgraphicsitem_isblocked_test.py new file mode 100644 index 000000000..642fab27b --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qgraphicsitem_isblocked_test.py @@ -0,0 +1,64 @@ +#!/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 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 PySide6 import QtCore +from PySide6 import QtGui +from PySide6 import QtWidgets +from helper.usesqapplication import UsesQApplication + +class Item(QtWidgets.QGraphicsItem): + + def __init__(self): + QtWidgets.QGraphicsItem.__init__(self) + + def boundingRect(self): + return QtCore.QRectF(0, 0, 100, 100) + + def paint(self, painter, option, widget): + painter.setBrush(QtGui.QColor(255, 255, 255)) + painter.drawRect(0, 0, 100, 100) + + +class QGraphicsViewIsBlockedTest(UsesQApplication): + + def testIsBlockedByModalPanel(self): + (first, second) = Item().isBlockedByModalPanel() + self.assertFalse(first) + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qgraphicsitem_test.py b/sources/pyside6/tests/QtWidgets/qgraphicsitem_test.py new file mode 100644 index 000000000..961d016c0 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qgraphicsitem_test.py @@ -0,0 +1,69 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +''' Test cases related to QGraphicsItem and subclasses''' + +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 PySide6.QtGui import QPolygonF, QColor, QBrush +from PySide6.QtWidgets import QGraphicsScene + +from helper.usesqapplication import UsesQApplication + +class QColorOnSetBrush(UsesQApplication): + '''Test case for passing a QColor directly to setBrush''' + + def setUp(self): + #Acquire resources + super(QColorOnSetBrush, self).setUp() + + self.scene = QGraphicsScene() + poly = QPolygonF() + self.item = self.scene.addPolygon(poly) + self.color = QColor('black') + + def tearDown(self): + #Release resources + del self.color + del self.item + del self.scene + super(QColorOnSetBrush, self).tearDown() + + def testQColor(self): + #QGraphicsAbstractShapeItem.setBrush(QColor) + self.item.setBrush(self.color) + self.assertEqual(QBrush(self.color), self.item.brush()) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qgraphicsobjectreimpl_test.py b/sources/pyside6/tests/QtWidgets/qgraphicsobjectreimpl_test.py new file mode 100644 index 000000000..e9b509a65 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qgraphicsobjectreimpl_test.py @@ -0,0 +1,82 @@ +############################################################################# +## +## 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 related to QGraphicsItem and subclasses''' + +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 PySide6.QtWidgets import QGraphicsObject, QGraphicsWidget +from PySide6.QtCore import QRectF + +from helper.usesqapplication import UsesQApplication + +class GObjA(QGraphicsObject): + def paint(self, *args): + pass + + def boundingRect(self): + return QRectF() + + def itemChange(self, *args): + return QGraphicsObject.itemChange(self, *args) + +class GObjB(QGraphicsObject): + def paint(self, *args): + pass + + def boundingRect(self): + return QRectF() + +class QGraphicsObjectReimpl(UsesQApplication): + '''Test case for reimplementing QGraphicsObject''' + + def testReimplementationTypes(self): + w = QGraphicsWidget() + + # PYSIDE-86: + # This case failed because GObjA was reimplementing + # the method itemChange() from QGraphicsItem, + # and then the QVariant was not associated with + # a QGraphicsItem but a QObjectItem because the base + # class was a QObject. + gobjA = GObjA() + gobjA.setParentItem(w) + self.assertIs(type(w), type(gobjA.parentItem())) + + gobjB = GObjB() + gobjB.setParentItem(w) + self.assertIs(type(w), type(gobjB.parentItem())) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qgraphicsproxywidget_test.py b/sources/pyside6/tests/QtWidgets/qgraphicsproxywidget_test.py new file mode 100644 index 000000000..ac9124f6c --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qgraphicsproxywidget_test.py @@ -0,0 +1,64 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import Qt, QTimer +from PySide6.QtGui import QPainter +from PySide6.QtWidgets import QLabel +from PySide6.QtWidgets import QGraphicsScene, QGraphicsView, QGraphicsItem, QGraphicsProxyWidget + +class QGraphicsProxyWidgetTest(UsesQApplication): + def testQGraphicsProxyWidget(self): + scene = QGraphicsScene() + + proxy = QGraphicsProxyWidget(None, Qt.Window) + widget = QLabel('Widget') + proxy.setWidget(widget) + proxy.setCacheMode(QGraphicsItem.DeviceCoordinateCache) + scene.addItem(proxy) + scene.setSceneRect(scene.itemsBoundingRect()) + + view = QGraphicsView(scene) + view.setRenderHints(QPainter.Antialiasing|QPainter.SmoothPixmapTransform) + view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate) + view.show() + + timer = QTimer.singleShot(100, self.app.quit) + self.app.exec_() + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qgraphicsscene_test.py b/sources/pyside6/tests/QtWidgets/qgraphicsscene_test.py new file mode 100644 index 000000000..6a563e590 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qgraphicsscene_test.py @@ -0,0 +1,224 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''Basic test cases for QGraphicsScene''' + +import gc +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 PySide6.QtCore import QPointF +from PySide6.QtGui import QPolygonF, QPixmap, QPainterPath, QTransform, QWindow +from PySide6.QtWidgets import QApplication, QPushButton +from PySide6.QtWidgets import QGraphicsScene +from PySide6.QtWidgets import QGraphicsEllipseItem, QGraphicsLineItem +from PySide6.QtWidgets import QGraphicsPathItem, QGraphicsPixmapItem +from PySide6.QtWidgets import QGraphicsPolygonItem, QGraphicsRectItem +from PySide6.QtWidgets import QGraphicsSimpleTextItem, QGraphicsTextItem +from PySide6.QtWidgets import QGraphicsProxyWidget, QGraphicsView + +from helper.usesqapplication import UsesQApplication + +class Constructor(unittest.TestCase): + '''QGraphicsScene constructor''' + + def testConstructor(self): + #QGraphicsScene constructor + obj = QGraphicsScene() + self.assertTrue(isinstance(obj, QGraphicsScene)) + +# Test for PYSIDE-868: Test whether painter.device() can be accessed +# correctly. This was crashing when the underlying QPaintDevice was a +# QWidget due to handling multiple inheritance incorrectly. +class CustomScene(QGraphicsScene): + def __init__(self, parent = None): + super(CustomScene, self).__init__(parent) + self.dpi = 0 + + def drawBackground(self, painter, rect): + self.dpi = painter.device().physicalDpiX() + + def drawForeground(self, painter, rect): + self.dpi = painter.device().physicalDpiX() + +class ConstructorWithRect(unittest.TestCase): + '''QGraphicsScene qrect constructor and related sizes''' + + def setUp(self): + #Acquire resources + # PyQt4 doesn't accept a QRect as argument to constructor + self.scene = QGraphicsScene(0, 200, 150, 175) + + def tearDown(self): + #Release resources + del self.scene + + def testHeight(self): + #QGraphicsScene.height() + self.assertEqual(self.scene.height(), 175) + + def testWidth(self): + #QGraphicsScene.width() + self.assertEqual(self.scene.width(), 150) + + +class AddItem(UsesQApplication): + '''Tests for QGraphicsScene.add*''' + + qapplication = True + + def setUp(self): + #Acquire resources + super(AddItem, self).setUp() + self.scene = QGraphicsScene() + # While the scene does not inherits from QWidget, requires + # an application to make the internals work. + + def tearDown(self): + #Release resources + del self.scene + super(AddItem, self).tearDown() + + def testEllipse(self): + #QGraphicsScene.addEllipse + item = self.scene.addEllipse(100, 100, 100, 100) + self.assertTrue(isinstance(item, QGraphicsEllipseItem)) + + def testLine(self): + #QGraphicsScene.addLine + item = self.scene.addLine(100, 100, 200, 200) + self.assertTrue(isinstance(item, QGraphicsLineItem)) + + def testPath(self): + #QGraphicsScene.addPath + item = self.scene.addPath(QPainterPath()) + self.assertTrue(isinstance(item, QGraphicsPathItem)) + + def testPixmap(self): + #QGraphicsScene.addPixmap + item = self.scene.addPixmap(QPixmap()) + self.assertTrue(isinstance(item, QGraphicsPixmapItem)) + + def testPolygon(self): + #QGraphicsScene.addPolygon + points = [QPointF(0, 0), QPointF(100, 100), QPointF(0, 100)] + item = self.scene.addPolygon(QPolygonF(points)) + self.assertTrue(isinstance(item, QGraphicsPolygonItem)) + + def testRect(self): + #QGraphicsScene.addRect + item = self.scene.addRect(100, 100, 100, 100) + self.assertTrue(isinstance(item, QGraphicsRectItem)) + + def testSimpleText(self): + #QGraphicsScene.addSimpleText + item = self.scene.addSimpleText('Monty Python 42') + self.assertTrue(isinstance(item, QGraphicsSimpleTextItem)) + + def testText(self): + #QGraphicsScene.addText + item = self.scene.addText('Monty Python 42') + self.assertTrue(isinstance(item, QGraphicsTextItem)) + + def testWidget(self): + #QGraphicsScene.addWidget + # XXX: printing some X11 error when using under PyQt4 + item = self.scene.addWidget(QPushButton()) + self.assertTrue(isinstance(item, QGraphicsProxyWidget)) + + +class ItemRetrieve(UsesQApplication): + '''Tests for QGraphicsScene item retrieval methods''' + + qapplication = True + + def setUp(self): + #Acquire resources + super(ItemRetrieve, self).setUp() + self.scene = QGraphicsScene() + + self.topleft = QGraphicsRectItem(0, 0, 100, 100) + self.topright = QGraphicsRectItem(100, 0, 100, 100) + self.bottomleft = QGraphicsRectItem(0, 100, 100, 100) + self.bottomright = QGraphicsRectItem(100, 100, 100, 100) + + self.items = [self.topleft, self.topright, self.bottomleft, + self.bottomright] + + for item in self.items: + self.scene.addItem(item) + + def tearDown(self): + #Release resources + del self.scene + super(ItemRetrieve, self).tearDown() + + def testItems(self): + #QGraphicsScene.items() + items = self.scene.items() + for i in items: + self.assertTrue(i in self.items) + + def testItemAt(self): + #QGraphicsScene.itemAt() + self.assertEqual(self.scene.itemAt(50, 50, QTransform()), self.topleft) + self.assertEqual(self.scene.itemAt(150, 50, QTransform()), self.topright) + self.assertEqual(self.scene.itemAt(50, 150, QTransform()), self.bottomleft) + self.assertEqual(self.scene.itemAt(150, 150, QTransform()), self.bottomright) + +class TestGraphicsGroup(UsesQApplication): + def testIt(self): + scene = QGraphicsScene() + i1 = QGraphicsRectItem() + scene.addItem(i1) + i2 = QGraphicsRectItem(i1) + i3 = QGraphicsRectItem() + i4 = QGraphicsRectItem() + group = scene.createItemGroup((i2, i3, i4)) + scene.removeItem(i1) + del i1 # this shouldn't delete i2 + self.assertEqual(i2.scene(), scene) + scene.destroyItemGroup(group) + self.assertRaises(RuntimeError, group.type) + + def testCustomScene(self): # For PYSIDE-868, see above + scene = CustomScene() + view = QGraphicsView(scene) + view.show() + while scene.dpi == 0: + QApplication.instance().processEvents() + view.hide() + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qimage_test.py b/sources/pyside6/tests/QtWidgets/qimage_test.py new file mode 100644 index 000000000..778b339d6 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qimage_test.py @@ -0,0 +1,309 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''Test cases for QImage''' + +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 PySide6.QtGui import * +from PySide6.QtWidgets import * +from helper.helper import adjust_filename +from helper.usesqapplication import UsesQApplication + +xpm = [ + "27 22 206 2", + " c None", + ". c #FEFEFE", + "+ c #FFFFFF", + "@ c #F9F9F9", + "# c #ECECEC", + "$ c #D5D5D5", + "% c #A0A0A0", + "& c #767676", + "* c #525252", + "= c #484848", + "- c #4E4E4E", + "; c #555555", + "> c #545454", + ", c #5A5A5A", + "' c #4B4B4B", + ") c #4A4A4A", + "! c #4F4F4F", + "~ c #585858", + "{ c #515151", + "] c #4C4C4C", + "^ c #B1B1B1", + "/ c #FCFCFC", + "( c #FDFDFD", + "_ c #C1C1C1", + ": c #848484", + "< c #616161", + "[ c #5E5E5E", + "} c #CECECE", + "| c #E2E2E2", + "1 c #E4E4E4", + "2 c #DFDFDF", + "3 c #D2D2D2", + "4 c #D8D8D8", + "5 c #D4D4D4", + "6 c #E6E6E6", + "7 c #F1F1F1", + "8 c #838383", + "9 c #8E8E8E", + "0 c #8F8F8F", + "a c #CBCBCB", + "b c #CCCCCC", + "c c #E9E9E9", + "d c #F2F2F2", + "e c #EDEDED", + "f c #B5B5B5", + "g c #A6A6A6", + "h c #ABABAB", + "i c #BBBBBB", + "j c #B0B0B0", + "k c #EAEAEA", + "l c #6C6C6C", + "m c #BCBCBC", + "n c #F5F5F5", + "o c #FAFAFA", + "p c #B6B6B6", + "q c #F3F3F3", + "r c #CFCFCF", + "s c #FBFBFB", + "t c #CDCDCD", + "u c #DDDDDD", + "v c #999999", + "w c #F0F0F0", + "x c #2B2B2B", + "y c #C3C3C3", + "z c #A4A4A4", + "A c #D7D7D7", + "B c #E7E7E7", + "C c #6E6E6E", + "D c #9D9D9D", + "E c #BABABA", + "F c #AEAEAE", + "G c #898989", + "H c #646464", + "I c #BDBDBD", + "J c #CACACA", + "K c #2A2A2A", + "L c #212121", + "M c #B7B7B7", + "N c #F4F4F4", + "O c #737373", + "P c #828282", + "Q c #4D4D4D", + "R c #000000", + "S c #151515", + "T c #B2B2B2", + "U c #D6D6D6", + "V c #D3D3D3", + "W c #2F2F2F", + "X c #636363", + "Y c #A1A1A1", + "Z c #BFBFBF", + "` c #E0E0E0", + " . c #6A6A6A", + ".. c #050505", + "+. c #A3A3A3", + "@. c #202020", + "#. c #5F5F5F", + "$. c #B9B9B9", + "%. c #C7C7C7", + "&. c #D0D0D0", + "*. c #3E3E3E", + "=. c #666666", + "-. c #DBDBDB", + ";. c #424242", + ">. c #C2C2C2", + ",. c #1A1A1A", + "'. c #2C2C2C", + "). c #F6F6F6", + "!. c #AAAAAA", + "~. c #DCDCDC", + "{. c #2D2D2D", + "]. c #2E2E2E", + "^. c #A7A7A7", + "/. c #656565", + "(. c #333333", + "_. c #464646", + ":. c #C4C4C4", + "<. c #B8B8B8", + "[. c #292929", + "}. c #979797", + "|. c #EFEFEF", + "1. c #909090", + "2. c #8A8A8A", + "3. c #575757", + "4. c #676767", + "5. c #C5C5C5", + "6. c #7A7A7A", + "7. c #797979", + "8. c #989898", + "9. c #EEEEEE", + "0. c #707070", + "a. c #C8C8C8", + "b. c #111111", + "c. c #AFAFAF", + "d. c #474747", + "e. c #565656", + "f. c #E3E3E3", + "g. c #494949", + "h. c #5B5B5B", + "i. c #222222", + "j. c #353535", + "k. c #D9D9D9", + "l. c #0A0A0A", + "m. c #858585", + "n. c #E5E5E5", + "o. c #0E0E0E", + "p. c #9A9A9A", + "q. c #6F6F6F", + "r. c #868686", + "s. c #060606", + "t. c #1E1E1E", + "u. c #E8E8E8", + "v. c #A5A5A5", + "w. c #0D0D0D", + "x. c #030303", + "y. c #272727", + "z. c #131313", + "A. c #1F1F1F", + "B. c #757575", + "C. c #F7F7F7", + "D. c #414141", + "E. c #080808", + "F. c #6B6B6B", + "G. c #313131", + "H. c #C0C0C0", + "I. c #C9C9C9", + "J. c #0B0B0B", + "K. c #232323", + "L. c #434343", + "M. c #3D3D3D", + "N. c #282828", + "O. c #7C7C7C", + "P. c #252525", + "Q. c #3A3A3A", + "R. c #F8F8F8", + "S. c #1B1B1B", + "T. c #949494", + "U. c #3B3B3B", + "V. c #242424", + "W. c #383838", + "X. c #6D6D6D", + "Y. c #818181", + "Z. c #939393", + "`. c #9E9E9E", + " + c #929292", + ".+ c #7D7D7D", + "++ c #ADADAD", + "@+ c #DADADA", + "#+ c #919191", + "$+ c #E1E1E1", + "%+ c #BEBEBE", + "&+ c #ACACAC", + "*+ c #9C9C9C", + "=+ c #B3B3B3", + "-+ c #808080", + ";+ c #A8A8A8", + ">+ c #393939", + ",+ c #747474", + "'+ c #7F7F7F", + ")+ c #D1D1D1", + "!+ c #606060", + "~+ c #5C5C5C", + "{+ c #686868", + "]+ c #7E7E7E", + "^+ c #787878", + "/+ c #595959", + ". . . + @ # $ % & * = - ; > , ' ) ! ~ { ] ^ / . . + + ", + ". ( + _ : < [ & } | 1 2 $ 3 4 5 3 6 7 + + 8 9 + . + . ", + ". + 0 9 a ( 3 a b c d e c f g h i g j $ k + l m + . + ", + "+ 2 8 n o p | ( q r s . # t + + + u ^ v e w + x + + + ", + "+ y z . @ A k B 7 n + ( s | p 8 C D 2 E 4 + + F G + . ", + "# H I $ J G K L - M N . 2 O P Q R R S T U s s V W j + ", + "X Y Z @ o ` _ g ...+.( 4 @.#.m G $.%.7 &.X *.=.-.;.&.", + "Q >.C ,.'.} e + ).!.k + . + + . ~.{.> ].x f 7 ^./.k (.", + "_.:.4 @ <.[.}.|.1.2.+ + + >.} 4 B + ( @ _ 3.4.5.6.r 7.", + "3.8.9.~ 0.+ a.Q b.+ + c.d.#.=.$ |.b #.e.z ^ ; ^. .f.g.", + "-.h.+ i.S M + # p j.% n 9.5.k.H l.m.V ^.n.o.M + M p.q.", + "7 r.N s.1.R t.<.|.| u.v.~ w.x.E + s y.z.A.B.C.+ 5 D.q ", + ").p.2 E.0.9 F.%.O {._ @.+ + i { [ i.G.H.P I.+ s q.} + ", + ").p.6 J.R b.K.L.M.A.! b.g.K [.R M k + N.I + + >.O.+ . ", + ").8.9.N.P...R R R R E.t.W n.+ Q.R.6 @.| + . + S.+ + . ", + "n }.w T.U.B.<.i.@ Y + + U.+ c u V.= B B 7 u.W.c + . + ", + "N T.# + }.X.Y.,.8.F.8 Z.[.`. +.+}.4 ++@+O.< ~.+ ( . + ", + "d #+1 + _ ~.u.$+b $.y @+| $+%+I.&+k.h W +.9.+ ( . + . ", + "w 0 |.*+. >.<.=+++++p a.p -+;+5.k.>+,+@ + . . + . + + ", + "q '+9.R.^ I.t b %.I.)+4 $+n.I.,+ .|.+ . . . + . + + + ", + ". p !+( + + + + + + E 0. .-+8.f.+ + . . + + . + + + + ", + ". ( A ~+{+]+^+l > /+D f.c q . + . . + + . + + + + + + " +] + +class QImageTest(UsesQApplication): + '''Test case for calling setPixel with float as argument''' + + def testQImageStringBuffer(self): + '''Test if the QImage signatures receiving string buffers exist.''' + img0 = QImage(adjust_filename('sample.png', __file__)) + + # btw let's test the bits() method + img1 = QImage(img0.bits(), img0.width(), img0.height(), img0.format()) + self.assertEqual(img0, img1) + img2 = QImage(img0.bits(), img0.width(), img0.height(), img0.bytesPerLine(), img0.format()) + self.assertEqual(img0, img2) + + ## test scanLine method + data1 = img0.scanLine(0) + data2 = img1.scanLine(0) + self.assertEqual(data1, data2) + + def testEmptyBuffer(self): + img = QImage(bytes('', "UTF-8"), 100, 100, QImage.Format_ARGB32) + + def testEmptyStringAsBuffer(self): + img = QImage(bytes('', "UTF-8"), 100, 100, QImage.Format_ARGB32) + + def testXpmConstructor(self): + label = QLabel() + img = QImage(xpm) + self.assertFalse(img.isNull()) + self.assertEqual(img.width(), 27) + self.assertEqual(img.height(), 22) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qinputdialog_get_test.py b/sources/pyside6/tests/QtWidgets/qinputdialog_get_test.py new file mode 100644 index 000000000..a2df8e863 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qinputdialog_get_test.py @@ -0,0 +1,58 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6 import QtCore, QtWidgets +from helper.timedqapplication import TimedQApplication + +class TestInputDialog(TimedQApplication): + + def testGetDouble(self): + self.assertEqual(QtWidgets.QInputDialog.getDouble(None, "title", "label"), (0.0, False)) + + def testGetInt(self): + self.assertEqual(QtWidgets.QInputDialog.getInt(None, "title", "label"), (0, False)) + + def testGetItem(self): + (item, bool) = QtWidgets.QInputDialog.getItem(None, "title", "label", ["1", "2", "3"]) + self.assertEqual(str(item), "1") + + def testGetText(self): + (text, bool) = QtWidgets.QInputDialog.getText(None, "title", "label") + self.assertEqual(str(text),"") + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qkeysequenceedit_test.py b/sources/pyside6/tests/QtWidgets/qkeysequenceedit_test.py new file mode 100644 index 000000000..8591b4979 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qkeysequenceedit_test.py @@ -0,0 +1,53 @@ +############################################################################# +## +## Copyright (C) 2017 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 QKeySequenceEdit.''' + +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 PySide6.QtCore import QTimer +from PySide6.QtWidgets import QKeySequenceEdit + +from helper.usesqapplication import UsesQApplication + +class QKeySequenceEditTest(UsesQApplication): + def testKeySequence(self): + keySequenceEdit = QKeySequenceEdit() + keySequenceEdit.show() + QTimer.singleShot(0, keySequenceEdit.close) + self.app.exec_() + print(keySequenceEdit.keySequence()) + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qlabel_test.py b/sources/pyside6/tests/QtWidgets/qlabel_test.py new file mode 100644 index 000000000..bb8d39bcf --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qlabel_test.py @@ -0,0 +1,88 @@ +############################################################################# +## +## 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 QLabel''' + +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(True) + +from PySide6.QtGui import QPixmap +from PySide6.QtWidgets import QLabel +import shiboken6 as shiboken + +from helper.usesqapplication import UsesQApplication + +class QLabelTest(UsesQApplication): + '''Test case for calling QLabel.setPixmap''' + + def setUp(self): + super(QLabelTest, self).setUp() + self.label = QLabel() + + def tearDown(self): + del self.label + super(QLabelTest, self).tearDown() + + def testSetPixmap(self): + + p1 = QPixmap(5, 5) + p2 = QPixmap(10, 10) + + self.label.setPixmap(p1) + self.assertIsNotNone(self.label.pixmap()) + + + # PYSIDE-150: + # When a new QPixmap is assigned to a QLabel, + # the previous one needs to be cleared. + # This means we should not keep a copy of the QPixmap + # on Python-side. + + # Getting pointer to the QPixmap + ret_p = self.label.pixmap() + self.assertIsNot(p1, ret_p) + # Save the address of the pointer + ret_p_addr = shiboken.getCppPointer(ret_p) + # Remove the QPixmap + del ret_p + # Set new QPixmap + self.label.setPixmap(p2) + + # There should be no pointers remaining with the same + # address that our QPixmap p1 because it was deleted + # using `del ret_p` + self.assertTrue(all(shiboken.getCppPointer(o) != ret_p_addr + for o in shiboken.getAllValidWrappers())) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qlayout_ref_test.py b/sources/pyside6/tests/QtWidgets/qlayout_ref_test.py new file mode 100644 index 000000000..717cd67b8 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qlayout_ref_test.py @@ -0,0 +1,185 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''Test cases for QLayout handling of child widgets references''' + +import os +import sys +from sys import getrefcount +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 PySide6.QtWidgets import QHBoxLayout, QVBoxLayout, QGridLayout, QWidget +from PySide6.QtWidgets import QStackedLayout, QFormLayout +from PySide6.QtWidgets import QApplication, QPushButton, QLabel + +from helper.usesqapplication import UsesQApplication + +class SaveReference(UsesQApplication): + '''Test case to check if QLayout-derived classes increment the refcount + of widgets passed to addWidget()''' + + # Adding here as nose can't see the qapplication attrib we inherit + qapplication = True + + def setUp(self): + #Acquire resources + super(SaveReference, self).setUp() + self.widget1 = QPushButton('click me') + self.widget2 = QLabel('aaa') + + def tearDown(self): + #Release resources + del self.widget2 + del self.widget1 + super(SaveReference, self).tearDown() + + def checkLayoutReference(self, layout): + #Checks the reference cound handling of layout.addWidget + self.assertEqual(getrefcount(self.widget1), 2) + layout.addWidget(self.widget1) + self.assertEqual(getrefcount(self.widget1), 3) + + self.assertEqual(getrefcount(self.widget2), 2) + layout.addWidget(self.widget2) + self.assertEqual(getrefcount(self.widget2), 3) + + # Check if doesn't mess around with previous widget refcount + self.assertEqual(getrefcount(self.widget1), 3) + + def testMoveLayout(self): + l = QHBoxLayout() + self.assertEqual(getrefcount(self.widget1), 2) + l.addWidget(self.widget1) + self.assertEqual(getrefcount(self.widget1), 3) + + w = QWidget() + w.setLayout(l) + self.assertEqual(getrefcount(self.widget1), 3) + + + def testHBoxReference(self): + #QHBoxLayout.addWidget reference count + w = QWidget() + self.checkLayoutReference(QHBoxLayout(w)) + + def testVBoxReference(self): + #QVBoxLayout.addWidget reference count + w = QWidget() + self.checkLayoutReference(QVBoxLayout(w)) + + def testGridReference(self): + #QGridLayout.addWidget reference count + w = QWidget() + self.checkLayoutReference(QGridLayout(w)) + + def testFormReference(self): + #QFormLayout.addWidget reference count + w = QWidget() + self.checkLayoutReference(QFormLayout(w)) + + def testStackedReference(self): + #QStackedLayout.addWidget reference count + w = QWidget() + self.checkLayoutReference(QStackedLayout(w)) + +class MultipleAdd(UsesQApplication): + '''Test case to check if refcount is incremented only once when multiple + calls to addWidget are made with the same widget''' + + qapplication = True + + def setUp(self): + #Acquire resources + super(MultipleAdd, self).setUp() + self.widget = QPushButton('click me') + self.win = QWidget() + self.layout = QHBoxLayout(self.win) + + def tearDown(self): + #Release resources + del self.widget + del self.layout + del self.win + super(MultipleAdd, self).tearDown() + + def testRefCount(self): + #Multiple QLayout.addWidget calls on the same widget + self.assertEqual(getrefcount(self.widget), 2) + self.layout.addWidget(self.widget) + self.assertEqual(getrefcount(self.widget), 3) + self.layout.addWidget(self.widget) + self.assertEqual(getrefcount(self.widget), 3) + self.layout.addWidget(self.widget) + self.assertEqual(getrefcount(self.widget), 3) + +class InternalAdd(UsesQApplication): + def testInternalRef(self): + mw = QWidget() + w = QWidget() + ow = QWidget() + + topLayout = QGridLayout() + + # unique reference + self.assertEqual(getrefcount(w), 2) + self.assertEqual(getrefcount(ow), 2) + + topLayout.addWidget(w, 0, 0) + topLayout.addWidget(ow, 1, 0) + + # layout keep the referemce + self.assertEqual(getrefcount(w), 3) + self.assertEqual(getrefcount(ow), 3) + + mainLayout = QGridLayout() + + mainLayout.addLayout(topLayout, 1, 0, 1, 4) + + # the same reference + self.assertEqual(getrefcount(w), 3) + self.assertEqual(getrefcount(ow), 3) + + mw.setLayout(mainLayout) + + # now trasfer the ownership to mw + self.assertEqual(getrefcount(w), 3) + self.assertEqual(getrefcount(ow), 3) + + del mw + + # remove the ref and invalidate the widget + self.assertEqual(getrefcount(w), 2) + self.assertEqual(getrefcount(ow), 2) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qlayout_test.py b/sources/pyside6/tests/QtWidgets/qlayout_test.py new file mode 100644 index 000000000..f90627d0b --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qlayout_test.py @@ -0,0 +1,145 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import * +from PySide6.QtWidgets import * + +class MyLayout(QLayout): + def __init__(self, parent=None): + QLayout.__init__(self, parent) + self._list = [] + + def addItem(self, item): + self.add(item) + + def addWidget(self, widget): + self.add(QWidgetItem(widget)) + + def itemAt(self, index): + if index < len(self._list): + return self._list[index] + + return None + + def count(self): + return len(self._list) + + def add(self, item): + self._list.append(item) + +class MissingItemAtLayout(QLayout): + def __init__(self, parent=None): + QLayout.__init__(self, parent) + self._list = [] + + def addItem(self, item): + self.add(item) + + def addWidget(self, widget): + self.add(QWidgetItem(widget)) + + def count(self): + return len(self._list) + + def add(self, item): + self._list.append(item) + +#Test if a layout implemented in python, the QWidget.setLayout works +#fine because this implement som layout functions used in glue code of +#QWidget, then in c++ when call a virtual function this need call the QLayout +#function implemented in python + +class QLayoutTest(UsesQApplication): + def testOwnershipTransfer(self): + b = QPushButton("teste") + l = MyLayout() + + l.addWidget(b) + + self.assertEqual(sys.getrefcount(b), 2) + + w = QWidget() + + #transfer ref + w.setLayout(l) + + self.assertEqual(sys.getrefcount(b), 3) + + + def testReferenceTransfer(self): + b = QPushButton("teste") + l = QHBoxLayout() + + # keep ref + l.addWidget(b) + self.assertEqual(sys.getrefcount(b), 3) + + w = QWidget() + + # transfer ref + w.setLayout(l) + + self.assertEqual(sys.getrefcount(b), 3) + + # release ref + del w + + self.assertEqual(sys.getrefcount(b), 2) + + def testMissingFunctions(self): + w = QWidget() + b = QPushButton("test") + l = MissingItemAtLayout() + + l.addWidget(b) + + self.assertRaises(RuntimeError, w.setLayout, l) + + def testQFormLayout(self): + w = QWidget() + formLayout = QFormLayout() + spacer = QSpacerItem(100, 30) + formLayout.setItem(0, QFormLayout.SpanningRole, spacer) + w.setLayout(formLayout) + w.show() + QTimer.singleShot(10, w.close) + self.app.exec_() + del w + self.assertRaises(RuntimeError, spacer.isEmpty) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qlcdnumber_test.py b/sources/pyside6/tests/QtWidgets/qlcdnumber_test.py new file mode 100644 index 000000000..d4ed8e5dd --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qlcdnumber_test.py @@ -0,0 +1,50 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QApplication, QLCDNumber + +class QLCDNumberOverflow(unittest.TestCase): + '''Test case for unhandled overflow on QLCDNumber() numDigits argument (see bug #215).''' + + def setUp(self): + self.app = QApplication([]) + + def testnumDigitsOverflow(self): + # NOTE: PyQt4 raises TypeError, but boost.python raises OverflowError + self.assertRaises(OverflowError, QLCDNumber, 840835495615213080) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qlistwidget_test.py b/sources/pyside6/tests/QtWidgets/qlistwidget_test.py new file mode 100644 index 000000000..912b2e74b --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qlistwidget_test.py @@ -0,0 +1,94 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6 import QtWidgets, QtCore +from helper.usesqapplication import UsesQApplication + +class QListWidgetTest(UsesQApplication): + + def populateList(self, lst): + o = QtCore.QObject() + o.setObjectName("obj") + + item = QtWidgets.QListWidgetItem("item0") + item.setData(QtCore.Qt.UserRole, o) + #item._data = o + self.assertTrue(sys.getrefcount(o), 3) + self.assertTrue(sys.getrefcount(item), 2) + lst.addItem(item) + self.assertTrue(sys.getrefcount(item), 3) + + def checkCurrentItem(self, lst): + item = lst.currentItem() + self.assertTrue(sys.getrefcount(item), 3) + + def checkItemData(self, lst): + item = lst.currentItem() + o = item.data(QtCore.Qt.UserRole) + self.assertTrue(sys.getrefcount(o), 4) + self.assertEqual(o, item._data) + self.assertTrue(sys.getrefcount(o), 2) + + def testConstructorWithParent(self): + lst = QtWidgets.QListWidget() + self.populateList(lst) + self.checkCurrentItem(lst) + i = lst.item(0) + self.assertTrue(sys.getrefcount(i), 3) + + del lst + self.assertTrue(sys.getrefcount(i), 2) + del i + + def testIt(self): + lst = QtWidgets.QListWidget() + lst.show() + slot = lambda : lst.removeItemWidget(lst.currentItem()) + lst.addItem(QtWidgets.QListWidgetItem("foo")) + QtCore.QTimer.singleShot(0, slot) + QtCore.QTimer.singleShot(0, lst.close) + self.app.exec_() + self.assertEqual(lst.count(), 1) + + def testClear(self): + lst = QtWidgets.QListWidget() + lst.addItem("foo") + item = lst.item(0) + self.assertIsNone(lst.clear()) + self.assertRaises(RuntimeError, lambda: item.text()) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qlistwidgetitem_test.py b/sources/pyside6/tests/QtWidgets/qlistwidgetitem_test.py new file mode 100644 index 000000000..550d77b41 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qlistwidgetitem_test.py @@ -0,0 +1,62 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6 import QtWidgets + +from helper.usesqapplication import UsesQApplication + +class QListWidgetItemConstructor(UsesQApplication): + + def setUp(self): + super(QListWidgetItemConstructor, self).setUp() + self.widgetList = QtWidgets.QListWidget() + + def tearDown(self): + del self.widgetList + super(QListWidgetItemConstructor, self).tearDown() + + def testConstructorWithParent(self): + # Bug 235 - QListWidgetItem constructor not saving ownership + QtWidgets.QListWidgetItem(self.widgetList) + item = self.widgetList.item(0) + self.assertEqual(item.listWidget(), self.widgetList) + + def testConstructorWithNone(self): + # Bug 452 - QListWidgetItem() not casting NoneType to null correctly. + item = QtWidgets.QListWidgetItem(None, 123) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qmainwindow_test.py b/sources/pyside6/tests/QtWidgets/qmainwindow_test.py new file mode 100644 index 000000000..a25e4504b --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qmainwindow_test.py @@ -0,0 +1,118 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys +import unittest +import weakref + +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 PySide6 import QtWidgets +from PySide6 import QtCore + +from helper.usesqapplication import UsesQApplication + +class MainWindow(QtWidgets.QMainWindow): + def __init__(self): + QtWidgets.QMainWindow.__init__(self) + + self.createToolbar() + + def createToolbar(self): + pointerButton = QtWidgets.QToolButton() + pointerToolbar = self.addToolBar("Pointer type") + pointerToolbar.addWidget(pointerButton) + +class MyButton(QtWidgets.QPushButton): + def __init__(self, parent=None): + QtWidgets.QPushButton.__init__(self) + self._called = False + + def myCallback(self): + self._called = True + + +class TestMainWindow(UsesQApplication): + + def testCreateToolbar(self): + w = MainWindow() + w.show() + QtCore.QTimer.singleShot(1000, self.app.quit) + self.app.exec_() + + def objDel(self, obj): + self.app.quit() + + def testRefCountToNull(self): + w = QtWidgets.QMainWindow() + c = QtWidgets.QWidget() + self.assertEqual(sys.getrefcount(c), 2) + w.setCentralWidget(c) + self.assertEqual(sys.getrefcount(c), 3) + wr = weakref.ref(c, self.objDel) + w.setCentralWidget(None) + c = None + self.app.exec_() + + def testRefCountToAnother(self): + w = QtWidgets.QMainWindow() + c = QtWidgets.QWidget() + self.assertEqual(sys.getrefcount(c), 2) + w.setCentralWidget(c) + self.assertEqual(sys.getrefcount(c), 3) + + c2 = QtWidgets.QWidget() + w.setCentralWidget(c2) + self.assertEqual(sys.getrefcount(c2), 3) + + wr = weakref.ref(c, self.objDel) + w.setCentralWidget(None) + c = None + + self.app.exec_() + + def testSignalDisconect(self): + w = QtWidgets.QMainWindow() + b = MyButton("button") + b.clicked.connect(b.myCallback) + w.setCentralWidget(b) + + b = MyButton("button") + b.clicked.connect(b.myCallback) + w.setCentralWidget(b) + + b.click() + self.assertEqual(b._called, True) + + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qmenu_test.py b/sources/pyside6/tests/QtWidgets/qmenu_test.py new file mode 100644 index 000000000..40cae96b1 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qmenu_test.py @@ -0,0 +1,92 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QMenu +from PySide6.QtGui import QKeySequence, QIcon +from PySide6.QtCore import SLOT + +from helper.usesqapplication import UsesQApplication + +class QMenuAddAction(UsesQApplication): + + def setUp(self): + super(QMenuAddAction, self).setUp() + self.menu = QMenu() + + def tearDown(self): + del self.menu + super(QMenuAddAction, self).tearDown() + + def testAddActionWithoutKeySequenceCallable(self): + # bug #280 + action = self.menu.addAction(self.app.tr('aaa'), lambda : 1) + + def testAddActionKeySequenceCallable(self): + # bug #228 + action = self.menu.addAction(self.app.tr('aaa'), lambda : 1, + QKeySequence(self.app.tr('Ctrl+O'))) + + def testAddActionKeySequenceSlot(self): + action = self.menu.addAction('Quit', self.app, SLOT('quit()'), + QKeySequence('Ctrl+O')) + +class QMenuAddActionWithIcon(UsesQApplication): + + def setUp(self): + super(QMenuAddActionWithIcon, self).setUp() + self.menu = QMenu() + self.icon = QIcon() + + def tearDown(self): + del self.menu + del self.icon + super(QMenuAddActionWithIcon, self).tearDown() + + def testAddActionWithoutKeySequenceCallable(self): + # bug #280 + action = self.menu.addAction(self.icon, self.app.tr('aaa'), lambda : 1) + + def testAddActionKeySequenceCallable(self): + # bug #228 + action = self.menu.addAction(self.icon, self.app.tr('aaa'), lambda : 1, + QKeySequence(self.app.tr('Ctrl+O'))) + + def testAddActionKeySequenceSlot(self): + action = self.menu.addAction(self.icon, 'Quit', self.app, SLOT('quit()'), + QKeySequence('Ctrl+O')) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qmenuadd_test.py b/sources/pyside6/tests/QtWidgets/qmenuadd_test.py new file mode 100644 index 000000000..c74ba8adf --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qmenuadd_test.py @@ -0,0 +1,58 @@ +# -*- 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$ +## +############################################################################# + +''' Test the QMenu.addAction() method''' + +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 PySide6 import QtWidgets + +from helper.usesqapplication import UsesQApplication + +class QMenuAddAction(UsesQApplication): + + def openFile(self, *args): + self.arg = args + + def testQMenuAddAction(self): + fileMenu = QtWidgets.QMenu("&File") + + addNewAction = fileMenu.addAction("&Open...", self.openFile) + addNewAction.trigger() + self.assertEqual(self.arg, ()) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qobject_mi_test.py b/sources/pyside6/tests/QtWidgets/qobject_mi_test.py new file mode 100644 index 000000000..2bd6947af --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qobject_mi_test.py @@ -0,0 +1,76 @@ +# -*- 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$ +## +############################################################################# + +'''Test cases for multiple inheritance from 2 QObjects''' + +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 PySide6.QtCore import QObject +from PySide6.QtGui import * +from PySide6.QtWidgets import * + +from helper.usesqapplication import UsesQApplication + +class WidgetValidator(QWidget, QIntValidator): + def __init__(self, parent=None): + QWidget.__init__(self, parent) + QIntValidator.__init__(self, parent) + + +class DoubleQObjectInheritanceTest(UsesQApplication): + + def testDouble(self): + '''Double inheritance from QObject classes''' + + obj = WidgetValidator() + + #QObject methods + obj.setObjectName('aaaa') + self.assertEqual(obj.objectName(), 'aaaa') + + #QWidget methods + obj.setVisible(False) + self.assertFalse(obj.isVisible()) + + #QIntValidator methods + state, string, number = obj.validate('aaaa', 0) + self.assertEqual(state, QValidator.Invalid) + state, string, number = obj.validate('33', 0) + self.assertEqual(state, QValidator.Acceptable) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qpen_test.py b/sources/pyside6/tests/QtWidgets/qpen_test.py new file mode 100644 index 000000000..6bff44740 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qpen_test.py @@ -0,0 +1,79 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import Qt, QTimer +from PySide6.QtGui import QPen, QPainter +from PySide6.QtWidgets import QWidget + +class Painting(QWidget): + def __init__(self): + QWidget.__init__(self) + self.penFromEnum = None + self.penFromInteger = None + + def paintEvent(self, event): + painter = QPainter(self) + painter.setPen(Qt.NoPen) + self.penFromEnum = painter.pen() + painter.setPen(int(Qt.NoPen)) + self.penFromInteger = painter.pen() + + +class QPenTest(UsesQApplication): + + def testCtorWithCreatedEnums(self): + '''A simple case of QPen creation using created enums.''' + width = 0 + style = Qt.PenStyle(0) + cap = Qt.PenCapStyle(0) + join = Qt.PenJoinStyle(0) + pen = QPen(Qt.blue, width, style, cap, join) + + def testSetPenWithPenStyleEnum(self): + '''Calls QPainter.setPen with both enum and integer. Bug #511.''' + w = Painting() + w.show() + QTimer.singleShot(1000, self.app.quit) + self.app.exec_() + self.assertEqual(w.penFromEnum.style(), Qt.NoPen) + self.assertEqual(w.penFromInteger.style(), Qt.SolidLine) + + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qpicture_test.py b/sources/pyside6/tests/QtWidgets/qpicture_test.py new file mode 100644 index 000000000..704a22d75 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qpicture_test.py @@ -0,0 +1,71 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import QTimer +from PySide6.QtGui import QPicture, QPainter +from PySide6.QtWidgets import QWidget + +class MyWidget(QWidget): + def paintEvent(self, e): + p = QPainter(self) + p.drawPicture(0, 0, self._picture) + self._app.quit() + +class QPictureTest(UsesQApplication): + def testFromData(self): + picture = QPicture() + painter = QPainter() + painter.begin(picture) + painter.drawEllipse(10,20, 80,70) + painter.end() + + data = picture.data() + picture2 = QPicture() + picture2.setData(data) + + self.assertEqual(picture2.data(), picture.data()) + + w = MyWidget() + w._picture = picture2 + w._app = self.app + + QTimer.singleShot(300, w.show) + self.app.exec_() + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qpixmap_constructor.py b/sources/pyside6/tests/QtWidgets/qpixmap_constructor.py new file mode 100644 index 000000000..4502885b7 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qpixmap_constructor.py @@ -0,0 +1,285 @@ +#!/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 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 PySide6.QtGui import QPixmap +from PySide6.QtWidgets import QLabel + +from helper.usesqapplication import UsesQApplication + +xpm = [ + "27 22 206 2", + " c None", + ". c #FEFEFE", + "+ c #FFFFFF", + "@ c #F9F9F9", + "# c #ECECEC", + "$ c #D5D5D5", + "% c #A0A0A0", + "& c #767676", + "* c #525252", + "= c #484848", + "- c #4E4E4E", + "; c #555555", + "> c #545454", + ", c #5A5A5A", + "' c #4B4B4B", + ") c #4A4A4A", + "! c #4F4F4F", + "~ c #585858", + "{ c #515151", + "] c #4C4C4C", + "^ c #B1B1B1", + "/ c #FCFCFC", + "( c #FDFDFD", + "_ c #C1C1C1", + ": c #848484", + "< c #616161", + "[ c #5E5E5E", + "} c #CECECE", + "| c #E2E2E2", + "1 c #E4E4E4", + "2 c #DFDFDF", + "3 c #D2D2D2", + "4 c #D8D8D8", + "5 c #D4D4D4", + "6 c #E6E6E6", + "7 c #F1F1F1", + "8 c #838383", + "9 c #8E8E8E", + "0 c #8F8F8F", + "a c #CBCBCB", + "b c #CCCCCC", + "c c #E9E9E9", + "d c #F2F2F2", + "e c #EDEDED", + "f c #B5B5B5", + "g c #A6A6A6", + "h c #ABABAB", + "i c #BBBBBB", + "j c #B0B0B0", + "k c #EAEAEA", + "l c #6C6C6C", + "m c #BCBCBC", + "n c #F5F5F5", + "o c #FAFAFA", + "p c #B6B6B6", + "q c #F3F3F3", + "r c #CFCFCF", + "s c #FBFBFB", + "t c #CDCDCD", + "u c #DDDDDD", + "v c #999999", + "w c #F0F0F0", + "x c #2B2B2B", + "y c #C3C3C3", + "z c #A4A4A4", + "A c #D7D7D7", + "B c #E7E7E7", + "C c #6E6E6E", + "D c #9D9D9D", + "E c #BABABA", + "F c #AEAEAE", + "G c #898989", + "H c #646464", + "I c #BDBDBD", + "J c #CACACA", + "K c #2A2A2A", + "L c #212121", + "M c #B7B7B7", + "N c #F4F4F4", + "O c #737373", + "P c #828282", + "Q c #4D4D4D", + "R c #000000", + "S c #151515", + "T c #B2B2B2", + "U c #D6D6D6", + "V c #D3D3D3", + "W c #2F2F2F", + "X c #636363", + "Y c #A1A1A1", + "Z c #BFBFBF", + "` c #E0E0E0", + " . c #6A6A6A", + ".. c #050505", + "+. c #A3A3A3", + "@. c #202020", + "#. c #5F5F5F", + "$. c #B9B9B9", + "%. c #C7C7C7", + "&. c #D0D0D0", + "*. c #3E3E3E", + "=. c #666666", + "-. c #DBDBDB", + ";. c #424242", + ">. c #C2C2C2", + ",. c #1A1A1A", + "'. c #2C2C2C", + "). c #F6F6F6", + "!. c #AAAAAA", + "~. c #DCDCDC", + "{. c #2D2D2D", + "]. c #2E2E2E", + "^. c #A7A7A7", + "/. c #656565", + "(. c #333333", + "_. c #464646", + ":. c #C4C4C4", + "<. c #B8B8B8", + "[. c #292929", + "}. c #979797", + "|. c #EFEFEF", + "1. c #909090", + "2. c #8A8A8A", + "3. c #575757", + "4. c #676767", + "5. c #C5C5C5", + "6. c #7A7A7A", + "7. c #797979", + "8. c #989898", + "9. c #EEEEEE", + "0. c #707070", + "a. c #C8C8C8", + "b. c #111111", + "c. c #AFAFAF", + "d. c #474747", + "e. c #565656", + "f. c #E3E3E3", + "g. c #494949", + "h. c #5B5B5B", + "i. c #222222", + "j. c #353535", + "k. c #D9D9D9", + "l. c #0A0A0A", + "m. c #858585", + "n. c #E5E5E5", + "o. c #0E0E0E", + "p. c #9A9A9A", + "q. c #6F6F6F", + "r. c #868686", + "s. c #060606", + "t. c #1E1E1E", + "u. c #E8E8E8", + "v. c #A5A5A5", + "w. c #0D0D0D", + "x. c #030303", + "y. c #272727", + "z. c #131313", + "A. c #1F1F1F", + "B. c #757575", + "C. c #F7F7F7", + "D. c #414141", + "E. c #080808", + "F. c #6B6B6B", + "G. c #313131", + "H. c #C0C0C0", + "I. c #C9C9C9", + "J. c #0B0B0B", + "K. c #232323", + "L. c #434343", + "M. c #3D3D3D", + "N. c #282828", + "O. c #7C7C7C", + "P. c #252525", + "Q. c #3A3A3A", + "R. c #F8F8F8", + "S. c #1B1B1B", + "T. c #949494", + "U. c #3B3B3B", + "V. c #242424", + "W. c #383838", + "X. c #6D6D6D", + "Y. c #818181", + "Z. c #939393", + "`. c #9E9E9E", + " + c #929292", + ".+ c #7D7D7D", + "++ c #ADADAD", + "@+ c #DADADA", + "#+ c #919191", + "$+ c #E1E1E1", + "%+ c #BEBEBE", + "&+ c #ACACAC", + "*+ c #9C9C9C", + "=+ c #B3B3B3", + "-+ c #808080", + ";+ c #A8A8A8", + ">+ c #393939", + ",+ c #747474", + "'+ c #7F7F7F", + ")+ c #D1D1D1", + "!+ c #606060", + "~+ c #5C5C5C", + "{+ c #686868", + "]+ c #7E7E7E", + "^+ c #787878", + "/+ c #595959", + ". . . + @ # $ % & * = - ; > , ' ) ! ~ { ] ^ / . . + + ", + ". ( + _ : < [ & } | 1 2 $ 3 4 5 3 6 7 + + 8 9 + . + . ", + ". + 0 9 a ( 3 a b c d e c f g h i g j $ k + l m + . + ", + "+ 2 8 n o p | ( q r s . # t + + + u ^ v e w + x + + + ", + "+ y z . @ A k B 7 n + ( s | p 8 C D 2 E 4 + + F G + . ", + "# H I $ J G K L - M N . 2 O P Q R R S T U s s V W j + ", + "X Y Z @ o ` _ g ...+.( 4 @.#.m G $.%.7 &.X *.=.-.;.&.", + "Q >.C ,.'.} e + ).!.k + . + + . ~.{.> ].x f 7 ^./.k (.", + "_.:.4 @ <.[.}.|.1.2.+ + + >.} 4 B + ( @ _ 3.4.5.6.r 7.", + "3.8.9.~ 0.+ a.Q b.+ + c.d.#.=.$ |.b #.e.z ^ ; ^. .f.g.", + "-.h.+ i.S M + # p j.% n 9.5.k.H l.m.V ^.n.o.M + M p.q.", + "7 r.N s.1.R t.<.|.| u.v.~ w.x.E + s y.z.A.B.C.+ 5 D.q ", + ").p.2 E.0.9 F.%.O {._ @.+ + i { [ i.G.H.P I.+ s q.} + ", + ").p.6 J.R b.K.L.M.A.! b.g.K [.R M k + N.I + + >.O.+ . ", + ").8.9.N.P...R R R R E.t.W n.+ Q.R.6 @.| + . + S.+ + . ", + "n }.w T.U.B.<.i.@ Y + + U.+ c u V.= B B 7 u.W.c + . + ", + "N T.# + }.X.Y.,.8.F.8 Z.[.`. +.+}.4 ++@+O.< ~.+ ( . + ", + "d #+1 + _ ~.u.$+b $.y @+| $+%+I.&+k.h W +.9.+ ( . + . ", + "w 0 |.*+. >.<.=+++++p a.p -+;+5.k.>+,+@ + . . + . + + ", + "q '+9.R.^ I.t b %.I.)+4 $+n.I.,+ .|.+ . . . + . + + + ", + ". p !+( + + + + + + E 0. .-+8.f.+ + . . + + . + + + + ", + ". ( A ~+{+]+^+l > /+D f.c q . + . . + + . + + + + + + " +] + +class QStringSequenceTest(UsesQApplication): + def testQPixmapConstructor(self): + label = QLabel() + pixmap1 = QPixmap(xpm) + self.assertFalse(pixmap1.isNull()) + self.assertEqual(pixmap1.width(), 27) + self.assertEqual(pixmap1.height(), 22) + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qpushbutton_test.py b/sources/pyside6/tests/QtWidgets/qpushbutton_test.py new file mode 100644 index 000000000..0c73670a5 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qpushbutton_test.py @@ -0,0 +1,75 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QPushButton, QMenu, QWidget +from PySide6.QtCore import QTimer + +class MyWidget(QWidget): + def __init__(self): + QWidget.__init__(self) + + m = QMenu(self) + b = QPushButton("Hello", self) + b.setMenu(m) + + +class QPushButtonTest(UsesQApplication): + def createMenu(self, button): + m = QMenu() + button.setMenu(m) + + def testSetMenu(self): + w = MyWidget() + w.show() + + timer = QTimer.singleShot(100, self.app.quit) + self.app.exec_() + + def buttonCb(self, checked): + self._clicked = True + + def testBoolinSignal(self): + b = QPushButton() + b.setCheckable(True) + self._clicked = False + b.toggled[bool].connect(self.buttonCb) + b.toggle() + self.assertTrue(self._clicked) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qshortcut_test.py b/sources/pyside6/tests/QtWidgets/qshortcut_test.py new file mode 100644 index 000000000..8f9c8a465 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qshortcut_test.py @@ -0,0 +1,83 @@ +# -*- 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$ +## +############################################################################# + +''' Test the QShortcut constructor''' + +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 PySide6.QtCore import Qt, QTimer +from PySide6.QtGui import QKeySequence, QShortcut +from PySide6.QtWidgets import QApplication, QWidget + +class Foo(QWidget): + def __init__(self): + QWidget.__init__(self) + self.ok = False + self.copy = False + + def slot_of_foo(self): + self.ok = True + + def slot_of_copy(self): + self.copy = True + +class MyShortcut(QShortcut): + def __init__(self, keys, wdg, slot): + QShortcut.__init__(self, keys, wdg, slot) + + def emit_signal(self): + self.activated.emit() + +class QAppPresence(unittest.TestCase): + + def testQShortcut(self): + self.qapp = QApplication([]) + f = Foo() + + self.sc = MyShortcut(QKeySequence(Qt.Key_Return), f, f.slot_of_foo) + self.scstd = MyShortcut(QKeySequence.Copy, f, f.slot_of_copy) + QTimer.singleShot(0, self.init); + self.qapp.exec_() + self.assertEqual(f.ok, True) + self.assertEqual(f.copy, True) + + def init(self): + self.sc.emit_signal(); + self.scstd.emit_signal(); + self.qapp.quit() + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qsplitter_test.py b/sources/pyside6/tests/QtWidgets/qsplitter_test.py new file mode 100644 index 000000000..413bd7a30 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qsplitter_test.py @@ -0,0 +1,51 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QSplitter + +from helper.usesqapplication import UsesQApplication + +class QSplitterTest(UsesQApplication): + + def testGetRange(self): + splitter = QSplitter() + _min, _max = splitter.getRange(0) + self.assertTrue(isinstance(_min, int)) + self.assertTrue(isinstance(_max, int)) + +if __name__ == "__main__": + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qstandarditemmodel_test.py b/sources/pyside6/tests/QtWidgets/qstandarditemmodel_test.py new file mode 100644 index 000000000..b252982e0 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qstandarditemmodel_test.py @@ -0,0 +1,106 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtGui import QStandardItemModel, QStandardItem +from PySide6.QtWidgets import QWidget +import shiboken6 as shiboken + +from helper.usesqapplication import UsesQApplication + + +class QStandardItemModelTest(UsesQApplication): + + def setUp(self): + super(QStandardItemModelTest, self).setUp() + self.window = QWidget() + self.model = QStandardItemModel(0, 3, self.window) + + def tearDown(self): + del self.window + del self.model + super(QStandardItemModelTest, self).tearDown() + + def testInsertRow(self): + # bug #227 + self.model.insertRow(0) + + def testClear(self): + + model = QStandardItemModel() + root = model.invisibleRootItem() + model.clear() + self.assertFalse(shiboken.isValid(root)) + + +class QStandardItemModelRef(UsesQApplication): + def testRefCount(self): + model = QStandardItemModel(5, 5) + items = [] + for r in range(5): + row = [] + for c in range(5): + row.append(QStandardItem("%d,%d" % (r,c)) ) + self.assertEqual(sys.getrefcount(row[c]), 2) + + model.insertRow(r, row) + + for c in range(5): + ref_after = sys.getrefcount(row[c]) + # check if the ref count was incremented after insertRow + self.assertEqual(ref_after, 3) + + items.append(row) + row = None + + for r in range(3): + my_row = model.takeRow(0) + my_row = None + for c in range(5): + # only rest 1 reference + self.assertEqual(sys.getrefcount(items[r][c]), 2) + + my_i = model.item(0,0) + # ref(my_i) + parent_ref + items list ref + self.assertEqual(sys.getrefcount(my_i), 4) + + model.clear() + # ref(my_i) + self.assertEqual(sys.getrefcount(my_i), 3) + + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qstring_qkeysequence_test.py b/sources/pyside6/tests/QtWidgets/qstring_qkeysequence_test.py new file mode 100644 index 000000000..3445db447 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qstring_qkeysequence_test.py @@ -0,0 +1,67 @@ +#!/usr/bin/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$ +## +############################################################################# + +'''Tests conversions of QString to and from QKeySequence.''' + +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 PySide6.QtGui import QAction, QKeySequence + + +class QStringQKeySequenceTest(UsesQApplication): + '''Tests conversions of QString to and from QKeySequence.''' + + def testQStringFromQKeySequence(self): + '''Creates a QString from a QKeySequence.''' + keyseq = 'Ctrl+A' + a = QKeySequence(keyseq) + self.assertEqual(a, keyseq) + + def testPythonStringAsQKeySequence(self): + '''Passes a Python string to an argument expecting a QKeySequence.''' + keyseq = 'Ctrl+A' + action = QAction(None) + action.setShortcut(keyseq) + shortcut = action.shortcut() + self.assertTrue(isinstance(shortcut, QKeySequence)) + self.assertEqual(shortcut.toString(), keyseq) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qstyle_test.py b/sources/pyside6/tests/QtWidgets/qstyle_test.py new file mode 100644 index 000000000..5d86e3d71 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qstyle_test.py @@ -0,0 +1,98 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import sys +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 PySide6.QtGui import QWindow +from PySide6.QtWidgets import (QApplication, QFontComboBox, QLabel, QProxyStyle, + QStyleFactory, QWidget) + +class ProxyStyle(QProxyStyle): + + def __init__(self, style): + QProxyStyle.__init__(self, style) + self.polished = 0 + + def polish(self, widget): + self.polished = self.polished + 1 + super(ProxyStyle, self).polish(widget) + + +class SetStyleTest(UsesQApplication): + '''Tests setting the same QStyle for all objects in a UI hierarchy.''' + + def testSetStyle(self): + '''All this test have to do is not break with some invalid Python wrapper.''' + + def setStyleHelper(widget, style): + widget.setStyle(style) + widget.setPalette(style.standardPalette()) + for child in widget.children(): + if isinstance(child, QWidget): + setStyleHelper(child, style) + + container = QWidget() + # QFontComboBox is used because it has an QLineEdit created in C++ inside it, + # and if the QWidget.setStyle(style) steals the ownership of the style + # for the C++ originated widget everything will break. + fontComboBox = QFontComboBox(container) + label = QLabel(container) + label.setText('Label') + style = QStyleFactory.create(QStyleFactory.keys()[0]) + setStyleHelper(container, style) + + def testSetProxyStyle(self): + label = QLabel("QtWidgets/ProxyStyle test") + baseStyle = QStyleFactory.create(QApplication.instance().style().objectName()) + self.assertTrue(baseStyle) + proxyStyle = ProxyStyle(baseStyle) + label.setStyle(proxyStyle) + label.show() + while not label.windowHandle().isExposed(): + 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/pyside6/tests/QtWidgets/qtableview_test.py b/sources/pyside6/tests/QtWidgets/qtableview_test.py new file mode 100644 index 000000000..a6117f180 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qtableview_test.py @@ -0,0 +1,50 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtCore import QAbstractTableModel +from PySide6.QtWidgets import QTableWidget +from helper.usesqapplication import UsesQApplication + +class QPenTest(UsesQApplication): + + def testItemModel(self): + tv = QTableWidget() + + self.assertEqual(type(tv.model()), QAbstractTableModel) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qtabwidget_test.py b/sources/pyside6/tests/QtWidgets/qtabwidget_test.py new file mode 100644 index 000000000..b5f5bb463 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qtabwidget_test.py @@ -0,0 +1,62 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import * +from helper.timedqapplication import TimedQApplication + +def makeBug643(tab): + button = QPushButton('Foo') + tab.insertTab(0, button, 'Foo') + +class RemoveTabMethod(TimedQApplication): + def setUp(self): + TimedQApplication.setUp(self) + self.tab = QTabWidget() + + def tearDown(self): + del self.tab + TimedQApplication.tearDown(self) + + + def testRemoveTabPresence(self): + self.assertTrue(getattr(self.tab, 'removeTab')) + + def testInsertTab(self): + makeBug643(self.tab) + self.assertEqual(self.tab.count(), 1) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qtabwidgetclear_test.py b/sources/pyside6/tests/QtWidgets/qtabwidgetclear_test.py new file mode 100644 index 000000000..6177c2452 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qtabwidgetclear_test.py @@ -0,0 +1,69 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QMainWindow, QTabWidget, QTextEdit, QSplitter +from helper.usesqapplication import UsesQApplication + +class TabWidgetClear(QMainWindow): + def __init__(self): + QMainWindow.__init__(self) + self.tabWidget = QTabWidget(self) + self.setCentralWidget(self.tabWidget) + self.editBox = QTextEdit(self) + self.tabWidget.addTab(self.getSplitter(), 'Test') + + def getSplitter(self): + splitter = QSplitter() + splitter.addWidget(self.editBox) + return splitter + + def toggle(self): + self.tabWidget.clear() + self.getSplitter() + +class TestTabWidgetClear(UsesQApplication): + + def testClear(self): + self.window = TabWidgetClear() + self.window.show() + try: + self.window.toggle() + except RuntimeError as e: + # This should never happened, PYSIDE-213 + raise e + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qtextedit_signal_test.py b/sources/pyside6/tests/QtWidgets/qtextedit_signal_test.py new file mode 100644 index 000000000..78507a61a --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qtextedit_signal_test.py @@ -0,0 +1,72 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6 import QtCore, QtWidgets +from helper.usesqapplication import UsesQApplication + + +class MyWindow(QtWidgets.QMainWindow): + appendText = QtCore.Signal(str) + + @QtCore.Slot() + def onButtonPressed(self): + self.appendText.emit("PySide") + + def __init__(self, parent=None): + super(MyWindow, self).__init__(parent) + + self.textEdit = QtWidgets.QTextEdit() + self.btn = QtWidgets.QPushButton("ClickMe") + self.btn.clicked.connect(self.onButtonPressed) + self.appendText.connect(self.textEdit.append) + + def start(self): + self.btn.click() + + def text(self): + return self.textEdit.toPlainText() + + +class testSignalWithCPPSlot(UsesQApplication): + + def testEmission(self): + w = MyWindow() + w.start() + self.assertEqual(w.text(), "PySide") + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qtextedit_test.py b/sources/pyside6/tests/QtWidgets/qtextedit_test.py new file mode 100644 index 000000000..80ca9bb82 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qtextedit_test.py @@ -0,0 +1,67 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''Test cases for QTextEdit and ownership problems.''' + +import os +import sys +from sys import getrefcount +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 PySide6.QtWidgets import QTextEdit + +from helper.usesqapplication import UsesQApplication + +class DontTouchReference(UsesQApplication): + '''Check if the QTextTable returned by QTextCursor.insertTable() is not + referenced by the QTextCursor that returns it.''' + + def setUp(self): + super(DontTouchReference, self).setUp() + self.editor = QTextEdit() + self.cursor = self.editor.textCursor() + self.table = self.cursor.insertTable(1, 1) + + def testQTextTable(self): + # methods which return QTextTable should not increment its reference + self.assertEqual(getrefcount(self.table), 2) + f = self.cursor.currentFrame() + del f + self.assertEqual(getrefcount(self.table), 2) + # destroying the cursor should not raise any "RuntimeError: internal + # C++ object already deleted." when accessing the QTextTable + del self.cursor + self.assertEqual(getrefcount(self.table), 2) + cell = self.table.cellAt(0, 0) + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qtoolbar_test.py b/sources/pyside6/tests/QtWidgets/qtoolbar_test.py new file mode 100644 index 000000000..95ef3dc83 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qtoolbar_test.py @@ -0,0 +1,69 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''Test cases for QToolbar''' + +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 PySide6.QtGui import QAction +from PySide6.QtWidgets import QToolBar, QMainWindow + +from helper.usesqapplication import UsesQApplication + +class AddActionText(UsesQApplication): + '''Test case for calling QToolbar.addAction passing a text''' + + def setUp(self): + #Acquire resources + super(AddActionText, self).setUp() + self.window = QMainWindow() + self.toolbar = QToolBar() + self.window.addToolBar(self.toolbar) + + def tearDown(self): + #Release resources + super(AddActionText, self).tearDown() + del self.toolbar + del self.window + + def testText(self): + #QToolBar.addAction(text) - add a QToolButton + self.toolbar.addAction('aaaa') + self.assertEqual(len(self.toolbar.actions()), 1) + action = self.toolbar.actions()[0] + self.assertTrue(isinstance(action, QAction)) + self.assertEqual(action.text(), 'aaaa') + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qtoolbox_test.py b/sources/pyside6/tests/QtWidgets/qtoolbox_test.py new file mode 100644 index 000000000..1ad8fdc6d --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qtoolbox_test.py @@ -0,0 +1,65 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtGui import QIcon +from PySide6.QtWidgets import QToolBox, QWidget + +from helper.usesqapplication import UsesQApplication + +class OwnershipControl(UsesQApplication): + + def setUp(self): + super(OwnershipControl, self).setUp() + self.toolbox = QToolBox() + + def tearDown(self): + del self.toolbox + super(OwnershipControl, self).tearDown() + + def testAddItem(self): + # Was losing ownership of the widget. + index = self.toolbox.addItem(QWidget(), 'item') + item = self.toolbox.widget(index) + self.assertTrue(isinstance(item, QWidget)) + + def testAddItemWithIcon(self): + index = self.toolbox.addItem(QWidget(), QIcon(), 'item') + item = self.toolbox.widget(index) + self.assertTrue(isinstance(item, QWidget)) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qtreeview_test.py b/sources/pyside6/tests/QtWidgets/qtreeview_test.py new file mode 100644 index 000000000..d9ad48227 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qtreeview_test.py @@ -0,0 +1,102 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtGui import QStandardItemModel +from PySide6.QtWidgets import (QWidget, QTreeView, QVBoxLayout, + QStyledItemDelegate, QHeaderView) +from PySide6.QtCore import Qt +from helper.usesqapplication import UsesQApplication + +class Widget(QWidget): + def __init__(self, parent=None): + QWidget.__init__(self, parent) + self.treeView = QTreeView(self) + layout = QVBoxLayout() + layout.addWidget(self.treeView) + self.setLayout(layout) + self.treeView.setModel(QStandardItemModel()) + + self.treeView.model().setHorizontalHeaderLabels(('3', '1', '5')) + +class QWidgetTest(UsesQApplication): + + def testDelegates(self): + widget = Widget() + t = widget.treeView + + # When calling setItemDelegateForColumn using a separate variable + # for the second argument (QAbstractItemDelegate), there was no problem + # on keeping the reference to this object, since the variable was kept + # alive (case A) + # Contrary, when instantiating this argument on the function call + # Using QStyledItemDelegate inside the call the reference of the + # object was lost, causing a segfault. (case B) + + # Case A + d = QStyledItemDelegate() + # Using QStyledItemDelegate from a variable so we keep the reference alive + # and we encounter no segfault. + t.setItemDelegateForColumn(0, d) + # This raised the Segmentation Fault too, because manually destroying + # the object caused a missing refrence. + del d + + # Getting the delegates + a = t.itemDelegateForColumn(0) + self.assertIsInstance(a, QStyledItemDelegate) + + # Case B + t.setItemDelegateForColumn(1, QStyledItemDelegate()) + + # Getting the delegates + b = t.itemDelegateForColumn(1) + self.assertIsInstance(b, QStyledItemDelegate) + + # Test for Rows + t.setItemDelegateForRow(0, QStyledItemDelegate()) + self.assertIsInstance(t.itemDelegateForRow(0), QStyledItemDelegate) + + # Test for general delegate + t.setItemDelegate(QStyledItemDelegate()) + self.assertIsInstance(t.itemDelegate(), QStyledItemDelegate) + + def testHeader(self): + tree = QTreeView() + tree.setHeader(QHeaderView(Qt.Horizontal)) + self.assertIsNotNone(tree.header()) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qtreewidget_test.py b/sources/pyside6/tests/QtWidgets/qtreewidget_test.py new file mode 100644 index 000000000..23ee01919 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qtreewidget_test.py @@ -0,0 +1,70 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import QTreeWidget, QTreeWidgetItem, QPushButton +from helper.usesqapplication import UsesQApplication + +class QTreeWidgetTest(UsesQApplication): + + # PYSIDE-73: + # There was a problem when adding items to a QTreeWidget + # when the Widget was being build on the method call instead + # of as a separate variable. + # The problem was there was not ownership transfer, so the + # QTreeWidget did not own the QWidget element + def testSetItemWidget(self): + + treeWidget = QTreeWidget() + treeWidget.setColumnCount(2) + + item = QTreeWidgetItem(['text of column 0', '']) + treeWidget.insertTopLevelItem(0, item) + # Adding QPushButton inside the method + treeWidget.setItemWidget(item, 1, + QPushButton('Push button on column 1')) + + # Getting the widget back + w = treeWidget.itemWidget(treeWidget.itemAt(0,1), 1) + self.assertIsInstance(w, QPushButton) + + p = QPushButton('New independent button') + # Adding QPushButton object from variable + treeWidget.setItemWidget(item, 0, p) + w = treeWidget.itemWidget(treeWidget.itemAt(0,0), 0) + self.assertIsInstance(w, QPushButton) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qtreewidgetitem_test.py b/sources/pyside6/tests/QtWidgets/qtreewidgetitem_test.py new file mode 100644 index 000000000..9edd6bee6 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qtreewidgetitem_test.py @@ -0,0 +1,74 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2020 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide6. +## +## $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$ +## +############################################################################# + +""" +Unit tests for QTreeWidgetItem +------------------------------ + +This test is actually meant for all types which provide `tp_richcompare` +but actually define something without providing `==` or `!=` operators. +QTreeWidgetItem for instance defines `<` only. + +PYSIDE-74: We redirect to type `object`s handling which is anyway the default + when `tp_richcompare` is undefined. +""" + +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 PySide6 import QtCore, QtWidgets + + +class QTreeWidgetItemTest(unittest.TestCase): + def testClass(self): + app = QtWidgets.QApplication([]) + treewidget = QtWidgets.QTreeWidget() + item = QtWidgets.QTreeWidgetItem(["Words and stuff"]) + item2 = QtWidgets.QTreeWidgetItem(["More words!"]) + treewidget.insertTopLevelItem(0, item) + + dummy_list = ["Numbers", "Symbols", "Spam"] + self.assertFalse(item in dummy_list) + self.assertTrue(item not in dummy_list) + self.assertFalse(item == item2) + self.assertTrue(item != item2) + treewidget.show() + QtCore.QTimer.singleShot(500, app.quit) + app.exec_() + + +if __name__ == "__main__": + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qvariant_test.py b/sources/pyside6/tests/QtWidgets/qvariant_test.py new file mode 100644 index 000000000..51ee27ec0 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qvariant_test.py @@ -0,0 +1,83 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtWidgets import (QApplication, QComboBox, QGraphicsScene, + QGraphicsRectItem) + +from helper.usesqapplication import UsesQApplication + +class MyDiagram(QGraphicsScene): + pass + +class MyItem(QGraphicsRectItem): + def itemChange(self, change, value): + return value; + +class Sequence(object): + # Having the __getitem__ method on a class transform the Python + # type to a PySequence. + # Before the patch: aa75437f9119d997dd290471ac3e2cc88ca88bf1 + # "Fix QVariant conversions when using PySequences" + # one could not use an object from this class, because internally + # we were requiring that the PySequence was finite. + def __getitem__(self, key): + raise IndexError() + +class QGraphicsSceneOnQVariantTest(UsesQApplication): + """Test storage ot QGraphicsScene into QVariants""" + def setUp(self): + super(QGraphicsSceneOnQVariantTest, self).setUp() + self.s = MyDiagram() + self.i = MyItem() + self.combo = QComboBox() + + def tearDown(self): + del self.s + del self.i + del self.combo + super(QGraphicsSceneOnQVariantTest, self).tearDown() + + def testIt(self): + self.s.addItem(self.i) + self.assertEqual(len(self.s.items()), 1) + + def testSequence(self): + # PYSIDE-641 + self.combo.addItem("test", userData=Sequence()) + self.assertTrue(isinstance(self.combo.itemData(0), Sequence)) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/qwidget_setlayout_test.py b/sources/pyside6/tests/QtWidgets/qwidget_setlayout_test.py new file mode 100644 index 000000000..6bb292f26 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qwidget_setlayout_test.py @@ -0,0 +1,67 @@ +#!/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 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 PySide6.QtWidgets import QWidget, QVBoxLayout, QPushButton, QApplication, QHBoxLayout +from helper.usesqapplication import UsesQApplication + +class QWidgetTest(UsesQApplication): + + def test_setLayout(self): + layout = QVBoxLayout() + btn1 = QPushButton("button_v1") + layout.addWidget(btn1) + + btn2 = QPushButton("button_v2") + layout.addWidget(btn2) + + layout2 = QHBoxLayout() + + btn1 = QPushButton("button_h1") + layout2.addWidget(btn1) + + btn2 = QPushButton("button_h2") + layout2.addWidget(btn2) + + layout.addLayout(layout2) + + widget = QWidget() + widget.setLayout(layout) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/qwidget_test.py b/sources/pyside6/tests/QtWidgets/qwidget_test.py new file mode 100644 index 000000000..a2b8e8b94 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/qwidget_test.py @@ -0,0 +1,80 @@ +############################################################################# +## +## Copyright (C) 2019 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 sys +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 PySide6.QtWidgets import QWidget, QMainWindow +from helper.usesqapplication import UsesQApplication + +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): + self.assertRaises(TypeError, QWidgetInherit) + +class QWidgetVisible(UsesQApplication): + + def testBasic(self): + # Also related to bug #244, on existence of setVisible''' + 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/pyside6/tests/QtWidgets/reference_count_test.py b/sources/pyside6/tests/QtWidgets/reference_count_test.py new file mode 100644 index 000000000..113d5b5b6 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/reference_count_test.py @@ -0,0 +1,102 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''Test cases for Reference count when the object is created in c++ side''' + +import gc +import os +import sys +import unittest +import weakref + +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 PySide6.QtCore import Qt, QPointF +from PySide6.QtGui import QPolygonF +from PySide6.QtWidgets import QApplication, QGraphicsScene, QGraphicsRectItem, QGraphicsPolygonItem, QGraphicsRectItem + +from helper.usesqapplication import UsesQApplication + +destroyedRect = False +destroyedPol = False + +def rect_del(o): + global destroyedRect + destroyedRect = True + +def pol_del(o): + global destroyedPol + destroyedPol = True + +class ReferenceCount(UsesQApplication): + + def setUp(self): + super(ReferenceCount, self).setUp() + self.scene = QGraphicsScene() + + def tearDown(self): + super(ReferenceCount, self).tearDown() + + def beforeTest(self): + points = [QPointF(0, 0), QPointF(100, 100), QPointF(0, 100)] + pol = self.scene.addPolygon(QPolygonF(points)) + self.assertTrue(isinstance(pol, QGraphicsPolygonItem)) + self.wrp = weakref.ref(pol, pol_del) + + #refcount need be 3 because one ref for QGraphicsScene, and one to rect obj + self.assertEqual(sys.getrefcount(pol), 3) + + def testReferenceCount(self): + global destroyedRect + global destroyedPol + + self.beforeTest() + + rect = self.scene.addRect(10.0, 10.0, 10.0, 10.0) + self.assertTrue(isinstance(rect, QGraphicsRectItem)) + + self.wrr = weakref.ref(rect, rect_del) + + #refcount need be 3 because one ref for QGraphicsScene, and one to rect obj + self.assertEqual(sys.getrefcount(rect), 3) + + del rect + #not destroyed because one ref continue in QGraphicsScene + self.assertEqual(destroyedRect, False) + self.assertEqual(destroyedPol, False) + + del self.scene + + #QGraphicsScene was destroyed and this destroy internal ref to rect + self.assertEqual(destroyedRect, True) + self.assertEqual(destroyedPol, True) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/sample.png b/sources/pyside6/tests/QtWidgets/sample.png Binary files differnew file mode 100644 index 000000000..60450f0dc --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/sample.png diff --git a/sources/pyside6/tests/QtWidgets/signature_test.py b/sources/pyside6/tests/QtWidgets/signature_test.py new file mode 100644 index 000000000..58d2ff9a5 --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/signature_test.py @@ -0,0 +1,94 @@ +############################################################################# +## +## Copyright (C) 2017 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of Qt for Python. +## +## $QT_BEGIN_LICENSE:LGPL$ +## 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 Lesser General Public License Usage +## Alternatively, this file may be used under the terms of the GNU Lesser +## General Public License version 3 as published by the Free Software +## Foundation and appearing in the file LICENSE.LGPL3 included in the +## packaging of this file. Please review the following information to +## ensure the GNU Lesser General Public License version 3 requirements +## will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 2.0 or (at your option) the GNU General +## Public license version 3 or any later version approved by the KDE Free +## Qt Foundation. The licenses are as published by the Free Software +## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +## 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-2.0.html and +## https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +from __future__ import print_function, absolute_import + +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) + +import PySide6.QtCore +import PySide6.QtWidgets +from shibokensupport.signature import inspect + + +class PySideSignatureTest(unittest.TestCase): + def testSignatureExist(self): + t1 = type(PySide6.QtCore.QObject.children.__signature__) + self.assertEqual(t1, inspect.Signature) + t2 = type(PySide6.QtCore.QObject.__dict__["children"].__signature__) + self.assertEqual(t2, t1) + obj = PySide6.QtWidgets.QApplication.palette + t3 = type(obj.__signature__) + self.assertEqual(t3, list) + self.assertEqual(len(obj.__signature__), 3) + for thing in obj.__signature__: + self.assertEqual(type(thing), inspect.Signature) + sm = PySide6.QtWidgets.QApplication.__dict__["palette"] + self.assertFalse(callable(sm)) + self.assertEqual(sm.__func__, obj) + self.assertTrue(hasattr(sm, "__signature__") and + sm.__signature__ is not None) + + def testSignatureIsCached(self): + # see if we get the same object + ob1 = PySide6.QtCore.QObject.children.__signature__ + ob2 = PySide6.QtCore.QObject.children.__signature__ + self.assertTrue(ob1 is ob2) + # same with multi signature + ob1 = PySide6.QtWidgets.QApplication.palette.__signature__ + ob2 = PySide6.QtWidgets.QApplication.palette.__signature__ + self.assertTrue(ob1 is ob2) + + def testModuleIsInitialized(self): + self.assertTrue(PySide6.QtWidgets.QApplication.__signature__ is not None) + + def test_NotCalled_is_callable_and_correct(self): + # A signature that has a default value with some "Default(...)" + # wrapper is callable and creates an object of the right type. + sig = PySide6.QtCore.QByteArray().toPercentEncoding.__signature__ + called_default = sig.parameters["exclude"].default() + self.assertEqual(type(called_default), PySide6.QtCore.QByteArray) + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside6/tests/QtWidgets/standardpixmap_test.py b/sources/pyside6/tests/QtWidgets/standardpixmap_test.py new file mode 100644 index 000000000..d3e2ee7ce --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/standardpixmap_test.py @@ -0,0 +1,49 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +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 PySide6.QtGui import QPixmap +from PySide6.QtWidgets import QStyle + +from helper.usesqapplication import UsesQApplication + +class StandardPixmapTest(UsesQApplication): + def testDefaultOptions(self): # Bug 253 + pixmap = self.app.style().standardPixmap(QStyle.SP_DirClosedIcon) + self.assertTrue(isinstance(pixmap, QPixmap)) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/test_module_template.py b/sources/pyside6/tests/QtWidgets/test_module_template.py new file mode 100644 index 000000000..74defe7ea --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/test_module_template.py @@ -0,0 +1,48 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "util")) +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths() + +from PySide6.QtWidgets import QWidget +from PySide6.QtCore import QObject + +class MyQObject(QObject): + pass + +class MyQWidget(QWidget): + pass + +class Sentinel(): + value = 10 + diff --git a/sources/pyside6/tests/QtWidgets/virtual_protected_inheritance_test.py b/sources/pyside6/tests/QtWidgets/virtual_protected_inheritance_test.py new file mode 100644 index 000000000..24d0ec01c --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/virtual_protected_inheritance_test.py @@ -0,0 +1,103 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''Test cases for overriding inherited protected virtual methods''' + +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 PySide6.QtCore import QTimerEvent +from PySide6.QtWidgets import QApplication, QSpinBox + +from helper.usesqapplication import UsesQApplication + +class MySpinButton(QSpinBox): + '''Simple example class of overriding QObject.timerEvent''' + + def __init__(self, max_runs=5, app=None): + #Creates a new spinbox that will run <max_runs> and quit <app> + super(MySpinButton, self).__init__() + + if app is None: + app = QApplication([]) + + self.app = app + self.max_runs = max_runs + self.runs = 0 + + def timerEvent(self, event): + #Timer event method + self.runs += 1 + + self.setValue(self.runs) + + if self.runs == self.max_runs: + self.app.quit() + + if not isinstance(event, QTimerEvent): + raise TypeError('Invalid event type. Must be TimerEvent') + +class TimerEventTest(UsesQApplication): + '''Test case for running QObject.timerEvent from inherited class''' + + qapplication = True + + def setUp(self): + #Acquire resources + super(TimerEventTest, self).setUp() + self.widget = MySpinButton(app=self.app) + + def tearDown(self): + #Release resources + del self.widget + super(TimerEventTest, self).tearDown() + + def testMethod(self): + #QWidget.timerEvent overrinding (protected inherited) + timer_id = self.widget.startTimer(0) + + self.app.exec_() + + self.widget.killTimer(timer_id) + + self.assertTrue(self.widget.runs >= self.widget.max_runs) + + +if __name__ == '__main__': + unittest.main() + #app = QApplication([]) + #widget = MySpinButton(app=app) + #widget.startTimer(500) + #widget.show() + #app.exec_() + diff --git a/sources/pyside6/tests/QtWidgets/virtual_pure_override_test.py b/sources/pyside6/tests/QtWidgets/virtual_pure_override_test.py new file mode 100644 index 000000000..8acc2128f --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/virtual_pure_override_test.py @@ -0,0 +1,83 @@ +#!/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 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 PySide6.QtWidgets import QGraphicsScene, QGraphicsRectItem, QGraphicsView, QApplication +from PySide6.QtGui import QBrush, QColor +from PySide6.QtCore import QTimer +from helper.usesqapplication import UsesQApplication + +qgraphics_item_painted = False + +class RoundRectItem(QGraphicsRectItem): + + def __init__(self, x, y, w, h): + QGraphicsRectItem.__init__(self, x, y, w, h) + + def paint(self, painter, qstyleoptiongraphicsitem, qwidget): + global qgraphics_item_painted + qgraphics_item_painted = True + + +class QGraphicsItemTest(UsesQApplication): + + def createRoundRect(self, scene): + item = RoundRectItem(10, 10, 100, 100) + item.setBrush(QBrush(QColor(255, 0, 0))) + scene.addItem(item) + return item + + def quit_app(self): + self.app.quit() + + def test_setParentItem(self): + global qgraphics_item_painted + + scene = QGraphicsScene() + scene.addText("test") + view = QGraphicsView(scene) + + rect = self.createRoundRect(scene) + view.show() + QTimer.singleShot(1000, self.quit_app) + self.app.exec_() + self.assertTrue(qgraphics_item_painted) + + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside6/tests/QtWidgets/wrong_return_test.py b/sources/pyside6/tests/QtWidgets/wrong_return_test.py new file mode 100644 index 000000000..5761c3f5e --- /dev/null +++ b/sources/pyside6/tests/QtWidgets/wrong_return_test.py @@ -0,0 +1,62 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''Test cases for Virtual functions with wrong return type''' + +import os +import sys +import unittest +import warnings + +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 PySide6 import QtWidgets +from helper.usesqapplication import UsesQApplication + + +warnings.simplefilter('error') + + +class MyWidget(QtWidgets.QWidget): + def __init__(self, parent=None): + super(MyWidget, self).__init__(parent) + + def sizeHint(self): + pass + +class testCase(UsesQApplication): + + def testVirtualReturn(self): + w = MyWidget() + self.assertWarns(RuntimeWarning, w.show) + + +if __name__ == '__main__': + unittest.main() |