Add unit tests for run_subprocess

This commit is contained in:
yuvipanda
2019-05-19 14:24:57 -07:00
parent 7071332445
commit f5ecce77a1
4 changed files with 31 additions and 10 deletions

21
tests/test_utils.py Normal file
View File

@@ -0,0 +1,21 @@
import pytest
from tljh import utils
import subprocess
import logging
def test_run_subprocess_exception(mocker):
logger = logging.getLogger('tljh')
mocker.patch.object(logger, 'error')
with pytest.raises(subprocess.CalledProcessError):
utils.run_subprocess(
['/bin/bash', '-c', 'echo error; exit 1']
)
logger.error.assert_called_with('error\n')
def test_run_subprocess(mocker):
logger = logging.getLogger('tljh')
mocker.patch.object(logger, 'debug')
utils.run_subprocess(['/bin/bash', '-c', 'echo success'])
logger.debug.assert_called_with('success\n')