1
0

test_yamldumper.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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(data, default_flow_style=False) == exp_yaml.replace('{', '').replace('}', '')
  27. def test_yaml_safe_dump(self):
  28. '''
  29. Test yaml.safe_dump a dict
  30. '''
  31. data = {'foo': 'bar'}
  32. assert salt.utils.yamldumper.safe_dump(data) == '{foo: bar}\n'
  33. assert salt.utils.yamldumper.safe_dump(data, default_flow_style=False) == 'foo: bar\n'