コード例 #1
0
    def test_constructor(self):
        test_strings = {
            'normal': "Tag1,Tag2",
            'normalParen': "(Tag1,Tag2)",
            'normalDoubleParen': "(Tag1,Tag2,(Tag3,Tag4))",
            'extraOpeningParen': "((Tag1,Tag2,(Tag3,Tag4))",
            'extra2OpeningParen': "(((Tag1,Tag2,(Tag3,Tag4))",
            'extraClosingParen': "(Tag1,Tag2,(Tag3,Tag4)))",
            'extra2ClosingParen': "(Tag1,Tag2,(Tag3,Tag4))))"
        }
        expected_result = {
            'normal': True,
            'normalParen': True,
            'normalDoubleParen': True,
            'extraOpeningParen': False,
            'extra2OpeningParen': False,
            'extraClosingParen': False,
            'extra2ClosingParen': False
        }

        # Just make sure it doesn't crash while parsing super invalid strings.
        for name, string in test_strings.items():
            hed_string = HedString(string)

            self.assertEqual(bool(hed_string), expected_result[name])
            if bool(hed_string):
                _ = hed_string.get_all_groups()
                _ = hed_string.get_all_tags()
コード例 #2
0
    def test_validate_column_group(self):
        validator = HedValidator(hed_schema=None)
        validation_issues = self.json_def_sidecar.validate_entries(
            validator, check_for_warnings=True)
        self.assertEqual(len(validation_issues), 0)

        validation_issues = self.default_sidecar.validate_entries(
            validator, check_for_warnings=True)
        self.assertEqual(len(validation_issues), 0)

        validation_issues = self.errors_sidecar.validate_entries(
            validator, check_for_warnings=True)
        self.assertEqual(len(validation_issues), 15)

        validation_issues = self.json_without_definitions_sidecar.validate_entries(
            validator, check_for_warnings=True)
        self.assertEqual(len(validation_issues), 1)

        hed_string = HedString(
            "(Definition/JsonFileDef/#, (Item/JsonDef1/#,Item/JsonDef1))")
        extra_def_dict = DefDict()
        hed_string.validate(extra_def_dict)

        validation_issues = self.json_without_definitions_sidecar.validate_entries(
            validator, check_for_warnings=True, extra_def_dicts=extra_def_dict)
        self.assertEqual(len(validation_issues), 0)
コード例 #3
0
 def test_remove_prefix_if_needed(self):
     mapper = ColumnMapper()
     mapper.set_column_prefix_dict(
         {self.add_column_number: self.required_prefix})
     remove_prefix_func = mapper.get_prefix_remove_func(
         self.add_column_number)
     test_string_obj = HedString(self.complex_hed_tag_required_prefix)
     no_prefix_string = test_string_obj.get_as_form("org_tag",
                                                    remove_prefix_func)
     self.assertEqual(str(no_prefix_string),
                      str(self.complex_hed_tag_no_prefix))
コード例 #4
0
    def test__validate_input(self):
        test_string_obj = HedString(self.base_hed_input)
        validation_issues = test_string_obj.validate(
            self.generic_hed_input_reader)
        self.assertIsInstance(validation_issues, list)

        name = "DummyDisplayFilename.txt"
        validation_issues = self.hed_file_with_errors.validate_file(
            self.generic_hed_input_reader, name=name)
        self.assertIsInstance(validation_issues, list)
        self.assertTrue(name in validation_issues[0][ErrorContext.FILE_NAME])
コード例 #5
0
 def test_def_mapping_single_line(self):
     schema_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                '../data/hed_pairs/HED8.0.0.mediawiki')
     hed_schema = schema.load_schema(schema_path)
     validator = HedValidator(hed_schema=hed_schema)
     def_mapper = DefinitionMapper()
     string_with_def = \
         '(Definition/TestDefPlaceholder/#,(Item/TestDef1/#,Item/TestDef2)), def/TestDefPlaceholder/2471'
     test_string = HedString(string_with_def)
     issues = test_string.validate([validator, def_mapper],
                                   check_for_definitions=True)
     self.assertEqual(len(issues), 0)
