コード例 #1
0
    def testInheritTypesFromDifferentNamespace(self):
        type1 = entity_type_lib.EntityType(filepath='path/to/ANIMAL/mammal',
                                           typename='dog',
                                           description='canine animal',
                                           local_field_tuples=_F(
                                               ['/woof', '/howl']))

        type2 = entity_type_lib.EntityType(filepath='path/to/INSECT/fly',
                                           typename='moth',
                                           description='flying insect.',
                                           local_field_tuples=_F(['/wings']),
                                           parents=['ANIMAL/dog'])

        type_namespace_1 = entity_type_lib.TypeNamespace(namespace='ANIMAL')
        type_namespace_1.InsertType(type1)
        type_namespace_2 = entity_type_lib.TypeNamespace(namespace='INSECT')
        type_namespace_2.InsertType(type2)
        namespace_validate = (namespace_validator.NamespaceValidator(
            [type_namespace_1, type_namespace_2]))

        self.assertFalse(namespace_validate.GetFindings())

        expanded_type_namespace_1 = namespace_validate.type_namespaces_map.get(
            type_namespace_1.namespace)
        expanded_type_namespace_2 = namespace_validate.type_namespaces_map.get(
            type_namespace_2.namespace)

        type1_expanded = expanded_type_namespace_1.valid_types_map.get(
            type1.typename)
        type2_expanded = expanded_type_namespace_2.valid_types_map.get(
            type2.typename)

        self.assertEmpty(type1_expanded.inherited_field_names)
        self.assertLen(type2_expanded.inherited_field_names, 2)
コード例 #2
0
    def testEntityTypeUniverseFindsDupIds(self):
        filepath = _GOOD_PATH + '/file.yaml'
        folder = entity_type_lib.EntityTypeFolder(_GOOD_PATH)
        namespace = folder.local_namespace

        entity_type1 = entity_type_lib.EntityType(typename='one',
                                                  filepath=filepath,
                                                  description='hi',
                                                  uid='1')
        namespace.InsertType(entity_type1)
        entity_type1a = entity_type_lib.EntityType(typename='oneA',
                                                   filepath=filepath,
                                                   description='hi',
                                                   uid='1')
        namespace.InsertType(entity_type1a)
        entity_type2 = entity_type_lib.EntityType(typename='two',
                                                  filepath=filepath,
                                                  description='hi',
                                                  uid='2')
        namespace.InsertType(entity_type2)

        types_universe = entity_type_lib.EntityTypeUniverse([folder])

        findings = types_universe.GetFindings()
        self.assertLen(findings, 2)
        self.assertTrue(
            types_universe.HasFindingTypes([findings_lib.DuplicateIdsError]))
        self.assertTrue(
            entity_type1.HasFindingTypes([findings_lib.DuplicateIdsError]))
        self.assertTrue(
            entity_type1a.HasFindingTypes([findings_lib.DuplicateIdsError]))
        self.assertFalse(entity_type2.GetFindings())
コード例 #3
0
    def testDuplicateLocalFieldSets(self):
        type1 = entity_type_lib.EntityType(filepath='path/to/ANIMAL/mammal',
                                           typename='dog',
                                           description='canine animal',
                                           local_field_tuples=_F(
                                               ['/woof', '/howl']))

        type2 = entity_type_lib.EntityType(filepath='path/to/ANIMAL/mammal',
                                           typename='wolf',
                                           description='canine animal',
                                           local_field_tuples=_F(
                                               ['/woof', '/howl']))
        type2.inherited_field_names = ({'/bark': _F1('/bark', optional=True)})

        type_namespace = entity_type_lib.TypeNamespace(namespace='ANIMAL')
        type_namespace.InsertType(type1)
        type_namespace.InsertType(type2)

        namespace_validator.NamespaceValidator([type_namespace])

        self.assertTrue(
            type1.HasFindingTypes(
                [findings_lib.DuplicateLocalFieldSetsWarning]))
        self.assertTrue(
            type2.HasFindingTypes(
                [findings_lib.DuplicateLocalFieldSetsWarning]))
