configdata: Add check for shadowing keys
This commit is contained in:
parent
8b9b750f8f
commit
938946c48b
@ -663,6 +663,12 @@ def _read_yaml(yaml_data):
|
|||||||
backends=_parse_yaml_backends(name, option.get('backend', None)),
|
backends=_parse_yaml_backends(name, option.get('backend', None)),
|
||||||
description=option['desc'])
|
description=option['desc'])
|
||||||
|
|
||||||
|
# Make sure no key shadows another.
|
||||||
|
for key1 in parsed:
|
||||||
|
for key2 in parsed:
|
||||||
|
if key2.startswith(key1 + '.'):
|
||||||
|
raise ValueError("Shadowing keys {} and {}".format(key1, key2))
|
||||||
|
|
||||||
return parsed
|
return parsed
|
||||||
|
|
||||||
|
|
||||||
|
@ -904,7 +904,7 @@ content.images:
|
|||||||
type: Bool
|
type: Bool
|
||||||
desc: Whether images are automatically loaded in web pages.
|
desc: Whether images are automatically loaded in web pages.
|
||||||
|
|
||||||
content.javascript:
|
content.javascript.enabled:
|
||||||
default: true
|
default: true
|
||||||
type: Bool
|
type: Bool
|
||||||
desc: Enables or disables the running of JavaScript programs.
|
desc: Enables or disables the running of JavaScript programs.
|
||||||
|
@ -69,6 +69,31 @@ class TestReadYaml:
|
|||||||
with pytest.raises(ValueError, match='Invalid keys'):
|
with pytest.raises(ValueError, match='Invalid keys'):
|
||||||
configdata._read_yaml(data)
|
configdata._read_yaml(data)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('first, second, shadowing', [
|
||||||
|
('foo', 'foo.bar', True),
|
||||||
|
('foo.bar', 'foo', True),
|
||||||
|
('foo.bar', 'foo.bar.baz', True),
|
||||||
|
('foo.bar', 'foo.baz', False),
|
||||||
|
])
|
||||||
|
def test_shadowing(self, first, second, shadowing):
|
||||||
|
"""Make sure a setting can't shadow another."""
|
||||||
|
data = textwrap.dedent("""
|
||||||
|
{first}:
|
||||||
|
type: Bool
|
||||||
|
default: true
|
||||||
|
desc: Hello World
|
||||||
|
|
||||||
|
{second}:
|
||||||
|
type: Bool
|
||||||
|
default: true
|
||||||
|
desc: Hello World
|
||||||
|
""".format(first=first, second=second))
|
||||||
|
if shadowing:
|
||||||
|
with pytest.raises(ValueError, match='Shadowing keys'):
|
||||||
|
configdata._read_yaml(data)
|
||||||
|
else:
|
||||||
|
configdata._read_yaml(data)
|
||||||
|
|
||||||
|
|
||||||
class TestParseYamlType:
|
class TestParseYamlType:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user