Skip to content

Commit

Permalink
#108 w-i-p
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Jul 2, 2018
1 parent 91f9516 commit 7aa86cb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
2 changes: 1 addition & 1 deletion _starter_.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# developer use
if len(sys.argv) == 1:
sys.argv.append("tree")
sys.argv.append("valid")
sys.argv.append("src/punx/data/33837rear_1D_1.75_16.5_NXcanSAS_v3.h5")
# # sys.argv.append("C:/Users/Pete/Downloads/1998spheres.h5")
# # sys.argv.append("src/punx/cache/v3.3/applications/NXcanSAS.nxdl.xml")
Expand Down
54 changes: 45 additions & 9 deletions src/punx/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,28 +344,64 @@ def validate_application_definition(self, v_item):
"""
validate group as a NeXus application definition
"""
appl_def_name = utils.decode_byte_string(v_item.h5_object["definition"].value)
# TODO: move this code to validations/ subdir
ad_name = utils.decode_byte_string(v_item.h5_object["definition"].value)
key = "NeXus application definition"

known = appl_def_name in self.manager.classes
status = finding.TF_RESULT[known]
msg = appl_def_name + ": recognized NXDL specification"
ad = self.manager.classes.get(ad_name)
status = finding.TF_RESULT[ad is not None]
msg = ad_name + ": recognized NXDL specification"
self.record_finding(v_item, "known NXDL", status, msg)
if ad is None:
return

msg = appl_def_name
if self.manager.classes[appl_def_name].category == "applications":
msg = ad_name
if ad.category == "applications":
msg += ": known NeXus application definition"
elif self.manager.classes[appl_def_name].category == "contributed":
elif ad.category == "contributed":
msg += ": known NeXus contributed definition used as application definition"
else:
status = finding.ERROR
msg += ": unknown application definition"
self.record_finding(v_item, key, status, msg)

c = appl_def_name + ": more validations needed"
c = ad_name + ": more validations needed"
self.record_finding(v_item, key, finding.TODO, c)

# TODO:
# TODO: groups, attributes, links, type, ...
ad_entry = list(ad.groups.values())[0] # only 1 at this level of the application definition (ad)
for field, spec in ad_entry.fields.items():

msg = "%s:%s" % (ad_name, field)
h5_obj = v_item.h5_object.get(field)
status = finding.TF_RESULT[h5_obj is not None]
if h5_obj is None:
msg += " not"
msg += " found"
v_obj = ValidationItem(v_item, h5_obj)
self.record_finding(v_obj, "NXDL field", status, msg)

if len(spec.enumerations) > 0:
found = False
for enum in spec.enumerations:
found = enum == utils.decode_byte_string(h5_obj.value)
if found:
break
msg = "%s:%s" % (ad_name, field)
required = spec.xml_attributes["minOccurs"].default_value == 1 # TODO: is this right?
if required:
msg += " (required)"
else:
msg += " (optional)"
status = finding.TF_RESULT[found]
if found:
msg += " has expected value: " + enum
else:
msg += " does not have value: " + " | ".join(spec.enumerations)
self.record_finding(v_obj, "NXDL field enumerations", status, msg)

# TODO: attributes, xml_attributes, dimensions, ...


def validate_NX_class_attribute(self, v_item, nx_class):
from .validations import nx_class_attribute
Expand Down

0 comments on commit 7aa86cb

Please sign in to comment.