from __future__ import print_function, division, absolute_import
from pyqtgraph import Qt
from . import utils
import itertools
import pytest

# 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

files = utils.buildFileList(utils.examples)
frontends = {Qt.PYQT4: False, Qt.PYSIDE: False}
# 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


@pytest.mark.parametrize(
    "frontend, f", itertools.product(sorted(list(frontends.keys())), files))
def test_examples(frontend, f):
    # Test the examples with all available front-ends
    print('frontend = %s. f = %s' % (frontend, f))
    if not frontends[frontend]:
        pytest.skip('%s is not installed. Skipping tests' % frontend)
    utils.testFile(f[0], f[1], utils.sys.executable, frontend)

if __name__ == "__main__":
    pytest.cmdline.main()

@@ -134,16 +134,695 @@
  pytest%0A
+import os%0Aimport __builtin__%0A%0A%0A# printing on travis ci frequently leads to %22interrupted system call%22 errors.%0A# as a workaround, we overwrite the built-in print function (bleh)%0Aif os.getenv('TRAVIS') is not None:%0A    def flaky_print(*args):%0A        %22%22%22Wrapper for print that retries in case of IOError.%0A        %22%22%22%0A        count = 0%0A        while count %3C 5:%0A            count += 1%0A            try:%0A                orig_print(*args)%0A                break%0A            except IOError:%0A                if count %3E= 5:%0A                    raise%0A                pass%0A    orig_print = __builtin__.print%0A    __builtin__.print = flaky_print%0A    print(%22Installed wrapper for flaky print.%22)%0A%0A
 %0A# appar

Add print wrapper to work around interrupted system calls on travis