tests: Allow custom args when starting testprocess.

This commit is contained in:
Florian Bruhin 2016-01-20 06:53:25 +01:00
parent eb276df876
commit ef17c86586
4 changed files with 26 additions and 10 deletions

View File

@ -207,10 +207,11 @@ class QuteProc(testprocess.Process):
else: else:
executable = sys.executable executable = sys.executable
args = ['-m', 'qutebrowser'] args = ['-m', 'qutebrowser']
args += ['--debug', '--no-err-windows', '--temp-basedir',
'about:blank']
return executable, args return executable, args
def _default_args(self):
return ['--debug', '--no-err-windows', '--temp-basedir', 'about:blank']
def path_to_url(self, path, *, port=None, https=False): def path_to_url(self, path, *, port=None, https=False):
"""Get a URL based on a filename for the localhost webserver. """Get a URL based on a filename for the localhost webserver.

View File

@ -73,6 +73,9 @@ class PythonProcess(testprocess.Process):
] ]
return (sys.executable, ['-c', ';'.join(code)]) return (sys.executable, ['-c', ';'.join(code)])
def _default_args(self):
return []
class QuitPythonProcess(testprocess.Process): class QuitPythonProcess(testprocess.Process):
@ -96,6 +99,9 @@ class QuitPythonProcess(testprocess.Process):
] ]
return (sys.executable, ['-c', ';'.join(code)]) return (sys.executable, ['-c', ';'.join(code)])
def _default_args(self):
return []
@pytest.yield_fixture @pytest.yield_fixture
def pyproc(): def pyproc():

View File

@ -159,7 +159,11 @@ class Process(QObject):
raise NotImplementedError raise NotImplementedError
def _executable_args(self): def _executable_args(self):
"""Get the executable and arguments to pass to it as a tuple.""" """Get the executable and necessary arguments as a tuple."""
raise NotImplementedError
def _default_args(self):
"""Get the default arguments to use if none were passed to start()."""
raise NotImplementedError raise NotImplementedError
def _get_data(self): def _get_data(self):
@ -208,16 +212,18 @@ class Process(QObject):
self._data.append(parsed) self._data.append(parsed)
self.new_data.emit(parsed) self.new_data.emit(parsed)
def start(self): def start(self, args=None):
"""Start the process and wait until it started.""" """Start the process and wait until it started."""
with self._wait_signal(self.ready, timeout=60000): with self._wait_signal(self.ready, timeout=60000):
self._start() self._start(args)
def _start(self): def _start(self, args):
"""Actually start the process.""" """Actually start the process."""
executable, args = self._executable_args() executable, exec_args = self._executable_args()
if args is None:
args = self._default_args()
self.proc.readyRead.connect(self.read_log) self.proc.readyRead.connect(self.read_log)
self.proc.start(executable, args) self.proc.start(executable, exec_args + args)
ok = self.proc.waitForStarted() ok = self.proc.waitForStarted()
assert ok assert ok
assert self.is_running() assert self.is_running()

View File

@ -154,14 +154,17 @@ class WebserverProcess(testprocess.Process):
if hasattr(sys, 'frozen'): if hasattr(sys, 'frozen'):
executable = os.path.join(os.path.dirname(sys.executable), executable = os.path.join(os.path.dirname(sys.executable),
self._script) self._script)
args = [str(self.port)] args = []
else: else:
executable = sys.executable executable = sys.executable
py_file = os.path.join(os.path.dirname(__file__), py_file = os.path.join(os.path.dirname(__file__),
self._script + '.py') self._script + '.py')
args = [py_file, str(self.port)] args = [py_file]
return executable, args return executable, args
def _default_args(self):
return [str(self.port)]
def cleanup(self): def cleanup(self):
"""Clean up and shut down the process.""" """Clean up and shut down the process."""
self.proc.terminate() self.proc.terminate()