Skip to content

Commit

Permalink
Merge pull request #791 from IanCa/develop
Browse files Browse the repository at this point in the history
Update check for prefix/minor unit typos
  • Loading branch information
VisLab authored Oct 27, 2023
2 parents 8977f83 + 49e9a45 commit 8bfc034
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion hed/errors/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ def val_warning_capitalization(tag):

@hed_tag_error(ValidationErrors.UNITS_MISSING, default_severity=ErrorSeverity.WARNING)
def val_warning_default_units_used(tag, default_unit):
# todo: add a test case for no default unit.
if default_unit is None:
return f"No unit specified on - '{tag}'. Multiple default values exist and cannot be inferred"
return f"No unit specified on - '{tag}'. No default unit is specified for type."
return f"No unit specified. Using '{default_unit}' as the default - '{tag}'"


Expand Down
1 change: 1 addition & 0 deletions hed/models/hed_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ def default_unit(self):
Returns:
unit(UnitEntry or None): the default unit entry for this tag, or None
"""
# todo: Make this cached
unit_classes = self.unit_classes.values()
if len(unit_classes) == 1:
first_unit_class_entry = list(unit_classes)[0]
Expand Down
2 changes: 2 additions & 0 deletions hed/validator/hed_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def run_basic_checks(self, hed_string, allow_placeholders):
return issues
if hed_string == "n/a" or not self._hed_schema:
return issues
for tag in hed_string.get_all_tags():
self._tag_validator.run_validate_tag_characters(tag, allow_placeholders=allow_placeholders)
issues += hed_string._calculate_to_canonical_forms(self._hed_schema)
if check_for_any_errors(issues):
return issues
Expand Down
17 changes: 15 additions & 2 deletions hed/validator/tag_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ def run_hed_string_validators(self, hed_string_obj, allow_placeholders=False):
validation_issues += self.check_tag_formatting(tag)
return validation_issues

def run_validate_tag_characters(self, original_tag, allow_placeholders):
""" Basic character validation of tags
Parameters:
original_tag (HedTag): A original tag.
allow_placeholders (bool): Allow value class or extensions to be placeholders rather than a specific value.
Returns:
list: The validation issues associated with the characters. Each issue is dictionary.
"""
return self.check_tag_invalid_chars(original_tag, allow_placeholders)

def run_individual_tag_validators(self, original_tag, allow_placeholders=False,
is_definition=False):
""" Runs the hed_ops on the individual tags.
Expand All @@ -77,11 +90,11 @@ def run_individual_tag_validators(self, original_tag, allow_placeholders=False,
is_definition (bool): This tag is part of a Definition, not a normal line.
Returns:
list: The validation issues associated with the top-level tags. Each issue is dictionary.
list: The validation issues associated with the tags. Each issue is dictionary.
"""
validation_issues = []
validation_issues += self.check_tag_invalid_chars(original_tag, allow_placeholders)
# validation_issues += self.check_tag_invalid_chars(original_tag, allow_placeholders)
if self._hed_schema:
validation_issues += self.check_tag_exists_in_schema(original_tag)
if original_tag.is_unit_class_tag():
Expand Down

0 comments on commit 8bfc034

Please sign in to comment.