Fix broken tests

This commit is contained in:
Daniel A. Wozniak 2023-12-08 14:58:11 -07:00 committed by Daniel Wozniak
parent b36f276007
commit 96bc89f721
3 changed files with 11 additions and 9 deletions

View file

@ -43,6 +43,9 @@ class NamedLoaderContext(collections.abc.MutableMapping):
self.loader_context = loader_context
self.default = default
def with_default(self, default):
return NamedLoaderContext(self.name, self.loader_context, default=default)
def loader(self):
"""
The LazyLoader in the current context. This will return None if there

View file

@ -1,12 +1,10 @@
import pathlib
import salt.loader.context
import salt.loader.lazy
import salt.utils.files
import tests.support.helpers
def xtest_opts_dunder_opts_without_import(tempdir):
def test_opts_dunder_opts_without_import(tmp_path):
"""
Test __opts__ without being imported.
@ -14,7 +12,7 @@ def xtest_opts_dunder_opts_without_import(tempdir):
salt.loader.dunder the __opts__ object will be a dictionary.
"""
opts = {"optimization_order": [0, 1, 2]}
with salt.utils.files.fopen(pathlib.Path(tempdir.tempdir) / "mymod.py", "w") as fp:
with salt.utils.files.fopen(tmp_path / "mymod.py", "w") as fp:
fp.write(
tests.support.helpers.dedent(
"""
@ -23,11 +21,11 @@ def xtest_opts_dunder_opts_without_import(tempdir):
"""
)
)
loader = salt.loader.lazy.LazyLoader([tempdir.tempdir], opts)
loader = salt.loader.lazy.LazyLoader([tmp_path], opts)
assert type(loader["mymod.mymethod"]()) == dict
def test_opts_dunder_opts_with_import(tempdir):
def test_opts_dunder_opts_with_import(tmp_path):
"""
Test __opts__ when imported.
@ -35,7 +33,7 @@ def test_opts_dunder_opts_with_import(tempdir):
salt.loader.dunder the __opts__ object will be a NamedLoaderContext.
"""
opts = {"optimization_order": [0, 1, 2]}
with salt.utils.files.fopen(pathlib.Path(tempdir.tempdir) / "mymod.py", "w") as fp:
with salt.utils.files.fopen(tmp_path / "mymod.py", "w") as fp:
fp.write(
tests.support.helpers.dedent(
"""
@ -47,6 +45,6 @@ def test_opts_dunder_opts_with_import(tempdir):
"""
)
)
loader = salt.loader.lazy.LazyLoader([tempdir.tempdir], opts)
loader = salt.loader.lazy.LazyLoader([tmp_path], opts)
assert loader["mymod.optstype"]() == salt.loader.context.NamedLoaderContext
assert loader["mymod.opts"]() == opts

View file

@ -11,6 +11,7 @@ import salt.modules.yumpkg as yumpkg
import salt.states.beacon as beaconstate
import salt.states.pkg as pkg
import salt.utils.state as state_utils
from salt.loader.dunder import __opts__
from salt.utils.event import SaltEvent
from tests.support.mock import MagicMock, patch
@ -21,7 +22,7 @@ log = logging.getLogger(__name__)
def configure_loader_modules(minion_opts):
return {
cp: {
"__opts__": minion_opts,
"__opts__": __opts__.with_default(minion_opts),
},
pkg: {
"__env__": "base",