コード例 #6
0
 def tag_form_base(self, test_strings, expected_results, expected_errors):
     for test_key in test_strings:
         test_string_obj = HedString(test_strings[test_key])
         test_errors = test_string_obj.convert_to_canonical_forms(
             hed_schema=self.hed_schema)
         expected_error = expected_errors[test_key]
         expected_result = expected_results[test_key]
         for tag in test_string_obj.tags():
             self.assertEqual(tag.base_tag, expected_result,
                              test_strings[test_key])
             self.assertCountEqual(test_errors, expected_error,
                                   test_strings[test_key])
コード例 #7
0
    def test_basic_onset_errors_with_def_mapper(self):
        def_dict = DefDict()
        def_string = HedString(self.placeholder_definition_string)
        def_string.validate(def_dict)
        def_mapper = DefinitionMapper(def_dict)
        onset_mapper = OnsetMapper(def_mapper)
        validators = [def_mapper, onset_mapper]

        test_strings = [
            f"({self.placeholder_label_def_string},Onset)",
            f"({self.placeholder_label_def_string},Offset)",
            f"({self.placeholder_label_def_string},Offset)",
            f"({self.placeholder_label_def_string}, Onset, (Event), (Event))",
            f"({self.placeholder_label_def_string}, Onset, (Event))",
            "(Onset)",
            f"({self.placeholder_label_def_string}, def/TestDefPlaceholder/2, Onset, (Event))",
            "(def/TestDefInvalid, Onset)", "(def/TestDefPlaceholder, Onset)",
            f"({self.placeholder_label_def_string}, Offset, (Event))"
        ]
        # count of how many onset names are in the mapper after the line is run
        expected_context = [1, 0, 0, 0, 1, 1, 1, 1, 1, 1]
        # count of issues the line generates
        test_issues = [
            [],
            [],
            self.format_error(OnsetErrors.OFFSET_BEFORE_ONSET, tag=0),
            self.format_error(OnsetErrors.ONSET_WRONG_NUMBER_GROUPS,
                              tag=0,
                              tag_list=[
                                  self.placeholder_label_def_string, 'Onset',
                                  '(Event)', '(Event)'
                              ]),
            [],
            self.format_error(OnsetErrors.ONSET_NO_DEF_TAG_FOUND, tag=0),
            self.format_error(OnsetErrors.ONSET_TOO_MANY_DEFS,
                              tag=0,
                              tag_list=['def/TestDefPlaceholder/2']),
            self.format_error(ValidationErrors.HED_DEF_UNMATCHED, tag=0),
            self.format_error(ValidationErrors.HED_DEF_VALUE_MISSING, tag=0),
            self.format_error(OnsetErrors.ONSET_WRONG_NUMBER_GROUPS,
                              tag=0,
                              tag_list=[
                                  self.placeholder_label_def_string, 'Offset',
                                  '(Event)'
                              ]),
        ]

        self._test_issues_base(test_strings,
                               test_issues,
                               expected_context,
                               validators,
                               expand_defs=False)
コード例 #8
0
 def test_group_tags(self):
     hed_string = '/Action/Reach/To touch,(/Attribute/Object side/Left,/Participant/Effect/Body part/Arm),' \
                  '/Attribute/Location/Screen/Top/70 px,/Attribute/Location/Screen/Left/23 px '
     string_obj = HedString(hed_string)
     # result = HedString.split_hed_string_into_groups(hed_string)
     tags_as_strings = [
         str(tag) for tag in string_obj.get_direct_children()
     ]
     self.assertCountEqual(tags_as_strings, [
         '/Action/Reach/To touch',
         '(/Attribute/Object side/Left,/Participant/Effect/Body part/Arm)',
         '/Attribute/Location/Screen/Top/70 px',
         '/Attribute/Location/Screen/Left/23 px'
     ])
