Add test for exit function

This commit is contained in:
Kenneth Lyons 2019-06-23 15:24:36 -07:00
parent 563083cf86
commit c210795cac

View File

@ -1,7 +1,12 @@
import os, sys, subprocess, tempfile import os
import sys
import subprocess
import tempfile
import pyqtgraph as pg import pyqtgraph as pg
import six import six
import pytest import pytest
import textwrap
import time
code = """ code = """
import sys import sys
@ -14,6 +19,25 @@ w = pg.{classname}({args})
skipmessage = ('unclear why this test is failing. skipping until someone has' skipmessage = ('unclear why this test is failing. skipping until someone has'
' time to fix it') ' time to fix it')
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
@pytest.mark.skipif(True, reason=skipmessage) @pytest.mark.skipif(True, reason=skipmessage)
def test_exit_crash(): def test_exit_crash():
# For each Widget subclass, run a simple python script that creates an # For each Widget subclass, run a simple python script that creates an
@ -40,3 +64,15 @@ def test_exit_crash():
assert proc.wait() == 0 assert proc.wait() == 0
os.remove(tmp) os.remove(tmp)
def test_pg_exit():
# test the pg.exit() function
code = textwrap.dedent("""
import pyqtgraph as pg
app = pg.mkQApp()
pg.plot()
pg.exit()
""")
rc = call_with_timeout([sys.executable, '-c', code], timeout=5)
assert rc == 0