Skip to content

Commit e31a177

Browse files
committed
Fix AttributeError: "load()" has been removed
ruamel.yaml 0.18 has removed `load()` which lets the test fail: ``` AttributeError: "load()" has been removed, use yaml = YAML(typ='rt') yaml.load(...) and register any classes that you use, or check the tag attribute on the loaded data, instead of file "ionit.py", line 126 file_context = yaml.load(config_file, Loader=yaml.SafeLoader) ``` Use the new ruamel.yaml API in case ruamel.yaml is used.
1 parent 3f2a379 commit e31a177

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

ionit

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ def load_python_plugin(file_path, current_context):
8585
return context
8686

8787

88+
def load_yaml(stream):
89+
"""Parse the first YAML document in a stream
90+
and produce the corresponding Python object.
91+
"""
92+
if hasattr(yaml, "YAML"):
93+
yaml_object = yaml.YAML(typ="safe")
94+
return yaml_object.load(stream)
95+
return yaml.load(stream, Loader=yaml.SafeLoader)
96+
97+
8898
def get_config_files(paths):
8999
"""Return files for the given paths (could either be files or directories)."""
90100
logger = logging.getLogger(SCRIPT_NAME)
@@ -123,7 +133,7 @@ def collect_context(paths, encoding):
123133
elif extension == ".yaml":
124134
logger.info("Reading configuration file '%s'...", file)
125135
with open(file, encoding=encoding) as config_file:
126-
file_context = yaml.load(config_file, Loader=yaml.SafeLoader)
136+
file_context = load_yaml(config_file)
127137
else:
128138
logger.info(
129139
"Skipping configuration file '%s', "

tests/test_ionit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def test_invalid_yaml(self):
150150
(
151151
"ERROR:ionit:Failed to read YAML from "
152152
r"'[^']*config/invalid-yaml/invalid.yaml': mapping values are not allowed "
153-
r"here\s+in \"\S*config/invalid-yaml/invalid.yaml\", line 3, column 14"
153+
r"(here|in this context)\s+"
154+
r"in \"\S*config/invalid-yaml/invalid.yaml\", line 3, column 14"
154155
),
155156
)
156157

0 commit comments

Comments
 (0)