ruamel.yaml: adjust to new DuplicatedKeyError (#6464)

This commit is contained in:
Paweł Redzyński
2021-08-19 20:02:16 +03:00
committed by GitHub
parent 57899ee86d
commit a7175501aa
3 changed files with 10 additions and 12 deletions
+2 -9
View File
@@ -23,17 +23,10 @@ def load_yaml(path, fs=None):
def parse_yaml(text, path, typ="safe"):
from ruamel.yaml import YAML
from ruamel.yaml import YAMLError as _YAMLError
from ruamel.yaml.constructor import DuplicateKeyError
yaml = YAML(typ=typ)
try:
with reraise(_YAMLError, YAMLFileCorruptedError(path)):
return yaml.load(text) or {}
except DuplicateKeyError as exc:
# NOTE: unfortunately this one doesn't inherit from YAMLError, so we
# have to catch it by-hand. See
# https://yaml.readthedocs.io/en/latest/api.html#duplicate-keys
raise YAMLError(path, exc.problem)
with reraise(_YAMLError, YAMLFileCorruptedError(path)):
return yaml.load(text) or {}
def parse_yaml_for_update(text, path):
+1 -1
View File
@@ -61,7 +61,7 @@ install_requires = [
"grandalf==0.6",
"distro>=1.3.0",
"appdirs>=1.4.3",
"ruamel.yaml>=0.16.1",
"ruamel.yaml>=0.17.11",
"toml>=0.10.1",
"funcy>=1.14",
"pathspec>=0.6.0,<0.9.0",
+7 -2
View File
@@ -1,6 +1,11 @@
import pytest
from dvc.utils.serialize import EncodingError, YAMLError, load_yaml, parse_yaml
from dvc.utils.serialize import (
EncodingError,
YAMLFileCorruptedError,
load_yaml,
parse_yaml,
)
def test_parse_yaml_duplicate_key_error():
@@ -10,7 +15,7 @@ def test_parse_yaml_duplicate_key_error():
mykey:
- bar
"""
with pytest.raises(YAMLError, match='found duplicate key "mykey"'):
with pytest.raises(YAMLFileCorruptedError):
parse_yaml(text, "mypath")