aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/QtCore
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/tests/QtCore')
-rw-r--r--sources/pyside6/tests/QtCore/CMakeLists.txt19
-rw-r--r--sources/pyside6/tests/QtCore/QtCore.pyproject148
-rw-r--r--sources/pyside6/tests/QtCore/attr_cache_py3k.py43
-rw-r--r--sources/pyside6/tests/QtCore/blocking_signals_test.py98
-rw-r--r--sources/pyside6/tests/QtCore/bug_1019.py41
-rw-r--r--sources/pyside6/tests/QtCore/bug_1063.py41
-rw-r--r--sources/pyside6/tests/QtCore/bug_1069.py37
-rw-r--r--sources/pyside6/tests/QtCore/bug_1313.py38
-rw-r--r--sources/pyside6/tests/QtCore/bug_278_test.py38
-rw-r--r--sources/pyside6/tests/QtCore/bug_300_test.py30
-rw-r--r--sources/pyside6/tests/QtCore/bug_324.py44
-rw-r--r--sources/pyside6/tests/QtCore/bug_332.py43
-rw-r--r--sources/pyside6/tests/QtCore/bug_408.py37
-rw-r--r--sources/pyside6/tests/QtCore/bug_428.py35
-rw-r--r--sources/pyside6/tests/QtCore/bug_462.py52
-rw-r--r--sources/pyside6/tests/QtCore/bug_505.py36
-rw-r--r--sources/pyside6/tests/QtCore/bug_515.py45
-rw-r--r--sources/pyside6/tests/QtCore/bug_606.py32
-rw-r--r--sources/pyside6/tests/QtCore/bug_656.py38
-rw-r--r--sources/pyside6/tests/QtCore/bug_686.py71
-rw-r--r--sources/pyside6/tests/QtCore/bug_699.py34
-rw-r--r--sources/pyside6/tests/QtCore/bug_706.py37
-rw-r--r--sources/pyside6/tests/QtCore/bug_820.py33
-rw-r--r--sources/pyside6/tests/QtCore/bug_826.py38
-rw-r--r--sources/pyside6/tests/QtCore/bug_829.py38
-rw-r--r--sources/pyside6/tests/QtCore/bug_835.py36
-rw-r--r--sources/pyside6/tests/QtCore/bug_920.py33
-rw-r--r--sources/pyside6/tests/QtCore/bug_927.py68
-rw-r--r--sources/pyside6/tests/QtCore/bug_931.py34
-rw-r--r--sources/pyside6/tests/QtCore/bug_938.py33
-rw-r--r--sources/pyside6/tests/QtCore/bug_953.py43
-rw-r--r--sources/pyside6/tests/QtCore/bug_987.py33
-rw-r--r--sources/pyside6/tests/QtCore/bug_994.py34
-rw-r--r--sources/pyside6/tests/QtCore/bug_PYSIDE-164.py51
-rw-r--r--sources/pyside6/tests/QtCore/bug_PYSIDE-2745.py38
-rw-r--r--sources/pyside6/tests/QtCore/bug_PYSIDE-41.py50
-rw-r--r--sources/pyside6/tests/QtCore/bug_PYSIDE-42.py33
-rw-r--r--sources/pyside6/tests/QtCore/child_event_test.py46
-rw-r--r--sources/pyside6/tests/QtCore/classinfo_test.py89
-rw-r--r--sources/pyside6/tests/QtCore/deepcopy_test.py39
-rw-r--r--sources/pyside6/tests/QtCore/deletelater_test.py42
-rw-r--r--sources/pyside6/tests/QtCore/destroysignal_test.py72
-rw-r--r--sources/pyside6/tests/QtCore/duck_punching_test.py60
-rw-r--r--sources/pyside6/tests/QtCore/emoji_string_test.py54
-rw-r--r--sources/pyside6/tests/QtCore/errormessages_with_features_test.py87
-rw-r--r--sources/pyside6/tests/QtCore/feature_with_uic/window.py53
-rw-r--r--sources/pyside6/tests/QtCore/feature_with_uic/window.ui62
-rw-r--r--sources/pyside6/tests/QtCore/feature_with_uic_test.py60
-rw-r--r--sources/pyside6/tests/QtCore/hash_test.py68
-rw-r--r--sources/pyside6/tests/QtCore/inherits_test.py33
-rw-r--r--sources/pyside6/tests/QtCore/loggingcategorymacros_test.py85
-rw-r--r--sources/pyside6/tests/QtCore/max_signals.py46
-rw-r--r--sources/pyside6/tests/QtCore/missing_symbols_test.py36
-rw-r--r--sources/pyside6/tests/QtCore/mockclass_test.py32
-rw-r--r--sources/pyside6/tests/QtCore/multiple_feature_test.py102
-rw-r--r--sources/pyside6/tests/QtCore/python_conversion.py39
-rw-r--r--sources/pyside6/tests/QtCore/qabs_test.py37
-rw-r--r--sources/pyside6/tests/QtCore/qabstractitemmodel_test.py40
-rw-r--r--sources/pyside6/tests/QtCore/qanimationgroup_test.py39
-rw-r--r--sources/pyside6/tests/QtCore/qbitarray_test.py50
-rw-r--r--sources/pyside6/tests/QtCore/qbytearray_concatenation_operator_test.py37
-rw-r--r--sources/pyside6/tests/QtCore/qbytearray_operator_iadd_test.py33
-rw-r--r--sources/pyside6/tests/QtCore/qbytearray_operator_test.py52
-rw-r--r--sources/pyside6/tests/QtCore/qbytearray_test.py83
-rw-r--r--sources/pyside6/tests/QtCore/qcalendar_test.py32
-rw-r--r--sources/pyside6/tests/QtCore/qcbor_test.py42
-rw-r--r--sources/pyside6/tests/QtCore/qcollator_test.py35
-rw-r--r--sources/pyside6/tests/QtCore/qcommandlineparser_test.py35
-rw-r--r--sources/pyside6/tests/QtCore/qcoreapplication_argv_test.py26
-rw-r--r--sources/pyside6/tests/QtCore/qcoreapplication_instance_test.py36
-rw-r--r--sources/pyside6/tests/QtCore/qcoreapplication_test.py31
-rw-r--r--sources/pyside6/tests/QtCore/qdatastream_test.py66
-rw-r--r--sources/pyside6/tests/QtCore/qdate_test.py35
-rw-r--r--sources/pyside6/tests/QtCore/qdatetime_test.py32
-rw-r--r--sources/pyside6/tests/QtCore/qdir_test.py40
-rw-r--r--sources/pyside6/tests/QtCore/qeasingcurve_test.py36
-rw-r--r--sources/pyside6/tests/QtCore/qenum_test.py83
-rw-r--r--sources/pyside6/tests/QtCore/qevent_test.py35
-rw-r--r--sources/pyside6/tests/QtCore/qfile_test.py52
-rw-r--r--sources/pyside6/tests/QtCore/qfileinfo_test.py39
-rw-r--r--sources/pyside6/tests/QtCore/qfileread_test.py35
-rw-r--r--sources/pyside6/tests/QtCore/qflags_test.py75
-rw-r--r--sources/pyside6/tests/QtCore/qhandle_test.py33
-rw-r--r--sources/pyside6/tests/QtCore/qinstallmsghandler_test.py52
-rw-r--r--sources/pyside6/tests/QtCore/qiodevice_buffered_read_test.py79
-rw-r--r--sources/pyside6/tests/QtCore/qiopipe_test.py37
-rw-r--r--sources/pyside6/tests/QtCore/qjsondocument_test.py31
-rw-r--r--sources/pyside6/tests/QtCore/qlinef_test.py35
-rw-r--r--sources/pyside6/tests/QtCore/qlocale_test.py55
-rw-r--r--sources/pyside6/tests/QtCore/qlockfile_test.py36
-rw-r--r--sources/pyside6/tests/QtCore/qmessageauthenticationcode_test.py33
-rw-r--r--sources/pyside6/tests/QtCore/qmetaobject_test.py199
-rw-r--r--sources/pyside6/tests/QtCore/qmetatype_test.py44
-rw-r--r--sources/pyside6/tests/QtCore/qmimedatabase_test.py41
-rw-r--r--sources/pyside6/tests/QtCore/qmodelindex_internalpointer_test.py58
-rw-r--r--sources/pyside6/tests/QtCore/qobject_children_segfault_test.py38
-rw-r--r--sources/pyside6/tests/QtCore/qobject_connect_notify_test.py76
-rw-r--r--sources/pyside6/tests/QtCore/qobject_destructor.py42
-rw-r--r--sources/pyside6/tests/QtCore/qobject_event_filter_test.py78
-rw-r--r--sources/pyside6/tests/QtCore/qobject_inherits_test.py56
-rw-r--r--sources/pyside6/tests/QtCore/qobject_objectproperty_test.py37
-rw-r--r--sources/pyside6/tests/QtCore/qobject_parent_test.py203
-rw-r--r--sources/pyside6/tests/QtCore/qobject_property_test.py32
-rw-r--r--sources/pyside6/tests/QtCore/qobject_protected_methods_test.py43
-rw-r--r--sources/pyside6/tests/QtCore/qobject_test.py76
-rw-r--r--sources/pyside6/tests/QtCore/qobject_timer_event_test.py48
-rw-r--r--sources/pyside6/tests/QtCore/qobject_tr_as_instance_test.py48
-rw-r--r--sources/pyside6/tests/QtCore/qoperatingsystemversion_test.py32
-rw-r--r--sources/pyside6/tests/QtCore/qpoint_test.py36
-rw-r--r--sources/pyside6/tests/QtCore/qprocess_test.py35
-rw-r--r--sources/pyside6/tests/QtCore/qproperty_decorator.py39
-rw-r--r--sources/pyside6/tests/QtCore/qrandomgenerator_test.py32
-rw-r--r--sources/pyside6/tests/QtCore/qrect_test.py48
-rw-r--r--sources/pyside6/tests/QtCore/qregularexpression_test.py37
-rw-r--r--sources/pyside6/tests/QtCore/qresource_test.py67
-rw-r--r--sources/pyside6/tests/QtCore/qrunnable_test.py46
-rw-r--r--sources/pyside6/tests/QtCore/qsettings_test.py79
-rw-r--r--sources/pyside6/tests/QtCore/qsharedmemory_client.py37
-rw-r--r--sources/pyside6/tests/QtCore/qsharedmemory_test.py74
-rw-r--r--sources/pyside6/tests/QtCore/qsize_test.py36
-rw-r--r--sources/pyside6/tests/QtCore/qslot_object_test.py54
-rw-r--r--sources/pyside6/tests/QtCore/qsocketnotifier_test.py36
-rw-r--r--sources/pyside6/tests/QtCore/qsrand_test.py39
-rw-r--r--sources/pyside6/tests/QtCore/qstandardpaths_test.py33
-rw-r--r--sources/pyside6/tests/QtCore/qstorageinfo_test.py33
-rw-r--r--sources/pyside6/tests/QtCore/qstring_test.py38
-rw-r--r--sources/pyside6/tests/QtCore/qsysinfo_test.py41
-rw-r--r--sources/pyside6/tests/QtCore/qtextstream_test.py35
-rw-r--r--sources/pyside6/tests/QtCore/qthread_prod_cons_test.py84
-rw-r--r--sources/pyside6/tests/QtCore/qthread_signal_test.py68
-rw-r--r--sources/pyside6/tests/QtCore/qthread_test.py101
-rw-r--r--sources/pyside6/tests/QtCore/qtimer_singleshot_test.py167
-rw-r--r--sources/pyside6/tests/QtCore/qtimer_timeout_test.py57
-rw-r--r--sources/pyside6/tests/QtCore/qtimezone_test.py32
-rw-r--r--sources/pyside6/tests/QtCore/qtnamespace_test.py34
-rw-r--r--sources/pyside6/tests/QtCore/qurl_test.py44
-rw-r--r--sources/pyside6/tests/QtCore/qurlquery_test.py37
-rw-r--r--sources/pyside6/tests/QtCore/quuid_test.py33
-rw-r--r--sources/pyside6/tests/QtCore/qversionnumber_test.py33
-rw-r--r--sources/pyside6/tests/QtCore/repr_test.py40
-rw-r--r--sources/pyside6/tests/QtCore/resources_mc.py35
-rw-r--r--sources/pyside6/tests/QtCore/setprop_on_ctor_test.py36
-rw-r--r--sources/pyside6/tests/QtCore/signal_sender.py92
-rw-r--r--sources/pyside6/tests/QtCore/snake_prop_feature_test.py124
-rw-r--r--sources/pyside6/tests/QtCore/staticMetaObject_test.py33
-rw-r--r--sources/pyside6/tests/QtCore/static_method_test.py32
-rw-r--r--sources/pyside6/tests/QtCore/thread_signals_test.py50
-rw-r--r--sources/pyside6/tests/QtCore/tr_noop_test.py39
-rw-r--r--sources/pyside6/tests/QtCore/translation_test.py78
-rw-r--r--sources/pyside6/tests/QtCore/unaryoperator_test.py42
-rw-r--r--sources/pyside6/tests/QtCore/unicode_test.py38
-rw-r--r--sources/pyside6/tests/QtCore/versioninfo_test.py31
152 files changed, 3272 insertions, 4378 deletions
diff --git a/sources/pyside6/tests/QtCore/CMakeLists.txt b/sources/pyside6/tests/QtCore/CMakeLists.txt
index f9044a1b6..f0228d943 100644
--- a/sources/pyside6/tests/QtCore/CMakeLists.txt
+++ b/sources/pyside6/tests/QtCore/CMakeLists.txt
@@ -1,5 +1,10 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
PYSIDE_TEST(attr_cache_py3k.py)
PYSIDE_TEST(bug_278_test.py)
+PYSIDE_TEST(bug_300_test.py)
+PYSIDE_TEST(bug_324.py)
PYSIDE_TEST(bug_332.py)
PYSIDE_TEST(bug_408.py)
PYSIDE_TEST(bug_428.py)
@@ -26,8 +31,10 @@ PYSIDE_TEST(bug_1019.py)
PYSIDE_TEST(bug_1063.py)
PYSIDE_TEST(bug_1069.py)
PYSIDE_TEST(bug_1313.py)
+PYSIDE_TEST(bug_PYSIDE-41.py)
PYSIDE_TEST(bug_PYSIDE-42.py)
PYSIDE_TEST(bug_PYSIDE-164.py)
+PYSIDE_TEST(bug_PYSIDE-2745.py)
PYSIDE_TEST(blocking_signals_test.py)
PYSIDE_TEST(classinfo_test.py)
PYSIDE_TEST(child_event_test.py)
@@ -37,6 +44,7 @@ PYSIDE_TEST(destroysignal_test.py)
PYSIDE_TEST(duck_punching_test.py)
PYSIDE_TEST(emoji_string_test.py)
PYSIDE_TEST(errormessages_with_features_test.py)
+PYSIDE_TEST(feature_with_uic_test.py)
PYSIDE_TEST(hash_test.py)
PYSIDE_TEST(inherits_test.py)
PYSIDE_TEST(max_signals.py)
@@ -52,18 +60,17 @@ PYSIDE_TEST(qbytearray_concatenation_operator_test.py)
PYSIDE_TEST(qbytearray_operator_iadd_test.py)
PYSIDE_TEST(qbytearray_operator_test.py)
PYSIDE_TEST(qbytearray_test.py)
-if (Qt${QT_MAJOR_VERSION}Core_VERSION VERSION_EQUAL 5.14.0
- OR Qt${QT_MAJOR_VERSION}Core_VERSION VERSION_GREATER 5.14.0)
- PYSIDE_TEST(qcalendar_test.py)
-endif()
+PYSIDE_TEST(qcalendar_test.py)
PYSIDE_TEST(qcbor_test.py)
PYSIDE_TEST(qcollator_test.py)
PYSIDE_TEST(qcommandlineparser_test.py)
+PYSIDE_TEST(qcoreapplication_argv_test.py)
PYSIDE_TEST(qcoreapplication_instance_test.py)
PYSIDE_TEST(qcoreapplication_test.py)
PYSIDE_TEST(qdatastream_test.py)
PYSIDE_TEST(qdatetime_test.py)
PYSIDE_TEST(qdate_test.py)
+PYSIDE_TEST(qdir_test.py)
PYSIDE_TEST(qeasingcurve_test.py)
PYSIDE_TEST(qenum_test.py)
PYSIDE_TEST(qevent_test.py)
@@ -78,6 +85,7 @@ PYSIDE_TEST(qlocale_test.py)
PYSIDE_TEST(qlockfile_test.py)
PYSIDE_TEST(qmessageauthenticationcode_test.py)
PYSIDE_TEST(qmetaobject_test.py)
+PYSIDE_TEST(qmetatype_test.py)
PYSIDE_TEST(qmimedatabase_test.py)
PYSIDE_TEST(qmodelindex_internalpointer_test.py)
PYSIDE_TEST(qobject_children_segfault_test.py)
@@ -122,6 +130,7 @@ PYSIDE_TEST(quuid_test.py)
PYSIDE_TEST(qversionnumber_test.py)
PYSIDE_TEST(repr_test.py)
PYSIDE_TEST(setprop_on_ctor_test.py)
+PYSIDE_TEST(signal_sender.py)
PYSIDE_TEST(snake_prop_feature_test.py)
PYSIDE_TEST(staticMetaObject_test.py)
PYSIDE_TEST(static_method_test.py)
@@ -131,6 +140,8 @@ PYSIDE_TEST(translation_test.py)
PYSIDE_TEST(unaryoperator_test.py)
PYSIDE_TEST(unicode_test.py)
PYSIDE_TEST(versioninfo_test.py)
+PYSIDE_TEST(loggingcategorymacros_test.py)
+PYSIDE_TEST(qrunnable_test.py)
if(X11)
PYSIDE_TEST(qhandle_test.py)
diff --git a/sources/pyside6/tests/QtCore/QtCore.pyproject b/sources/pyside6/tests/QtCore/QtCore.pyproject
new file mode 100644
index 000000000..bd5951316
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/QtCore.pyproject
@@ -0,0 +1,148 @@
+{
+ "files": ["attr_cache_py3k.py",
+ "blocking_signals_test.py",
+ "bug_1019.py",
+ "bug_1063.py",
+ "bug_1069.py",
+ "bug_1313.py",
+ "bug_278_test.py",
+ "bug_300_test.py",
+ "bug_324.py",
+ "bug_332.py",
+ "bug_408.py",
+ "bug_428.py",
+ "bug_462.py",
+ "bug_505.py",
+ "bug_515.py",
+ "bug_606.py",
+ "bug_656.py",
+ "bug_686.py",
+ "bug_699.py",
+ "bug_706.py",
+ "bug_820.py",
+ "bug_826.py",
+ "bug_829.py",
+ "bug_835.py",
+ "bug_920.py",
+ "bug_927.py",
+ "bug_931.py",
+ "bug_938.py",
+ "bug_953.py",
+ "bug_987.py",
+ "bug_994.py",
+ "bug_PYSIDE-164.py",
+ "bug_PYSIDE-41.py",
+ "bug_PYSIDE-42.py",
+ "child_event_test.py",
+ "classinfo_test.py",
+ "deepcopy_test.py",
+ "deletelater_test.py",
+ "destroysignal_test.py",
+ "duck_punching_test.py",
+ "emoji_string_test.py",
+ "errormessages_with_features_test.py",
+ "feature_with_uic/window.py",
+ "feature_with_uic/window.ui",
+ "feature_with_uic_test.py",
+ "hash_test.py",
+ "inherits_test.py",
+ "loggingcategorymacros_test.py",
+ "max_signals.py",
+ "missing_symbols_test.py",
+ "mockclass_test.py",
+ "multiple_feature_test.py",
+ "python_conversion.py",
+ "qabs_test.py",
+ "qabstractitemmodel_test.py",
+ "qanimationgroup_test.py",
+ "qbitarray_test.py",
+ "qbytearray_concatenation_operator_test.py",
+ "qbytearray_operator_iadd_test.py",
+ "qbytearray_operator_test.py",
+ "qbytearray_test.py",
+ "qcalendar_test.py",
+ "qcbor_test.py",
+ "qcollator_test.py",
+ "qcommandlineparser_test.py",
+ "qcoreapplication_argv_test.py",
+ "qcoreapplication_instance_test.py",
+ "qcoreapplication_test.py",
+ "qdatastream_test.py",
+ "qdate_test.py",
+ "qdatetime_test.py",
+ "qdir_test.py",
+ "qeasingcurve_test.py",
+ "qenum_test.py",
+ "qevent_test.py",
+ "qfile_test.py",
+ "qfileinfo_test.py",
+ "qfileread_test.py",
+ "qflags_test.py",
+ "qhandle_test.py",
+ "qinstallmsghandler_test.py",
+ "qjsondocument_test.py",
+ "qlinef_test.py",
+ "qlocale_test.py",
+ "qlockfile_test.py",
+ "qmessageauthenticationcode_test.py",
+ "qmetaobject_test.py",
+ "qmetatype_test.py",
+ "qmimedatabase_test.py",
+ "qmodelindex_internalpointer_test.py",
+ "qobject_children_segfault_test.py",
+ "qobject_connect_notify_test.py",
+ "qobject_destructor.py",
+ "qobject_event_filter_test.py",
+ "qobject_inherits_test.py",
+ "qobject_objectproperty_test.py",
+ "qobject_parent_test.py",
+ "qobject_property_test.py",
+ "qobject_protected_methods_test.py",
+ "qobject_test.py",
+ "qobject_timer_event_test.py",
+ "qobject_tr_as_instance_test.py",
+ "qoperatingsystemversion_test.py",
+ "qpoint_test.py",
+ "qprocess_test.py",
+ "qproperty_decorator.py",
+ "qrandomgenerator_test.py",
+ "qrect_test.py",
+ "qregularexpression_test.py",
+ "qresource_test.py",
+ "qsettings_test.py",
+ "qsharedmemory_client.py",
+ "qsharedmemory_test.py",
+ "qsize_test.py",
+ "qslot_object_test.py",
+ "qsocketnotifier_test.py",
+ "qsrand_test.py",
+ "qstandardpaths_test.py",
+ "qstorageinfo_test.py",
+ "qstring_test.py",
+ "qsysinfo_test.py",
+ "qtextstream_test.py",
+ "qthread_prod_cons_test.py",
+ "qthread_signal_test.py",
+ "qthread_test.py",
+ "qtimer_singleshot_test.py",
+ "qtimer_timeout_test.py",
+ "qtimezone_test.py",
+ "qtnamespace_test.py",
+ "qurl_test.py",
+ "qurlquery_test.py",
+ "quuid_test.py",
+ "qversionnumber_test.py",
+ "repr_test.py",
+ "resources.qrc",
+ "resources_mc.py",
+ "setprop_on_ctor_test.py",
+ "snake_prop_feature_test.py",
+ "staticMetaObject_test.py",
+ "static_method_test.py",
+ "thread_signals_test.py",
+ "tr_noop_test.py",
+ "translation_test.py",
+ "unaryoperator_test.py",
+ "unicode_test.py",
+ "versioninfo_test.py"]
+}
diff --git a/sources/pyside6/tests/QtCore/attr_cache_py3k.py b/sources/pyside6/tests/QtCore/attr_cache_py3k.py
index 4044b5f64..ca66e0e17 100644
--- a/sources/pyside6/tests/QtCore/attr_cache_py3k.py
+++ b/sources/pyside6/tests/QtCore/attr_cache_py3k.py
@@ -1,43 +1,6 @@
-# This Python file uses the following encoding: utf-8
-
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+from __future__ import annotations
'''
Unit tests for attribute cache in Python 3
diff --git a/sources/pyside6/tests/QtCore/blocking_signals_test.py b/sources/pyside6/tests/QtCore/blocking_signals_test.py
index 87d0701b8..48d8ab7b9 100644
--- a/sources/pyside6/tests/QtCore/blocking_signals_test.py
+++ b/sources/pyside6/tests/QtCore/blocking_signals_test.py
@@ -1,33 +1,10 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
''' Test case for QObject.signalsBlocked() and blockSignal()'''
+import gc
import os
import sys
from tempfile import mkstemp
@@ -38,7 +15,13 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import QObject, SIGNAL, QFile, QSignalBlocker
+from PySide6.QtCore import QObject, Signal, QFile, QSignalBlocker
+
+
+class Sender(QObject):
+ mysignal = Signal()
+ mysignal_int_int = Signal(int, int)
+
class TestSignalsBlockedBasic(unittest.TestCase):
'''Basic test case for signalsBlocked'''
@@ -59,6 +42,23 @@ class TestSignalsBlockedBasic(unittest.TestCase):
blocker.reblock()
self.assertTrue(obj.signalsBlocked())
del blocker
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+ self.assertTrue(not obj.signalsBlocked())
+
+ def testContext(self):
+ obj = QObject()
+ self.assertTrue(not obj.signalsBlocked())
+ with QSignalBlocker(obj):
+ self.assertTrue(obj.signalsBlocked())
+ self.assertTrue(not obj.signalsBlocked())
+
+ def testContextWithAs(self):
+ obj = QObject()
+ self.assertTrue(not obj.signalsBlocked())
+ with QSignalBlocker(obj) as blocker:
+ self.assertTrue(obj.signalsBlocked())
+ self.assertEqual(type(blocker), QSignalBlocker)
self.assertTrue(not obj.signalsBlocked())
@@ -66,53 +66,57 @@ class TestSignalsBlocked(unittest.TestCase):
'''Test case to check if the signals are really blocked'''
def setUp(self):
- #Set up the basic resources needed
- self.obj = QObject()
+ # Set up the basic resources needed
+ self.obj = Sender()
self.args = tuple()
self.called = False
def tearDown(self):
- #Delete used resources
+ # Delete used resources
del self.obj
del self.args
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
def callback(self, *args):
- #Default callback
- if args == self.args:
+ # Default callback
+ if args == self.args:
self.called = True
else:
raise TypeError("Invalid arguments")
def testShortCircuitSignals(self):
- #Blocking of Python short-circuit signals
- QObject.connect(self.obj, SIGNAL('mysignal()'), self.callback)
+ # Blocking of Python short-circuit signals
+ self.obj.mysignal.connect(self.callback)
- self.obj.emit(SIGNAL('mysignal()'))
+ self.obj.mysignal.emit()
self.assertTrue(self.called)
self.called = False
self.obj.blockSignals(True)
- self.obj.emit(SIGNAL('mysignal()'))
+ self.obj.mysignal.emit()
self.assertTrue(not self.called)
def testPythonSignals(self):
- #Blocking of Python typed signals
- QObject.connect(self.obj, SIGNAL('mysignal(int,int)'), self.callback)
+ # Blocking of Python typed signals
+
+ self.obj.mysignal_int_int.connect(self.callback)
self.args = (1, 3)
- self.obj.emit(SIGNAL('mysignal(int,int)'), *self.args)
+ self.obj.mysignal_int_int.emit(*self.args)
self.assertTrue(self.called)
self.called = False
self.obj.blockSignals(True)
- self.obj.emit(SIGNAL('mysignal(int,int)'), *self.args)
+ self.obj.mysignal_int_int.emit(*self.args)
self.assertTrue(not self.called)
+
class TestQFileSignalBlocking(unittest.TestCase):
'''Test case for blocking the signal QIODevice.aboutToClose()'''
def setUp(self):
- #Set up the needed resources - A temp file and a QFile
+ # Set up the needed resources - A temp file and a QFile
self.called = False
handle, self.filename = mkstemp()
os.close(handle)
@@ -120,18 +124,20 @@ class TestQFileSignalBlocking(unittest.TestCase):
self.qfile = QFile(self.filename)
def tearDown(self):
- #Release acquired resources
+ # Release acquired resources
os.remove(self.filename)
del self.qfile
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
def callback(self):
- #Default callback
+ # Default callback
self.called = True
def testAboutToCloseBlocking(self):
- #QIODevice.aboutToClose() blocking
+ # QIODevice.aboutToClose() blocking
- QObject.connect(self.qfile, SIGNAL('aboutToClose()'), self.callback)
+ self.qfile.aboutToClose.connect(self.callback)
self.assertTrue(self.qfile.open(QFile.ReadOnly))
self.qfile.close()
diff --git a/sources/pyside6/tests/QtCore/bug_1019.py b/sources/pyside6/tests/QtCore/bug_1019.py
index 349ccb2cb..0257dda94 100644
--- a/sources/pyside6/tests/QtCore/bug_1019.py
+++ b/sources/pyside6/tests/QtCore/bug_1019.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -35,17 +11,19 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import QCoreApplication, QTimer, Slot
+
class MyTimer (QTimer):
def __init__(self):
- QTimer.__init__(self)
+ super().__init__()
self.startCalled = False
@Slot()
def slotUsedToIncreaseMethodOffset(self):
pass
+
class MyTimer2 (MyTimer):
@Slot()
@@ -53,16 +31,19 @@ class MyTimer2 (MyTimer):
pass
def start(self):
+ """ 'Overrides' non-virtual slot QTimer.start()."""
self.startCalled = True
QCoreApplication.instance().quit()
+
class TestBug1019 (unittest.TestCase):
def testIt(self):
app = QCoreApplication([])
t = MyTimer2()
QTimer.singleShot(0, t.start)
- app.exec_()
+ app.exec()
self.assertTrue(t.startCalled)
+
if __name__ == "__main__":
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_1063.py b/sources/pyside6/tests/QtCore/bug_1063.py
index 8ccd9a593..fec6836a1 100644
--- a/sources/pyside6/tests/QtCore/bug_1063.py
+++ b/sources/pyside6/tests/QtCore/bug_1063.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
''' unit test for BUG #1063 '''
@@ -38,17 +14,17 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6 import QtCore
+from PySide6.QtCore import QFile, QIODevice, QTextStream
class QTextStreamTestCase(unittest.TestCase):
def setUp(self):
self.temp_file = tempfile.NamedTemporaryFile(delete=False)
self.temp_file.close()
- self.f = QtCore.QFile(self.temp_file.name)
- self.f.open(QtCore.QIODevice.WriteOnly)
+ self.f = QFile(self.temp_file.name)
+ self.f.open(QIODevice.WriteOnly)
self.strings = ('foo', 'bar')
- self.stream = QtCore.QTextStream(self.f)
+ self.stream = QTextStream(self.f)
def testIt(self):
for s in self.strings:
@@ -57,9 +33,10 @@ class QTextStreamTestCase(unittest.TestCase):
self.f.close()
# make sure we didn't get an empty file
- self.assertNotEqual(QtCore.QFile(self.temp_file.name).size(), 0)
+ self.assertNotEqual(QFile(self.temp_file.name).size(), 0)
os.unlink(self.temp_file.name)
+
if __name__ == "__main__":
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_1069.py b/sources/pyside6/tests/QtCore/bug_1069.py
index a62ff5530..746897a80 100644
--- a/sources/pyside6/tests/QtCore/bug_1069.py
+++ b/sources/pyside6/tests/QtCore/bug_1069.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
''' unit test for BUG #1069 '''
@@ -37,13 +13,13 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6 import QtCore
+from PySide6.QtCore import QByteArray, QDataStream, QIODevice
class QDataStreamOpOverloadTestCase(unittest.TestCase):
def setUp(self):
- self.ba = QtCore.QByteArray()
- self.stream = QtCore.QDataStream(self.ba, QtCore.QIODevice.WriteOnly)
+ self.ba = QByteArray()
+ self.stream = QDataStream(self.ba, QIODevice.WriteOnly)
def testIt(self):
self.stream << "hello"
@@ -55,5 +31,6 @@ class QDataStreamOpOverloadTestCase(unittest.TestCase):
self.assertEqual(ok, True)
+
if __name__ == "__main__":
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_1313.py b/sources/pyside6/tests/QtCore/bug_1313.py
index 01a76f5c9..3d66a6d2c 100644
--- a/sources/pyside6/tests/QtCore/bug_1313.py
+++ b/sources/pyside6/tests/QtCore/bug_1313.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
''' unit test for BUG #1313 '''
@@ -37,11 +13,11 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6 import QtCore
+from PySide6.QtCore import QObject, Signal
-class MyQObject(QtCore.QObject):
- sig = QtCore.Signal()
+class MyQObject(QObject):
+ sig = Signal()
demo_coroutine_definition_code = """
@@ -67,7 +43,7 @@ def demo_generator():
my_qobject = MyQObject()
my_qobject.sig.connect(lambda: None)
return
- yield # to make it a generator
+ yield # to make it a generator
class GeneratorRaisesStopIterationTestCase(unittest.TestCase):
diff --git a/sources/pyside6/tests/QtCore/bug_278_test.py b/sources/pyside6/tests/QtCore/bug_278_test.py
index aadaaf4d9..d929dc10c 100644
--- a/sources/pyside6/tests/QtCore/bug_278_test.py
+++ b/sources/pyside6/tests/QtCore/bug_278_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,22 +12,23 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6 import QtCore
+from PySide6.QtCore import QObject
+
def setValue(o):
values = ['Name']
o.setProperty('test1', values)
+
class QQtVersionTest(unittest.TestCase):
'''Tests for QVariant conversion of QStringList'''
def testGet(self):
- o = QtCore.QObject()
+ o = QObject()
setValue(o)
self.assertEqual(o.property('test1'), ['Name'])
-
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_300_test.py b/sources/pyside6/tests/QtCore/bug_300_test.py
new file mode 100644
index 000000000..1862dc56a
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/bug_300_test.py
@@ -0,0 +1,30 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import QModelIndex, QStringListModel
+
+
+class TestQAbstractItemModelSignals(unittest.TestCase):
+ def sigCallback(self, index, r, c):
+ self._called = True
+
+ def testSignals(self):
+ self._called = False
+ m = QStringListModel()
+ m.rowsAboutToBeInserted[QModelIndex, int, int].connect(self.sigCallback)
+ m.insertRows(0, 3)
+ self.assertTrue(self._called)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_324.py b/sources/pyside6/tests/QtCore/bug_324.py
new file mode 100644
index 000000000..a93f94089
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/bug_324.py
@@ -0,0 +1,44 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+''' Test bug 324: http://bugs.openbossa.org/show_bug.cgi?id=324'''
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import QCoreApplication, QObject, Signal
+
+
+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 = QCoreApplication([])
+ 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/QtCore/bug_332.py b/sources/pyside6/tests/QtCore/bug_332.py
index 7d7be4d05..9e910de1f 100644
--- a/sources/pyside6/tests/QtCore/bug_332.py
+++ b/sources/pyside6/tests/QtCore/bug_332.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,17 +12,19 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6 import QtCore
+from PySide6.QtCore import QMutex
+
+
+class Lock(QMutex):
+ def tryLock(self, timeout=10):
+ return QMutex.tryLock(self, timeout)
-class Lock(QtCore.QMutex):
- def tryLock(self,timeoutt=10):
- return QtCore.QMutex.tryLock(self,timeoutt)
class TestBug(unittest.TestCase):
def testCase(self):
l = Lock()
- l.tryLock() # this cause a assertion
+ l.tryLock() # this cause a assertion
if __name__ == '__main__':
diff --git a/sources/pyside6/tests/QtCore/bug_408.py b/sources/pyside6/tests/QtCore/bug_408.py
index 96e1614e9..e8bc45636 100644
--- a/sources/pyside6/tests/QtCore/bug_408.py
+++ b/sources/pyside6/tests/QtCore/bug_408.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -35,11 +11,12 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import QIODevice, QTextStream
+
class MyDevice(QIODevice):
def __init__(self, txt):
- QIODevice.__init__(self)
+ super().__init__()
self.txt = txt
self.ptr = 0
@@ -49,6 +26,7 @@ class MyDevice(QIODevice):
self.ptr += size
return retval
+
class QIODeviceTest(unittest.TestCase):
def testIt(self):
@@ -59,5 +37,6 @@ class QIODeviceTest(unittest.TestCase):
self.assertEqual(s.readLine(), "hello world")
self.assertEqual(s.readLine(), "hello again")
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_428.py b/sources/pyside6/tests/QtCore/bug_428.py
index da065c6de..11617aaf7 100644
--- a/sources/pyside6/tests/QtCore/bug_428.py
+++ b/sources/pyside6/tests/QtCore/bug_428.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,10 +13,12 @@ init_test_paths(False)
from PySide6.QtCore import QObject
+
class MyBaseObject(QObject):
def __init__(self, number):
self.myMember = 'myMember' + number
- QObject.__init__(self)
+ super().__init__()
+
class QObjectConstructorTest(unittest.TestCase):
def testBug(self):
@@ -49,5 +27,6 @@ class QObjectConstructorTest(unittest.TestCase):
obj = MyBaseObject(number)
self.assertEqual(obj.myMember, 'myMember' + number)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_462.py b/sources/pyside6/tests/QtCore/bug_462.py
index da048c0fb..830a4c148 100644
--- a/sources/pyside6/tests/QtCore/bug_462.py
+++ b/sources/pyside6/tests/QtCore/bug_462.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,25 +13,28 @@ init_test_paths(False)
from PySide6.QtCore import QObject, QCoreApplication, QEvent, QThread
+
class MyEvent(QEvent):
- def __init__(self,i):
+ def __init__(self, i):
print("TYPE:", type(QEvent.User))
- super(MyEvent,self).__init__(QEvent.Type(QEvent.User + 100 ))
+ super().__init__(QEvent.Type(QEvent.User))
self.i = i
+
class MyThread (QThread):
- def __init__(self,owner):
- super(MyThread,self).__init__()
- self.owner=owner;
+ def __init__(self, owner):
+ super().__init__()
+ self.owner = owner
def run(self):
for i in range(3):
- e=MyEvent(i);
- QCoreApplication.postEvent(self.owner,e)
+ e = MyEvent(i)
+ QCoreApplication.postEvent(self.owner, e)
+
class MyBaseObject(QObject):
def __init__(self):
- QObject.__init__(self)
+ super().__init__()
self.events = []
self.t = MyThread(self)
self.t.start()
@@ -71,10 +50,11 @@ class CheckForEventsTypes(unittest.TestCase):
def testTypes(self):
o = MyBaseObject()
o.app = QCoreApplication(sys.argv)
- o.app.exec_()
+ o.app.exec()
for e in o.events:
self.assertTrue(isinstance(e, MyEvent))
o.app = None
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_505.py b/sources/pyside6/tests/QtCore/bug_505.py
index 5b3fba93d..8c4a045df 100644
--- a/sources/pyside6/tests/QtCore/bug_505.py
+++ b/sources/pyside6/tests/QtCore/bug_505.py
@@ -1,31 +1,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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+import gc
import os
import sys
import unittest
@@ -37,6 +14,7 @@ init_test_paths(False)
from PySide6.QtCore import QObject
+
class MyBaseObject(QObject):
def __init__(self, parent=None):
QObject.__init__(self, parent)
@@ -46,12 +24,16 @@ class MyBaseObject(QObject):
if self.objectName() != "PySide":
raise NameError('Fail')
+
class CheckForEventsTypes(unittest.TestCase):
def testDelObject(self):
p = MyBaseObject()
o = MyBaseObject(p)
del o
del p
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_515.py b/sources/pyside6/tests/QtCore/bug_515.py
index 5a5264486..f63e86c95 100644
--- a/sources/pyside6/tests/QtCore/bug_515.py
+++ b/sources/pyside6/tests/QtCore/bug_515.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
""" Unittest for bug #515 """
""" http://bugs.openbossa.org/show_bug.cgi?id=515 """
@@ -38,18 +14,23 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1] / "util"))
from init_paths import init_test_paths
init_test_paths()
-from PySide6 import QtCore
+from PySide6.QtCore import QCoreApplication, qAddPostRoutine
+
callCleanup = False
+
+
def _cleanup():
global callCleanup
callCleanup = True
+
def _checkCleanup():
global callCleanup
- assert(callCleanup)
+ assert (callCleanup)
+
-app = QtCore.QCoreApplication([])
-QtCore.qAddPostRoutine(_cleanup)
-QtCore.qAddPostRoutine(_checkCleanup)
+app = QCoreApplication([])
+qAddPostRoutine(_cleanup)
+qAddPostRoutine(_checkCleanup)
del app
diff --git a/sources/pyside6/tests/QtCore/bug_606.py b/sources/pyside6/tests/QtCore/bug_606.py
index abe4ab2ca..8e6a9384a 100644
--- a/sources/pyside6/tests/QtCore/bug_606.py
+++ b/sources/pyside6/tests/QtCore/bug_606.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -40,6 +16,7 @@ from PySide6.QtCore import QPoint, QPointF
from PySide6.QtCore import QLine, QLineF
from PySide6.QtCore import QSize, QSizeF
+
class testCases(unittest.TestCase):
def testQPointToTuple(self):
p = QPoint(1, 2)
@@ -65,5 +42,6 @@ class testCases(unittest.TestCase):
s = QSizeF(1, 2)
self.assertEqual((1, 2), s.toTuple())
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_656.py b/sources/pyside6/tests/QtCore/bug_656.py
index b047875c2..75131326c 100644
--- a/sources/pyside6/tests/QtCore/bug_656.py
+++ b/sources/pyside6/tests/QtCore/bug_656.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -35,12 +11,14 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1] / "util"))
from init_paths import init_test_paths
init_test_paths()
-from PySide6.QtCore import *
+from PySide6.QtCore import QCoreApplication
+
class CoreApp(QCoreApplication):
- def __init__(self,*args):
- super(CoreApp,self).__init__(*args)
+ def __init__(self, *args):
+ super().__init__(*args)
# It shouldn't crash after the __init__ call
+
import sys
app = CoreApp(sys.argv)
diff --git a/sources/pyside6/tests/QtCore/bug_686.py b/sources/pyside6/tests/QtCore/bug_686.py
index d6394bb90..808e42b72 100644
--- a/sources/pyside6/tests/QtCore/bug_686.py
+++ b/sources/pyside6/tests/QtCore/bug_686.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -35,11 +11,13 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import (QMutex, QMutexLocker, QReadLocker, QReadWriteLock,
+ QThread, QWriteLocker)
+
class MyWriteThread(QThread):
def __init__(self, lock):
- QThread.__init__(self)
+ super().__init__()
self.lock = lock
self.started = False
self.canQuit = False
@@ -49,10 +27,12 @@ class MyWriteThread(QThread):
while not self.lock.tryLockForWrite():
pass
self.canQuit = True
+ self.lock.unlock()
+
class MyReadThread(QThread):
def __init__(self, lock):
- QThread.__init__(self)
+ super().__init__()
self.lock = lock
self.started = False
self.canQuit = False
@@ -62,10 +42,12 @@ class MyReadThread(QThread):
while not self.lock.tryLockForRead():
pass
self.canQuit = True
+ self.lock.unlock()
+
class MyMutexedThread(QThread):
def __init__(self, mutex):
- QThread.__init__(self)
+ super().__init__()
self.mutex = mutex
self.started = False
self.canQuit = False
@@ -77,6 +59,7 @@ class MyMutexedThread(QThread):
self.mutex.unlock()
self.canQuit = True
+
class TestQMutex (unittest.TestCase):
def testReadLocker(self):
@@ -86,10 +69,10 @@ class TestQMutex (unittest.TestCase):
with QReadLocker(lock):
thread.start()
while not thread.started:
- pass
+ QThread.msleep(10)
self.assertFalse(thread.canQuit)
- thread.wait(2000)
+ self.assertTrue(thread.wait(2000))
self.assertTrue(thread.canQuit)
def testWriteLocker(self):
@@ -99,10 +82,10 @@ class TestQMutex (unittest.TestCase):
with QWriteLocker(lock):
thread.start()
while not thread.started:
- pass
+ QThread.msleep(10)
self.assertFalse(thread.canQuit)
- thread.wait(2000)
+ self.assertTrue(thread.wait(2000))
self.assertTrue(thread.canQuit)
def testMutexLocker(self):
@@ -112,11 +95,25 @@ class TestQMutex (unittest.TestCase):
with QMutexLocker(mutex):
thread.start()
while not thread.started:
- pass
+ QThread.msleep(10)
self.assertFalse(thread.canQuit)
- thread.wait(2000)
+ self.assertTrue(thread.wait(2000))
self.assertTrue(thread.canQuit)
+ def testWithAsLocker(self):
+ lock = QReadWriteLock()
+ with QReadLocker(lock) as locker:
+ self.assertTrue(isinstance(locker, QReadLocker))
+ with QWriteLocker(lock) as locker:
+ self.assertTrue(isinstance(locker, QWriteLocker))
+ mutex = QMutex()
+ with QMutexLocker(mutex) as locker:
+ self.assertTrue(isinstance(locker, QMutexLocker))
+ with self.assertRaises(TypeError):
+ with QMutexLocker(lock) as locker:
+ pass
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_699.py b/sources/pyside6/tests/QtCore/bug_699.py
index fcba92def..dbd686cdd 100644
--- a/sources/pyside6/tests/QtCore/bug_699.py
+++ b/sources/pyside6/tests/QtCore/bug_699.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -35,7 +11,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import QObject, Property
+
class TestBug699 (unittest.TestCase):
@@ -49,5 +26,6 @@ class TestBug699 (unittest.TestCase):
def testIt(self):
self.assertRaises(TypeError, self.defClass)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_706.py b/sources/pyside6/tests/QtCore/bug_706.py
index 47b25b641..1fa04f77f 100644
--- a/sources/pyside6/tests/QtCore/bug_706.py
+++ b/sources/pyside6/tests/QtCore/bug_706.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -35,12 +11,14 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import QAbstractListModel, QCoreApplication, QModelIndex
+
class MyModel (QAbstractListModel):
- def rowCount(self, parent = None):
+ def rowCount(self, parent=None):
return 3
+
class TestBug706(unittest.TestCase):
def mySlot(self, idx, start, end):
@@ -58,5 +36,6 @@ class TestBug706(unittest.TestCase):
self.assertEqual(self.start, 0)
self.assertEqual(self.end, 1)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_820.py b/sources/pyside6/tests/QtCore/bug_820.py
index 501dd9ce1..182fea41c 100644
--- a/sources/pyside6/tests/QtCore/bug_820.py
+++ b/sources/pyside6/tests/QtCore/bug_820.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import functools
import os
@@ -38,6 +14,7 @@ init_test_paths(False)
from PySide6.QtCore import QObject, Slot, Signal, SIGNAL
+
def log_exception():
def log_exception_decorator(func):
@functools.wraps(func)
@@ -64,6 +41,7 @@ def log_exception2():
return log_exception_decorator
+
class MyObject(QObject):
def __init__(self, parent=None):
@@ -99,6 +77,7 @@ class SlotWithDecoratorTest(unittest.TestCase):
self.assertTrue(o._mySlotcalled)
self.assertTrue(o._mySlot2called)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_826.py b/sources/pyside6/tests/QtCore/bug_826.py
index 2b16c8288..0e639e697 100644
--- a/sources/pyside6/tests/QtCore/bug_826.py
+++ b/sources/pyside6/tests/QtCore/bug_826.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -41,11 +17,12 @@ import PySide6
TEST_EVENT_TYPE = QEvent.Type(QEvent.registerEventType())
+
class TestEvent(QEvent):
- TestEventType = QEvent.Type(QEvent.registerEventType())
+ TestEventType = QEvent.Type(TEST_EVENT_TYPE)
def __init__(self, rand=0):
- super(TestEvent, self).__init__(TestEvent.TestEventType)
+ super().__init__(TestEvent.TestEventType)
self._rand = rand
def getRand(self):
@@ -57,9 +34,6 @@ class TestEnums(unittest.TestCase):
self.assertTrue(QEvent.User <= TestEvent.TestEventType <= QEvent.MaxUser)
self.assertTrue(QEvent.User <= TEST_EVENT_TYPE <= QEvent.MaxUser)
- def testUserTypesRepr(self):
- self.assertEqual(eval(repr(TestEvent.TestEventType)), TestEvent.TestEventType)
- self.assertEqual(eval(repr(TEST_EVENT_TYPE)), TEST_EVENT_TYPE)
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_829.py b/sources/pyside6/tests/QtCore/bug_829.py
index 54f461850..89790c001 100644
--- a/sources/pyside6/tests/QtCore/bug_829.py
+++ b/sources/pyside6/tests/QtCore/bug_829.py
@@ -1,34 +1,11 @@
-#############################################################################
-##
-## Copyright (C) 2016 The Qt Company Ltd.
-## Copyright (C) 2011 Thomas Perl <thp.io/about>
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# Copyright (C) 2011 Thomas Perl <thp.io/about>
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
# Test case for PySide bug 829
+import gc
import os
import sys
import unittest
@@ -52,6 +29,8 @@ class QVariantConversions(unittest.TestCase):
confFile.close()
self._confFileName = confFile.fileName()
del confFile
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
s = QSettings(self._confFileName, QSettings.IniFormat)
self.assertEqual(s.status(), QSettings.NoError)
# Save value
@@ -59,6 +38,8 @@ class QVariantConversions(unittest.TestCase):
s.sync()
self.assertEqual(s.status(), QSettings.NoError)
del s
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
# Restore value
s = QSettings(self._confFileName, QSettings.IniFormat)
@@ -69,5 +50,6 @@ class QVariantConversions(unittest.TestCase):
if self._confFileName is not None:
os.unlink(QDir.toNativeSeparators(self._confFileName))
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_835.py b/sources/pyside6/tests/QtCore/bug_835.py
index e546cccea..ffc599ee9 100644
--- a/sources/pyside6/tests/QtCore/bug_835.py
+++ b/sources/pyside6/tests/QtCore/bug_835.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -35,12 +11,13 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import QObject
get_counter = 0
set_counter = 0
+
class Descriptor(object):
def __get__(self, obj, owner):
global get_counter
@@ -57,10 +34,12 @@ class Descriptor(object):
set_counter += 1
obj.var = value
+
class FooBar(QObject):
test = Descriptor()
var = 0
+
class SetAndGetTestCases(unittest.TestCase):
def setUp(self):
global get_counter
@@ -97,5 +76,6 @@ class SetAndGetTestCases(unittest.TestCase):
get_counter = 0
set_counter = 0
+
if __name__ == "__main__":
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_920.py b/sources/pyside6/tests/QtCore/bug_920.py
index 7caea3810..d39c44547 100644
--- a/sources/pyside6/tests/QtCore/bug_920.py
+++ b/sources/pyside6/tests/QtCore/bug_920.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -39,10 +14,12 @@ init_test_paths(False)
import PySide6.QtCore as QtCore
+
class Signaller(QtCore.QObject):
s1 = QtCore.Signal()
s2 = QtCore.Signal()
+
class TestBug920(unittest.TestCase):
def testIt(self):
diff --git a/sources/pyside6/tests/QtCore/bug_927.py b/sources/pyside6/tests/QtCore/bug_927.py
index 80f332979..fb1ffdde1 100644
--- a/sources/pyside6/tests/QtCore/bug_927.py
+++ b/sources/pyside6/tests/QtCore/bug_927.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -36,24 +12,40 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import QTime, QRunnable, QThreadPool
+from PySide6.QtCore import QRunnable, QThread, QThreadPool
+
+
+thread_function_called = False
+
+
+class thread_function():
+ global thread_function_called
+ thread_function_called = True
+
class Task(QRunnable):
- def run(self):
- t = QTime()
- t.start()
- time.sleep(2) # Sleep 2 seconds
+ def run(self):
+ QThread.msleep(100)
class QThreadPoolTest(unittest.TestCase):
- '''This used to cause a segfault due the ownership control on globalInstance function '''
def testSlowJobs(self):
- for i in range(3):
- task = Task()
- QThreadPool.globalInstance().start(task)
- time.sleep(1) # Sleep 1 second
+ '''This used to cause a segfault due the ownership control on
+ globalInstance function'''
+ for i in range(3):
+ task = Task()
+ QThreadPool.globalInstance().start(task)
+ time.sleep(0.05)
+
+ self.assertTrue(QThreadPool.globalInstance().waitForDone())
+
+ def testCallable(self):
+ global thread_function_called
+ tp = QThreadPool.globalInstance()
+ tp.start(thread_function)
+ self.assertTrue(tp.waitForDone())
+ self.assertTrue(thread_function_called)
- QThreadPool.globalInstance().waitForDone()
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_931.py b/sources/pyside6/tests/QtCore/bug_931.py
index 1dcde427f..f710e1fbb 100644
--- a/sources/pyside6/tests/QtCore/bug_931.py
+++ b/sources/pyside6/tests/QtCore/bug_931.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,9 +13,12 @@ init_test_paths(False)
from PySide6.QtCore import QObject, Signal
o = QObject()
+
+
class MyObject(QObject):
s = Signal(int)
+
class CheckSignalType(unittest.TestCase):
def testSignal(self):
self.assertTrue(isinstance(QObject.destroyed, Signal))
@@ -52,5 +31,6 @@ class CheckSignalType(unittest.TestCase):
self.assertTrue(isinstance(MyObject.s, Signal))
self.assertFalse(isinstance(int, Signal))
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_938.py b/sources/pyside6/tests/QtCore/bug_938.py
index 2566efada..63607cd40 100644
--- a/sources/pyside6/tests/QtCore/bug_938.py
+++ b/sources/pyside6/tests/QtCore/bug_938.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -35,7 +11,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import QBuffer
class TestBug938 (unittest.TestCase):
@@ -47,5 +23,6 @@ class TestBug938 (unittest.TestCase):
b.close()
self.assertEqual(b.buffer().size(), 5)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_953.py b/sources/pyside6/tests/QtCore/bug_953.py
index d13c219cd..b772b8536 100644
--- a/sources/pyside6/tests/QtCore/bug_953.py
+++ b/sources/pyside6/tests/QtCore/bug_953.py
@@ -1,31 +1,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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+import gc
import os
import sys
@@ -35,21 +12,25 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1] / "util"))
from init_paths import init_test_paths
init_test_paths()
-from PySide6.QtCore import *
+from PySide6.QtCore import QCoreApplication, QObject, QTimer
+
class Dispatcher(QObject):
_me = None
def __init__(self):
- super(Dispatcher, self).__init__()
+ super().__init__()
self._me = self
QTimer.singleShot(0, self._finish)
def _finish(self):
- del self._me # It can't crash here!
+ del self._me # It can't crash here!
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
QTimer.singleShot(10, QCoreApplication.instance().quit)
+
if __name__ == '__main__':
app = QCoreApplication([])
Dispatcher()
- app.exec_()
+ app.exec()
diff --git a/sources/pyside6/tests/QtCore/bug_987.py b/sources/pyside6/tests/QtCore/bug_987.py
index d5a2bcd33..82494fe4b 100644
--- a/sources/pyside6/tests/QtCore/bug_987.py
+++ b/sources/pyside6/tests/QtCore/bug_987.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -44,7 +20,8 @@ class TestBug987(unittest.TestCase):
def testInvalidDisconnection(self):
o = QObject()
- self.assertRaises(RuntimeError, o.destroyed.disconnect, self.callback)
+ self.assertFalse(o.destroyed.disconnect(self.callback))
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_994.py b/sources/pyside6/tests/QtCore/bug_994.py
index 1e1e137d8..258d40dd8 100644
--- a/sources/pyside6/tests/QtCore/bug_994.py
+++ b/sources/pyside6/tests/QtCore/bug_994.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -40,7 +16,7 @@ from PySide6.QtCore import QIODevice, QTextStream
class MyIODevice (QIODevice):
def readData(self, amount):
- return bytes("\0a" * int(amount/2), "UTF-8")
+ return bytes("\0a" * int(amount / 2), "UTF-8")
def readLineData(self, maxSize):
return bytes("\0b" * 4, "UTF-8")
@@ -48,6 +24,7 @@ class MyIODevice (QIODevice):
def atEnd(self):
return False
+
class TestBug944 (unittest.TestCase):
def testIt(self):
@@ -57,5 +34,6 @@ class TestBug944 (unittest.TestCase):
self.assertEqual(s.read(4), "\0a\0a")
self.assertEqual(device.readLine(), "\0b\0b\0b\0b")
+
if __name__ == "__main__":
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_PYSIDE-164.py b/sources/pyside6/tests/QtCore/bug_PYSIDE-164.py
index bab09033d..2a082eeb6 100644
--- a/sources/pyside6/tests/QtCore/bug_PYSIDE-164.py
+++ b/sources/pyside6/tests/QtCore/bug_PYSIDE-164.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -35,20 +11,25 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import QCoreApplication, QEventLoop, QObject, Qt, QThread, QTimer, SIGNAL
+from PySide6.QtCore import QCoreApplication, QEventLoop, QObject, Qt, QThread, Signal
+
class Emitter(QThread):
+
+ signal = Signal(int)
+
def __init__(self):
- QThread.__init__(self)
+ super().__init__()
def run(self):
print("Before emit.")
- self.emit(SIGNAL("signal(int)"), 0)
+ self.signal.emit(0)
print("After emit.")
+
class Receiver(QObject):
def __init__(self, eventloop):
- QObject.__init__(self)
+ super().__init__()
self.eventloop = eventloop
def receive(self, number):
@@ -59,16 +40,16 @@ class Receiver(QObject):
class TestBugPYSIDE164(unittest.TestCase):
def testBlockingSignal(self):
- app = QCoreApplication.instance() or QCoreApplication([])
+ app = QCoreApplication.instance() or QCoreApplication([]) # noqa: F841
eventloop = QEventLoop()
emitter = Emitter()
receiver = Receiver(eventloop)
- emitter.connect(emitter, SIGNAL("signal(int)"),
- receiver.receive, Qt.BlockingQueuedConnection)
+ emitter.signal.connect(receiver.receive, Qt.BlockingQueuedConnection)
emitter.start()
- retval = eventloop.exec_()
+ retval = eventloop.exec()
emitter.wait(2000)
self.assertEqual(retval, 0)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_PYSIDE-2745.py b/sources/pyside6/tests/QtCore/bug_PYSIDE-2745.py
new file mode 100644
index 000000000..99f2e498f
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/bug_PYSIDE-2745.py
@@ -0,0 +1,38 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import QTimer
+
+from helper.usesqapplication import UsesQApplication
+
+
+class TestBugPYSIDE2745(UsesQApplication):
+
+ def setUp(self):
+ UsesQApplication.setUp(self)
+ self.counter = 0
+
+ def fail(self):
+ self.counter += 1
+ raise Exception()
+
+ def test_fail(self):
+ QTimer.singleShot(0, self.fail)
+ QTimer.singleShot(0, self.fail)
+ QTimer.singleShot(1, self.app.quit)
+ self.app.exec()
+ self.assertEqual(self.counter, 2)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_PYSIDE-41.py b/sources/pyside6/tests/QtCore/bug_PYSIDE-41.py
new file mode 100644
index 000000000..02a43d83a
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/bug_PYSIDE-41.py
@@ -0,0 +1,50 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import QPersistentModelIndex, QStringListModel
+
+
+class TestBugPYSIDE41(unittest.TestCase):
+
+ def testIt(self):
+
+ # list of single-character strings
+ strings = list('abcdefghijklmnopqrstuvwxyz')
+
+ model = QStringListModel(strings)
+
+ # Test hashing of both QModelIndex and QPersistentModelIndex
+ indexFunctions = []
+ indexFunctions.append(model.index)
+ indexFunctions.append(lambda i: QPersistentModelIndex(model.index(i)))
+
+ for indexFunction in indexFunctions:
+
+ # If two objects compare equal, their hashes MUST also be equal. (The
+ # reverse is not a requirement.)
+ for i, _ in enumerate(strings):
+ index1 = indexFunction(i)
+ index2 = indexFunction(i)
+ self.assertEqual(index1, index2)
+ self.assertEqual(hash(index1), hash(index2))
+
+ # Adding the full set of indexes to itself is a no-op.
+ allIndexes1 = set(indexFunction(i) for i, _ in enumerate(strings))
+ allIndexes2 = set(indexFunction(i) for i, _ in enumerate(strings))
+ allIndexesCombined = allIndexes1 & allIndexes2
+ self.assertEqual(allIndexes1, allIndexesCombined)
+ self.assertEqual(allIndexes2, allIndexesCombined)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtCore/bug_PYSIDE-42.py b/sources/pyside6/tests/QtCore/bug_PYSIDE-42.py
index a64be8e05..1572e6de3 100644
--- a/sources/pyside6/tests/QtCore/bug_PYSIDE-42.py
+++ b/sources/pyside6/tests/QtCore/bug_PYSIDE-42.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -35,7 +11,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import QFile, QObject
class TestBugPYSIDE42 (unittest.TestCase):
@@ -49,5 +25,6 @@ class TestBugPYSIDE42 (unittest.TestCase):
self.assertNotEqual(hash1, hash2)
self.assertEqual(hash1, hash(obj1))
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/child_event_test.py b/sources/pyside6/tests/QtCore/child_event_test.py
index 1172f6027..a6b8d3d50 100644
--- a/sources/pyside6/tests/QtCore/child_event_test.py
+++ b/sources/pyside6/tests/QtCore/child_event_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test case for QObject.childEvent and QTimer.childEvent overloading'''
@@ -40,20 +15,22 @@ from init_paths import init_test_paths
init_test_paths(False)
from PySide6.QtCore import QObject, QTimer, QCoreApplication
-from helper.usesqcoreapplication import UsesQCoreApplication
+from helper.usesqapplication import UsesQApplication
+
class ExtQObject(QObject):
def __init__(self):
- QObject.__init__(self)
+ super().__init__()
self.child_event_received = False
def childEvent(self, event):
QObject.childEvent(self, event)
self.child_event_received = True
+
class ExtQTimer(QTimer):
def __init__(self):
- QTimer.__init__(self)
+ super().__init__()
self.child_event_received = False
def childEvent(self, event):
@@ -61,14 +38,14 @@ class ExtQTimer(QTimer):
self.child_event_received = True
-class TestChildEvent(UsesQCoreApplication):
+class TestChildEvent(UsesQApplication):
'''Test case for QObject::childEvent and QTimer::childEvent'''
def setUp(self):
- UsesQCoreApplication.setUp(self)
+ UsesQApplication.setUp(self)
def tearDown(self):
- UsesQCoreApplication.tearDown(self)
+ UsesQApplication.tearDown(self)
def testQObject(self):
parent = ExtQObject()
@@ -82,6 +59,7 @@ class TestChildEvent(UsesQCoreApplication):
child.setParent(parent)
self.assertTrue(parent.child_event_received)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/classinfo_test.py b/sources/pyside6/tests/QtCore/classinfo_test.py
index e6a0a9256..626ae308e 100644
--- a/sources/pyside6/tests/QtCore/classinfo_test.py
+++ b/sources/pyside6/tests/QtCore/classinfo_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import sys
import os
@@ -38,6 +14,7 @@ init_test_paths(False)
from PySide6.QtCore import QObject, QCoreApplication, ClassInfo
+
class TestClassInfo(unittest.TestCase):
def test_metadata(self):
@ClassInfo(author='pyside', url='http://www.pyside.org')
@@ -48,20 +25,37 @@ class TestClassInfo(unittest.TestCase):
mo = o.metaObject()
self.assertEqual(mo.classInfoCount(), 2)
- ci = mo.classInfo(0) #author
+ ci = mo.classInfo(0) # author
self.assertEqual(ci.name(), 'author')
self.assertEqual(ci.value(), 'pyside')
- ci = mo.classInfo(1) #url
+ ci = mo.classInfo(1) # url
self.assertEqual(ci.name(), 'url')
self.assertEqual(ci.value(), 'http://www.pyside.org')
+ def test_dictionary(self):
+ @ClassInfo({'author': 'pyside', 'author company': 'The Qt Company'})
+ class MyObject(QObject):
+ pass
+
+ o = MyObject()
+ mo = o.metaObject()
+ self.assertEqual(mo.classInfoCount(), 2)
+
+ ci = mo.classInfo(0) # author
+ self.assertEqual(ci.name(), 'author')
+ self.assertEqual(ci.value(), 'pyside')
+
+ ci = mo.classInfo(1) # url
+ self.assertEqual(ci.name(), 'author company')
+ self.assertEqual(ci.value(), 'The Qt Company')
+
def test_verify_metadata_types(self):
- valid_dict = { '123': '456' }
+ valid_dict = {'123': '456'}
- invalid_dict_1 = { '123': 456 }
- invalid_dict_2 = { 123: 456 }
- invalid_dict_3 = { 123: '456' }
+ invalid_dict_1 = {'123': 456}
+ invalid_dict_2 = {123: 456}
+ invalid_dict_3 = {123: '456'}
ClassInfo(**valid_dict)
@@ -93,20 +87,29 @@ class TestClassInfo(unittest.TestCase):
self.assertRaises(TypeError, decorator, MyObject2)
def test_can_only_be_used_on_qobjects(self):
- def test_function(): pass
- self.assertRaises(TypeError, ClassInfo(), test_function)
+ def make_info():
+ return ClassInfo(author='pyside')
- class NotAQObject(object): pass
- self.assertRaises(TypeError, ClassInfo(), NotAQObject)
+ def test_function():
+ pass
+ self.assertRaises(TypeError, make_info(), test_function)
- class QObjectSubclass(QObject): pass
- ClassInfo()(QObjectSubclass)
+ class NotAQObject(object):
+ pass
+ self.assertRaises(TypeError, make_info(), NotAQObject)
- class SubclassOfNativeQObjectSubclass(QCoreApplication): pass
- ClassInfo()(SubclassOfNativeQObjectSubclass)
+ class QObjectSubclass(QObject):
+ pass
+ make_info()(QObjectSubclass)
+
+ class SubclassOfNativeQObjectSubclass(QCoreApplication):
+ pass
+ make_info()(SubclassOfNativeQObjectSubclass)
+
+ class SubclassOfPythonQObjectSubclass(QObjectSubclass):
+ pass
+ make_info()(SubclassOfPythonQObjectSubclass)
- class SubclassOfPythonQObjectSubclass(QObjectSubclass): pass
- ClassInfo()(SubclassOfPythonQObjectSubclass)
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/deepcopy_test.py b/sources/pyside6/tests/QtCore/deepcopy_test.py
index 711b023a9..c41f7bbb0 100644
--- a/sources/pyside6/tests/QtCore/deepcopy_test.py
+++ b/sources/pyside6/tests/QtCore/deepcopy_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
from copy import deepcopy
import os
@@ -44,12 +20,14 @@ try:
except ImportError:
HAVE_Q = False
+
class DeepCopyHelper:
def testCopy(self):
copy = deepcopy([self.original])[0]
self.assertTrue(copy is not self.original)
self.assertEqual(copy, self.original)
+
class QByteArrayDeepCopy(DeepCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QByteArray(bytes('the quick brown fox jumps over the lazy dog', "UTF-8"))
@@ -89,30 +67,37 @@ class QRectFDeepCopy(DeepCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QRectF(100.33, 200.254, 300.321, 400.123)
+
class QLineDeepCopy(DeepCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QLine(1, 2, 3, 4)
+
class QLineFDeepCopy(DeepCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QLineF(1.1, 2.2, 3.3, 4.4)
+
class QPointDeepCopy(DeepCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QPoint(1, 2)
+
class QPointFDeepCopy(DeepCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QPointF(1.1, 2.2)
+
class QDirDeepCopy(DeepCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QDir("./")
+
class QUuiCopy(DeepCopyHelper, unittest.TestCase):
@unittest.skipUnless(HAVE_Q, "QUuid is currently not supported on this platform.")
def setUp(self):
self.original = QUuid("67C8770B-44F1-410A-AB9A-F9B5446F13EE")
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/deletelater_test.py b/sources/pyside6/tests/QtCore/deletelater_test.py
index 1d8dff895..5d31ef367 100644
--- a/sources/pyside6/tests/QtCore/deletelater_test.py
+++ b/sources/pyside6/tests/QtCore/deletelater_test.py
@@ -1,35 +1,11 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QTimer.singleShot'''
+import gc
import os
import sys
import unittest
@@ -40,17 +16,21 @@ from init_paths import init_test_paths
init_test_paths(False)
from PySide6.QtCore import QObject, QTimer, QCoreApplication, SIGNAL
-from helper.usesqcoreapplication import UsesQCoreApplication
+from helper.usesqapplication import UsesQApplication
+
-class TestDeleteLater(UsesQCoreApplication):
+class TestDeleteLater(UsesQApplication):
'''Test case for function DeleteLater'''
def testCase(self):
o = QObject()
o.deleteLater()
del o
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
QTimer.singleShot(100, self.app.quit)
- self.app.exec_()
+ self.app.exec()
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/destroysignal_test.py b/sources/pyside6/tests/QtCore/destroysignal_test.py
index fe91d5340..5c743fe4d 100644
--- a/sources/pyside6/tests/QtCore/destroysignal_test.py
+++ b/sources/pyside6/tests/QtCore/destroysignal_test.py
@@ -1,31 +1,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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+import gc
import os
import sys
import unittest
@@ -35,7 +12,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import QTimer, QObject
+from PySide6.QtCore import QTimer, QObject, Signal
class TestDestroySignal(unittest.TestCase):
@@ -48,6 +25,10 @@ class TestDestroySignal(unittest.TestCase):
t = QTimer()
t.destroyed[QObject].connect(self.onObjectDestroyed)
del t
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+ # PYSIDE-535: Why do I need to do it twice, here?
+ gc.collect()
self.assertTrue(self._destroyed)
def testWithParent(self):
@@ -56,8 +37,43 @@ class TestDestroySignal(unittest.TestCase):
t = QTimer(p)
t.destroyed[QObject].connect(self.onObjectDestroyed)
del p
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+ # PYSIDE-535: Why do I need to do it twice, here?
+ gc.collect()
self.assertTrue(self._destroyed)
+
+class Foo(QObject):
+ s = Signal(int)
+
+ def __init__(self):
+ QObject.__init__(self)
+ sys.stderr.write(f"__init__ {id(self):x}\n")
+
+ def __del__(self):
+ sys.stderr.write(f"__del__ {id(self):x}\n")
+
+ def send(self, i):
+ self.s.emit(i)
+
+
+# PYSIDE-2201/2328: This crashed until we introduced a weak reference.
+class TestDestroyNoConnect(unittest.TestCase):
+
+ def testSignalDestroyedMissingReference(self):
+ # This works since it has one reference more to Foo
+ Foo().send(43)
+ # This crashed because we have no reference in the signal.
+ with self.assertRaises(RuntimeError):
+ Foo().s.emit(44)
+
+ def testSignalDestroyedinConnect(self):
+ # PYSIDE-2328: Connect to signal of temporary
+ with self.assertRaises(RuntimeError):
+ Foo().s.connect(None)
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/duck_punching_test.py b/sources/pyside6/tests/QtCore/duck_punching_test.py
index 2dc67b509..e2204eca8 100644
--- a/sources/pyside6/tests/QtCore/duck_punching_test.py
+++ b/sources/pyside6/tests/QtCore/duck_punching_test.py
@@ -1,35 +1,11 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test case for duck punching new implementations of C++ virtual methods into object instances.'''
+import gc
import os
import sys
import types
@@ -41,34 +17,40 @@ from init_paths import init_test_paths
init_test_paths(False)
from PySide6.QtCore import QObject
-from helper.usesqcoreapplication import UsesQCoreApplication
+from helper.usesqapplication import UsesQApplication
+
def MethodType(func, instance, instanceType):
return types.MethodType(func, instance)
+
class Duck(QObject):
def __init__(self):
- QObject.__init__(self)
+ super().__init__()
+
def childEvent(self, event):
QObject.childEvent(self, event)
-class TestDuckPunchingOnQObjectInstance(UsesQCoreApplication):
+
+class TestDuckPunchingOnQObjectInstance(UsesQApplication):
'''Test case for duck punching new implementations of C++ virtual methods into object instances.'''
def setUp(self):
- #Acquire resources
+ # Acquire resources
self.duck_childEvent_called = False
- UsesQCoreApplication.setUp(self)
+ UsesQApplication.setUp(self)
def tearDown(self):
- #Release resources
+ # Release resources
del self.duck_childEvent_called
- UsesQCoreApplication.tearDown(self)
-
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+ UsesQApplication.tearDown(self)
def testChildEventMonkeyPatch(self):
- #Test if the new childEvent injected on QObject instance is called from C++
+ # Test if the new childEvent injected on QObject instance is called from C++
parent = QObject()
+
def childEvent(obj, event):
self.duck_childEvent_called = True
parent.childEvent = MethodType(childEvent, parent, QObject)
@@ -83,8 +65,9 @@ class TestDuckPunchingOnQObjectInstance(UsesQCoreApplication):
parent.childEvent = None
def testChildEventMonkeyPatchWithInheritance(self):
- #Test if the new childEvent injected on a QObject's extension class instance is called from C++
+ # Test if the new childEvent injected on a QObject's extension class instance is called from C++
parent = Duck()
+
def childEvent(obj, event):
QObject.childEvent(obj, event)
self.duck_childEvent_called = True
@@ -101,6 +84,7 @@ class TestDuckPunchingOnQObjectInstance(UsesQCoreApplication):
# assert that checks if the wrapper mapper is empty.
parent.childEvent = None
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/emoji_string_test.py b/sources/pyside6/tests/QtCore/emoji_string_test.py
index 553864088..6b4db7d99 100644
--- a/sources/pyside6/tests/QtCore/emoji_string_test.py
+++ b/sources/pyside6/tests/QtCore/emoji_string_test.py
@@ -1,43 +1,6 @@
-# This Python file uses the following encoding: utf-8
-
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+from __future__ import annotations
"""
emoji-string-test.py
@@ -59,19 +22,21 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1] / "util"))
from init_paths import init_test_paths
init_test_paths()
-from PySide6 import QtCore
+from PySide6.QtCore import QObject, Signal
+
emoji_str = u'\U0001f632' + u' ' # "😲 "
-class TestStuff(QtCore.QObject):
- testsig = QtCore.Signal(str)
+
+class TestStuff(QObject):
+ testsig = Signal(str)
def a_nop(self, sendMeAnEmoji):
print(sendMeAnEmoji)
return
def __init__(self):
- super(TestStuff, self).__init__()
+ super().__init__()
self.testsig.connect(self.a_nop)
self.testsig.emit(emoji_str)
@@ -81,6 +46,7 @@ class TestStuff(QtCore.QObject):
# https://stackoverflow.com/questions/30775689/python-length-of-unicode-string-confusion
assert len(emoji_str) == 2 if sys.maxunicode > 0xffff else 3
+
if __name__ == "__main__":
mything = TestStuff()
mything.plausi()
diff --git a/sources/pyside6/tests/QtCore/errormessages_with_features_test.py b/sources/pyside6/tests/QtCore/errormessages_with_features_test.py
index bbad67a77..6ed1a665f 100644
--- a/sources/pyside6/tests/QtCore/errormessages_with_features_test.py
+++ b/sources/pyside6/tests/QtCore/errormessages_with_features_test.py
@@ -1,41 +1,6 @@
-#############################################################################
-##
-## Copyright (C) 2020 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+from __future__ import annotations
import os
import sys
@@ -46,8 +11,14 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6 import QtWidgets
-from PySide6.support import __feature__
+from PySide6 import QtCore
+from PySide6.QtWidgets import QApplication, QLabel
+
+is_pypy = hasattr(sys, "pypy_version_info")
+if not is_pypy:
+ from PySide6.support import feature
+
+import inspect
"""
errormessages_with_features_test.py
@@ -60,64 +31,72 @@ This test is in its own file because combining it with
"snake_prop_feature_test" gave strange interactions with the other tests.
"""
+
+@unittest.skipIf(is_pypy, "__feature__ cannot yet be used with PyPy")
class ErrormessagesWithFeatures(unittest.TestCase):
probe = "called with wrong argument types"
- probe_miss = "missing signature"
def setUp(self):
- qApp or QtWidgets.QApplication()
- __feature__.set_selection(0)
+ qApp or QApplication()
+ feature.reset()
def tearDown(self):
- __feature__.set_selection(0)
+ feature.reset()
qApp.shutdown()
def testCorrectErrorMessagesPlain(self):
with self.assertRaises(TypeError) as cm:
- QtWidgets.QLabel().setFont(42)
+ QLabel().setFont(42)
print("\n\n" + cm.exception.args[0])
self.assertTrue(self.probe in cm.exception.args[0])
def testCorrectErrorMessagesSnake(self):
from __feature__ import snake_case
with self.assertRaises(TypeError) as cm:
- QtWidgets.QLabel().set_font(42)
+ QLabel().set_font(42)
print("\n\n" + cm.exception.args[0])
self.assertTrue(self.probe in cm.exception.args[0])
def testCorrectErrorMessagesProp(self):
from __feature__ import true_property
with self.assertRaises(TypeError) as cm:
- QtWidgets.QLabel().font = 42
+ QLabel().font = 42
print("\n\n" + cm.exception.args[0])
self.assertTrue(self.probe in cm.exception.args[0])
def testCorrectErrorMessagesSnakeProp(self):
from __feature__ import snake_case, true_property
with self.assertRaises(TypeError) as cm:
- QtWidgets.QLabel().font = 42
+ QLabel().font = 42
print("\n\n" + cm.exception.args[0])
self.assertTrue(self.probe in cm.exception.args[0])
def testCorrectErrorMessagesClassProp(self):
from __feature__ import true_property
with self.assertRaises(TypeError) as cm:
- QtWidgets.QApplication.quitOnLastWindowClosed = object
+ QApplication.quitOnLastWindowClosed = object
print("\n\n" + cm.exception.args[0])
- self.assertTrue(self.probe_miss in cm.exception.args[0])
+ self.assertTrue(self.probe in cm.exception.args[0])
with self.assertRaises(TypeError) as cm:
qApp.quitOnLastWindowClosed = object
- self.assertTrue(self.probe_miss in cm.exception.args[0])
+ self.assertTrue(self.probe in cm.exception.args[0])
def testCorrectErrorMessagesClassSnakeProp(self):
from __feature__ import snake_case, true_property
with self.assertRaises(TypeError) as cm:
- QtWidgets.QApplication.quit_on_last_window_closed = object
+ QApplication.quit_on_last_window_closed = object
print("\n\n" + cm.exception.args[0])
- self.assertTrue(self.probe_miss in cm.exception.args[0])
+ self.assertTrue(self.probe in cm.exception.args[0])
with self.assertRaises(TypeError) as cm:
qApp.quit_on_last_window_closed = object
- self.assertTrue(self.probe_miss in cm.exception.args[0])
+ self.assertTrue(self.probe in cm.exception.args[0])
+
+ def testDocIsWorking(self):
+ """
+ make sure that it does not crash when touched
+ """
+ inspect.getdoc(QApplication)
+ inspect.getdoc(QtCore)
if __name__ == '__main__':
diff --git a/sources/pyside6/tests/QtCore/feature_with_uic/window.py b/sources/pyside6/tests/QtCore/feature_with_uic/window.py
new file mode 100644
index 000000000..0a94d2ecd
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/feature_with_uic/window.py
@@ -0,0 +1,53 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+from __future__ import annotations
+
+from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
+ QMetaObject, QObject, QPoint, QRect,
+ QSize, QTime, QUrl, Qt)
+from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
+ QFont, QFontDatabase, QGradient, QIcon,
+ QImage, QKeySequence, QLinearGradient, QPainter,
+ QPalette, QPixmap, QRadialGradient, QTransform)
+from PySide6.QtWidgets import (QApplication, QHBoxLayout, QMainWindow, QMenuBar,
+ QPushButton, QSizePolicy, QStatusBar, QVBoxLayout,
+ QWidget)
+
+class Ui_MainWindow(object):
+ def setupUi(self, MainWindow):
+ if not MainWindow.objectName():
+ MainWindow.setObjectName(u"MainWindow")
+ MainWindow.resize(263, 196)
+ self.centralwidget = QWidget(MainWindow)
+ self.centralwidget.setObjectName(u"centralwidget")
+ self.horizontalLayout = QHBoxLayout(self.centralwidget)
+ self.horizontalLayout.setObjectName(u"horizontalLayout")
+ self.verticalLayout = QVBoxLayout()
+ self.verticalLayout.setObjectName(u"verticalLayout")
+ self.pushButton = QPushButton(self.centralwidget)
+ self.pushButton.setObjectName(u"pushButton")
+
+ self.verticalLayout.addWidget(self.pushButton)
+
+ self.horizontalLayout.addLayout(self.verticalLayout)
+
+ MainWindow.setCentralWidget(self.centralwidget)
+ self.menubar = QMenuBar(MainWindow)
+ self.menubar.setObjectName(u"menubar")
+ self.menubar.setGeometry(QRect(0, 0, 263, 23))
+ MainWindow.setMenuBar(self.menubar)
+ self.statusbar = QStatusBar(MainWindow)
+ self.statusbar.setObjectName(u"statusbar")
+ MainWindow.setStatusBar(self.statusbar)
+
+ self.retranslateUi(MainWindow)
+ self.pushButton.clicked.connect(MainWindow.close)
+
+ QMetaObject.connectSlotsByName(MainWindow)
+ # setupUi
+
+ def retranslateUi(self, MainWindow):
+ MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None))
+ self.pushButton.setText(QCoreApplication.translate("MainWindow", u"PushButton", None))
+ # retranslateUi
+
diff --git a/sources/pyside6/tests/QtCore/feature_with_uic/window.ui b/sources/pyside6/tests/QtCore/feature_with_uic/window.ui
new file mode 100644
index 000000000..0b85824ea
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/feature_with_uic/window.ui
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>263</width>
+ <height>196</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QPushButton" name="pushButton">
+ <property name="text">
+ <string>PushButton</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>263</width>
+ <height>23</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QStatusBar" name="statusbar"/>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>pushButton</sender>
+ <signal>clicked()</signal>
+ <receiver>MainWindow</receiver>
+ <slot>close()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>131</x>
+ <y>97</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>131</x>
+ <y>97</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/sources/pyside6/tests/QtCore/feature_with_uic_test.py b/sources/pyside6/tests/QtCore/feature_with_uic_test.py
new file mode 100644
index 000000000..ff8ac2147
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/feature_with_uic_test.py
@@ -0,0 +1,60 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+from __future__ import annotations
+
+"""
+feature_with_uic_test.py
+------------------------
+
+Check if feature switching works with a normal UIC file.
+This crashed due to callbacks into QApplication.
+
+PYSIDE-1626: Switch early in `BindingManager::getOverride`.
+"""
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from helper.usesqapplication import UsesQApplication
+
+from PySide6.QtCore import QCoreApplication, QLibraryInfo, qVersion
+from PySide6.QtWidgets import QApplication, QMainWindow
+
+# PYSIDE-535: We cannot use __feature__ in PyPy, yet
+try:
+ from __feature__ import snake_case
+
+ from feature_with_uic.window import Ui_MainWindow
+ have_feature = True
+except ImportError:
+ Ui_MainWindow = object
+ have_feature = False
+
+
+class MainWindow(QMainWindow, Ui_MainWindow):
+
+ def __init__(self) -> None:
+ super().__init__()
+ self.setupUi(self)
+
+
+@unittest.skipIf(hasattr(sys, "pypy_version_info"),
+ "__feature__ cannot yet be used with PyPy")
+class FeatureTest(UsesQApplication):
+
+ def testFeaturesWorkWithUIC(self):
+ window = MainWindow()
+ window.set_window_title(qVersion())
+ window.show()
+ while not window.window_handle().is_exposed():
+ QCoreApplication.process_events()
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtCore/hash_test.py b/sources/pyside6/tests/QtCore/hash_test.py
index 71fb9cde9..91edc5a09 100644
--- a/sources/pyside6/tests/QtCore/hash_test.py
+++ b/sources/pyside6/tests/QtCore/hash_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -40,13 +15,18 @@ init_test_paths(False)
from PySide6.QtCore import QDate, QDateTime, QTime, QUrl
from PySide6.QtCore import QLine, QPoint, QRect, QSize
+
+URL = "https://qt.io/"
+
+
class HashTest(unittest.TestCase):
def testInsert(self):
myHash = {}
qdate = QDate.currentDate()
qdatetime = QDateTime.currentDateTime()
qtime = QTime.currentTime()
- qurl = QUrl("http://www.pyside.org")
+ qurl = QUrl(URL)
+ self.assertTrue(qurl.isValid())
qpoint = QPoint(12, 42)
myHash[qdate] = "QDate"
@@ -89,6 +69,34 @@ class HashTest(unittest.TestCase):
self.assertEqual(l1, l2)
self.assertEqual(hash(l1), hash(l2))
+ def testQTimeHash(self):
+ t1 = QTime(5, 5, 5)
+ t2 = QTime(5, 5, 5)
+ self.assertFalse(t1 is t2)
+ self.assertEqual(t1, t2)
+ self.assertEqual(hash(t1), hash(t2))
+
+ def testQDateHash(self):
+ d1 = QDate(1968, 3, 9)
+ d2 = QDate(1968, 3, 9)
+ self.assertFalse(d1 is d2)
+ self.assertEqual(d1, d2)
+ self.assertEqual(hash(d1), hash(d2))
+
+ def testQDateTimeHash(self):
+ d1 = QDateTime(QDate(1968, 3, 9), QTime(5, 5, 5))
+ d2 = QDateTime(QDate(1968, 3, 9), QTime(5, 5, 5))
+ self.assertFalse(d1 is d2)
+ self.assertEqual(d1, d2)
+ self.assertEqual(hash(d1), hash(d2))
+
+ def testQUrlHash(self):
+ u1 = QUrl(URL)
+ u2 = QUrl(URL)
+ self.assertFalse(u1 is u2)
+ self.assertEqual(u1, u2)
+ self.assertEqual(hash(u1), hash(u2))
+
+
if __name__ == '__main__':
unittest.main()
-
diff --git a/sources/pyside6/tests/QtCore/inherits_test.py b/sources/pyside6/tests/QtCore/inherits_test.py
index a176cbd44..9008c2161 100644
--- a/sources/pyside6/tests/QtCore/inherits_test.py
+++ b/sources/pyside6/tests/QtCore/inherits_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,9 +13,11 @@ init_test_paths(False)
from PySide6.QtCore import QObject
+
class MyObject(QObject):
pass
+
class MainTest(unittest.TestCase):
def testInherits(self):
o = MyObject()
@@ -47,5 +25,6 @@ class MainTest(unittest.TestCase):
self.assertEqual(mo.className(), 'MyObject')
self.assertTrue(o.inherits('MyObject'))
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/loggingcategorymacros_test.py b/sources/pyside6/tests/QtCore/loggingcategorymacros_test.py
new file mode 100644
index 000000000..2879b8874
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/loggingcategorymacros_test.py
@@ -0,0 +1,85 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+"""Tests for category logging macros qCDebug, qCInfo, qCWarning, qCCritical"""
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import (QLoggingCategory, QtMsgType, qCDebug, qCWarning, qCInfo,
+ qCCritical, qInstallMessageHandler)
+
+param = None
+
+
+def handler(msgt, ctx, msg):
+ global param
+ param = ctx.category + ": " + msg.strip()
+
+
+class TestQLoggingCategory(unittest.TestCase):
+ def setUp(self) -> None:
+ super().setUp()
+ self.defaultCategory = QLoggingCategory("default")
+ self.debugCategory = QLoggingCategory("debug.log", QtMsgType.QtDebugMsg)
+ self.infoCategory = QLoggingCategory("info.log", QtMsgType.QtInfoMsg)
+ self.warningCategory = QLoggingCategory("warning.log", QtMsgType.QtWarningMsg)
+ self.criticalCategory = QLoggingCategory("critical.log", QtMsgType.QtCriticalMsg)
+ qInstallMessageHandler(handler)
+ self.no_devices = 2
+
+ def test_qCDebug(self):
+ qCDebug(self.defaultCategory, "no device")
+ self.assertEqual(param, "default: no device")
+ qCDebug(self.debugCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "debug.log: devices: 2")
+
+ # not updated because category is Info which is above Debug
+ # nothing will be printed here
+ qCDebug(self.infoCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "debug.log: devices: 2")
+
+ def test_qCInfo(self):
+ qCInfo(self.defaultCategory, "no device")
+ self.assertEqual(param, "default: no device")
+ qCInfo(self.debugCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "debug.log: devices: 2")
+ qCInfo(self.infoCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "info.log: devices: 2")
+
+ # not updated because category is Warning which is above Info
+ # nothing will be printed here
+ qCInfo(self.warningCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "info.log: devices: 2")
+
+ def test_qCWarning(self):
+ qCWarning(self.defaultCategory, "no device")
+ self.assertEqual(param, "default: no device")
+ qCWarning(self.debugCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "debug.log: devices: 2")
+ qCWarning(self.warningCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "warning.log: devices: 2")
+
+ # not updated because category is Critical which is above Warning
+ # nothing will be printed here
+ qCWarning(self.criticalCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "warning.log: devices: 2")
+
+ def test_qCritical(self):
+ qCCritical(self.defaultCategory, "no device")
+ self.assertEqual(param, "default: no device")
+ qCCritical(self.warningCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "warning.log: devices: 2")
+ qCCritical(self.criticalCategory, f"devices: {self.no_devices}")
+ self.assertEqual(param, "critical.log: devices: 2")
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtCore/max_signals.py b/sources/pyside6/tests/QtCore/max_signals.py
index 2122aa738..64f3c0bb3 100644
--- a/sources/pyside6/tests/QtCore/max_signals.py
+++ b/sources/pyside6/tests/QtCore/max_signals.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,33 +13,37 @@ init_test_paths(False)
from PySide6.QtCore import QObject, SIGNAL
+
class MyObject(QObject):
pass
class TestSignalLimitless(unittest.TestCase):
SIGNAL_MAX = 100
+
def test100DynamicSignals(self):
self.count = 0
+
def onSignal():
self.count += 1
- #create 100 dynamic signals
+ # create 100 dynamic signals
o = MyObject()
for i in range(self.SIGNAL_MAX):
- o.connect(SIGNAL('sig%d()'%i), onSignal)
+ o.connect(SIGNAL(f'sig{i}()'), onSignal)
- #chek if the signals are valid
+ # check if the signals are valid
m = o.metaObject()
for i in range(self.SIGNAL_MAX):
- self.assertTrue(m.indexOfSignal('sig%d()'%i) > 0)
+ self.assertTrue(m.indexOfSignal(f'sig{i}()') > 0)
- #emit all 100 signals
+ # emit all 100 signals
for i in range(self.SIGNAL_MAX):
- o.emit(SIGNAL('sig%d()'%i))
+ o.emit(SIGNAL(f'sig{i}()'))
self.assertEqual(self.count, self.SIGNAL_MAX)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/missing_symbols_test.py b/sources/pyside6/tests/QtCore/missing_symbols_test.py
index a0ad4749c..020a0263a 100644
--- a/sources/pyside6/tests/QtCore/missing_symbols_test.py
+++ b/sources/pyside6/tests/QtCore/missing_symbols_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''(Very) Simple test case for missing names from QtCore'''
@@ -39,13 +15,15 @@ init_test_paths(False)
from PySide6 import QtCore
+
class MissingClasses(unittest.TestCase):
- def testQSettings(self): # Bug 232
+ def testQSettings(self): # Bug 232
getattr(QtCore, 'QSettings')
- def testQtTrNoop(self): # Bug 220
+ def testQtTrNoop(self): # Bug 220
getattr(QtCore, 'QT_TR_NOOP')
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/mockclass_test.py b/sources/pyside6/tests/QtCore/mockclass_test.py
index 51d980e74..57d1ddd58 100644
--- a/sources/pyside6/tests/QtCore/mockclass_test.py
+++ b/sources/pyside6/tests/QtCore/mockclass_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
# Test case for PySide bug 634
# http://bugs.pyside.org/show_bug.cgi?id=634
@@ -41,6 +17,7 @@ init_test_paths(False)
from PySide6.QtCore import QCoreApplication
+
class Mock(object):
def __init__(self):
self.called = False
@@ -58,6 +35,7 @@ class MockClassTest(unittest.TestCase):
QCoreApplication.instance()
self.assertTrue(mock.called)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/multiple_feature_test.py b/sources/pyside6/tests/QtCore/multiple_feature_test.py
index 0f25e2f5c..1a31dda22 100644
--- a/sources/pyside6/tests/QtCore/multiple_feature_test.py
+++ b/sources/pyside6/tests/QtCore/multiple_feature_test.py
@@ -1,41 +1,6 @@
-#############################################################################
-##
-## Copyright (C) 2020 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+from __future__ import annotations
import os
import sys
@@ -46,8 +11,12 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6 import QtCore
-from PySide6.support import __feature__
+from PySide6.QtCore import QCborArray, QObject
+
+is_pypy = hasattr(sys, "pypy_version_info")
+if not is_pypy:
+ from PySide6.support import feature
+
from textwrap import dedent
"""
@@ -62,6 +31,13 @@ There is much more to come.
MethodDescriptorType = type(str.split)
+
+def xprint(*args, **kw):
+ if "-v" in sys.argv:
+ print(*args, **kw)
+
+
+@unittest.skipIf(is_pypy, "__feature__ cannot yet be used with PyPy")
class FeaturesTest(unittest.TestCase):
def testAllFeatureCombinations(self):
@@ -71,31 +47,31 @@ class FeaturesTest(unittest.TestCase):
def tst_bit0(flag, self, bits):
if flag == 0:
- QtCore.QCborArray.isEmpty
- QtCore.QCborArray.__dict__["isEmpty"]
+ QCborArray.isEmpty
+ QCborArray.__dict__["isEmpty"]
with self.assertRaises(AttributeError):
- QtCore.QCborArray.is_empty
+ QCborArray.is_empty
with self.assertRaises(KeyError):
- QtCore.QCborArray.__dict__["is_empty"]
+ QCborArray.__dict__["is_empty"]
else:
- QtCore.QCborArray.is_empty
- QtCore.QCborArray.__dict__["is_empty"]
+ QCborArray.is_empty
+ QCborArray.__dict__["is_empty"]
with self.assertRaises(AttributeError):
- QtCore.QCborArray.isEmpty
+ QCborArray.isEmpty
with self.assertRaises(KeyError):
- QtCore.QCborArray.__dict__["isEmpty"]
+ QCborArray.__dict__["isEmpty"]
def tst_bit1(flag, self, bits):
getter_name = "object_name" if bits & 1 else "objectName"
setter_name = "set_object_name" if bits & 1 else "setObjectName"
- thing = getattr(QtCore.QObject, getter_name)
+ thing = getattr(QObject, getter_name)
if flag:
self.assertEqual(type(thing), property)
with self.assertRaises(AttributeError):
- getattr(QtCore.QObject, setter_name)
+ getattr(QObject, setter_name)
else:
self.assertEqual(type(thing), MethodDescriptorType)
- getattr(QtCore.QObject, setter_name)
+ getattr(QObject, setter_name)
edict = {}
for bit in range(2, 8):
@@ -107,30 +83,30 @@ class FeaturesTest(unittest.TestCase):
def tst_bit{bit}(flag, self, bits):
if flag == 0:
with self.assertRaises(AttributeError):
- QtCore.QCborArray.fake_feature_{bit_pow:02x}
+ QCborArray.fake_feature_{bit_pow:02x}
with self.assertRaises(KeyError):
- QtCore.QCborArray.__dict__["fake_feature_{bit_pow:02x}"]
+ QCborArray.__dict__["fake_feature_{bit_pow:02x}"]
else:
- QtCore.QCborArray.fake_feature_{bit_pow:02x}
- QtCore.QCborArray.__dict__["fake_feature_{bit_pow:02x}"]
+ QCborArray.fake_feature_{bit_pow:02x}
+ QCborArray.__dict__["fake_feature_{bit_pow:02x}"]
"""), "<string>", "exec"), globals(), edict)
globals().update(edict)
- feature_list = __feature__._really_all_feature_names
+ feature_list = feature._really_all_feature_names
func_list = [tst_bit0, tst_bit1, tst_bit2, tst_bit3,
tst_bit4, tst_bit5, tst_bit6, tst_bit7]
for idx in range(0x100):
- __feature__.set_selection(0)
+ feature.reset()
config = f"feature_{idx:02x}"
- print()
- print(f"--- Feature Test Config `{config}` ---")
- print("Imports:")
+ xprint()
+ xprint(f"--- Feature Test Config `{config}` ---")
+ xprint("Imports:")
for bit in range(8):
if idx & 1 << bit:
- feature = feature_list[bit]
- text = f"from __feature__ import {feature}"
- print(text)
+ cur_feature = feature_list[bit]
+ text = f"from __feature__ import {cur_feature}"
+ xprint(text)
eval(compile(text, "<string>", "exec"), globals(), edict)
for bit in range(8):
value = idx & 1 << bit
diff --git a/sources/pyside6/tests/QtCore/python_conversion.py b/sources/pyside6/tests/QtCore/python_conversion.py
index 451a54bac..e023ee5b5 100644
--- a/sources/pyside6/tests/QtCore/python_conversion.py
+++ b/sources/pyside6/tests/QtCore/python_conversion.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QLineF'''
@@ -43,6 +18,7 @@ import datetime
from PySide6.QtCore import QTime, QDateTime, QDate
+
class TestDateTimeConversions (unittest.TestCase):
def testQDate(self):
date = datetime.date(2010, 4, 23)
@@ -59,7 +35,7 @@ class TestDateTimeConversions (unittest.TestCase):
self.assertEqual(time.hour, other.hour())
self.assertEqual(time.minute, other.minute())
self.assertEqual(time.second, other.second())
- self.assertEqual(time.microsecond/1000, other.msec())
+ self.assertEqual(time.microsecond / 1000, other.msec())
self.assertEqual(time, other.toPython())
@@ -76,7 +52,7 @@ class TestDateTimeConversions (unittest.TestCase):
self.assertEqual(dateTime.hour, otherTime.hour())
self.assertEqual(dateTime.minute, otherTime.minute())
self.assertEqual(dateTime.second, otherTime.second())
- self.assertEqual(dateTime.microsecond/1000, otherTime.msec())
+ self.assertEqual(dateTime.microsecond / 1000, otherTime.msec())
self.assertEqual(dateTime, other.toPython())
@@ -93,9 +69,10 @@ class TestDateTimeConversions (unittest.TestCase):
self.assertEqual(dateTime.hour, otherTime.hour())
self.assertEqual(dateTime.minute, otherTime.minute())
self.assertEqual(dateTime.second, otherTime.second())
- self.assertEqual(dateTime.microsecond/1000, otherTime.msec())
+ self.assertEqual(dateTime.microsecond / 1000, otherTime.msec())
self.assertEqual(dateTime, other.toPython())
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qabs_test.py b/sources/pyside6/tests/QtCore/qabs_test.py
index a711ba9fb..5f08fe4bc 100644
--- a/sources/pyside6/tests/QtCore/qabs_test.py
+++ b/sources/pyside6/tests/QtCore/qabs_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -35,15 +11,15 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6 import QtCore
+from PySide6.QtCore import qAbs
class QAbsTest(unittest.TestCase):
- '''Tests for QtCore.qAbs'''
+ '''Tests for qAbs'''
def testBasic(self):
def check(x):
- self.assertEqual(QtCore.qAbs(x), abs(x))
+ self.assertEqual(qAbs(x), abs(x))
check(0)
check(-10)
@@ -51,5 +27,6 @@ class QAbsTest(unittest.TestCase):
check(10.5)
check(-10.5)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qabstractitemmodel_test.py b/sources/pyside6/tests/QtCore/qabstractitemmodel_test.py
index 71d72b10e..20d070a03 100644
--- a/sources/pyside6/tests/QtCore/qabstractitemmodel_test.py
+++ b/sources/pyside6/tests/QtCore/qabstractitemmodel_test.py
@@ -1,32 +1,6 @@
-# -*- 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,7 +11,10 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import (QAbstractItemModel, QAbstractListModel,
+ QIdentityProxyModel, QObject, QPersistentModelIndex,
+ QStringListModel, Qt)
+
class MyModel (QAbstractListModel):
pass
@@ -48,7 +25,7 @@ class TestQModelIndexInternalPointer(unittest.TestCase):
def testInternalPointer(self):
m = MyModel()
foo = QObject()
- idx = m.createIndex(0,0, foo)
+ idx = m.createIndex(0, 0, foo)
check = m.checkIndex(idx, QAbstractItemModel.CheckIndexOption.IndexIsValid
| QAbstractItemModel.CheckIndexOption.DoNotUseParent
| QAbstractItemModel.CheckIndexOption.ParentIsInvalid)
@@ -70,6 +47,7 @@ class TestQModelIndexInternalPointer(unittest.TestCase):
proxyData = str(proxyModel.data(proxyIndex, Qt.DisplayRole))
self.assertEqual(sourceData, proxyData)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qanimationgroup_test.py b/sources/pyside6/tests/QtCore/qanimationgroup_test.py
index 6c07113e0..f3eec76bf 100644
--- a/sources/pyside6/tests/QtCore/qanimationgroup_test.py
+++ b/sources/pyside6/tests/QtCore/qanimationgroup_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,7 +12,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import QCoreApplication, QParallelAnimationGroup, QSequentialAnimationGroup, QTimer
+
class QAnimationGroupTest(unittest.TestCase):
@@ -52,10 +28,11 @@ class QAnimationGroupTest(unittest.TestCase):
panim.clear()
- self.assertRaises(RuntimeError, lambda :sanim.parent())
+ self.assertRaises(RuntimeError, lambda: sanim.parent())
QTimer.singleShot(100, app.quit)
- app.exec_()
+ app.exec()
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qbitarray_test.py b/sources/pyside6/tests/QtCore/qbitarray_test.py
index 1fee4f69c..239453da7 100644
--- a/sources/pyside6/tests/QtCore/qbitarray_test.py
+++ b/sources/pyside6/tests/QtCore/qbitarray_test.py
@@ -1,35 +1,11 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Tests if QBitArray class is iterable and also '~' (__invert__) and bitwise operators'''
+import gc
import os
import sys
import unittest
@@ -41,6 +17,7 @@ init_test_paths(False)
from PySide6.QtCore import QBitArray
+
def bool_list_from_qbitarray(qbitarray):
'''This function is used instead of a list comprehension because
the QBitArray is being tested also to check if it is providing
@@ -51,11 +28,12 @@ def bool_list_from_qbitarray(qbitarray):
qbitarray_values.append(qbitarray.at(i))
return qbitarray_values
+
class QBitArrayIsIterableTest(unittest.TestCase):
'''Tests if QBitArray class is iterable and also '~' (__invert__) and bitwise operators'''
def setUp(self):
- #Acquire resources
+ # Acquire resources
self.qbitarray = QBitArray(3)
self.qbitarray_values = [True, False, False]
# WARNING: do not pythonify the following loop
@@ -71,15 +49,17 @@ class QBitArrayIsIterableTest(unittest.TestCase):
self.other_qbitarray.setBit(i, self.other_qbitarray_values[i])
def tearDown(self):
- #Release resources
+ # Release resources
del self.qbitarray
del self.other_qbitarray
del self.qbitarray_values
del self.other_qbitarray_values
del self.inverted_qbitarray_values
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
def testQBitArrayIsIterable(self):
- #Tests if QBitArray class is iterable
+ # Tests if QBitArray class is iterable
qbitarray_is_iterable = True
try:
bitarray = [bit for bit in self.qbitarray]
@@ -88,7 +68,7 @@ class QBitArrayIsIterableTest(unittest.TestCase):
self.assertTrue(qbitarray_is_iterable)
def testQBitArrayInvertOperator(self):
- #Tests QBitArray '~' (__invert__) operator
+ # Tests QBitArray '~' (__invert__) operator
inverted_qbitarray = ~self.qbitarray
# WARNING: do not pythonify the following loop, the
# iterability of QBitArray class is tested in another place
@@ -96,7 +76,7 @@ class QBitArrayIsIterableTest(unittest.TestCase):
self.assertEqual(self.inverted_qbitarray_values, inverted_qbitarray_values)
def testQBitArrayOrBitwiseOperator(self):
- #Tests QBitArray '|' (or) operator
+ # Tests QBitArray '|' (or) operator
has_or_bitwise_operator = True
ored_qbitarray, ored_bool_list = None, None
try:
@@ -108,7 +88,7 @@ class QBitArrayIsIterableTest(unittest.TestCase):
self.assertEqual(bool_list_from_qbitarray(ored_qbitarray), ored_bool_list)
def testQBitArrayAndBitwiseOperator(self):
- #Tests QBitArray '&' (and) operator
+ # Tests QBitArray '&' (and) operator
has_and_bitwise_operator = True
anded_qbitarray, anded_bool_list = None, None
try:
@@ -120,7 +100,7 @@ class QBitArrayIsIterableTest(unittest.TestCase):
self.assertEqual(bool_list_from_qbitarray(anded_qbitarray), anded_bool_list)
def testQBitArrayXorBitwiseOperator(self):
- #Tests QBitArray '^' (xor) operator
+ # Tests QBitArray '^' (xor) operator
has_xor_bitwise_operator = True
xored_qbitarray, xored_bool_list = None, None
try:
diff --git a/sources/pyside6/tests/QtCore/qbytearray_concatenation_operator_test.py b/sources/pyside6/tests/QtCore/qbytearray_concatenation_operator_test.py
index dcc3a059b..9c508d381 100644
--- a/sources/pyside6/tests/QtCore/qbytearray_concatenation_operator_test.py
+++ b/sources/pyside6/tests/QtCore/qbytearray_concatenation_operator_test.py
@@ -1,33 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QByteArray concatenation with '+' operator'''
@@ -47,20 +21,21 @@ class QByteArrayConcatenationOperatorTest(unittest.TestCase):
'''Test cases for QByteArray concatenation with '+' operator'''
def testConcatQByteArrayAndPythonString(self):
- #Test concatenation of a QByteArray with a Python bytes, in this order
+ # Test concatenation of a QByteArray with a Python bytes, in this order
qba = QByteArray(bytes('foo', "UTF-8"))
result = qba + bytes('\x00bar', "UTF-8")
self.assertEqual(type(result), QByteArray)
self.assertEqual(result, bytes('foo\x00bar', "UTF-8"))
def testConcatPythonStringAndQByteArray(self):
- #Test concatenation of a Python bytes with a QByteArray, in this order
+ # Test concatenation of a Python bytes with a QByteArray, in this order
concat_python_string_add_qbytearray_worked = True
qba = QByteArray(bytes('foo', "UTF-8"))
result = bytes('bar\x00', "UTF-8") + qba
self.assertEqual(type(result), QByteArray)
self.assertEqual(result, bytes('bar\x00foo', "UTF-8"))
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qbytearray_operator_iadd_test.py b/sources/pyside6/tests/QtCore/qbytearray_operator_iadd_test.py
index a65f76775..cd14941bc 100644
--- a/sources/pyside6/tests/QtCore/qbytearray_operator_iadd_test.py
+++ b/sources/pyside6/tests/QtCore/qbytearray_operator_iadd_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -58,7 +34,7 @@ class BaseQByteArrayOperatorIAdd(object):
def testString(self):
'''QByteArray += bytes of size > 1'''
s = bytearray(bytes('dummy', "UTF-8"))
- self.obj += s # XXx iadd support abytearray
+ self.obj += s # XXx iadd support abytearray
self.assertEqual(self.obj, self.orig_obj + s)
self.assertEqual(self.obj.size(), self.orig_obj.size() + len(s))
@@ -90,5 +66,6 @@ class ValidQByteArrayOperatorIAdd(unittest.TestCase, BaseQByteArrayOperatorIAdd)
self.obj = QByteArray(bytes('some byte array', "UTF-8"))
self.orig_obj = QByteArray(bytes('some byte array', "UTF-8"))
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qbytearray_operator_test.py b/sources/pyside6/tests/QtCore/qbytearray_operator_test.py
index 77678d199..c0e8b55e3 100644
--- a/sources/pyside6/tests/QtCore/qbytearray_operator_test.py
+++ b/sources/pyside6/tests/QtCore/qbytearray_operator_test.py
@@ -1,33 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QByteArray operators'''
@@ -42,30 +16,32 @@ init_test_paths(False)
from PySide6.QtCore import QByteArray
+
class QByteArrayOperatorEqual(unittest.TestCase):
'''TestCase for operator QByteArray == QByteArray'''
def testDefault(self):
- #QByteArray() == QByteArray()
+ # QByteArray() == QByteArray()
obj1 = QByteArray()
obj2 = QByteArray()
self.assertEqual(obj1, obj2)
def testSimple(self):
- #QByteArray(some_string) == QByteArray(some_string)
+ # QByteArray(some_string) == QByteArray(some_string)
string = bytes('egg snakes', "UTF-8")
self.assertEqual(QByteArray(string), QByteArray(string))
def testPyString(self):
- #QByteArray(string) == string
+ # QByteArray(string) == string
string = bytes('my test string', "UTF-8")
self.assertEqual(QByteArray(string), string)
+
class QByteArrayOperatorAt(unittest.TestCase):
'''TestCase for operator QByteArray[]'''
def testInRange(self):
- #QByteArray[x] where x is a valid index
+ # QByteArray[x] where x is a valid index
string = 'abcdefgh'
obj = QByteArray(bytes(string, "UTF-8"))
@@ -73,25 +49,25 @@ class QByteArrayOperatorAt(unittest.TestCase):
self.assertEqual(obj[i], bytes(string[i], "UTF-8"))
def testInRangeReverse(self):
- #QByteArray[x] where x is a valid index (reverse order)
+ # QByteArray[x] where x is a valid index (reverse order)
string = 'abcdefgh'
obj = QByteArray(bytes(string, "UTF-8"))
- for i in range(len(string)-1, 0, -1):
+ for i in range(len(string) - 1, 0, -1):
self.assertEqual(obj[i], bytes(string[i], "UTF-8"))
-
def testOutOfRange(self):
- #QByteArray[x] where x is out of index
+ # QByteArray[x] where x is out of index
string = bytes('1234567', "UTF-8")
obj = QByteArray(string)
- self.assertRaises(IndexError, lambda :obj[len(string)])
+ self.assertRaises(IndexError, lambda: obj[len(string)])
def testNullStrings(self):
ba = QByteArray(bytes('\x00', "UTF-8"))
self.assertEqual(ba.at(0), '\x00')
self.assertEqual(ba[0], bytes('\x00', "UTF-8"))
+
class QByteArrayOperatorLen(unittest.TestCase):
'''Test case for __len__ operator of QByteArray'''
diff --git a/sources/pyside6/tests/QtCore/qbytearray_test.py b/sources/pyside6/tests/QtCore/qbytearray_test.py
index 69e608d98..6f130ad6e 100644
--- a/sources/pyside6/tests/QtCore/qbytearray_test.py
+++ b/sources/pyside6/tests/QtCore/qbytearray_test.py
@@ -1,39 +1,13 @@
-# -*- coding:utf-8 -*-
-# !/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QByteArray'''
import ctypes
import os
import pickle
+import struct
import sys
import unittest
@@ -43,7 +17,9 @@ from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import QByteArray, QSettings, QObject, QDataStream, QIODevice
+from PySide6.QtCore import (QByteArray, QSettings, QObject, QDataStream,
+ QIODevice, qCompress, qUncompress)
+
class QByteArrayTestToNumber(unittest.TestCase):
def testToNumberInt(self):
@@ -95,10 +71,11 @@ class QByteArraySplit(unittest.TestCase):
'''Test case for QByteArray.split'''
def testPathSeparator(self):
- #QByteArray.split('/')
+ # QByteArray.split('/')
obj = QByteArray(bytes(unittest.__file__, "UTF8"))
self.assertEqual(obj.split('/'), unittest.__file__.split('/'))
+
class QByteArrayData(unittest.TestCase):
'''Test case for QByteArray.data'''
@@ -114,6 +91,7 @@ class QByteArrayData(unittest.TestCase):
self.assertEqual(s1, s2)
self.assertEqual(s1, ba)
+
class QByteArrayOperatorAtSetter(unittest.TestCase):
'''Test case for operator QByteArray[] - __setitem__'''
@@ -123,6 +101,7 @@ class QByteArrayOperatorAtSetter(unittest.TestCase):
obj[1] = bytes('0', "UTF8")
self.assertEqual(obj, QByteArray(bytes('103456', "UTF8")))
+
class QByteArrayOnQDataStream(unittest.TestCase):
'''
Bug PYSIDE-232
@@ -134,6 +113,7 @@ class QByteArrayOnQDataStream(unittest.TestCase):
# The __repr__ not suppose to crash anymore
self.assertNotEqual(repr(b), None)
+
class TestBug664(unittest.TestCase):
'''
QByteArray.data() should return correct data
@@ -148,6 +128,7 @@ class QByteArrayOnQVariant(unittest.TestCase):
a = QSettings().value("some_prop", QByteArray())
self.assertEqual(type(a), QByteArray)
+
class TestBug567(unittest.TestCase):
'''
QByteArray should support slices
@@ -171,12 +152,14 @@ class TestPickler(unittest.TestCase):
ba2 = pickle.loads(output)
self.assertEqual(str(ba), str(ba2))
+
class QByteArrayBug720(unittest.TestCase):
def testIt(self):
ba = QByteArray(bytes("32\"1\x00123", "UTF8"))
self.assertEqual(str(ba), str(bytes("32\"1\x00123", "UTF-8")))
self.assertEqual(repr(ba), "PySide6.QtCore.QByteArray(b'32\"1\\x00123')")
+
class QByteArrayImplicitConvert(unittest.TestCase):
def testString(self):
# No implicit conversions from QByteArray to python string
@@ -225,7 +208,7 @@ class QByteArraySliceAssignment(unittest.TestCase):
# shrink
b[2:8] = QByteArray(bytes('aaa', "UTF8"))
self.assertEqual(b, bytes('01aaa89', "UTF8"))
- # expanse
+ # expand
b[2:5] = QByteArray(bytes('uvwxyz', "UTF8"))
self.assertEqual(b, bytes('01uvwxyz89', "UTF8"))
# Delete behavior
@@ -233,7 +216,7 @@ class QByteArraySliceAssignment(unittest.TestCase):
self.assertEqual(b, bytes('0189', "UTF8"))
b = QByteArray(bytes('0123456789', "UTF8"))
- # reverse assginment
+ # reverse assignment
b[5:2:-1] = QByteArray(bytes('ABC', "UTF8"))
self.assertEqual(b, bytes('012CBA6789', "UTF8"))
# step is not 1
@@ -251,7 +234,7 @@ class QByteArraySliceAssignment(unittest.TestCase):
# shrink
b[2:8] = bytearray(bytes('aaa', "UTF8"))
self.assertEqual(b, bytes('01aaa89', "UTF8"))
- # expanse
+ # expand
b[2:5] = bytearray(bytes('uvwxyz', "UTF8"))
self.assertEqual(b, bytes('01uvwxyz89', "UTF8"))
# Delete behavior
@@ -259,7 +242,7 @@ class QByteArraySliceAssignment(unittest.TestCase):
self.assertEqual(b, bytes('0189', "UTF8"))
b = QByteArray(bytes('0123456789', "UTF8"))
- # reverse assginment
+ # reverse assignment
b[5:2:-1] = bytearray(bytes('ABC', "UTF8"))
self.assertEqual(b, bytes('012CBA6789', "UTF8"))
# step is not 1
@@ -275,6 +258,34 @@ class QByteArraySliceAssignment(unittest.TestCase):
actual_bytes = bytes(byte_array)
self.assertEqual(orig_bytes, actual_bytes)
+ def testUnpack(self):
+ b = QByteArray(b'\x19\x00\x00\x00\xc4\t\x00\x00')
+ t = struct.unpack('<ii', b)
+ self.assertEqual(len(t), 2)
+ self.assertEqual(t[0], 25)
+ self.assertEqual(t[1], 2500)
+
+
+class QCompressTest(unittest.TestCase):
+ def testQByteArrayCompression(self):
+ """Compress/uncompress a QByteArray."""
+ data = bytes(10 * 'long redundant sentence bla bla', "UTF8")
+ ba = QByteArray(data)
+ compressed = qCompress(ba)
+ self.assertTrue(len(compressed) < len(data))
+ uncompressed = qUncompress(compressed)
+ self.assertEqual(uncompressed, data)
+
+ def testBufferCompression(self):
+ """Compress/uncompress portions of bytes without converting to
+ QByteArray."""
+ data = bytes(10 * 'long redundant sentence bla bla', "UTF8")
+ used_len = int(len(data) / 2)
+ compressed = qCompress(data, used_len, -1)
+ self.assertTrue(len(compressed) < used_len)
+ uncompressed = qUncompress(compressed.data(), len(compressed))
+ self.assertEqual(uncompressed, data[:used_len])
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qcalendar_test.py b/sources/pyside6/tests/QtCore/qcalendar_test.py
index 0f9bfaf56..0861cd269 100644
--- a/sources/pyside6/tests/QtCore/qcalendar_test.py
+++ b/sources/pyside6/tests/QtCore/qcalendar_test.py
@@ -1,32 +1,7 @@
#!/usr/bin/python
-
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QCalendar (5.14)'''
@@ -41,6 +16,7 @@ init_test_paths(False)
from PySide6.QtCore import QCalendar
+
class TestQCalendar (unittest.TestCase):
def testCalendar(self):
calendar = QCalendar(QCalendar.System.Gregorian)
diff --git a/sources/pyside6/tests/QtCore/qcbor_test.py b/sources/pyside6/tests/QtCore/qcbor_test.py
index 06ba2d4d1..8d49c7151 100644
--- a/sources/pyside6/tests/QtCore/qcbor_test.py
+++ b/sources/pyside6/tests/QtCore/qcbor_test.py
@@ -1,35 +1,11 @@
#!/usr/bin/python
-
-#############################################################################
-##
-## Copyright (C) 2018 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of the test suite of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:GPL-EXCEPT$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 3 as published by the Free Software
-## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QCbor'''
+import gc
import os
import sys
import unittest
@@ -40,7 +16,8 @@ from init_paths import init_test_paths
init_test_paths(False)
from PySide6.QtCore import (QByteArray, QCborStreamReader, QCborStreamWriter,
- QCborValue)
+ QCborTag, QCborValue)
+
class TestCbor(unittest.TestCase):
def testReader(self):
@@ -48,6 +25,8 @@ class TestCbor(unittest.TestCase):
writer = QCborStreamWriter(ba)
writer.append(42)
del writer
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
self.assertTrue(not ba.isEmpty())
reader = QCborStreamReader(ba)
self.assertTrue(reader.hasNext())
@@ -59,10 +38,12 @@ class TestCbor(unittest.TestCase):
writer = QCborStreamWriter(ba)
writer.append("hello")
del writer
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
self.assertTrue(not ba.isEmpty())
reader = QCborStreamReader(ba)
self.assertTrue(reader.hasNext())
- if (reader.isByteArray()): # Python 2
+ if (reader.isByteArray()): # Python 2
value = reader.readByteArray()
self.assertTrue(value)
self.assertEqual(value.data, "hello")
@@ -77,5 +58,6 @@ class TestCbor(unittest.TestCase):
self.assertTrue(value.isString())
self.assertEqual(value.toString(), 'hello')
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qcollator_test.py b/sources/pyside6/tests/QtCore/qcollator_test.py
index b67b5ff2c..1be545582 100644
--- a/sources/pyside6/tests/QtCore/qcollator_test.py
+++ b/sources/pyside6/tests/QtCore/qcollator_test.py
@@ -1,32 +1,7 @@
#!/usr/bin/python
-
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QCollator'''
@@ -40,7 +15,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import QCollator, QLocale, Qt
+
class QCollatorTest(unittest.TestCase):
def testState(self):
@@ -63,5 +39,6 @@ class QCollatorTest(unittest.TestCase):
self.assertEqual(c.ignorePunctuation(), True)
self.assertEqual(c.locale(), QLocale(QLocale.NorwegianBokmal))
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qcommandlineparser_test.py b/sources/pyside6/tests/QtCore/qcommandlineparser_test.py
index 0c254f1d7..df17f95ee 100644
--- a/sources/pyside6/tests/QtCore/qcommandlineparser_test.py
+++ b/sources/pyside6/tests/QtCore/qcommandlineparser_test.py
@@ -1,32 +1,7 @@
#!/usr/bin/python
-
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QCommandLineParser and QCommandLineOption'''
@@ -40,7 +15,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import QCoreApplication, QCommandLineOption, QCommandLineParser
+
class QCommandLineParserTest(unittest.TestCase):
def testParser(self):
@@ -58,5 +34,6 @@ class QCommandLineParserTest(unittest.TestCase):
self.assertEqual(parser2.values("b"), [])
self.assertEqual(parser2.positionalArguments(), [])
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qcoreapplication_argv_test.py b/sources/pyside6/tests/QtCore/qcoreapplication_argv_test.py
new file mode 100644
index 000000000..9871eb97f
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/qcoreapplication_argv_test.py
@@ -0,0 +1,26 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import QCoreApplication
+
+
+class TestQCoreApplication(unittest.TestCase):
+ def testConsoleEncoding(self):
+ """PYSIDE-1425, console encoding on Windows."""
+ arg0 = "Üllrich Ümläut"
+ app = QCoreApplication([arg0])
+ self.assertEqual(app.arguments()[0], arg0)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qcoreapplication_instance_test.py b/sources/pyside6/tests/QtCore/qcoreapplication_instance_test.py
index f3f4bfd8c..4daab45bb 100644
--- a/sources/pyside6/tests/QtCore/qcoreapplication_instance_test.py
+++ b/sources/pyside6/tests/QtCore/qcoreapplication_instance_test.py
@@ -1,33 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QCoreApplication.instance static method'''
@@ -42,15 +16,17 @@ init_test_paths(False)
from PySide6.QtCore import QCoreApplication
+
class QCoreApplicationInstanceTest(unittest.TestCase):
'''Test cases for QCoreApplication.instance static method'''
def testQCoreApplicationInstance(self):
- #Tests QCoreApplication.instance()
+ # Tests QCoreApplication.instance()
self.assertEqual(QCoreApplication.instance(), None)
app = QCoreApplication([])
self.assertEqual(QCoreApplication.instance(), app)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qcoreapplication_test.py b/sources/pyside6/tests/QtCore/qcoreapplication_test.py
index 8809c2a8e..f8ea5a0f1 100644
--- a/sources/pyside6/tests/QtCore/qcoreapplication_test.py
+++ b/sources/pyside6/tests/QtCore/qcoreapplication_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,6 +13,7 @@ init_test_paths(False)
from PySide6.QtCore import QCoreApplication
+
class TestQCoreApplication(unittest.TestCase):
def testNoArguments(self):
app = QCoreApplication()
diff --git a/sources/pyside6/tests/QtCore/qdatastream_test.py b/sources/pyside6/tests/QtCore/qdatastream_test.py
index fd1dcfd46..5850974a1 100644
--- a/sources/pyside6/tests/QtCore/qdatastream_test.py
+++ b/sources/pyside6/tests/QtCore/qdatastream_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QDataStream'''
@@ -35,12 +10,15 @@ import sys
import unittest
from pathlib import Path
+
sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
+
init_test_paths(False)
from PySide6.QtCore import QBitArray, QByteArray, QIODevice, QDataStream, QDate, QTime, QDateTime
+
def create_bitarray(string):
array = QBitArray(len(string))
for i, char in enumerate(string):
@@ -109,6 +87,7 @@ class QDataStreamWrite(unittest.TestCase):
y = int(self.read.readUInt32())
self.assertEqual(x, y)
+
class QDataStreamShift(unittest.TestCase):
'''Test case for << and >> operators'''
@@ -223,7 +202,6 @@ class QDataStreamShift(unittest.TestCase):
self.assertTrue(res.isValid())
self.assertFalse(res.isNull())
-
def testQTimeNull(self):
'''QDataStream <<>> QTime - null'''
self.stream << QTime()
@@ -274,7 +252,6 @@ class QDataStreamShift(unittest.TestCase):
class QDataStreamShiftBitArray(unittest.TestCase):
-
def _check_bitarray(self, data_set):
'''Check the >> operator for the given data set'''
@@ -307,7 +284,7 @@ class QDataStreamShiftBitArray(unittest.TestCase):
self._check_bitarray([(serialized, QDataStream.ReadPastEnd, QBitArray())])
-class QDataStreamRawData(unittest.TestCase):
+class QDataStreamBuffer(unittest.TestCase):
def testRawData(self):
data = QDataStream()
self.assertEqual(data.readRawData(4), None)
@@ -320,6 +297,31 @@ class QDataStreamRawData(unittest.TestCase):
data = QDataStream(ba)
self.assertEqual(data.readRawData(4), bytes('AB\x00C', "UTF-8"))
+ def testRawDataBytes(self):
+ test_data = b'AB\0'
+ data = QDataStream()
+ ba = QByteArray()
+ data = QDataStream(ba, QIODevice.WriteOnly)
+ data.writeRawData(test_data)
+ self.assertEqual(ba.data(), test_data)
+ data = QDataStream(ba)
+ self.assertEqual(data.readRawData(3), test_data)
+
+ def testBytes(self):
+ dataOne = QDataStream()
+ self.assertEqual(dataOne.readBytes(4), None)
+
+ ba = QByteArray()
+ data = QDataStream(ba, QIODevice.WriteOnly)
+ # writeBytes() writes a quint32 containing the length of the data,
+ # followed by the data.
+ data.writeBytes(bytes('AB\x00C', 'UTF-8'))
+ self.assertEqual(ba.data(), bytes('\x00\x00\x00\x04AB\x00C', 'UTF-8'))
+
+ data = QDataStream(ba)
+ buffer = data.readBytes(4)
+ self.assertEqual(buffer, bytes('AB\x00C', 'UTF-8'))
+
+
if __name__ == '__main__':
unittest.main()
-
diff --git a/sources/pyside6/tests/QtCore/qdate_test.py b/sources/pyside6/tests/QtCore/qdate_test.py
index 91f445e83..6979c62fb 100644
--- a/sources/pyside6/tests/QtCore/qdate_test.py
+++ b/sources/pyside6/tests/QtCore/qdate_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QDate'''
@@ -39,7 +14,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import QDate
+
class TestQDate (unittest.TestCase):
def testGetDate(self):
@@ -65,5 +41,6 @@ class TestQDate (unittest.TestCase):
nodate = QDate()
self.assertFalse(nodate)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qdatetime_test.py b/sources/pyside6/tests/QtCore/qdatetime_test.py
index 5342f40b0..fa9a988be 100644
--- a/sources/pyside6/tests/QtCore/qdatetime_test.py
+++ b/sources/pyside6/tests/QtCore/qdatetime_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import datetime
import os
@@ -38,6 +14,7 @@ init_test_paths(False)
from PySide6.QtCore import QDateTime, QDate, QTime
+
class TestQDate (unittest.TestCase):
def testDateConversion(self):
dateTime = QDateTime(QDate(2011, 5, 17), QTime(11, 1, 14, 15))
@@ -54,5 +31,6 @@ class TestQDate (unittest.TestCase):
qt = QDateTime(py)
self.assertEqual(qt, py)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qdir_test.py b/sources/pyside6/tests/QtCore/qdir_test.py
new file mode 100644
index 000000000..ba360629b
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/qdir_test.py
@@ -0,0 +1,40 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import QDir
+
+
+class QDirTest(unittest.TestCase):
+ '''Test case for QDir'''
+
+ def testConstructor(self):
+ # Optional case without arguments is equivalent to the constructor
+ # QDir(const QString &path = QString())
+ a = QDir()
+
+ self.assertTrue(a.isReadable())
+ self.assertTrue(a.isRelative())
+
+ # Empty string
+ b = QDir("")
+ self.assertEqual(a, b)
+
+ # Empty Path
+ c = QDir(Path())
+ self.assertEqual(a, c)
+
+ self.assertEqual(b, c)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qeasingcurve_test.py b/sources/pyside6/tests/QtCore/qeasingcurve_test.py
index 4966b207c..b39563bb9 100644
--- a/sources/pyside6/tests/QtCore/qeasingcurve_test.py
+++ b/sources/pyside6/tests/QtCore/qeasingcurve_test.py
@@ -1,34 +1,11 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
import unittest
+import gc
from pathlib import Path
sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
@@ -37,12 +14,14 @@ init_test_paths(False)
from PySide6.QtCore import QEasingCurve
+
def myFunction(progress):
if progress == 1.0:
return 100.0
else:
return -100.0
+
class TestQEasingCurve(unittest.TestCase):
def testCustomType(self):
ec = QEasingCurve()
@@ -56,6 +35,9 @@ class TestQEasingCurve(unittest.TestCase):
ec.setCustomType(myFunction)
self.assertEqual(ec.valueForProgress(1.0), 100.0)
self.assertEqual(ec.valueForProgress(0.5), -100.0)
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qenum_test.py b/sources/pyside6/tests/QtCore/qenum_test.py
index 146773094..e064ea40d 100644
--- a/sources/pyside6/tests/QtCore/qenum_test.py
+++ b/sources/pyside6/tests/QtCore/qenum_test.py
@@ -1,32 +1,7 @@
#!/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 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QEnum and QFlags'''
@@ -45,20 +20,6 @@ from PySide6.QtCore import Qt, QIODevice, QObject, QEnum, QFlag
class TestEnum(unittest.TestCase):
-
- def testToInt(self):
- self.assertEqual(QIODevice.NotOpen, 0)
- self.assertEqual(QIODevice.ReadOnly, 1)
- self.assertEqual(QIODevice.WriteOnly, 2)
- self.assertEqual(QIODevice.ReadWrite, 1 | 2)
- self.assertEqual(QIODevice.Append, 4)
- self.assertEqual(QIODevice.Truncate, 8)
- self.assertEqual(QIODevice.Text, 16)
- self.assertEqual(QIODevice.Unbuffered, 32)
-
- def testToIntInFunction(self):
- self.assertEqual(str(int(QIODevice.WriteOnly)), "2")
-
def testOperations(self):
k = Qt.Key.Key_1
@@ -67,16 +28,6 @@ class TestEnum(unittest.TestCase):
self.assertEqual(k - 2, -(2 - k))
self.assertEqual(k * 2, 2 * k)
- # Floats
- with self.assertRaises(TypeError):
- a = k + 2.0
-
- with self.assertRaises(TypeError):
- a = k - 2.0
-
- with self.assertRaises(TypeError):
- a = k * 2.0
-
@unittest.skipUnless(getattr(sys, "getobjects", None), "requires --with-trace-refs")
@unittest.skipUnless(getattr(sys, "gettotalrefcount", None), "requires --with-pydebug")
def testEnumNew_NoLeak(self):
@@ -97,18 +48,20 @@ class TestEnum(unittest.TestCase):
class TestQFlags(unittest.TestCase):
+
def testToItn(self):
om = QIODevice.NotOpen
+ omcmp = om.value
self.assertEqual(om, QIODevice.NotOpen)
- self.assertTrue(om == 0)
+ self.assertTrue(omcmp == 0)
- self.assertTrue(om != QIODevice.ReadOnly)
- self.assertTrue(om != 1)
+ self.assertTrue(omcmp != QIODevice.ReadOnly)
+ self.assertTrue(omcmp != 1)
def testToIntInFunction(self):
om = QIODevice.WriteOnly
- self.assertEqual(int(om), 2)
+ self.assertEqual(int(om.value), 2)
def testNonExtensibleEnums(self):
try:
@@ -142,6 +95,7 @@ class TestEnumPickling(unittest.TestCase):
# PYSIDE-957: The QEnum macro
+
try:
import enum
HAVE_ENUM = True
@@ -149,21 +103,27 @@ except ImportError:
HAVE_ENUM = False
QEnum = QFlag = lambda x: x
import types
- class Enum: pass
+
+ class Enum:
+ pass
enum = types.ModuleType("enum")
enum.Enum = enum.Flag = enum.IntEnum = enum.IntFlag = Enum
Enum.__module__ = "enum"
Enum.__members__ = {}
del Enum
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
enum.auto = lambda: 42
HAVE_FLAG = hasattr(enum, "Flag")
+
@QEnum
class OuterEnum(enum.Enum):
A = 1
B = 2
+
class SomeClass(QObject):
@QEnum
@@ -192,16 +152,15 @@ class SomeClass(QObject):
QEnum(SomeEnum) # works even without the decorator assignment
-@unittest.skipUnless(HAVE_ENUM, "requires 'enum' module (use 'pip install enum34' for Python 2)")
class TestQEnumMacro(unittest.TestCase):
+ meta_name = "EnumType" if sys.version_info[:2] >= (3, 11) else "EnumMeta"
+
def testTopLevel(self):
- self.assertEqual(type(OuterEnum).__module__, "enum")
- self.assertEqual(type(OuterEnum).__name__, "EnumMeta")
+ self.assertEqual(type(OuterEnum).__name__, self.meta_name)
self.assertEqual(len(OuterEnum.__members__), 2)
def testSomeClass(self):
- self.assertEqual(type(SomeClass.SomeEnum).__module__, "enum")
- self.assertEqual(type(SomeClass.SomeEnum).__name__, "EnumMeta")
+ self.assertEqual(type(SomeClass.SomeEnum).__name__, self.meta_name)
self.assertEqual(len(SomeClass.SomeEnum.__members__), 3)
with self.assertRaises(TypeError):
int(SomeClass.SomeEnum.C) == 6
diff --git a/sources/pyside6/tests/QtCore/qevent_test.py b/sources/pyside6/tests/QtCore/qevent_test.py
index 8251c5814..d2ab7d1eb 100644
--- a/sources/pyside6/tests/QtCore/qevent_test.py
+++ b/sources/pyside6/tests/QtCore/qevent_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QtCore.QEvent'''
@@ -41,11 +16,12 @@ init_test_paths(False)
from PySide6.QtCore import QEvent
+
class QEventTypeFlag(unittest.TestCase):
'''Test case for usage of QEvent.Type flags'''
def testFlagAccess(self):
- #QEvent.Type flags usage
+ # QEvent.Type flags usage
event = QEvent(QEvent.Timer)
self.assertEqual(event.type(), QEvent.Timer)
@@ -56,5 +32,6 @@ class QEventTypeFlag(unittest.TestCase):
event = QEvent(QEvent.IconTextChange)
self.assertEqual(event.type(), QEvent.IconTextChange)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qfile_test.py b/sources/pyside6/tests/QtCore/qfile_test.py
index d00ac72a7..4535159de 100644
--- a/sources/pyside6/tests/QtCore/qfile_test.py
+++ b/sources/pyside6/tests/QtCore/qfile_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -38,6 +14,7 @@ init_test_paths(False)
from PySide6.QtCore import QDir, QFile, QIODevice, QSaveFile, QTemporaryDir
+
class GetCharTest(unittest.TestCase):
'''Test case for QIODevice.getChar in QFile'''
@@ -84,5 +61,26 @@ class GetCharTest(unittest.TestCase):
self.assertTrue(saveFile.commit())
self.assertTrue(os.path.exists(QDir.toNativeSeparators(saveFile.fileName())))
+
+class GetCharTestPath(GetCharTest):
+ # PYSIDE-1499: Do the same with Path objects
+
+ def setUp(self):
+ '''Acquire resources'''
+ handle, filename = tempfile.mkstemp()
+ self.filename = Path(filename)
+ os.write(handle, bytes('a', "UTF-8"))
+ os.close(handle)
+
+
+class DirPath(unittest.TestCase):
+ # PYSIDE-1499: Test QDir with Path objects
+ def testQDirPath(self):
+ test_path = Path("some") / "dir"
+ qdir1 = QDir(os.fspath(test_path))
+ qdir2 = QDir(test_path)
+ self.assertEqual(qdir1, qdir2)
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qfileinfo_test.py b/sources/pyside6/tests/QtCore/qfileinfo_test.py
index 3049a8fc1..1836ca8a3 100644
--- a/sources/pyside6/tests/QtCore/qfileinfo_test.py
+++ b/sources/pyside6/tests/QtCore/qfileinfo_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -38,6 +14,7 @@ init_test_paths(False)
from PySide6.QtCore import QFile, QFileInfo
+
class QFileConstructor(unittest.TestCase):
'''QFileInfo constructor with qfile'''
@@ -45,5 +22,13 @@ class QFileConstructor(unittest.TestCase):
'''QFileInfo(QFile)'''
obj = QFileInfo(QFile())
+ def testQFileInfoPath(self):
+ # PYSIDE-1499: Test QFileInfo with Path objects
+ test_path = Path("some") / "dir"
+ qinf1 = QFileInfo(os.fspath(test_path))
+ qinf2 = QFileInfo(test_path)
+ self.assertEqual(qinf1, qinf2)
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qfileread_test.py b/sources/pyside6/tests/QtCore/qfileread_test.py
index 0e4e670e5..250f16ce1 100644
--- a/sources/pyside6/tests/QtCore/qfileread_test.py
+++ b/sources/pyside6/tests/QtCore/qfileread_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -41,12 +17,15 @@ from PySide6.QtCore import QIODevice, QTemporaryFile
class FileChild1(QTemporaryFile):
pass
+
class FileChild2(QTemporaryFile):
def readData(self, maxlen):
return super(FileChild2, self).readData(maxlen)
+
def readLineData(self, maxlen):
return super(FileChild2, self).readLineData(maxlen)
+
class readDataTest(unittest.TestCase):
'''Test case for readData and readLineData'''
@@ -70,7 +49,6 @@ class readDataTest(unittest.TestCase):
s1 = self.filename1.read(50)
self.assertEqual(s1, 'Test text for testing')
-
def testBug40(self):
self.filename2.seek(0)
s2 = self.filename2.read(50)
@@ -84,5 +62,6 @@ class readDataTest(unittest.TestCase):
s1 = self.filename1.read(50)
self.assertEqual(s1, s2)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qflags_test.py b/sources/pyside6/tests/QtCore/qflags_test.py
index 4b368681f..31b6f60f0 100644
--- a/sources/pyside6/tests/QtCore/qflags_test.py
+++ b/sources/pyside6/tests/QtCore/qflags_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QFlags'''
@@ -42,6 +17,7 @@ init_test_paths(False)
from PySide6.QtCore import Qt, QTemporaryFile, QFile, QIODevice, QObject
+
class QFlagTest(unittest.TestCase):
'''Test case for usage of flags'''
@@ -110,21 +86,46 @@ class QFlagOperatorTest(unittest.TestCase):
flags = Qt.NoItemFlags | Qt.ItemIsUserCheckable
self.assertEqual(flags | Qt.ItemIsEnabled, Qt.ItemIsEnabled | flags)
+ def testEqualNonNumericalObject(self):
+ '''QFlags ==,!= non-numerical object '''
+ flags = Qt.NoItemFlags | Qt.ItemIsUserCheckable
+
+ self.assertTrue(flags != None) # noqa: E711
+ self.assertFalse(flags == None) # noqa: E711
+
+ self.assertTrue(flags != "tomato")
+ self.assertFalse(flags == "tomato")
+
+ with self.assertRaises(TypeError):
+ flags > None
+ with self.assertRaises(TypeError):
+ flags >= None
+ with self.assertRaises(TypeError):
+ flags < None
+ with self.assertRaises(TypeError):
+ flags <= None
+
+
class QFlagsOnQVariant(unittest.TestCase):
def testQFlagsOnQVariant(self):
o = QObject()
o.setProperty("foo", QIODevice.ReadOnly | QIODevice.WriteOnly)
self.assertEqual(type(o.property("foo")), QIODevice.OpenMode)
-class QFlagsWrongType(unittest.TestCase):
- def testWrongType(self):
- '''Wrong type passed to QFlags binary operators'''
- for op in operator.or_, operator.and_, operator.xor:
- for x in '43', 'jabba', QObject, object:
- self.assertRaises(TypeError, op, Qt.NoItemFlags, x)
- self.assertRaises(TypeError, op, x, Qt.NoItemFlags)
- # making sure this actually does not fail all the time
- self.assertEqual(operator.or_(Qt.NoItemFlags, 43), 43)
+
+class QEnumFlagDefault(unittest.TestCase):
+ """
+ Check that old flag and enum syntax can be used.
+ The signatures of these surrogate functions intentionally do not exist
+ because people should learn to use the new Enums correctly.
+ """
+ def testOldQFlag(self):
+ self.assertEqual(Qt.AlignmentFlag(), Qt.AlignmentFlag(0))
+ oldFlag = Qt.Alignment()
+ oldEnum = Qt.AlignmentFlag()
+ self.assertEqual(type(oldFlag), Qt.Alignment)
+ self.assertEqual(type(oldEnum), Qt.AlignmentFlag)
+ self.assertEqual(type(oldFlag), type(oldEnum))
if __name__ == '__main__':
diff --git a/sources/pyside6/tests/QtCore/qhandle_test.py b/sources/pyside6/tests/QtCore/qhandle_test.py
index 08e53633c..2b59a2d8b 100644
--- a/sources/pyside6/tests/QtCore/qhandle_test.py
+++ b/sources/pyside6/tests/QtCore/qhandle_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QEnum and QFlags'''
@@ -41,6 +16,7 @@ init_test_paths(False)
from PySide6.QtCore import QThread, Qt
+
class TestHANDLE(unittest.TestCase):
def testIntConversion(self):
i = 0
@@ -48,5 +24,6 @@ class TestHANDLE(unittest.TestCase):
i = 0 + int(h)
self.assertEqual(i, int(h))
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qinstallmsghandler_test.py b/sources/pyside6/tests/QtCore/qinstallmsghandler_test.py
index ca6e5afba..041b006ca 100644
--- a/sources/pyside6/tests/QtCore/qinstallmsghandler_test.py
+++ b/sources/pyside6/tests/QtCore/qinstallmsghandler_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for qInstallMsgHandler'''
@@ -37,17 +13,24 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import (QLibraryInfo, QtMsgType,
+ QMessageLogContext,
+ qCritical, qFormatLogMessage, qDebug,
+ qInstallMessageHandler, qWarning)
+
param = []
+
def handler(msgt, ctx, msg):
global param
param = [msgt, ctx, msg.strip()]
+
def handleruseless(msgt, ctx, msg):
pass
+
class QInstallMsgHandlerTest(unittest.TestCase):
def tearDown(self):
@@ -58,6 +41,7 @@ class QInstallMsgHandlerTest(unittest.TestCase):
ret = qInstallMessageHandler(None)
self.assertEqual(ret, None)
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testRet(self):
ret = qInstallMessageHandler(None)
self.assertEqual(ret, None)
@@ -73,15 +57,21 @@ class QInstallMsgHandlerTest(unittest.TestCase):
rethandler = qInstallMessageHandler(handler)
if QLibraryInfo.isDebugBuild():
qDebug("Test Debug")
- self.assertEqual(param[0], QtDebugMsg)
+ self.assertEqual(param[0], QtMsgType.QtDebugMsg)
self.assertEqual(param[2], "Test Debug")
qWarning("Test Warning")
- self.assertEqual(param[0], QtWarningMsg)
+ self.assertEqual(param[0], QtMsgType.QtWarningMsg)
self.assertEqual(param[2], "Test Warning")
qCritical("Test Critical")
- self.assertEqual(param[0], QtCriticalMsg)
+ self.assertEqual(param[0], QtMsgType.QtCriticalMsg)
self.assertEqual(param[2], "Test Critical")
+ def testFormat(self):
+ ctx = QMessageLogContext()
+ s = qFormatLogMessage(QtMsgType.QtInfoMsg, ctx, 'bla')
+ self.assertTrue(s)
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qiodevice_buffered_read_test.py b/sources/pyside6/tests/QtCore/qiodevice_buffered_read_test.py
new file mode 100644
index 000000000..a20e41be8
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/qiodevice_buffered_read_test.py
@@ -0,0 +1,79 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+'''Test cases for buffered read methods of QIODevice'''
+
+from PySide6.QtCore import QBuffer
+
+import enum
+import unittest
+
+
+class TestQIODeviceBufferedRead(unittest.TestCase):
+ class TestType(enum.Enum):
+ Read = enum.auto()
+ ReadLine = enum.auto()
+ Peek = enum.auto()
+
+ def setUp(self) -> None:
+ self.buffer = QBuffer()
+ self.text = "Tomato juice\nPotato salad\n"
+
+ self.assertTrue(
+ self.buffer.open(QBuffer.OpenModeFlag.ReadWrite), self.buffer.errorString())
+ self.assertGreaterEqual(
+ self.buffer.write(self.text.encode("utf-8")), 0, self.buffer.errorString())
+
+ self.buffer.seek(0)
+
+ def tearDown(self) -> None:
+ self.buffer.close()
+
+ def test_read(self) -> None:
+ response1 = self.buffer.read(1024).data().decode("utf-8")
+ self.assertEqual(response1, self.text)
+
+ self.buffer.seek(0)
+ response2 = bytearray(1024)
+ bytes_read = self.buffer.read(response2, 1024)
+
+ self.assertGreaterEqual(bytes_read, 0, self.buffer.errorString())
+ self.assertEqual(response2[:bytes_read].decode("utf-8"), response1)
+
+ def test_readLine(self) -> None:
+ response1 = self.buffer.readLine(1024).data().decode("utf-8")
+ # Only read until the first line (including the line break)
+ self.assertEqual(response1, self.text.split("\n", 1)[0] + "\n")
+
+ self.buffer.seek(0)
+ response2 = bytearray(1024)
+ bytes_read = self.buffer.readLine(response2, 1024)
+
+ self.assertGreaterEqual(bytes_read, 0, self.buffer.errorString())
+ self.assertEqual(response2[:bytes_read].decode("utf-8"), response1)
+
+ def test_peek(self) -> None:
+ response1 = self.buffer.peek(1024).data().decode("utf-8")
+ self.assertEqual(response1, self.text)
+
+ # Test that peek has no side effects
+ response_again1 = self.buffer.read(1024).data().decode("utf-8")
+ self.assertEqual(response_again1, response1)
+
+ self.buffer.seek(0)
+ response2 = bytearray(1024)
+ bytes_read = self.buffer.peek(response2, 1024)
+
+ self.assertGreaterEqual(bytes_read, 0, self.buffer.errorString())
+ self.assertEqual(response2[:bytes_read].decode("utf-8"), response1)
+
+ # Test that peek has no side effects
+ response_again2 = bytearray(1024)
+ bytes_read_again2 = self.buffer.read(response_again2, 1024)
+ self.assertEqual(bytes_read, bytes_read_again2)
+ self.assertEqual(response_again2, response2)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qiopipe_test.py b/sources/pyside6/tests/QtCore/qiopipe_test.py
new file mode 100644
index 000000000..908a3a892
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/qiopipe_test.py
@@ -0,0 +1,37 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+'''Test cases for the QIOPipe class'''
+
+from PySide6.QtCore import QIODevice, QIOPipe
+
+import unittest
+
+
+class QIOPipeTest(unittest.TestCase):
+ def setUp(self) -> None:
+ self.pipe = QIOPipe()
+ self.pipe.open(QIODevice.OpenModeFlag.ReadWrite)
+ return super().setUp()
+
+ def tearDown(self) -> None:
+ super().tearDown()
+
+ def ready_read_bytes_written(self):
+ received_data = self.pipe.end2().readAll().data()
+ self.assertEqual(received_data, self.data)
+
+ def test_readyRead(self):
+ self.data = b"Hello, World!"
+ self.pipe.end2().readyRead.connect(self.ready_read_bytes_written)
+ self.pipe.end1().write(self.data)
+
+ def test_bytesWritten(self):
+ self.data = b"Hello, World!"
+ self.pipe.end2().bytesWritten.connect(self.ready_read_bytes_written)
+ self.pipe.end1().write(self.data)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qjsondocument_test.py b/sources/pyside6/tests/QtCore/qjsondocument_test.py
index 334ba07ec..63683fd3f 100644
--- a/sources/pyside6/tests/QtCore/qjsondocument_test.py
+++ b/sources/pyside6/tests/QtCore/qjsondocument_test.py
@@ -1,32 +1,7 @@
#!/usr/bin/python
-
-#############################################################################
-##
-## Copyright (C) 2018 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of the test suite of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:GPL-EXCEPT$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 3 as published by the Free Software
-## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QJsonDocument/nullptr_t'''
diff --git a/sources/pyside6/tests/QtCore/qlinef_test.py b/sources/pyside6/tests/QtCore/qlinef_test.py
index 663310716..7c9e668df 100644
--- a/sources/pyside6/tests/QtCore/qlinef_test.py
+++ b/sources/pyside6/tests/QtCore/qlinef_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QLineF'''
@@ -39,7 +14,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import QLineF, QPointF
+
class TestQLineF (unittest.TestCase):
def testIntersect(self):
@@ -51,5 +27,6 @@ class TestQLineF (unittest.TestCase):
self.assertEqual(QLineF.BoundedIntersection, value)
self.assertEqual(QPointF(1, 0), p)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qlocale_test.py b/sources/pyside6/tests/QtCore/qlocale_test.py
index d2ba4bf5e..6ad933d8f 100644
--- a/sources/pyside6/tests/QtCore/qlocale_test.py
+++ b/sources/pyside6/tests/QtCore/qlocale_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QLocale'''
@@ -42,6 +17,7 @@ init_test_paths(False)
from PySide6.QtCore import QLocale
+
class QLocaleTestToNumber(unittest.TestCase):
def testToNumberInt(self):
obj = QLocale(QLocale.C)
@@ -62,6 +38,11 @@ class QLocaleTestToNumber(unittest.TestCase):
self.assertEqual((ctypes.c_short(37).value, True),
obj.toShort('37'))
+ def testToNumberLong(self):
+ obj = QLocale(QLocale.C)
+ self.assertEqual((ctypes.c_long(37).value, True),
+ obj.toLong('37'))
+
def testToNumberULongLong(self):
obj = QLocale(QLocale.C)
self.assertEqual((ctypes.c_ulonglong(37).value, True),
@@ -71,5 +52,23 @@ class QLocaleTestToNumber(unittest.TestCase):
obj = QLocale(QLocale.C)
self.assertTrue(not obj.toULongLong('-37')[1])
+ def testToCurrencyString(self):
+ """PYSIDE-2133, do not use int overload, dropping decimals."""
+ en_locale = QLocale("en_US")
+ value = en_locale.toCurrencyString(1234.56)
+ self.assertEqual(value, "$1,234.56")
+
+ def testToString(self):
+ """PYSIDE-2168, check negative values"""
+ en_locale = QLocale("en_US")
+ value = en_locale.toString(-4)
+ self.assertEqual(value, "-4")
+ # Verify that large types (long long/double) are used.
+ value = en_locale.toString(3000000000)
+ self.assertEqual(value, "3,000,000,000")
+ value = en_locale.toString(10e40)
+ self.assertEqual(value, "1E+41")
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qlockfile_test.py b/sources/pyside6/tests/QtCore/qlockfile_test.py
index 2508b3f7b..e6e614b26 100644
--- a/sources/pyside6/tests/QtCore/qlockfile_test.py
+++ b/sources/pyside6/tests/QtCore/qlockfile_test.py
@@ -1,32 +1,7 @@
#!/usr/bin/python
-
-#############################################################################
-##
-## Copyright (C) 2018 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of the test suite of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:GPL-EXCEPT$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 3 as published by the Free Software
-## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QLockFile'''
@@ -42,6 +17,7 @@ init_test_paths()
from PySide6.QtCore import QDir, QLockFile, QCoreApplication
+
class TestQMessageAuthenticationCode (unittest.TestCase):
def setUp(self):
@@ -57,7 +33,11 @@ class TestQMessageAuthenticationCode (unittest.TestCase):
lockFile = QLockFile(self._fileName)
self.assertTrue(lockFile.lock())
self.assertTrue(lockFile.isLocked())
+ lock_info = lockFile.getLockInfo();
+ self.assertEqual(len(lock_info), 3)
+ self.assertEqual(lock_info[0], os.getpid())
lockFile.unlock()
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qmessageauthenticationcode_test.py b/sources/pyside6/tests/QtCore/qmessageauthenticationcode_test.py
index d312fe412..92778a78b 100644
--- a/sources/pyside6/tests/QtCore/qmessageauthenticationcode_test.py
+++ b/sources/pyside6/tests/QtCore/qmessageauthenticationcode_test.py
@@ -1,32 +1,7 @@
#!/usr/bin/python
-
-#############################################################################
-##
-## Copyright (C) 2018 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of the test suite of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:GPL-EXCEPT$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 3 as published by the Free Software
-## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QMessageAuthenticationCode'''
@@ -41,6 +16,7 @@ init_test_paths(False)
from PySide6.QtCore import QCryptographicHash, QMessageAuthenticationCode
+
class TestQMessageAuthenticationCode (unittest.TestCase):
def test(self):
code = QMessageAuthenticationCode(QCryptographicHash.Sha1, bytes('bla', "UTF-8"))
@@ -48,5 +24,6 @@ class TestQMessageAuthenticationCode (unittest.TestCase):
self.assertTrue(result.size() > 0)
print(result.toHex())
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qmetaobject_test.py b/sources/pyside6/tests/QtCore/qmetaobject_test.py
index e4773afbb..ff8ed859e 100644
--- a/sources/pyside6/tests/QtCore/qmetaobject_test.py
+++ b/sources/pyside6/tests/QtCore/qmetaobject_test.py
@@ -1,33 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Tests for static methos conflicts with class methods'''
@@ -40,15 +14,72 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import (QCoreApplication, QFile, QMetaMethod, QMetaObject,
+ QObject, QModelIndex, QPoint, QTimer, QSemaphore,
+ QStringListModel, Qt, Signal, Slot,
+ SIGNAL, Q_ARG, Q_RETURN_ARG)
+
class Foo(QFile):
- pass
+ pass
+
class DynObject(QObject):
def slot(self):
pass
+
+class InvokeTester(QObject):
+ def __init__(self, parent=None):
+ super().__init__(parent)
+
+ @Slot(int, int, result=int)
+ def add(self, a, b):
+ return a + b
+
+ @Slot(str, str, result=str)
+ def concatenate(self, a, b):
+ return a + b
+
+ @Slot(QPoint, result=int)
+ def manhattan_length(self, point):
+ return abs(point.x()) + abs(point.y())
+
+ @Slot(QPoint, QPoint, result=QPoint)
+ def add_points(self, point1, point2):
+ return point1 + point2
+
+ @Slot(QObject, result=str)
+ def object_name(self, o):
+ return o.objectName()
+
+ @Slot(QObject, result=QObject)
+ def first_child(self, o):
+ return o.children()[0]
+
+
+class SemaphoreSender(QObject):
+ signal = Signal(QSemaphore)
+
+ def __init__(self, parent=None):
+ super().__init__(parent)
+ self.semaphore = QSemaphore()
+
+ def emitSignal(self):
+ self.signal.emit(self.semaphore)
+
+
+class SemaphoreReceiver(QObject):
+
+ def __init__(self, parent=None):
+ super().__init__(parent)
+ self.semaphore = None
+
+ @Slot(QSemaphore)
+ def receiverSlot(self, semaphore):
+ self.semaphore = semaphore
+
+
class qmetaobject_test(unittest.TestCase):
"""
def test_QMetaObject(self):
@@ -75,15 +106,6 @@ class qmetaobject_test(unittest.TestCase):
o.connect(o2, SIGNAL("bars()"), o.slot)
self.assertTrue(o2.metaObject().indexOfMethod("bars()") > -1)
- #self.assertTrue(o.metaObject().indexOfMethod("bar()") == -1)
- #self.assertTrue(o.metaObject().indexOfMethod("slot()") > -1)
-
- #slot_index = o.metaObject().indexOfMethod("slot()")
-
- #o.connect(o, SIGNAL("foo()"), o2, SIGNAL("bar()"))
- #signal_index = o.metaObject().indexOfMethod("foo()");
-
- #self.assertTrue(slot_index != signal_index)
# PYSIDE-784, plain Qt objects should not have intermediary
# metaObjects.
@@ -92,6 +114,101 @@ class qmetaobject_test(unittest.TestCase):
self.assertEqual(timer.metaObject().superClass().className(),
"QObject")
+ # PYSIDE-1827, slots with non-QObject object types should work
+ # (metatypes are registered)
+ def test_ObjectSlotSignal(self):
+ app = QCoreApplication() # noqa: F841
+ sender = SemaphoreSender()
+ receiver = SemaphoreReceiver()
+ sender.signal.connect(receiver.receiverSlot, Qt.QueuedConnection)
+ sender.emitSignal()
+ while not receiver.semaphore:
+ QCoreApplication.processEvents()
+ self.assertEqual(sender.semaphore, receiver.semaphore)
+
+ # PYSIDE-1898,
+ def test_Invoke(self):
+ tester = InvokeTester()
+
+ # Primitive types
+ sum = QMetaObject.invokeMethod(tester, "add", Q_RETURN_ARG(int),
+ Q_ARG(int, 2), Q_ARG(int, 3))
+ self.assertEqual(sum, 5)
+
+ # Same with QMetaMethod
+ mo = tester.metaObject()
+ method = mo.method(mo.indexOfMethod("add(int,int)"))
+ self.assertTrue(method.isValid())
+ sum = method.invoke(tester, Qt.ConnectionType.AutoConnection,
+ Q_RETURN_ARG(int), Q_ARG(int, 2), Q_ARG(int, 3))
+ self.assertEqual(sum, 5)
+ sum = method.invoke(tester, Q_RETURN_ARG(int), Q_ARG(int, 2),
+ Q_ARG(int, 3))
+ self.assertEqual(sum, 5)
+
+ concatenated = QMetaObject.invokeMethod(tester, "concatenate",
+ Q_RETURN_ARG(str),
+ Q_ARG(str, "bla"),
+ Q_ARG(str, "bla"))
+ self.assertEqual(concatenated, "blabla")
+
+ # Wrapped type as in-parameter
+ point = QPoint(10, 20)
+ len = QMetaObject.invokeMethod(tester, "manhattan_length",
+ Q_RETURN_ARG(int),
+ Q_ARG(QPoint, point))
+ self.assertEqual(len, point.manhattanLength())
+
+ # Wrapped type as result
+ point2 = QPoint(30, 30)
+ point3 = QMetaObject.invokeMethod(tester, "add_points",
+ Q_RETURN_ARG(QPoint),
+ Q_ARG(QPoint, point),
+ Q_ARG(QPoint, point2))
+ self.assertEqual(point + point2, point3)
+
+ # Pass an object
+ o = QObject()
+ o.setObjectName("Foo")
+ name = QMetaObject.invokeMethod(tester, "object_name",
+ Q_RETURN_ARG(str),
+ Q_ARG(QObject, o))
+ self.assertEqual(name, o.objectName())
+
+ # Return an object
+ child = QObject(o)
+ child.setObjectName("Child")
+ c = QMetaObject.invokeMethod(tester, "first_child",
+ Q_RETURN_ARG(QObject),
+ Q_ARG(QObject, o))
+ self.assertTrue(c)
+ self.assertEqual(c, child)
+
+ def test_InvokeTypeString(self):
+ strings = ["item1", "item2"]
+ model = QStringListModel(strings)
+ index = model.index(1, 0)
+ QMetaObject.invokeMethod(model, "setData",
+ Q_ARG(QModelIndex, index),
+ Q_ARG("QVariant", "bla"))
+ self.assertEqual(model.data(index), "bla")
+
+ # Same with QMetaMethod
+ mo = model.metaObject()
+ method = mo.method(mo.indexOfMethod("setData(QModelIndex,QVariant)"))
+ self.assertTrue(method.isValid())
+ method.invoke(model, Qt.ConnectionType.AutoConnection,
+ Q_ARG(QModelIndex, index), Q_ARG("QVariant", "blub"))
+ self.assertEqual(model.data(index), "blub")
+ method.invoke(model, Q_ARG(QModelIndex, index), Q_ARG("QVariant", "blip"))
+ self.assertEqual(model.data(index), "blip")
+
+ def test_QMetaMethod(self):
+ o = QObject()
+ m = QMetaMethod.fromSignal(o.destroyed)
+ self.assertTrue(m.isValid)
+ self.assertEqual(m.methodSignature(), b"destroyed()")
+
+
if __name__ == '__main__':
unittest.main()
-
diff --git a/sources/pyside6/tests/QtCore/qmetatype_test.py b/sources/pyside6/tests/QtCore/qmetatype_test.py
new file mode 100644
index 000000000..cdd02e5ba
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/qmetatype_test.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+# Copyright (C) 2022The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+'''Tests for QMetaType'''
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import (QMetaType, QObject, QPoint)
+
+
+class qmetatype_test(unittest.TestCase):
+ def test_ObjectSlotSignal(self):
+ meta_type = QMetaType(int)
+ self.assertTrue(meta_type.isValid())
+ self.assertEqual(meta_type.name(), "int")
+
+ meta_type = QMetaType(str)
+ self.assertTrue(meta_type.isValid())
+ self.assertEqual(meta_type.name(), "QString")
+
+ meta_type = QMetaType(float)
+ self.assertTrue(meta_type.isValid())
+ self.assertEqual(meta_type.name(), "double")
+
+ meta_type = QMetaType(QPoint)
+ self.assertTrue(meta_type.isValid())
+ self.assertEqual(meta_type.name(), "QPoint")
+
+ meta_type = QMetaType(QObject)
+ self.assertTrue(meta_type.isValid())
+ self.assertEqual(meta_type.name(), "QObject*")
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qmimedatabase_test.py b/sources/pyside6/tests/QtCore/qmimedatabase_test.py
index ee16142e0..c2b967a26 100644
--- a/sources/pyside6/tests/QtCore/qmimedatabase_test.py
+++ b/sources/pyside6/tests/QtCore/qmimedatabase_test.py
@@ -1,36 +1,10 @@
#!/usr/bin/python
-
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QMimeDatabase'''
-import ctypes
import os
import sys
import unittest
@@ -42,6 +16,7 @@ init_test_paths(False)
from PySide6.QtCore import QMimeDatabase, QLocale
+
class QMimeDatabaseTest(unittest.TestCase):
def testMimeTypeForName(self):
db = QMimeDatabase()
@@ -49,8 +24,7 @@ class QMimeDatabaseTest(unittest.TestCase):
s0 = db.mimeTypeForName("application/x-zerosize")
self.assertTrue(s0.isValid())
self.assertEqual(s0.name(), "application/x-zerosize")
- if "en" in QLocale().name():
- self.assertEqual(s0.comment(), "empty document")
+ self.assertTrue(s0.comment())
s0Again = db.mimeTypeForName("application/x-zerosize")
self.assertEqual(s0Again.name(), s0.name())
@@ -65,13 +39,13 @@ class QMimeDatabaseTest(unittest.TestCase):
rdf = db.mimeTypeForName("application/rdf+xml")
self.assertTrue(rdf.isValid())
self.assertEqual(rdf.name(), "application/rdf+xml")
+ self.assertTrue(rdf.comment())
if "en" in QLocale().name():
self.assertEqual(rdf.comment(), "RDF file")
bzip2 = db.mimeTypeForName("application/x-bzip2")
self.assertTrue(bzip2.isValid())
- if "en" in QLocale().name():
- self.assertEqual(bzip2.comment(), "Bzip archive")
+ self.assertTrue(bzip2.comment())
defaultMime = db.mimeTypeForName("application/octet-stream")
self.assertTrue(defaultMime.isValid())
@@ -81,5 +55,6 @@ class QMimeDatabaseTest(unittest.TestCase):
doesNotExist = db.mimeTypeForName("foobar/x-doesnot-exist")
self.assertTrue(not doesNotExist.isValid())
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qmodelindex_internalpointer_test.py b/sources/pyside6/tests/QtCore/qmodelindex_internalpointer_test.py
index 9e7febdf5..e3dfce8b9 100644
--- a/sources/pyside6/tests/QtCore/qmodelindex_internalpointer_test.py
+++ b/sources/pyside6/tests/QtCore/qmodelindex_internalpointer_test.py
@@ -1,35 +1,10 @@
-# -*- 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
''' Test case for QAbstractListModel.createIndex and QModelIndex.internalPointer'''
+import gc
import os
import sys
import unittest
@@ -39,46 +14,51 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import QAbstractListModel, QObject
+
class MyModel (QAbstractListModel):
pass
+
class TestQModelIndexInternalPointer(unittest.TestCase):
''' Test case for QAbstractListModel.createIndex and QModelIndex.internalPointer'''
def setUp(self):
- #Acquire resources
+ # Acquire resources
self.model = MyModel()
def tearDown(self):
- #Release resources
+ # Release resources
del self.model
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
def testInternalPointer(self):
- #Test QAbstractListModel.createIndex and
- #QModelIndex.internalPointer with regular Python objects
+ # Test QAbstractListModel.createIndex and
+ # QModelIndex.internalPointer with regular Python objects
obj = QObject()
idx = self.model.createIndex(0, 0, "Hello")
i = idx.internalPointer()
self.assertEqual(i, "Hello")
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testReferenceCounting(self):
- #Test reference counting when retrieving data with
- #QModelIndex.internalPointer
+ # Test reference counting when retrieving data with
+ # QModelIndex.internalPointer
o = [1, 2, 3]
o_refcnt = sys.getrefcount(o)
idx = self.model.createIndex(0, 0, o)
ptr = idx.internalPointer()
self.assertEqual(sys.getrefcount(o), o_refcnt + 1)
-
def testIndexForDefaultDataArg(self):
- #Test QAbstractListModel.createIndex with a default
- #value for data argument
+ # Test QAbstractListModel.createIndex with a default
+ # value for data argument
idx = self.model.createIndex(0, 0)
self.assertEqual(None, idx.internalPointer())
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qobject_children_segfault_test.py b/sources/pyside6/tests/QtCore/qobject_children_segfault_test.py
index f1d7fff1c..4bdd3922b 100644
--- a/sources/pyside6/tests/QtCore/qobject_children_segfault_test.py
+++ b/sources/pyside6/tests/QtCore/qobject_children_segfault_test.py
@@ -1,33 +1,10 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for parent-child relationship'''
+import gc
import os
import sys
import unittest
@@ -39,11 +16,12 @@ init_test_paths(False)
from PySide6.QtCore import QObject, QCoreApplication
+
class ChildrenCoreApplication(unittest.TestCase):
'''Test case for calling QObject.children after creating a QCoreApp'''
def testQCoreAppChildren(self):
- #QObject.children() after creating a QCoreApplication
+ # QObject.children() after creating a QCoreApplication
# Minimal test:
# 1- Create QCoreApp
# 2- Create parent and childrens
@@ -55,7 +33,9 @@ class ChildrenCoreApplication(unittest.TestCase):
# Uncomment the lines below to make the test pass
# del children
# del child2
- del parent # XXX Segfaults here
+ del parent # XXX Segfaults here
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
self.assertTrue(True)
diff --git a/sources/pyside6/tests/QtCore/qobject_connect_notify_test.py b/sources/pyside6/tests/QtCore/qobject_connect_notify_test.py
index 714c47189..af9e081d9 100644
--- a/sources/pyside6/tests/QtCore/qobject_connect_notify_test.py
+++ b/sources/pyside6/tests/QtCore/qobject_connect_notify_test.py
@@ -1,32 +1,6 @@
-# -*- 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
''' Test case for QObject::connectNotify()'''
@@ -39,15 +13,20 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
-from helper.usesqcoreapplication import UsesQCoreApplication
+from PySide6.QtCore import QObject, Signal, SIGNAL, SLOT
+from helper.usesqapplication import UsesQApplication
+
def cute_slot():
pass
+
class Obj(QObject):
+
+ foo = Signal()
+
def __init__(self):
- QObject.__init__(self)
+ super().__init__()
self.con_notified = False
self.dis_notified = False
self.signal = ""
@@ -63,50 +42,59 @@ class Obj(QObject):
self.con_notified = False
self.dis_notified = False
-class TestQObjectConnectNotify(UsesQCoreApplication):
+
+class TestQObjectConnectNotify(UsesQApplication):
'''Test case for QObject::connectNotify'''
def setUp(self):
- UsesQCoreApplication.setUp(self)
+ UsesQApplication.setUp(self)
self.called = False
def tearDown(self):
- UsesQCoreApplication.tearDown(self)
+ UsesQApplication.tearDown(self)
def testBasic(self):
sender = Obj()
receiver = QObject()
+ sender.destroyed.connect(receiver.deleteLater)
+ self.assertTrue(sender.con_notified)
+ self.assertEqual(sender.signal.methodSignature(), "destroyed()")
+ self.assertTrue(sender.destroyed.disconnect(receiver.deleteLater))
+ self.assertTrue(sender.dis_notified)
+
+ def testBasicString(self):
+ sender = Obj()
+ receiver = QObject()
sender.connect(SIGNAL("destroyed()"), receiver, SLOT("deleteLater()"))
self.assertTrue(sender.con_notified)
# When connecting to a regular slot, and not a python callback function, QObject::connect
# will use the non-cloned method signature, so connecting to destroyed() will actually
# connect to destroyed(QObject*).
self.assertEqual(sender.signal.methodSignature(), "destroyed(QObject*)")
- sender.disconnect(SIGNAL("destroyed()"), receiver, SLOT("deleteLater()"))
+ self.assertTrue(sender.disconnect(SIGNAL("destroyed()"), receiver, SLOT("deleteLater()")))
self.assertTrue(sender.dis_notified)
def testPySignal(self):
sender = Obj()
receiver = QObject()
- sender.connect(SIGNAL("foo()"), receiver, SLOT("deleteLater()"))
+ sender.foo.connect(receiver.deleteLater)
self.assertTrue(sender.con_notified)
- sender.disconnect(SIGNAL("foo()"), receiver, SLOT("deleteLater()"))
+ self.assertTrue(sender.foo.disconnect(receiver.deleteLater))
self.assertTrue(sender.dis_notified)
def testPySlots(self):
sender = Obj()
- receiver = QObject()
- sender.connect(SIGNAL("destroyed()"), cute_slot)
+ sender.destroyed.connect(cute_slot)
self.assertTrue(sender.con_notified)
- sender.disconnect(SIGNAL("destroyed()"), cute_slot)
+ self.assertTrue(sender.destroyed.disconnect(cute_slot))
self.assertTrue(sender.dis_notified)
def testpyAll(self):
sender = Obj()
- receiver = QObject()
- sender.connect(SIGNAL("foo()"), cute_slot)
+ sender.foo.connect(cute_slot)
self.assertTrue(sender.con_notified)
- sender.disconnect(SIGNAL("foo()"), cute_slot)
+ self.assertTrue(sender.foo.disconnect(cute_slot))
self.assertTrue(sender.dis_notified)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qobject_destructor.py b/sources/pyside6/tests/QtCore/qobject_destructor.py
index 50f2ffc10..9bb80459a 100644
--- a/sources/pyside6/tests/QtCore/qobject_destructor.py
+++ b/sources/pyside6/tests/QtCore/qobject_destructor.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -35,20 +11,24 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6 import QtCore
+from PySide6.QtCore import QObject
-class MyObject(QtCore.QObject):
+
+class MyObject(QObject):
def __init__(self, other=None):
- QtCore.QObject.__init__(self, None)
+ super().__init__(None)
self._o = other
+
class TestDestructor(unittest.TestCase):
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testReference(self):
- o = QtCore.QObject()
+ o = QObject()
m = MyObject(o)
self.assertEqual(sys.getrefcount(o), 3)
del m
self.assertEqual(sys.getrefcount(o), 2)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qobject_event_filter_test.py b/sources/pyside6/tests/QtCore/qobject_event_filter_test.py
index 112f21103..a011f7240 100644
--- a/sources/pyside6/tests/QtCore/qobject_event_filter_test.py
+++ b/sources/pyside6/tests/QtCore/qobject_event_filter_test.py
@@ -1,33 +1,10 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QObject.eventFilter'''
+import gc
import os
import sys
import unittest
@@ -40,12 +17,13 @@ init_test_paths(False)
from PySide6.QtCore import QObject, QTimerEvent
-from helper.usesqcoreapplication import UsesQCoreApplication
+from helper.usesqapplication import UsesQApplication
+
class FilterObject(QObject):
'''Filter object for the basic test'''
def __init__(self, obj=None, event_type=None, *args):
- #Creates a new filter object
+ # Creates a new filter object
QObject.__init__(self, *args)
self.obj = obj
self.event_type = event_type
@@ -53,7 +31,7 @@ class FilterObject(QObject):
self.events_bypassed = 0
def setTargetObject(self, obj):
- #Sets the object that will be filtered
+ # Sets the object that will be filtered
self.obj = obj
def eventFilter(self, obj, event):
@@ -70,6 +48,7 @@ class FilterObject(QObject):
else:
return QObject.eventFilter(self, obj, event)
+
class FilteredObject(QObject):
'''Class that will be filtered. Quits the app after 5 timer events'''
def __init__(self, app, *args):
@@ -78,39 +57,60 @@ class FilteredObject(QObject):
self.times_called = 0
def timerEvent(self, evt):
- #Overriden method
+ # Overridden method
self.times_called += 1
if self.times_called == 5:
self.app.quit()
-class TestQObjectEventFilterPython(UsesQCoreApplication):
+
+class PolymorphicIdFilterObject(QObject):
+ """PYSIDE-2675: Check whether QChildEvent.added() is accessible via PolymorphicId"""
+ def __init__(self, parent=None):
+ super().__init__(parent)
+ self.added = False
+
+ def event(self, event):
+ self.added = event.added()
+ return False
+
+
+class TestQObjectEventFilterPython(UsesQApplication):
'''QObject.eventFilter - Reimplemented in python
Filters 5 TimerEvents and then bypasses the other events to the
timerEvent method. After 5 runs, the timerEvent method will ask
the core application to exit'''
def setUp(self):
- #Acquire resources
- UsesQCoreApplication.setUp(self)
+ # Acquire resources
+ UsesQApplication.setUp(self)
self.obj_filter = FilterObject(event_type=QTimerEvent)
+
def tearDown(self):
- #Release resources
+ # Release resources
del self.obj_filter
- UsesQCoreApplication.tearDown(self)
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+ UsesQApplication.tearDown(self)
def testEventFilter(self):
- #QObject.eventFilter reimplemented in python
+ # QObject.eventFilter reimplemented in python
filtered = FilteredObject(self.app)
filtered.installEventFilter(self.obj_filter)
self.obj_filter.setTargetObject(filtered)
filtered.startTimer(0)
- self.app.exec_()
+ self.app.exec()
self.assertEqual(filtered.times_called, 5)
self.assertEqual(self.obj_filter.events_handled, 5)
+ def testPolymorphicId(self):
+ testObject = PolymorphicIdFilterObject()
+ t2 = QObject(testObject) # noqa: F841
+ self.assertTrue(testObject.added)
+
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testInstallEventFilterRefCountAfterDelete(self):
'''Bug 910 - installEventFilter() increments reference count on target object
http://bugs.pyside.org/show_bug.cgi?id=910'''
@@ -127,6 +127,7 @@ class TestQObjectEventFilterPython(UsesQCoreApplication):
del obj
self.assertEqual(wref(), None)
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testInstallEventFilterRefCountAfterRemove(self):
# Bug 910
obj = QObject()
@@ -145,5 +146,6 @@ class TestQObjectEventFilterPython(UsesQCoreApplication):
del obj
self.assertEqual(wref(), None)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qobject_inherits_test.py b/sources/pyside6/tests/QtCore/qobject_inherits_test.py
index 0d0b0d174..bdd927fe2 100644
--- a/sources/pyside6/tests/QtCore/qobject_inherits_test.py
+++ b/sources/pyside6/tests/QtCore/qobject_inherits_test.py
@@ -1,33 +1,10 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QObject methods'''
+import gc
import os
import sys
import unittest
@@ -42,19 +19,20 @@ from PySide6.QtWidgets import QApplication, QLabel, QVBoxLayout
is_alive = None
+
class InheritsCase(unittest.TestCase):
'''Test case for QObject.inherits'''
def testCppInheritance(self):
- #QObject.inherits() for c++ classes
- #An class inherits itself
+ # QObject.inherits() for c++ classes
+ # A class inherits itself
self.assertTrue(QObject().inherits('QObject'))
def testPythonInheritance(self):
- #QObject.inherits() for python classes
+ # QObject.inherits() for python classes
class Dummy(QObject):
- #Dummy class
+ # Dummy class
pass
self.assertTrue(Dummy().inherits('QObject'))
@@ -62,15 +40,16 @@ class InheritsCase(unittest.TestCase):
self.assertTrue(not Dummy().inherits('FooBar'))
def testPythonMultiInheritance(self):
- #QObject.inherits() for multiple inheritance
+ # QObject.inherits() for multiple inheritance
# QObject.inherits(classname) should fail if classname isn't a
# QObject subclass
class Parent(object):
- #Dummy parent
+ # Dummy parent
pass
+
class Dummy(QObject, Parent):
- #Dummy class
+ # Dummy class
pass
self.assertTrue(Dummy().inherits('QObject'))
@@ -81,7 +60,7 @@ class InheritsCase(unittest.TestCase):
class DerivedObject(QObject):
def __init__(self):
self.member = 'member'
- QObject.__init__(self)
+ super().__init__()
obj0 = DerivedObject()
# The second instantiation of DerivedObject will generate an exception
# that will not come to surface immediately.
@@ -108,6 +87,7 @@ class InheritsCase(unittest.TestCase):
# 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
@@ -122,9 +102,13 @@ class InheritsCase(unittest.TestCase):
child.deleteLater()
self.assertTrue(is_alive)
del child
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
self.assertTrue(is_alive)
QTimer.singleShot(100, app.quit)
- app.exec_()
+ app.exec()
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
self.assertFalse(is_alive)
diff --git a/sources/pyside6/tests/QtCore/qobject_objectproperty_test.py b/sources/pyside6/tests/QtCore/qobject_objectproperty_test.py
index ac86ed8d1..b12c3c77e 100644
--- a/sources/pyside6/tests/QtCore/qobject_objectproperty_test.py
+++ b/sources/pyside6/tests/QtCore/qobject_objectproperty_test.py
@@ -1,33 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test case for the bug #378
http://bugs.openbossa.org/show_bug.cgi?id=378
@@ -44,6 +18,7 @@ init_test_paths(False)
from PySide6.QtCore import QObject
+
class ExtQObject(QObject):
def __init__(self):
# "foobar" will become a object attribute that will not be
@@ -53,7 +28,8 @@ class ExtQObject(QObject):
self.foobar = None
# The parent __init__ method must be called after the
# definition of "self.foobar".
- QObject.__init__(self)
+ super().__init__()
+
class TestBug378(unittest.TestCase):
'''Test case for the bug #378'''
@@ -61,6 +37,7 @@ class TestBug378(unittest.TestCase):
def testBug378(self):
obj = ExtQObject()
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qobject_parent_test.py b/sources/pyside6/tests/QtCore/qobject_parent_test.py
index 776d34461..103a3eb03 100644
--- a/sources/pyside6/tests/QtCore/qobject_parent_test.py
+++ b/sources/pyside6/tests/QtCore/qobject_parent_test.py
@@ -1,36 +1,12 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for parent-child relationship'''
+import gc
import os
import sys
-from sys import getrefcount
import unittest
from pathlib import Path
@@ -38,44 +14,61 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import QObject, QRegularExpression, QTimer, Qt
+
+
+class TestObject1(QTimer):
+ def __init(self, parent):
+ super().__init__(parent)
+
+
+class TestObject2(TestObject1):
+ def __init(self, parent):
+ super().__init__(parent)
+
class ParentRefCountCase(unittest.TestCase):
'''Test case for the refcount changes of setParent'''
def setUp(self):
- #Acquire resources
+ # Acquire resources
self.parent = QObject()
self.child = QObject()
def tearDown(self):
- #Release resources
+ # Release resources
del self.child
del self.parent
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testSetParent(self):
- #QObject.setParent() refcount changes
- self.assertEqual(getrefcount(self.child), 2)
+ # QObject.setParent() refcount changes
+ self.assertEqual(sys.getrefcount(self.child), 2)
self.child.setParent(self.parent)
- self.assertEqual(getrefcount(self.child), 3)
+ self.assertEqual(sys.getrefcount(self.child), 3)
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testSetParentTwice(self):
- self.assertEqual(getrefcount(self.child), 2)
+ self.assertEqual(sys.getrefcount(self.child), 2)
self.child.setParent(self.parent)
- self.assertEqual(getrefcount(self.child), 3)
+ self.assertEqual(sys.getrefcount(self.child), 3)
self.child.setParent(self.parent)
- self.assertEqual(getrefcount(self.child), 3)
+ self.assertEqual(sys.getrefcount(self.child), 3)
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testConstructor(self):
- #QObject(QObject) refcount changes
+ # QObject(QObject) refcount changes
child = QObject(self.parent)
- self.assertEqual(getrefcount(child), 3)
+ self.assertEqual(sys.getrefcount(child), 3)
+
class ParentCase(unittest.TestCase):
'''Small collection of tests related to parent-child relationship'''
def testSetParent(self):
- #QObject.setParent()
+ # QObject.setParent()
parent = QObject()
child = QObject()
child.setParent(parent)
@@ -83,7 +76,7 @@ class ParentCase(unittest.TestCase):
self.assertEqual(parent, child.parent())
def testParentConstructor(self):
- #QObject(parent)
+ # QObject(parent)
parent = QObject()
child = QObject(parent)
@@ -91,40 +84,65 @@ class ParentCase(unittest.TestCase):
orig_repr = repr(child)
del child
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
self.assertEqual(orig_repr, repr(parent.children()[0]))
def testChildren(self):
- #QObject.children()
+ # QObject.children()
parent = QObject()
children = [QObject(parent) for x in range(25)]
self.assertEqual(parent.children(), children)
def testFindChild(self):
- #QObject.findChild() with all QObject
+ # QObject.findChild() with all QObject
parent = QObject()
- name = 'object%d'
children = [QObject(parent) for i in range(20)]
for i, child in enumerate(children):
- child.setObjectName(name % i)
+ child.setObjectName(f'object{i}')
for i, child in enumerate(children):
- self.assertEqual(child, parent.findChild(QObject, name % i))
+ self.assertEqual(child, parent.findChild(QObject, f'object{i}'))
+
+ def testFindChildOptions(self):
+ parent = QObject()
+ child = QObject(parent)
+ nested_child_name = 'nestedChild'
+ nested_child = QObject(child)
+ nested_child.setObjectName(nested_child_name)
+
+ search_result = parent.findChild(QObject, nested_child_name)
+ self.assertTrue(search_result)
+ search_result = parent.findChild(QObject, nested_child_name,
+ Qt.FindChildrenRecursively)
+ self.assertTrue(search_result)
+ search_result = parent.findChild(QObject, nested_child_name,
+ Qt.FindDirectChildrenOnly)
+ self.assertFalse(search_result)
+
+ search_results = parent.findChildren(QObject, nested_child_name)
+ self.assertEqual(len(search_results), 1)
+ search_result = parent.findChildren(QObject, nested_child_name,
+ Qt.FindChildrenRecursively)
+ self.assertEqual(len(search_results), 1)
+ search_results = parent.findChildren(QObject, nested_child_name,
+ Qt.FindDirectChildrenOnly)
+ self.assertEqual(len(search_results), 0)
def testFindChildWithoutName(self):
parent = QObject()
- name = 'object%d'
children = [QObject(parent) for i in range(20)]
for i, child in enumerate(children):
- child.setObjectName(name % i)
+ child.setObjectName(f'object{i}')
child = parent.findChild(QObject)
self.assertTrue(isinstance(child, QObject))
def testFindChildren(self):
- #QObject.findChildren() with all QObject
+ # QObject.findChildren() with all QObject
parent = QObject()
target_name = 'foo'
children = [QTimer(parent) for i in range(20)]
@@ -150,86 +168,110 @@ class ParentCase(unittest.TestCase):
self.assertEqual(res, test_children)
def testParentEquality(self):
- #QObject.parent() == parent
+ # QObject.parent() == parent
parent = QObject()
child = QObject(parent)
self.assertEqual(parent, child.parent())
+ def testFindChildByType(self):
+ parent = QObject()
+ expected = TestObject2(parent)
+ actual = parent.findChild(TestObject2)
+ self.assertEqual(actual, expected)
+ actual = parent.findChild(TestObject1)
+ self.assertEqual(actual, expected)
+ actual = parent.findChild(QTimer)
+ self.assertEqual(actual, expected)
+
+ def testFindChildrenByType(self):
+ parent = QObject()
+ expected = [TestObject2(parent)]
+ actual = parent.findChildren(TestObject2)
+ self.assertEqual(actual, expected)
+ actual = parent.findChildren(TestObject1)
+ self.assertEqual(actual, expected)
+ actual = parent.findChildren(QTimer)
+ self.assertEqual(actual, expected)
+
class TestParentOwnership(unittest.TestCase):
'''Test case for Parent/Child object ownership'''
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testParentDestructor(self):
parent = QObject()
- self.assertEqual(getrefcount(parent), 2)
+ self.assertEqual(sys.getrefcount(parent), 2)
child = QObject(parent)
- self.assertEqual(getrefcount(child), 3)
- self.assertEqual(getrefcount(parent), 2)
+ self.assertEqual(sys.getrefcount(child), 3)
+ self.assertEqual(sys.getrefcount(parent), 2)
del parent
- self.assertEqual(getrefcount(child), 2)
+ self.assertEqual(sys.getrefcount(child), 2)
# this will fail because parent deleted child cpp object
- self.assertRaises(RuntimeError, lambda :child.objectName())
+ self.assertRaises(RuntimeError, lambda: child.objectName())
# test parent with multiples children
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testMultipleChildren(self):
o = QObject()
- self.assertEqual(getrefcount(o), 2)
+ self.assertEqual(sys.getrefcount(o), 2)
c = QObject(o)
- self.assertEqual(getrefcount(c), 3)
- self.assertEqual(getrefcount(o), 2)
+ self.assertEqual(sys.getrefcount(c), 3)
+ self.assertEqual(sys.getrefcount(o), 2)
c2 = QObject(o)
- self.assertEqual(getrefcount(o), 2)
- self.assertEqual(getrefcount(c), 3)
- self.assertEqual(getrefcount(c2), 3)
+ self.assertEqual(sys.getrefcount(o), 2)
+ self.assertEqual(sys.getrefcount(c), 3)
+ self.assertEqual(sys.getrefcount(c2), 3)
del o
- self.assertEqual(getrefcount(c), 2)
- self.assertEqual(getrefcount(c2), 2)
+ self.assertEqual(sys.getrefcount(c), 2)
+ self.assertEqual(sys.getrefcount(c2), 2)
# this will fail because parent deleted child cpp object
- self.assertRaises(RuntimeError, lambda :c.objectName())
- self.assertRaises(RuntimeError, lambda :c2.objectName())
+ self.assertRaises(RuntimeError, lambda: c.objectName())
+ self.assertRaises(RuntimeError, lambda: c2.objectName())
# test recursive parent
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testRecursiveParent(self):
o = QObject()
- self.assertEqual(getrefcount(o), 2)
+ self.assertEqual(sys.getrefcount(o), 2)
c = QObject(o)
- self.assertEqual(getrefcount(c), 3)
- self.assertEqual(getrefcount(o), 2)
+ self.assertEqual(sys.getrefcount(c), 3)
+ self.assertEqual(sys.getrefcount(o), 2)
c2 = QObject(c)
- self.assertEqual(getrefcount(o), 2)
- self.assertEqual(getrefcount(c), 3)
- self.assertEqual(getrefcount(c2), 3)
+ self.assertEqual(sys.getrefcount(o), 2)
+ self.assertEqual(sys.getrefcount(c), 3)
+ self.assertEqual(sys.getrefcount(c2), 3)
del o
- self.assertEqual(getrefcount(c), 2)
- self.assertEqual(getrefcount(c2), 2)
+ self.assertEqual(sys.getrefcount(c), 2)
+ self.assertEqual(sys.getrefcount(c2), 2)
# this will fail because parent deleted child cpp object
- self.assertRaises(RuntimeError, lambda :c.objectName())
- self.assertRaises(RuntimeError, lambda :c2.objectName())
+ self.assertRaises(RuntimeError, lambda: c.objectName())
+ self.assertRaises(RuntimeError, lambda: c2.objectName())
# test parent transfer
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testParentTransfer(self):
o = QObject()
- self.assertEqual(getrefcount(o), 2)
+ self.assertEqual(sys.getrefcount(o), 2)
c = QObject()
- self.assertEqual(getrefcount(c), 2)
+ self.assertEqual(sys.getrefcount(c), 2)
c.setParent(o)
- self.assertEqual(getrefcount(c), 3)
+ self.assertEqual(sys.getrefcount(c), 3)
c.setParent(None)
- self.assertEqual(getrefcount(c), 2)
+ self.assertEqual(sys.getrefcount(c), 2)
del c
del o
@@ -237,7 +279,8 @@ class TestParentOwnership(unittest.TestCase):
class ExtQObject(QObject):
def __init__(self):
- QObject.__init__(self)
+ super().__init__()
+
class ReparentingTest(unittest.TestCase):
'''Test cases for reparenting'''
diff --git a/sources/pyside6/tests/QtCore/qobject_property_test.py b/sources/pyside6/tests/QtCore/qobject_property_test.py
index 7abe3ede0..37936205e 100644
--- a/sources/pyside6/tests/QtCore/qobject_property_test.py
+++ b/sources/pyside6/tests/QtCore/qobject_property_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QObject property and setProperty'''
@@ -39,6 +15,7 @@ init_test_paths(False)
from PySide6.QtCore import QObject, Property, Signal
+
class MyObjectWithNotifyProperty(QObject):
def __init__(self, parent=None):
QObject.__init__(self, parent)
@@ -54,6 +31,7 @@ class MyObjectWithNotifyProperty(QObject):
notifyP = Signal()
myProperty = Property(int, readP, fset=writeP, notify=notifyP)
+
class PropertyWithNotify(unittest.TestCase):
def called(self):
self.called_ = True
diff --git a/sources/pyside6/tests/QtCore/qobject_protected_methods_test.py b/sources/pyside6/tests/QtCore/qobject_protected_methods_test.py
index baa62ac1e..5ab5d12c3 100644
--- a/sources/pyside6/tests/QtCore/qobject_protected_methods_test.py
+++ b/sources/pyside6/tests/QtCore/qobject_protected_methods_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QObject protected methods'''
@@ -41,32 +16,34 @@ init_test_paths(False)
from PySide6.QtCore import QObject, QThread, SIGNAL
+
class Dummy(QObject):
'''Dummy class'''
pass
+
class QObjectReceivers(unittest.TestCase):
'''Test case for QObject.receivers()'''
def cb(self, *args):
- #Dummy callback
+ # Dummy callback
pass
def testQObjectReceiversExtern(self):
- #QObject.receivers() - Protected method external access
+ # QObject.receivers() - Protected method external access
obj = Dummy()
self.assertEqual(obj.receivers(SIGNAL("destroyed()")), 0)
- QObject.connect(obj, SIGNAL("destroyed()"), self.cb)
+ obj.destroyed.connect(self.cb)
self.assertEqual(obj.receivers(SIGNAL("destroyed()")), 1)
def testQThreadReceiversExtern(self):
- #QThread.receivers() - Inherited protected method
+ # QThread.receivers() - Inherited protected method
obj = QThread()
self.assertEqual(obj.receivers(SIGNAL('destroyed()')), 0)
- QObject.connect(obj, SIGNAL("destroyed()"), self.cb)
+ obj.destroyed.connect(self.cb)
self.assertEqual(obj.receivers(SIGNAL("destroyed()")), 1)
diff --git a/sources/pyside6/tests/QtCore/qobject_test.py b/sources/pyside6/tests/QtCore/qobject_test.py
index d452e828e..176ab34b8 100644
--- a/sources/pyside6/tests/QtCore/qobject_test.py
+++ b/sources/pyside6/tests/QtCore/qobject_test.py
@@ -1,33 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QObject methods'''
@@ -40,18 +14,38 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import QObject, Signal, Qt
+from PySide6.QtCore import QObject, Signal, Slot, Qt
+
class Obj(QObject):
signal = Signal()
+
def empty(self):
pass
+ def emitSignal(self):
+ self.signal.emit()
+
+
+class Receiver(QObject):
+
+ def __init__(self, parent=None):
+ super().__init__(parent)
+ self._count = 0
+
+ def count(self):
+ return self._count
+
+ @Slot()
+ def testSlot(self):
+ self._count += 1
+
+
class ObjectNameCase(unittest.TestCase):
'''Tests related to QObject object name'''
def testSimple(self):
- #QObject.objectName(string)
+ # QObject.objectName(string)
name = 'object1'
obj = QObject()
obj.setObjectName(name)
@@ -59,7 +53,7 @@ class ObjectNameCase(unittest.TestCase):
self.assertEqual(name, obj.objectName())
def testEmpty(self):
- #QObject.objectName('')
+ # QObject.objectName('')
name = ''
obj = QObject()
obj.setObjectName(name)
@@ -67,13 +61,13 @@ class ObjectNameCase(unittest.TestCase):
self.assertEqual(name, obj.objectName())
def testDefault(self):
- #QObject.objectName() default
+ # QObject.objectName() default
obj = QObject()
self.assertEqual('', obj.objectName())
def testUnicode(self):
name = 'não'
- #FIXME Strange error on upstream when using equal(name, obj)
+ # FIXME Strange error on upstream when using equal(name, obj)
obj = QObject()
obj.setObjectName(name)
self.assertEqual(obj.objectName(), name)
@@ -85,5 +79,19 @@ class ObjectNameCase(unittest.TestCase):
self.assertTrue(obj.signal.connect(obj.empty, Qt.UniqueConnection))
self.assertFalse(obj.signal.connect(obj.empty, Qt.UniqueConnection))
+ def testDisconnect(self):
+ obj = Obj()
+ receiver = Receiver()
+ conn_id = obj.signal.connect(receiver.testSlot)
+ self.assertTrue(conn_id)
+
+ obj.emitSignal()
+ self.assertEqual(receiver.count(), 1)
+
+ obj.signal.disconnect(conn_id)
+ obj.emitSignal()
+ self.assertEqual(receiver.count(), 1)
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qobject_timer_event_test.py b/sources/pyside6/tests/QtCore/qobject_timer_event_test.py
index 0ddf77c10..ce0c12b2d 100644
--- a/sources/pyside6/tests/QtCore/qobject_timer_event_test.py
+++ b/sources/pyside6/tests/QtCore/qobject_timer_event_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test case for QObject.timerEvent overloading'''
@@ -41,12 +16,13 @@ init_test_paths(False)
from PySide6.QtCore import QObject, QCoreApplication
-from helper.usesqcoreapplication import UsesQCoreApplication
+from helper.usesqapplication import UsesQApplication
+
class Dummy(QObject):
def __init__(self, app):
- super(Dummy, self).__init__()
+ super().__init__()
self.times_called = 0
self.app = app
@@ -58,23 +34,25 @@ class Dummy(QObject):
if self.times_called == 5:
self.app.exit(0)
-class QObjectTimerEvent(UsesQCoreApplication):
+
+class QObjectTimerEvent(UsesQApplication):
def setUp(self):
- #Acquire resources
+ # Acquire resources
super(QObjectTimerEvent, self).setUp()
def tearDown(self):
- #Release resources
+ # Release resources
super(QObjectTimerEvent, self).tearDown()
def testTimerEvent(self):
- #QObject.timerEvent overloading
+ # QObject.timerEvent overloading
obj = Dummy(self.app)
timer_id = obj.startTimer(200)
- self.app.exec_()
+ self.app.exec()
obj.killTimer(timer_id)
self.assertEqual(obj.times_called, 5)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qobject_tr_as_instance_test.py b/sources/pyside6/tests/QtCore/qobject_tr_as_instance_test.py
index 4647a2c4b..f3df03a0c 100644
--- a/sources/pyside6/tests/QtCore/qobject_tr_as_instance_test.py
+++ b/sources/pyside6/tests/QtCore/qobject_tr_as_instance_test.py
@@ -1,36 +1,11 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QObject's tr static methods.'''
+import gc
import os
import os
import sys
@@ -43,7 +18,8 @@ init_test_paths(False)
from PySide6.QtCore import QObject
-#from helper.usesqcoreapplication import UsesQCoreApplication
+#from helper.usesqapplication import UsesQApplication
+
class QObjectTrTest(unittest.TestCase):
'''Test case to check if QObject tr static methods could be treated as instance methods.'''
@@ -53,9 +29,11 @@ class QObjectTrTest(unittest.TestCase):
def tearDown(self):
del self.obj
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
def testTrCommonCase(self):
- #Test common case for QObject.tr
+ # Test common case for QObject.tr
invar1 = 'test1'
outvar1 = self.obj.tr(invar1)
invar2 = 'test2'
@@ -63,13 +41,15 @@ class QObjectTrTest(unittest.TestCase):
self.assertEqual((invar1, invar2), (outvar1, outvar2))
def testTrAsInstanceMethod(self):
- #Test QObject.tr as instance
+ # Test QObject.tr as instance.
+ # PYSIDE-1252: This works now as a class method!
invar1 = 'test1'
- outvar1 = QObject.tr(self.obj, invar1)
+ outvar1 = QObject.tr(invar1)
invar2 = 'test2'
- outvar2 = QObject.tr(self.obj, invar2, 'test comment')
+ outvar2 = QObject.tr(invar2, 'test comment')
self.assertEqual((invar1, invar2), (outvar1, outvar2))
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qoperatingsystemversion_test.py b/sources/pyside6/tests/QtCore/qoperatingsystemversion_test.py
index 0b336ca01..7365e7212 100644
--- a/sources/pyside6/tests/QtCore/qoperatingsystemversion_test.py
+++ b/sources/pyside6/tests/QtCore/qoperatingsystemversion_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,11 +13,13 @@ init_test_paths(False)
from PySide6.QtCore import QOperatingSystemVersion
+
class TestQOperatingSystemVersion(unittest.TestCase):
def test(self):
ov = QOperatingSystemVersion.current()
name = f"{ov.name()} v{ov.majorVersion()}.{ov.minorVersion()}.{ov.microVersion()}"
print(name)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qpoint_test.py b/sources/pyside6/tests/QtCore/qpoint_test.py
index 49a4d8c25..9770b5662 100644
--- a/sources/pyside6/tests/QtCore/qpoint_test.py
+++ b/sources/pyside6/tests/QtCore/qpoint_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QPoint and QPointF'''
@@ -43,12 +19,14 @@ from PySide6.QtCore import QPoint, QPointF
class QPointTest(unittest.TestCase):
def testQPointCtor(self):
- point = QPoint(QPoint(10,20))
+ point = QPoint(QPoint(10, 20))
+
class QPointFTest(unittest.TestCase):
def testQPointFCtor(self):
- pointf = QPointF(QPoint(10,20))
+ pointf = QPointF(QPoint(10, 20))
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qprocess_test.py b/sources/pyside6/tests/QtCore/qprocess_test.py
index 691e2befc..6466b8575 100644
--- a/sources/pyside6/tests/QtCore/qprocess_test.py
+++ b/sources/pyside6/tests/QtCore/qprocess_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QProcess'''
@@ -39,7 +14,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import *
+from PySide6.QtCore import QProcess
+
class TestQProcess (unittest.TestCase):
def testStartDetached(self):
@@ -60,5 +36,6 @@ class TestQProcess (unittest.TestCase):
else:
print("PROCESS ALREADY DEAD :-/")
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qproperty_decorator.py b/sources/pyside6/tests/QtCore/qproperty_decorator.py
index 021bbed56..7d6fbc91d 100644
--- a/sources/pyside6/tests/QtCore/qproperty_decorator.py
+++ b/sources/pyside6/tests/QtCore/qproperty_decorator.py
@@ -1,31 +1,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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+import gc
import os
import sys
import unittest
@@ -38,9 +15,10 @@ init_test_paths(False)
from PySide6.QtCore import QObject, Property
+
class MyObject(QObject):
def __init__(self):
- QObject.__init__(self)
+ super().__init__()
self._value = None
@Property(int)
@@ -66,7 +44,12 @@ class PropertyTest(unittest.TestCase):
self.assertEqual(o._value, 10)
self.assertEqual(o.value, 10)
del o
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+ # PYSIDE-535: Why do I need to do it twice, here?
+ gc.collect()
self.assertTrue(self._obDestroyed)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qrandomgenerator_test.py b/sources/pyside6/tests/QtCore/qrandomgenerator_test.py
index fc1c7b872..6ae69b6b3 100644
--- a/sources/pyside6/tests/QtCore/qrandomgenerator_test.py
+++ b/sources/pyside6/tests/QtCore/qrandomgenerator_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,6 +13,7 @@ init_test_paths(False)
from PySide6.QtCore import QRandomGenerator, QRandomGenerator64
+
class QRandomGeneratorTest(unittest.TestCase):
'''Test case for QRandomGenerator'''
@@ -52,5 +29,6 @@ class QRandomGeneratorTest(unittest.TestCase):
generator = QRandomGenerator64()
r = generator.generate()
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qrect_test.py b/sources/pyside6/tests/QtCore/qrect_test.py
index 8420f0246..fb91654f2 100644
--- a/sources/pyside6/tests/QtCore/qrect_test.py
+++ b/sources/pyside6/tests/QtCore/qrect_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QRect'''
@@ -41,10 +16,11 @@ init_test_paths(False)
from PySide6.QtCore import QPoint, QRect, QRectF
+
class RectConstructor(unittest.TestCase):
def testDefault(self):
- #QRect()
+ # QRect()
obj = QRect()
self.assertTrue(obj.isNull())
@@ -58,6 +34,7 @@ class RectConstructor(unittest.TestCase):
self.assertEqual(rect1, rect2)
+
class RectOperator(unittest.TestCase):
'''Test case for QRect operators'''
@@ -74,7 +51,7 @@ class RectOperator(unittest.TestCase):
self.assertEqual(rect1, rect2)
def testNullRectIntersection(self):
- #QRect & QRect for null rects
+ # QRect & QRect for null rects
rect1 = QRect()
rect2 = QRect()
rect3 = rect1 & rect2
@@ -90,21 +67,21 @@ class RectOperator(unittest.TestCase):
self.assertEqual(rect3, QRect())
def testIntersectPartial(self):
- #QRect & QRect for partial intersections
+ # QRect & QRect for partial intersections
rect1 = QRect(10, 10, 10, 10)
rect2 = QRect(15, 15, 10, 10)
rect3 = rect1 & rect2
self.assertEqual(rect3, QRect(15, 15, 5, 5))
def testIntersetEnclosed(self):
- #QRect & QRect for a qrect inside another
+ # QRect & QRect for a qrect inside another
rect1 = QRect(10, 10, 20, 20)
rect2 = QRect(15, 15, 5, 5)
rect3 = rect1 & rect2
self.assertEqual(rect3, rect2)
def testNullRectIntersectBounding(self):
- #QRect | QRect for null rects
+ # QRect | QRect for null rects
rect1 = QRect()
rect2 = QRect()
rect3 = rect1 & rect2
@@ -120,14 +97,14 @@ class RectOperator(unittest.TestCase):
self.assertEqual(rect3, QRect(10, 10, 15, 15))
def testBoundingPartialIntersection(self):
- #QRect | QRect for partial intersections
+ # QRect | QRect for partial intersections
rect1 = QRect(10, 10, 10, 10)
rect2 = QRect(15, 15, 10, 10)
rect3 = rect1 | rect2
self.assertEqual(rect3, QRect(10, 10, 15, 15))
def testBoundingEnclosed(self):
- #QRect | QRect for a qrect inside another
+ # QRect | QRect for a qrect inside another
rect1 = QRect(10, 10, 20, 20)
rect2 = QRect(15, 15, 5, 5)
rect3 = rect1 | rect2
@@ -143,6 +120,5 @@ class RectOperator(unittest.TestCase):
self.assertEqual(rect1.getCoords(), (1, 2, 4, 6))
-
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qregularexpression_test.py b/sources/pyside6/tests/QtCore/qregularexpression_test.py
index 457ff7460..ae7281d75 100644
--- a/sources/pyside6/tests/QtCore/qregularexpression_test.py
+++ b/sources/pyside6/tests/QtCore/qregularexpression_test.py
@@ -1,32 +1,7 @@
#!/usr/bin/python
-
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QRegularExpression'''
@@ -41,6 +16,7 @@ init_test_paths(False)
from PySide6.QtCore import QRegularExpression, QRegularExpressionMatch, QRegularExpressionMatchIterator
+
class QRegularExpressionTest(unittest.TestCase):
def testMatch(self):
@@ -55,11 +31,12 @@ class QRegularExpressionTest(unittest.TestCase):
re = QRegularExpression('(\w+)')
self.assertTrue(re.isValid())
count = 0
- it = re.globalMatch('word1 word2 word3');
+ it = re.globalMatch('word1 word2 word3')
while it.hasNext():
it.next()
- count = count + 1
+ count = count + 1
self.assertEqual(count, 3)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qresource_test.py b/sources/pyside6/tests/QtCore/qresource_test.py
index 40d90c65c..0f7b920e8 100644
--- a/sources/pyside6/tests/QtCore/qresource_test.py
+++ b/sources/pyside6/tests/QtCore/qresource_test.py
@@ -1,32 +1,6 @@
-# -*- 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QResource usage'''
@@ -39,34 +13,39 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from helper.helper import adjust_filename
-from PySide6.QtCore import QFile, QIODevice
+from PySide6.QtCore import QByteArray, QFile, QIODevice
import resources_mc
+
class ResourcesUsage(unittest.TestCase):
'''Test case for resources usage'''
def testPhrase(self):
- #Test loading of quote.txt resource
- f = open(adjust_filename('quoteEnUS.txt', __file__), "r")
- orig = f.read()
- f.close()
-
- f = QFile(':/quote.txt')
- f.open(QIODevice.ReadOnly) #|QIODevice.Text)
- print("Error:", f.errorString())
+ # Test loading of quote.txt resource
+ file = Path(__file__).resolve().parent / 'quoteEnUS.txt'
+ self.assertTrue(file.is_file())
+ orig = QByteArray(file.read_bytes())
+ # In case the file is checked out in 'crlf' mode, strip '\r'
+ # since we read binary.
+ if sys.platform == 'win32':
+ carriage_return = orig.indexOf('\r')
+ if carriage_return != -1:
+ orig.remove(carriage_return, 1)
+
+ f = QFile(':/quote.txt') # |QIODevice.Text
+ self.assertTrue(f.open(QIODevice.ReadOnly), f.errorString())
copy = f.readAll()
f.close()
self.assertEqual(orig, copy)
def testImage(self):
- #Test loading of sample.png resource
- f = open(adjust_filename('sample.png', __file__), "rb")
- orig = f.read()
- f.close()
+ # Test loading of sample.png resource
+ file = Path(__file__).resolve().parent / 'sample.png'
+ self.assertTrue(file.is_file())
+ orig = file.read_bytes()
f = QFile(':/sample.png')
- f.open(QIODevice.ReadOnly)
+ self.assertTrue(f.open(QIODevice.ReadOnly), f.errorString())
copy = f.readAll()
f.close()
self.assertEqual(len(orig), len(copy))
diff --git a/sources/pyside6/tests/QtCore/qrunnable_test.py b/sources/pyside6/tests/QtCore/qrunnable_test.py
new file mode 100644
index 000000000..1b743a8e9
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/qrunnable_test.py
@@ -0,0 +1,46 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+'''Test cases for QRunnable'''
+
+import os
+import sys
+import unittest
+from io import StringIO
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import QCoreApplication, QRunnable, QThreadPool, QThread, qDebug
+from helper.usesqapplication import UsesQApplication
+test_result = ""
+
+
+def check_test():
+ global test_result
+ test_result = "test works"
+
+
+class QRunnableTest(UsesQApplication):
+ def testCreateWithAutoDelete(self):
+ global test_result
+ test_result = "" # reset
+ runnable = QRunnable.create(check_test)
+ runnable.run()
+ self.assertEqual(test_result, "test works")
+
+ def testwithQThreadPool(self):
+ global test_result
+ test_result = "" # reset
+ runnable = QRunnable.create(check_test)
+ tp = QThreadPool.globalInstance()
+ tp.start(runnable)
+ self.assertTrue(tp.waitForDone())
+ self.assertEqual(test_result, "test works")
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qsettings_test.py b/sources/pyside6/tests/QtCore/qsettings_test.py
index 00eec2679..5f86c9fbb 100644
--- a/sources/pyside6/tests/QtCore/qsettings_test.py
+++ b/sources/pyside6/tests/QtCore/qsettings_test.py
@@ -1,33 +1,10 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QDate'''
+import gc
import os
import sys
import unittest
@@ -37,12 +14,14 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from helper.helper import adjust_filename
-from PySide6.QtCore import QSettings
+from PySide6.QtCore import QDir, QSettings, QTemporaryDir, QByteArray
+
class TestQSettings(unittest.TestCase):
def testConversions(self):
- file_path = adjust_filename('qsettings_test.ini', __file__)
+ file = Path(__file__).resolve().parent / 'qsettings_test.ini'
+ self.assertTrue(file.is_file())
+ file_path = QDir.fromNativeSeparators(os.fspath(file))
settings = QSettings(file_path, QSettings.IniFormat)
r = settings.value('var1')
@@ -54,22 +33,48 @@ class TestQSettings(unittest.TestCase):
r = settings.value('var2', type=list)
self.assertEqual(type(r), list)
+ # Test mixed conversions
+ ba = QByteArray("hello".encode("utf-8"))
+
+ r = settings.value("test", ba, type=QByteArray)
+ self.assertEqual(type(r), QByteArray)
+
+ r = settings.value("test", ba, type=str)
+ self.assertEqual(type(r), str)
+
+ # Test invalid conversions
+ with self.assertRaises(TypeError):
+ r = settings.value("test", ba, type=dict)
def testDefaultValueConversion(self):
- settings = QSettings('foo.ini', QSettings.IniFormat)
+ temp_dir = QDir.tempPath()
+ dir = QTemporaryDir(f'{temp_dir}/qsettings_XXXXXX')
+ self.assertTrue(dir.isValid())
+ file_name = dir.filePath('foo.ini')
+ settings = QSettings(file_name, QSettings.IniFormat)
+ sample_list = ["a", "b"]
+ string_list_of_empty = [""]
settings.setValue('zero_value', 0)
settings.setValue('empty_list', [])
+ settings.setValue('some_strings', sample_list)
+ settings.setValue('string_list_of_empty', string_list_of_empty)
settings.setValue('bool1', False)
settings.setValue('bool2', True)
del settings
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
# Loading values already set
- settings = QSettings('foo.ini', QSettings.IniFormat)
+ settings = QSettings(file_name, QSettings.IniFormat)
# Getting value that doesn't exist
r = settings.value("variable")
self.assertEqual(type(r), type(None))
+ r = settings.value("variable", type=list)
+ self.assertEqual(type(r), list)
+ self.assertEqual(len(r), 0)
+
# Handling zero value
r = settings.value('zero_value')
self.assertEqual(type(r), int)
@@ -86,6 +91,15 @@ class TestQSettings(unittest.TestCase):
self.assertTrue(len(r) == 0)
self.assertEqual(type(r), list)
+ r = settings.value('some_strings')
+ self.assertEqual(r, sample_list)
+
+ r = settings.value('some_strings', type=list)
+ self.assertEqual(r, sample_list)
+
+ r = settings.value('string_list_of_empty', type=list)
+ self.assertEqual(r, string_list_of_empty)
+
# Booleans
r = settings.value('bool1')
self.assertEqual(type(r), bool)
@@ -112,5 +126,6 @@ class TestQSettings(unittest.TestCase):
r = settings.value('lala', 22, type=float)
self.assertEqual(type(r), float)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qsharedmemory_client.py b/sources/pyside6/tests/QtCore/qsharedmemory_client.py
new file mode 100644
index 000000000..05640d7fe
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/qsharedmemory_client.py
@@ -0,0 +1,37 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+'''Client for the unit test of QSharedMemory'''
+
+import sys
+
+from PySide6.QtCore import QSharedMemory
+
+
+def read_string(shared_memory):
+ """Read out a null-terminated string from the QSharedMemory"""
+ mv = memoryview(shared_memory.constData())
+ result = ''
+ for i in range(shared_memory.size()):
+ char = mv[i]
+ if not char:
+ break
+ result += chr(char)
+ return result
+
+
+if __name__ == '__main__':
+ if len(sys.argv) != 2:
+ print('Pass segment name', file=sys.stderr)
+ sys.exit(-1)
+ shared_memory = QSharedMemory(sys.argv[1])
+ if not shared_memory.attach(QSharedMemory.ReadOnly):
+ raise SystemError(f'attach to "{name}" failed')
+ if not shared_memory.lock():
+ raise SystemError(f'lock of "{name}" failed')
+ data = read_string(shared_memory)
+ shared_memory.unlock()
+ shared_memory.detach()
+ sys.stdout.write(data)
+ sys.exit(0)
diff --git a/sources/pyside6/tests/QtCore/qsharedmemory_test.py b/sources/pyside6/tests/QtCore/qsharedmemory_test.py
new file mode 100644
index 000000000..9ec976ac6
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/qsharedmemory_test.py
@@ -0,0 +1,74 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+'''Unit tests for QSharedMemory'''
+
+import ctypes
+import os
+import subprocess
+import sys
+import unittest
+
+from pathlib import Path
+FILE = Path(__file__).resolve()
+sys.path.append(os.fspath(FILE.parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import QSharedMemory, QRandomGenerator, qVersion
+from qsharedmemory_client import read_string
+
+
+TEST_STRING = 'ABCD'
+
+
+def run(cmd):
+ # FIXME Python 3.7: Use subprocess.run()
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=False,
+ universal_newlines=True)
+ output, error = proc.communicate()
+ proc.wait()
+ return_code = proc.returncode
+ return (return_code, output, error)
+
+
+class QSharedMemoryTest(unittest.TestCase):
+
+ def setUp(self):
+ r = QRandomGenerator.global_().bounded(1000)
+ v = qVersion()
+ self._name = f"pyside{v}_test_{r}"
+ print(self._name)
+ self._shared_memory = QSharedMemory(self._name)
+
+ def tearDown(self):
+ if self._shared_memory.isAttached():
+ self._shared_memory.detach()
+
+ def test(self):
+ # Create and write
+ self.assertTrue(self._shared_memory.create(1024, QSharedMemory.ReadWrite))
+ self.assertTrue(self._shared_memory.lock())
+ mv = memoryview(self._shared_memory.data())
+ for idx, c in enumerate(TEST_STRING + chr(0)):
+ mv[idx] = ord(c)
+ mv = None
+ self.assertTrue(self._shared_memory.unlock())
+
+ # Read
+ self.assertTrue(self._shared_memory.lock())
+ self.assertEqual(read_string(self._shared_memory), TEST_STRING)
+ self.assertTrue(self._shared_memory.unlock())
+
+ # Run a subprocess and let it read
+ client = FILE.parent / 'qsharedmemory_client.py'
+ returncode, output, error = run([sys.executable, client, self._name])
+ if error:
+ print(error, file=sys.stderr)
+ self.assertEqual(returncode, 0)
+ self.assertEqual(output, TEST_STRING)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qsize_test.py b/sources/pyside6/tests/QtCore/qsize_test.py
index 2429352c9..3de779bd6 100644
--- a/sources/pyside6/tests/QtCore/qsize_test.py
+++ b/sources/pyside6/tests/QtCore/qsize_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QSize'''
@@ -41,16 +16,17 @@ init_test_paths(False)
from PySide6.QtCore import QSize
+
class QSizeOperator(unittest.TestCase):
def testOperatorMultiply(self):
- #QSize operator * float
+ # QSize operator * float
# bug 131
a = QSize(1, 1)
x = a * 3.4
self.assertEqual(QSize(3, 3), x)
def testOperatorRevertedMultiply(self):
- #QSize operator * float, reverted
+ # QSize operator * float, reverted
# bug 132
a = QSize(1, 1)
x = 3.4 * a
diff --git a/sources/pyside6/tests/QtCore/qslot_object_test.py b/sources/pyside6/tests/QtCore/qslot_object_test.py
index 56cd462ee..5412680df 100644
--- a/sources/pyside6/tests/QtCore/qslot_object_test.py
+++ b/sources/pyside6/tests/QtCore/qslot_object_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -36,44 +11,45 @@ from pathlib import Path
sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6 import QtCore
+
+from PySide6.QtCore import QCoreApplication, QObject, QTimer
"""
This is a simple slot test that was updated to use the qApp "macro".
It is implicitly in builtins and does not need an import.
"""
-class objTest(QtCore.QObject):
+
+class objTest(QObject):
def __init__(self, parent=None):
- QtCore.QObject.__init__(self, parent)
+ super().__init__(parent)
self.ok = False
def slot(self):
self.ok = True
- qApp.quit()
+ qApp.quit() # noqa: F821
class slotTest(unittest.TestCase):
def quit_app(self):
- qApp.quit()
+ qApp.quit() # noqa: F821
def testBasic(self):
- timer = QtCore.QTimer()
+ timer = QTimer()
timer.setInterval(100)
my_obj = objTest()
- my_slot = QtCore.SLOT("slot()")
- QtCore.QObject.connect(timer, QtCore.SIGNAL("timeout()"), my_obj, my_slot)
+ timer.timeout.connect(my_obj.slot)
timer.start(100)
- QtCore.QTimer.singleShot(1000, self.quit_app)
- qApp.exec_()
+ QTimer.singleShot(1000, self.quit_app)
+ qApp.exec() # noqa: F821
self.assertTrue(my_obj.ok)
if __name__ == '__main__':
- QtCore.QCoreApplication()
+ QCoreApplication()
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qsocketnotifier_test.py b/sources/pyside6/tests/QtCore/qsocketnotifier_test.py
index b348d5aa7..beb90314a 100644
--- a/sources/pyside6/tests/QtCore/qsocketnotifier_test.py
+++ b/sources/pyside6/tests/QtCore/qsocketnotifier_test.py
@@ -1,32 +1,7 @@
#!/usr/bin/python
-
-#############################################################################
-##
-## Copyright (C) 2018 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of the test suite of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:GPL-EXCEPT$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 3 as published by the Free Software
-## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QUuid'''
@@ -40,13 +15,12 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtWidgets import QApplication
-from PySide6.QtCore import QSocketNotifier
+from PySide6.QtCore import QCoreApplication, QSocketNotifier
class QSocketNotifierTest(unittest.TestCase):
def testClass(self):
- app = QApplication([])
+ app = QCoreApplication([])
# socketpair is not available on Windows
if os.name != "nt":
w_sock, r_sock = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
diff --git a/sources/pyside6/tests/QtCore/qsrand_test.py b/sources/pyside6/tests/QtCore/qsrand_test.py
index 4db29e24f..d0e071dcf 100644
--- a/sources/pyside6/tests/QtCore/qsrand_test.py
+++ b/sources/pyside6/tests/QtCore/qsrand_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import gc
import os
@@ -38,14 +14,21 @@ init_test_paths(False)
from PySide6.QtCore import QRandomGenerator
+
class OverflowExceptionCollect(unittest.TestCase):
'''Test case for OverflowError exception during garbage collection. See bug #147'''
+ def assertRaises(self, *args, **kwds):
+ if not hasattr(sys, "pypy_version_info"):
+ # PYSIDE-535: PyPy complains "Fatal RPython error: NotImplementedError"
+ return super().assertRaises(*args, **kwds)
+
def testOverflow(self):
# NOTE: PyQt4 raises TypeError, but boost.python raises OverflowError
self.assertRaises(OverflowError, QRandomGenerator, 42415335332353253)
# should not abort if bug #147 is fixed
gc.collect()
+
if __name__ == '__main__':
- unittest.main()
+ unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qstandardpaths_test.py b/sources/pyside6/tests/QtCore/qstandardpaths_test.py
index 0e5e7358d..0846e2a68 100644
--- a/sources/pyside6/tests/QtCore/qstandardpaths_test.py
+++ b/sources/pyside6/tests/QtCore/qstandardpaths_test.py
@@ -1,32 +1,7 @@
#!/usr/bin/python
-
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QStandardPaths'''
@@ -42,6 +17,7 @@ init_test_paths(False)
from PySide6.QtCore import QStandardPaths
+
class QStandardPathsTest(unittest.TestCase):
def testTestModeEnabled(self):
print("QStandardPaths.isTestModeEnabled:", QStandardPaths.isTestModeEnabled())
@@ -52,5 +28,6 @@ class QStandardPathsTest(unittest.TestCase):
QStandardPaths.setTestModeEnabled(sp)
self.assertEqual(QStandardPaths.isTestModeEnabled(), sp)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qstorageinfo_test.py b/sources/pyside6/tests/QtCore/qstorageinfo_test.py
index b86b85c1c..44b3ce303 100644
--- a/sources/pyside6/tests/QtCore/qstorageinfo_test.py
+++ b/sources/pyside6/tests/QtCore/qstorageinfo_test.py
@@ -1,32 +1,7 @@
#!/usr/bin/python
-
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QStorageInfo'''
@@ -41,10 +16,12 @@ init_test_paths(False)
from PySide6.QtCore import QStorageInfo
+
class QandardPathsTest(unittest.TestCase):
def testQStorageInfo(self):
for v in QStorageInfo.mountedVolumes():
print(v.name(), v.rootPath(), v.device())
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qstring_test.py b/sources/pyside6/tests/QtCore/qstring_test.py
index a07a559a3..397dceb1e 100644
--- a/sources/pyside6/tests/QtCore/qstring_test.py
+++ b/sources/pyside6/tests/QtCore/qstring_test.py
@@ -1,33 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QString'''
@@ -42,6 +16,7 @@ init_test_paths(False)
from PySide6.QtCore import QObject
+
class QStringConstructor(unittest.TestCase):
'''Test case for QString constructors'''
@@ -51,8 +26,13 @@ class QStringConstructor(unittest.TestCase):
self.assertEqual(obj.objectName(), 'foo')
obj.setObjectName('áâãà')
self.assertEqual(obj.objectName(), 'áâãà')
+ obj.setObjectName('A\x00B')
+ self.assertEqual(obj.objectName(), 'A\x00B')
+ obj.setObjectName('ä\x00B')
+ self.assertEqual(obj.objectName(), 'ä\x00B')
obj.setObjectName(None)
self.assertEqual(obj.objectName(), '')
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qsysinfo_test.py b/sources/pyside6/tests/QtCore/qsysinfo_test.py
index 90e241775..71a39bb5d 100644
--- a/sources/pyside6/tests/QtCore/qsysinfo_test.py
+++ b/sources/pyside6/tests/QtCore/qsysinfo_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,14 +13,17 @@ init_test_paths(False)
from PySide6.QtCore import QSysInfo
+
class TestQSysInfo(unittest.TestCase):
+
def testEnumEndian(self):
- self.assertEqual(QSysInfo.BigEndian, 0)
- self.assertEqual(QSysInfo.LittleEndian, 1)
- self.assertTrue(QSysInfo.ByteOrder > -1)
+ self.assertEqual(QSysInfo.BigEndian.value, 0)
+ self.assertEqual(QSysInfo.LittleEndian.value, 1)
+ self.assertTrue(QSysInfo.ByteOrder.value > -1)
def testEnumSizes(self):
- self.assertTrue(QSysInfo.WordSize > 0)
+ self.assertTrue(QSysInfo.WordSize.value > 0)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qtextstream_test.py b/sources/pyside6/tests/QtCore/qtextstream_test.py
index b48f716bc..99aae2187 100644
--- a/sources/pyside6/tests/QtCore/qtextstream_test.py
+++ b/sources/pyside6/tests/QtCore/qtextstream_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QTextStream'''
@@ -39,6 +15,7 @@ init_test_paths(False)
from PySide6.QtCore import QByteArray, QTextStream, QIODevice, QFile
+
class QTextStreamShiftTest(unittest.TestCase):
def setUp(self):
@@ -55,6 +32,7 @@ class QTextStreamShiftTest(unittest.TestCase):
self.assertTrue(isinstance(res, str))
self.assertEqual(res, '4')
+
class QTextStreamGetSet(unittest.TestCase):
def setUp(self):
@@ -68,6 +46,7 @@ class QTextStreamGetSet(unittest.TestCase):
self.obj.setDevice(None)
self.assertEqual(None, self.obj.device())
+
class QTextStreamInitialization(unittest.TestCase):
def testConstruction(self):
@@ -80,6 +59,7 @@ class QTextStreamInitialization(unittest.TestCase):
self.assertTrue(obj.atEnd())
self.assertEqual(obj.readAll(), '')
+
class QTextStreamReadLinesFromDevice(unittest.TestCase):
def _check_data(self, data_set):
@@ -108,5 +88,6 @@ class QTextStreamReadLinesFromDevice(unittest.TestCase):
self._check_data(data)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qthread_prod_cons_test.py b/sources/pyside6/tests/QtCore/qthread_prod_cons_test.py
index 05ea4da04..6fbc8432e 100644
--- a/sources/pyside6/tests/QtCore/qthread_prod_cons_test.py
+++ b/sources/pyside6/tests/QtCore/qthread_prod_cons_test.py
@@ -1,35 +1,11 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Producer-Consumer test/example with QThread'''
+import gc
import logging
import os
from random import random
@@ -45,96 +21,94 @@ logging.basicConfig(level=logging.WARNING)
from PySide6.QtCore import QThread, QCoreApplication, QObject, SIGNAL
+
class Bucket(QObject):
'''Dummy class to hold the produced values'''
def __init__(self, max_size=10, *args):
- #Constructor which receives the max number of produced items
- super(Bucket, self).__init__(*args)
+ # Constructor which receives the max number of produced items
+ super().__init__(*args)
self.data = []
self.max_size = 10
def pop(self):
- #Retrieves an item
+ # Retrieves an item
return self.data.pop(0)
def push(self, data):
- #Pushes an item
+ # Pushes an item
self.data.append(data)
+
class Producer(QThread):
'''Producer thread'''
def __init__(self, bucket, *args):
- #Constructor. Receives the bucket
- super(Producer, self).__init__(*args)
+ # Constructor. Receives the bucket
+ super().__init__(*args)
self.runs = 0
self.bucket = bucket
self.production_list = []
def run(self):
- #Produces at most bucket.max_size items
+ # Produces at most bucket.max_size items
while self.runs < self.bucket.max_size:
- value = int(random()*10) % 10
+ value = int(random() * 10) % 10
self.bucket.push(value)
self.production_list.append(value)
- logging.debug('PRODUCER - pushed %d' % value)
+ logging.debug(f'PRODUCER - pushed {value}')
self.runs += 1
self.msleep(5)
-
class Consumer(QThread):
'''Consumer thread'''
def __init__(self, bucket, *args):
- #Constructor. Receives the bucket
- super(Consumer, self).__init__(*args)
+ # Constructor. Receives the bucket
+ super().__init__(*args)
self.runs = 0
self.bucket = bucket
self.consumption_list = []
def run(self):
- #Consumes at most bucket.max_size items
+ # Consumes at most bucket.max_size items
while self.runs < self.bucket.max_size:
try:
value = self.bucket.pop()
self.consumption_list.append(value)
- logging.debug('CONSUMER - got %d' % value)
+ logging.debug(f'CONSUMER - got {value}')
self.runs += 1
except IndexError:
logging.debug('CONSUMER - empty bucket')
self.msleep(5)
+
class ProducerConsumer(unittest.TestCase):
'''Basic test case for producer-consumer QThread'''
def setUp(self):
- #Create fixtures
+ # Create fixtures
self.app = QCoreApplication([])
def tearDown(self):
- #Destroy fixtures
+ # Destroy fixtures
del self.app
-
- def finishCb(self):
- #Quits the application
- self.app.exit(0)
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
def testProdCon(self):
- #QThread producer-consumer example
+ # QThread producer-consumer example
bucket = Bucket()
prod = Producer(bucket)
cons = Consumer(bucket)
+ cons.finished.connect(QCoreApplication.quit)
prod.start()
cons.start()
- QObject.connect(prod, SIGNAL('finished()'), self.finishCb)
- QObject.connect(cons, SIGNAL('finished()'), self.finishCb)
-
- self.app.exec_()
+ self.app.exec()
- prod.wait(50)
- cons.wait(50)
+ self.assertTrue(prod.wait(1000))
+ self.assertTrue(cons.wait(1000))
self.assertEqual(prod.production_list, cons.consumption_list)
diff --git a/sources/pyside6/tests/QtCore/qthread_signal_test.py b/sources/pyside6/tests/QtCore/qthread_signal_test.py
index c50ec0101..93c83ea6e 100644
--- a/sources/pyside6/tests/QtCore/qthread_signal_test.py
+++ b/sources/pyside6/tests/QtCore/qthread_signal_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for connecting signals between threads'''
@@ -37,39 +13,40 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import QThread, QObject, SIGNAL, QCoreApplication
+from PySide6.QtCore import QThread, QTimer, QObject, Signal, Slot, QCoreApplication
-thread_run = False
class Source(QObject):
+ source = Signal()
+
def __init__(self, *args):
- QObject.__init__(self, *args)
+ super().__init__(*args)
+ @Slot()
def emit_sig(self):
- self.emit(SIGNAL('source()'))
+ self.source.emit()
+
class Target(QObject):
def __init__(self, *args):
- QObject.__init__(self, *args)
+ super().__init__(*args)
self.called = False
+ @Slot()
def myslot(self):
self.called = True
+
class ThreadJustConnects(QThread):
def __init__(self, source, *args):
- QThread.__init__(self, *args)
+ super().__init__(*args)
self.source = source
self.target = Target()
def run(self):
- global thread_run
- thread_run = True
- QObject.connect(self.source, SIGNAL('source()'), self.target.myslot)
-
- while not self.target.called:
- pass
-
+ self.source.source.connect(self.target.myslot)
+ self.source.source.connect(self.quit)
+ self.exec()
class BasicConnection(unittest.TestCase):
@@ -81,18 +58,15 @@ class BasicConnection(unittest.TestCase):
source = Source()
thread = ThreadJustConnects(source)
- QObject.connect(thread, SIGNAL('finished()'), lambda: app.exit(0))
+ thread.finished.connect(QCoreApplication.quit)
thread.start()
- while not thread_run:
- pass
-
- source.emit_sig()
-
- app.exec_()
+ QTimer.singleShot(50, source.emit_sig)
+ app.exec()
thread.wait()
self.assertTrue(thread.target.called)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qthread_test.py b/sources/pyside6/tests/QtCore/qthread_test.py
index e3f7c7f19..856283a23 100644
--- a/sources/pyside6/tests/QtCore/qthread_test.py
+++ b/sources/pyside6/tests/QtCore/qthread_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QThread'''
@@ -39,78 +14,72 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import QThread, QCoreApplication, QObject, SIGNAL, QMutex, QTimer
+from PySide6.QtCore import QThread, QCoreApplication, QObject, QTimer, Slot
from PySide6.QtCore import QEventLoop
-from helper.usesqcoreapplication import UsesQCoreApplication
+from helper.usesqapplication import UsesQApplication
-mutex = QMutex()
class Dummy(QThread):
'''Dummy thread'''
def __init__(self, *args):
- super(Dummy, self).__init__(*args)
+ super().__init__(*args)
self.called = False
def run(self):
- #Start-quit sequence
+ # Start-quit sequence
self.qobj = QObject()
- mutex.lock()
self.called = True
- mutex.unlock()
-class QThreadSimpleCase(UsesQCoreApplication):
+
+class QThreadSimpleCase(UsesQApplication):
def setUp(self):
- UsesQCoreApplication.setUp(self)
+ UsesQApplication.setUp(self)
+ self._started_called = False
+ self._finished_called = False
self.called = False
- def tearDown(self):
- UsesQCoreApplication.tearDown(self)
-
def testThread(self):
- #Basic QThread test
+ # Basic QThread test
obj = Dummy()
obj.start()
self.assertTrue(obj.wait(100))
self.assertTrue(obj.called)
- def cb(self, *args):
- self.called = True
- #self.exit_app_cb()
-
+ @Slot()
def abort_application(self):
if self._thread.isRunning():
+ print("Warning: terminating thread", file=sys.stderr)
self._thread.terminate()
self.app.quit()
- def testSignalFinished(self):
- #QThread.finished() (signal)
- obj = Dummy()
- QObject.connect(obj, SIGNAL('finished()'), self.cb)
- mutex.lock()
- obj.start()
- mutex.unlock()
-
- self._thread = obj
- QTimer.singleShot(1000, self.abort_application)
- self.app.exec_()
+ @Slot()
+ def finished(self):
+ self._finished_called = True
- self.assertTrue(self.called)
+ @Slot()
+ def started(self):
+ self._started_called = True
- def testSignalStarted(self):
- #QThread.started() (signal)
- obj = Dummy()
- QObject.connect(obj, SIGNAL('started()'), self.cb)
- obj.start()
+ def testSignals(self):
+ # QThread.finished() (signal)
+ self._thread = Dummy()
+ self._thread.started.connect(self.started)
+ self._thread.finished.connect(self.finished)
+ self._thread.finished.connect(self.app.quit)
- self._thread = obj
+ QTimer.singleShot(50, self._thread.start)
QTimer.singleShot(1000, self.abort_application)
- self.app.exec_()
- self.assertEqual(obj.qobj.thread(), obj) # test QObject.thread() method
- self.assertTrue(self.called)
+ self.app.exec()
+ if self._thread.isRunning():
+ self._thread.wait(100)
+
+ self.assertTrue(self._started_called)
+ self.assertTrue(self._finished_called)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qtimer_singleshot_test.py b/sources/pyside6/tests/QtCore/qtimer_singleshot_test.py
index 7119ccd40..9b187104c 100644
--- a/sources/pyside6/tests/QtCore/qtimer_singleshot_test.py
+++ b/sources/pyside6/tests/QtCore/qtimer_singleshot_test.py
@@ -1,35 +1,11 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for QTimer.singleShot'''
+import gc
import os
import sys
import unittest
@@ -39,14 +15,15 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import QObject, QTimer, QCoreApplication, Signal
-from helper.usesqcoreapplication import UsesQCoreApplication
+from PySide6.QtCore import QObject, QThread, QTimer, Signal, Slot, SLOT
+from helper.usesqapplication import UsesQApplication
+
class WatchDog(QObject):
'''Exits the QCoreApplication main loop after sometime.'''
def __init__(self, watched):
- QObject.__init__(self)
+ super().__init__()
self.times_called = 0
self.watched = watched
@@ -55,47 +32,146 @@ class WatchDog(QObject):
if self.times_called == 20:
self.watched.exit_app_cb()
-class TestSingleShot(UsesQCoreApplication):
+
+class ThreadForContext(QThread):
+ def __init__(self):
+ super().__init__()
+ self.called = False
+ self.qthread = None
+ self.context = QObject()
+
+ def run(self):
+ self.called = True
+ self.qthread = QThread.currentThread()
+ self.exec()
+
+
+class TestSingleShot(UsesQApplication):
'''Test case for QTimer.singleShot'''
def setUp(self):
- #Acquire resources
- UsesQCoreApplication.setUp(self)
+ # Acquire resources
+ UsesQApplication.setUp(self)
self.watchdog = WatchDog(self)
self.called = False
+ self.qthread = None
def tearDown(self):
- #Release resources
+ # Release resources
del self.watchdog
del self.called
- UsesQCoreApplication.tearDown(self)
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+ UsesQApplication.tearDown(self)
def callback(self):
self.called = True
+ self.qthread = QThread.currentThread()
+ self.qthread.exit()
self.app.quit()
def testSingleShot(self):
QTimer.singleShot(100, self.callback)
- self.app.exec_()
+ self.app.exec()
+ self.assertTrue(self.called)
+
+ def testSingleShotZero(self):
+ QTimer.singleShot(0, self.callback)
+ self.app.exec()
self.assertTrue(self.called)
+ def testSingleShotWithContext(self):
+ thread = ThreadForContext()
+ thread.start()
+ thread.context.moveToThread(thread)
+ QTimer.singleShot(100, thread.context, self.callback)
+ self.app.exec()
+ thread.wait()
+ self.assertTrue(self.called)
+ self.assertTrue(thread.called)
+ self.assertEqual(self.qthread, thread.qthread)
+
+ def testSingleShotWithContextZero(self):
+ thread = ThreadForContext()
+ thread.start()
+ thread.context.moveToThread(thread)
+ QTimer.singleShot(0, thread.context, self.callback)
+ self.app.exec()
+ thread.wait()
+ self.assertTrue(self.called)
+ self.assertTrue(thread.called)
+ self.assertEqual(self.qthread, thread.qthread)
+
+
+class TestSingleShotCallableObject(UsesQApplication):
+ '''Test case for QTimer.singleShot with callable inside an object'''
+
+ def setUp(self):
+ # Acquire resources
+ UsesQApplication.setUp(self)
+ self.watchdog = WatchDog(self)
+
+ def tearDown(self):
+ # Release resources
+ del self.watchdog
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+ UsesQApplication.tearDown(self)
+
+ class CallbackObject(QObject):
+ def __init__(self, app) -> None:
+ super().__init__()
+ self.app = app
+
+ @Slot()
+ def func(self):
+ self.called = True
+ self.app.quit()
+
+ def testSingleShotWithObjectAndMember(self):
+ callback = self.CallbackObject(self.app)
+ QTimer.singleShot(100, callback, SLOT("func()"))
+ self.app.exec()
+ self.assertTrue(callback.called)
+
+ def testSingleShotWithObjectAndMemberZero(self):
+ callback = self.CallbackObject(self.app)
+ QTimer.singleShot(0, callback, SLOT("func()"))
+ self.app.exec()
+ self.assertTrue(callback.called)
+
+ def testSingleShotWithCallableInObject(self):
+ callback = self.CallbackObject(self.app)
+ QTimer.singleShot(100, callback.func)
+ self.app.exec()
+ self.assertTrue(callback.called)
+
+ def testSingleShotWithCallableInObjectZero(self):
+ callback = self.CallbackObject(self.app)
+ QTimer.singleShot(0, callback.func)
+ self.app.exec()
+ self.assertTrue(callback.called)
+
+
class SigEmitter(QObject):
sig1 = Signal()
-class TestSingleShotSignal(UsesQCoreApplication):
+class TestSingleShotSignal(UsesQApplication):
'''Test case for QTimer.singleShot connecting to signals'''
def setUp(self):
- UsesQCoreApplication.setUp(self)
+ UsesQApplication.setUp(self)
self.watchdog = WatchDog(self)
self.called = False
def tearDown(self):
del self.watchdog
del self.called
- UsesQCoreApplication.tearDown(self)
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+ UsesQApplication.tearDown(self)
def callback(self):
self.called = True
@@ -105,9 +181,16 @@ class TestSingleShotSignal(UsesQCoreApplication):
emitter = SigEmitter()
emitter.sig1.connect(self.callback)
QTimer.singleShot(100, emitter.sig1)
- self.app.exec_()
+ self.app.exec()
self.assertTrue(self.called)
+ def testSingleShotSignalZero(self):
+ emitter = SigEmitter()
+ emitter.sig1.connect(self.callback)
+ QTimer.singleShot(0, emitter.sig1)
+ self.app.exec()
+ self.assertTrue(self.called)
+
+
if __name__ == '__main__':
unittest.main()
-
diff --git a/sources/pyside6/tests/QtCore/qtimer_timeout_test.py b/sources/pyside6/tests/QtCore/qtimer_timeout_test.py
index 255ef9d25..985ba9d76 100644
--- a/sources/pyside6/tests/QtCore/qtimer_timeout_test.py
+++ b/sources/pyside6/tests/QtCore/qtimer_timeout_test.py
@@ -1,33 +1,10 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test case for timeout() signals from QTimer object.'''
+import gc
import os
import sys
import unittest
@@ -38,14 +15,14 @@ from init_paths import init_test_paths
init_test_paths(False)
from PySide6.QtCore import QObject, QTimer, SIGNAL
-from helper.usesqcoreapplication import UsesQCoreApplication
+from helper.usesqapplication import UsesQApplication
class WatchDog(QObject):
'''Exits the QCoreApplication main loop after sometime.'''
def __init__(self, watched):
- QObject.__init__(self)
+ super().__init__()
self.times_called = 0
self.watched = watched
@@ -55,39 +32,43 @@ class WatchDog(QObject):
self.watched.exit_app_cb()
-class TestTimeoutSignal(UsesQCoreApplication):
+class TestTimeoutSignal(UsesQApplication):
'''Test case to check if the signals are really being caught'''
def setUp(self):
- #Acquire resources
- UsesQCoreApplication.setUp(self)
+ # Acquire resources
+ super().setUp()
self.watchdog = WatchDog(self)
self.timer = QTimer()
self.called = False
def tearDown(self):
- #Release resources
+ # Release resources
del self.watchdog
del self.timer
del self.called
- UsesQCoreApplication.tearDown(self)
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+ super().tearDown()
def callback(self, *args):
- #Default callback
+ # Default callback
self.called = True
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testTimeoutSignal(self):
- #Test the QTimer timeout() signal
+ # Test the QTimer timeout() signal
refCount = sys.getrefcount(self.timer)
- QObject.connect(self.timer, SIGNAL('timeout()'), self.callback)
+ self.timer.timeout.connect(self.callback)
self.timer.start(4)
self.watchdog.startTimer(10)
- self.app.exec_()
+ self.app.exec()
self.assertTrue(self.called)
self.assertEqual(sys.getrefcount(self.timer), refCount)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qtimezone_test.py b/sources/pyside6/tests/QtCore/qtimezone_test.py
index d143d0c94..3bfadc662 100644
--- a/sources/pyside6/tests/QtCore/qtimezone_test.py
+++ b/sources/pyside6/tests/QtCore/qtimezone_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,6 +13,7 @@ init_test_paths(False)
from PySide6.QtCore import QTimeZone
+
class TestQTimeZone (unittest.TestCase):
def testTimeZone(self):
id = bytes('Europe/Berlin', "UTF-8")
@@ -46,5 +23,6 @@ class TestQTimeZone (unittest.TestCase):
name = timeZone.displayName(QTimeZone.GenericTime, QTimeZone.DefaultName)
self.assertTrue(name)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qtnamespace_test.py b/sources/pyside6/tests/QtCore/qtnamespace_test.py
index 7244fd89e..3e41a87b5 100644
--- a/sources/pyside6/tests/QtCore/qtnamespace_test.py
+++ b/sources/pyside6/tests/QtCore/qtnamespace_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test suite for QtCore.Qt namespace'''
@@ -41,11 +16,12 @@ init_test_paths(False)
from PySide6.QtCore import Qt
+
class QtNamespace(unittest.TestCase):
'''Test case for accessing attributes from Qt namespace'''
def testBasic(self):
- #Access to Qt namespace
+ # Access to Qt namespace
getattr(Qt, 'Horizontal')
getattr(Qt, 'WindowMaximizeButtonHint')
self.assertTrue(True)
diff --git a/sources/pyside6/tests/QtCore/qurl_test.py b/sources/pyside6/tests/QtCore/qurl_test.py
index 75f74fbbc..1e9310fe7 100644
--- a/sources/pyside6/tests/QtCore/qurl_test.py
+++ b/sources/pyside6/tests/QtCore/qurl_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test suite for QtCore.QUrl'''
@@ -42,16 +17,17 @@ init_test_paths(False)
from PySide6.QtCore import QUrl
from PySide6.QtCore import QUrlQuery
+
class QUrlBasicConstructor(unittest.TestCase):
'''Tests the basic constructors'''
def testBasic(self):
- #Default constructor for QUrl
+ # Default constructor for QUrl
url = QUrl()
self.assertEqual(url.toString(), "")
def testSetAttributes(self):
- #Construct QUrl by set* methods
+ # Construct QUrl by set* methods
url = QUrl()
url.setScheme('ftp')
@@ -75,6 +51,7 @@ class QUrlBasicConstructor(unittest.TestCase):
self.assertEqual(url.toString(),
'ftp://john:abc123@www.google.com:8080/mail/view')
+
class QueryItemsTest(unittest.TestCase):
'''Test query item management'''
@@ -116,13 +93,15 @@ class QueryItemsTest(unittest.TestCase):
for i, data in enumerate(valid_data):
url.addQueryItem(key, data)
self.assertEqual(url.allQueryItemValues(key),
- list(valid_data[:i+1]))
+ list(valid_data[:i + 1]))
def testPath(self):
url = QUrl("http://qt-project.org/images/ban/pgs_front.jpg")
self.assertEqual(url.path(), "/images/ban/pgs_front.jpg")
# PYSIDE-345: No bindings for QUrlQuery
+
+
class QueryItemsTest(unittest.TestCase):
'''Test query item management'''
@@ -164,7 +143,8 @@ class QueryItemsTest(unittest.TestCase):
for i, data in enumerate(valid_data):
url.addQueryItem(key, data)
self.assertEqual(url.allQueryItemValues(key),
- list(valid_data[:i+1]))
+ list(valid_data[:i + 1]))
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qurlquery_test.py b/sources/pyside6/tests/QtCore/qurlquery_test.py
index 4e2a8fc14..d510908d9 100644
--- a/sources/pyside6/tests/QtCore/qurlquery_test.py
+++ b/sources/pyside6/tests/QtCore/qurlquery_test.py
@@ -1,32 +1,7 @@
#!/usr/bin/python
-
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QUrlQuery'''
@@ -42,22 +17,24 @@ init_test_paths(False)
from PySide6.QtCore import QUrlQuery
+
class QUrlQueryTest(unittest.TestCase):
def testConstructing(self):
empty = QUrlQuery()
self.assertTrue(empty.isEmpty())
- empty.clear();
+ empty.clear()
self.assertTrue(empty.isEmpty())
def testAddRemove(self):
query = QUrlQuery()
- query.addQueryItem("a", "b");
+ query.addQueryItem("a", "b")
self.assertTrue(not query.isEmpty())
self.assertTrue(query.hasQueryItem("a"))
self.assertEqual(query.queryItemValue("a"), "b")
self.assertEqual(query.allQueryItemValues("a"), ["b"])
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/quuid_test.py b/sources/pyside6/tests/QtCore/quuid_test.py
index 215ab68e8..c4a3f8311 100644
--- a/sources/pyside6/tests/QtCore/quuid_test.py
+++ b/sources/pyside6/tests/QtCore/quuid_test.py
@@ -1,32 +1,7 @@
#!/usr/bin/python
-
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QUuid'''
@@ -41,6 +16,7 @@ init_test_paths(False)
from PySide6.QtCore import QUuid
+
class QUuidTest(unittest.TestCase):
def testFromString(self):
uuidString = '{fc69b59e-cc34-4436-a43c-ee95d128b8c5}'
@@ -49,5 +25,6 @@ class QUuidTest(unittest.TestCase):
self.assertTrue(not uuid.isNull())
self.assertEqual(uuid.toString(), uuidString)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/qversionnumber_test.py b/sources/pyside6/tests/QtCore/qversionnumber_test.py
index d08a64d25..db259646b 100644
--- a/sources/pyside6/tests/QtCore/qversionnumber_test.py
+++ b/sources/pyside6/tests/QtCore/qversionnumber_test.py
@@ -1,32 +1,7 @@
#!/usr/bin/python
-
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QVersionNumber'''
@@ -41,6 +16,7 @@ init_test_paths(False)
from PySide6.QtCore import QVersionNumber
+
class QVersionNumberTest(unittest.TestCase):
def testFromString(self):
versionString = '5.9.2'
@@ -51,5 +27,6 @@ class QVersionNumberTest(unittest.TestCase):
self.assertEqual(version.microVersion(), 2)
self.assertEqual(version.toString(), versionString)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/repr_test.py b/sources/pyside6/tests/QtCore/repr_test.py
index 72a5e3a9a..cf3ebd6a6 100644
--- a/sources/pyside6/tests/QtCore/repr_test.py
+++ b/sources/pyside6/tests/QtCore/repr_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -44,12 +20,14 @@ try:
except ImportError:
HAVE_Q = False
+
class ReprCopyHelper:
def testCopy(self):
copy = eval(self.original.__repr__())
self.assertTrue(copy is not self.original)
self.assertEqual(copy, self.original)
+
class QByteArrayReprCopy(ReprCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QByteArray(bytes('the quick brown fox jumps over the lazy dog', "UTF-8"))
@@ -79,34 +57,42 @@ class QSizeFReprCopy(ReprCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QSizeF(42.7, 190.2)
+
class QRectReprCopy(ReprCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QRect(100, 200, 300, 400)
+
class QRectFReprCopy(ReprCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QRectF(100.33, 200.254, 300.321, 400.123)
+
class QLineReprCopy(ReprCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QLine(1, 2, 3, 4)
+
class QLineFReprCopy(ReprCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QLineF(1.1, 2.2, 3.3, 4.4)
+
class QPointReprCopy(ReprCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QPoint(1, 2)
+
class QPointFReprCopy(ReprCopyHelper, unittest.TestCase):
def setUp(self):
self.original = QPointF(1.1, 2.2)
+
class QUuiCopy(ReprCopyHelper, unittest.TestCase):
@unittest.skipUnless(HAVE_Q, "QUuid is currently not supported on this platform.")
def setUp(self):
self.original = QUuid("67C8770B-44F1-410A-AB9A-F9B5446F13EE")
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/resources_mc.py b/sources/pyside6/tests/QtCore/resources_mc.py
index 0de0a8774..36f596cc1 100644
--- a/sources/pyside6/tests/QtCore/resources_mc.py
+++ b/sources/pyside6/tests/QtCore/resources_mc.py
@@ -1,32 +1,6 @@
-# -*- 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
# Resource object code
#
@@ -3562,10 +3536,13 @@ qt_resource_struct = b"""\
\x00\x00\x00\x18\x00\x00\x00\x00\x00\x01\x00\x00\x00\x39\
"""
+
def qInitResources():
QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
+
def qCleanupResources():
QtCore.qUnregisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
+
qInitResources()
diff --git a/sources/pyside6/tests/QtCore/setprop_on_ctor_test.py b/sources/pyside6/tests/QtCore/setprop_on_ctor_test.py
index a5cded3ac..2fda6640c 100644
--- a/sources/pyside6/tests/QtCore/setprop_on_ctor_test.py
+++ b/sources/pyside6/tests/QtCore/setprop_on_ctor_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -42,8 +17,9 @@ from PySide6.QtCore import QTimer
class SetPropOnCtorTest(unittest.TestCase):
def testIt(self):
- timer = QTimer(interval = 42)
- self.assertEqual(timer.interval(), 42);
+ timer = QTimer(interval=42)
+ self.assertEqual(timer.interval(), 42)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/signal_sender.py b/sources/pyside6/tests/QtCore/signal_sender.py
new file mode 100644
index 000000000..464c50e3d
--- /dev/null
+++ b/sources/pyside6/tests/QtCore/signal_sender.py
@@ -0,0 +1,92 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from helper.usesqapplication import UsesQApplication
+
+from PySide6.QtCore import (QCoreApplication, QObject, QStringListModel,
+ QTimer, Signal, Slot, Qt)
+
+
+class Sender(QObject):
+ testSignal = Signal()
+
+ def emitSignal(self):
+ self.testSignal.emit()
+
+
+class Receiver(QObject):
+
+ def __init__(self, parent=None):
+ super().__init__()
+ self._sender = None
+ self._slot_count = 0
+
+ @Slot()
+ def testSlot(self):
+ self._sender = self.sender()
+ self._slot_count += 1
+
+
+class DerivedReceiver(Receiver):
+ pass
+
+
+class TestSignalSender(UsesQApplication):
+ """Test PYSIDE-2144/1295, check that QObject::sender() works also if it is
+ routed via GlobalReceiverV2 in case of a non-C++ slot (Python callback,
+ as for derived classes)."""
+ def testSignalSender(self):
+ sender = Sender()
+ receiver = Receiver()
+ sender.testSignal.connect(receiver.testSlot)
+ derived_receiver = DerivedReceiver()
+ sender.testSignal.connect(derived_receiver.testSlot)
+ sender.emitSignal()
+
+ QTimer.singleShot(100, self.app.quit)
+ while derived_receiver._slot_count == 0:
+ QCoreApplication.processEvents()
+
+ self.assertEqual(receiver._sender, sender)
+ self.assertEqual(derived_receiver._sender, sender)
+
+
+class TestConstructorConnection(UsesQApplication):
+ """PYSIDE-2329: Check constructor connections for signals from the
+ base as well as signals with arguments."""
+ def testConstructorConnection(self):
+
+ was_destroyed = False
+ was_changed = False
+
+ def destroyed_handler():
+ nonlocal was_destroyed
+ was_destroyed = True
+
+ def changed_handler():
+ nonlocal was_changed
+ was_changed = True
+
+ data_list = ["blub"]
+ model = QStringListModel(data_list,
+ destroyed=destroyed_handler,
+ dataChanged=changed_handler)
+ model.setData(model.index(0, 0), "bla", Qt.EditRole)
+ del model
+
+ self.assertTrue(was_changed)
+ self.assertTrue(was_destroyed)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtCore/snake_prop_feature_test.py b/sources/pyside6/tests/QtCore/snake_prop_feature_test.py
index ba58d52d1..f14cf21e2 100644
--- a/sources/pyside6/tests/QtCore/snake_prop_feature_test.py
+++ b/sources/pyside6/tests/QtCore/snake_prop_feature_test.py
@@ -1,41 +1,6 @@
-#############################################################################
-##
-## Copyright (C) 2020 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+from __future__ import annotations
import os
import sys
@@ -46,8 +11,12 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6 import QtWidgets
-from PySide6.support import __feature__
+from PySide6.QtCore import Property, QSize
+from PySide6.QtWidgets import QApplication, QMainWindow, QWidget
+
+is_pypy = hasattr(sys, "pypy_version_info")
+if not is_pypy:
+ from PySide6.support import feature
"""
snake_prop_feature_test.py
@@ -58,18 +27,20 @@ Test the snake_case and true_property feature.
This works now, including class properties.
"""
-class Window(QtWidgets.QWidget):
+
+class Window(QWidget):
def __init__(self):
- super(Window, self).__init__()
+ super().__init__()
+@unittest.skipIf(is_pypy, "__feature__ cannot yet be used with PyPy")
class FeatureTest(unittest.TestCase):
def setUp(self):
- qApp or QtWidgets.QApplication()
- __feature__.set_selection(0)
+ qApp or QApplication()
+ feature.reset()
def tearDown(self):
- __feature__.set_selection(0)
+ feature.reset()
qApp.shutdown()
def testRenamedFunctions(self):
@@ -90,14 +61,16 @@ class FeatureTest(unittest.TestCase):
window.modal
from __feature__ import snake_case, true_property
+ # PYSIDE-1548: Make sure that another import does not clear the features.
+ import sys
- self.assertTrue(isinstance(QtWidgets.QWidget.modal, property))
+ self.assertTrue(isinstance(QWidget.modal, property))
self.assertTrue(isinstance(window.modal, bool))
with self.assertRaises(AttributeError):
window.isModal
# switching back
- __feature__.set_selection(0)
+ feature.reset()
self.assertTrue(callable(window.isModal))
with self.assertRaises(AttributeError):
@@ -106,10 +79,10 @@ class FeatureTest(unittest.TestCase):
def testClassProperty(self):
from __feature__ import snake_case, true_property
# We check the class...
- self.assertEqual(type(QtWidgets.QApplication.quit_on_last_window_closed), bool)
- x = QtWidgets.QApplication.quit_on_last_window_closed
- QtWidgets.QApplication.quit_on_last_window_closed = not x
- self.assertEqual(QtWidgets.QApplication.quit_on_last_window_closed, not x)
+ self.assertEqual(type(QApplication.quit_on_last_window_closed), bool)
+ x = QApplication.quit_on_last_window_closed
+ QApplication.quit_on_last_window_closed = not x
+ self.assertEqual(QApplication.quit_on_last_window_closed, not x)
# ... and now the instance.
self.assertEqual(type(qApp.quit_on_last_window_closed), bool)
x = qApp.quit_on_last_window_closed
@@ -117,7 +90,54 @@ class FeatureTest(unittest.TestCase):
self.assertEqual(qApp.quit_on_last_window_closed, not x)
# make sure values are equal
self.assertEqual(qApp.quit_on_last_window_closed,
- QtWidgets.QApplication.quit_on_last_window_closed)
+ QApplication.quit_on_last_window_closed)
+
+ def testUserClassNotAffected(self):
+ FunctionType = type(lambda: 42)
+ # Note: the types module does not have MethodDescriptorType in low versions.
+ MethodDescriptorType = type(str.split)
+
+ class UserClass(QWidget):
+
+ def someFunc1(self):
+ pass
+
+ @staticmethod
+ def someFunc2(a, b):
+ pass
+
+ inspect = UserClass.__dict__
+ self.assertTrue(isinstance(inspect["someFunc1"], FunctionType))
+ self.assertTrue(isinstance(inspect["someFunc2"], staticmethod))
+ self.assertTrue(isinstance(UserClass.someFunc2, FunctionType))
+ self.assertTrue(isinstance(UserClass.addAction, MethodDescriptorType))
+
+ from __feature__ import snake_case
+
+ inspect = UserClass.__dict__
+ self.assertTrue(isinstance(inspect["someFunc1"], FunctionType))
+ self.assertTrue(isinstance(inspect["someFunc2"], staticmethod))
+ self.assertTrue(isinstance(UserClass.someFunc2, FunctionType))
+ self.assertTrue(isinstance(UserClass.add_action, MethodDescriptorType))
+
+ def testTrueProperyCanOverride(self):
+ from __feature__ import true_property
+
+ class CustomWidget(QWidget):
+ global prop_result
+ prop_result = None
+
+ @Property(QSize)
+ def minimumSizeHint(self):
+ global prop_result
+ print("called")
+ prop_result = super().minimumSizeHint
+ return prop_result
+
+ window = QMainWindow()
+ window.setCentralWidget(CustomWidget(window))
+ window.show()
+ self.assertTrue(isinstance(prop_result, QSize))
if __name__ == '__main__':
diff --git a/sources/pyside6/tests/QtCore/staticMetaObject_test.py b/sources/pyside6/tests/QtCore/staticMetaObject_test.py
index 29ab9a358..0fd207b41 100644
--- a/sources/pyside6/tests/QtCore/staticMetaObject_test.py
+++ b/sources/pyside6/tests/QtCore/staticMetaObject_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,11 +13,13 @@ init_test_paths(False)
from PySide6.QtCore import QObject, Slot, QMetaObject
+
class MyObject(QObject):
@Slot(int, str)
def slot1(self, a, b):
pass
+
class testAttribute(unittest.TestCase):
def testBug896(self):
mo = MyObject.staticMetaObject
@@ -54,5 +32,6 @@ class testAttribute(unittest.TestCase):
self.assertEqual(mo.indexOfSignal('destroyed(void)'), -1)
self.assertTrue(mo.indexOfSignal('destroyed()') > -1)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/static_method_test.py b/sources/pyside6/tests/QtCore/static_method_test.py
index c395f3770..7515c5f6f 100644
--- a/sources/pyside6/tests/QtCore/static_method_test.py
+++ b/sources/pyside6/tests/QtCore/static_method_test.py
@@ -1,32 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Test cases for overloads involving static and non-static versions of a method.'''
@@ -41,6 +16,7 @@ init_test_paths(False)
from PySide6.QtCore import QFile
+
class StaticNonStaticMethodsTest(unittest.TestCase):
'''Test cases for overloads involving static and non-static versions of a method.'''
diff --git a/sources/pyside6/tests/QtCore/thread_signals_test.py b/sources/pyside6/tests/QtCore/thread_signals_test.py
index 21e4d7043..ffef4cda0 100644
--- a/sources/pyside6/tests/QtCore/thread_signals_test.py
+++ b/sources/pyside6/tests/QtCore/thread_signals_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
''' Test case for QObject.signalsBlocked() and blockSignal()'''
@@ -37,17 +13,22 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import QObject, SIGNAL, QFile, QThread, QTimer, Qt
-from helper.usesqcoreapplication import UsesQCoreApplication
+from PySide6.QtCore import Signal, QThread
+from helper.usesqapplication import UsesQApplication
+
class MyThread(QThread):
+ test = Signal(str)
+
def run(self):
- self.emit(SIGNAL("test(const QString&)"), "INdT - PySide");
+ self.test.emit("INdT - PySide")
+
-class TestThreadSignal(UsesQCoreApplication):
+class TestThreadSignal(UsesQApplication):
__called__ = True
+
def _callback(self, msg):
self.assertEqual(msg, "INdT - PySide")
self.__called__ = True
@@ -55,12 +36,13 @@ class TestThreadSignal(UsesQCoreApplication):
def testThread(self):
t = MyThread()
- QObject.connect(t, SIGNAL("test(const QString&)"), self._callback);
+ t.test.connect(self._callback)
t.start()
- self.app.exec_()
+ self.app.exec()
t.wait()
- self.assertTrue(self.__called__);
+ self.assertTrue(self.__called__)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/tr_noop_test.py b/sources/pyside6/tests/QtCore/tr_noop_test.py
index 5743c94a3..7340660be 100644
--- a/sources/pyside6/tests/QtCore/tr_noop_test.py
+++ b/sources/pyside6/tests/QtCore/tr_noop_test.py
@@ -1,31 +1,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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
+import gc
import os
import sys
import unittest
@@ -38,6 +15,7 @@ init_test_paths(False)
from PySide6.QtCore import QT_TR_NOOP, QT_TR_NOOP_UTF8
from PySide6.QtCore import QT_TRANSLATE_NOOP, QT_TRANSLATE_NOOP3, QT_TRANSLATE_NOOP_UTF8
+
class QtTrNoopTest(unittest.TestCase):
def setUp(self):
@@ -45,31 +23,38 @@ class QtTrNoopTest(unittest.TestCase):
def tearDown(self):
del self.txt
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testQtTrNoop(self):
refcnt = sys.getrefcount(self.txt)
result = QT_TR_NOOP(self.txt)
self.assertEqual(result, self.txt)
self.assertEqual(sys.getrefcount(result), refcnt + 1)
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testQtTrNoopUtf8(self):
refcnt = sys.getrefcount(self.txt)
result = QT_TR_NOOP_UTF8(self.txt)
self.assertEqual(result, self.txt)
self.assertEqual(sys.getrefcount(result), refcnt + 1)
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testQtTranslateNoop(self):
refcnt = sys.getrefcount(self.txt)
result = QT_TRANSLATE_NOOP(None, self.txt)
self.assertEqual(result, self.txt)
self.assertEqual(sys.getrefcount(result), refcnt + 1)
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testQtTranslateNoopUtf8(self):
refcnt = sys.getrefcount(self.txt)
result = QT_TRANSLATE_NOOP_UTF8(self.txt)
self.assertEqual(result, self.txt)
self.assertEqual(sys.getrefcount(result), refcnt + 1)
+ @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
def testQtTranslateNoop3(self):
refcnt = sys.getrefcount(self.txt)
result = QT_TRANSLATE_NOOP3(None, self.txt, None)
diff --git a/sources/pyside6/tests/QtCore/translation_test.py b/sources/pyside6/tests/QtCore/translation_test.py
index 28e618534..07f1fa580 100644
--- a/sources/pyside6/tests/QtCore/translation_test.py
+++ b/sources/pyside6/tests/QtCore/translation_test.py
@@ -1,33 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests to test QTranslator and translation in general.'''
@@ -42,9 +16,10 @@ init_test_paths(False)
from PySide6.QtCore import QObject, QTranslator, QCoreApplication
-from helper.usesqcoreapplication import UsesQCoreApplication
+from helper.usesqapplication import UsesQApplication
-class TranslationTest(UsesQCoreApplication):
+
+class TranslationTest(UsesQApplication):
'''Test case for Qt translation facilities.'''
def setUp(self):
@@ -52,17 +27,53 @@ class TranslationTest(UsesQCoreApplication):
self.trdir = os.path.join(os.path.dirname(__file__), 'translations')
def testLatin(self):
- #Set string value to Latin
+ # Set string value to Latin
+ translator = QTranslator()
+ translator.load(os.path.join(self.trdir, 'trans_latin.qm'))
+ self.app.installTranslator(translator)
+
+ obj = QObject()
+ obj.setObjectName(obj.tr('Hello World!'))
+ self.assertEqual(obj.objectName(), 'Orbis, te saluto!')
+
+ def testLatinClass(self):
+ # Set string value to Latin, no instance
translator = QTranslator()
translator.load(os.path.join(self.trdir, 'trans_latin.qm'))
self.app.installTranslator(translator)
obj = QObject()
+ obj.setObjectName(QObject.tr('Hello World!'))
+ self.assertEqual(obj.objectName(), 'Orbis, te saluto!')
+
+ def testLatinDerived(self):
+ # PYSIDE-131: Test that derived classes work, too.
+ translator = QTranslator()
+ translator.load(os.path.join(self.trdir, 'trans_latin.qm'))
+ self.app.installTranslator(translator)
+
+ class Derived(QObject):
+ pass
+
+ obj = Derived()
obj.setObjectName(obj.tr('Hello World!'))
self.assertEqual(obj.objectName(), 'Orbis, te saluto!')
+ def testLatinDerivedClass(self):
+ # PYSIDE-131: Test that derived classes work, too, no instance.
+ translator = QTranslator()
+ translator.load(os.path.join(self.trdir, 'trans_latin.qm'))
+ self.app.installTranslator(translator)
+
+ class Derived(QObject):
+ pass
+
+ obj = Derived()
+ obj.setObjectName(Derived.tr('Hello World!'))
+ self.assertEqual(obj.objectName(), 'Orbis, te saluto!')
+
def testRussian(self):
- #Set string value to Russian
+ # Set string value to Russian
translator = QTranslator()
translator.load(os.path.join(self.trdir, 'trans_russian.qm'))
self.app.installTranslator(translator)
@@ -86,6 +97,7 @@ class TranslationTest(UsesQCoreApplication):
self.assertTrue(isinstance(obj, str))
self.assertEqual(obj, value)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/unaryoperator_test.py b/sources/pyside6/tests/QtCore/unaryoperator_test.py
index fada917ee..2a935afc2 100644
--- a/sources/pyside6/tests/QtCore/unaryoperator_test.py
+++ b/sources/pyside6/tests/QtCore/unaryoperator_test.py
@@ -1,35 +1,11 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Tests the presence of unary operator __neg__ on the QPoint class'''
+import gc
import os
import sys
import unittest
@@ -41,25 +17,28 @@ init_test_paths(False)
from PySide6.QtCore import QPoint
+
class NegUnaryOperatorTest(unittest.TestCase):
'''Tests the presence of unary operator __neg__ on the QPoint class'''
def setUp(self):
- #Acquire resources
+ # Acquire resources
self.x, self.y = 10, 20
self.neg_x, self.neg_y = -self.x, -self.y
self.qpoint = QPoint(self.x, self.y)
def tearDown(self):
- #Release resources
+ # Release resources
del self.qpoint
del self.x
del self.y
del self.neg_x
del self.neg_y
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
def testNegUnaryOperator(self):
- #Test __neg__ unary operator on QPoint class
+ # Test __neg__ unary operator on QPoint class
__neg__method_exists = True
try:
neg_qpoint = -self.qpoint
@@ -69,6 +48,7 @@ class NegUnaryOperatorTest(unittest.TestCase):
self.assertTrue(__neg__method_exists)
self.assertEqual(self.qpoint, -neg_qpoint)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/unicode_test.py b/sources/pyside6/tests/QtCore/unicode_test.py
index 1d3a729fa..b45c8bedf 100644
--- a/sources/pyside6/tests/QtCore/unicode_test.py
+++ b/sources/pyside6/tests/QtCore/unicode_test.py
@@ -1,33 +1,7 @@
#!/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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
'''Unit tests for QString conversion to/from Python Unicode'''
@@ -43,6 +17,7 @@ init_test_paths(False)
from PySide6.QtCore import QObject
from PySide6.QtCore import QByteArray
+
class UnicodeConversion(unittest.TestCase):
'''Test case for QString to/from Python Unicode conversion'''
@@ -53,17 +28,18 @@ class UnicodeConversion(unittest.TestCase):
pass
def testSetRegularStringRetrieveUnicode(self):
- #Set regular Python string retrieve unicode
+ # Set regular Python string retrieve unicode
obj = QObject()
obj.setObjectName('test')
self.assertEqual(obj.objectName(), 'test')
def testSetUnicodeRetrieveUnicode(self):
- #Set Python unicode string and retrieve unicode
+ # Set Python unicode string and retrieve unicode
obj = QObject()
obj.setObjectName('ümlaut')
self.assertEqual(obj.objectName(), 'ümlaut')
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside6/tests/QtCore/versioninfo_test.py b/sources/pyside6/tests/QtCore/versioninfo_test.py
index 9a31dfc00..342c3adf0 100644
--- a/sources/pyside6/tests/QtCore/versioninfo_test.py
+++ b/sources/pyside6/tests/QtCore/versioninfo_test.py
@@ -1,30 +1,6 @@
-#############################################################################
-##
-## 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$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+from __future__ import annotations
import os
import sys
@@ -37,6 +13,7 @@ init_test_paths(False)
import PySide6
+
class TestVersionInfo(unittest.TestCase):
def testIt(self):