コード例 #9
0
    def test_get_all_tag_attributes(self):
        test_string = HedString("Jerk-rate/#")
        test_string.convert_to_canonical_forms(self.hed_schema_3g)
        tag_props = self.hed_schema_3g.get_all_tag_attributes(test_string)
        expected_props = {
            "takesValue": "true",
            "valueClass": "numericClass",
            "unitClass": 'jerkUnits'
        }
        self.assertCountEqual(tag_props, expected_props)

        tag_props = self.hed_schema_3g.get_all_tag_attributes("This/Is/Not/A/Tag")
        expected_props = {
        }
        self.assertCountEqual(tag_props, expected_props)

        test_string = HedString("Statistical-value")
        test_string.convert_to_canonical_forms(self.hed_schema_3g)
        tag_props = self.hed_schema_3g.get_all_tag_attributes(test_string)
        expected_props = {
            HedKey.ExtensionAllowed: "true",
        }
        self.assertCountEqual(tag_props, expected_props)
        # also test long form.
        tag_props = self.hed_schema_3g.get_all_tag_attributes("Property/Data-property/Data-value/Statistical-value")
        self.assertCountEqual(tag_props, expected_props)
コード例 #10
0
 def _test_issues_no_context(self, test_strings, test_issues, validators):
     for string, expected_params in zip(test_strings, test_issues):
         test_string = HedString(string)
         error_handler = ErrorHandler()
         error_handler.push_error_context(ErrorContext.HED_STRING,
                                          test_string,
                                          increment_depth_after=False)
         onset_issues = test_string.validate(validators, expand_defs=True)
         issues = self.format_errors_fully(error_handler,
                                           hed_string=test_string,
                                           params=expected_params)
         # print(str(onset_issues))
         # print(str(issues))
         error_handler.pop_error_context()
         self.assertCountEqual(onset_issues, issues)
コード例 #11
0
    def setUpClass(cls):
        cls.event_mapper = ColumnMapper()
        cls.integer_key_dictionary = {1: 'one', 2: 'two', 3: 'three'}
        cls.one_based_tag_columns = [1, 2, 3]
        cls.zero_based_row_column_count = 3
        cls.column_prefix_dictionary = {
            3: 'Event/Description/',
            4: 'Event/Label/',
            5: 'Event/Category/'
        }
        cls.category_key = 'Event/Category/'
        cls.category_partipant_and_stimulus_tags = \
            HedString('Event/Category/Participant response, Event/Category/Stimulus')
        cls.category_tags = HedString('Participant response, Stimulus')
        cls.row_with_hed_tags = ['event1', 'tag1', 'tag2']

        cls.base_data_dir = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), '../data/')
        cls.basic_events_json = os.path.join(
            cls.base_data_dir, "sidecar_tests/both_types_events.json")
        cls.basic_event_name = "trial_type"
        cls.basic_event_type = ColumnType.Categorical
        cls.basic_attribute_column = "onset"
        cls.basic_column_map = [
            "onset", "duration", "trial_type", "response_time", " stim_file"
        ]
        cls.basic_event_row = [
            "1.2", "0.6", "go", "1.435", "images/red_square.jpg"
        ]
        cls.basic_event_row_invalid = [
            "1.2", "0.6", "invalid_category_key", "1.435",
            "images/red_square.jpg"
        ]

        cls.add_column_name = "TestColumn"
        cls.add_column_number = 0
        cls.hed_string = "Event/Label/#"
        cls.test_column_map = ["TestColumn"]
        cls.required_prefix = "TestRequiredPrefix/"
        cls.complex_hed_tag_required_prefix = \
            "TestRequiredPrefix/ThisIsAHedTag, (TestRequiredPrefix/NewTag, TestRequiredPrefix/NewTag3)"
        cls.complex_hed_tag_no_prefix = "ThisIsAHedTag,(NewTag,NewTag3)"

        cls.short_tag_key = 'Item/Language-item/Character/'
        cls.short_tag_with_missing_prefix = "D"
        cls.short_tag_partial_prefix = 'Language-item/Character/'
        cls.short_tag_partial_prefix2 = 'Character/'
