Skip to content

Commit 7a996a5

Browse files
committed
[validation] Add property unique id validation
Closes #261
1 parent 8550c0f commit 7a996a5

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

odml/validation.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ 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))
7877
for err in handler(obj):
7978
self.error(err)
8079

@@ -140,12 +139,8 @@ def section_unique_ids(parent, id_map=None):
140139
id_map = {}
141140

142141
for sec in parent.sections:
143-
for prop in sec:
144-
if prop.id in id_map:
145-
yield ValidationError(prop, "Duplicate id in Property '%s' and '%s'" %
146-
(prop.get_path(), id_map[prop.id]))
147-
return
148-
id_map[prop.id] = "Property '%s'" % prop.get_path()
142+
for e in property_unique_ids(sec, id_map):
143+
yield e
149144

150145
if sec.id in id_map:
151146
yield ValidationError(sec, "Duplicate id in Section '%s' and '%s'" %
@@ -157,6 +152,18 @@ def section_unique_ids(parent, id_map=None):
157152
yield e
158153

159154

155+
def property_unique_ids(parent, id_map=None):
156+
if not id_map:
157+
id_map = {}
158+
159+
for prop in parent.properties:
160+
if prop.id in id_map:
161+
yield ValidationError(prop, "Duplicate id in Property '%s' and '%s'" %
162+
(prop.get_path(), id_map[prop.id]))
163+
return
164+
id_map[prop.id] = "Property '%s'" % prop.get_path()
165+
166+
160167
Validation.register_handler('odML', document_unique_ids)
161168

162169

0 commit comments

Comments
 (0)