mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add tests for opts dunder
This commit is contained in:
parent
3140aecd2b
commit
96c59e07fc
2 changed files with 50 additions and 0 deletions
|
@ -8,6 +8,7 @@ loader_context = salt.loader.context.LoaderContext()
|
|||
|
||||
|
||||
__file_client__ = loader_context.named_context("__file_client__", default=None)
|
||||
__opts__ = loader_context.named_context("__opts__")
|
||||
__context__ = loader_context.named_context("__context__")
|
||||
__pillar__ = loader_context.named_context("__pillar__")
|
||||
__grains__ = loader_context.named_context("__grains__")
|
||||
|
|
49
tests/pytests/functional/loader/test_dunder.py
Normal file
49
tests/pytests/functional/loader/test_dunder.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
import pathlib
|
||||
|
||||
import salt.loader.context
|
||||
import salt.loader.lazy
|
||||
import salt.utils.files
|
||||
import tests.support.helpers
|
||||
|
||||
|
||||
def test_opts_dunder_opts_without_import(tempdir):
|
||||
"""
|
||||
Test __opts__ without being imported.
|
||||
|
||||
When a loaded module uses __opts__ but does not import it from
|
||||
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:
|
||||
fp.write(
|
||||
tests.support.helpers.dedent(
|
||||
"""
|
||||
def mymethod():
|
||||
return type(__opts__)
|
||||
"""
|
||||
)
|
||||
)
|
||||
loader = salt.loader.lazy.LazyLoader([tempdir.tempdir], opts)
|
||||
assert loader["mymod.mymethod"]() == dict
|
||||
|
||||
|
||||
def test_opts_dunder_opts_with_import(tempdir):
|
||||
"""
|
||||
Test __opts__ when imported.
|
||||
|
||||
When a loaded module uses __opts__ by importing it from
|
||||
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:
|
||||
fp.write(
|
||||
tests.support.helpers.dedent(
|
||||
"""
|
||||
from salt.loader.dunder import __opts__
|
||||
def mymethod():
|
||||
return type(__opts__)
|
||||
"""
|
||||
)
|
||||
)
|
||||
loader = salt.loader.lazy.LazyLoader([tempdir.tempdir], opts)
|
||||
assert loader["mymod.mymethod"]() == salt.loader.context.NamedLoaderContext
|
Loading…
Add table
Reference in a new issue