testprocess: Get executable/args from subclasses.
This commit is contained in:
parent
26596316c6
commit
f858af666f
@ -19,9 +19,6 @@
|
|||||||
|
|
||||||
"""Base class for a subprocess run for tests.."""
|
"""Base class for a subprocess run for tests.."""
|
||||||
|
|
||||||
import sys
|
|
||||||
import os.path
|
|
||||||
|
|
||||||
import pytestqt.plugin # pylint: disable=import-error
|
import pytestqt.plugin # pylint: disable=import-error
|
||||||
from PyQt5.QtCore import pyqtSlot, pyqtSignal, QProcess, QObject
|
from PyQt5.QtCore import pyqtSlot, pyqtSignal, QProcess, QObject
|
||||||
|
|
||||||
@ -43,12 +40,10 @@ class Process(QObject):
|
|||||||
new_data: Emitted when a new line was parsed.
|
new_data: Emitted when a new line was parsed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PROCESS_NAME = None
|
|
||||||
new_data = pyqtSignal(object)
|
new_data = pyqtSignal(object)
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
assert self.PROCESS_NAME is not None
|
|
||||||
self._invalid = False
|
self._invalid = False
|
||||||
self._data = []
|
self._data = []
|
||||||
self.proc = QProcess()
|
self.proc = QProcess()
|
||||||
@ -63,7 +58,7 @@ class Process(QObject):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def _executable_args(self):
|
def _executable_args(self):
|
||||||
"""Get the arguments to pass to the executable."""
|
"""Get the executable and arguments to pass to it as a tuple."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def _get_data(self):
|
def _get_data(self):
|
||||||
@ -107,16 +102,8 @@ class Process(QObject):
|
|||||||
|
|
||||||
def _start(self):
|
def _start(self):
|
||||||
"""Actually start the process."""
|
"""Actually start the process."""
|
||||||
if hasattr(sys, 'frozen'):
|
executable, args = self._executable_args()
|
||||||
executable = os.path.join(os.path.dirname(sys.executable),
|
self.proc.start(executable, args)
|
||||||
self.PROCESS_NAME)
|
|
||||||
args = []
|
|
||||||
else:
|
|
||||||
executable = sys.executable
|
|
||||||
args = [os.path.join(os.path.dirname(__file__),
|
|
||||||
self.PROCESS_NAME + '.py')]
|
|
||||||
|
|
||||||
self.proc.start(executable, args + self._executable_args())
|
|
||||||
ok = self.proc.waitForStarted()
|
ok = self.proc.waitForStarted()
|
||||||
assert ok
|
assert ok
|
||||||
self.proc.readyRead.connect(self.read_log)
|
self.proc.readyRead.connect(self.read_log)
|
||||||
|
@ -23,7 +23,9 @@
|
|||||||
"""Fixtures for the httpbin webserver."""
|
"""Fixtures for the httpbin webserver."""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
import socket
|
import socket
|
||||||
|
import os.path
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -66,8 +68,6 @@ class HTTPBin(testprocess.Process):
|
|||||||
\ (?P<size>[^ ]*)
|
\ (?P<size>[^ ]*)
|
||||||
""", re.VERBOSE)
|
""", re.VERBOSE)
|
||||||
|
|
||||||
PROCESS_NAME = 'webserver_sub'
|
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.port = self._get_port()
|
self.port = self._get_port()
|
||||||
@ -100,7 +100,16 @@ class HTTPBin(testprocess.Process):
|
|||||||
return Request(verb=match.group('verb'), url=match.group('url'))
|
return Request(verb=match.group('verb'), url=match.group('url'))
|
||||||
|
|
||||||
def _executable_args(self):
|
def _executable_args(self):
|
||||||
return [str(self.port)]
|
if hasattr(sys, 'frozen'):
|
||||||
|
executable = os.path.join(os.path.dirname(sys.executable),
|
||||||
|
'webserver_sub')
|
||||||
|
args = [str(self.port)]
|
||||||
|
else:
|
||||||
|
executable = sys.executable
|
||||||
|
py_file = os.path.join(os.path.dirname(__file__),
|
||||||
|
'webserver_sub.py')
|
||||||
|
args = [py_file, str(self.port)]
|
||||||
|
return executable, args
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
"""Clean up and shut down the process."""
|
"""Clean up and shut down the process."""
|
||||||
|
Loading…
Reference in New Issue
Block a user