コード例 #4
0
    def testEntityTypeUniverseHandlesNamespaceMovesWithIds(self):
        filepath = _GOOD_PATH + '/file.yaml'
        folder = entity_type_lib.EntityTypeFolder(_GOOD_PATH)
        namespace = folder.local_namespace

        filepath2 = _GOOD_PATH_2 + '/file.yaml'
        folder2 = entity_type_lib.EntityTypeFolder(_GOOD_PATH_2)
        namespace2 = folder2.local_namespace

        entity_type1 = entity_type_lib.EntityType(typename='one',
                                                  filepath=filepath,
                                                  description='hi',
                                                  uid='1')
        namespace.InsertType(entity_type1)
        entity_type1a = entity_type_lib.EntityType(typename='oneA',
                                                   filepath=filepath2,
                                                   description='hi',
                                                   uid='1')
        namespace2.InsertType(entity_type1a)

        types_universe = entity_type_lib.EntityTypeUniverse([folder, folder2])

        findings = types_universe.GetFindings()
        self.assertLen(findings, 2)
        self.assertTrue(
            types_universe.HasFindingTypes([findings_lib.DuplicateIdsError]))
        self.assertTrue(
            entity_type1.HasFindingTypes([findings_lib.DuplicateIdsError]))
        self.assertTrue(
            entity_type1a.HasFindingTypes([findings_lib.DuplicateIdsError]))
コード例 #5
0
    def testInheritanceCycleAcrossNamepsaces(self):
        type1 = entity_type_lib.EntityType(filepath='path/to/ANIMAL/mammal',
                                           typename='dog',
                                           description='canine animal',
                                           local_field_tuples=_F(['/woof']),
                                           parents=['ANIMAL/wolf'])

        type2 = entity_type_lib.EntityType(filepath='path/to/ANIMAL/mammal',
                                           typename='wolf',
                                           description='canine animal',
                                           local_field_tuples=_F(['/growl']),
                                           parents=['FUZZY_ANIMAL/dingo'])

        type3 = entity_type_lib.EntityType(
            filepath='path/to/FUZZY_ANIMAL/mammal',
            typename='dingo',
            description='canine animal',
            local_field_tuples=_F(['/wag']),
            parents=['ANIMAL/dog'])

        namespace = entity_type_lib.TypeNamespace(namespace='ANIMAL')
        namespace.InsertType(type1)
        namespace.InsertType(type2)
        namespace2 = entity_type_lib.TypeNamespace(namespace='FUZZY_ANIMAL')
        namespace2.InsertType(type3)
        namespace_validate = (namespace_validator.NamespaceValidator(
            [namespace, namespace2]))

        self.assertTrue(
            namespace_validate.HasFindingTypes(
                [findings_lib.InheritanceCycleError]))
コード例 #6
0
    def testBackwardsCompatibilityRemovedType(self):
        # Two types.  One is abstract.
        ns1_path = '{0}/entity_types/anyfolder'.format('namespace_one')
        folder1 = entity_type_lib.EntityTypeFolder(ns1_path)
        ns1 = folder1.local_namespace
        type1 = entity_type_lib.EntityType(filepath=ns1_path + '/file.yaml',
                                           typename='type1',
                                           inherited_fields_expanded=True)
        ns1.InsertType(type1)
        type2 = entity_type_lib.EntityType(filepath=ns1_path + '/file.yaml',
                                           typename='type2',
                                           inherited_fields_expanded=True,
                                           is_abstract=True)
        ns1.InsertType(type2)
        old_uv = entity_type_lib.EntityTypeUniverse([folder1])

        # No Types.
        folder1a = entity_type_lib.EntityTypeFolder(ns1_path)
        new_uv = entity_type_lib.EntityTypeUniverse([folder1a])

        findings = presubmit_validate_types_lib.CheckBackwardsCompatibility(
            new_uv, old_uv)

        self.assertLen(findings, 1)
        self.assertIsInstance(findings[0], findings_lib.RemovedTypeWarning)
        self.assertIn('type1', str(findings[0]))
