a family and a variable cannot have the same path

This commit is contained in:
Emmanuel Garette 2021-02-16 13:45:43 +01:00
parent e60fd4adbc
commit 85151da58d
8 changed files with 29 additions and 1 deletions

View file

@ -356,7 +356,7 @@ class RougailObjSpace:
# it's not a family
tag = FORCE_TAG.get(child.tag, child.tag)
children = getattr(space, tag, {})
if name in children:
if name in children and isinstance(children[name], getattr(self, child.tag)):
return children[name]
return None

View file

@ -66,6 +66,9 @@ class Path:
if full_name in self.families and \
self.families[full_name]['variableobj'] != variableobj: # pragma: no cover
raise DictConsistencyError(_(f'Duplicate family name "{name}"'), 37, variableobj.xmlfiles)
if full_name in self.variables:
msg = _(f'A variable and a family has the same path "{full_name}"')
raise DictConsistencyError(msg, 56, variableobj.xmlfiles)
self.families[full_name] = dict(name=name,
namespace=namespace,
variableobj=variableobj,
@ -150,6 +153,9 @@ class Path:
else:
full_path = name
variableobj.path = full_path
if full_path in self.families:
msg = _(f'A family and a variable has the same path "{full_path}"')
raise DictConsistencyError(msg, 57, variableobj.xmlfiles)
self.variables[full_path] = dict(name=name,
family=family,
leader=None,

View file

@ -0,0 +1,11 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail>
<variables>
<family name="general">
<variable name="my_variable2"/>
</family>
<variable name="general"/>
</variables>
</rougail>
<!-- vim: ts=4 sw=4 expandtab
-->

View file

@ -0,0 +1,11 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail>
<variables>
<variable name="general"/>
<family name="general">
<variable name="my_variable2"/>
</family>
</variables>
</rougail>
<!-- vim: ts=4 sw=4 expandtab
-->