mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
parent
df76113c5c
commit
2e7f743371
3 changed files with 42 additions and 0 deletions
|
@ -45,6 +45,9 @@ class SaltYamlSafeLoader(yaml.SafeLoader, object):
|
|||
self.add_constructor(
|
||||
u'tag:yaml.org,2002:omap',
|
||||
type(self).construct_yaml_map)
|
||||
self.add_constructor(
|
||||
u'tag:yaml.org,2002:python/unicode',
|
||||
type(self).construct_unicode)
|
||||
self.dictclass = dictclass
|
||||
|
||||
def construct_yaml_map(self, node):
|
||||
|
@ -53,6 +56,9 @@ class SaltYamlSafeLoader(yaml.SafeLoader, object):
|
|||
value = self.construct_mapping(node)
|
||||
data.update(value)
|
||||
|
||||
def construct_unicode(self, node):
|
||||
return node.value
|
||||
|
||||
def construct_mapping(self, node, deep=False):
|
||||
'''
|
||||
Build the mapping for YAML
|
||||
|
|
30
tests/unit/renderers/yaml_test.py
Normal file
30
tests/unit/renderers/yaml_test.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting import TestCase
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
# Import Salt libs
|
||||
from salt.renderers import yaml
|
||||
|
||||
yaml.__salt__ = {}
|
||||
yaml.__opts__ = {}
|
||||
|
||||
|
||||
class YAMLRendererTestCase(TestCase):
|
||||
def test_yaml_render_string(self):
|
||||
data = "string"
|
||||
result = yaml.render(data)
|
||||
|
||||
self.assertEqual(result, data)
|
||||
|
||||
def test_yaml_render_unicode(self):
|
||||
data = "!!python/unicode python unicode string"
|
||||
result = yaml.render(data)
|
||||
|
||||
self.assertEqual(result, u"python unicode string")
|
|
@ -490,6 +490,12 @@ class TestCustomExtensions(TestCase):
|
|||
rendered = env.from_string('{{ dataset|yaml }}').render(dataset=dataset)
|
||||
self.assertEqual(dataset, rendered)
|
||||
|
||||
def test_serialize_yaml_unicode(self):
|
||||
dataset = u"str value"
|
||||
env = Environment(extensions=[SerializerExtension])
|
||||
rendered = env.from_string('{{ dataset|yaml }}').render(dataset=dataset)
|
||||
self.assertEqual("!!python/unicode str value", rendered)
|
||||
|
||||
def test_serialize_python(self):
|
||||
dataset = {
|
||||
"foo": True,
|
||||
|
|
Loading…
Add table
Reference in a new issue