test_yamlencoding.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Tests for salt.utils.yamlencoding
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt libs
  8. import salt.utils.yaml
  9. import salt.utils.yamlencoding
  10. from tests.support.unit import TestCase
  11. class YamlEncodingTestCase(TestCase):
  12. def test_yaml_dquote(self):
  13. for teststr in (r'"\ []{}"',):
  14. self.assertEqual(teststr, salt.utils.yaml.safe_load(salt.utils.yamlencoding.yaml_dquote(teststr)))
  15. def test_yaml_dquote_doesNotAddNewLines(self):
  16. teststr = '"' * 100
  17. self.assertNotIn('\n', salt.utils.yamlencoding.yaml_dquote(teststr))
  18. def test_yaml_squote(self):
  19. ret = salt.utils.yamlencoding.yaml_squote(r'"')
  20. self.assertEqual(ret, r"""'"'""")
  21. def test_yaml_squote_doesNotAddNewLines(self):
  22. teststr = "'" * 100
  23. self.assertNotIn('\n', salt.utils.yamlencoding.yaml_squote(teststr))
  24. def test_yaml_encode(self):
  25. for testobj in (None, True, False, '[7, 5]', '"monkey"', 5, 7.5, "2014-06-02 15:30:29.7"):
  26. self.assertEqual(testobj, salt.utils.yaml.safe_load(salt.utils.yamlencoding.yaml_encode(testobj)))
  27. for testobj in ({}, [], set()):
  28. self.assertRaises(TypeError, salt.utils.yamlencoding.yaml_encode, testobj)