|
2 | 2 | import simvue
|
3 | 3 | import time
|
4 | 4 | import sys
|
| 5 | +import tempfile |
| 6 | +import pathlib |
5 | 7 | import multiprocessing
|
6 | 8 |
|
7 | 9 |
|
@@ -42,3 +44,47 @@ def test_executor_add_process(
|
42 | 44 | message_contains="successfully" if successful else "non-zero exit",
|
43 | 45 | )
|
44 | 46 | 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