diff options
Diffstat (limited to 'sources/pyside6/tests/QtCore/qflags_test.py')
-rw-r--r-- | sources/pyside6/tests/QtCore/qflags_test.py | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/sources/pyside6/tests/QtCore/qflags_test.py b/sources/pyside6/tests/QtCore/qflags_test.py index 4b368681f..2a5306685 100644 --- a/sources/pyside6/tests/QtCore/qflags_test.py +++ b/sources/pyside6/tests/QtCore/qflags_test.py @@ -1,32 +1,6 @@ #!/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 '''Test cases for QFlags''' @@ -42,6 +16,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 +85,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__': |