diff options
Diffstat (limited to 'sources/pyside2/tests/pysidetest')
28 files changed, 562 insertions, 37 deletions
diff --git a/sources/pyside2/tests/pysidetest/CMakeLists.txt b/sources/pyside2/tests/pysidetest/CMakeLists.txt index 3c993cf4e..46a8023c3 100644 --- a/sources/pyside2/tests/pysidetest/CMakeLists.txt +++ b/sources/pyside2/tests/pysidetest/CMakeLists.txt @@ -30,6 +30,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/testbinding/testobject_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/testbinding/intvalue_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/testbinding/pysidecpp_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/testbinding/pysidecpp_testobjectwithnamespace_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/testbinding/pysidecpp_testobject2withnamespace_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/testbinding/pysidecpp2_testobjectwithoutnamespace_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/testbinding/testview_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/testbinding/testbinding_module_wrapper.cpp @@ -106,10 +107,17 @@ set_property(TARGET testbinding PROPERTY OUTPUT_NAME "testbinding${SHIBOKEN_PYTH if(WIN32) set_property(TARGET testbinding PROPERTY SUFFIX ".pyd") endif() + +if(PYTHON_LIMITED_API) + set(TESTBINDING_PYTHON_LIBS ${PYTHON_LIMITED_LIBRARIES}) +else() + set(TESTBINDING_PYTHON_LIBS ${PYTHON_LIBRARIES}) +endif() + target_link_libraries(testbinding pysidetest pyside2 - ${PYTHON_LIBRARIES} + ${TESTBINDING_PYTHON_LIBS} Shiboken2::libshiboken ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} @@ -124,21 +132,24 @@ PYSIDE_TEST(decoratedslot_test.py) if (Qt5Core_VERSION VERSION_GREATER 5.7.0) PYSIDE_TEST(delegatecreateseditor_test.py) endif() +PYSIDE_TEST(all_modules_load_test.py) +PYSIDE_TEST(bug_1016.py) +PYSIDE_TEST(embedding_test.py) PYSIDE_TEST(enum_test.py) PYSIDE_TEST(homonymoussignalandmethod_test.py) +PYSIDE_TEST(iterable_test.py) PYSIDE_TEST(list_signal_test.py) +PYSIDE_TEST(mixin_signal_slots_test.py) PYSIDE_TEST(modelview_test.py) PYSIDE_TEST(new_inherited_functions_test.py) PYSIDE_TEST(notify_id.py) +PYSIDE_TEST(properties_test.py) +PYSIDE_TEST(qapp_like_a_macro_test.py) PYSIDE_TEST(qvariant_test.py) +PYSIDE_TEST(repr_test.py) +PYSIDE_TEST(signal_slot_warning.py) PYSIDE_TEST(signalandnamespace_test.py) -PYSIDE_TEST(signalwithdefaultvalue_test.py) PYSIDE_TEST(signalemissionfrompython_test.py) -PYSIDE_TEST(version_test.py) +PYSIDE_TEST(signalwithdefaultvalue_test.py) PYSIDE_TEST(typedef_signal_test.py) -PYSIDE_TEST(bug_1016.py) -PYSIDE_TEST(mixin_signal_slots_test.py) -PYSIDE_TEST(signal_slot_warning.py) -PYSIDE_TEST(all_modules_load_test.py) -PYSIDE_TEST(qapp_like_a_macro_test.py) -PYSIDE_TEST(embedding_test.py) +PYSIDE_TEST(version_test.py) diff --git a/sources/pyside2/tests/pysidetest/all_modules_load_test.py b/sources/pyside2/tests/pysidetest/all_modules_load_test.py index e802685fb..10ccc5221 100644 --- a/sources/pyside2/tests/pysidetest/all_modules_load_test.py +++ b/sources/pyside2/tests/pysidetest/all_modules_load_test.py @@ -26,7 +26,14 @@ ## ############################################################################# +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 PySide2 # Note: diff --git a/sources/pyside2/tests/pysidetest/bug_1016.py b/sources/pyside2/tests/pysidetest/bug_1016.py index c2b709333..9f035e0e1 100644 --- a/sources/pyside2/tests/pysidetest/bug_1016.py +++ b/sources/pyside2/tests/pysidetest/bug_1016.py @@ -26,9 +26,17 @@ ## ############################################################################# -from testbinding 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(True) + +import shiboken2 +from testbinding import * + class TestBug1016 (unittest.TestCase): def testIt(self): diff --git a/sources/pyside2/tests/pysidetest/constructor_properties_test.py b/sources/pyside2/tests/pysidetest/constructor_properties_test.py index 48e2a7aae..139091fed 100644 --- a/sources/pyside2/tests/pysidetest/constructor_properties_test.py +++ b/sources/pyside2/tests/pysidetest/constructor_properties_test.py @@ -37,9 +37,15 @@ ## ############################################################################# +import os +import sys import unittest -from helper import UsesQApplication +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths(False) + +from helper.usesqapplication import UsesQApplication from PySide2.QtCore import Qt from PySide2.QtWidgets import QApplication, QLabel, QFrame diff --git a/sources/pyside2/tests/pysidetest/decoratedslot_test.py b/sources/pyside2/tests/pysidetest/decoratedslot_test.py index 47878ed8c..3825f48ab 100644 --- a/sources/pyside2/tests/pysidetest/decoratedslot_test.py +++ b/sources/pyside2/tests/pysidetest/decoratedslot_test.py @@ -28,7 +28,14 @@ ## ############################################################################# +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 PySide2.QtCore import QObject from testbinding import TestObject diff --git a/sources/pyside2/tests/pysidetest/delegatecreateseditor_test.py b/sources/pyside2/tests/pysidetest/delegatecreateseditor_test.py index 1d5a59178..111d4ebbf 100644 --- a/sources/pyside2/tests/pysidetest/delegatecreateseditor_test.py +++ b/sources/pyside2/tests/pysidetest/delegatecreateseditor_test.py @@ -28,12 +28,21 @@ ## ############################################################################# +import os +import sys import unittest -from helper import UsesQApplication +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 helper.usesqapplication import UsesQApplication from testbinding import TestView from PySide2.QtCore import Qt -from PySide2.QtWidgets import QAbstractItemDelegate, QComboBox +from PySide2.QtGui import QStandardItem, QStandardItemModel +from PySide2.QtWidgets import (QAbstractItemDelegate, QComboBox, + QSpinBox, QStyledItemDelegate, + QStyleOptionViewItem, QWidget) id_text = 'This is me' @@ -77,6 +86,19 @@ class EditorCreatedByDelegateTest(UsesQApplication): self.assertEqual(editor.itemData(0, Qt.DisplayRole), id_text) editor.metaObject() + def testIntDelegate(self): + """PYSIDE-1250: When creating a QVariant, use int instead of long long + for anything that fits into a int. Verify by checking that a spin + box is created as item view editor for int.""" + item = QStandardItem() + item.setData(123123, Qt.EditRole) # <-- QVariant conversion here + model = QStandardItemModel() + model.appendRow(item) + style_option = QStyleOptionViewItem() + delegate = QStyledItemDelegate() + editor = delegate.createEditor(None, style_option, model.index(0, 0)) + self.assertEqual(type(editor), QSpinBox) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside2/tests/pysidetest/embedding_test.py b/sources/pyside2/tests/pysidetest/embedding_test.py index aa71360ca..1960838ff 100644 --- a/sources/pyside2/tests/pysidetest/embedding_test.py +++ b/sources/pyside2/tests/pysidetest/embedding_test.py @@ -37,8 +37,14 @@ ## ############################################################################# +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) + # This test tests the embedding feature of PySide. # Normally, embedding is only used when necessary. # By setting the variable "pyside_uses_embedding", diff --git a/sources/pyside2/tests/pysidetest/enum_test.py b/sources/pyside2/tests/pysidetest/enum_test.py index 428e087f0..d179d6248 100644 --- a/sources/pyside2/tests/pysidetest/enum_test.py +++ b/sources/pyside2/tests/pysidetest/enum_test.py @@ -28,7 +28,14 @@ ## ############################################################################# +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 Enum1, TestObjectWithoutNamespace class ListConnectionTest(unittest.TestCase): diff --git a/sources/pyside2/tests/pysidetest/homonymoussignalandmethod_test.py b/sources/pyside2/tests/pysidetest/homonymoussignalandmethod_test.py index 906d0ddb7..1566b4a82 100644 --- a/sources/pyside2/tests/pysidetest/homonymoussignalandmethod_test.py +++ b/sources/pyside2/tests/pysidetest/homonymoussignalandmethod_test.py @@ -28,7 +28,14 @@ ## ############################################################################# +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 '''Tests the behaviour of homonymous signals and slots.''' diff --git a/sources/pyside2/tests/pysidetest/iterable_test.py b/sources/pyside2/tests/pysidetest/iterable_test.py new file mode 100644 index 000000000..c5685112d --- /dev/null +++ b/sources/pyside2/tests/pysidetest/iterable_test.py @@ -0,0 +1,91 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +""" +iterable_test.py + +This test checks that the Iterable protocol is implemented correctly. +""" + +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 PySide2 +from PySide2 import QtCore, QtGui + +try: + import numpy as np + have_numpy = True +except ImportError: + have_numpy = False + +class PySequenceTest(unittest.TestCase): + + def test_iterable(self): + def gen(lis): + for item in lis: + if item == "crash": + raise IndexError + yield item + # testing "pyseq_to_cpplist_conversion" + testfunc = QtCore.QUrl.fromStringList + # use a generator (iterable) + self.assertEqual(testfunc(gen(["asd", "ghj"])), + [PySide2.QtCore.QUrl('asd'), PySide2.QtCore.QUrl('ghj')]) + # use an iterator + self.assertEqual(testfunc(iter(["asd", "ghj"])), + [PySide2.QtCore.QUrl('asd'), PySide2.QtCore.QUrl('ghj')]) + self.assertRaises(IndexError, testfunc, gen(["asd", "crash", "ghj"])) + # testing QMatrix4x4 + testfunc = QtGui.QMatrix4x4 + self.assertEqual(testfunc(gen(range(16))), testfunc(range(16))) + # Note: The errormessage needs to be improved! + # We should better get a ValueError + self.assertRaises((TypeError, ValueError), testfunc, gen(range(15))) + # All other matrix sizes: + testfunc = QtGui.QMatrix2x2 + self.assertEqual(testfunc(gen(range(4))), testfunc(range(4))) + testfunc = QtGui.QMatrix2x3 + self.assertEqual(testfunc(gen(range(6))), testfunc(range(6))) + + @unittest.skipUnless(have_numpy, "requires numpy") + def test_iterable_numpy(self): + # Demo for numpy: We create a unit matrix. + num_mat = np.eye(4) + num_mat.shape = 16 + unit = QtGui.QMatrix4x4(num_mat) + self.assertEqual(unit, QtGui.QMatrix4x4()) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/pysidetest/list_signal_test.py b/sources/pyside2/tests/pysidetest/list_signal_test.py index a438f0c89..d66ba7905 100644 --- a/sources/pyside2/tests/pysidetest/list_signal_test.py +++ b/sources/pyside2/tests/pysidetest/list_signal_test.py @@ -28,7 +28,14 @@ ## ############################################################################# +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 PySide2.QtCore import QObject diff --git a/sources/pyside2/tests/pysidetest/mixin_signal_slots_test.py b/sources/pyside2/tests/pysidetest/mixin_signal_slots_test.py index 44bb33be6..d0b40cfa0 100644 --- a/sources/pyside2/tests/pysidetest/mixin_signal_slots_test.py +++ b/sources/pyside2/tests/pysidetest/mixin_signal_slots_test.py @@ -33,7 +33,14 @@ are registered at type parsing time. Also test that the signal and slot indices do not change after signal connection or emission. ''' +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 PySide2 import QtCore class Mixin(object): diff --git a/sources/pyside2/tests/pysidetest/modelview_test.py b/sources/pyside2/tests/pysidetest/modelview_test.py index a0f723c4a..a4ae9dd40 100644 --- a/sources/pyside2/tests/pysidetest/modelview_test.py +++ b/sources/pyside2/tests/pysidetest/modelview_test.py @@ -28,7 +28,14 @@ ## ############################################################################# +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) + import py3kcompat as py3k from testbinding import TestView from PySide2.QtCore import QAbstractListModel, QObject, QModelIndex diff --git a/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py b/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py index 09e5f2610..81a764986 100644 --- a/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py +++ b/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py @@ -28,10 +28,14 @@ from __future__ import print_function -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 PySide2 import * for modname, mod in sys.modules.items(): # Python 2 leaves "None" in the dict. diff --git a/sources/pyside2/tests/pysidetest/notify_id.py b/sources/pyside2/tests/pysidetest/notify_id.py index d96e8d91f..393736a65 100644 --- a/sources/pyside2/tests/pysidetest/notify_id.py +++ b/sources/pyside2/tests/pysidetest/notify_id.py @@ -26,7 +26,14 @@ ## ############################################################################# +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 PySide2.QtCore import QObject, Signal, Property, Slot '''Tests that the signal notify id of a property is correct, aka corresponds to the initially set diff --git a/sources/pyside2/tests/pysidetest/properties_test.py b/sources/pyside2/tests/pysidetest/properties_test.py new file mode 100644 index 000000000..cedfac8d1 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/properties_test.py @@ -0,0 +1,132 @@ +############################################################################# +## +## Copyright (C) 2020 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of Qt for Python. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import os +import sys +import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from init_paths import init_test_paths +init_test_paths(False) + +from PySide2.QtCore import QObject, QStringListModel, Signal, Property, Slot + +"""Tests PySide2.QtCore.Property()""" + + +class TestObject(QObject): + + valueChanged = Signal() + + def __init__(self, parent=None): + super(TestObject, self).__init__(parent) + self._value = -1 + self.valueChanged.connect(self._changed) + self.getter_called = 0 + self.setter_called = 0 + self.changed_emitted = 0 + + @Slot(int) + def _changed(self): + self.changed_emitted += 1 + + def getValue(self): + self.getter_called += 1 + return self._value + + def setValue(self, value): + self.setter_called += 1 + if (self._value != value): + self._value = value + self.valueChanged.emit() + + value = Property(int, fget=getValue, fset=setValue, + notify=valueChanged) + + +class TestDerivedObject(QStringListModel): + + valueChanged = Signal() + + def __init__(self, parent=None): + super(TestDerivedObject, self).__init__(parent) + self._value = -1 + self.valueChanged.connect(self._changed) + self.getter_called = 0 + self.setter_called = 0 + self.changed_emitted = 0 + + @Slot(int) + def _changed(self): + self.changed_emitted += 1 + + def getValue(self): + self.getter_called += 1 + return self._value + + def setValue(self, value): + self.setter_called += 1 + if (self._value != value): + self._value = value + self.valueChanged.emit() + + value = Property(int, fget=getValue, fset=setValue, + notify=valueChanged) + + +class PropertyTest(unittest.TestCase): + + def test1Object(self): + """Basic property test.""" + testObject = TestObject() + v = testObject.value + self.assertEqual(v, -1) + self.assertEqual(testObject.getter_called, 1) + testObject.value = 42 + v = testObject.value + self.assertEqual(v, 42) + self.assertEqual(testObject.changed_emitted, 1) + self.assertEqual(testObject.setter_called, 1) + self.assertEqual(testObject.getter_called, 2) + + def test2DerivedObject(self): + """PYSIDE-1255: Run the same test for a class inheriting QObject.""" + testObject = TestDerivedObject() + v = testObject.value + self.assertEqual(v, -1) + self.assertEqual(testObject.getter_called, 1) + testObject.value = 42 + v = testObject.value + self.assertEqual(v, 42) + self.assertEqual(testObject.changed_emitted, 1) + self.assertEqual(testObject.setter_called, 1) + self.assertEqual(testObject.getter_called, 2) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py b/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py index c58aba82e..bfcf40111 100644 --- a/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py +++ b/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py @@ -26,14 +26,26 @@ ## ############################################################################# +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 PySide2 # This test tests the new "macro" feature of qApp. # It also uses the qApp variable to finish the instance and start over. +# Note: this test makes qapplication_singleton_test.py obsolete. + class qAppMacroTest(unittest.TestCase): + _test_1093_is_first = True + def test_qApp_is_like_a_macro_and_can_restart(self): + self._test_1093_is_first = False from PySide2 import QtCore try: from PySide2 import QtGui, QtWidgets @@ -41,36 +53,36 @@ class qAppMacroTest(unittest.TestCase): QtWidgets = QtGui = QtCore # qApp is in the builtins self.assertEqual(bool(qApp), False) - # and also in certain PySide modules - QtCore.qApp, QtGui.qApp, QtWidgets.qApp - # and they are all the same - self.assertTrue(qApp is QtCore.qApp is QtGui.qApp is QtWidgets.qApp) - # and the type is NoneType, but it is not None (cannot work) - self.assertTrue(type(qApp) is type(None)) - self.assertTrue(qApp is not None) + # and the type is None + self.assertTrue(qApp is None) # now we create an application for all cases classes = (QtCore.QCoreApplication, QtGui.QGuiApplication, QtWidgets.QApplication) for klass in classes: print("created", klass([])) - del __builtins__.qApp - print("deleted qApp") + qApp.shutdown() + print("deleted qApp", qApp) # creating without deletion raises: QtCore.QCoreApplication([]) with self.assertRaises(RuntimeError): QtCore.QCoreApplication([]) - # assigning qApp is obeyed - QtCore.qApp = 42 - del __builtins__.qApp - self.assertEqual(QtCore.qApp, 42) - self.assertNotEqual(__builtins__, 42) - # delete it and it re-appears - del QtCore.qApp - QtCore.QCoreApplication([]) - self.assertEqual(QtCore.QCoreApplication.instance(), QtCore.qApp) - # and they are again all the same - self.assertTrue(qApp is QtCore.qApp is QtGui.qApp is QtWidgets.qApp) + self.assertEqual(QtCore.QCoreApplication.instance(), qApp) + + def test_1093(self): + # Test that without creating a QApplication staticMetaObject still exists. + # Please see https://bugreports.qt.io/browse/PYSIDE-1093 for explanation. + # Note: This test must run first, otherwise we would be mislead! + assert self._test_1093_is_first + from PySide2 import QtCore + self.assertTrue(QtCore.QObject.staticMetaObject is not None) + app = QtCore.QCoreApplication.instance() + self.assertTrue(QtCore.QObject.staticMetaObject is not None) + if app is None: + app = QtCore.QCoreApplication([]) + self.assertTrue(QtCore.QObject.staticMetaObject is not None) + qApp.shutdown() + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside2/tests/pysidetest/qvariant_test.py b/sources/pyside2/tests/pysidetest/qvariant_test.py index ec8343a12..0efece889 100644 --- a/sources/pyside2/tests/pysidetest/qvariant_test.py +++ b/sources/pyside2/tests/pysidetest/qvariant_test.py @@ -26,13 +26,19 @@ ## ############################################################################# +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 PySide2.QtCore import Qt from PySide2.QtGui import QKeySequence -from helper import UsesQApplication +from helper.usesqapplication import UsesQApplication class QVariantTest(UsesQApplication): diff --git a/sources/pyside2/tests/pysidetest/repr_test.py b/sources/pyside2/tests/pysidetest/repr_test.py new file mode 100644 index 000000000..356d11911 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/repr_test.py @@ -0,0 +1,90 @@ +# -*- coding: utf-8 -*- + +############################################################################# +## +## Copyright (C) 2019 The Qt Company Ltd. +## Copyright (C) 2019 Andreas Beckermann +## 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$ +## +############################################################################# + +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 PySideCPP, TestObject + +class QObjectDerivedReprTest(unittest.TestCase): + """Test the __repr__ implementation of QObject derived classes""" + + def testReprWithoutNamespace(self): + """Test that classes outside a namespace that have a operator<<(QDebug,...) defined use that + for __repr__""" + t = TestObject(123) + + # We don't define __str__, so str(q) should call __repr__ + self.assertEqual(t.__repr__(), str(t)) + + # __repr__ should use the operator<<(QDebug,...) implementation + self.assertIn('TestObject(id=123)', str(t)) + + def testReprWithNamespace(self): + """Test that classes inside a namespace that have a operator<<(QDebug,...) defined use that + for __repr__""" + t = PySideCPP.TestObjectWithNamespace(None) + + # We don't define __str__, so str(q) should call __repr__ + self.assertEqual(t.__repr__(), str(t)) + + # __repr__ should use the operator<<(QDebug,...) implementation + self.assertIn('TestObjectWithNamespace("TestObjectWithNamespace")', str(t)) + + def testReprInject(self): + """Test that injecting __repr__ via typesystem overrides the operator<<(QDebug, ...)""" + t = PySideCPP.TestObject2WithNamespace(None) + + # We don't define __str__, so str(q) should call __repr__ + self.assertEqual(t.__repr__(), str(t)) + + # __repr__ should use the operator<<(QDebug,...) implementation + self.assertEqual(str(t), "TestObject2WithNamespace(injected_repr)") + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/pysidetest/signal_slot_warning.py b/sources/pyside2/tests/pysidetest/signal_slot_warning.py index 84ddc23de..a54974c3b 100644 --- a/sources/pyside2/tests/pysidetest/signal_slot_warning.py +++ b/sources/pyside2/tests/pysidetest/signal_slot_warning.py @@ -33,11 +33,17 @@ from __future__ import print_function -import unittest -import PySide2.QtCore as QtCore +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) + +import PySide2.QtCore as QtCore + class Whatever(QtCore.QObject): echoSignal = QtCore.Signal(str) diff --git a/sources/pyside2/tests/pysidetest/signalandnamespace_test.py b/sources/pyside2/tests/pysidetest/signalandnamespace_test.py index 9bb42ea40..f56beaf84 100644 --- a/sources/pyside2/tests/pysidetest/signalandnamespace_test.py +++ b/sources/pyside2/tests/pysidetest/signalandnamespace_test.py @@ -28,7 +28,14 @@ ## ############################################################################# +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 PySideCPP, TestObjectWithoutNamespace class ModelViewTest(unittest.TestCase): diff --git a/sources/pyside2/tests/pysidetest/signalemissionfrompython_test.py b/sources/pyside2/tests/pysidetest/signalemissionfrompython_test.py index 43b31f5c0..ed7302c69 100644 --- a/sources/pyside2/tests/pysidetest/signalemissionfrompython_test.py +++ b/sources/pyside2/tests/pysidetest/signalemissionfrompython_test.py @@ -28,7 +28,14 @@ ## ############################################################################# +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 PySide2.QtCore import QObject, SIGNAL diff --git a/sources/pyside2/tests/pysidetest/signalwithdefaultvalue_test.py b/sources/pyside2/tests/pysidetest/signalwithdefaultvalue_test.py index 11951fb09..fc13fc0d9 100644 --- a/sources/pyside2/tests/pysidetest/signalwithdefaultvalue_test.py +++ b/sources/pyside2/tests/pysidetest/signalwithdefaultvalue_test.py @@ -28,7 +28,14 @@ ## ############################################################################# +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 PySide2.QtCore import QObject, SIGNAL diff --git a/sources/pyside2/tests/pysidetest/testobject.cpp b/sources/pyside2/tests/pysidetest/testobject.cpp index 03a7a965c..441ae872f 100644 --- a/sources/pyside2/tests/pysidetest/testobject.cpp +++ b/sources/pyside2/tests/pysidetest/testobject.cpp @@ -52,3 +52,25 @@ void TestObject::emitSignalWithTypedefValue(int value) { emit signalWithTypedefValue(TypedefValue(value)); } + +QDebug operator<<(QDebug dbg, TestObject& testObject) +{ + QDebugStateSaver saver(dbg); + dbg.nospace() << "TestObject(id=" << testObject.idValue() << ") "; + return dbg; +} + +namespace PySideCPP { + QDebug operator<<(QDebug dbg, TestObjectWithNamespace& testObject) + { + QDebugStateSaver saver(dbg); + dbg.nospace() << "TestObjectWithNamespace(" << testObject.name() << ") "; + return dbg; + } + QDebug operator<<(QDebug dbg, TestObject2WithNamespace& testObject) + { + QDebugStateSaver saver(dbg); + dbg.nospace() << "TestObject2WithNamespace(" << testObject.name() << ") "; + return dbg; + } +} diff --git a/sources/pyside2/tests/pysidetest/testobject.h b/sources/pyside2/tests/pysidetest/testobject.h index 6cfb01101..f8a174d46 100644 --- a/sources/pyside2/tests/pysidetest/testobject.h +++ b/sources/pyside2/tests/pysidetest/testobject.h @@ -33,6 +33,7 @@ #include <QApplication> #include <QMetaType> #include <QVariant> +#include <QDebug> #ifdef pysidetest_EXPORTS #define PYSIDE_EXPORTS 1 #endif @@ -81,6 +82,7 @@ private: int m_idValue; QList<QObject*> m_children; }; +PYSIDE_API QDebug operator<<(QDebug dbg, TestObject &testObject); typedef int PySideInt; @@ -104,6 +106,16 @@ signals: void emitSignalWithNamespace(PySideCPP::TestObjectWithNamespace* obj); void emitSignalWithTypedef(PySideInt val); }; +PYSIDE_API QDebug operator<<(QDebug dbg, TestObjectWithNamespace &testObject); + +class PYSIDE_API TestObject2WithNamespace : public QObject +{ + Q_OBJECT +public: + TestObject2WithNamespace(QObject* parent) : QObject(parent) {} + QString name() { return "TestObject2WithNamespace"; } +}; +PYSIDE_API QDebug operator<<(QDebug dbg, TestObject2WithNamespace& testObject); } // Namespace PySideCPP diff --git a/sources/pyside2/tests/pysidetest/typedef_signal_test.py b/sources/pyside2/tests/pysidetest/typedef_signal_test.py index f7724b618..ecbfa35d4 100644 --- a/sources/pyside2/tests/pysidetest/typedef_signal_test.py +++ b/sources/pyside2/tests/pysidetest/typedef_signal_test.py @@ -26,8 +26,14 @@ ## ############################################################################# +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 PySide2.QtCore import QObject from testbinding import TestObject diff --git a/sources/pyside2/tests/pysidetest/typesystem_pysidetest.xml b/sources/pyside2/tests/pysidetest/typesystem_pysidetest.xml index 1904f236f..1e777edd2 100644 --- a/sources/pyside2/tests/pysidetest/typesystem_pysidetest.xml +++ b/sources/pyside2/tests/pysidetest/typesystem_pysidetest.xml @@ -37,6 +37,13 @@ <namespace-type name="PySideCPP"> <object-type name="TestObjectWithNamespace"/> + <object-type name="TestObject2WithNamespace"> + <add-function signature="__repr__" return-type="PyObject*"> + <inject-code class="target" position="beginning"> + %PYARG_0 = Shiboken::String::fromCString("TestObject2WithNamespace(injected_repr)"); + </inject-code> + </add-function> + </object-type> </namespace-type> <namespace-type name="PySideCPP2" generate="no"> diff --git a/sources/pyside2/tests/pysidetest/version_test.py b/sources/pyside2/tests/pysidetest/version_test.py index 447fafdeb..5cc34d8c3 100644 --- a/sources/pyside2/tests/pysidetest/version_test.py +++ b/sources/pyside2/tests/pysidetest/version_test.py @@ -28,7 +28,14 @@ ## ############################################################################# +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 PySide2 import __version_info__, __version__, QtCore class CheckForVariablesTest(unittest.TestCase): |