コード例 #12
0
 def test_top_level_tags(self):
     hed_string = 'Event/Category/Experimental stimulus,Item/Object/Vehicle/Train,Attribute/Visual/Color/Purple'
     result = HedString.split_hed_string_into_groups(hed_string)
     tags_as_strings = [str(tag) for tag in result]
     self.assertCountEqual(tags_as_strings, [
         'Event/Category/Experimental stimulus',
         'Item/Object/Vehicle/Train', 'Attribute/Visual/Color/Purple'
     ])
コード例 #13
0
 def test_add_prefix_verify_short_tag_conversion(self):
     schema_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                self.schema_file)
     hed_schema = load_schema(schema_file)
     prepended_hed_string = ColumnMetadata._prepend_prefix_to_required_tag_column_if_needed(
         HedString(self.short_tag_with_missing_prefix), self.short_tag_key)
     issues = prepended_hed_string.convert_to_canonical_forms(hed_schema)
     for tag in prepended_hed_string.get_all_tags():
         self.assertEqual("Character/D", tag.short_tag)
コード例 #14
0
 def test_parsed_tags(self):
     hed_string = '/Action/Reach/To touch,(/Attribute/Object side/Left,/Participant/Effect/Body part/Arm),' \
                  '/Attribute/Location/Screen/Top/70 px,/Attribute/Location/Screen/Left/23 px '
     parsed_string = HedString(hed_string)
     self.assertCountEqual(
         [str(tag) for tag in parsed_string.get_all_tags()], [
             '/Action/Reach/To touch',
             '/Attribute/Object side/Left',
             '/Participant/Effect/Body part/Arm',
             '/Attribute/Location/Screen/Top/70 px',
             '/Attribute/Location/Screen/Left/23 px',
         ])
     self.assertCountEqual([
         str(group) for group in parsed_string.get_all_groups()
     ], [
         '/Action/Reach/To touch,(/Attribute/Object side/Left,/Participant/Effect/Body part/Arm),'
         '/Attribute/Location/Screen/Top/70 px,/Attribute/Location/Screen/Left/23 px',
         '(/Attribute/Object side/Left,/Participant/Effect/Body part/Arm)'
     ])
コード例 #15
0
    def test_onset_with_defs_in_them(self):
        def_dict = DefDict()
        def_string = HedString(self.placeholder_definition_string)
        def_string.validate(def_dict)
        def_mapper = DefinitionMapper(def_dict)
        onset_mapper = OnsetMapper(def_mapper)

        test_strings = [
            f"({self.placeholder_label_def_string},Onset, ({self.label_def_string}))",
        ]
        # count of how many onset names are in the mapper after the line is run
        expected_context = [
            1,
        ]
        # count of issues the line generates
        test_issues = [[]]

        self._test_issues_base(test_strings, test_issues, expected_context,
                               [onset_mapper])
コード例 #16
0
 def compare_split_results(self, test_strings, expected_results):
     for test_key in test_strings:
         test_string = test_strings[test_key]
         expected_result = expected_results[test_key]
         actual_results = HedString.split_hed_string(test_string)
         decoded_results = [
             test_string[start:end]
             for (is_tag, (start, end)) in actual_results
         ]
         self.assertEqual(decoded_results, expected_result)
