Skip to content
Merged
Show file tree
Hide file tree
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
70 changes: 16 additions & 54 deletions hedvalidation/hed/validator/tag_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class TagValidator:
UNIT_SYMBOL_TYPE = 'unitSymbol'
UNITS_ELEMENT = 'units'
VALID_ERROR_TYPE = 'invalidTag'
OPENING_GROUP_parentheses = '('
CLOSING_GROUP_parentheses = ')'
OPENING_GROUP_CHARACTER = '('
CLOSING_GROUP_CHARACTER = ')'
DOUBLE_QUOTE = '"'
COMMA = ','
TILDE = '~'
Expand Down Expand Up @@ -198,7 +198,7 @@ def run_hed_string_validators(self, hed_string):
validation_issues = []
validation_issues += self.find_invalid_character_issues(hed_string)
validation_issues += self.count_tag_group_parentheses(hed_string)
validation_issues += self.find_comma_issues_in_hed_string(hed_string)
validation_issues += self.find_delimiter_issues_in_hed_string(hed_string)
return validation_issues

def run_tag_level_validators(self, original_tag_list, formatted_tag_list):
Expand Down Expand Up @@ -829,7 +829,7 @@ def get_tag_substring_by_end_index(self, tag, end_index):
return tag[:end_index]
return tag

def find_comma_issues_in_hed_string(self, hed_string): # rewrite this to fix issue 3
def find_delimiter_issues_in_hed_string(self, hed_string):
"""Reports a validation error if there are missing commas or commas in tags that take values.

Parameters
Expand All @@ -855,28 +855,28 @@ def find_comma_issues_in_hed_string(self, hed_string): # rewrite this to fix is
if TagValidator.character_is_delimiter(current_character):
if current_tag.strip() == current_character:
issues += error_reporter.report_error_type('extraDelimiter',
character=current_character,
index=i,
hed_string=hed_string)
character=current_character,
index=i,
hed_string=hed_string)
current_tag = ''
continue
current_tag = ''
elif current_character == self.OPENING_GROUP_parentheses:
if current_tag.strip() == self.OPENING_GROUP_parentheses:
elif current_character == self.OPENING_GROUP_CHARACTER:
if current_tag.strip() == self.OPENING_GROUP_CHARACTER:
current_tag = ''
else:
issues += error_reporter.report_error_type('invalidTag', tag=current_tag)
elif TagValidator.comma_is_missing_after_closing_parentheses(last_non_empty_valid_character,
current_character):
issues += error_reporter.report_error_type('commaMissing', tag=current_tag)
current_character):
issues += error_reporter.report_error_type('commaMissing', tag=current_tag[:-1])
break
last_non_empty_valid_character = current_character
last_non_empty_valid_index = i
if TagValidator.character_is_delimiter(last_non_empty_valid_character):
issues += error_reporter.report_error_type('extraDelimiter',
character=last_non_empty_valid_character,
index=last_non_empty_valid_index,
hed_string=hed_string)
character=last_non_empty_valid_character,
index=last_non_empty_valid_index,
hed_string=hed_string)
return issues

def skip_iterations(self, iterator, start, end):
Expand Down Expand Up @@ -922,43 +922,6 @@ def report_invalid_character_error(character, index, hed_string):
return error_reporter.report_error_type(TagValidator.CHARACTER_ERROR_TYPE, character=character, index=index,
hed_string=hed_string)

@staticmethod
def report_missing_comma_error(error_tag):
"""Reports a error that is related with a missing comma.

Parameters
----------
error_tag: str
The tag that caused the error.
Returns
-------
string
The error message associated with a missing comma.

"""
error_tag = error_tag[:-1].strip()
return error_reporter.report_error_type(TagValidator.COMMA_ERROR_TYPE, tag=error_tag)

@staticmethod
def comma_is_missing_before_opening_parentheses(last_non_empty_character, current_character):
"""Checks to see if a comma is missing before a opening parentheses in a HED string. This is a helper function for
the find_missing_commas_in_hed_string function.

Parameters
----------
last_non_empty_character: character
The last non-empty string in the HED string.
current_character: str
The current character in the HED string.
Returns
-------
bool
True if a comma is missing before a opening parentheses. False, if otherwise.

