diff options
author | Christian Tismer <tismer@stackless.com> | 2022-06-21 10:22:04 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2022-07-14 17:21:46 +0200 |
commit | 0a3f69537d5901d626077c0a8e6486f33ebf88af (patch) | |
tree | f6080f2cc2c33b56cf738e40ec5ba21ebb726a3b /sources/shiboken6/tests/samplebinding | |
parent | f92b7dcac9537fb091dc15d3ee218f1984d8abef (diff) |
PyEnum: Simplify the test-cases with the new forgiveness mode
With the new forgiveness, all the "normal" uses of old enums
are working with the new enums, too.
What does not work are range violations and inheritance of enums
from other enums.
Also, the implemented trick does not work for enums which
do not belong to a class. The induced bugs are easy to find,
because they should normally break at import time.
[ChangeLog][PySide6] The new forgiveness mode of Python enums
allows to use old enum code, most of the time. Much changed
test code was reverted.
Change-Id: I9c081831309f1b2358fe86e6107b0f4d78fd48cf
Pick-to: 6.3
Task-number: PYSIDE-1735
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/tests/samplebinding')
-rw-r--r-- | sources/shiboken6/tests/samplebinding/derived_test.py | 5 | ||||
-rw-r--r-- | sources/shiboken6/tests/samplebinding/enum_test.py | 11 | ||||
-rw-r--r-- | sources/shiboken6/tests/samplebinding/namespace_test.py | 20 |
3 files changed, 14 insertions, 22 deletions
diff --git a/sources/shiboken6/tests/samplebinding/derived_test.py b/sources/shiboken6/tests/samplebinding/derived_test.py index 2d5eb4293..7db8e5155 100644 --- a/sources/shiboken6/tests/samplebinding/derived_test.py +++ b/sources/shiboken6/tests/samplebinding/derived_test.py @@ -57,7 +57,6 @@ class DerivedTest(unittest.TestCase): self.assertEqual(type(result), OverloadedFuncEnum) self.assertEqual(result, sample.OverloadedFunc_d) - @unittest.skipIf(sys.pyside63_option_python_enum, "Makes no sense with strict Enums") def testOtherOverloadedMethodCall(self): '''Another test to check overloaded method calling, just to double check.''' derived = Derived() @@ -70,13 +69,13 @@ class DerivedTest(unittest.TestCase): self.assertEqual(type(result), Derived.OtherOverloadedFuncEnum) self.assertEqual(result, Derived.OtherOverloadedFunc_id) - @unittest.skipIf(sys.pyside63_option_python_enum, "Makes no sense with strict Enums") def testOverloadedMethodCallWithDifferentNumericTypes(self): '''Test if the correct overloaded method accepts a different numeric type as argument.''' derived = Derived() result = derived.overloaded(1.1, 2.2) self.assertEqual(type(result), OverloadedFuncEnum) - self.assertEqual(result, sample.OverloadedFunc_ii) + if not sys.pyside63_option_python_enum: + self.assertEqual(result, sample.OverloadedFunc_ii) def testOverloadedMethodCallWithWrongNumberOfArguments(self): '''Test if a call to an overloaded method with the wrong number of arguments raises an exception.''' diff --git a/sources/shiboken6/tests/samplebinding/enum_test.py b/sources/shiboken6/tests/samplebinding/enum_test.py index 9284257f0..8275b0edf 100644 --- a/sources/shiboken6/tests/samplebinding/enum_test.py +++ b/sources/shiboken6/tests/samplebinding/enum_test.py @@ -18,11 +18,14 @@ import shiboken6 import sample from sample import SampleNamespace, ObjectType, Event +from shibokensupport.signature import get_signature + def createTempFile(): import tempfile return tempfile.SpooledTemporaryFile(mode='rw') + class EnumTest(unittest.TestCase): '''Test case for Python representation of C++ enums.''' @@ -54,13 +57,11 @@ 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) @@ -128,11 +129,11 @@ class EnumTest(unittest.TestCase): base = types[1] # The class has an empty signature. - self.assertEqual(klass.__signature__, None) + self.assertEqual(get_signature(klass), None) # The base class must be Enum - self.assertNotEqual(base.__signature__, None) + self.assertNotEqual(get_signature(base), None) # It contains an int annotation. - param = base.__signature__.parameters["itemValue"] + param = get_signature(base).parameters["itemValue"] self.assertEqual(param.annotation, int) diff --git a/sources/shiboken6/tests/samplebinding/namespace_test.py b/sources/shiboken6/tests/samplebinding/namespace_test.py index 2d5895082..3238473a0 100644 --- a/sources/shiboken6/tests/samplebinding/namespace_test.py +++ b/sources/shiboken6/tests/samplebinding/namespace_test.py @@ -31,20 +31,12 @@ class TestVariablesUnderNamespace(unittest.TestCase): class TestClassesUnderNamespace(unittest.TestCase): def testIt(self): - if sys.pyside63_option_python_enum: - c1 = SampleNamespace.SomeClass() - e1 = SampleNamespace.SomeClass.ProtectedEnum(0) - c2 = SampleNamespace.SomeClass.SomeInnerClass() - e2 = SampleNamespace.SomeClass.SomeInnerClass.ProtectedEnum(0) - c3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough() - e3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum(0) - else: - c1 = SampleNamespace.SomeClass() - e1 = SampleNamespace.SomeClass.ProtectedEnum() - c2 = SampleNamespace.SomeClass.SomeInnerClass() - e2 = SampleNamespace.SomeClass.SomeInnerClass.ProtectedEnum() - c3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough() - e3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum() + c1 = SampleNamespace.SomeClass() + e1 = SampleNamespace.SomeClass.ProtectedEnum() + c2 = SampleNamespace.SomeClass.SomeInnerClass() + e2 = SampleNamespace.SomeClass.SomeInnerClass.ProtectedEnum() + c3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough() + e3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum(0) def testFunctionAddedOnNamespace(self): res = SampleNamespace.ImInsideANamespace(2, 2) |