Skip to content

Commit d810ec8

Browse files
committed
[validation] Add constant validation rank labels
1 parent 0288992 commit d810ec8

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

odml/validation.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,31 @@
33
Generic odML validation framework
44
"""
55

6+
LABEL_ERROR = 'error'
7+
LABEL_WARNING = 'warning'
8+
69

710
class ValidationError(object):
811
"""
912
Represents an error found in the validation process
1013
1114
The error is bound to an odML-object (*obj*) or a list of
1215
those and contains a message and a rank which may be one of:
13-
'error', 'warning', 'info'
16+
'error', 'warning'.
1417
"""
1518

16-
def __init__(self, obj, msg, rank='error'):
19+
def __init__(self, obj, msg, rank=LABEL_ERROR):
1720
self.obj = obj
1821
self.msg = msg
1922
self.rank = rank
2023

2124
@property
2225
def is_warning(self):
23-
return self.rank == 'warning'
26+
return self.rank == LABEL_WARNING
2427

2528
@property
2629
def is_error(self):
27-
return self.rank == 'error'
30+
return self.rank == LABEL_ERROR
2831

2932
@property
3033
def path(self):
@@ -98,7 +101,7 @@ def __getitem__(self, obj):
98101
def section_type_must_be_defined(sec):
99102
"""test that no section has an undefined type"""
100103
if sec.type is None or sec.type == '' or sec.type == 'undefined':
101-
yield ValidationError(sec, 'Section type undefined', 'warning')
104+
yield ValidationError(sec, 'Section type undefined', LABEL_WARNING)
102105

103106

104107
Validation.register_handler('section', section_type_must_be_defined)
@@ -113,21 +116,21 @@ def section_repository_present(sec):
113116
if repo is None:
114117
yield ValidationError(sec,
115118
'A section should have an associated repository',
116-
'warning')
119+
LABEL_WARNING)
117120
return
118121

119122
try:
120123
tsec = sec.get_terminology_equivalent()
121124
except Exception as exc:
122125
yield ValidationError(sec,
123126
'Could not load terminology: %s' % exc,
124-
'warning')
127+
LABEL_WARNING)
125128
return
126129

127130
if tsec is None:
128131
yield ValidationError(sec,
129132
"Section type '%s' not found in terminology" % sec.type,
130-
'warning')
133+
LABEL_WARNING)
131134

132135

133136
Validation.register_handler('section', section_repository_present)
@@ -226,7 +229,7 @@ def object_unique_names(obj, children, attr=lambda x: x.name,
226229
names = set()
227230
for i in children(obj):
228231
if attr(i) in names:
229-
yield ValidationError(i, msg, 'error')
232+
yield ValidationError(i, msg, LABEL_ERROR)
230233
names.add(attr(i))
231234

232235

@@ -265,7 +268,7 @@ def property_terminology_check(prop):
265268
except KeyError:
266269
yield ValidationError(prop,
267270
"Property '%s' not found in terminology" % prop.name,
268-
'warning')
271+
LABEL_WARNING)
269272

270273

271274
Validation.register_handler('property', property_terminology_check)
@@ -285,12 +288,12 @@ def property_dependency_check(prop):
285288
except KeyError:
286289
yield ValidationError(prop,
287290
"Property refers to a non-existent dependency object",
288-
'warning')
291+
LABEL_WARNING)
289292
return
290293

291294
if prop.dependency_value not in dep_obj.value[0]:
292295
yield ValidationError(prop, "Dependency-value is not equal to value of"
293-
" the property's dependency", 'warning')
296+
" the property's dependency", LABEL_WARNING)
294297

295298

296299
Validation.register_handler('property', property_dependency_check)

0 commit comments

Comments
 (0)