コード例 #7
0
    def testBackwardsCompatibilityAcrossNamespaces(self):
        # Two types.  One is abstract.
        ns1_path = '{0}/entity_types/anyfolder'.format('namespace_one')
        ns2_path = '{0}/entity_types/anyfolder'.format('namespace_two')
        folder1 = entity_type_lib.EntityTypeFolder(ns1_path)
        ns1 = folder1.local_namespace
        type1 = entity_type_lib.EntityType(filepath=ns1_path + '/file.yaml',
                                           typename='type1',
                                           inherited_fields_expanded=True,
                                           uid='1')
        ns1.InsertType(type1)
        old_uv = entity_type_lib.EntityTypeUniverse([folder1])

        folder1a = entity_type_lib.EntityTypeFolder(ns1_path)
        folder2 = entity_type_lib.EntityTypeFolder(ns2_path)
        ns2 = folder1a.local_namespace
        type1a = entity_type_lib.EntityType(filepath=ns2_path + '/file.yaml',
                                            typename='type1a',
                                            inherited_fields_expanded=True,
                                            uid='1')
        ns2.InsertType(type1a)
        new_uv = entity_type_lib.EntityTypeUniverse([folder1a, folder2])

        findings = presubmit_validate_types_lib.CheckBackwardsCompatibility(
            new_uv, old_uv)

        self.assertEmpty(findings)
コード例 #8
0
  def testAddMultipleTypes(self):
    fields_universe = field_lib.FieldUniverse([])
    fields_universe._namespace_map = {
        '': [field_lib.Field('animal')],
        'ANIMAL': [field_lib.Field('meow')]
    }
    folderpath = 'ANIMAL/entity_types'
    type_folder = entity_type_lib.EntityTypeFolder(folderpath, fields_universe)
    self.assertFalse(type_folder.GetFindings())

    rel_typepath = os.path.join(folderpath, 'mammal')
    # bad entity type, field 'claws' is undefined.
    bad_type = entity_type_lib.EntityType(
        filepath=rel_typepath,
        typename='cat',
        description='feline animal',
        local_field_tuples=_FS(['ANIMAL/meow', 'ANIMAL/claws', '/animal']))
    # good entity type
    good_type = entity_type_lib.EntityType(
        filepath=rel_typepath,
        typename='kitty',
        description='feline animal',
        local_field_tuples=_FS(['ANIMAL/meow', '/animal']))
    type_folder._AddType(good_type)
    type_folder._AddType(bad_type)

    self.assertTrue(
        type_folder.local_namespace.HasFindingTypes(
            [findings_lib.UndefinedFieldError]))
    self.assertLen(type_folder.local_namespace.valid_types_map, 1)
    self.assertIn(good_type.typename,
                  type_folder.local_namespace.valid_types_map)
    self.assertEqual(
        type_folder.local_namespace.valid_types_map.get(good_type.typename),
        good_type)
コード例 #9
0
    def testAddDuplicateTypes(self):
        fields_universe = field_lib.FieldUniverse([])
        fields_universe._namespace_map = {'': ('animal'), 'ANIMAL': ('meow')}
        folderpath = 'ANIMAL/entity_types'
        type_folder = entity_type_lib.EntityTypeFolder(folderpath,
                                                       fields_universe)
        self.assertFalse(type_folder.GetFindings())

        rel_typepath = os.path.join(folderpath, 'mammal')
        # entity type
        entity_type = entity_type_lib.EntityType(
            filepath=rel_typepath,
            typename='kitty',
            description='feline animal',
            local_field_tuples=_FS(['ANIMAL/meow', '/animal']))
        # duplicate type
        dup_type = entity_type_lib.EntityType(filepath=rel_typepath,
                                              typename='kitty',
                                              description='feline animal',
                                              local_field_tuples=_FS(
                                                  ['ANIMAL/meow', '/animal']))

        type_folder._AddType(entity_type)
        type_folder._AddType(dup_type)

        self.assertTrue(
            type_folder.local_namespace.HasFindingTypes(
                [findings_lib.DuplicateTypesError]))
        self.assertLen(type_folder.local_namespace.valid_types_map, 1)
        self.assertIn(entity_type.typename,
                      type_folder.local_namespace.valid_types_map)
        self.assertEqual(
            type_folder.local_namespace.valid_types_map.get(
                entity_type.typename), entity_type)
