|
| 1 | +import os |
| 2 | +import shlex |
| 3 | +import subprocess |
1 | 4 | from pathlib import Path |
2 | 5 | from unittest.mock import patch |
3 | | - |
4 | 6 | import pytest |
5 | | - |
6 | | -import os |
7 | | -import subprocess |
8 | 7 | from PyStemmusScope import StemmusScope |
9 | 8 | from PyStemmusScope import config_io |
| 9 | +from PyStemmusScope import utils |
10 | 10 | from . import data_folder |
11 | 11 |
|
12 | 12 |
|
@@ -200,11 +200,14 @@ def test_run_matlab(self, mocked_popen, model_with_setup, tmp_path): |
200 | 200 | result = model.run() |
201 | 201 |
|
202 | 202 | path_to_config = f"'{actual_cfg_file}'" |
203 | | - command_line = f'matlab -r "STEMMUS_SCOPE_exe({path_to_config});exit;"' |
204 | | - expected = [command_line, "-nodisplay", "-nosplash", "-nodesktop"] |
| 203 | + eval_code= f'STEMMUS_SCOPE_exe({path_to_config});exit;' |
| 204 | + args = ["matlab", "-r", eval_code, "-nodisplay", "-nosplash", "-nodesktop"] |
| 205 | + # seperate args dont work on linux! |
| 206 | + if utils.os_name() !="nt": |
| 207 | + args = shlex.join(args) |
205 | 208 |
|
206 | 209 | mocked_popen.assert_called_with( |
207 | | - expected, cwd=tmp_path, |
| 210 | + args, cwd=tmp_path, |
208 | 211 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
209 | 212 | shell=True, |
210 | 213 | ) |
@@ -248,11 +251,16 @@ def test_run_matlab(self, mocked_popen, model_with_setup, tmp_path): |
248 | 251 | result = model.run() |
249 | 252 |
|
250 | 253 | path_to_config = f"'{actual_cfg_file}'" |
251 | | - command_line = f'octave --eval "STEMMUS_SCOPE_exe({path_to_config});exit;"' |
252 | | - expected = [command_line, "--no-gui", "--silent"] |
| 254 | + # fix for windows |
| 255 | + path_to_config = path_to_config.replace("\\", "/") |
| 256 | + eval_code = f'STEMMUS_SCOPE_exe({path_to_config});exit;' |
| 257 | + args = ["octave", "--eval", eval_code, "--no-gui", "--silent"] |
| 258 | + # seperate args dont work on linux! |
| 259 | + if utils.os_name() !="nt": |
| 260 | + args = shlex.join(args) |
253 | 261 |
|
254 | 262 | mocked_popen.assert_called_with( |
255 | | - expected, cwd=tmp_path, |
| 263 | + args, cwd=tmp_path, |
256 | 264 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
257 | 265 | shell=True, |
258 | 266 | ) |
|
0 commit comments