Commit 78ee9223 authored by Matias Guijarro's avatar Matias Guijarro

Merge branch '1ptiyml' into 'master'

raise exception (with name of faulty file) if empty YML file is present

See merge request !949
parents ce923e8b bdbb1dd9
Pipeline #6187 failed with stages
in 18 minutes and 48 seconds
......@@ -798,16 +798,19 @@ class Config(object):
return r_list
def _parse(self, d, parent):
for key, value in d.iteritems():
if isinstance(value, dict):
node = Node(self, parent=parent)
self._parse(value, node)
self._create_index(node)
parent[key] = node
elif isinstance(value, list):
parent[key] = self._parse_list(value, parent)
else:
parent[key] = value
if d is None:
raise RuntimeError("Error parsing %r" % parent)
else:
for key, value in d.iteritems():
if isinstance(value, dict):
node = Node(self, parent=parent)
self._parse(value, node)
self._create_index(node)
parent[key] = node
elif isinstance(value, list):
parent[key] = self._parse_list(value, parent)
else:
parent[key] = value
def _clear_instances(self):
self._name2instance = dict()
......
......@@ -67,6 +67,24 @@ def test_config_save(beacon):
rw_cfg2.save()
def test_empty_yml(beacon, beacon_directory):
import subprocess
subprocess.call(['echo " " > %s/toto.yml' % beacon_directory], shell=True)
# before patch empty YML:
# assert pytest.raises(AttributeError, beacon.reload)
# after patch empty YML: assert pytest.raises(AttributeError, beacon.reload)
assert pytest.raises(RuntimeError, beacon.reload)
with pytest.raises(RuntimeError) as e_info:
beacon.reload()
assert "filename" in str(e_info.value)
subprocess.call(["rm -f %s/toto.yml" % beacon_directory], shell=True)
def test_references(beacon):
refs_cfg = beacon.get("refs_test")
m0 = beacon.get("m0")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment