def test_dump00(self): import ruyaml # NOQA data = None s = ruyaml.round_trip_dump(data) assert s == 'null\n...\n' d = ruyaml.round_trip_load(s) assert d == data
def test_dump03(self): import ruyaml # NOQA data = None s = ruyaml.round_trip_dump(data, explicit_start=True) assert s == '---\n...\n' d = ruyaml.round_trip_load(s) assert d == data
def test_dump02(self): import ruyaml # NOQA data = None s = ruyaml.round_trip_dump(data, explicit_end=False) assert s == 'null\n...\n' d = ruyaml.round_trip_load(s) assert d == data
def test_scalar_with_comments(self): import ruyaml # NOQA for x in [ "", '\n', '\n# Another comment\n', '\n\n', '\n\n# abc\n#xyz\n', '\n\n# abc\n#xyz\n', '# abc\n\n#xyz\n', '\n\n # abc\n #xyz\n', ]: commented_line = test_block_scalar_commented_line_template.format(x) data = ruyaml.round_trip_load(commented_line) assert ruyaml.round_trip_dump(data) == commented_line
def test_issue_127(): import ruyaml # NOQA class Ref(ruyaml.YAMLObject): yaml_constructor = ruyaml.RoundTripConstructor yaml_representer = ruyaml.RoundTripRepresenter yaml_tag = u'!Ref' def __init__(self, logical_id): self.logical_id = logical_id @classmethod def from_yaml(cls, loader, node): return cls(loader.construct_scalar(node)) @classmethod def to_yaml(cls, dumper, data): if isinstance(data.logical_id, ruyaml.scalarstring.ScalarString): style = data.logical_id.style # ruyaml>0.15.8 else: style = None return dumper.represent_scalar(cls.yaml_tag, data.logical_id, style=style) document = dedent("""\ AList: - !Ref One - !Ref 'Two' - !Ref Two and a half BList: [!Ref Three, !Ref "Four"] CList: - Five Six - 'Seven Eight' """) data = ruyaml.round_trip_load(document, preserve_quotes=True) assert ruyaml.round_trip_dump(data, indent=4, block_seq_indent=2) == document.replace( '\n Two and', ' Two and')
def round_trip_dump( data, stream=None, indent=None, block_seq_indent=None, top_level_colon_align=None, prefix_colon=None, explicit_start=None, explicit_end=None, version=None, ): import ruyaml # NOQA return ruyaml.round_trip_dump( data, stream=stream, indent=indent, block_seq_indent=block_seq_indent, top_level_colon_align=top_level_colon_align, prefix_colon=prefix_colon, explicit_start=explicit_start, explicit_end=explicit_end, version=version, )