예제 #1
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)
예제 #2
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]))
예제 #3
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]))
예제 #4
0
    def testBackwardsCompatibilityRemovedFields(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', 'local2']),
                                           inherited_fields_expanded=True)
        type1.inherited_field_names = {
            '/inherited1': _F1('/inherited1', False),
            '/inherited2': _F1('/inherited2', False)
        }
        ns1.InsertType(type1)
        type2 = entity_type_lib.EntityType(filepath=ns1_path + '/file.yaml',
                                           typename='type2',
                                           local_field_tuples=_F(
                                               ['abstract1', 'abstract2']),
                                           inherited_fields_expanded=True,
                                           is_abstract=True)
        type2.inherited_field_names = {
            '/abstract1a': _F1('/abstract1a', False),
            '/abstract2a': _F1('/abstract2a', False)
        }
        ns1.InsertType(type2)
        old_uv = entity_type_lib.EntityTypeUniverse([folder1])

        # Same Types with removed 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=_F(['local1']),
                                            inherited_fields_expanded=True)
        type1a.inherited_field_names = {
            '/inherited1': _F1('/inherited1', False)
        }
        ns1a.InsertType(type1a)
        type2a = entity_type_lib.EntityType(filepath=ns1_path + '/file.yaml',
                                            typename='type2',
                                            local_field_tuples=_F(
                                                ['abstract1']),
                                            inherited_fields_expanded=True,
                                            is_abstract=True)
        type2a.inherited_field_names = {
            '/abstract1a': _F1('/abstract1a', False)
        }
        ns1a.InsertType(type2a)
        new_uv = entity_type_lib.EntityTypeUniverse([folder1a])

        findings = presubmit_validate_types_lib.CheckBackwardsCompatibility(
            new_uv, old_uv)
        self.assertLen(findings, 2)
        field1 = 'local2'
        field2 = 'inherited2'
        if field1 not in str(findings[0]):
            field1 = 'inherited2'
            field2 = 'local2'
        self.assertIsInstance(findings[0], findings_lib.RemovedFieldWarning)
        self.assertIn(field1, str(findings[0]))
        self.assertIsInstance(findings[1], findings_lib.RemovedFieldWarning)
        self.assertIn(field2, str(findings[1]))