コード例 #17
0
    def test_onset_multiple_or_misplaced_errors(self):
        def_dict = DefDict()
        def_string = HedString(self.placeholder_definition_string)
        def_string.validate(def_dict)
        def_string = HedString(self.definition_string)
        def_string.validate(def_dict)
        def_mapper = DefinitionMapper(def_dict)
        onset_mapper = OnsetMapper(def_mapper)
        hed_validator = HedValidator(hed_schema=self.hed_schema)
        validators = [hed_validator, def_mapper, onset_mapper]

        test_strings = [
            f"{self.placeholder_label_def_string},Onset",
            f"({self.placeholder_label_def_string},Onset, Onset)",
            f"({self.placeholder_label_def_string},Onset, Offset)",
        ]
        # count of issues the line generates
        onset_list = [
            'Property/Data-property/Data-marker/Temporal-marker/Onset'
        ]
        offset_list = [
            'Property/Data-property/Data-marker/Temporal-marker/Offset'
        ]
        test_issues = [
            self.format_error(ValidationErrors.HED_TOP_LEVEL_TAG, tag=1),
            self.format_error(ValidationErrors.HED_TAG_REPEATED, tag=2) +
            self.format_error(ValidationErrors.HED_MULTIPLE_TOP_TAGS,
                              tag=1,
                              multiple_tags=onset_list),
            self.format_error(ValidationErrors.HED_MULTIPLE_TOP_TAGS,
                              tag=1,
                              multiple_tags=offset_list),
        ]

        self._test_issues_no_context(test_strings, test_issues, validators)

        test_issues = [
            self.format_error(ValidationErrors.HED_TOP_LEVEL_TAG, tag=1),
            self.format_error(ValidationErrors.HED_TAG_REPEATED, tag=2) +
            self.format_error(ValidationErrors.HED_MULTIPLE_TOP_TAGS,
                              tag=1,
                              multiple_tags=onset_list),
            self.format_error(ValidationErrors.HED_MULTIPLE_TOP_TAGS,
                              tag=1,
                              multiple_tags=offset_list),
        ]

        # Repeat with just hed validator
        self._test_issues_no_context(test_strings, test_issues, hed_validator)
コード例 #18
0
    def converter_base(self, test_strings, expected_results, expected_errors, convert_to_short=True):
        for test_key in test_strings:
            test_string_obj = HedString(test_strings[test_key])
            error_handler = ErrorHandler()
            error_handler.push_error_context(ErrorContext.HED_STRING, test_string_obj, increment_depth_after=False)
            test_issues = test_string_obj.convert_to_canonical_forms(self.hed_schema)
            if convert_to_short:
                string_result = test_string_obj.get_as_short()
            else:
                string_result = test_string_obj.get_as_long()
            expected_params = expected_errors[test_key]
            expected_result = expected_results[test_key]

            expected_issue = self.format_errors_fully(error_handler, hed_string=test_string_obj,
                                                      params=expected_params)
            error_handler.add_context_to_issues(test_issues)

            # print(test_key)
            # print(expected_issue)
            # print(test_issues)
            self.assertEqual(string_result, expected_result, test_strings[test_key])
            self.assertCountEqual(test_issues, expected_issue, test_strings[test_key])
コード例 #19
0
    def test_basic_onset_errors_expanded(self):
        def_dict = DefDict()
        def_string = HedString(self.placeholder_definition_string)
        def_string.validate(def_dict)
        def_string = HedString(self.definition_string)
        def_string.validate(def_dict)
        def_mapper = DefinitionMapper(def_dict)
        onset_mapper = OnsetMapper(def_mapper)

        test_strings = [
            f"({self.placeholder_expanded_def_string},Onset)",
            f"({self.placeholder_expanded_def_string},Offset)",
            f"({self.placeholder_expanded_def_string},Offset)",
            f"({self.placeholder_expanded_def_string}, Onset, (Event), (Event))",
            f"({self.placeholder_expanded_def_string}, Onset, (Event))",
            "(Onset)",
            f"({self.placeholder_expanded_def_string}, def/InvalidDef, Onset, (Event))",
            "(def/TestDefInvalid, Onset)", "(def/TestDefPlaceholder, Onset)",
            "(def/TestDefNormal/InvalidPlaceholder, Onset)"
        ]
        # count of how many onset names are in the mapper after the line is run
        expected_context = [1, 0, 0, 0, 1, 1, 1, 1, 1, 1]
        # count of issues the line generates
        test_issues = [[], [],
                       self.format_error(OnsetErrors.OFFSET_BEFORE_ONSET,
                                         tag=0),
                       self.format_error(
                           OnsetErrors.ONSET_WRONG_NUMBER_GROUPS,
                           tag=0,
                           tag_list=[
                               self.placeholder_expanded_def_string, 'Onset',
                               '(Event)', '(Event)'
                           ]), [],
                       self.format_error(OnsetErrors.ONSET_NO_DEF_TAG_FOUND,
                                         tag=0),
                       self.format_error(OnsetErrors.ONSET_TOO_MANY_DEFS,
                                         tag=0,
                                         tag_list=['def/InvalidDef']),
                       self.format_error(OnsetErrors.ONSET_DEF_UNMATCHED,
                                         tag=0),
                       self.format_error(OnsetErrors.ONSET_PLACEHOLDER_WRONG,
                                         tag=0,
                                         has_placeholder=True),
                       self.format_error(OnsetErrors.ONSET_PLACEHOLDER_WRONG,
                                         tag=0,
                                         has_placeholder=False)]

        self._test_issues_base(test_strings, test_issues, expected_context,
                               [onset_mapper])