"""
return last_non_empty_character and not TagValidator.character_is_delimiter(last_non_empty_character) and \
current_character == TagValidator.OPENING_GROUP_parentheses

@staticmethod
def comma_is_missing_after_closing_parentheses(last_non_empty_character, current_character):
"""Checks to see if a comma is missing after a closing parentheses in a HED string. This is a helper function for
Expand All @@ -976,9 +939,8 @@ def comma_is_missing_after_closing_parentheses(last_non_empty_character, current
True if a comma is missing after a closing parentheses. False, if otherwise.

"""
return last_non_empty_character == TagValidator.CLOSING_GROUP_parentheses and not \
(TagValidator.character_is_delimiter(current_character)
or current_character == TagValidator.CLOSING_GROUP_parentheses)
return last_non_empty_character == TagValidator.CLOSING_GROUP_CHARACTER and not \
TagValidator.character_is_delimiter(current_character)

@staticmethod
def character_is_delimiter(character):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ def test_tag_takes_value(self):
takes_value_tag = self.tag_validator.tag_takes_value(self.valid_formatted_tag)
self.assertFalse(takes_value_tag)

def test_is_numeric_tag(self):
numeric_tag = self.tag_validator.is_numeric_tag(self.valid_formatted_is_numeric_tag)
self.assertTrue(numeric_tag)

def test_is_unit_class_tag(self):
unit_class_tag = self.tag_validator.is_unit_class_tag(self.valid_formatted_unit_class_tag)
self.assertTrue(unit_class_tag)
Expand Down Expand Up @@ -263,39 +259,39 @@ def test_check_if_tag_unit_class_units_are_valid(self):
self.assertTrue(validation_error)
self.assertIsInstance(validation_error, str)

def test_count_tag_group_brackets(self):
validation_error = self.tag_validator.count_tag_group_brackets(self.valid_hed_string)
def test_count_tag_group_parentheses(self):
validation_error = self.tag_validator.count_tag_group_parentheses(self.valid_hed_string)
self.assertFalse(validation_error)
self.assertIsInstance(validation_error, str)
validation_error = self.tag_validator.count_tag_group_brackets(self.invalid_hed_string)
validation_error = self.tag_validator.count_tag_group_parentheses(self.invalid_hed_string)
self.assertTrue(validation_error)
self.assertIsInstance(validation_error, str)

def test_find_missing_commas_in_hed_string(self):
validation_error = self.tag_validator.find_comma_issues_in_hed_string(self.valid_hed_string)
def test_find_delimiter_issues_in_hed_string(self):
validation_error = self.tag_validator.find_delimiter_issues_in_hed_string(self.valid_hed_string)
self.assertFalse(validation_error)
self.assertIsInstance(validation_error, str)
validation_error = self.tag_validator.find_comma_issues_in_hed_string(self.missing_comma_hed_string)
validation_error = self.tag_validator.find_delimiter_issues_in_hed_string(self.missing_comma_hed_string)
self.assertTrue(validation_error)
self.assertIsInstance(validation_error, str)
validation_error = \
self.tag_validator.find_comma_issues_in_hed_string(self.valid_formatted_tag_with_parentheses)
self.tag_validator.find_delimiter_issues_in_hed_string(self.valid_formatted_tag_with_parentheses)
self.assertFalse(validation_error)
self.assertIsInstance(validation_error, str)
validation_error = \
self.tag_validator.find_comma_issues_in_hed_string(self.invalid_formatted_tag_with_parentheses)
self.tag_validator.find_delimiter_issues_in_hed_string(self.invalid_formatted_tag_with_parentheses)
self.assertTrue(validation_error)
self.assertIsInstance(validation_error, str)
validation_error = \
self.tag_validator.find_comma_issues_in_hed_string(self.valid_formatted_tag_with_parentheses_group)
self.tag_validator.find_delimiter_issues_in_hed_string(self.valid_formatted_tag_with_parentheses_group)
self.assertFalse(validation_error)
self.assertIsInstance(validation_error, str)
validation_error = \
self.tag_validator.find_comma_issues_in_hed_string(self.hed_string_ending_with_parentheses)
self.tag_validator.find_delimiter_issues_in_hed_string(self.hed_string_ending_with_parentheses)
self.assertFalse(validation_error)
self.assertIsInstance(validation_error, str)
validation_error = \
self.tag_validator.find_comma_issues_in_hed_string(self.valid_formatted_tag_with_complex_parentheses)
self.tag_validator.find_delimiter_issues_in_hed_string(self.valid_formatted_tag_with_complex_parentheses)
self.assertFalse(validation_error)
self.assertIsInstance(validation_error, str)

Expand All @@ -314,36 +310,22 @@ def test_tag_is_valid(self):
tag_is_valid = self.tag_validator.tag_exists_in_schema(self.invalid_formatted_tag)
self.assertFalse(tag_is_valid)

def test_is_hh_mm_time(self):
validation_error = TagValidator.is_hh_mm_time(self.valid_time_string)
def test_is_clock_face_time(self):
validation_error = TagValidator.is_clock_face_time(self.valid_time_string)
self.assertTrue(validation_error, str)
validation_error = TagValidator.is_hh_mm_time(self.invalid_time_string)
validation_error = TagValidator.is_clock_face_time(self.invalid_time_string)
self.assertFalse(validation_error, str)

def test_comma_is_missing_after_closing_bracket(self):
comma_is_missing = \
self.tag_validator.comma_is_missing_after_closing_bracket(self.last_non_empty_character_not_delimiter,
self.tag_validator.comma_is_missing_after_closing_parentheses(self.last_non_empty_character_not_delimiter,
self.current_character)
self.assertTrue(comma_is_missing)
comma_is_missing = \
self.tag_validator.comma_is_missing_after_closing_bracket(self.last_non_empty_character_delimiter,
self.tag_validator.comma_is_missing_after_closing_parentheses(self.last_non_empty_character_delimiter,
self.current_character)
self.assertFalse(comma_is_missing)

def test_comma_is_missing_before_opening_bracket(self):
comma_is_missing = \
self.tag_validator.comma_is_missing_before_opening_bracket(self.last_non_empty_character_not_delimiter,
self.current_opening_bracket_character)
self.assertTrue(comma_is_missing)
comma_is_missing = \
self.tag_validator.comma_is_missing_before_opening_bracket(self.last_non_empty_character_delimiter,
self.current_opening_bracket_character)
self.assertFalse(comma_is_missing)

def test_report_missing_comma_error(self):
missing_comma_error = TagValidator.report_missing_comma_error(self.invalid_original_tag)
self.assertTrue(missing_comma_error)

def test_check_if_duplicate_tags_exist(self):
validation_error = self.tag_validator.check_if_duplicate_tags_exist(self.valid_original_duplicate_tag_list,
self.valid_formatted_duplicate_tag_list)
Expand Down
22 changes: 11 additions & 11 deletions hedvalidation/tests/test_hed_input_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setUpClass(cls):
cls.attribute_onset_tag = 'Attribute/Onset'
cls.category_partipant_and_stimulus_tags = 'Event/Category/Participant response,Event/Category/Stimulus'
cls.category_tags = 'Participant response, Stimulus'
cls.validation_issues = ''
cls.validation_issues = []
cls.semantic_version_one = '1.2.3'
cls.semantic_version_two = '1.2.4'
cls.semantic_version_three = '1.2.5'
Expand All @@ -48,30 +48,30 @@ def test__convert_tag_columns_to_processing_format(self):

def test__validate_hed_input(self):
validation_issues = self.generic_hed_input_reader._validate_hed_input()
self.assertIsInstance(validation_issues, str)
self.assertIsInstance(validation_issues, list)

def test__validate_individual_tags_in_hed_string(self):
hed_string_delimiter = HedStringDelimiter(self.hed_string_with_invalid_tags)
validation_issues = self.generic_hed_input_reader._validate_individual_tags_in_hed_string(hed_string_delimiter)
self.assertIsInstance(validation_issues, str)
self.assertIsInstance(validation_issues, list)
self.assertTrue(validation_issues)

def test__validate_top_levels_in_hed_string(self):
hed_string_delimiter = HedStringDelimiter(self.hed_string_with_no_required_tags)
validation_issues = self.generic_hed_input_reader._validate_top_level_in_hed_string(hed_string_delimiter)
self.assertIsInstance(validation_issues, str)
self.assertIsInstance(validation_issues, list)
self.assertFalse(validation_issues)

def test__validate_tag_levels_in_hed_string(self):
hed_string_delimiter = HedStringDelimiter(self.hed_string_with_multiple_unique_tags)
validation_issues = self.generic_hed_input_reader._validate_tag_levels_in_hed_string(hed_string_delimiter)
self.assertIsInstance(validation_issues, str)
self.assertIsInstance(validation_issues, list)
self.assertTrue(validation_issues)

def test__validate_groups_in_hed_string(self):
hed_string_delimiter = HedStringDelimiter(self.hed_string_with_too_many_tildes)
validation_issues = self.generic_hed_input_reader._validate_groups_in_hed_string(hed_string_delimiter)
self.assertIsInstance(validation_issues, str)
self.assertIsInstance(validation_issues, list)
self.assertTrue(validation_issues)

def test__append_validation_issues_if_found(self):
Expand All @@ -82,7 +82,7 @@ def test__append_validation_issues_if_found(self):
row_number,
self.hed_string_with_invalid_tags,
self.column_to_hed_tags_dictionary)
self.assertIsInstance(validation_issues, str)
self.assertIsInstance(validation_issues, list)
self.assertFalse(validation_issues)

def test__append_row_validation_issues_if_found(self):
Expand All @@ -92,7 +92,7 @@ def test__append_row_validation_issues_if_found(self):
self.generic_hed_input_reader._append_row_validation_issues_if_found(self.validation_issues,
row_number,
self.hed_string_with_invalid_tags)
self.assertIsInstance(validation_issues, str)
self.assertIsInstance(validation_issues, list)
self.assertFalse(validation_issues)

def test__append_column_validation_issues_if_found(self):
Expand All @@ -102,18 +102,18 @@ def test__append_column_validation_issues_if_found(self):
self.generic_hed_input_reader._append_column_validation_issues_if_found(self.validation_issues,
row_number,
self.column_to_hed_tags_dictionary)
self.assertIsInstance(validation_issues, str)
self.assertIsInstance(validation_issues, list)
self.assertFalse(validation_issues)

def test_validate_column_hed_string(self):
self.assertFalse(self.validation_issues)
validation_issues = self.generic_hed_input_reader.validate_column_hed_string(self.hed_string_with_invalid_tags)
self.assertIsInstance(validation_issues, str)
self.assertIsInstance(validation_issues, list)
self.assertTrue(validation_issues)

def test_get_validation_issues(self):
validation_issues = self.generic_hed_input_reader.get_validation_issues()
self.assertIsInstance(validation_issues, str)
self.assertIsInstance(validation_issues, list)

def test_get_file_extension(self):
file_extension = HedInputReader.get_file_extension(self.text_file_with_extension)
Expand Down
9 changes: 8 additions & 1 deletion hedvalidation/tests/test_hed_string_delimiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ def setUpClass(cls):
cls.group_hed_string = '(tag1, tag2)'
cls.empty_hed_string = ''
cls.newline_hed_string = '\n'
cls.space_hed_string = ' '
cls.space_tab_hed_string = ' \t '
cls.removal_elements = ['(tag2,tag5,(tag1),tag6)', '(tag3,tag5,tag6)']
cls.unformatted_tag = '/Event/label/This label ends with a slash/'
cls.formatted_tag = 'event/label/this label ends with a slash'

def test_split_hed_string_into_list(self):
split_hed_string = HedStringDelimiter.split_hed_string_into_list(self.mixed_hed_string)
hed_string_delimiter = HedStringDelimiter(self.mixed_hed_string)
split_hed_string = hed_string_delimiter.split_hed_string_into_list(self.mixed_hed_string)
self.assertTrue(split_hed_string)
self.assertIsInstance(split_hed_string, list)

Expand Down Expand Up @@ -141,6 +144,10 @@ def test_string_is_space_or_empty(self):
self.assertTrue(is_space_or_empty)
is_space_or_empty = HedStringDelimiter.string_is_space_or_empty(self.newline_hed_string)
self.assertTrue(is_space_or_empty)
is_space_or_empty = HedStringDelimiter.string_is_space_or_empty(self.space_hed_string)
self.assertTrue(is_space_or_empty)
is_space_or_empty = HedStringDelimiter.string_is_space_or_empty(self.space_tab_hed_string)
self.assertTrue(is_space_or_empty)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion hedvalidation/tests/test_translation_hed.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_malformed_delimiters(self):
expected_issues = {
# NOT COMPLETE
'missingOpeningComma': report_error_type('invalidTag', tag='/Action/Reach/To touch('),
'missingClosingComma': report_error_type('commaMissing', tag='/Participant/Effect/Body part/Arm)/'),
'missingClosingComma': report_error_type('commaMissing', tag='/Participant/Effect/Body part/Arm)'),
'extraOpeningComma': report_error_type('extraDelimiter', character=',', index=0,
hed_string=test_strings['extraOpeningComma']),
'extraClosingComma': report_error_type('extraDelimiter', character=',',
Expand Down
Loading