@@ -65,7 +65,7 @@ def __init__(self, doc):
6565 self .doc = doc # may also be a section
6666 self .errors = []
6767 self .validate (doc )
68- # TODO isn't there a 'walk' method for these things?
68+
6969 for sec in doc .itersections (recursive = True ):
7070 self .validate (sec )
7171 for prop in sec .properties :
@@ -100,56 +100,61 @@ def section_type_must_be_defined(sec):
100100 if sec .type is None or sec .type == '' or sec .type == 'undefined' :
101101 yield ValidationError (sec , 'Section type undefined' , 'warning' )
102102
103+
103104Validation .register_handler ('section' , section_type_must_be_defined )
104105
105106
106- def section_repository_should_be_present (sec ):
107+ def section_repository_present (sec ):
107108 """
108109 1. warn, if a section has no repository or
109110 2. the section type is not present in the repository
110111 """
111112 repo = sec .get_repository ()
112113 if repo is None :
113- yield ValidationError (sec , 'A section should have an associated '
114- 'repository' , 'warning' )
114+ yield ValidationError (sec ,
115+ 'A section should have an associated repository' ,
116+ 'warning' )
115117 return
116118
117119 try :
118120 tsec = sec .get_terminology_equivalent ()
119- except Exception as e :
120- yield ValidationError (sec , 'Could not load terminology: %s' % e ,
121- 'warning' )
121+ except Exception as exc :
122+ yield ValidationError (sec ,
123+ 'Could not load terminology: %s' % exc ,
124+ 'warning' )
122125 return
123126
124127 if tsec is None :
125- yield ValidationError (sec , "Section type '%s' not found in terminology" % sec .type ,
126- 'warning' )
128+ yield ValidationError (sec ,
129+ "Section type '%s' not found in terminology" % sec .type ,
130+ 'warning' )
127131
128- Validation .register_handler ('section' , section_repository_should_be_present )
132+
133+ Validation .register_handler ('section' , section_repository_present )
129134
130135
131136def document_unique_ids (doc ):
132137 id_map = {doc .id : "Document '%s'" % doc .get_path ()}
133- for e in section_unique_ids (doc , id_map ):
134- yield e
138+ for i in section_unique_ids (doc , id_map ):
139+ yield i
135140
136141
137142def section_unique_ids (parent , id_map = None ):
138143 if not id_map :
139144 id_map = {}
140145
141146 for sec in parent .sections :
142- for e in property_unique_ids (sec , id_map ):
143- yield e
147+ for i in property_unique_ids (sec , id_map ):
148+ yield i
144149
145150 if sec .id in id_map :
146151 yield ValidationError (sec , "Duplicate id in Section '%s' and '%s'" %
147152 (sec .get_path (), id_map [sec .id ]))
148153 return
149154 id_map [sec .id ] = "Section '%s'" % sec .get_path ()
150155
151- for e in section_unique_ids (sec , id_map ):
152- yield e
156+ for i in section_unique_ids (sec , id_map ):
157+ yield i
153158
154159
155160def property_unique_ids (parent , id_map = None ):
@@ -182,13 +187,13 @@ def object_unique_names(obj, children, attr=lambda x: x.name,
182187 if len (names ) == len (children (obj )):
183188 return # quick exit
184189 names = set ()
185- for s in children (obj ):
186- if attr (s ) in names :
187- yield ValidationError (s , msg , 'error' )
188- names .add (attr (s ))
190+ for i in children (obj ):
191+ if attr (i ) in names :
192+ yield ValidationError (i , msg , 'error' )
193+ names .add (attr (i ))
189194
190195
191- def section_unique_name_type_combination (obj ):
196+ def section_unique_name_type (obj ):
192197 for i in object_unique_names (
193198 obj ,
194199 attr = lambda x : (x .name , x .type ),
@@ -201,8 +206,9 @@ def property_unique_names(obj):
201206 for i in object_unique_names (obj , lambda x : x .properties ):
202207 yield i
203208
204- Validation .register_handler ('odML' , section_unique_name_type_combination )
205- Validation .register_handler ('section' , section_unique_name_type_combination )
209+
210+ Validation .register_handler ('odML' , section_unique_name_type )
211+ Validation .register_handler ('section' , section_unique_name_type )
206212Validation .register_handler ('section' , property_unique_names )
207213
208214
@@ -221,8 +227,10 @@ def property_terminology_check(prop):
221227 tprop = tsec .properties [prop .name ]
222228 except KeyError :
223229 tprop = None
224- yield ValidationError (prop , "Property '%s' not found in terminology" %
225- prop .name , 'warning' )
230+ yield ValidationError (prop ,
231+ "Property '%s' not found in terminology" % prop .name ,
232+ 'warning' )
233+
226234
227235Validation .register_handler ('property' , property_terminology_check )
228236
@@ -239,12 +247,14 @@ def property_dependency_check(prop):
239247 try :
240248 dep_obj = prop .parent [dep ]
241249 except KeyError :
242- yield ValidationError (prop , "Property refers to a non-existent "
243- "dependency object" , 'warning' )
250+ yield ValidationError (prop ,
251+ "Property refers to a non-existent dependency object" ,
252+ 'warning' )
244253 return
245254
246- if prop .dependency_value not in dep_obj .value [0 ]: # FIXME
255+ if prop .dependency_value not in dep_obj .value [0 ]:
247256 yield ValidationError (prop , "Dependency-value is not equal to value of"
248257 " the property's dependency" , 'warning' )
249258
259+
250260Validation .register_handler ('property' , property_dependency_check )
0 commit comments