示例#1
0
 def test_quote_all_numbers(self):
     # the go yaml parser appears to interpret numbers with leading zeros as numbers
     # while py_yaml interprets them as strings. We now force this to be quoted in
     # rubiks.
     src = {'foo': '0012345'}
     dst = "foo: '0012345'"
     self.assertEqual(kube_yaml.yaml_safe_dump(src).strip(), dst.strip())
     src = {'foo': '12345'}
     dst = "foo: '12345'"
     self.assertEqual(kube_yaml.yaml_safe_dump(src).strip(), dst.strip())
     src = {'foo': '0012345abc'}
     dst = "foo: 0012345abc"
     self.assertEqual(kube_yaml.yaml_safe_dump(src).strip(), dst.strip())
示例#2
0
    def test_yaml_indent(self):
        global SHOW

        v = {'a': {'x': Confidential('foo\nbar\nbaz'), 'y': 'plain'}, 'b': Confidential('bar'), 'c': 'xyzzy'}
        r = kube_yaml.yaml_safe_dump(v)
        self.assertTrue(isinstance(r, var_types.VarEntity))
        SHOW = True
        self.assertEqual(str(r), "a:\n  x: |-\n    foo\n    bar\n    baz\n\n  y: plain\nb: bar\nc: xyzzy\n")
        SHOW = False
        self.assertEqual(str(r), "a:\n  x: '*** HIDDEN ***'\n  y: plain\nb: '*** HIDDEN ***'\nc: xyzzy\n")
示例#3
0
    def test_yaml_basic(self):
        global SHOW

        v = {'a': Confidential('foo'), 'b': Confidential('bar'), 'c': 'xyzzy'}
        r = kube_yaml.yaml_safe_dump(v)
        self.assertTrue(isinstance(r, var_types.VarEntity))
        SHOW = True
        self.assertEqual(str(r), "a: foo\nb: bar\nc: xyzzy\n")
        SHOW = False
        self.assertEqual(str(r), "a: '*** HIDDEN ***'\nb: '*** HIDDEN ***'\nc: xyzzy\n")
示例#4
0
    def test_basic(self):
        src = OrderedDict(foo=[1, '2', 3])
        src['bar'] = 'baz'
        src['qux'] = {'xyzzy': 10}
        dst = """
foo:
- 1
- '2'
- 3
bar: baz
qux:
  xyzzy: 10
"""
        self.assertEqual(kube_yaml.yaml_safe_dump(src).strip(), dst.strip())
示例#5
0
    def test_wrap(self):
        src = OrderedDict(foo='here is some text\nwith some line breaks\nin it')
        src['bar'] = 'and some more text on a single line'
        src['qux'] = 'and yet more with line breaks\nwhich will show through'
        dst = """
foo: |-
  here is some text
  with some line breaks
  in it
bar: and some more text on a single line
qux: |-
  and yet more with line breaks
  which will show through
"""
        self.assertEqual(kube_yaml.yaml_safe_dump(src).strip(), dst.strip())
示例#6
0
 def to_string(self):
     ret = kube_yaml.yaml_safe_dump(self.value, default_flow_style=False)
     if isinstance(ret, var_types.VarEntity) and self._in_validation:
         return ret.validation_value()
     return str(ret)
示例#7
0
 def to_string(self):
     return str(kube_yaml.yaml_safe_dump(self.value, default_flow_style=False))
示例#8
0
 def yaml_dump(obj):
     return kube_yaml.yaml_safe_dump(obj, default_flow_style=False)
示例#9
0
 def yaml(self):
     self.cached_yaml = yaml_safe_dump(self.cached_obj,
                                       default_flow_style=False)
示例#10
0
 def yaml(self):
     if isinstance(self.cached_obj, list):
         self.cached_yaml = yaml_safe_dump_all(self.cached_obj, default_flow_style=False)
     else:
         self.cached_yaml = yaml_safe_dump(self.cached_obj, default_flow_style=False)