コード例 #1
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)
コード例 #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 + ")")
コード例 #3
0
    def test_expand_def_tags_no_expand(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=False)
        self.assertFalse(def_issues)
        self.assertEqual(str(test_string), "")

        test_string = HedString(self.basic_definition_string_no_paren)
        def_issues = test_string.validate(def_mapper, expand_defs=False)
        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=False)
        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=False)
        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=False)
        self.assertFalse(def_issues)
        self.assertEqual(str(test_string), self.basic_hed_string_with_def)

        test_string = HedString(self.basic_hed_string_with_def_first)
        def_issues = test_string.validate(def_mapper, expand_defs=False)
        self.assertFalse(def_issues)
        self.assertEqual(str(test_string), self.basic_hed_string_with_def_first)

        test_string = HedString(self.basic_hed_string_with_def_first_paren)
        def_issues = test_string.validate(def_mapper, expand_defs=False)
        self.assertFalse(def_issues)
        self.assertEqual(str(test_string), self.basic_hed_string_with_def_first_paren)
コード例 #4
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)