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())
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")
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")
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())
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())
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)
def to_string(self): return str(kube_yaml.yaml_safe_dump(self.value, default_flow_style=False))
def yaml_dump(obj): return kube_yaml.yaml_safe_dump(obj, default_flow_style=False)
def yaml(self): self.cached_yaml = yaml_safe_dump(self.cached_obj, default_flow_style=False)
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)