コード例 #20
0
    def test_onset_multiple_or_misplaced_errors_no_validator(self):
        def_dict = DefDict()
        def_string = HedString(self.placeholder_definition_string)
        def_string.validate(def_dict)
        def_string = HedString(self.definition_string)
        def_string.validate(def_dict)
        def_mapper = DefinitionMapper(def_dict)
        onset_mapper = OnsetMapper(def_mapper)
        validators = [def_mapper, onset_mapper]

        test_strings = [
            f"{self.placeholder_label_def_string},Onset",
            f"({self.placeholder_label_def_string},Onset, Onset)",
            f"({self.placeholder_label_def_string},Onset, Offset)",
            f"({self.placeholder_label_def_string},Onset, Event)",
        ]
        # count of issues the line generates
        test_issues = [
            [],
            self.format_error(OnsetErrors.ONSET_TAG_OUTSIDE_OF_GROUP,
                              tag=4,
                              def_tag="Def-expand/TestDefPlaceholder/2471"),
            self.format_error(OnsetErrors.ONSET_TAG_OUTSIDE_OF_GROUP,
                              tag=4,
                              def_tag="Def-expand/TestDefPlaceholder/2471"),
            self.format_error(OnsetErrors.ONSET_TAG_OUTSIDE_OF_GROUP,
                              tag=4,
                              def_tag="Def-expand/TestDefPlaceholder/2471"),
        ]

        self._test_issues_no_context(test_strings, test_issues, validators)

        # Verify it also works without def mapping
        test_issues = [
            [],
            self.format_error(OnsetErrors.ONSET_TAG_OUTSIDE_OF_GROUP,
                              tag=2,
                              def_tag=self.placeholder_label_def_string),
            self.format_error(OnsetErrors.ONSET_TAG_OUTSIDE_OF_GROUP,
                              tag=2,
                              def_tag=self.placeholder_label_def_string),
            self.format_error(OnsetErrors.ONSET_TAG_OUTSIDE_OF_GROUP,
                              tag=2,
                              def_tag=self.placeholder_label_def_string),
        ]

        self._test_issues_no_context(test_strings, test_issues,
                                     [validators[1]])
コード例 #21
0
    def test_test_interleaving_onset_offset(self):
        def_dict = DefDict()
        def_string = HedString(self.placeholder_definition_string)
        def_string.validate(def_dict)
        def_string = HedString(self.definition_string)
        def_string.validate(def_dict)
        def_mapper = DefinitionMapper(def_dict)
        onset_mapper = OnsetMapper(def_mapper)

        test_strings = [
            f"({self.placeholder_label_def_string},Onset)",
            f"({self.placeholder_label_def_string2},Onset)",
            "Event",
            f"({self.placeholder_label_def_string},Offset)",
            f"({self.placeholder_label_def_string},Offset)",
            f"({self.label_def_string}, Onset)",
            f"({self.placeholder_label_def_string2},Offset)",
        ]
        # count of how many onset names are in the mapper after the line is run
        expected_context = [
            1,
            2,
            2,
            1,
            1,
            2,
            1,
        ]
        # count of issues the line generates
        test_issues = [
            [],
            [],
            [],
            [],
            self.format_error(OnsetErrors.OFFSET_BEFORE_ONSET, tag=0),
            [],
            [],
        ]

        self._test_issues_base(test_strings, test_issues, expected_context,
                               [onset_mapper])
