From f858af666f03d1e9d742eac284ac58d0b8002212 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 10 Oct 2015 18:16:47 +0200 Subject: [PATCH] testprocess: Get executable/args from subclasses. --- tests/integration/testprocess.py | 19 +++---------------- tests/integration/webserver.py | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/tests/integration/testprocess.py b/tests/integration/testprocess.py index a2edc0cb7..21a610fd6 100644 --- a/tests/integration/testprocess.py +++ b/tests/integration/testprocess.py @@ -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) diff --git a/tests/integration/webserver.py b/tests/integration/webserver.py index 59c659ac6..d1de1516f 100644 --- a/tests/integration/webserver.py +++ b/tests/integration/webserver.py @@ -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[^ ]*) """, 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."""