Skip to content

Commit

Permalink
Merge pull request #652 from IanCa/develop
Browse files Browse the repository at this point in the history
Update CHARACTER_INVALID and STYLE_WARNING tests.
  • Loading branch information
VisLab authored Apr 13, 2023
2 parents 46035b8 + c6f40ee commit 6f3d888
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
14 changes: 8 additions & 6 deletions hed/validator/tag_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def check_invalid_character_issues(self, hed_string):
"""
validation_issues = []
for index, character in enumerate(hed_string):
if character in TagValidator.INVALID_STRING_CHARS:
if character in TagValidator.INVALID_STRING_CHARS or ord(character) > 127:
validation_issues += self._report_invalid_character_error(hed_string, index)

return validation_issues
Expand Down Expand Up @@ -298,19 +298,20 @@ def check_tag_unit_class_units_are_valid(self, original_tag, report_tag_as=None,
stripped_value, unit = original_tag.get_stripped_unit_value()
if not unit:
bad_units = " " in original_tag.extension

had_error = False
# Todo: in theory this should separately validate the number and the units, for units
# that are prefixes like $. Right now those are marked as unit invalid AND value_invalid.
if bad_units:
stripped_value = stripped_value.split(" ")[0]
if original_tag.is_takes_value_tag() and\
not self._validate_value_class_portion(original_tag, stripped_value):
validation_issues += ErrorHandler.format_error(ValidationErrors.VALUE_INVALID,
report_tag_as if report_tag_as else original_tag,
actual_error=error_code)
report_tag_as if report_tag_as else original_tag)
if error_code:
had_error = True
validation_issues += ErrorHandler.format_error(ValidationErrors.VALUE_INVALID,
report_tag_as if report_tag_as else original_tag)
report_tag_as if report_tag_as else original_tag,
actual_error=error_code)


if bad_units:
Expand All @@ -325,7 +326,8 @@ def check_tag_unit_class_units_are_valid(self, original_tag, report_tag_as=None,
tag=report_tag_as if report_tag_as else original_tag,
default_unit=default_unit)

if error_code:
# We don't want to give this overall error twice
if error_code and not had_error:
new_issue = validation_issues[0].copy()
new_issue['code'] = error_code
validation_issues += [new_issue]
Expand Down
5 changes: 2 additions & 3 deletions spec_tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@

skip_tests = {
"VERSION_DEPRECATED": "Not applicable",
"CHARACTER_INVALID": "Not finalized",
"STYLE_WARNING": "Bad tests",
"onset-offset-error-duplicated-onset-or-offset": "TBD how we implement this",
"tag-extension-invalid-bad-node-name": "Part of character invalid checking",
"tag-extension-invalid-bad-node-name": "Part of character invalid checking/didn't get to it yet",
}

class MyTestCase(unittest.TestCase):
Expand Down Expand Up @@ -77,6 +75,7 @@ def run_single_test(self, test_file):
if name in skip_tests:
print(f"Skipping {name} test because: {skip_tests[name]}")
continue

description = info['description']
schema = info['schema']
check_for_warnings = info.get("warning", False)
Expand Down

0 comments on commit 6f3d888

Please sign in to comment.