mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
002aa88a97
Without allow_unicode=True, unicode characters are processed through the str representer and on Python 2 are dumped as a Unicode code point (i.e. a literal \u0414). This commit makes allow_unicode=True the default in our salt.utils.yamlloader.safe_dump() helper. It also adds a new salt.utils.yamlloader.dump() helper which wraps yaml.dump() and also makes allow_unicode=True the default. To make importing and using our custom yaml loader/dumper easier, a convenience module called salt.utils.yaml has been added, which does a wildcard import from both salt.utils.yamldumper and salt.utils.yamlloader. Refs to yaml.load/dump and yaml.safe_load/safe_dump have been updated to salt.utils.yaml, to ensure that unicode is handled properly.
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
'''
|
|
Tests for salt.utils.yamlencoding
|
|
'''
|
|
|
|
# Import Python libs
|
|
from __future__ import absolute_import
|
|
|
|
# Import Salt libs
|
|
import salt.utils.yaml
|
|
import salt.utils.yamlencoding
|
|
from tests.support.unit import TestCase
|
|
|
|
|
|
class YamlEncodingTestCase(TestCase):
|
|
|
|
def test_yaml_dquote(self):
|
|
for teststr in (r'"\ []{}"',):
|
|
self.assertEqual(teststr, salt.utils.yaml.safe_load(salt.utils.yamlencoding.yaml_dquote(teststr)))
|
|
|
|
def test_yaml_dquote_doesNotAddNewLines(self):
|
|
teststr = '"' * 100
|
|
self.assertNotIn('\n', salt.utils.yamlencoding.yaml_dquote(teststr))
|
|
|
|
def test_yaml_squote(self):
|
|
ret = salt.utils.yamlencoding.yaml_squote(r'"')
|
|
self.assertEqual(ret, r"""'"'""")
|
|
|
|
def test_yaml_squote_doesNotAddNewLines(self):
|
|
teststr = "'" * 100
|
|
self.assertNotIn('\n', salt.utils.yamlencoding.yaml_squote(teststr))
|
|
|
|
def test_yaml_encode(self):
|
|
for testobj in (None, True, False, '[7, 5]', '"monkey"', 5, 7.5, "2014-06-02 15:30:29.7"):
|
|
self.assertEqual(testobj, salt.utils.yaml.safe_load(salt.utils.yamlencoding.yaml_encode(testobj)))
|
|
|
|
for testobj in ({}, [], set()):
|
|
self.assertRaises(TypeError, salt.utils.yamlencoding.yaml_encode, testobj)
|