mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-19 07:18:27 +01:00
ruamel.yaml: adjust to new DuplicatedKeyError (#6464)
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user