Skip to content

Commit

Permalink
tests: add unit tests for process_run function (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau authored Oct 11, 2024
1 parent 836a4fb commit 5b9dffb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/unit/utils/test_os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import subprocess
import textwrap
from pathlib import Path
from unittest import mock
from unittest.mock import call

import pytest
Expand Down Expand Up @@ -419,3 +420,25 @@ def test_umount_retry_fail(self, mocker):
call(1),
call(1),
]


@pytest.mark.parametrize(
("command", "log_calls"),
[
(["true"], []),
(["echo", "hi"], [mock.call(":: hi")]),
(
["bash", "-c", "echo Line 1; echo Line 2; echo Line 3 >> /dev/stderr"],
[
mock.call(":: Line 1"),
mock.call(":: Line 2"),
mock.call(":: Line 3"),
],
),
],
)
def test_process_run_output_correct(command: list[str], log_calls):
mock_logger = mock.Mock()
os_utils.process_run(command, mock_logger)

assert mock_logger.mock_calls == log_calls

0 comments on commit 5b9dffb

Please sign in to comment.