예제 #1
0
    def test_duplicate_keys_02(self):
        # Issue 165 unicode keys in error/warning
        from srsly.ruamel_yaml import safe_load
        from srsly.ruamel_yaml.constructor import DuplicateKeyError

        with pytest.raises(DuplicateKeyError):
            safe_load("type: Doméstica\ntype: International")
예제 #2
0
    def test_duplicate_key_00(self):
        from srsly.ruamel_yaml import version_info
        from srsly.ruamel_yaml import safe_load, round_trip_load
        from srsly.ruamel_yaml.constructor import (
            DuplicateKeyFutureWarning,
            DuplicateKeyError,
        )

        s = dedent(
            """\
        &anchor foo:
            foo: bar
            *anchor : duplicate key
            baz: bat
            *anchor : duplicate key
        """
        )
        if version_info < (0, 15, 1):
            pass
        elif version_info < (0, 16, 0):
            with pytest.warns(DuplicateKeyFutureWarning):
                safe_load(s)
            with pytest.warns(DuplicateKeyFutureWarning):
                round_trip_load(s)
        else:
            with pytest.raises(DuplicateKeyError):
                safe_load(s)
            with pytest.raises(DuplicateKeyError):
                round_trip_load(s)
예제 #3
0
    def test_issue_232(self):
        import srsly.ruamel_yaml
        import srsly.ruamel_yaml as yaml

        with pytest.raises(srsly.ruamel_yaml.parser.ParserError):
            yaml.safe_load("]")
        with pytest.raises(srsly.ruamel_yaml.parser.ParserError):
            yaml.safe_load("{]")
예제 #4
0
    def test_merge_items(self):
        from srsly.ruamel_yaml import safe_load

        d = safe_load(self.yaml_str)
        data = round_trip_load(self.yaml_str)
        count = 0
        for x in data[2].items():
            count += 1
            print(count, x)
        assert count == len(d[2])
예제 #5
0
    def test_root_literal_scalar_no_indent_1_1_old_style(self):
        from textwrap import dedent
        from srsly.ruamel_yaml import safe_load

        s = "testing123"
        inp = """
        %YAML 1.1
        --- |
          {}
        """
        d = safe_load(dedent(inp.format(s)))
        print(d)
        assert d == s + "\n"
예제 #6
0
    def test_len_items_delete(self):
        from srsly.ruamel_yaml import safe_load
        from srsly.ruamel_yaml.compat import PY3

        d = safe_load(self.yaml_str)
        data = round_trip_load(self.yaml_str)
        x = data[2].items()
        print("d2 items", d[2].items(), len(d[2].items()), x, len(x))
        ref = len(d[2].items())
        print("ref", ref)
        assert len(x) == ref
        del data[2]["m"]
        if PY3:
            ref -= 1
        assert len(x) == ref
        del data[2]["d"]
        if PY3:
            ref -= 1
        assert len(x) == ref
        del data[2]["a"]
        if PY3:
            ref -= 1
        assert len(x) == ref