def testEnumWithItems(self):
        class EnumWithItems(messages.Enum):
            A = 3
            B = 1
            C = 2

        expected = descriptor.EnumDescriptor()
        expected.name = 'EnumWithItems'

        a = descriptor.EnumValueDescriptor()
        a.name = 'A'
        a.number = 3

        b = descriptor.EnumValueDescriptor()
        b.name = 'B'
        b.number = 1

        c = descriptor.EnumValueDescriptor()
        c.name = 'C'
        c.number = 2

        expected.values = [b, c, a]

        described = descriptor.describe_enum(EnumWithItems)
        described.check_initialized()
        self.assertEquals(expected, described)
    def testEmptyEnum(self):
        class EmptyEnum(messages.Enum):
            pass

        expected = descriptor.EnumDescriptor()
        expected.name = 'EmptyEnum'

        described = descriptor.describe_enum(EmptyEnum)
        described.check_initialized()
        self.assertEquals(expected, described)
    def testEnums(self):
        """Test that enums are described."""
        module = self.LoadModule(
            'my.package', 'class Enum1(messages.Enum): pass\n'
            'class Enum2(messages.Enum): pass\n')

        enum1 = descriptor.EnumDescriptor()
        enum1.name = 'Enum1'

        enum2 = descriptor.EnumDescriptor()
        enum2.name = 'Enum2'

        expected = descriptor.FileDescriptor()
        expected.package = 'my.package'
        expected.enum_types = [enum1, enum2]

        described = descriptor.describe_file(module)
        described.check_initialized()
        self.assertEquals(expected, described)
    def testNestedEnum(self):
        class MyScope(messages.Message):
            class NestedEnum(messages.Enum):
                pass

        expected = descriptor.EnumDescriptor()
        expected.name = 'NestedEnum'

        described = descriptor.describe_enum(MyScope.NestedEnum)
        described.check_initialized()
        self.assertEquals(expected, described)