Exemple #1
0
    def test_issue_288a(self):
        import sys
        from io import StringIO

        from ruyaml import YAML

        yamldoc = dedent("""\
        ---
        # Reusable values
        aliases:
          # First-element comment
          - &firstEntry First entry
          # Second-element comment
          - &secondEntry Second entry

          # Third-element comment is
           # a multi-line value
          - &thirdEntry Third entry

        # EOF Comment
        """)

        yaml = YAML()
        yaml.indent(mapping=2, sequence=4, offset=2)
        yaml.explicit_start = True
        yaml.preserve_quotes = True
        yaml.width = sys.maxsize
        data = yaml.load(yamldoc)
        buf = StringIO()
        yaml.dump(data, buf)
        assert buf.getvalue() == yamldoc
Exemple #2
0
    def test_issue_279(self):
        from io import StringIO

        from ruyaml import YAML

        yaml = YAML()
        yaml.indent(sequence=4, offset=2)
        inp = dedent("""\
        experiments:
          - datasets:
        # ATLAS EWK
              - {dataset: ATLASWZRAP36PB, frac: 1.0}
              - {dataset: ATLASZHIGHMASS49FB, frac: 1.0}
        """)
        a = yaml.load(inp)
        buf = StringIO()
        yaml.dump(a, buf)
        print(buf.getvalue())
        assert buf.getvalue() == inp
Exemple #3
0
 def test_rt_root_sq_scalar_expl_indent(self):
     yaml = YAML()
     yaml.explicit_start = True
     yaml.indent = 4
     s = "'testing: 123'"
     ys = """
     ---
         {}
     """
     ys = ys.format(s)
     d = yaml.load(ys)
     yaml.dump(d, compare=ys)
Exemple #4
0
 def test_rt_root_plain_scalar_no_indent(self):
     yaml = YAML()
     yaml.explicit_start = True
     yaml.indent = 0
     s = 'testing123'
     ys = """
     ---
     {}
     """
     ys = ys.format(s)
     d = yaml.load(ys)
     yaml.dump(d, compare=ys)
Exemple #5
0
 def test_rt_root_dq_scalar_expl_indent(self):
     # if yaml.indent is the default (None)
     # then write after the directive indicator
     yaml = YAML()
     yaml.explicit_start = True
     yaml.indent = 0
     s = '"\'testing123"'
     ys = """
     ---
     {}
     """
     ys = ys.format(s)
     d = yaml.load(ys)
     yaml.dump(d, compare=ys)
Exemple #6
0
    def test_issue_290a(self):
        import sys
        from io import StringIO

        from ruyaml import YAML

        yamldoc = dedent("""\
        ---
        aliases:
          # Folded-element comment
          # for a multi-line value
          - &FoldedEntry >
            THIS IS A
            FOLDED, MULTI-LINE
            VALUE

          # Literal-element comment
          # for a multi-line value
          - &literalEntry |
            THIS IS A
            LITERAL, MULTI-LINE
            VALUE

          # Plain-element comment
          - &plainEntry Plain entry
        """)

        yaml = YAML()
        yaml.indent(mapping=2, sequence=4, offset=2)
        yaml.explicit_start = True
        yaml.preserve_quotes = True
        yaml.width = sys.maxsize
        data = yaml.load(yamldoc)
        buf = StringIO()
        yaml.dump(data, buf)
        assert buf.getvalue() == yamldoc