aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-04-18 18:58:18 +0200
committerChristian Tismer <tismer@stackless.com>2021-11-19 14:53:57 +0100
commit2385c01953c4fe0986fc2d490b718967e2b3b2c9 (patch)
treed51953f6ddf75ffa6421e171c4253c500e559687
parent4805d04ec67e215dfe9c6384b73a3c59e0f53a68 (diff)
PyPySide: replace the __signature__ attribute by get_signature()
In PyPy, types cannot simply be patched. It would be quite some effort to derive extra heap types for that. Instead, we use `get_signature()` for all tests, which has the same effect. Task-number: PYSIDE-535 Change-Id: I8d9e4adcfc33231d0cd96260feaf2b205bef9a18 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r--sources/pyside6/tests/QtWidgets/signature_test.py26
-rw-r--r--sources/pyside6/tests/pysidetest/new_inherited_functions_test.py3
-rw-r--r--sources/shiboken6/tests/otherbinding/signature_test.py8
-rw-r--r--sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py9
-rw-r--r--sources/shiboken6/tests/samplebinding/namespace_test.py8
-rw-r--r--sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py4
-rw-r--r--sources/shiboken6/tests/samplebinding/renaming_test.py8
7 files changed, 45 insertions, 21 deletions
diff --git a/sources/pyside6/tests/QtWidgets/signature_test.py b/sources/pyside6/tests/QtWidgets/signature_test.py
index c507c2ca7..4955c6b41 100644
--- a/sources/pyside6/tests/QtWidgets/signature_test.py
+++ b/sources/pyside6/tests/QtWidgets/signature_test.py
@@ -49,44 +49,44 @@ init_test_paths(False)
import PySide6.QtCore
import PySide6.QtWidgets
+from PySide6.support.signature import get_signature
class PySideSignatureTest(unittest.TestCase):
def testSignatureExist(self):
- t1 = type(PySide6.QtCore.QObject.children.__signature__)
+ t1 = type(get_signature(PySide6.QtCore.QObject.children))
self.assertEqual(t1, inspect.Signature)
- t2 = type(PySide6.QtCore.QObject.__dict__["children"].__signature__)
+ t2 = type(get_signature(PySide6.QtCore.QObject.__dict__["children"]))
self.assertEqual(t2, t1)
obj = PySide6.QtWidgets.QApplication.palette
- t3 = type(obj.__signature__)
+ t3 = type(get_signature(obj))
self.assertEqual(t3, list)
- self.assertEqual(len(obj.__signature__), 3)
- for thing in obj.__signature__:
+ self.assertEqual(len(get_signature(obj)), 3)
+ for thing in get_signature(obj):
self.assertEqual(type(thing), inspect.Signature)
sm = PySide6.QtWidgets.QApplication.__dict__["palette"]
# PYSIDE-1436: staticmethod is a callable since Python 3.10
# Instead of checking callable(sm), we check the type:
self.assertEqual(type(sm), staticmethod)
- self.assertTrue(hasattr(sm, "__signature__") and
- sm.__signature__ is not None)
+ self.assertTrue(get_signature(sm) is not None)
def testSignatureIsCached(self):
# see if we get the same object
- ob1 = PySide6.QtCore.QObject.children.__signature__
- ob2 = PySide6.QtCore.QObject.children.__signature__
+ ob1 = get_signature(PySide6.QtCore.QObject.children)
+ ob2 = get_signature(PySide6.QtCore.QObject.children)
self.assertTrue(ob1 is ob2)
# same with multi signature
- ob1 = PySide6.QtWidgets.QApplication.palette.__signature__
- ob2 = PySide6.QtWidgets.QApplication.palette.__signature__
+ ob1 = get_signature(PySide6.QtWidgets.QApplication.palette)
+ ob2 = get_signature(PySide6.QtWidgets.QApplication.palette)
self.assertTrue(ob1 is ob2)
def testModuleIsInitialized(self):
- self.assertTrue(PySide6.QtWidgets.QApplication.__signature__ is not None)
+ self.assertTrue(get_signature(PySide6.QtWidgets.QApplication) is not None)
def test_NotCalled_is_callable_and_correct(self):
# A signature that has a default value with some "Default(...)"
# wrapper is callable and creates an object of the right type.
- sig = PySide6.QtCore.QByteArray().toPercentEncoding.__signature__
+ sig = get_signature(PySide6.QtCore.QByteArray().toPercentEncoding)
called_default = sig.parameters["exclude"].default()
self.assertEqual(type(called_default), PySide6.QtCore.QByteArray)
diff --git a/sources/pyside6/tests/pysidetest/new_inherited_functions_test.py b/sources/pyside6/tests/pysidetest/new_inherited_functions_test.py
index 95bf0615f..210ac9178 100644
--- a/sources/pyside6/tests/pysidetest/new_inherited_functions_test.py
+++ b/sources/pyside6/tests/pysidetest/new_inherited_functions_test.py
@@ -36,6 +36,7 @@ from init_paths import init_test_paths
init_test_paths(False)
from PySide6 import *
+from PySide6.support.signature import get_signature
for modname, mod in sys.modules.items():
# Python 2 leaves "None" in the dict.
if modname.startswith("PySide6.") and mod is not None:
@@ -175,7 +176,7 @@ class MainTest(unittest.TestCase):
except AttributeError:
unittest.TestCase().skipTest("this test makes only sense if QtWidgets is available.")
- sigs = PySide6.QtWidgets.QApplication.palette.__signature__
+ sigs = get_signature(PySide6.QtWidgets.QApplication.palette)
self.assertEqual(len(sigs), 3)
diff --git a/sources/shiboken6/tests/otherbinding/signature_test.py b/sources/shiboken6/tests/otherbinding/signature_test.py
index 9f94edd34..3160ce5fa 100644
--- a/sources/shiboken6/tests/otherbinding/signature_test.py
+++ b/sources/shiboken6/tests/otherbinding/signature_test.py
@@ -43,12 +43,18 @@ init_paths()
from other import OtherObjectType
from shiboken_test_helper import objectFullname
+from shiboken6 import Shiboken
+_init_pyside_extension() # trigger bootstrap
+
+from shibokensupport.signature import get_signature
+
+
class SignatureTest(unittest.TestCase):
# Check if the argument of 'OtherObjectType::enumAsInt(SampleNamespace::SomeClass::PublicScopedEnum value)'
# has the correct representation
def testNamespaceFromOtherModule(self):
- argType = OtherObjectType.enumAsInt.__signature__.parameters['value'].annotation
+ argType = get_signature(OtherObjectType.enumAsInt).parameters['value'].annotation
self.assertEqual(objectFullname(argType), 'sample.SampleNamespace.SomeClass.PublicScopedEnum')
if __name__ == '__main__':
diff --git a/sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py b/sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py
index 72705c4c4..f9cbdf20d 100644
--- a/sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py
+++ b/sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py
@@ -41,6 +41,11 @@ init_paths()
import sample
from shiboken_test_helper import objectFullname
+from shiboken6 import Shiboken
+_init_pyside_extension() # trigger bootstrap
+
+from shibokensupport.signature import get_signature
+
class TestEnumFromRemovedNamespace(unittest.TestCase):
def testEnumPromotedToGlobal(self):
@@ -59,10 +64,10 @@ class TestEnumFromRemovedNamespace(unittest.TestCase):
"sample.ObjectOnInvisibleNamespace")
# Function arguments
- signature = sample.ObjectOnInvisibleNamespace.toInt.__signature__
+ signature = get_signature(sample.ObjectOnInvisibleNamespace.toInt)
self.assertEqual(objectFullname(signature.parameters['e'].annotation),
"sample.RemovedNamespace1_Enum")
- signature = sample.ObjectOnInvisibleNamespace.consume.__signature__
+ signature = get_signature(sample.ObjectOnInvisibleNamespace.consume)
self.assertEqual(objectFullname(signature.parameters['other'].annotation),
"sample.ObjectOnInvisibleNamespace")
diff --git a/sources/shiboken6/tests/samplebinding/namespace_test.py b/sources/shiboken6/tests/samplebinding/namespace_test.py
index 3dc79fa96..ca6d2bf39 100644
--- a/sources/shiboken6/tests/samplebinding/namespace_test.py
+++ b/sources/shiboken6/tests/samplebinding/namespace_test.py
@@ -43,6 +43,10 @@ init_paths()
from sample import *
from shiboken_test_helper import objectFullname
+from shiboken6 import Shiboken
+_init_pyside_extension() # trigger bootstrap
+
+from shibokensupport.signature import get_signature
# For tests of invisible namespaces, see
# enumfromremovednamespace_test.py / removednamespaces.h
@@ -79,9 +83,9 @@ class TestClassesUnderNamespace(unittest.TestCase):
"<class 'sample.SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum'>")
# Test if enum inside of class is correct represented
- self.assertEqual(objectFullname(SampleNamespace.enumInEnumOut.__signature__.parameters['in_'].annotation),
+ self.assertEqual(objectFullname(get_signature(SampleNamespace.enumInEnumOut).parameters['in_'].annotation),
"sample.SampleNamespace.InValue")
- self.assertEqual(objectFullname(SampleNamespace.enumAsInt.__signature__.parameters['value'].annotation),
+ self.assertEqual(objectFullname(get_signature(SampleNamespace.enumAsInt).parameters['value'].annotation),
"sample.SampleNamespace.SomeClass.PublicScopedEnum")
diff --git a/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py b/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py
index ad3bd899a..a1ee230ce 100644
--- a/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py
+++ b/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py
@@ -56,6 +56,8 @@ from sample import IntArray2, VirtualMethods
import shiboken6
_init_pyside_extension() # trigger init, which does not happen in tests
+from shibokensupport.signature import get_signature
+
import typing
@@ -75,7 +77,7 @@ class PointerPrimitiveTypeTest(unittest.TestCase):
def testReturnVarSignature(self):
# signature="getMargins(int*,int*,int*,int*)const">
- ann = VirtualMethods.getMargins.__signature__.return_annotation
+ ann = get_signature(VirtualMethods.getMargins).return_annotation
self.assertEqual(ann, typing.Tuple[int, int, int, int])
diff --git a/sources/shiboken6/tests/samplebinding/renaming_test.py b/sources/shiboken6/tests/samplebinding/renaming_test.py
index a31dceb35..32467c025 100644
--- a/sources/shiboken6/tests/samplebinding/renaming_test.py
+++ b/sources/shiboken6/tests/samplebinding/renaming_test.py
@@ -43,6 +43,12 @@ init_paths()
from sample import RenamedValue, RenamedUser
+from shiboken6 import Shiboken
+_init_pyside_extension() # trigger bootstrap
+
+from shibokensupport.signature import get_signature
+
+
class RenamingTest(unittest.TestCase):
def test(self):
'''Tests whether the C++ class ToBeRenamedValue renamed via attribute
@@ -54,7 +60,7 @@ class RenamingTest(unittest.TestCase):
"<class 'sample.RenamedValue'>")
rename_user = RenamedUser()
rename_user.useRenamedValue(renamed_value)
- actual_signature = str(rename_user.useRenamedValue.__signature__)
+ actual_signature = str(get_signature(rename_user.useRenamedValue))
self.assertTrue(re.match(r"^\(self,\s*?v:\s*?sample.RenamedValue\)\s*?->\s*?None$",
actual_signature))