Files
freeipa/ipatests/test_ipalib/test_util.py
T
Oleg Kozlov a0e09526b3 Check pager's executable before subprocess.Popen
Get the value of `PAGER` environment variable in case it's defined, check the executable, if it exists - use a pager, otherwise - print function.

Fixes: https://pagure.io/freeipa/issue/7746
Reviewed-By: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
2018-12-07 14:06:29 +01:00

26 lines
586 B
Python

#
# Copyright (C) 2018 FreeIPA Contributors see COPYING for license
#
"""Tests for ipalib.util module
"""
import os
from unittest import mock
import pytest
from ipalib.util import get_pager
@pytest.mark.parametrize('pager,expected_result', [
# Valid values
('cat', '/usr/bin/cat'),
('/usr/bin/cat', '/usr/bin/cat'),
# Invalid values (wrong command, package is not installed, etc)
('cat_', None),
('', None)
])
def test_get_pager(pager, expected_result):
with mock.patch.dict(os.environ, {'PAGER': pager}):
assert get_pager() == expected_result