14
14
from tempfile import NamedTemporaryFile
15
15
16
16
TEST_MESSAGE = "Hello Mantid!"
17
- EXECUTABLE_SWITCHER = {"linux" : ["launch_mantidworkbench.sh" , "mantidworkbench" ], "darwin" : ["workbench" ], "win32" : ["workbench.exe" ]}
17
+ EXECUTABLE_SWITCHER = {
18
+ "linux" : ["launch_mantidworkbench.sh" , "workbench" ],
19
+ "darwin" : ["workbench" ],
20
+ "win32" : ["workbench" ],
21
+ }
18
22
SUBPROCESS_TIMEOUT_SECS = 300
19
23
20
24
@@ -25,15 +29,6 @@ def get_mantid_executables_for_platform(platform):
25
29
return workbench_executables
26
30
27
31
28
- def get_mantid_executable_path (platform ):
29
- directory = ConfigService .getPropertiesDir ().replace ("\\ " , "/" )
30
- for executable in get_mantid_executables_for_platform (platform ):
31
- workbench_exe = os .path .join (directory , executable )
32
- if os .path .exists (workbench_exe ):
33
- return workbench_exe
34
- raise RuntimeError (f"Could not find path to { workbench_exe } . Tried { get_mantid_executables_for_platform (platform )} " )
35
-
36
-
37
32
def start_and_wait_for_completion (args_list ):
38
33
pids_before_open = set (psutil .pids ())
39
34
process = subprocess .Popen (args_list , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
@@ -78,18 +73,21 @@ def __init__(self):
78
73
79
74
self ._test_file = NamedTemporaryFile (suffix = ".txt" , delete = False ).name .replace ("\\ " , "/" )
80
75
self ._test_script = NamedTemporaryFile (suffix = ".py" , delete = False ).name .replace ("\\ " , "/" )
81
- self ._executable = get_mantid_executable_path (sys .platform )
76
+ self ._executables = get_mantid_executables_for_platform (sys .platform )
82
77
write_test_script (self ._test_script , self ._test_file )
83
78
84
79
def runTest (self ):
85
- exitcode = start_and_wait_for_completion ([self ._executable , "--execute" , self ._test_script , "--quit" ])
86
-
87
- # Was the process successful
88
- self .assertEqual (0 , exitcode )
89
- # Assert that the test script runs successfully by writing to a .txt file
90
- with open (self ._test_file , "r" ) as file :
91
- self .assertEqual (TEST_MESSAGE , file .readline ())
80
+ directory = ConfigService .getPropertiesDir ().replace ("\\ " , "/" )
81
+ for executable in self ._executables :
82
+ file_path = os .path .join (directory , executable )
83
+ executable = file_path if os .path .exists (file_path ) else executable
84
+ exitcode = start_and_wait_for_completion ([executable , "--execute" , self ._test_script , "--quit" ])
85
+ # Was the process successful
86
+ self .assertEqual (0 , exitcode )
87
+ # Assert that the test script runs successfully by writing to a .txt file
88
+ with open (self ._test_file , "r" ) as file :
89
+ self .assertEqual (TEST_MESSAGE , file .readline ())
90
+ remove_file (self ._test_file )
92
91
93
92
def cleanup (self ):
94
93
remove_file (self ._test_script )
95
- remove_file (self ._test_file )
0 commit comments