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 # it's not a family
tag = FORCE_TAG.get(child.tag, child.tag) tag = FORCE_TAG.get(child.tag, child.tag)
children = getattr(space, 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 children[name]
return None return None

View File

@ -66,6 +66,9 @@ class Path:
if full_name in self.families and \ if full_name in self.families and \
self.families[full_name]['variableobj'] != variableobj: # pragma: no cover self.families[full_name]['variableobj'] != variableobj: # pragma: no cover
raise DictConsistencyError(_(f'Duplicate family name "{name}"'), 37, variableobj.xmlfiles) 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, self.families[full_name] = dict(name=name,
namespace=namespace, namespace=namespace,
variableobj=variableobj, variableobj=variableobj,
@ -150,6 +153,9 @@ class Path:
else: else:
full_path = name full_path = name
variableobj.path = full_path 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, self.variables[full_path] = dict(name=name,
family=family, family=family,
leader=None, 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
-->