diff options
Diffstat (limited to 'sources/pyside6/tests/pysidetest/qvariant_test.py')
-rw-r--r-- | sources/pyside6/tests/pysidetest/qvariant_test.py | 77 |
1 files changed, 46 insertions, 31 deletions
diff --git a/sources/pyside6/tests/pysidetest/qvariant_test.py b/sources/pyside6/tests/pysidetest/qvariant_test.py index eadc2aad0..faefc8169 100644 --- a/sources/pyside6/tests/pysidetest/qvariant_test.py +++ b/sources/pyside6/tests/pysidetest/qvariant_test.py @@ -1,31 +1,7 @@ -############################################################################# -## -## 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 +import enum import os import sys import unittest @@ -35,18 +11,57 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(True) -from testbinding import TestObject -from PySide6.QtCore import Qt -from PySide6.QtGui import QKeySequence +from testbinding import TestObject, TestQVariantEnum +from PySide6.QtCore import Qt, QKeyCombination +from PySide6.QtGui import QKeySequence, QAction from helper.usesqapplication import UsesQApplication + +class PyTestQVariantEnum(TestQVariantEnum): + def __init__(self, var_enum): + super().__init__(var_enum) + + def getRValEnum(self): + return Qt.Orientation.Vertical + + def channelingEnum(self, rval_enum): + return (isinstance(rval_enum, enum.Enum) + and rval_enum == Qt.Orientation.Vertical) + + class QVariantTest(UsesQApplication): def testQKeySequenceQVariantOperator(self): # bug #775 - ks = QKeySequence(Qt.SHIFT, Qt.CTRL, Qt.Key_P, Qt.Key_R) + ks = QKeySequence(Qt.ShiftModifier, Qt.ControlModifier, Qt.Key_P, Qt.Key_R) self.assertEqual(TestObject.checkType(ks), 4107) + def testQKeySequenceMoreVariations(self): + QAction().setShortcut(Qt.CTRL | Qt.Key_B) + QAction().setShortcut(Qt.CTRL | Qt.ALT | Qt.Key_B) + QAction().setShortcut(Qt.CTRL | Qt.AltModifier | Qt.Key_B) + QAction().setShortcut(QKeySequence(QKeyCombination(Qt.CTRL | Qt.Key_B))) + QKeySequence(Qt.CTRL | Qt.Key_Q) + + def testEnum(self): + # Testing C++ class + testqvariant = TestQVariantEnum(Qt.CheckState.Checked) + self.assertEqual(testqvariant.getLValEnum(), Qt.CheckState.Checked) + self.assertIsInstance(testqvariant.getLValEnum(), enum.Enum) + # in the case where we return a QVariant of C++ enum, it returns a + # QVariant(int) to Python unless explicitly handled manually by Shiboken + self.assertEqual(testqvariant.getRValEnum(), 1) + self.assertEqual(testqvariant.isEnumChanneled(), False) + + # Testing Python child class + pytestqvariant = PyTestQVariantEnum(Qt.CheckState.Checked) + self.assertEqual(pytestqvariant.isEnumChanneled(), True) + # check toInt() conversion works for PyObjectWrapper + self.assertEqual(PyTestQVariantEnum.getNumberFromQVarEnum(Qt.Orientation.Vertical), 2) + # check toInt() conversion for IntEnum + self.assertEqual(PyTestQVariantEnum.getNumberFromQVarEnum(Qt.GestureType.TapGesture), 1) + + if __name__ == '__main__': unittest.main() |