コード例 #10
0
    def testAddTypeWithNamespacedField(self):
        fields_universe = field_lib.FieldUniverse([])
        fields_universe._namespace_map = {
            '': [field_lib.Field('animal')],
            'ANIMAL': [field_lib.Field('meow')],
            'ATTACK': [field_lib.Field('claws')]
        }
        folderpath = 'ANIMAL/entity_types'
        type_folder = entity_type_lib.EntityTypeFolder(folderpath,
                                                       fields_universe)
        self.assertFalse(type_folder.GetFindings())

        rel_typepath = os.path.join(folderpath, 'mammal')

        # field 'claws' is undefined.
        entity_type = entity_type_lib.EntityType(
            filepath=rel_typepath,
            typename='cat',
            description='feline animal',
            local_field_tuples=_FS(['ANIMAL/meow', 'ATTACK/claws', '/animal']))
        type_folder._AddType(entity_type)

        self.assertFalse(type_folder.local_namespace.GetFindings())
        self.assertLen(type_folder.local_namespace.valid_types_map, 1)
        self.assertIn(entity_type.typename,
                      type_folder.local_namespace.valid_types_map)
        self.assertEqual(
            type_folder.local_namespace.valid_types_map.get(
                entity_type.typename), entity_type)
コード例 #11
0
    def testGetFieldFromConfigText(self):
        entity_type = entity_type_lib.EntityType(
            filepath='path/to/ANIMAL/mammal',
            description='canine animal',
            local_field_tuples=_FS(['HAPPY/wag', '/woof', 'ANIMALS/fuzzy']),
            inherited_fields_expanded=True,
            namespace=entity_type_lib.TypeNamespace('ANIMALS'))
        self.assertEqual(
            'fuzzy',
            entity_type.GetFieldFromConfigText('fuzzy').field.field)
        self.assertEqual(
            'fuzzy',
            entity_type.GetFieldFromConfigText('ANIMALS/fuzzy').field.field)
        self.assertEqual(
            'wag',
            entity_type.GetFieldFromConfigText('HAPPY/wag').field.field)
        self.assertEqual(
            'woof',
            entity_type.GetFieldFromConfigText('woof').field.field)
        self.assertEqual(
            'woof',
            entity_type.GetFieldFromConfigText('/woof').field.field)

        self.assertIsNone(entity_type.GetFieldFromConfigText('/wag'))
        self.assertIsNone(entity_type.GetFieldFromConfigText('wag'))
コード例 #12
0
    def testEntityTypeUniverseGetFindings(self):
        filepath = _GOOD_PATH + '/file.yaml'
        context = findings_lib.FileContext(filepath)
        folder = entity_type_lib.EntityTypeFolder(_GOOD_PATH)
        folder.AddFinding(
            findings_lib.InconsistentFileLocationError('', context))
        namespace = folder.local_namespace
        namespace.AddFinding(findings_lib.IllegalCharacterError(
            'two', context))
        # This will generate a MissingDescriptionWarning on itself
        entity_type = entity_type_lib.EntityType(typename='one',
                                                 filepath=filepath)
        namespace.InsertType(entity_type)

        types_universe = entity_type_lib.EntityTypeUniverse([folder])

        findings = types_universe.GetFindings()
        self.assertLen(findings, 3)
        self.assertTrue(
            types_universe.HasFindingTypes([
                findings_lib.InconsistentFileLocationError,
                findings_lib.IllegalCharacterError,
                findings_lib.MissingDescriptionWarning
            ]))
        self.assertFalse(types_universe.IsValid())
コード例 #13
0
  def testIllegalTypenameType(self):
    entity_type = entity_type_lib.EntityType(
        filepath='path/to/ANIMAL/mammal', typename=True, description='false')

    errors = entity_type.GetFindings()
    self.assertLen(errors, 1)
    self.assertTrue(
        entity_type.HasFindingTypes([findings_lib.IllegalKeyTypeError]))
    self.assertFalse(entity_type.IsValid())
