Ejemplo n.º 1
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)
Ejemplo n.º 2
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 + ")")
Ejemplo n.º 3
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])