Skip to content

Commit 7e342e2

Browse files
committed
[validation] Add section unique id validation
1 parent 7ee5066 commit 7e342e2

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

odml/validation.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def __init__(self, doc):
7474
def validate(self, obj):
7575
handlers = self._handlers.get(obj.format().name, [])
7676
for handler in handlers:
77+
print("obj: %s, Handler: %s" % (obj, handler))
7778
for err in handler(obj):
7879
self.error(err)
7980

@@ -128,6 +129,28 @@ def section_repository_should_be_present(sec):
128129
Validation.register_handler('section', section_repository_should_be_present)
129130

130131

132+
def section_unique_ids(parent, id_map=None):
133+
if not id_map:
134+
id_map = {}
135+
136+
for sec in parent.sections:
137+
for prop in sec:
138+
if prop.id in id_map:
139+
yield ValidationError(prop, "Duplicate id in Property '%s' and '%s'" %
140+
(prop.get_path(), id_map[prop.id]))
141+
return
142+
id_map[prop.id] = "Property '%s'" % prop.get_path()
143+
144+
if sec.id in id_map:
145+
yield ValidationError(sec, "Duplicate id in Section '%s' and '%s'" %
146+
(sec.get_path(), id_map[sec.id]))
147+
return
148+
id_map[sec.id] = "Section '%s'" % sec.get_path()
149+
150+
for e in section_unique_ids(sec, id_map):
151+
yield e
152+
153+
131154
def object_unique_names(obj, children, attr=lambda x: x.name,
132155
msg="Object names must be unique"):
133156
"""

0 commit comments

Comments
 (0)