| 1 |
import importlib |
| 2 |
from unittest.mock import Mock |
| 3 |
|
| 4 |
|
| 5 |
subprocess_command = importlib.import_module( |
| 6 |
"fenrirscreenreader.commands.commands.subprocess" |
| 7 |
) |
| 8 |
|
| 9 |
|
| 10 |
def test_external_script_output_is_delivered_by_main_loop_callback(tmp_path): |
| 11 |
script_path = tmp_path / "helper.sh" |
| 12 |
script_path.write_text("#!/bin/sh\necho ready\n", encoding="utf-8") |
| 13 |
script_path.chmod(0o755) |
| 14 |
task_manager = Mock() |
| 15 |
task_manager.submit_external_task.return_value = 7 |
| 16 |
output_manager = Mock() |
| 17 |
environment = { |
| 18 |
"runtime": { |
| 19 |
"BackgroundTaskManager": task_manager, |
| 20 |
"OutputManager": output_manager, |
| 21 |
}, |
| 22 |
"general": {"curr_user": "Username"}, |
| 23 |
} |
| 24 |
script_command = subprocess_command.command() |
| 25 |
script_command.initialize(environment, str(script_path)) |
| 26 |
|
| 27 |
script_command.run() |
| 28 |
|
| 29 |
output_manager.present_text.assert_not_called() |
| 30 |
function, callback, path, current_user = ( |
| 31 |
task_manager.submit_external_task.call_args.args |
| 32 |
) |
| 33 |
assert function is subprocess_command.run_script |
| 34 |
assert path == str(script_path) |
| 35 |
assert current_user == "Username" |
| 36 |
|
| 37 |
callback( |
| 38 |
{ |
| 39 |
"task_id": 7, |
| 40 |
"succeeded": True, |
| 41 |
"value": {"return_code": 0, "stdout": "ready\n", "stderr": ""}, |
| 42 |
"error": "", |
| 43 |
} |
| 44 |
) |
| 45 |
output_manager.present_text.assert_called_once_with( |
| 46 |
"ready\n", sound_icon="", interrupt=False |
| 47 |
) |