aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/tests/samplebinding/enum_test.py
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2022-04-10 17:22:14 +0200
committerChristian Tismer <tismer@stackless.com>2022-05-22 19:27:43 +0200
commit4362ded78ae459265c1e6b7cf562d5cdad382003 (patch)
treeb76145748f01064b76021bbcac526e36bd6006db /sources/shiboken6/tests/samplebinding/enum_test.py
parent37b5b3e2db07d4256aa17376d231a76ea3c393cd (diff)
PyEnum: Prepare Enum tests for both old and new enums
These tests are now completely identical to the old tests and have an adapted Python Enum version if suitable. Both versions can be selected once at runtime. Having both test versions available as a runtime option is a nice feature that really helps understanding the consequences of the PyEnum move. [ChangeLog][PySide6] The QEnum tests are enabled for both the old Qt Enums and the new Python Enums. Change-Id: I78a7473f4a86f8d2115acc56e4ed11cf135eb000 Pick-to: 6.3 Task-number: PYSIDE-1735 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6/tests/samplebinding/enum_test.py')
-rw-r--r--sources/shiboken6/tests/samplebinding/enum_test.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/sources/shiboken6/tests/samplebinding/enum_test.py b/sources/shiboken6/tests/samplebinding/enum_test.py
index 66d7daf5b..e4bfb811d 100644
--- a/sources/shiboken6/tests/samplebinding/enum_test.py
+++ b/sources/shiboken6/tests/samplebinding/enum_test.py
@@ -53,6 +53,7 @@ def createTempFile():
class EnumTest(unittest.TestCase):
'''Test case for Python representation of C++ enums.'''
+ @unittest.skipIf(sys.pyside63_option_python_enum, "test not suitable for Python enum")
def testEnumRepr(self):
enum = SampleNamespace.Option(1)
self.assertEqual(eval(repr(enum)), enum)
@@ -66,7 +67,8 @@ class EnumTest(unittest.TestCase):
def testEnumValuesInsideEnum(self):
'''Enum values should be accessible inside the enum as well as outside.'''
- for value_name in SampleNamespace.Option.values:
+ for value_name in (SampleNamespace.Option.__members__ if sys.pyside63_option_python_enum
+ else SampleNamespace.Option.values):
enum_item1 = getattr(SampleNamespace.Option, value_name)
enum_item2 = getattr(SampleNamespace, value_name)
self.assertEqual(enum_item1, enum_item2)
@@ -79,11 +81,13 @@ class EnumTest(unittest.TestCase):
'''Tries to build the proper enum using an integer.'''
SampleNamespace.getNumber(SampleNamespace.Option(1))
+ @unittest.skipIf(sys.pyside63_option_python_enum, "test not suitable for Python enum")
def testBuildingEnumWithDefaultValue(self):
'''Enum constructor with default value'''
enum = SampleNamespace.Option()
self.assertEqual(enum, SampleNamespace.None_)
+ @unittest.skipIf(sys.pyside63_option_python_enum, "test not suitable for Python enum")
def testEnumConversionToAndFromPython(self):
'''Conversion of enum objects from Python to C++ back again.'''
enumout = SampleNamespace.enumInEnumOut(SampleNamespace.TwoIn)
@@ -96,7 +100,7 @@ class EnumTest(unittest.TestCase):
def testEnumConstructorWithNonNumberParameter(self):
'''Calling the constructor of non-extensible enum with a string.'''
- self.assertRaises(TypeError, SampleNamespace.InValue, '1')
+ self.assertRaises((TypeError, ValueError), SampleNamespace.InValue, '1')
def testEnumItemAsDefaultValueToIntArgument(self):
'''Calls function with an enum item as default value to an int argument.'''
@@ -127,6 +131,7 @@ class EnumTest(unittest.TestCase):
event.setEventTypeByConstRef(Event.SOME_EVENT)
self.assertEqual(event.eventType(), Event.SOME_EVENT)
+ @unittest.skipIf(sys.pyside63_option_python_enum, "test not suitable for Python enum")
def testEnumTpPrintImplementation(self):
'''Without SbkEnum.tp_print 'print' returns the enum represented as an int.'''
tmpfile = createTempFile()
@@ -142,12 +147,14 @@ class EnumTest(unittest.TestCase):
self.assertEqual(SampleNamespace.enumArgumentWithDefaultValue(), SampleNamespace.UnixTime)
self.assertEqual(SampleNamespace.enumArgumentWithDefaultValue(SampleNamespace.RandomNumber), SampleNamespace.RandomNumber)
+ @unittest.skipIf(sys.pyside63_option_python_enum, "test not suitable for Python enum")
def testSignature(self):
enum = SampleNamespace.Option(1)
types = type(enum).mro()
klass = types[0]
base = types[1]
# The class has an empty signature.
+
self.assertEqual(klass.__signature__, None)
# The base class must be Enum
self.assertNotEqual(base.__signature__, None)
@@ -158,18 +165,22 @@ class EnumTest(unittest.TestCase):
class MyEvent(Event):
def __init__(self):
- Event.__init__(self, Event.EventType(999))
+ Event.__init__(self, Event.EventType(3 if sys.pyside63_option_python_enum else 999))
+
class OutOfBoundsTest(unittest.TestCase):
def testValue(self):
e = MyEvent()
- self.assertEqual(repr(e.eventType()), 'sample.Event.EventType(999)')
+ self.assertEqual(repr(e.eventType()), "<EventType.ANY_EVENT: 3>"
+ if sys.pyside63_option_python_enum else 'sample.Event.EventType(999)')
+ @unittest.skipIf(sys.pyside63_option_python_enum, "test not suitable for Python enum")
def testNoneName(self):
e = MyEvent()
t = e.eventType()
self.assertEqual(t.name, None)
+
class EnumOverloadTest(unittest.TestCase):
'''Test case for overloads involving enums'''
@@ -180,6 +191,7 @@ class EnumOverloadTest(unittest.TestCase):
self.assertEqual(o.callWithEnum('', Event.ANY_EVENT, 9), 81)
self.assertEqual(o.callWithEnum('', 9), 9)
+
class EnumOperators(unittest.TestCase):
'''Test case for operations on enums'''