<commit_before>#!/usr/bin/env python
#
# Copyright 2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

"""Tests for apitools.base.protorpclite.descriptor."""
import types
import unittest

import six

from apitools.base.protorpclite import descriptor
from apitools.base.protorpclite import message_types
from apitools.base.protorpclite import messages
from apitools.base.protorpclite import test_util


RUSSIA = u'\u0420\u043e\u0441\u0441\u0438\u044f'


class ModuleInterfaceTest(test_util.ModuleInterfaceTest,
                          test_util.TestCase):

    MODULE = descriptor


class DescribeEnumValueTest(test_util.TestCase):

    def testDescribe(self):
        class MyEnum(messages.Enum):
            MY_NAME = 10

        expected = descriptor.EnumValueDescriptor()
        expected.name = 'MY_NAME'
        expected.number = 10

        described = descriptor.describe_enum_value(MyEnum.MY_NAME)
        described.check_initialized()
        self.assertEquals(expected, described)


class DescribeEnumTest(test_util.TestCase):

    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 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)

    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]<commit_msg>Add a skip for a pypy test.<commit_after>#!/usr/bin/env python
#
# Copyright 2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

"""Tests for apitools.base.protorpclite.descriptor."""
import platform
import types
import unittest

import six

from apitools.base.protorpclite import descriptor
from apitools.base.protorpclite import message_types
from apitools.base.protorpclite import messages
from apitools.base.protorpclite import test_util


RUSSIA = u'\u0420\u043e\u0441\u0441\u0438\u044f'


class ModuleInterfaceTest(test_util.ModuleInterfaceTest,
                          test_util.TestCase):

    MODULE = descriptor


class DescribeEnumValueTest(test_util.TestCase):

    def testDescribe(self):
        class MyEnum(messages.Enum):
            MY_NAME = 10

        expected = descriptor.EnumValueDescriptor()
        expected.name = 'MY_NAME'
        expected.number = 10

        described = descriptor.describe_enum_value(MyEnum.MY_NAME)
        described.check_initialized()
        self.assertEquals(expected, described)


class DescribeEnumTest(test_util.TestCase):

    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 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)

    @unittest.skipIf('PyPy' in platform.python_implementation(),
                     'todo: reenable this')
    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]
{'fraction_non_alphanumeric': 0.08372911169744943, 'fraction_numerical': 0.014072119613016711, 'mean_word_length': 2.7334208798424164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2225980', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1518, 'n_words': 419}