|
| 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