2015-07-12 17:19:18 +00:00
|
|
|
from __future__ import print_function, division, absolute_import
|
|
|
|
from pyqtgraph import Qt
|
2015-08-02 20:46:41 +00:00
|
|
|
from . import utils
|
2015-07-12 20:45:39 +00:00
|
|
|
import itertools
|
|
|
|
import pytest
|
2016-12-14 18:14:11 +00:00
|
|
|
import os, sys
|
2016-12-14 18:07:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
# printing on travis ci frequently leads to "interrupted system call" errors.
|
|
|
|
# as a workaround, we overwrite the built-in print function (bleh)
|
|
|
|
if os.getenv('TRAVIS') is not None:
|
2016-12-14 18:14:11 +00:00
|
|
|
if sys.version_info[0] < 3:
|
|
|
|
import __builtin__ as builtins
|
|
|
|
else:
|
|
|
|
import builtins
|
|
|
|
|
2016-12-14 18:07:16 +00:00
|
|
|
def flaky_print(*args):
|
|
|
|
"""Wrapper for print that retries in case of IOError.
|
|
|
|
"""
|
|
|
|
count = 0
|
|
|
|
while count < 5:
|
|
|
|
count += 1
|
|
|
|
try:
|
|
|
|
orig_print(*args)
|
|
|
|
break
|
|
|
|
except IOError:
|
|
|
|
if count >= 5:
|
|
|
|
raise
|
|
|
|
pass
|
2016-12-14 18:19:01 +00:00
|
|
|
orig_print = builtins.print
|
2016-12-14 18:14:11 +00:00
|
|
|
builtins.print = flaky_print
|
2016-12-14 18:07:16 +00:00
|
|
|
print("Installed wrapper for flaky print.")
|
|
|
|
|
2015-07-12 17:19:18 +00:00
|
|
|
|
2015-08-02 20:46:41 +00:00
|
|
|
# apparently importlib does not exist in python 2.6...
|
|
|
|
try:
|
|
|
|
import importlib
|
|
|
|
except ImportError:
|
|
|
|
# we are on python 2.6
|
|
|
|
print("If you want to test the examples, please install importlib from "
|
|
|
|
"pypi\n\npip install importlib\n\n")
|
|
|
|
pass
|
2015-07-12 17:19:18 +00:00
|
|
|
|
2015-08-02 20:46:41 +00:00
|
|
|
files = utils.buildFileList(utils.examples)
|
2019-05-28 04:07:25 +00:00
|
|
|
frontends = {Qt.PYQT4: False, Qt.PYQT5: False, Qt.PYSIDE: False, Qt.PYSIDE2: False}
|
2015-07-12 20:45:39 +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
|
2015-07-12 17:19:18 +00:00
|
|
|
|
2015-07-18 13:38:34 +00:00
|
|
|
|
2015-07-12 20:45:39 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"frontend, f", itertools.product(sorted(list(frontends.keys())), files))
|
|
|
|
def test_examples(frontend, f):
|
2015-07-18 13:38:34 +00:00
|
|
|
# Test the examples with all available front-ends
|
2015-07-12 20:45:39 +00:00
|
|
|
print('frontend = %s. f = %s' % (frontend, f))
|
|
|
|
if not frontends[frontend]:
|
2015-08-02 21:18:38 +00:00
|
|
|
pytest.skip('%s is not installed. Skipping tests' % frontend)
|
2015-07-12 20:45:39 +00:00
|
|
|
utils.testFile(f[0], f[1], utils.sys.executable, frontend)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
pytest.cmdline.main()
|