aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/tests
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2018-07-14 15:10:56 +0200
committerChristian Tismer <tismer@stackless.com>2018-12-22 12:26:10 +0000
commit73a9168ad56559bb3fba0d93866b05a7fde812de (patch)
treeb57018ee6702eac794867635d549a3b65509ca71 /sources/pyside2/tests
parentc013faebdfb248e1ce66fa41aa0a771aaf4e3d80 (diff)
Complete The Signature Introspection
The signature module has been quite far developed. In the course of making things fit for the TypeErrors with the signature module, now also all signatures from all shiboken modules are queried. Instead of writing an extra signature existence test for shiboken, it made more sense to extend the existing init_platform.py by the shiboken modules. In fact, by this query a corner case was exploited that worked on Python 2 but assertion-crashed on Python 3. The mapping.py modules were also completed to support all new PySide2 modules. Special care had to be taken because the "shiboken2" module exists both as directory and as binary module. The fix was tricky, and I will add a task that replaces such workarounds by a better design. Task-number: PYSIDE-510 Change-Id: Ibf8e322d1905976a0044a702ea178b7f98629fb4 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside2/tests')
-rw-r--r--sources/pyside2/tests/QtGui/qmatrix_test.py3
-rw-r--r--sources/pyside2/tests/registry/existence_test.py14
-rw-r--r--sources/pyside2/tests/registry/init_platform.py117
3 files changed, 110 insertions, 24 deletions
diff --git a/sources/pyside2/tests/QtGui/qmatrix_test.py b/sources/pyside2/tests/QtGui/qmatrix_test.py
index 7cfe9ea60..bc6a2b8ae 100644
--- a/sources/pyside2/tests/QtGui/qmatrix_test.py
+++ b/sources/pyside2/tests/QtGui/qmatrix_test.py
@@ -47,7 +47,8 @@ class QMatrixTest(unittest.TestCase):
def testMatrixWithWrongType(self):
matrix = QMatrix(11, 12, 21, 22, 100, 200)
point = QPoint(3, 3)
- self.assertRaises(TypeError, matrix.__mul__, point)
+ # This exception may move from a TypeError to a ValueError.
+ self.assertRaises((TypeError, ValueError), matrix.__mul__, point)
def testMatrix2x2(self):
matrix = QMatrix2x2([1.0, 2.0, 3.0, 4.0])
diff --git a/sources/pyside2/tests/registry/existence_test.py b/sources/pyside2/tests/registry/existence_test.py
index 0d8014ad8..762a5888e 100644
--- a/sources/pyside2/tests/registry/existence_test.py
+++ b/sources/pyside2/tests/registry/existence_test.py
@@ -39,17 +39,23 @@
from __future__ import print_function, absolute_import
+"""
+existence_test.py
+
+A test that checks all function signatures if they still exist.
+"""
+
import os
import sys
import unittest
from textwrap import dedent
from init_platform import (enum_all, generate_all, is_ci,
- getEffectiveRefPath, getRefPath, qtVersion)
+ get_effective_refpath, get_refpath, qt_version)
from util import isolate_warnings, check_warnings, suppress_warnings, warn
from PySide2 import *
-refPath = getRefPath()
-effectiveRefPath = getEffectiveRefPath()
+refPath = get_refpath()
+effectiveRefPath = get_effective_refpath()
effectiveRefPathRoot = os.path.splitext(effectiveRefPath)[0]
pyc = effectiveRefPathRoot + ".pyc"
if os.path.exists(pyc) and not os.path.exists(effectiveRefPath):
@@ -132,7 +138,7 @@ class TestSignaturesExists(unittest.TestCase):
tested_versions = (5, 6), (5, 9), (5, 11) #, (5, 12) # activate this, soon!
-if not have_refmodule and is_ci and qtVersion()[:2] in tested_versions:
+if not have_refmodule and is_ci and qt_version()[:2] in tested_versions:
class TestFor_CI_Init(unittest.TestCase):
"""
This helper class generates the reference file for CI.
diff --git a/sources/pyside2/tests/registry/init_platform.py b/sources/pyside2/tests/registry/init_platform.py
index ded8ba81c..ca2b2cb68 100644
--- a/sources/pyside2/tests/registry/init_platform.py
+++ b/sources/pyside2/tests/registry/init_platform.py
@@ -40,21 +40,98 @@
from __future__ import print_function, absolute_import
"""
+init_platform.py
+
Existence registry
+==================
This is a registry for all existing function signatures.
One file is generated with all signatures of a platform and version.
+
+The scope has been extended to generate all signatures from the
+shiboken and pysidetest projects.
"""
import sys
import os
import re
-import PySide2
from contextlib import contextmanager
from textwrap import dedent
+script_dir = os.path.normpath(os.path.join(__file__, *".. .. .. .. ..".split()))
+history_dir = os.path.join(script_dir, 'build_history')
+
+# Find out if we have the build dir, already. Then use it.
+look_for = os.path.join("pyside2", "tests", "pysidetest")
+have_build_dir = [x for x in sys.path if x.endswith(look_for)]
+if have_build_dir:
+ all_build_dir = os.path.normpath(os.path.join(have_build_dir[0], "..", "..", ".."))
+elif os.path.exists(history_dir):
+ # Using the last build to find the build dir.
+ # Note: This is not reliable when building in parallel!
+ last_build = max(x for x in os.listdir(history_dir) if x.startswith("20"))
+ fpath = os.path.join(history_dir, last_build, "build_dir.txt")
+ if os.path.exists(fpath):
+ with open(fpath) as f:
+ all_build_dir = f.read().strip()
+else:
+ print(dedent("""
+ Can't find the build dir in the history.
+ Compile again and don't forget to specify "--build-tests".
+ """))
+ sys.exit(1)
+
+if not os.path.exists(os.path.join(all_build_dir, look_for)):
+ print(dedent("""
+ PySide has not been built with tests enabled.
+ Compile again and don't forget to specify "--build-tests".
+ """))
+ sys.exit(1)
+
+pyside_build_dir = os.path.join(all_build_dir, "pyside2")
+shiboken_build_dir = os.path.join(all_build_dir, "shiboken2")
+
+# now we compute all paths:
+def set_ospaths(build_dir):
+ ps = os.pathsep
+ ospath_var = "PATH" if sys.platform == "win32" else "LD_LIBRARY_PATH"
+ old_val = os.environ.get(ospath_var, "")
+ lib_path = [os.path.join(build_dir, "pyside2", "libpyside"),
+ os.path.join(build_dir, "pyside2", "tests", "pysidetest"),
+ os.path.join(build_dir, "shiboken2", "tests", "libminimal"),
+ os.path.join(build_dir, "shiboken2", "tests", "libsample"),
+ os.path.join(build_dir, "shiboken2", "tests", "libother"),
+ os.path.join(build_dir, "shiboken2", "tests", "libsmart"),
+ os.path.join(build_dir, "shiboken2", "libshiboken")]
+ ospath = ps.join(lib_path + old_val.split(ps))
+ os.environ[ospath_var] = ospath
+
+set_ospaths(all_build_dir)
+sys.path[:0] = [os.path.join(shiboken_build_dir, "shibokenmodule"),
+ pyside_build_dir]
+
+import PySide2
+
all_modules = list("PySide2." + x for x in PySide2.__all__)
+# now we should be able to do all imports:
+if not have_build_dir:
+ sys.path.insert(0, os.path.join(pyside_build_dir, "tests", "pysidetest"))
+import testbinding
+all_modules.append("testbinding")
+
+# Note: This is not the shiboken dir as usual, but the binary.
+import shiboken2 as Shiboken
+Shiboken.__name__ = "Shiboken"
+sys.modules["Shiboken"] = sys.modules.pop("shiboken2")
+all_modules.append("Shiboken")
+
+# 'sample' seems to be needed by 'other', so import it first.
+for modname in "minimal sample other smart".split():
+ sys.path.insert(0, os.path.join(shiboken_build_dir, "tests", modname + "binding"))
+ __import__(modname)
+ all_modules.append(modname)
+
from PySide2.QtCore import __version__
from PySide2.support.signature.lib.enum_sig import SimplifyingEnumerator
@@ -79,36 +156,35 @@ else:
# Make sure not to get .pyc in Python2.
sourcepath = os.path.splitext(__file__)[0] + ".py"
-def qtVersion():
+def qt_version():
return tuple(map(int, __version__.split(".")))
-# Format a registry file name for version
-def _registryFileName(version):
+# Format a registry file name for version.
+def _registry_filename(version):
name = "exists_{}_{}_{}_{}{}.py".format(platform_name,
version[0], version[1], version[2], "_ci" if is_ci else "")
return os.path.join(os.path.dirname(__file__), name)
-# Return the expected registry file name
-def getRefPath():
- return _registryFileName(qtVersion())
+# Return the expected registry file name.
+def get_refpath():
+ return _registry_filename(qt_version())
# Return the registry file name, either that of the current
-# version or fall back to a previous patch release
-def getEffectiveRefPath():
- refpath = getRefPath()
+# version or fall back to a previous patch release.
+def get_effective_refpath():
+ refpath = get_refpath()
if os.path.exists(refpath):
return refpath
- version = qtVersion()
- majorVersion = version[0]
- minorVersion = version[1]
- patchVersion = version[2]
- while patchVersion >= 0:
- file = _registryFileName((majorVersion, minorVersion, patchVersion))
+ version = qt_version()
+ major, minor, patch = version[:3]
+ while patch >= 0:
+ file = _registry_filename((major, minor, patch))
if os.path.exists(file):
return file
- patchVersion = patchVersion - 1
+ patch = patch - 1
return refpath
+
class Formatter(object):
"""
Formatter is formatting the signature listing of an enumerator.
@@ -163,8 +239,9 @@ def enum_all():
ret.update(enu.module(mod_name))
return ret
+
def generate_all():
- refPath = getRefPath()
+ refPath = get_refpath()
module = os.path.basename(os.path.splitext(refPath)[0])
with open(refPath, "w") as outfile, open(sourcepath) as f:
fmt = Formatter(outfile)
@@ -190,10 +267,12 @@ def generate_all():
enu.module(mod_name)
fmt.print("# eof")
+
def __main__():
print("+++ generating {}. You should probably check this file in."
- .format(getRefPath()))
+ .format(get_refpath()))
generate_all()
+
if __name__ == "__main__":
__main__()