Skip to content

Commit

Permalink
Merge pull request #1013 from VisLab/test_branch
Browse files Browse the repository at this point in the history
Updated error handling of definition groups
  • Loading branch information
VisLab authored Sep 13, 2024
2 parents a8fd639 + c29b515 commit 1eb1e3f
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 20 deletions.
8 changes: 7 additions & 1 deletion hed/models/definition_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,18 @@ def _find_group(self, definition_tag, group, error_handler):
# initial validation
groups = group.groups()
issues = []
tags = group.tags()
# if len(tags) != 1:
# issues += \
# ErrorHandler.format_error_with_context(error_handler,
# DefinitionErrors.WRONG_NUMBER_TAGS,
# def_name=definition_tag.extension, tag_list=tags)
if len(groups) > 1:
issues += \
ErrorHandler.format_error_with_context(error_handler,
DefinitionErrors.WRONG_NUMBER_GROUPS,
def_name=definition_tag.extension, tag_list=groups)
elif len(groups) == 0:
elif len(groups) == 0 and '#' in definition_tag.extension:
issues += \
ErrorHandler.format_error_with_context(error_handler,
DefinitionErrors.NO_DEFINITION_CONTENTS,
Expand Down
121 changes: 121 additions & 0 deletions hed/validator/specialTags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"Definition": {
"child": true,
"requireChild": true,
"tagGroup": true,
"topLevelTagGroup": true,
"maxNumberSubgroups": 1,
"minNumberSubgroups": 0,
"ERROR_CODE": "DEFINITION_INVALID",
"subgroupTagsNotAllowed": [
"Def",
"Def-expand",
"Event-context",
"Definition",
"Onset",
"Inset",
"Offset",
"Delay",
"Duration"
],
"defTagRequired": false,
"otherAllowedTags": []
},
"Def": {
"child": true,
"tagGroup": false,
"topLevelTagGroup": false,
"maxNumberSubgroups": null,
"minNumberSubgroups": null,
"ERROR_CODE": "DEF_INVALID",
"subgroupTagsNotAllowed": [],
"defTagRequired": false,
"otherAllowedTags": null
},
"Def-expand": {
"child": true,
"tagGroup": true,
"topLevelTagGroup": false,
"maxNumberSubgroups": 1,
"minNumberSubgroups": 0,
"ERROR_CODE": "DEF_EXPAND_INVALID",
"subgroupTagsNotAllowed": [
"Def",
"Def-expand",
"Event-context",
"Definition",
"Onset",
"Inset",
"Offset",
"Delay",
"Duration"
],
"defTagRequired": false,
"otherAllowedTags": []
},
"Onset": {
"child": false,
"tagGroup": true,
"topLevelTagGroup": true,
"maxNumberSubgroups": 1,
"minNumberSubgroups": 0,
"ERROR_CODE": "TEMPORAL_TAG_ERROR",
"subgroupTagsNotAllowed": ["Event-context", "Definition", "Onset", "Inset", "Offset", "Delay", "Duration"],
"defTagRequired": true,
"otherAllowedTags": []
},
"Inset": {
"child": false,
"tagGroup": true,
"topLevelTagGroup": true,
"maxNumberSubgroups": 1,
"minNumberSubgroups": 0,
"ERROR_CODE": "TEMPORAL_TAG_ERROR",
"subgroupTagsNotAllowed": ["Event-context", "Definition", "Onset", "Inset", "Offset", "Delay", "Duration"],
"defTagRequired": true,
"otherAllowedTags": []
},
"Offset": {
"child": false,
"tagGroup": true,
"topLevelTagGroup": true,
"maxNumberSubgroups": 0,
"minNumberSubgroups": 0,
"ERROR_CODE": "TEMPORAL_TAG_ERROR",
"subgroupTagsNotAllowed": [],
"defTagRequired": true,
"otherAllowedTags": []
},
"Delay": {
"child": true,
"tagGroup": true,
"topLevelTagGroup": true,
"maxNumberSubgroups": 1,
"minNumberSubgroups": 1,
"ERROR_CODE": "TEMPORAL_TAG_ERROR",
"subgroupTagsNotAllowed": ["Event-context", "Definition", "Onset", "Inset", "Offset", "Delay", "Duration"],
"defTagRequired": false,
"otherAllowedTags": ["Duration"]
},
"Duration": {
"child": true,
"topLevelTagGroup": true,
"maxNumberSubgroups": 1,
"minNumberSubgroups": 1,
"ERROR_CODE": "TEMPORAL_TAG_ERROR",
"subgroupTagsNotAllowed": ["Event-context", "Definition", "Onset", "Inset", "Offset", "Delay", "Duration"],
"defTagRequired": false,
"otherAllowedTags": ["Delay"]
},
"Event-context": {
"child": false,
"tagGroup": true,
"topLevelTagGroup": true,
"maxNumberSubgroups": null,
"minNumberSubgroups": 0,
"ERROR_CODE": "TAG_GROUP_ERROR",
"subgroupTagsNotAllowed": ["Event-context", "Definition", "Onset", "Inset", "Offset", "Delay", "Duration"],
"defTagRequired": false,
"otherAllowedTags": []
}
}
42 changes: 23 additions & 19 deletions tests/models/test_definition_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ def test_definitions(self):
'noGroupTag': "(Definition/InvalidDef0)",
'placeholderNoGroupTag': "(Definition/InvalidDef1/#)",
'placeholderWrongSpot': "(Definition/InvalidDef1#)",
'twoDefTags': f"(Definition/ValidDef1,Definition/InvalidDef2,{self.def_contents_string})",
'twoDefTags': f"(Definition/InvalidDef1,Definition/InvalidDef2,{self.def_contents_string})",
'twoGroupTags': f"(Definition/InvalidDef1,{self.def_contents_string},{self.def_contents_string2})",
'extraValidTags': "(Definition/InvalidDefA, Red, Blue)",
'extraOtherTags': "(Definition/InvalidDef1, InvalidContents)",
'duplicateDef': f"(Definition/Def1, {self.def_contents_string}), (Definition/Def1, {self.def_contents_string})",
'duplicateDef2': f"(Definition/Def1, {self.def_contents_string}), (Definition/Def1/#, {self.placeholder_def_contents})",
Expand All @@ -77,35 +78,37 @@ def test_definitions(self):
'placeholdersWrongSpot': f"(Definition/InvalidDef/#, (Age/#,Item/TestDef2))",
}
expected_results = {
'noGroupTag': self.format_error(DefinitionErrors.NO_DEFINITION_CONTENTS,
"InvalidDef0"),
'placeholderNoGroupTag': self.format_error(DefinitionErrors.NO_DEFINITION_CONTENTS,"InvalidDef1/#"),
'placeholderWrongSpot': self.format_error(DefinitionErrors.NO_DEFINITION_CONTENTS,"InvalidDef1#") + self.format_error(DefinitionErrors.INVALID_DEFINITION_EXTENSION,
tag=0, def_name="InvalidDef1#"),
'twoDefTags': self.format_error(DefinitionErrors.WRONG_NUMBER_TAGS,
"ValidDef1", ["Definition/InvalidDef2"]),
'twoGroupTags': self.format_error(DefinitionErrors.WRONG_NUMBER_GROUPS,
"InvalidDef1",
[self.def_contents_string, self.def_contents_string2]),
'extraOtherTags': self.format_error(DefinitionErrors.NO_DEFINITION_CONTENTS, "InvalidDef1")
+ self.format_error(DefinitionErrors.WRONG_NUMBER_TAGS, "InvalidDef1", ['InvalidContents']),
'noGroupTag': [],
'placeholderNoGroupTag': self.format_error(DefinitionErrors.NO_DEFINITION_CONTENTS, "InvalidDef1/#"),
'placeholderWrongSpot': self.format_error(DefinitionErrors.NO_DEFINITION_CONTENTS, "InvalidDef1#") +
self.format_error(DefinitionErrors.INVALID_DEFINITION_EXTENSION,
tag=0, def_name="InvalidDef1#"),
'twoDefTags': self.format_error(DefinitionErrors.WRONG_NUMBER_TAGS, "InvalidDef1",
["Definition/InvalidDef2"]),
'twoGroupTags': self.format_error(DefinitionErrors.WRONG_NUMBER_GROUPS, "InvalidDef1",
[self.def_contents_string, self.def_contents_string2]),
'extraValidTags': self.format_error(DefinitionErrors.WRONG_NUMBER_TAGS, "InvalidDefA",
["Red", "Blue"]),
'extraOtherTags': self.format_error(DefinitionErrors.WRONG_NUMBER_TAGS, "InvalidDef1",
["InvalidContents"]),
'duplicateDef': self.format_error(DefinitionErrors.DUPLICATE_DEFINITION, "Def1"),
'duplicateDef2': self.format_error(DefinitionErrors.DUPLICATE_DEFINITION, "Def1"),

'defTooManyPlaceholders': self.format_error(DefinitionErrors.WRONG_NUMBER_PLACEHOLDER_TAGS,
"TestDefPlaceholder", expected_count=1,
tag_list=["Age/#", "Item/TestDef2/#"]),
"TestDefPlaceholder", expected_count=1,
tag_list=["Age/#", "Item/TestDef2/#"]),
'invalidPlaceholderExtension': self.format_error(DefinitionErrors.INVALID_DEFINITION_EXTENSION,
tag=0, def_name="InvalidDef1/this-part-is-not-allowed"),
tag=0, def_name="InvalidDef1/this-part-is-not-allowed"),
'invalidPlaceholder': self.format_error(DefinitionErrors.INVALID_DEFINITION_EXTENSION,
tag=0, def_name="InvalidDef1/InvalidPlaceholder"),
tag=0, def_name="InvalidDef1/InvalidPlaceholder"),
'defInGroup': self.format_error(DefinitionErrors.DEF_TAG_IN_DEFINITION,
tag=HedTag("Def/ImproperlyPlacedDef", self.hed_schema), def_name="ValidDefName"),
tag=HedTag("Def/ImproperlyPlacedDef", self.hed_schema),
def_name="ValidDefName"),
'defExpandInGroup': self.format_error(DefinitionErrors.DEF_TAG_IN_DEFINITION,
tag=HedTag("Def-expand/ImproperlyPlacedDef", self.hed_schema),
def_name="ValidDefName"),
'doublePoundSignPlaceholder': self.format_error(DefinitionErrors.INVALID_DEFINITION_EXTENSION,
tag=0, def_name="InvalidDef/##"),
tag=0, def_name="InvalidDef/##"),
'doublePoundSignDiffPlaceholder': self.format_error(DefinitionErrors.WRONG_NUMBER_PLACEHOLDER_TAGS,
"InvalidDef", expected_count=1, tag_list=['Age/##']),
'placeholdersWrongSpot': []
Expand Down Expand Up @@ -144,5 +147,6 @@ def test_altering_definition_contents(self):

self.assertNotEqual(hed_string1, hed_string2)


if __name__ == '__main__':
unittest.main()

0 comments on commit 1eb1e3f

Please sign in to comment.