Skip to content

Add test and ensure '_' -> '-' conversion in command assembly #371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2024
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
3 changes: 3 additions & 0 deletions simvue/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ def callback_function(status_code: int, std_out: str, std_err: str) -> None:
for arg, value in kwargs.items():
if arg.startswith("__"):
continue

arg = arg.replace("_", "-")

if len(arg) == 1:
if isinstance(value, bool) and value:
_command += [f"-{arg}"]
Expand Down
46 changes: 46 additions & 0 deletions tests/refactor/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import simvue
import time
import sys
import tempfile
import pathlib
import multiprocessing


Expand Down Expand Up @@ -42,3 +44,47 @@ def test_executor_add_process(
message_contains="successfully" if successful else "non-zero exit",
)
assert len(_events) == 1


@pytest.mark.executor
def test_add_process_command_assembly(request: pytest.FixtureRequest) -> None:
with tempfile.TemporaryDirectory() as tempd:
_python_script="""
import argparse
import os.path

parser = argparse.ArgumentParser()
parser.add_argument('input_file')
parser.add_argument('--output-file')

args=parser.parse_args()

in_text = open(args.input_file).read()

with open(args.output_file, 'w') as out_f:
out_f.write(in_text)
out_f.write('End of Line.')
"""
with (in_file := pathlib.Path(tempd).joinpath("input.txt")).open("w") as out_f:
out_f.write("Flynn has entered the grid.\n")

with (code_file := pathlib.Path(tempd).joinpath("demo.py")).open("w") as out_f:
out_f.write(_python_script)

out_file = pathlib.Path(tempd).joinpath("output.txt")
expected_cmd = f"python {code_file} {in_file} --output-file {out_file}"

with simvue.Run() as run:
run.init(
"test_advanced_executor",
folder="/simvue_unit_testing",
tags=["simvue_client_tests", request.node.name]
)
run.add_process(
identifier=(exe_id := "advanced_run"),
executable="python",
script=f"{code_file}",
input_file=f"{in_file}",
output_file=out_file
)
assert run._executor._command_str[exe_id] == expected_cmd
Loading