2019-11-12 16:45:42 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-06-23 22:24:36 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import tempfile
|
2014-11-27 02:25:17 +00:00
|
|
|
import pyqtgraph as pg
|
2015-07-17 18:49:01 +00:00
|
|
|
import pytest
|
2019-06-23 22:24:36 +00:00
|
|
|
import textwrap
|
|
|
|
import time
|
2014-11-27 02:25:17 +00:00
|
|
|
|
|
|
|
code = """
|
|
|
|
import sys
|
|
|
|
sys.path.insert(0, '{path}')
|
|
|
|
import pyqtgraph as pg
|
|
|
|
app = pg.mkQApp()
|
|
|
|
w = pg.{classname}({args})
|
|
|
|
"""
|
|
|
|
|
2015-07-17 19:51:38 +00:00
|
|
|
skipmessage = ('unclear why this test is failing. skipping until someone has'
|
|
|
|
' time to fix it')
|
2014-11-27 02:25:17 +00:00
|
|
|
|
2019-06-23 22:24:36 +00:00
|
|
|
|
|
|
|
def call_with_timeout(*args, **kwargs):
|
|
|
|
"""Mimic subprocess.call with timeout for python < 3.3"""
|
|
|
|
wait_per_poll = 0.1
|
|
|
|
try:
|
|
|
|
timeout = kwargs.pop('timeout')
|
|
|
|
except KeyError:
|
|
|
|
timeout = 10
|
|
|
|
|
|
|
|
rc = None
|
|
|
|
p = subprocess.Popen(*args, **kwargs)
|
|
|
|
for i in range(int(timeout/wait_per_poll)):
|
|
|
|
rc = p.poll()
|
|
|
|
if rc is not None:
|
|
|
|
break
|
|
|
|
time.sleep(wait_per_poll)
|
|
|
|
return rc
|
|
|
|
|
|
|
|
|
2015-07-17 19:51:38 +00:00
|
|
|
@pytest.mark.skipif(True, reason=skipmessage)
|
2014-11-27 02:25:17 +00:00
|
|
|
def test_exit_crash():
|
2015-07-11 16:20:29 +00:00
|
|
|
# For each Widget subclass, run a simple python script that creates an
|
|
|
|
# instance and then shuts down. The intent is to check for segmentation
|
2014-11-27 02:25:17 +00:00
|
|
|
# faults when each script exits.
|
|
|
|
tmp = tempfile.mktemp(".py")
|
|
|
|
path = os.path.dirname(pg.__file__)
|
|
|
|
|
|
|
|
initArgs = {
|
|
|
|
'CheckTable': "[]",
|
|
|
|
'ProgressDialog': '"msg"',
|
|
|
|
'VerticalLabel': '"msg"',
|
|
|
|
}
|
|
|
|
|
|
|
|
for name in dir(pg):
|
|
|
|
obj = getattr(pg, name)
|
|
|
|
if not isinstance(obj, type) or not issubclass(obj, pg.QtGui.QWidget):
|
|
|
|
continue
|
2015-07-11 16:17:48 +00:00
|
|
|
|
|
|
|
print(name)
|
2014-11-27 02:25:17 +00:00
|
|
|
argstr = initArgs.get(name, "")
|
2019-11-12 16:45:42 +00:00
|
|
|
with open(tmp, 'w') as f:
|
|
|
|
f.write(code.format(path=path, classname=name, args=argstr))
|
2014-11-27 02:25:17 +00:00
|
|
|
proc = subprocess.Popen([sys.executable, tmp])
|
|
|
|
assert proc.wait() == 0
|
|
|
|
|
|
|
|
os.remove(tmp)
|
2019-06-23 22:24:36 +00:00
|
|
|
|
2020-05-30 14:15:46 +00:00
|
|
|
@pytest.mark.skipif(pg.Qt.QtVersion.startswith("5.9"), reason="Functionality not well supported, failing only on this config")
|
2019-06-23 22:24:36 +00:00
|
|
|
def test_pg_exit():
|
|
|
|
# test the pg.exit() function
|
|
|
|
code = textwrap.dedent("""
|
|
|
|
import pyqtgraph as pg
|
|
|
|
app = pg.mkQApp()
|
|
|
|
pg.plot()
|
|
|
|
pg.exit()
|
|
|
|
""")
|
2019-06-24 23:17:48 +00:00
|
|
|
rc = call_with_timeout([sys.executable, '-c', code], timeout=5, shell=False)
|
2019-06-23 22:24:36 +00:00
|
|
|
assert rc == 0
|