コード例 #14
0
    def testBackwardsCompatibilityOptionalAddedFieldsOk(self):
        # Two types.  One is abstract.
        ns1_path = '{0}/entity_types/anyfolder'.format('namespace_one')
        folder1 = entity_type_lib.EntityTypeFolder(ns1_path)
        ns1 = folder1.local_namespace
        type1 = entity_type_lib.EntityType(filepath=ns1_path + '/file.yaml',
                                           typename='type1',
                                           local_field_tuples=_F(['local1']),
                                           inherited_fields_expanded=True)
        ns1.InsertType(type1)
        type2 = entity_type_lib.EntityType(filepath=ns1_path + '/file.yaml',
                                           typename='type2',
                                           local_field_tuples=_F(['local1']),
                                           inherited_fields_expanded=True)
        ns1.InsertType(type2)
        old_uv = entity_type_lib.EntityTypeUniverse([folder1])

        # Same Types with added fields
        folder1a = entity_type_lib.EntityTypeFolder(ns1_path)
        ns1a = folder1a.local_namespace
        type1a = entity_type_lib.EntityType(
            filepath=ns1_path + '/file.yaml',
            typename='type1',
            local_field_tuples=[_F1('local1', False),
                                _F1('local2', False)],
            inherited_fields_expanded=True)
        ns1a.InsertType(type1a)
        type2a = entity_type_lib.EntityType(
            filepath=ns1_path + '/file.yaml',
            typename='type2',
            local_field_tuples=[_F1('local1', False),
                                _F1('local2', True)],
            inherited_fields_expanded=True)
        ns1a.InsertType(type2a)
        new_uv = entity_type_lib.EntityTypeUniverse([folder1a])

        findings = presubmit_validate_types_lib.CheckBackwardsCompatibility(
            new_uv, old_uv)

        self.assertLen(findings, 1)
        self.assertTrue(
            type1a.HasFindingTypes([findings_lib.AddedFieldWarning]))
        self.assertFalse(
            type2a.HasFindingTypes([findings_lib.AddedFieldWarning]))
コード例 #15
0
    def testGoodEntityType(self):
        entity_type = entity_type_lib.EntityType(
            filepath='path/to/ANIMAL/mammal',
            typename='dog',
            description='canine animal',
            local_field_tuples=_FS(['/woof', '/wag']),
            parents=['wolf', 'ANIMAL', 'dingo'])

        self.assertFalse(entity_type.GetFindings())
        self.assertTrue(entity_type.IsValid())
コード例 #16
0
    def testMissingDescription(self):
        entity_type = entity_type_lib.EntityType(
            filepath='path/to/ANIMAL/mammal', typename='dog')

        errors = entity_type.GetFindings()
        self.assertLen(errors, 1)
        self.assertTrue(
            entity_type.HasFindingTypes(
                [findings_lib.MissingDescriptionWarning]))
        self.assertTrue(entity_type.IsValid())
コード例 #17
0
    def testMissingTypename(self):
        entity_type = entity_type_lib.EntityType(
            filepath='path/to/ANIMAL/mammal',
            description='canine animal',
            local_field_tuples=_FS(['/woof', '/wag']))

        errors = entity_type.GetFindings()
        self.assertLen(errors, 1)
        self.assertTrue(
            entity_type.HasFindingTypes([findings_lib.MissingTypenameError]))
        self.assertFalse(entity_type.IsValid())
コード例 #18
0
    def testHasField(self):
        entity_type = entity_type_lib.EntityType(
            filepath='path/to/ANIMAL/mammal',
            description='canine animal',
            local_field_tuples=_FS(['HAPPY/wag']),
            inherited_fields_expanded=True)
        entity_type.inherited_field_names['/woof'] = _F('/woof')

        self.assertTrue(entity_type.HasField('HAPPY/wag'))
        self.assertTrue(entity_type.HasField('/woof'))
        self.assertFalse(entity_type.HasField('SAD/wag'))
コード例 #19
0
    def testDuplicateFieldsWithDifferentCaps(self):
        entity_type = entity_type_lib.EntityType(
            filepath='path/to/ANIMAL/mammal',
            typename='cat',
            description='feline animal',
            local_field_tuples=_FS(['/mEow', '/claws', '/meow']))

        errors = entity_type.GetFindings()
        self.assertLen(errors, 1)
        self.assertTrue(
            entity_type.HasFindingTypes([findings_lib.DuplicateFieldError]))
        self.assertFalse(entity_type.IsValid())
