test_yamldumper.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # -*- coding: utf-8 -*-
  2. """
  3. Unit tests for salt.utils.yamldumper
  4. """
  5. # Import python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Libs
  8. import salt.ext.six
  9. import salt.utils.yamldumper
  10. # Import Salt Testing Libs
  11. from tests.support.unit import TestCase
  12. class YamlDumperTestCase(TestCase):
  13. """
  14. TestCase for salt.utils.yamldumper module
  15. """
  16. def test_yaml_dump(self):
  17. """
  18. Test yaml.dump a dict
  19. """
  20. data = {"foo": "bar"}
  21. if salt.ext.six.PY2:
  22. exp_yaml = "{!!python/unicode 'foo': !!python/unicode 'bar'}\n"
  23. else:
  24. exp_yaml = "{foo: bar}\n"
  25. assert salt.utils.yamldumper.dump(data) == exp_yaml
  26. assert salt.utils.yamldumper.dump(
  27. data, default_flow_style=False
  28. ) == exp_yaml.replace("{", "").replace("}", "")
  29. def test_yaml_safe_dump(self):
  30. """
  31. Test yaml.safe_dump a dict
  32. """
  33. data = {"foo": "bar"}
  34. assert salt.utils.yamldumper.safe_dump(data) == "{foo: bar}\n"
  35. assert (
  36. salt.utils.yamldumper.safe_dump(data, default_flow_style=False)
  37. == "foo: bar\n"
  38. )