Fix the tests

This commit is contained in:
Victor Zhestkov 2022-09-08 10:40:47 +03:00 committed by Megan Wilhite
parent d9c666a4d2
commit 0b43ffecbc

View file

@ -2762,9 +2762,12 @@ def test_kernelparams_return_linux(cmdline, expectation):
assert core.kernelparams() == expectation
@pytest.mark.skip_unless_on_linux
def test_kernelparams_return_linux_non_utf8():
_salt_utils_files_fopen = salt.utils.files.fopen
def _open_mock(file_name, *args, **kwargs):
return open(
return _salt_utils_files_fopen(
pathlib.Path(__file__).parent.joinpath("proc-files").joinpath("cmdline"),
*args,
**kwargs
@ -3039,8 +3042,10 @@ def test_linux_devicetree_data(test_input, expected):
@pytest.mark.skip_on_windows
def test_linux_proc_files_with_non_utf8_chars():
_salt_utils_files_fopen = salt.utils.files.fopen
def _mock_open(filename, *args, **kwargs):
return open(
return _salt_utils_files_fopen(
pathlib.Path(__file__).parent.joinpath("proc-files").joinpath("cmdline-1"),
*args,
**kwargs
@ -3054,6 +3059,7 @@ def test_linux_proc_files_with_non_utf8_chars():
core.__salt__,
{
"cmd.retcode": salt.modules.cmdmod.retcode,
"cmd.run": MagicMock(return_value=""),
},
), patch.object(
core, "_linux_bin_exists", return_value=False
@ -3065,6 +3071,8 @@ def test_linux_proc_files_with_non_utf8_chars():
core, "_hw_data", return_value=empty_mock
), patch.object(
core, "_virtual", return_value=empty_mock
), patch.object(
core, "_bsd_cpudata", return_value=empty_mock
), patch.object(
os, "stat", side_effect=OSError()
):
@ -3074,18 +3082,20 @@ def test_linux_proc_files_with_non_utf8_chars():
@pytest.mark.skip_on_windows
def test_virtual_linux_proc_files_with_non_utf8_chars():
def _is_file_mock(filename):
if filename == "/proc/1/environ":
return True
return False
_salt_utils_files_fopen = salt.utils.files.fopen
def _mock_open(filename, *args, **kwargs):
return open(
return _salt_utils_files_fopen(
pathlib.Path(__file__).parent.joinpath("proc-files").joinpath("environ"),
*args,
**kwargs
)
def _is_file_mock(filename):
if filename == "/proc/1/environ":
return True
return False
with patch("os.path.isfile", _is_file_mock), patch(
"salt.utils.files.fopen", _mock_open
), patch.object(salt.utils.path, "which", MagicMock(return_value=None)), patch.dict(