aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/tests
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-04-26 08:03:54 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-04-26 08:04:41 +0200
commit9b01aae7777c7ccde9eed1a8c55aead1524e00e5 (patch)
treec62834ca412f290485dd96d2a7522809b8fce6e1 /sources/pyside2/tests
parent2156651b39fbb6717ed936c94dcd28295436e0a4 (diff)
parent0b842db3a95a44fbda3379d2093cb52f8ae2a1ff (diff)
Merge remote-tracking branch 'origin/5.9' into 5.11
Diffstat (limited to 'sources/pyside2/tests')
-rw-r--r--sources/pyside2/tests/QtCore/qobject_inherits_test.py37
-rw-r--r--sources/pyside2/tests/QtLocation/CMakeLists.txt1
-rw-r--r--sources/pyside2/tests/QtLocation/location.py41
-rw-r--r--sources/pyside2/tests/QtPositioning/CMakeLists.txt1
-rw-r--r--sources/pyside2/tests/QtPositioning/positioning.py43
-rw-r--r--sources/pyside2/tests/QtSensors/CMakeLists.txt1
-rw-r--r--sources/pyside2/tests/QtSensors/sensors.py55
-rw-r--r--sources/pyside2/tests/QtWebEngineCore/CMakeLists.txt29
-rw-r--r--sources/pyside2/tests/QtWebEngineCore/web_engine_custom_scheme.py64
-rw-r--r--sources/pyside2/tests/QtWebEngineWidgets/pyside-474-qtwebengineview.py4
-rw-r--r--sources/pyside2/tests/QtWidgets/CMakeLists.txt3
-rw-r--r--sources/pyside2/tests/QtWidgets/qapp_issue_585.py68
-rw-r--r--sources/pyside2/tests/QtWidgets/qgraphicsobjectreimpl_test.py76
-rw-r--r--sources/pyside2/tests/QtWidgets/qtreeview_test.py9
-rw-r--r--sources/pyside2/tests/QtWidgets/qtreewidget_test.py64
15 files changed, 490 insertions, 6 deletions
diff --git a/sources/pyside2/tests/QtCore/qobject_inherits_test.py b/sources/pyside2/tests/QtCore/qobject_inherits_test.py
index 8c4c797a4..1d089776b 100644
--- a/sources/pyside2/tests/QtCore/qobject_inherits_test.py
+++ b/sources/pyside2/tests/QtCore/qobject_inherits_test.py
@@ -29,8 +29,12 @@
'''Test cases for QObject methods'''
import unittest
+import sys
-from PySide2.QtCore import QObject
+from PySide2.QtCore import QObject, QTimer
+from PySide2.QtWidgets import QApplication, QLabel, QVBoxLayout
+
+is_alive = None
class InheritsCase(unittest.TestCase):
'''Test case for QObject.inherits'''
@@ -87,5 +91,36 @@ class InheritsCase(unittest.TestCase):
self.assertRaises(TypeError, declareClass)
+ # PYSIDE-11:
+ # The takeOwnership() method was relying that the SbkObject
+ # had a converter, which it's not the case when multiple
+ # inheritance is used.
+ # The deleteLater() method uses the takeOwnership() to give
+ # control of the object to C++, so it can be remove once
+ # the destructor is called.
+ # The solution was to add a default case when the object
+ # is null under the pythonTypeIsValueType() method in shiboken.
+ def testDeleteMultipleInheritance(self):
+ app = QApplication(sys.argv)
+ class DerivedLabel(QLabel, QObject):
+ def __del__(self):
+ global is_alive
+ is_alive = False
+
+ global is_alive
+ child = DerivedLabel('Hello')
+ is_alive = True
+ parent = QVBoxLayout()
+ parent.addWidget(child)
+ parent.removeWidget(child)
+ child.deleteLater()
+ self.assertTrue(is_alive)
+ del child
+ self.assertTrue(is_alive)
+ QTimer.singleShot(100, app.quit)
+ app.exec_()
+ self.assertFalse(is_alive)
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside2/tests/QtLocation/CMakeLists.txt b/sources/pyside2/tests/QtLocation/CMakeLists.txt
new file mode 100644
index 000000000..b97ac1098
--- /dev/null
+++ b/sources/pyside2/tests/QtLocation/CMakeLists.txt
@@ -0,0 +1 @@
+PYSIDE_TEST(location.py)
diff --git a/sources/pyside2/tests/QtLocation/location.py b/sources/pyside2/tests/QtLocation/location.py
new file mode 100644
index 000000000..ca964c46c
--- /dev/null
+++ b/sources/pyside2/tests/QtLocation/location.py
@@ -0,0 +1,41 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of PySide2.
+##
+## $QT_BEGIN_LICENSE:GPL-EXCEPT$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 3 as published by the Free Software
+## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+'''Unit test for Location'''
+
+from PySide2.QtLocation import QGeoServiceProvider
+import unittest
+
+class QLocationTestCase(unittest.TestCase):
+ def test(self):
+ geoServiceProvider = QGeoServiceProvider("none")
+ self.assertEqual(geoServiceProvider.errorString(),
+ 'The geoservices provider none is not supported.')
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/sources/pyside2/tests/QtPositioning/CMakeLists.txt b/sources/pyside2/tests/QtPositioning/CMakeLists.txt
new file mode 100644
index 000000000..b9f7631b1
--- /dev/null
+++ b/sources/pyside2/tests/QtPositioning/CMakeLists.txt
@@ -0,0 +1 @@
+PYSIDE_TEST(positioning.py)
diff --git a/sources/pyside2/tests/QtPositioning/positioning.py b/sources/pyside2/tests/QtPositioning/positioning.py
new file mode 100644
index 000000000..9f61fe1ef
--- /dev/null
+++ b/sources/pyside2/tests/QtPositioning/positioning.py
@@ -0,0 +1,43 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of PySide2.
+##
+## $QT_BEGIN_LICENSE:GPL-EXCEPT$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 3 as published by the Free Software
+## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+'''Unit test for Positioning'''
+
+from PySide2.QtPositioning import QGeoPositionInfoSource
+import unittest
+
+class QPositioningTestCase(unittest.TestCase):
+ def test(self):
+ source = QGeoPositionInfoSource.createDefaultSource(None)
+ self.assertTrue(source is not None)
+ name = source.sourceName()
+ print('QtPositioning source: {}'.format(name))
+ self.assertTrue(name)
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/sources/pyside2/tests/QtSensors/CMakeLists.txt b/sources/pyside2/tests/QtSensors/CMakeLists.txt
new file mode 100644
index 000000000..87e548f87
--- /dev/null
+++ b/sources/pyside2/tests/QtSensors/CMakeLists.txt
@@ -0,0 +1 @@
+PYSIDE_TEST(sensors.py)
diff --git a/sources/pyside2/tests/QtSensors/sensors.py b/sources/pyside2/tests/QtSensors/sensors.py
new file mode 100644
index 000000000..5b41ac63d
--- /dev/null
+++ b/sources/pyside2/tests/QtSensors/sensors.py
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of PySide2.
+##
+## $QT_BEGIN_LICENSE:GPL-EXCEPT$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 3 as published by the Free Software
+## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+'''Test cases for QSensor'''
+
+from PySide2.QtSensors import QSensor, QSensorReading
+import unittest
+
+class QSensorTest(unittest.TestCase):
+ def test(self):
+ for sensorType in QSensor.sensorTypes():
+ identifiers = QSensor.sensorsForType(sensorType)
+ values = []
+ usedIdentifier = None
+ for identifier in identifiers:
+ sensor = QSensor(sensorType, None);
+ sensor.setIdentifier(identifier)
+ if sensor.connectToBackend():
+ usedIdentifier = identifier
+ reading = sensor.reading()
+ for i in range(0, reading.valueCount()):
+ values.append(reading.value(i))
+ break
+ if usedIdentifier:
+ print('Sensor ', sensorType, usedIdentifier, values)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside2/tests/QtWebEngineCore/CMakeLists.txt b/sources/pyside2/tests/QtWebEngineCore/CMakeLists.txt
new file mode 100644
index 000000000..2e361383c
--- /dev/null
+++ b/sources/pyside2/tests/QtWebEngineCore/CMakeLists.txt
@@ -0,0 +1,29 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of PySide2.
+##
+## $QT_BEGIN_LICENSE:GPL-EXCEPT$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 3 as published by the Free Software
+## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+PYSIDE_TEST(web_engine_custom_scheme.py)
diff --git a/sources/pyside2/tests/QtWebEngineCore/web_engine_custom_scheme.py b/sources/pyside2/tests/QtWebEngineCore/web_engine_custom_scheme.py
new file mode 100644
index 000000000..b7c57d8e6
--- /dev/null
+++ b/sources/pyside2/tests/QtWebEngineCore/web_engine_custom_scheme.py
@@ -0,0 +1,64 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of PySide2.
+##
+## $QT_BEGIN_LICENSE:GPL-EXCEPT$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 3 as published by the Free Software
+## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+from __future__ import print_function
+
+import unittest
+
+from PySide2.QtCore import QBuffer, QTimer
+from PySide2.QtWidgets import QApplication
+from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile
+from PySide2.QtWebEngineCore import QWebEngineUrlSchemeHandler
+
+class TestSchemeHandler(QWebEngineUrlSchemeHandler):
+ def requestStarted(self, request):
+ if request.requestUrl() == "testpy:hello":
+ request.redirect("testpy:goodbye")
+ return
+
+ self.buffer = QBuffer()
+ self.buffer.setData("Really nice goodbye text.")
+ self.buffer.aboutToClose.connect(self.buffer.deleteLater)
+ request.reply("text/plain;charset=utf-8", self.buffer)
+
+class MainTest(unittest.TestCase):
+ def test_SchemeHandlerRedirect(self):
+ app = QApplication([])
+ handler = TestSchemeHandler()
+ profile = QWebEngineProfile.defaultProfile()
+ profile.installUrlSchemeHandler("testpy", handler)
+ view = QWebEngineView()
+ view.loadFinished.connect(app.quit)
+ QTimer.singleShot(5000, app.quit)
+ view.show()
+ view.load("testpy:hello")
+ app.exec_()
+ self.assertEqual(view.url(), "testpy:goodbye")
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside2/tests/QtWebEngineWidgets/pyside-474-qtwebengineview.py b/sources/pyside2/tests/QtWebEngineWidgets/pyside-474-qtwebengineview.py
index 6ea3aa95a..b4aef26d1 100644
--- a/sources/pyside2/tests/QtWebEngineWidgets/pyside-474-qtwebengineview.py
+++ b/sources/pyside2/tests/QtWebEngineWidgets/pyside-474-qtwebengineview.py
@@ -39,11 +39,7 @@ class MainTest(unittest.TestCase):
qApp = (QtWidgets.QApplication.instance() or
QtWidgets.QApplication([]))
view = QtWebEngineWidgets.QWebEngineView()
- with self.assertRaises(TypeError):
- view.findText(123)
view.findText("nothing")
- # we are testing only the existence of the function,
- # after it suddenly showed up.
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside2/tests/QtWidgets/CMakeLists.txt b/sources/pyside2/tests/QtWidgets/CMakeLists.txt
index fa64d1c3b..9caf7e365 100644
--- a/sources/pyside2/tests/QtWidgets/CMakeLists.txt
+++ b/sources/pyside2/tests/QtWidgets/CMakeLists.txt
@@ -82,6 +82,7 @@ PYSIDE_TEST(parent_method_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_exit_segfault_test.py)
PYSIDE_TEST(qapplication_singleton_test.py)
@@ -92,6 +93,7 @@ PYSIDE_TEST(qdynamic_signal.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)
@@ -121,6 +123,7 @@ 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(qtoolbar_test.py)
PYSIDE_TEST(qtoolbox_test.py)
PYSIDE_TEST(qvariant_test.py)
diff --git a/sources/pyside2/tests/QtWidgets/qapp_issue_585.py b/sources/pyside2/tests/QtWidgets/qapp_issue_585.py
new file mode 100644
index 000000000..9dd2014c0
--- /dev/null
+++ b/sources/pyside2/tests/QtWidgets/qapp_issue_585.py
@@ -0,0 +1,68 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of PySide2.
+##
+## $QT_BEGIN_LICENSE:GPL-EXCEPT$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 3 as published by the Free Software
+## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+"""
+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.
+"""
+
+from PySide2.QtCore import QTimer
+from PySide2 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/pyside2/tests/QtWidgets/qgraphicsobjectreimpl_test.py b/sources/pyside2/tests/QtWidgets/qgraphicsobjectreimpl_test.py
new file mode 100644
index 000000000..fd79ce3aa
--- /dev/null
+++ b/sources/pyside2/tests/QtWidgets/qgraphicsobjectreimpl_test.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 PySide2.
+##
+## $QT_BEGIN_LICENSE:GPL-EXCEPT$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 3 as published by the Free Software
+## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+''' Test cases related to QGraphicsItem and subclasses'''
+
+import unittest
+
+from PySide2.QtWidgets import QGraphicsObject, QGraphicsWidget
+from PySide2.QtCore import QRectF
+
+from helper 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/pyside2/tests/QtWidgets/qtreeview_test.py b/sources/pyside2/tests/QtWidgets/qtreeview_test.py
index a731ddafa..703131ec3 100644
--- a/sources/pyside2/tests/QtWidgets/qtreeview_test.py
+++ b/sources/pyside2/tests/QtWidgets/qtreeview_test.py
@@ -29,7 +29,9 @@
import unittest
from PySide2.QtGui import QStandardItemModel
-from PySide2.QtWidgets import QWidget, QTreeView, QVBoxLayout, QStyledItemDelegate
+from PySide2.QtWidgets import (QWidget, QTreeView, QVBoxLayout,
+ QStyledItemDelegate, QHeaderView)
+from PySide2.QtCore import Qt
from helper import UsesQApplication
class Widget(QWidget):
@@ -85,5 +87,10 @@ class QWidgetTest(UsesQApplication):
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/pyside2/tests/QtWidgets/qtreewidget_test.py b/sources/pyside2/tests/QtWidgets/qtreewidget_test.py
new file mode 100644
index 000000000..11fa83c5a
--- /dev/null
+++ b/sources/pyside2/tests/QtWidgets/qtreewidget_test.py
@@ -0,0 +1,64 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of PySide2.
+##
+## $QT_BEGIN_LICENSE:GPL-EXCEPT$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 3 as published by the Free Software
+## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+import unittest
+
+from PySide2.QtWidgets import QTreeWidget, QTreeWidgetItem, QPushButton
+from helper 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()