Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 12 additions & 33 deletions Testing/SystemTests/tests/qt/WorkbenchStartupTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,14 @@
# SPDX - License - Identifier: GPL - 3.0 +
import os
import subprocess
import sys
import systemtesting

from mantid.kernel import ConfigService
from tempfile import NamedTemporaryFile

TEST_MESSAGE = "Hello Mantid!"
EXECUTABLE_SWITCHER = {
"linux": ["launch_mantidworkbench.sh", "workbench"],
"darwin": ["workbench"],
"win32": ["workbench"],
}
SUBPROCESS_TIMEOUT_SECS = 300


def get_mantid_executables_for_platform(platform):
workbench_executables = EXECUTABLE_SWITCHER.get(platform, None)
if workbench_executables is None:
raise RuntimeError(f"Unknown platform {platform}.")
return workbench_executables


def start_and_wait_for_completion(args_list):
process = subprocess.Popen(args_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
exitcode = process.wait(timeout=SUBPROCESS_TIMEOUT_SECS)
Expand Down Expand Up @@ -58,28 +44,21 @@ def __init__(self):

self._test_file = NamedTemporaryFile(suffix=".txt", delete=False).name.replace("\\", "/")
self._test_script = NamedTemporaryFile(suffix=".py", delete=False).name.replace("\\", "/")
self._executables = get_mantid_executables_for_platform(sys.platform)
write_test_script(self._test_script, self._test_file)

def runTest(self):
directory = ConfigService.getPropertiesDir().replace("\\", "/")
for executable in self._executables:
file_path = os.path.join(directory, executable)
executable, module = (file_path, False) if os.path.exists(file_path) else (executable, True)
arg_list = [executable, "--execute", self._test_script, "--quit"]
if module:
arg_list = ["python", "-m"] + arg_list

exitcode, stderr = start_and_wait_for_completion(arg_list)
# Was the process successful
self.assertEqual(0, exitcode)
# Check for no warnings or errors on startup
error_warning_lines = [line for line in stderr.split("\n") if "[Error]" in line or "[Warning]" in line]
self.assertEqual([], error_warning_lines, f"stderr was warning / error output: {error_warning_lines}")
# Assert that the test script runs successfully by writing to a .txt file
with open(self._test_file, "r") as file:
self.assertEqual(TEST_MESSAGE, file.readline())
remove_file(self._test_file)
arg_list = ["python", "-m", "workbench", "--execute", self._test_script, "--quit"]

exitcode, stderr = start_and_wait_for_completion(arg_list)
# Check for no warnings or errors on startup
error_warning_lines = [line for line in stderr.split("\n") if "[Error]" in line or "[Warning]" in line]
self.assertEqual([], error_warning_lines, f"stderr was warning / error output: {error_warning_lines}")
# Assert that the test script runs successfully by writing to a .txt file
with open(self._test_file, "r") as file:
self.assertEqual(TEST_MESSAGE, file.readline())
remove_file(self._test_file)
# Was the process successful
self.assertEqual(0, exitcode)

def cleanup(self):
remove_file(self._test_script)
2 changes: 1 addition & 1 deletion qt/applications/workbench/workbench/app/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def start(options: argparse.ArgumentParser):
# this is already the default on Windows/macOS.
# This will mean the relevant 'atexit' code will execute in the child process, and therefore the
# FrameworkManager and UsageService will be shutdown as expected.
launch_command = f"python {wp.__file__}"
launch_command = f"{sys.executable} {wp.__file__}"
if options.script:
launch_command += f" {options.script}"
if options.execute:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def retrieve_thread_traces_from_coredump_file(workbench_pid: str) -> bytes:
try:
core_dumps_path = _get_core_dumps_dir()
except ValueError as e:
log.error(str(e))
log.warning(str(e))
return b""

# Get most recent dump file.
Expand Down