aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside2')
-rw-r--r--sources/pyside2/tests/registry/existence_test.py19
-rw-r--r--sources/pyside2/tests/registry/init_platform.py57
-rw-r--r--sources/pyside2/tests/registry/util.py67
3 files changed, 78 insertions, 65 deletions
diff --git a/sources/pyside2/tests/registry/existence_test.py b/sources/pyside2/tests/registry/existence_test.py
index f5f614d04..0313bd9f8 100644
--- a/sources/pyside2/tests/registry/existence_test.py
+++ b/sources/pyside2/tests/registry/existence_test.py
@@ -70,30 +70,27 @@ import os
import sys
import unittest
from textwrap import dedent
-from init_platform import (enum_all, generate_all, is_ci,
- get_effective_refpath, get_refpath, qt_version)
-from util import isolate_warnings, check_warnings, suppress_warnings, warn
+from init_platform import enum_all, generate_all
+from util import (isolate_warnings, check_warnings, suppress_warnings, warn,
+ is_ci, qt_version, get_script_dir, get_effective_refpath,
+ get_refpath, import_refmodule)
from PySide2 import *
refPath = get_refpath()
effectiveRefPath = get_effective_refpath()
-effectiveRefPathRoot = os.path.splitext(effectiveRefPath)[0]
-pyc = effectiveRefPathRoot + ".pyc"
+pyc = os.path.splitext(effectiveRefPath)[0] + ".pyc"
if os.path.exists(pyc) and not os.path.exists(effectiveRefPath):
# on Python2 the pyc file would be imported
os.unlink(pyc)
-module = os.path.basename(effectiveRefPathRoot)
if refPath != effectiveRefPath:
print("*** Falling back to ", effectiveRefPath, " since expected ",
refPath, " does not exist")
-home_dir = effectiveRefPath
-for _ in "abcde":
- home_dir = os.path.dirname(home_dir)
-shortpath = os.path.relpath(effectiveRefPath, home_dir)
+script_dir = get_script_dir()
+shortpath = os.path.relpath(effectiveRefPath, script_dir)
try:
- exec("import {} as sig_exists".format(module))
+ sig_exists = import_refmodule()
print("found:", shortpath)
have_refmodule = True
except ImportError:
diff --git a/sources/pyside2/tests/registry/init_platform.py b/sources/pyside2/tests/registry/init_platform.py
index 52fd4705d..e46c3c113 100644
--- a/sources/pyside2/tests/registry/init_platform.py
+++ b/sources/pyside2/tests/registry/init_platform.py
@@ -54,9 +54,9 @@ shiboken and pysidetest projects.
import sys
import os
-import re
from contextlib import contextmanager
from textwrap import dedent
+from util import get_script_dir
def qt_build():
result = '<Unknown build of Qt>'
@@ -67,7 +67,7 @@ def qt_build():
pass
return result
-script_dir = os.path.normpath(os.path.join(__file__, *".. .. .. .. ..".split()))
+script_dir = get_script_dir()
history_dir = os.path.join(script_dir, 'build_history')
# Find out if we have the build dir, already. Then use it.
@@ -127,7 +127,7 @@ sys.path[:0] = [os.path.join(shiboken_build_dir, "shibokenmodule"),
import PySide2
-all_modules = list("PySide2." + x for x in PySide2.__all__)
+all_modules = list("PySide2." + _ for _ in PySide2.__all__)
# now we should be able to do all imports:
if not have_build_dir:
@@ -147,62 +147,11 @@ for modname in "minimal sample other smart".split():
__import__(modname)
all_modules.append(modname)
-from PySide2.QtCore import __version__
from shibokensupport.signature.lib.enum_sig import SimplifyingEnumerator
-is_py3 = sys.version_info[0] == 3
-is_ci = os.environ.get("QTEST_ENVIRONMENT", "") == "ci"
-# Python2 legacy: Correct 'linux2' to 'linux', recommended way.
-if sys.platform.startswith('linux'):
- # We have to be more specific because we had differences between
- # RHEL 6.6 and RHEL 7.4 .
- # Note: The platform module is deprecated. We need to switch to the
- # distro package, ASAP! The distro has been extracted from Python,
- # because it changes more often than the Python version.
- try:
- import distro
- except ImportError:
- import platform as distro
- platform_name = "".join(distro.linux_distribution()[:2]).lower()
- # this currently happens on opensuse in 5.14:
- if not platform_name:
- # We intentionally crash when that last resort is also absent:
- platform_name = os.environ["MACHTYPE"]
- platform_name = re.sub('[^0-9a-z]', '_', platform_name)
-else:
- platform_name = sys.platform
-# In the linux case, we need more information.
# Make sure not to get .pyc in Python2.
sourcepath = os.path.splitext(__file__)[0] + ".py"
-def qt_version():
- return tuple(map(int, __version__.split(".")))
-
-# 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 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 get_effective_refpath():
- refpath = get_refpath()
- if os.path.exists(refpath):
- return refpath
- version = qt_version()
- major, minor, patch = version[:3]
- while patch >= 0:
- file = _registry_filename((major, minor, patch))
- if os.path.exists(file):
- return file
- patch = patch - 1
- return refpath
-
class Formatter(object):
"""
diff --git a/sources/pyside2/tests/registry/util.py b/sources/pyside2/tests/registry/util.py
index 3033608e6..3fcba921a 100644
--- a/sources/pyside2/tests/registry/util.py
+++ b/sources/pyside2/tests/registry/util.py
@@ -48,6 +48,7 @@ and eventually report them afterwards as error.
"""
import sys
+import os
import warnings
import re
from contextlib import contextmanager
@@ -97,4 +98,70 @@ def warn(message, category=None, stacklevel=2):
category = UserWarning
warnings.warn(message, category, stacklevel)
+
+# Python2 legacy: Correct 'linux2' to 'linux', recommended way.
+if sys.platform.startswith('linux'):
+ # We have to be more specific because we had differences between
+ # RHEL 6.6 and RHEL 7.4 .
+ # Note: The platform module is deprecated. We need to switch to the
+ # distro package, ASAP! The distro has been extracted from Python,
+ # because it changes more often than the Python version.
+ try:
+ import distro
+ except ImportError:
+ import platform as distro
+ platform_name = "".join(distro.linux_distribution()[:2]).lower()
+ # this currently happens on opensuse in 5.14:
+ if not platform_name:
+ # We intentionally crash when that last resort is also absent:
+ platform_name = os.environ["MACHTYPE"]
+ platform_name = re.sub('[^0-9a-z]', '_', platform_name)
+else:
+ platform_name = sys.platform
+# In the linux case, we need more information.
+
+is_py3 = sys.version_info[0] == 3
+is_ci = os.environ.get("QTEST_ENVIRONMENT", "") == "ci"
+
+def get_script_dir():
+ script_dir = os.path.normpath(os.path.dirname(__file__))
+ while "sources" not in os.listdir(script_dir):
+ script_dir = os.path.dirname(script_dir)
+ return script_dir
+
+def qt_version():
+ from PySide2.QtCore import __version__
+ return tuple(map(int, __version__.split(".")))
+
+# Format a registry file name for version.
+def _registry_filename(version, use_ci_module):
+ name = "exists_{}_{}_{}_{}{}.py".format(platform_name,
+ version[0], version[1], version[2], "_ci" if use_ci_module else "")
+ return os.path.join(os.path.dirname(__file__), name)
+
+# Return the expected registry file name.
+def get_refpath(use_ci_module=is_ci):
+ return _registry_filename(qt_version(), use_ci_module)
+
+# Return the registry file name, either that of the current
+# version or fall back to a previous patch release.
+def get_effective_refpath(use_ci_module=is_ci):
+ refpath = get_refpath(use_ci_module)
+ if os.path.exists(refpath):
+ return refpath
+ version = qt_version()
+ major, minor, patch = version[:3]
+ while patch >= 0:
+ file = _registry_filename((major, minor, patch), use_ci_module)
+ if os.path.exists(file):
+ return file
+ patch -= 1
+ return refpath
+
+# Import the CI version of the platform module
+def import_refmodule(use_ci_module=is_ci):
+ refpath = get_effective_refpath(use_ci_module)
+ modname = os.path.basename(os.path.splitext(refpath)[0])
+ return __import__(modname)
+
# eof