import importlib from unittest.mock import Mock subprocess_command = importlib.import_module( "fenrirscreenreader.commands.commands.subprocess" ) def test_external_script_output_is_delivered_by_main_loop_callback(tmp_path): script_path = tmp_path / "helper.sh" script_path.write_text("#!/bin/sh\necho ready\n", encoding="utf-8") script_path.chmod(0o755) task_manager = Mock() task_manager.submit_external_task.return_value = 7 output_manager = Mock() environment = { "runtime": { "BackgroundTaskManager": task_manager, "OutputManager": output_manager, }, "general": {"curr_user": "Username"}, } script_command = subprocess_command.command() script_command.initialize(environment, str(script_path)) script_command.run() output_manager.present_text.assert_not_called() function, callback, path, current_user = ( task_manager.submit_external_task.call_args.args ) assert function is subprocess_command.run_script assert path == str(script_path) assert current_user == "Username" callback( { "task_id": 7, "succeeded": True, "value": {"return_code": 0, "stdout": "ready\n", "stderr": ""}, "error": "", } ) output_manager.present_text.assert_called_once_with( "ready\n", sound_icon="", interrupt=False )