Skip to content

Commit 4468f2e

Browse files
committed
test(utils/run_cmd): add initial test
1 parent d90ab05 commit 4468f2e

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/unit/test_exec.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import subprocess
2+
from unittest.mock import patch
3+
4+
from debmagic import _utils
5+
6+
7+
@patch("subprocess.run", autospec=True)
8+
def test_util_exec_str(mock_run):
9+
mock_run.return_value = subprocess.CompletedProcess(["some", "command"], returncode=0)
10+
_utils.run_cmd("some command")
11+
mock_run.assert_called_once_with(["some", "command"], check=True)
12+
13+
14+
@patch("subprocess.run", autospec=True)
15+
def test_util_exec_list(mock_run):
16+
mock_run.return_value = subprocess.CompletedProcess(["some", "command"], returncode=0)
17+
_utils.run_cmd(["some", "command"])
18+
mock_run.assert_called_once_with(["some", "command"], check=True)
19+
20+
21+
@patch("subprocess.run", autospec=True)
22+
def test_util_exec_str_dryrun(mock_run):
23+
_utils.run_cmd("some command", dry_run=True)
24+
mock_run.assert_not_called()
25+
26+
27+
@patch("subprocess.run", autospec=True)
28+
def test_util_exec_str_shlex(mock_run):
29+
mock_run.return_value = subprocess.CompletedProcess(["nothing"], returncode=0)
30+
_utils.run_cmd("some command 'some arg'")
31+
mock_run.assert_called_once_with(["some", "command", "some arg"], check=True)
32+
33+
34+
@patch("subprocess.run", autospec=True)
35+
def test_util_exec_str_check(mock_run):
36+
mock_run.return_value = subprocess.CompletedProcess(["something"], returncode=0)
37+
_utils.run_cmd("something", check=True)
38+
mock_run.assert_called_once_with(["something"], check=True)
39+
40+
41+
@patch("subprocess.run", autospec=True)
42+
def test_util_exec_str_nocheck(mock_run):
43+
mock_run.return_value = subprocess.CompletedProcess(["something"], returncode=0)
44+
_utils.run_cmd("something", check=False)
45+
mock_run.assert_called_once_with(["something"], check=False)

0 commit comments

Comments
 (0)