Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/nexusformat/nexus/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,14 @@ def validate_group(self, xml_dict, nxgroup, indent=0):
for key, value in xml_dict.items():
if key == 'group':
for group in value:
recommended = False
if '@minOccurs' in value[group]:
minOccurs = int(value[group]['@minOccurs'])
elif value[group].get('@optional') == 'true':
minOccurs = 0
elif value[group].get('@recommended') == 'true':
minOccurs = 0
recommended = True
else:
minOccurs = 1
if '@type' in value[group]:
Expand All @@ -1078,7 +1084,11 @@ def validate_group(self, xml_dict, nxgroup, indent=0):
f'{len(nxgroups)} {group} group(s) '
f'are in the NeXus file. At least {minOccurs} '
'are required', level='error')
elif minOccurs == 0:
elif len(nxgroups) == 0 and recommended:
self.log(
'This recommended group is not in the NeXus file',
level='warning')
elif len(nxgroups) == 0:
self.log(
'This optional group is not in the NeXus file')
for i, nxsubgroup in enumerate(nxgroups):
Expand All @@ -1098,8 +1108,14 @@ def validate_group(self, xml_dict, nxgroup, indent=0):
self.output_log()
elif key == 'field' or key == 'link':
for field in value:
recommended = False
if '@minOccurs' in value[field]:
minOccurs = int(value[field]['@minOccurs'])
elif value[field].get('@optional') == 'true':
minOccurs = 0
elif value[field].get('@recommended') == 'true':
minOccurs = 0
recommended = True
else:
minOccurs = 1
if field in nxgroup.entries:
Expand All @@ -1116,6 +1132,9 @@ def validate_group(self, xml_dict, nxgroup, indent=0):
if minOccurs > 0:
self.log(f'This required {key} is not '
'in the NeXus file', level='error')
elif recommended:
self.log(f'This recommended {key} is not '
'in the NeXus file', level='warning')
else:
self.log(f'This optional {key}) is not '
'in the NeXus file')
Expand Down