1
0

test_loader_context.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. """
  2. Tests for salt.loader_context
  3. """
  4. import salt.loader
  5. import salt.loader_context
  6. def test_named_loader_context():
  7. loader_context = salt.loader_context.LoaderContext()
  8. named_context = salt.loader_context.NamedLoaderContext("__test__", loader_context)
  9. test_dunder = {"foo": "bar"}
  10. lazy_loader = salt.loader.LazyLoader(["/foo"], pack={"__test__": test_dunder})
  11. assert named_context.loader() is None
  12. token = salt.loader_context.loader_ctxvar.set(lazy_loader)
  13. try:
  14. assert named_context.loader() == lazy_loader
  15. # The loader's value is the same object as test_dunder
  16. assert named_context.value() is test_dunder
  17. assert named_context["foo"] == "bar"
  18. finally:
  19. salt.loader_context.loader_ctxvar.reset(token)
  20. def test_named_loader_default():
  21. loader_context = salt.loader_context.LoaderContext()
  22. default = {"foo": "bar"}
  23. named_context = salt.loader_context.NamedLoaderContext(
  24. "__test__", loader_context, default=default
  25. )
  26. assert named_context.loader() is None
  27. # The loader's value is the same object as default
  28. assert named_context.value() is default
  29. assert named_context["foo"] == "bar"