Beispiel #1
0
    def test_issue_300a(self):
        import srsly.ruamel_yaml

        inp = dedent("""
        %YAML 1.1
        %TAG ! tag:example.com,2019/path#fragment
        ---
        null
        """)
        yaml = YAML()
        with pytest.raises(srsly.ruamel_yaml.scanner.ScannerError,
                           match="while scanning a directive"):
            yaml.load(inp)
Beispiel #2
0
    def test_issue_288a(self):
        import sys
        from srsly.ruamel_yaml.compat import StringIO
        from srsly.ruamel_yaml 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
Beispiel #3
0
    def test_issue_290a(self):
        import sys
        from srsly.ruamel_yaml.compat import StringIO
        from srsly.ruamel_yaml 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
Beispiel #4
0
    def test_issue_233a(self):
        from srsly.ruamel_yaml import YAML
        import json

        yaml = YAML()
        data = yaml.load("[]")
        json_str = json.dumps(data)  # NOQA
Beispiel #5
0
    def test_issue_284(self):
        import srsly.ruamel_yaml

        inp = dedent("""\
        plain key: in-line value
        : # Both empty
        "quoted key":
        - entry
        """)
        yaml = srsly.ruamel_yaml.YAML(typ="rt")
        yaml.version = (1, 2)
        d = yaml.load(inp)
        assert d[None] is None

        yaml = srsly.ruamel_yaml.YAML(typ="rt")
        yaml.version = (1, 1)
        with pytest.raises(srsly.ruamel_yaml.parser.ParserError,
                           match="expected <block end>"):
            d = yaml.load(inp)
Beispiel #6
0
    def test_issue_286(self):
        from srsly.ruamel_yaml import YAML
        from srsly.ruamel_yaml.compat import StringIO

        yaml = YAML()
        inp = dedent("""\
        parent_key:
        - sub_key: sub_value

        # xxx""")
        a = yaml.load(inp)
        a["new_key"] = "new_value"
        buf = StringIO()
        yaml.dump(a, buf)
        assert buf.getvalue().endswith("xxx\nnew_key: new_value\n")
Beispiel #7
0
    def test_issue_234(self):
        from srsly.ruamel_yaml import YAML

        inp = dedent("""\
        - key: key1
          ctx: [one, two]
          help: one
          cmd: >
            foo bar
            foo bar
        """)
        yaml = YAML(typ="safe", pure=True)
        data = yaml.load(inp)
        fold = data[0]["cmd"]
        print(repr(fold))
        assert "\a" not in fold
Beispiel #8
0
    def test_issue_285(self):
        from srsly.ruamel_yaml import YAML

        yaml = YAML()
        inp = dedent("""\
        %YAML 1.1
        ---
        - y
        - n
        - Y
        - N
        """)
        a = yaml.load(inp)
        assert a[0]
        assert a[2]
        assert not a[1]
        assert not a[3]
Beispiel #9
0
    def test_issue_279(self):
        from srsly.ruamel_yaml import YAML
        from srsly.ruamel_yaml.compat import StringIO

        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
Beispiel #10
0
    def test_issue_245(self):
        from srsly.ruamel_yaml import YAML

        inp = """
        d: yes
        """
        for typ in ["safepure", "rt", "safe"]:
            if typ.endswith("pure"):
                pure = True
                typ = typ[:-4]
            else:
                pure = None

            yaml = YAML(typ=typ, pure=pure)
            yaml.version = (1, 1)
            d = yaml.load(inp)
            print(typ, yaml.parser, yaml.resolver)
            assert d["d"] is True