2019-06-03 05:06:07 +00:00
|
|
|
from collections import namedtuple
|
2020-02-25 07:00:42 +00:00
|
|
|
from pyqtgraph import Qt
|
2019-06-02 05:18:39 +00:00
|
|
|
import errno
|
2021-05-31 04:29:24 +00:00
|
|
|
import time
|
2019-06-02 05:18:39 +00:00
|
|
|
import importlib
|
2015-07-12 20:45:39 +00:00
|
|
|
import itertools
|
|
|
|
import pytest
|
2016-12-14 18:14:11 +00:00
|
|
|
import os, sys
|
2020-12-22 08:39:29 +00:00
|
|
|
import platform
|
2019-06-02 05:18:39 +00:00
|
|
|
import subprocess
|
2021-01-26 21:45:53 +00:00
|
|
|
from argparse import Namespace
|
2020-10-19 18:51:12 +00:00
|
|
|
if __name__ == "__main__" and (__package__ is None or __package__==''):
|
|
|
|
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
sys.path.insert(0, parent_dir)
|
|
|
|
import examples
|
|
|
|
__package__ = "examples"
|
2019-06-02 05:18:39 +00:00
|
|
|
|
2021-01-26 21:45:53 +00:00
|
|
|
from . import utils
|
2019-06-02 05:18:39 +00:00
|
|
|
|
2020-10-19 18:51:12 +00:00
|
|
|
def buildFileList(examples, files=None):
|
|
|
|
if files is None:
|
2021-01-26 21:45:53 +00:00
|
|
|
files = []
|
2020-10-19 18:51:12 +00:00
|
|
|
for key, val in examples.items():
|
2021-01-26 21:45:53 +00:00
|
|
|
if isinstance(val, dict):
|
2020-10-19 18:51:12 +00:00
|
|
|
buildFileList(val, files)
|
2021-01-26 21:45:53 +00:00
|
|
|
elif isinstance(val, Namespace):
|
|
|
|
files.append((key, val.filename))
|
|
|
|
else:
|
|
|
|
files.append((key, val))
|
2020-10-19 18:51:12 +00:00
|
|
|
return files
|
2019-06-03 05:06:07 +00:00
|
|
|
|
|
|
|
|
2020-10-19 18:51:12 +00:00
|
|
|
path = os.path.abspath(os.path.dirname(__file__))
|
2021-05-28 15:44:23 +00:00
|
|
|
files = [("Example App", "RunExampleApp.py")]
|
2021-01-26 21:45:53 +00:00
|
|
|
for ex in [utils.examples, utils.others]:
|
|
|
|
files = buildFileList(ex, files)
|
|
|
|
files = sorted(set(files))
|
2019-08-29 20:56:25 +00:00
|
|
|
frontends = {
|
|
|
|
Qt.PYQT5: False,
|
2021-01-18 04:38:28 +00:00
|
|
|
Qt.PYQT6: False,
|
|
|
|
Qt.PYSIDE2: False,
|
|
|
|
Qt.PYSIDE6: False,
|
2019-08-29 20:56:25 +00:00
|
|
|
}
|
2019-06-03 05:06:07 +00:00
|
|
|
# sort out which of the front ends are available
|
|
|
|
for frontend in frontends.keys():
|
|
|
|
try:
|
|
|
|
importlib.import_module(frontend)
|
|
|
|
frontends[frontend] = True
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
2019-08-29 20:56:25 +00:00
|
|
|
installedFrontends = sorted([
|
|
|
|
frontend for frontend, isPresent in frontends.items() if isPresent
|
|
|
|
])
|
2019-06-03 05:06:07 +00:00
|
|
|
|
2021-02-26 05:38:12 +00:00
|
|
|
darwin_opengl_broken = (platform.system() == "Darwin" and
|
|
|
|
tuple(map(int, platform.mac_ver()[0].split("."))) >= (10, 16) and
|
2021-04-16 05:08:50 +00:00
|
|
|
sys.version_info < (3, 9, 1))
|
2021-02-26 05:38:12 +00:00
|
|
|
|
|
|
|
darwin_opengl_reason = ("pyopenGL cannot find openGL library on big sur: "
|
|
|
|
"https://github.com/python/cpython/pull/21241")
|
|
|
|
|
2019-06-03 05:06:07 +00:00
|
|
|
exceptionCondition = namedtuple("exceptionCondition", ["condition", "reason"])
|
2019-08-29 20:56:25 +00:00
|
|
|
conditionalExamples = {
|
|
|
|
"hdf5.py": exceptionCondition(
|
|
|
|
False,
|
|
|
|
reason="Example requires user interaction"
|
|
|
|
),
|
|
|
|
"RemoteSpeedTest.py": exceptionCondition(
|
|
|
|
False,
|
|
|
|
reason="Test is being problematic on CI machines"
|
|
|
|
),
|
|
|
|
'GLVolumeItem.py': exceptionCondition(
|
2021-02-26 05:38:12 +00:00
|
|
|
not darwin_opengl_broken,
|
|
|
|
reason=darwin_opengl_reason
|
2019-08-29 20:56:25 +00:00
|
|
|
),
|
|
|
|
'GLIsosurface.py': exceptionCondition(
|
2021-02-26 05:38:12 +00:00
|
|
|
not darwin_opengl_broken,
|
|
|
|
reason=darwin_opengl_reason
|
2019-08-29 20:56:25 +00:00
|
|
|
),
|
|
|
|
'GLSurfacePlot.py': exceptionCondition(
|
2021-02-26 05:38:12 +00:00
|
|
|
not darwin_opengl_broken,
|
|
|
|
reason=darwin_opengl_reason
|
2019-08-29 20:56:25 +00:00
|
|
|
),
|
|
|
|
'GLScatterPlotItem.py': exceptionCondition(
|
2021-02-26 05:38:12 +00:00
|
|
|
not darwin_opengl_broken,
|
|
|
|
reason=darwin_opengl_reason
|
2019-08-29 20:56:25 +00:00
|
|
|
),
|
|
|
|
'GLshaders.py': exceptionCondition(
|
2021-02-26 05:38:12 +00:00
|
|
|
not darwin_opengl_broken,
|
|
|
|
reason=darwin_opengl_reason
|
2019-08-29 20:56:25 +00:00
|
|
|
),
|
2021-06-06 05:13:04 +00:00
|
|
|
'GLTextItem.py': exceptionCondition(
|
|
|
|
not darwin_opengl_broken,
|
|
|
|
reason=darwin_opengl_reason
|
|
|
|
),
|
2019-08-29 20:56:25 +00:00
|
|
|
'GLLinePlotItem.py': exceptionCondition(
|
2021-02-26 05:38:12 +00:00
|
|
|
not darwin_opengl_broken,
|
|
|
|
reason=darwin_opengl_reason
|
2019-08-29 20:56:25 +00:00
|
|
|
),
|
|
|
|
'GLMeshItem.py': exceptionCondition(
|
2021-02-26 05:38:12 +00:00
|
|
|
not darwin_opengl_broken,
|
|
|
|
reason=darwin_opengl_reason
|
2019-08-29 20:56:25 +00:00
|
|
|
),
|
|
|
|
'GLImageItem.py': exceptionCondition(
|
2021-02-26 05:38:12 +00:00
|
|
|
not darwin_opengl_broken,
|
|
|
|
reason=darwin_opengl_reason
|
2021-01-26 21:45:53 +00:00
|
|
|
),
|
|
|
|
'GLBarGraphItem.py': exceptionCondition(
|
2021-02-26 05:38:12 +00:00
|
|
|
not darwin_opengl_broken,
|
|
|
|
reason=darwin_opengl_reason
|
2021-01-26 21:45:53 +00:00
|
|
|
),
|
|
|
|
'GLViewWidget.py': exceptionCondition(
|
2021-02-26 05:38:12 +00:00
|
|
|
not darwin_opengl_broken,
|
|
|
|
reason=darwin_opengl_reason
|
2019-08-29 20:56:25 +00:00
|
|
|
)
|
2019-06-03 05:06:07 +00:00
|
|
|
}
|
|
|
|
|
2020-06-03 05:44:17 +00:00
|
|
|
@pytest.mark.skipif(
|
|
|
|
Qt.QT_LIB == "PySide2"
|
|
|
|
and tuple(map(int, Qt.PySide2.__version__.split("."))) >= (5, 14)
|
|
|
|
and tuple(map(int, Qt.PySide2.__version__.split("."))) < (5, 14, 2, 2),
|
|
|
|
reason="new PySide2 doesn't have loadUi functionality"
|
|
|
|
)
|
2019-06-03 05:06:07 +00:00
|
|
|
@pytest.mark.parametrize(
|
2019-08-29 20:56:25 +00:00
|
|
|
"frontend, f",
|
|
|
|
[
|
|
|
|
pytest.param(
|
|
|
|
frontend,
|
2019-06-03 05:06:07 +00:00
|
|
|
f,
|
2019-08-29 20:56:25 +00:00
|
|
|
marks=pytest.mark.skipif(
|
|
|
|
conditionalExamples[f[1]].condition is False,
|
|
|
|
reason=conditionalExamples[f[1]].reason
|
|
|
|
) if f[1] in conditionalExamples.keys() else (),
|
|
|
|
)
|
|
|
|
for frontend, f, in itertools.product(installedFrontends, files)
|
|
|
|
],
|
|
|
|
ids = [
|
|
|
|
" {} - {} ".format(f[1], frontend)
|
|
|
|
for frontend, f in itertools.product(
|
|
|
|
installedFrontends,
|
|
|
|
files
|
|
|
|
)
|
|
|
|
]
|
2019-06-03 05:06:07 +00:00
|
|
|
)
|
2021-02-22 10:23:01 +00:00
|
|
|
def testExamples(frontend, f):
|
2019-06-03 05:06:07 +00:00
|
|
|
name, file = f
|
2019-06-02 05:18:39 +00:00
|
|
|
global path
|
2019-08-29 20:56:25 +00:00
|
|
|
fn = os.path.join(path, file)
|
2019-06-02 05:18:39 +00:00
|
|
|
os.chdir(path)
|
2021-05-31 04:29:24 +00:00
|
|
|
sys.stdout.write(f"{name}")
|
2019-06-02 05:18:39 +00:00
|
|
|
sys.stdout.flush()
|
2019-06-03 05:06:07 +00:00
|
|
|
import1 = "import %s" % frontend if frontend != '' else ''
|
2019-06-02 05:18:39 +00:00
|
|
|
import2 = os.path.splitext(os.path.split(fn)[1])[0]
|
|
|
|
code = """
|
|
|
|
try:
|
2021-02-08 06:11:20 +00:00
|
|
|
{0}
|
2019-06-02 05:18:39 +00:00
|
|
|
import initExample
|
|
|
|
import pyqtgraph as pg
|
2021-02-08 06:11:20 +00:00
|
|
|
import {1}
|
2019-06-02 05:18:39 +00:00
|
|
|
import sys
|
|
|
|
print("test complete")
|
|
|
|
sys.stdout.flush()
|
2021-02-08 06:11:20 +00:00
|
|
|
pg.Qt.QtCore.QTimer.singleShot(1000, pg.Qt.QtWidgets.QApplication.quit)
|
2021-05-13 21:28:22 +00:00
|
|
|
pg.exec()
|
2021-02-08 06:11:20 +00:00
|
|
|
names = [x for x in dir({1}) if not x.startswith('_')]
|
|
|
|
for name in names:
|
|
|
|
delattr({1}, name)
|
2019-06-02 05:18:39 +00:00
|
|
|
except:
|
|
|
|
print("test failed")
|
|
|
|
raise
|
|
|
|
|
2021-02-08 06:11:20 +00:00
|
|
|
""".format(import1, import2)
|
2021-05-31 04:29:24 +00:00
|
|
|
process = subprocess.Popen([sys.executable],
|
|
|
|
stdin=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
text=True)
|
|
|
|
process.stdin.write(code)
|
2019-08-29 20:56:25 +00:00
|
|
|
process.stdin.close()
|
2021-05-31 04:29:24 +00:00
|
|
|
|
2019-06-02 05:18:39 +00:00
|
|
|
output = ''
|
|
|
|
fail = False
|
|
|
|
while True:
|
|
|
|
try:
|
2021-05-31 04:29:24 +00:00
|
|
|
c = process.stdout.read(1)
|
2019-06-02 05:18:39 +00:00
|
|
|
except IOError as err:
|
|
|
|
if err.errno == errno.EINTR:
|
|
|
|
# Interrupted system call; just try again.
|
|
|
|
c = ''
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
output += c
|
|
|
|
if output.endswith('test complete'):
|
|
|
|
break
|
|
|
|
if output.endswith('test failed'):
|
|
|
|
fail = True
|
|
|
|
break
|
2021-02-08 06:11:20 +00:00
|
|
|
start = time.time()
|
|
|
|
killed = False
|
|
|
|
while process.poll() is None:
|
|
|
|
time.sleep(0.1)
|
|
|
|
if time.time() - start > 2.0 and not killed:
|
|
|
|
process.kill()
|
|
|
|
killed = True
|
2021-05-31 04:29:24 +00:00
|
|
|
|
|
|
|
stdout, stderr = (process.stdout.read(), process.stderr.read())
|
|
|
|
process.stdout.close()
|
|
|
|
process.stderr.close()
|
|
|
|
|
2019-08-29 20:56:25 +00:00
|
|
|
if (fail or
|
2021-06-08 07:13:17 +00:00
|
|
|
'Exception:' in stderr or
|
|
|
|
'Error:' in stderr):
|
2021-05-31 04:29:24 +00:00
|
|
|
if (not fail
|
|
|
|
and name == "RemoteGraphicsView"
|
|
|
|
and "pyqtgraph.multiprocess.remoteproxy.ClosedError" in stderr):
|
|
|
|
# This test can intermittently fail when the subprocess is killed
|
|
|
|
return None
|
|
|
|
print(stdout)
|
|
|
|
print(stderr)
|
|
|
|
pytest.fail(
|
|
|
|
f"{stdout}\n{stderr}\nFailed {name} Example Test Located in {file}",
|
|
|
|
pytrace=False
|
|
|
|
)
|
2015-07-12 20:45:39 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
pytest.cmdline.main()
|