Debian Codegraph @

tests/unit/test_subprocess_command.py

raw
1 from unittest.mock import Mock
2
3 import pytest
4
5 from fenrirscreenreader.commands.commands import subprocess as subprocess_command
6
7
8 @pytest.mark.unit
9 def test_script_command_executes_without_shell(monkeypatch):
10 process = Mock()
11 process.returncode = 0
12 process.communicate.return_value = ("done", "")
13 popen = Mock(return_value=process)
14 monkeypatch.setattr(subprocess_command.subprocess, "Popen", popen)
15
16 result = subprocess_command.run_script(
17 "/tmp/script with spaces", "Username"
18 )
19
20 popen.assert_called_once_with(
21 ["/tmp/script with spaces", "Username"],
22 stdout=subprocess_command.subprocess.PIPE,
23 stderr=subprocess_command.subprocess.PIPE,
24 text=True,
25 )
26 assert result == {"return_code": 0, "stdout": "done", "stderr": ""}