From 60ae12fedeaf07d81efd87309917691a98592648 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Thu, 11 Apr 2024 11:06:45 +0100 Subject: [PATCH] The test us a unit test, not functional. No need for the test yaml file either. --- tests/pytests/functional/modules/test_yaml.py | 74 ----------------- .../pytests/functional/modules/testyaml.yaml | 2 - tests/pytests/unit/modules/test_yaml.py | 79 +++++++++++++++++++ 3 files changed, 79 insertions(+), 76 deletions(-) delete mode 100644 tests/pytests/functional/modules/test_yaml.py delete mode 100644 tests/pytests/functional/modules/testyaml.yaml create mode 100644 tests/pytests/unit/modules/test_yaml.py diff --git a/tests/pytests/functional/modules/test_yaml.py b/tests/pytests/functional/modules/test_yaml.py deleted file mode 100644 index 2a8fbc113ff..00000000000 --- a/tests/pytests/functional/modules/test_yaml.py +++ /dev/null @@ -1,74 +0,0 @@ -from pathlib import Path - -import pytest - -import salt.loader -import salt.modules.config -import salt.modules.cp -import salt.modules.slsutil -import salt.utils.files -from tests.support.mock import MagicMock - -try: - import salt.modules.yaml - import salt.utils.yamllint - - YAMLLINT_AVAILABLE = True -except ImportError: - YAMLLINT_AVAILABLE = False - - -pytestmark = [ - pytest.mark.skipif( - YAMLLINT_AVAILABLE is False, reason="The 'yammllint' pacakge is not available" - ), -] - - -@pytest.fixture -def configure_loader_modules(minion_opts): - cached_file = str(Path(__file__).parent / "testyaml.yaml") - return { - salt.modules.yaml: { - "__salt__": { - "config.get": salt.modules.config.get, - "cp.cache_file": MagicMock( - salt.modules.cp.cache_file, autospec=True, return_value=cached_file - ), - "slsutil.renderer": MagicMock( - salt.modules.slsutil.renderer, - autospec=True, - return_value="key: value\n", - ), - }, - "__opts__": minion_opts, - "__utils__": { - "files.fopen": salt.utils.files.fopen, - "yamllint.lint": salt.utils.yamllint.lint, - }, - }, - salt.modules.config: { - "__opts__": minion_opts, - }, - } - - -def test_lint_yaml(): - """ - ensure that we can lint from the yaml lint utils - """ - assert salt.modules.yaml.lint("salt://test/test.sls") == { - "problems": [], - "source": "key:\n value\n", - } - - -def test_lint_pre_render(): - assert salt.modules.yaml.lint("salt://test.test.sls", pre_render="jinja") == { - "problems": [], - "source": "key: value\n", - } - - -def test_yamllint_virtual(): - assert salt.modules.yaml.__virtual__() == "yaml" diff --git a/tests/pytests/functional/modules/testyaml.yaml b/tests/pytests/functional/modules/testyaml.yaml deleted file mode 100644 index 2ac4cd4399c..00000000000 --- a/tests/pytests/functional/modules/testyaml.yaml +++ /dev/null @@ -1,2 +0,0 @@ -key: - value diff --git a/tests/pytests/unit/modules/test_yaml.py b/tests/pytests/unit/modules/test_yaml.py new file mode 100644 index 00000000000..1f00af710c8 --- /dev/null +++ b/tests/pytests/unit/modules/test_yaml.py @@ -0,0 +1,79 @@ +import os + +import pytest + +import salt.loader +import salt.modules.config +import salt.modules.cp +import salt.modules.slsutil +import salt.utils.files +from tests.support.mock import MagicMock + +try: + import salt.modules.yaml + import salt.utils.yamllint + + YAMLLINT_AVAILABLE = True +except ImportError: + YAMLLINT_AVAILABLE = False + + +pytestmark = [ + pytest.mark.skip_on_windows(reason="Dam line breaks"), + pytest.mark.skipif( + YAMLLINT_AVAILABLE is False, reason="The 'yammllint' pacakge is not available" + ), +] + + +@pytest.fixture +def configure_loader_modules(minion_opts): + with pytest.helpers.temp_file( + "testyaml.yaml", contents="key:\n value\n" + ) as cached_file: + yield { + salt.modules.yaml: { + "__salt__": { + "config.get": salt.modules.config.get, + "cp.cache_file": MagicMock( + salt.modules.cp.cache_file, + autospec=True, + return_value=str(cached_file), + ), + "slsutil.renderer": MagicMock( + salt.modules.slsutil.renderer, + autospec=True, + return_value=f"key: value{os.linesep}", + ), + }, + "__opts__": minion_opts, + "__utils__": { + "files.fopen": salt.utils.files.fopen, + "yamllint.lint": salt.utils.yamllint.lint, + }, + }, + salt.modules.config: { + "__opts__": minion_opts, + }, + } + + +def test_lint_yaml(): + """ + ensure that we can lint from the yaml lint utils + """ + assert salt.modules.yaml.lint("salt://test/test.sls") == { + "problems": [], + "source": f"key:{os.linesep} value{os.linesep}", + } + + +def test_lint_pre_render(): + assert salt.modules.yaml.lint("salt://test.test.sls", pre_render="jinja") == { + "problems": [], + "source": f"key: value{os.linesep}", + } + + +def test_yamllint_virtual(): + assert salt.modules.yaml.__virtual__() == "yaml"