コード例 #20
0
 def testSmallDeviationFindingEqualityKey(self):
     parents = ['wolf', 'ANIMAL', 'dingo']
     entity_type = entity_type_lib.EntityType(
         filepath='path/to/ANIMAL/mammal',
         typename='dog',
         description='canine animal')
     key = object()
     finding1 = findings_lib.SmallFieldDeviationWarning(
         entity_type, parents, 3, _F(['a', 'b']), key)
     finding2 = findings_lib.SmallFieldDeviationWarning(
         entity_type, parents, 3, _F(['a', 'b']), key)
     self.assertEqual(finding1, finding2)
コード例 #21
0
    def testDuplicateParents(self):
        entity_type = entity_type_lib.EntityType(
            filepath='path/to/ANIMAL/mammal',
            typename='dog',
            description='canine animal',
            parents=['wolf', 'wolf'])

        errors = entity_type.GetFindings()
        self.assertLen(errors, 1)
        self.assertTrue(
            entity_type.HasFindingTypes([findings_lib.DuplicateParentError]))
        self.assertFalse(entity_type.IsValid())
コード例 #22
0
    def testTypesWithEmptyFields(self):
        type1 = entity_type_lib.EntityType(filepath='path/to/ANIMAL/mammal',
                                           typename='dog',
                                           description='canine animal')

        type2 = entity_type_lib.EntityType(filepath='path/to/ANIMAL/mammal',
                                           typename='wolf',
                                           description='canine animal')

        type_namespace = entity_type_lib.TypeNamespace(namespace='ANIMAL')
        type_namespace.InsertType(type1)
        type_namespace.InsertType(type2)

        namespace_validator.NamespaceValidator([type_namespace])

        self.assertFalse(
            type1.HasFindingTypes(
                [findings_lib.DuplicateLocalFieldSetsWarning]))
        self.assertFalse(
            type2.HasFindingTypes(
                [findings_lib.DuplicateLocalFieldSetsWarning]))
コード例 #23
0
    def testSetsInheritedOptionality(self):
        type1 = entity_type_lib.EntityType(filepath='path/to/ANIMAL/mammal',
                                           typename='dog',
                                           description='canine animal',
                                           local_field_tuples=[
                                               _F1('/woof', optional=True),
                                               _F1('/growl', optional=True)
                                           ],
                                           parents=[])

        type2 = entity_type_lib.EntityType(filepath='path/to/ANIMAL/mammal',
                                           typename='wolf',
                                           description='canine animal',
                                           local_field_tuples=[
                                               _F1('/woof', optional=True),
                                               _F1('/growl', optional=False)
                                           ],
                                           parents=[])

        type3 = entity_type_lib.EntityType(
            filepath='path/to/ANIMAL/mammal',
            typename='dingo',
            description='canine animal',
            local_field_tuples=[_F1('/wag', optional=False)],
            parents=['ANIMAL/dog', 'ANIMAL/wolf'])

        type_namespace_1 = entity_type_lib.TypeNamespace(namespace='ANIMAL')
        type_namespace_1.InsertType(type1)
        type_namespace_1.InsertType(type2)
        type_namespace_1.InsertType(type3)

        namespace_validate = (namespace_validator.NamespaceValidator(
            [type_namespace_1]))

        self.assertTrue(namespace_validate.IsValid())
        field_map = type3.GetAllFields()
        self.assertFalse(field_map['/growl'].optional)
        self.assertTrue(field_map['/woof'].optional)
        self.assertFalse(field_map['/wag'].optional)
コード例 #24
0
    def testGoodFieldIncrement(self):
        entity_type = entity_type_lib.EntityType(
            filepath='path/to/ANIMAL/mammal',
            typename='dog',
            description='canine animal',
            local_field_tuples=_F(['/woof', '/woof_1']))

        type_namespace = entity_type_lib.TypeNamespace(namespace='ANIMAL')
        type_namespace.InsertType(entity_type)
        namespace_validate = (namespace_validator.NamespaceValidator(
            [type_namespace]))

        self.assertTrue(namespace_validate.IsValid())
