testprocess: Get executable/args from subclasses.

This commit is contained in:
Florian Bruhin 2015-10-10 18:16:47 +02:00
parent 26596316c6
commit f858af666f
2 changed files with 15 additions and 19 deletions

View File

@ -19,9 +19,6 @@
"""Base class for a subprocess run for tests.."""
import sys
import os.path
import pytestqt.plugin # pylint: disable=import-error
from PyQt5.QtCore import pyqtSlot, pyqtSignal, QProcess, QObject
@ -43,12 +40,10 @@ class Process(QObject):
new_data: Emitted when a new line was parsed.
"""
PROCESS_NAME = None
new_data = pyqtSignal(object)
def __init__(self, parent=None):
super().__init__(parent)
assert self.PROCESS_NAME is not None
self._invalid = False
self._data = []
self.proc = QProcess()
@ -63,7 +58,7 @@ class Process(QObject):
raise NotImplementedError
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
def _get_data(self):
@ -107,16 +102,8 @@ class Process(QObject):
def _start(self):
"""Actually start the process."""
if hasattr(sys, 'frozen'):
executable = os.path.join(os.path.dirname(sys.executable),
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())
executable, args = self._executable_args()
self.proc.start(executable, args)
ok = self.proc.waitForStarted()
assert ok
self.proc.readyRead.connect(self.read_log)

View File

@ -23,7 +23,9 @@
"""Fixtures for the httpbin webserver."""
import re
import sys
import socket
import os.path
import collections
import pytest
@ -66,8 +68,6 @@ class HTTPBin(testprocess.Process):
\ (?P<size>[^ ]*)
""", re.VERBOSE)
PROCESS_NAME = 'webserver_sub'
def __init__(self, parent=None):
super().__init__(parent)
self.port = self._get_port()
@ -100,7 +100,16 @@ class HTTPBin(testprocess.Process):
return Request(verb=match.group('verb'), url=match.group('url'))
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):
"""Clean up and shut down the process."""