Skip to content

Commit

Permalink
Remove some old code and tests and update to reflect JS version
Browse files Browse the repository at this point in the history
  • Loading branch information
happy5214 committed Jul 4, 2020
1 parent 171b73d commit 2feb49a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 89 deletions.
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
50 changes: 16 additions & 34 deletions hedvalidation/tests/test_tag_validator.py
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
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

0 comments on commit 2feb49a

Please sign in to comment.