コード例 #22
0
    def test_onset_two_in_one_line(self):
        def_dict = DefDict()
        def_string = HedString(self.placeholder_definition_string)
        def_string.validate(def_dict)
        def_string = HedString(self.definition_string)
        def_string.validate(def_dict)
        def_mapper = DefinitionMapper(def_dict)
        onset_mapper = OnsetMapper(def_mapper)

        test_strings = [
            f"({self.placeholder_label_def_string},Onset), ({self.placeholder_label_def_string2},Onset)",
            f"({self.placeholder_label_def_string2},Offset)",
            f"({self.placeholder_label_def_string},Offset)",
            f"({self.placeholder_label_def_string},Onset)",
            f"({self.placeholder_label_def_string},Offset), ({self.placeholder_label_def_string2},Onset)",
            f"({self.placeholder_label_def_string},Onset), ({self.placeholder_label_def_string},Onset)",
        ]
        # count of how many onset names are in the mapper after the line is run
        expected_context = [2, 1, 0, 1, 1, 2]
        # count of issues the line generates
        test_issues = [[], [], [], [], [], []]

        self._test_issues_base(test_strings, test_issues, expected_context,
                               [onset_mapper])
コード例 #23
0
    def test_changing_tag_then_def_mapping(self):
        def_dict = DefDict()
        def_string = HedString(self.basic_definition_string)
        def_string.convert_to_canonical_forms(None)
        def_dict.check_for_definitions(def_string)
        def_mapper = DefinitionMapper(def_dict)
        validator = HedValidator(self.hed_schema)
        validators = [validator, def_mapper]

        test_string = HedString(self.label_def_string)
        tag = test_string.get_direct_children()[0]
        tag.tag = "Organizational-property/" + str(tag)
        def_issues = test_string.validate(validators, expand_defs=True)
        self.assertFalse(def_issues)
        self.assertEqual(test_string.get_as_short(), f"{self.expanded_def_string}")

        test_string = HedString(self.label_def_string)
        tag = test_string.get_direct_children()[0]
        tag.tag = "Organizational-property22/" + str(tag)
        def_issues = test_string.validate(validators, expand_defs=True)
        self.assertTrue(def_issues)
コード例 #24
0
    def test_expand_def_tags(self):
        def_dict = DefDict()
        def_string = HedString(self.basic_definition_string)
        def_string.convert_to_canonical_forms(None)
        def_dict.check_for_definitions(def_string)
        def_mapper = DefinitionMapper(def_dict)

        test_string = HedString(self.basic_definition_string)
        def_issues = test_string.validate(def_mapper, expand_defs=True)
        self.assertEqual(str(test_string), "")

        test_string = HedString(self.basic_definition_string_no_paren)
        def_issues = test_string.validate(def_mapper, expand_defs=True)
        self.assertFalse(def_issues)
        self.assertEqual(str(test_string), self.basic_definition_string_no_paren)

        test_string = HedString(self.basic_hed_string + "," + self.basic_definition_string)
        def_issues = test_string.validate(def_mapper, expand_defs=True)
        self.assertFalse(def_issues)
        self.assertEqual(str(test_string), self.basic_hed_string)

        test_string = HedString(self.basic_definition_string + "," + self.basic_hed_string)
        def_issues = test_string.validate(def_mapper, expand_defs=True)
        self.assertFalse(def_issues)
        self.assertEqual(str(test_string), self.basic_hed_string)

        test_string = HedString(self.basic_hed_string_with_def)
        def_issues = test_string.validate(def_mapper, expand_defs=True)
        self.assertFalse(def_issues)
        self.assertEqual(str(test_string), self.basic_hed_string + "," + self.expanded_def_string)

        test_string = HedString(self.basic_hed_string_with_def_first)
        def_issues = test_string.validate(def_mapper, expand_defs=True)
        self.assertFalse(def_issues)
        self.assertEqual(str(test_string), self.expanded_def_string + "," + self.basic_hed_string)

        test_string = HedString(self.basic_hed_string_with_def_first_paren)
        def_issues = test_string.validate(def_mapper, expand_defs=True)
        self.assertFalse(def_issues)
        self.assertEqual(str(test_string), "(" + self.expanded_def_string + "," + self.basic_hed_string + ")")