コード例 #25
0
  def testInheritedFieldsSet(self):
    entity_type = entity_type_lib.EntityType(
        filepath='path/to/ANIMAL/mammal',
        typename='dog',
        description='canine animal',
        local_field_tuples=_FS(['/woof', '/wag']),
        inherited_fields_expanded=True)

    errors = entity_type.GetFindings()
    self.assertLen(errors, 1)
    self.assertTrue(
        entity_type.HasFindingTypes([findings_lib.InheritedFieldsSetError]))
    self.assertFalse(entity_type.IsValid())
コード例 #26
0
    def testInheritingFromPassthroughIsError(self):
        passthrough_type = entity_type_lib.EntityType(
            filepath='path/to/ANIMAL/gateway',
            typename='dog',
            description='a gateway to dogs',
            allow_undefined_fields=True)
        entity_type = entity_type_lib.EntityType(
            filepath='path/to/ANIMAL/mammal',
            typename='dingo',
            description='canine animal',
            local_field_tuples=_F(['/woof']),
            parents=['ANIMAL/dog'])

        type_namespace = entity_type_lib.TypeNamespace(namespace='ANIMAL')
        type_namespace.InsertType(passthrough_type)
        type_namespace.InsertType(entity_type)
        namespace_validate = (namespace_validator.NamespaceValidator(
            [type_namespace]))

        self.assertTrue(
            namespace_validate.HasFindingTypes(
                [findings_lib.PassthroughParentError]))
コード例 #27
0
    def testBadFieldFormat(self):
        entity_type = entity_type_lib.EntityType(
            filepath='path/to/ANIMAL/mammal',
            typename='cat',
            description='feline animal',
            local_field_tuples=_FS(['/meow', 'NS/wrong/claws']))

        errors = entity_type.GetFindings()
        self.assertLen(errors, 1)
        self.assertTrue(
            entity_type.HasFindingTypes(
                [findings_lib.UnrecognizedFieldFormatError]))
        self.assertFalse(entity_type.IsValid())
コード例 #28
0
    def testGoodPassthroughType(self):
        passthrough_type = entity_type_lib.EntityType(
            filepath='path/to/ANIMAL/gateway',
            typename='dog',
            description='a gateway to dogs',
            allow_undefined_fields=True,
            local_field_tuples=_F(['/woof_1', '/woof_2', '/woof_3']))

        type_namespace = entity_type_lib.TypeNamespace(namespace='ANIMAL')
        type_namespace.InsertType(passthrough_type)
        namespace_validate = (namespace_validator.NamespaceValidator(
            [type_namespace]))

        self.assertTrue(namespace_validate.IsValid())
コード例 #29
0
    def testInheritTypesFromDifferentNamespaceError(self):
        type1 = entity_type_lib.EntityType(filepath='path/to/ANIMAL/mammal',
                                           typename='dog',
                                           description='canine animal',
                                           local_field_tuples=_F(
                                               ['/woof', '/howl']))

        type2 = entity_type_lib.EntityType(filepath='path/to/INSECT/fly',
                                           typename='moth',
                                           description='flying insect.',
                                           local_field_tuples=_F(['/wings']),
                                           parents=['ANIMALLLLL/dog'])

        type_namespace_1 = entity_type_lib.TypeNamespace(namespace='ANIMAL')
        type_namespace_1.InsertType(type1)
        type_namespace_2 = entity_type_lib.TypeNamespace(namespace='INSECT')
        type_namespace_2.InsertType(type2)
        namespace_validate = (namespace_validator.NamespaceValidator(
            [type_namespace_1, type_namespace_2]))

        self.assertTrue(
            namespace_validate.HasFindingTypes(
                [findings_lib.NonexistentParentError]))
コード例 #30
0
  def testIllegalAbstractPassthroughType(self):
    entity_type = entity_type_lib.EntityType(
        filepath='path/to/ANIMAL/mammal',
        typename='dog',
        description='canine animal',
        is_abstract=True,
        allow_undefined_fields=True)

    errors = entity_type.GetFindings()
    self.assertLen(errors, 1)
    self.assertTrue(
        entity_type.HasFindingTypes([findings_lib.AbstractPassthroughTypeError
                                    ]))
    self.assertFalse(entity_type.IsValid())