Skip to content

Commit

Permalink
Fix freedesktop_os_release mock in test_linux_proc_files_with_non_utf…
Browse files Browse the repository at this point in the history
…8_chars

`freedesktop_os_release` must return a dictionary containing at least
`NAME`, `ID`, and `PRETTY_NAME` or raise an `OSError`. Fix the mock in
`test_linux_proc_files_with_non_utf8_chars` to return a minimal
dictionary instead of an empty mock.

Signed-off-by: Benjamin Drung <bdrung@ubuntu.com>
  • Loading branch information
bdrung authored and Megan Wilhite committed Nov 30, 2022
1 parent 6874185 commit a2ec4f0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/pytests/unit/grains/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3298,6 +3298,7 @@ def test_linux_proc_files_with_non_utf8_chars():
_salt_utils_files_fopen = salt.utils.files.fopen

empty_mock = MagicMock(return_value={})
os_release_mock = {"NAME": "Linux", "ID": "linux", "PRETTY_NAME": "Linux"}

with tempfile.TemporaryDirectory() as tempdir:

Expand All @@ -3322,7 +3323,7 @@ def _mock_open(filename, *args, **kwargs):
), patch.object(
core, "_parse_lsb_release", return_value=empty_mock
), patch.object(
core, "_freedesktop_os_release", return_value=empty_mock
core, "_freedesktop_os_release", return_value=os_release_mock
), patch.object(
core, "_hw_data", return_value=empty_mock
), patch.object(
Expand Down

0 comments on commit a2ec4f0

Please sign in to comment.