コード例 #25
0
 def test_type(self):
     hed_string = 'Event/Category/Experimental stimulus,Item/Object/Vehicle/Train,Attribute/Visual/Color/Purple'
     result = HedString.split_hed_string_into_groups(hed_string)
     self.assertIsInstance(result, list)
コード例 #26
0
    def test_expand_def_tags_with_validator(self):
        def_dict = DefDict()
        def_string = HedString(self.basic_definition_string)
        def_string.convert_to_canonical_forms(None)
        def_dict.check_for_definitions(def_string)
        def_mapper = DefinitionMapper(def_dict)
        validator = HedValidator(self.hed_schema)
        validators = [validator, def_mapper]

        test_string = HedString(self.basic_definition_string)
        def_issues = test_string.validate(validators, expand_defs=True)
        self.assertEqual(test_string.get_as_short(), "")

        test_string = HedString(self.basic_definition_string_no_paren)
        def_issues = test_string.validate(validators, expand_defs=True)
        self.assertTrue(def_issues)
        self.assertEqual(test_string.get_as_short(), self.basic_definition_string_no_paren)

        test_string = HedString(self.basic_hed_string + "," + self.basic_definition_string)
        def_issues = test_string.validate(validators, expand_defs=True)
        self.assertFalse(def_issues)
        self.assertEqual(test_string.get_as_short(), self.basic_hed_string)

        test_string = HedString(self.basic_definition_string + "," + self.basic_hed_string)
        def_issues = test_string.validate(validators, expand_defs=True)
        self.assertFalse(def_issues)
        self.assertEqual(test_string.get_as_short(), self.basic_hed_string)

        test_string = HedString(self.basic_hed_string_with_def)
        def_issues = test_string.validate(validators, expand_defs=True)
        self.assertFalse(def_issues)
        self.assertEqual(test_string.get_as_short(), self.basic_hed_string + "," + self.expanded_def_string)

        test_string = HedString(self.basic_hed_string_with_def_first)
        def_issues = test_string.validate(validators, expand_defs=True)
        self.assertFalse(def_issues)
        self.assertEqual(test_string.get_as_short(), self.expanded_def_string + "," + self.basic_hed_string)

        test_string = HedString(self.basic_hed_string_with_def_first_paren)
        def_issues = test_string.validate(validators, expand_defs=True)
        self.assertFalse(def_issues)
        self.assertEqual(test_string.get_as_short(), "(" + self.expanded_def_string + "," + self.basic_hed_string + ")")
コード例 #27
0
    def test_expand_def_tags_placeholder_invalid(self):
        def_dict = DefDict()
        def_string = HedString(self.placeholder_def_string)
        def_string.convert_to_canonical_forms(None)
        def_dict.check_for_definitions(def_string)
        def_mapper = DefinitionMapper(def_dict)

        placeholder_label_def_string_no_placeholder = "def/TestDefPlaceholder"

        test_string = HedString(placeholder_label_def_string_no_placeholder)
        test_string.convert_to_canonical_forms(None)
        def_issues = def_mapper.expand_def_tags(test_string)
        self.assertEqual(str(test_string), placeholder_label_def_string_no_placeholder)
        self.assertTrue(def_issues)

        def_dict = DefDict()
        def_string = HedString(self.basic_definition_string)
        def_string.convert_to_canonical_forms(None)
        def_dict.check_for_definitions(def_string)
        def_mapper = DefinitionMapper(def_dict)

        label_def_string_has_invalid_placeholder = "def/TestDef/54687"

        test_string = HedString(label_def_string_has_invalid_placeholder)
        test_string.convert_to_canonical_forms(None)
        def_issues = def_mapper.expand_def_tags(test_string)
        self.assertEqual(str(test_string), label_def_string_has_invalid_placeholder)
        self.assertTrue(def_issues)
コード例 #28
0
 def test_function(string):
     return [
         str(child)
         for child in HedString.split_hed_string_into_groups(string)
     ]