aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/QtCore/qenum_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/tests/QtCore/qenum_test.py')
-rw-r--r--sources/pyside6/tests/QtCore/qenum_test.py82
1 files changed, 20 insertions, 62 deletions
diff --git a/sources/pyside6/tests/QtCore/qenum_test.py b/sources/pyside6/tests/QtCore/qenum_test.py
index 146773094..45a8e9124 100644
--- a/sources/pyside6/tests/QtCore/qenum_test.py
+++ b/sources/pyside6/tests/QtCore/qenum_test.py
@@ -1,32 +1,6 @@
#!/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
'''Test cases for QEnum and QFlags'''
@@ -45,20 +19,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 +27,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 +47,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 +94,7 @@ class TestEnumPickling(unittest.TestCase):
# PYSIDE-957: The QEnum macro
+
try:
import enum
HAVE_ENUM = True
@@ -149,21 +102,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 +151,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