Skip to content

Commit 9770a44

Browse files
committed
Merge branch 'hotfixes' into dev
2 parents 836d829 + 2d1b505 commit 9770a44

1 file changed

Lines changed: 34 additions & 14 deletions

File tree

tests/functional/test_run_execute_process.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import filecmp
99

1010
from simvue import Run, Client
11+
from simvue.executor import get_current_shell
1112
from simvue.sender import sender
1213

1314
@pytest.mark.executor
@@ -16,32 +17,51 @@ def test_monitor_processes(create_plain_run_offline: tuple[Run, dict]):
1617
_run: Run
1718
_run, _ = create_plain_run_offline
1819

19-
if any(shell in os.environ.get("SHELL", "") for shell in ("zsh", "bash")) or sys.platform != "win32":
20+
if any(shell in os.environ.get("SHELL", "") for shell in ("zsh", "bash")):
2021
_run.add_process(f"process_1_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", "Hello world!", executable="echo", n=True)
2122
_run.add_process(f"process_2_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", "bash", debug=True, c="exit 0")
2223
_run.add_process(f"process_3_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", "ls", "-ltr")
2324
else:
24-
_run.add_process(f"process_1_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", "Hello World!", executable="Write-Output")
25-
_run.add_process(f"process_2_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", executable="Get-ChildItem")
26-
_run.add_process(f"process_3_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", "exit 0")
25+
_run.add_process(f"process_1_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", Command="Write-Output 'Hello World!'", executable="powershell")
26+
_run.add_process(f"process_2_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", Command="Get-ChildItem", executable="powershell")
27+
_run.add_process(f"process_3_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", Command="exit 0", executable="powershell")
2728
sender(_run._sv_obj._local_staging_file.parents[1], 1, 10, ["folders", "runs", "alerts"])
2829

2930

3031
@pytest.mark.executor
3132
def test_abort_all_processes(create_plain_run: tuple[Run, dict]) -> None:
3233
_run, _ = create_plain_run
33-
with tempfile.NamedTemporaryFile(delete=False, suffix=".sh") as temp_f:
34+
_pwsh = any(shell in os.environ.get("SHELL", get_current_shell()) for shell in ("pwsh", "powershell"))
35+
36+
_arguments = dict(
37+
extension=".sh" if not _pwsh else ".ps1",
38+
lines=[
39+
"echo 'Using Bash...'\n",
40+
"for i in {0..20}; do\n",
41+
" echo $i\n",
42+
" sleep 1\n",
43+
"done\n"
44+
] if not _pwsh else [
45+
"Write-Output 'Using Powershell...'\n",
46+
"for ($i = 0; $i -le 20; $i++) {\n",
47+
" Write-Output $i\n",
48+
"}\n"
49+
],
50+
executable="powershell" if _pwsh else "bash"
51+
)
52+
with tempfile.NamedTemporaryFile(delete=False, suffix=_arguments["extension"]) as temp_f:
3453
with open(temp_f.name, "w") as out_f:
35-
out_f.writelines([
36-
"for i in {0..20}; do\n",
37-
" echo $i\n",
38-
" sleep 1\n",
39-
"done\n"
40-
])
54+
out_f.writelines(_arguments["lines"])
4155

4256
for i in range(1, 3):
43-
_run.add_process(f"process_{i}_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", executable="bash", script=temp_f.name)
44-
assert _run.executor.get_command(f"process_{i}_{os.environ.get('PYTEST_XDIST_WORKER', 0)}") == f"bash {temp_f.name}"
57+
_run.add_process(
58+
f"process_{i}_{os.environ.get('PYTEST_XDIST_WORKER', 0)}",
59+
executable=_arguments["executable"],
60+
script=temp_f.name
61+
)
62+
assert _run.executor.get_command(
63+
f"process_{i}_{os.environ.get('PYTEST_XDIST_WORKER', 0)}"
64+
) == f"{_arguments['executable']} {temp_f.name}"
4565

4666

4767
time.sleep(3)
@@ -70,7 +90,7 @@ def test_abort_all_processes(create_plain_run: tuple[Run, dict]) -> None:
7090
_out_files = pathlib.Path.cwd().glob(f"*process_*_{os.environ.get('PYTEST_XDIST_WORKER', 0)}.out")
7191
for file in _out_files:
7292
with file.open() as in_f:
73-
assert (lines := in_f.readlines())
93+
assert (lines := in_f.readlines()[1:])
7494
assert int(lines[0].strip()) < 4
7595
with contextlib.suppress(FileNotFoundError):
7696
os.unlink(temp_f.name)

0 commit comments

Comments
 (0)