aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/tests/pysidetest
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2017-10-19 11:27:13 +0200
committerChristian Tismer <tismer@stackless.com>2017-11-14 09:39:59 +0000
commitb825eec459a3d5dcddf14061d578ef89e6ad5ee4 (patch)
tree1d01b860a1134fffb31ab0029a4251c939460a4f /sources/pyside2/tests/pysidetest
parentfa1c97fc2a7f25fe178b0c180b56f78ac00bc4c9 (diff)
Update and complete the signature module
There is now an external typing module for Python 2.7 and Python 3.6 from Guido (PSF license again) that makes the differences between both versions vanish. Also, when generating interface files, some types did not show correctly, and the constant "0" is wrong in almost all cases. Values in signatures looked often bad since they have no nice __repr__, and it was almost impossible to create correct .pyi files. Now, these instances are created as wrapped string types with a nice __repr__. A call of these objects creates the real constant. This way, also objects can be rendered which are dependent from the existence of other objects (i.E. QPixMap). This patch improves the usability of the signature module. We can now generate source code or .pyi files without modifications. Task-number: PYSIDE-510 Change-Id: I55490d76a29fc6c0e4f821c0c77d5e5d1e28976e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside2/tests/pysidetest')
-rw-r--r--sources/pyside2/tests/pysidetest/signature_test.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/sources/pyside2/tests/pysidetest/signature_test.py b/sources/pyside2/tests/pysidetest/signature_test.py
index 583b793eb..5478f0011 100644
--- a/sources/pyside2/tests/pysidetest/signature_test.py
+++ b/sources/pyside2/tests/pysidetest/signature_test.py
@@ -55,7 +55,8 @@ all_modules = list("PySide2." + x for x in PySide2.__all__)
from PySide2.support.signature import parser, inspect
-_do_print = True if os.isatty(sys.stdout.fileno()) else False
+_do_print = (True if os.isatty(sys.stdout.fileno()) or "-v" in sys.argv
+ else False)
def dprint(*args, **kw):
if _do_print:
@@ -84,6 +85,8 @@ def enum_module(mod_name):
dprint(" def __init__" + str(signature))
count += 1
class_members = list(klass.__dict__.items())
+ have_sig = signature is not None
+ have_members = 0
for func_name, func in class_members:
signature = getattr(func, '__signature__', None)
if signature is not None:
@@ -94,6 +97,10 @@ def enum_module(mod_name):
else:
dprint(" def", func_name + str(signature))
count += 1
+ have_members = count
+ if not have_sig and not have_members:
+ # print at least "pass"
+ dprint(" pass")
return count
def enum_all():
@@ -149,5 +156,12 @@ class PySideSignatureTest(unittest.TestCase):
def testModuleIsInitialized(self):
assert PySide2.QtWidgets.QApplication.__signature__ 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 = PySide2.QtCore.QByteArray().toPercentEncoding.__signature__
+ called_default = sig.parameters["exclude"].default()
+ self.assertEqual(type(called_default), PySide2.QtCore.QByteArray)
+
if __name__ == "__main__":
unittest.main()