def test_get_formatted_tag_groups(self): hed_string_delimiter = HedStringDelimiter(self.mixed_hed_string) tag_set = hed_string_delimiter.get_tags() formatted_group_tags = hed_string_delimiter.get_formatted_tag_groups() self.assertTrue(formatted_group_tags) self.assertIsInstance(formatted_group_tags, list) self.assertNotEqual(len(tag_set), len(formatted_group_tags))
def test_get_top_level_tags(self): hed_string_delimiter = HedStringDelimiter(self.mixed_hed_string) tag_set = hed_string_delimiter.get_tags() top_level_tags = hed_string_delimiter.get_top_level_tags() self.assertTrue(top_level_tags) self.assertIsInstance(top_level_tags, list) self.assertNotEqual(len(tag_set), len(top_level_tags))
def test_hed_string_is_a_group(self): is_group = HedStringDelimiter.hed_string_is_a_group( self.mixed_hed_string) self.assertFalse(is_group) self.assertIsInstance(is_group, bool) is_group = HedStringDelimiter.hed_string_is_a_group( self.group_hed_string) self.assertTrue(is_group) self.assertIsInstance(is_group, bool)
def test_string_is_space_or_empty(self): is_space_or_empty = HedStringDelimiter.string_is_space_or_empty( self.mixed_hed_string) self.assertFalse(is_space_or_empty) is_space_or_empty = HedStringDelimiter.string_is_space_or_empty( self.empty_hed_string) 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)
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.assertTrue(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.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.assertFalse(validation_issues)
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.assertTrue(validation_issues)
def _validate_hed_strings(self, hed_strings): """Validates the tags in an array of HED strings Parameters ---------- hed_string: string array An array of HED string. Returns ------- string The issues associated with the HED strings """ eeg_issues = [] for i in range(0, len(hed_strings)): hed_string = hed_strings[i] validation_issues = self._tag_validator.run_hed_string_validators(hed_string); if not validation_issues: hed_string_delimiter = HedStringDelimiter(hed_string); validation_issues += self._validate_top_level_in_hed_string(hed_string_delimiter); validation_issues += self._validate_tag_levels_in_hed_string(hed_string_delimiter); validation_issues += self._validate_individual_tags_in_hed_string(hed_string_delimiter); validation_issues += self._validate_groups_in_hed_string(hed_string_delimiter); if validation_issues: validation_issues = "Issue in event " + str(i+1) + ":" + validation_issues eeg_issues.append(validation_issues) return eeg_issues;
def test_find_group_tags(self): hed_string_delimiter = HedStringDelimiter(self.mixed_hed_string) tag_set = hed_string_delimiter.get_tags() group_tags_1 = hed_string_delimiter.get_tag_groups() self.assertTrue(group_tags_1) self.assertIsInstance(group_tags_1, list) self.assertNotEqual(len(tag_set), len(group_tags_1)) hed_string_delimiter._find_group_tags( hed_string_delimiter.get_split_hed_string_list()) group_tags_2 = hed_string_delimiter.get_tag_groups() self.assertTrue(group_tags_2) self.assertIsInstance(group_tags_2, list) self.assertNotEqual(len(tag_set), len(group_tags_2)) self.assertEqual(group_tags_1, group_tags_2)
def test__find_top_level_tags(self): hed_string_delimiter = HedStringDelimiter(self.mixed_hed_string) tag_set = hed_string_delimiter.get_tags() top_level_tags_1 = hed_string_delimiter.get_top_level_tags() self.assertTrue(top_level_tags_1) self.assertIsInstance(top_level_tags_1, list) self.assertNotEqual(len(tag_set), len(top_level_tags_1)) hed_string_delimiter._find_top_level_tags() top_level_tags_2 = hed_string_delimiter.get_top_level_tags() self.assertTrue(top_level_tags_2) self.assertIsInstance(top_level_tags_2, list) self.assertNotEqual(len(tag_set), len(top_level_tags_2)) self.assertEqual(top_level_tags_1, top_level_tags_2)
def test_format_hed_tags_in_list(self): hed_string_delimiter = HedStringDelimiter(self.mixed_hed_string) top_level_tags = hed_string_delimiter.get_top_level_tags() formatted_top_level_tags = HedStringDelimiter.format_hed_tags_in_list( top_level_tags) self.assertIsInstance(formatted_top_level_tags, list) self.assertEqual(len(top_level_tags), len(formatted_top_level_tags)) tag_groups = hed_string_delimiter.get_tag_groups() formatted_tag_groups = HedStringDelimiter.format_hed_tags_in_list( tag_groups) self.assertIsInstance(formatted_tag_groups, list) self.assertEqual(len(tag_groups), len(formatted_tag_groups))
def validate_column_hed_string(self, column_hed_string): """Appends the issues associated with a particular row in a spreadsheet. Parameters ---------- column_hed_string: string The HED string associated with a row column. Returns ------- string The issues associated with a particular row column. """ validation_issues = ''; validation_issues += self._tag_validator.run_hed_string_validators(column_hed_string); if not validation_issues: hed_string_delimiter = HedStringDelimiter(column_hed_string); validation_issues += self._validate_individual_tags_in_hed_string(hed_string_delimiter); validation_issues += self._validate_groups_in_hed_string(hed_string_delimiter); return validation_issues;
def _append_row_validation_issues_if_found(self, validation_issues, row_number, row_hed_string): """Appends the issues associated with a particular row in a spreadsheet. Parameters ---------- validation_issues: string A string that contains all the issues found in the spreadsheet. row_number: integer The row number that the issues are associated with. row_hed_string: string The HED string associated with a row. Returns ------- string The issues with the appended issues found in the particular row. """ if row_hed_string: hed_string_delimiter = HedStringDelimiter(row_hed_string); row_validation_issues = self._validate_top_level_in_hed_string(hed_string_delimiter); row_validation_issues += self._validate_tag_levels_in_hed_string(hed_string_delimiter); if row_validation_issues: validation_issues += HedInputReader.generate_row_issue_message(row_number) + row_validation_issues; return validation_issues;
def test_get_split_hed_string_list(self): hed_string_delimiter = HedStringDelimiter(self.mixed_hed_string) split_hed_string = hed_string_delimiter.get_split_hed_string_list() self.assertTrue(split_hed_string) self.assertIsInstance(split_hed_string, list)
def test_get_hed_string(self): hed_string_delimiter = HedStringDelimiter(self.mixed_hed_string) hed_string = hed_string_delimiter.get_hed_string() self.assertTrue(hed_string) self.assertIsInstance(hed_string, str) self.assertEqual(hed_string, self.mixed_hed_string)
def test_get_formatted_tags(self): hed_string_delimiter = HedStringDelimiter(self.mixed_hed_string) formatted_tags = hed_string_delimiter.get_formatted_tags() self.assertTrue(formatted_tags) self.assertIsInstance(formatted_tags, list)
def test_get_tags(self): hed_string_delimiter = HedStringDelimiter(self.mixed_hed_string) tag_set = hed_string_delimiter.get_tags() self.assertTrue(tag_set) self.assertIsInstance(tag_set, list)
def test_format_hed_tag(self): formatted_tag = HedStringDelimiter.format_hed_tag(self.unformatted_tag) self.assertIsInstance(formatted_tag, str) self.assertEqual(formatted_tag, self.formatted_tag)
def test_format_hed_tags_in_set(self): hed_string_delimiter = HedStringDelimiter(self.mixed_hed_string) tag_set = hed_string_delimiter.get_tags() formatted_tag_set = HedStringDelimiter.format_hed_tags_in_set(tag_set) self.assertIsInstance(formatted_tag_set, set) self.assertEqual(len(tag_set), len(formatted_tag_set))
def test_split_hed_string_into_list(self): split_hed_string = HedStringDelimiter.split_hed_string_into_list( self.mixed_hed_string) self.assertTrue(split_hed_string) self.assertIsInstance(split_hed_string, list)