Skip to content

Commit 93af689

Browse files
committed
[validation] Add reports method
1 parent 186d80c commit 93af689

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

odml/validation.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,36 @@ def run_validation(self):
173173
for prop in sec.properties:
174174
self.validate(prop)
175175

176+
def report(self):
177+
"""
178+
Validates the registered object and returns a results report.
179+
"""
180+
self.run_validation()
181+
182+
err_count = 0
183+
reduce = set()
184+
sec_count = 0
185+
prop_count = 0
186+
187+
for i in self.errors:
188+
if i.is_error:
189+
err_count += 1
190+
191+
if i.obj not in reduce and 'section' in str(i.obj).lower():
192+
sec_count += 1
193+
elif i.obj not in reduce and 'property' in str(i.obj).lower():
194+
prop_count += 1
195+
196+
reduce.add(i.obj)
197+
198+
warn_count = len(self.errors) - err_count
199+
msg = ""
200+
if err_count or warn_count:
201+
msg = "Validation found %s errors and %s warnings" % (err_count, warn_count)
202+
msg += " in %s Sections and %s Properties." % (sec_count, prop_count)
203+
204+
return msg
205+
176206
def register_custom_handler(self, klass, handler):
177207
"""
178208
Adds a validation handler for an odml class. The handler is called in the

0 commit comments

Comments
 (0)