Skip to content

Commit 7ec1a96

Browse files
authored
Merge pull request #371 from simvue-io/hotfix/handle-underscored-process-args
Add test and ensure '_' -> '-' conversion in command assembly
2 parents 097e886 + e327b2e commit 7ec1a96

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

simvue/executor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ def callback_function(status_code: int, std_out: str, std_err: str) -> None:
189189
for arg, value in kwargs.items():
190190
if arg.startswith("__"):
191191
continue
192+
193+
arg = arg.replace("_", "-")
194+
192195
if len(arg) == 1:
193196
if isinstance(value, bool) and value:
194197
_command += [f"-{arg}"]

tests/refactor/test_executor.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import simvue
33
import time
44
import sys
5+
import tempfile
6+
import pathlib
57
import multiprocessing
68

79

@@ -42,3 +44,47 @@ def test_executor_add_process(
4244
message_contains="successfully" if successful else "non-zero exit",
4345
)
4446
assert len(_events) == 1
47+
48+
49+
@pytest.mark.executor
50+
def test_add_process_command_assembly(request: pytest.FixtureRequest) -> None:
51+
with tempfile.TemporaryDirectory() as tempd:
52+
_python_script="""
53+
import argparse
54+
import os.path
55+
56+
parser = argparse.ArgumentParser()
57+
parser.add_argument('input_file')
58+
parser.add_argument('--output-file')
59+
60+
args=parser.parse_args()
61+
62+
in_text = open(args.input_file).read()
63+
64+
with open(args.output_file, 'w') as out_f:
65+
out_f.write(in_text)
66+
out_f.write('End of Line.')
67+
"""
68+
with (in_file := pathlib.Path(tempd).joinpath("input.txt")).open("w") as out_f:
69+
out_f.write("Flynn has entered the grid.\n")
70+
71+
with (code_file := pathlib.Path(tempd).joinpath("demo.py")).open("w") as out_f:
72+
out_f.write(_python_script)
73+
74+
out_file = pathlib.Path(tempd).joinpath("output.txt")
75+
expected_cmd = f"python {code_file} {in_file} --output-file {out_file}"
76+
77+
with simvue.Run() as run:
78+
run.init(
79+
"test_advanced_executor",
80+
folder="/simvue_unit_testing",
81+
tags=["simvue_client_tests", request.node.name]
82+
)
83+
run.add_process(
84+
identifier=(exe_id := "advanced_run"),
85+
executable="python",
86+
script=f"{code_file}",
87+
input_file=f"{in_file}",
88+
output_file=out_file
89+
)
90+
assert run._executor._command_str[exe_id] == expected_cmd

0 commit comments

Comments
 (0)