from unittest.mock import Mock import pytest from fenrirscreenreader.commands.commands import subprocess as subprocess_command @pytest.mark.unit def test_script_command_executes_without_shell(monkeypatch): process = Mock() process.returncode = 0 process.communicate.return_value = ("done", "") popen = Mock(return_value=process) monkeypatch.setattr(subprocess_command.subprocess, "Popen", popen) result = subprocess_command.run_script( "/tmp/script with spaces", "Username" ) popen.assert_called_once_with( ["/tmp/script with spaces", "Username"], stdout=subprocess_command.subprocess.PIPE, stderr=subprocess_command.subprocess.PIPE, text=True, ) assert result == {"return_code": 0, "stdout": "done", "stderr": ""}