当前位置: 首页>>代码示例>>Python>>正文


Python enum.EnumMeta方法代码示例

本文整理汇总了Python中enum.EnumMeta方法的典型用法代码示例。如果您正苦于以下问题:Python enum.EnumMeta方法的具体用法?Python enum.EnumMeta怎么用?Python enum.EnumMeta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在enum的用法示例。


在下文中一共展示了enum.EnumMeta方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_inspect_getmembers

# 需要导入模块: import enum [as 别名]
# 或者: from enum import EnumMeta [as 别名]
def test_inspect_getmembers(self):
        values = dict((
                ('__class__', EnumMeta),
                ('__doc__', 'An enumeration.'),
                ('__members__', self.Color.__members__),
                ('__module__', __name__),
                ('blue', self.Color.blue),
                ('green', self.Color.green),
                ('name', Enum.__dict__['name']),
                ('red', self.Color.red),
                ('value', Enum.__dict__['value']),
                ))
        result = dict(inspect.getmembers(self.Color))
        self.assertEqual(values.keys(), result.keys())
        failed = False
        for k in values.keys():
            if result[k] != values[k]:
                print()
                print('\n%s\n     key: %s\n  result: %s\nexpected: %s\n%s\n' %
                        ('=' * 75, k, result[k], values[k], '=' * 75), sep='')
                failed = True
        if failed:
            self.fail("result does not equal expected, see print above") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:test_enum.py

示例2: test_inspect_getmembers

# 需要导入模块: import enum [as 别名]
# 或者: from enum import EnumMeta [as 别名]
def test_inspect_getmembers(self):
        values = dict((
                ('__class__', EnumMeta),
                ('__doc__', None),
                ('__members__', self.Color.__members__),
                ('__module__', __name__),
                ('blue', self.Color.blue),
                ('green', self.Color.green),
                ('name', Enum.__dict__['name']),
                ('red', self.Color.red),
                ('value', Enum.__dict__['value']),
                ))
        result = dict(inspect.getmembers(self.Color))
        self.assertEqual(values.keys(), result.keys())
        failed = False
        for k in values.keys():
            if result[k] != values[k]:
                print()
                print('\n%s\n     key: %s\n  result: %s\nexpected: %s\n%s\n' %
                        ('=' * 75, k, result[k], values[k], '=' * 75), sep='')
                failed = True
        if failed:
            self.fail("result does not equal expected, see print above") 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:25,代码来源:test_enum.py

示例3: test_substory_protocol_match_with_enum

# 需要导入模块: import enum [as 别名]
# 或者: from enum import EnumMeta [as 别名]
def test_substory_protocol_match_with_enum(r, f):
    """We should allow to use stories composition, if parent story protocol is a
    superset of the substory protocol."""

    class T(f.ChildWithEnum, f.EnumMethod):
        pass

    class J(f.WideParentWithEnum, f.NormalParentMethod):
        def __init__(self):
            self.x = T().x

    # Substory DI.

    assert isinstance(J().a.failures, enum.EnumMeta)
    assert set(J().a.failures.__members__.keys()) == {"foo", "bar", "baz", "quiz"}

    with pytest.raises(FailureError) as exc_info:
        r(J().a)()
    assert repr(exc_info.value) == "FailureError(<Errors.foo: 1>)"

    result = r(J().a.run)()
    assert result.failed_because(J().a.failures.foo) 
开发者ID:proofit404,项目名称:stories,代码行数:24,代码来源:test_failure_reasons.py

示例4: test_expand_substory_protocol_enum_with_null

# 需要导入模块: import enum [as 别名]
# 或者: from enum import EnumMeta [as 别名]
def test_expand_substory_protocol_enum_with_null(r, f):
    """We expand protocol of composed story, if substory define protocol with enum class
    and parent story does not define protocol."""

    class T(f.ChildWithEnum, f.NormalMethod):
        pass

    class J(f.ParentWithNull, f.NormalParentMethod):
        def __init__(self):
            self.x = T().x

    # Substory DI.

    assert isinstance(J().a.failures, enum.EnumMeta)
    assert set(J().a.failures.__members__.keys()) == {"foo", "bar", "baz"}

    result = r(J().a)()
    assert result is None

    result = r(J().a.run)()
    assert result.is_success
    assert result.value is None 
开发者ID:proofit404,项目名称:stories,代码行数:24,代码来源:test_failure_reasons.py

示例5: test_expand_substory_protocol_enum_with_enum

# 需要导入模块: import enum [as 别名]
# 或者: from enum import EnumMeta [as 别名]
def test_expand_substory_protocol_enum_with_enum(r, f):
    """We expand protocol of composed story, if substory and parent story define
    protocol with enum class."""

    class T(f.ChildWithEnum, f.EnumMethod):
        pass

    class J(f.ShrinkParentWithEnum, f.NormalParentMethod):
        def __init__(self):
            self.x = T().x

    # Substory DI.

    assert isinstance(J().a.failures, enum.EnumMeta)
    assert set(J().a.failures.__members__.keys()) == {"foo", "bar", "baz", "quiz"}

    with pytest.raises(FailureError) as exc_info:
        r(J().a)()
    assert repr(exc_info.value) == "FailureError(<Errors.foo: 1>)"

    result = r(J().a.run)()
    assert result.failed_because(J().a.failures.foo) 
开发者ID:proofit404,项目名称:stories,代码行数:24,代码来源:test_failure_reasons.py

示例6: enum_check

# 需要导入模块: import enum [as 别名]
# 或者: from enum import EnumMeta [as 别名]
def enum_check(*args, stacklevel=2):
    """Check if arguments are of *enumeration protocol* type (``enum.EnumMeta`` and/or ``aenum.EnumMeta``).

    Args:
        *args: Arguments to check.
        stacklevel (int): Stack level to fetch originated function name.

    Raises:
        EnumError: If any of the arguments is **NOT** *enumeration protocol* type
            (``enum.EnumMeta`` and/or ``aenum.EnumMeta``).

    """
    for var in args:
        if not isinstance(var, (enum.EnumMeta, aenum.EnumMeta)):
            name = type(var).__name__
            func = inspect.stack()[stacklevel][3]
            raise EnumError(f'Function {func} expected enumeration, {name} got instead.') 
开发者ID:JarryShaw,项目名称:PyPCAPKit,代码行数:19,代码来源:validations.py

示例7: test_multiple_mixin_mro

# 需要导入模块: import enum [as 别名]
# 或者: from enum import EnumMeta [as 别名]
def test_multiple_mixin_mro(self):
        class auto_enum(EnumMeta):
            def __new__(metacls, cls, bases, classdict):
                original_dict = classdict
                classdict = enum._EnumDict()
                for k, v in original_dict.items():
                    classdict[k] = v
                temp = type(classdict)()
                names = set(classdict._member_names)
                i = 0
                for k in classdict._member_names:
                    v = classdict[k]
                    if v == ():
                        v = i
                    else:
                        i = v
                    i += 1
                    temp[k] = v
                for k, v in classdict.items():
                    if k not in names:
                        temp[k] = v
                return super(auto_enum, metacls).__new__(
                        metacls, cls, bases, temp)

        AutoNumberedEnum = auto_enum('AutoNumberedEnum', (Enum,), {})

        AutoIntEnum = auto_enum('AutoIntEnum', (IntEnum,), {})

        class TestAutoNumber(AutoNumberedEnum):
            a = ()
            b = 3
            c = ()

        class TestAutoInt(AutoIntEnum):
            a = ()
            b = 3
            c = () 
开发者ID:typeintandem,项目名称:tandem,代码行数:39,代码来源:test.py

示例8: test_inspect_classify_class_attrs

# 需要导入模块: import enum [as 别名]
# 或者: from enum import EnumMeta [as 别名]
def test_inspect_classify_class_attrs(self):
        # indirectly test __objclass__
        from inspect import Attribute
        values = [
                Attribute(name='__class__', kind='data',
                    defining_class=object, object=EnumMeta),
                Attribute(name='__doc__', kind='data',
                    defining_class=self.Color, object='An enumeration.'),
                Attribute(name='__members__', kind='property',
                    defining_class=EnumMeta, object=EnumMeta.__members__),
                Attribute(name='__module__', kind='data',
                    defining_class=self.Color, object=__name__),
                Attribute(name='blue', kind='data',
                    defining_class=self.Color, object=self.Color.blue),
                Attribute(name='green', kind='data',
                    defining_class=self.Color, object=self.Color.green),
                Attribute(name='red', kind='data',
                    defining_class=self.Color, object=self.Color.red),
                Attribute(name='name', kind='data',
                    defining_class=Enum, object=Enum.__dict__['name']),
                Attribute(name='value', kind='data',
                    defining_class=Enum, object=Enum.__dict__['value']),
                ]
        values.sort(key=lambda item: item.name)
        result = list(inspect.classify_class_attrs(self.Color))
        result.sort(key=lambda item: item.name)
        failed = False
        for v, r in zip(values, result):
            if r != v:
                print('\n%s\n%s\n%s\n%s\n' % ('=' * 75, r, v, '=' * 75), sep='')
                failed = True
        if failed:
            self.fail("result does not equal expected, see print above") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:35,代码来源:test_enum.py

示例9: validate

# 需要导入模块: import enum [as 别名]
# 或者: from enum import EnumMeta [as 别名]
def validate(self):
        """
        Verify that the value of the Enumeration is valid.

        Raises:
            TypeError: if the enum is not of type Enum
            ValueError: if the value is not of the expected Enum subtype or if
                the value cannot be represented by an unsigned 32-bit integer
        """
        if not isinstance(self.enum, enumeration.EnumMeta):
            raise TypeError(
                'enumeration type {0} must be of type EnumMeta'.format(
                    self.enum))
        if self.value is not None:
            if not isinstance(self.value, self.enum):
                raise TypeError(
                    'enumeration {0} must be of type {1}'.format(
                        self.value, self.enum))
            if type(self.value.value) not in six.integer_types:
                raise TypeError('enumeration value must be an int')
            else:
                if self.value.value > Enumeration.MAX:
                    raise ValueError(
                        'enumeration value greater than accepted max')
                elif self.value.value < Enumeration.MIN:
                    raise ValueError(
                        'enumeration value less than accepted min') 
开发者ID:OpenKMIP,项目名称:PyKMIP,代码行数:29,代码来源:primitives.py

示例10: test_inspect_classify_class_attrs

# 需要导入模块: import enum [as 别名]
# 或者: from enum import EnumMeta [as 别名]
def test_inspect_classify_class_attrs(self):
        # indirectly test __objclass__
        from inspect import Attribute
        values = [
                Attribute(name='__class__', kind='data',
                    defining_class=object, object=EnumMeta),
                Attribute(name='__doc__', kind='data',
                    defining_class=self.Color, object=None),
                Attribute(name='__members__', kind='property',
                    defining_class=EnumMeta, object=EnumMeta.__members__),
                Attribute(name='__module__', kind='data',
                    defining_class=self.Color, object=__name__),
                Attribute(name='blue', kind='data',
                    defining_class=self.Color, object=self.Color.blue),
                Attribute(name='green', kind='data',
                    defining_class=self.Color, object=self.Color.green),
                Attribute(name='red', kind='data',
                    defining_class=self.Color, object=self.Color.red),
                Attribute(name='name', kind='data',
                    defining_class=Enum, object=Enum.__dict__['name']),
                Attribute(name='value', kind='data',
                    defining_class=Enum, object=Enum.__dict__['value']),
                ]
        values.sort(key=lambda item: item.name)
        result = list(inspect.classify_class_attrs(self.Color))
        result.sort(key=lambda item: item.name)
        failed = False
        for v, r in zip(values, result):
            if r != v:
                print('\n%s\n%s\n%s\n%s\n' % ('=' * 75, r, v, '=' * 75), sep='')
                failed = True
        if failed:
            self.fail("result does not equal expected, see print above") 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:35,代码来源:test_enum.py

示例11: convert_choice_to_enum

# 需要导入模块: import enum [as 别名]
# 或者: from enum import EnumMeta [as 别名]
def convert_choice_to_enum(type, column, registry=None):
    name = "{}_{}".format(column.table.name, column.name).upper()
    if isinstance(type.choices, EnumMeta):
        # type.choices may be Enum/IntEnum, in ChoiceType both presented as EnumMeta
        # do not use from_enum here because we can have more than one enum column in table
        return Enum(name, list((v.name, v.value) for v in type.choices))
    else:
        return Enum(name, type.choices) 
开发者ID:graphql-python,项目名称:graphene-sqlalchemy,代码行数:10,代码来源:converter.py

示例12: test_reasons_defined_with_enum

# 需要导入模块: import enum [as 别名]
# 或者: from enum import EnumMeta [as 别名]
def test_reasons_defined_with_enum(r, f):
    """We can use enum class to define story failure protocol."""

    class T(f.ChildWithEnum, f.EnumMethod):
        pass

    class J(f.ParentWithEnum, f.NormalParentMethod):
        def __init__(self):
            self.x = T().x

    # Simple.

    assert isinstance(T().x.failures, enum.EnumMeta)
    assert set(T().x.failures.__members__.keys()) == {"foo", "bar", "baz"}

    with pytest.raises(FailureError) as exc_info:
        r(T().x)()
    assert repr(exc_info.value) == "FailureError(<Errors.foo: 1>)"

    result = r(T().x.run)()
    assert not result.is_success
    assert result.is_failure
    assert result.failed_because(T().x.failures.foo)

    # Substory DI.

    assert isinstance(J().a.failures, enum.EnumMeta)
    assert set(J().a.failures.__members__.keys()) == {"foo", "bar", "baz"}

    with pytest.raises(FailureError) as exc_info:
        r(J().a)()
    assert repr(exc_info.value) == "FailureError(<Errors.foo: 1>)"

    result = r(J().a.run)()
    assert not result.is_success
    assert result.is_failure
    assert result.failed_because(J().a.failures.foo) 
开发者ID:proofit404,项目名称:stories,代码行数:39,代码来源:test_failure_reasons.py

示例13: test_deny_failure_substory_without_protocol_story_protocol_with_enum

# 需要导入模块: import enum [as 别名]
# 或者: from enum import EnumMeta [as 别名]
def test_deny_failure_substory_without_protocol_story_protocol_with_enum(r, f):
    """Substory defined without failure protocol can not return Failure, if this
    substory was composed with parent story defined with enum as failure protocol."""

    class T(f.ChildWithNull, f.NullMethod):
        pass

    class J(f.ParentWithEnum, f.NormalParentMethod):
        def __init__(self):
            self.x = T().x

    # Substory DI.

    expected = """
Failure() can not be used in a story composition.

Different types of failure protocol were used in parent and substory definitions.

Function returned value: T.one

Use 'failures' story method to define failure protocol.
    """.strip()

    assert isinstance(J().a.failures, enum.EnumMeta)
    assert set(J().a.failures.__members__.keys()) == {"foo", "bar", "baz"}

    with pytest.raises(FailureProtocolError) as exc_info:
        r(J().a)()
    assert str(exc_info.value) == expected

    with pytest.raises(FailureProtocolError) as exc_info:
        r(J().a.run)()
    assert str(exc_info.value) == expected 
开发者ID:proofit404,项目名称:stories,代码行数:35,代码来源:test_failure_reasons.py

示例14: test_deny_failure_story_without_protocol_substory_protocol_with_enum

# 需要导入模块: import enum [as 别名]
# 或者: from enum import EnumMeta [as 别名]
def test_deny_failure_story_without_protocol_substory_protocol_with_enum(r, f):
    """Story defined without failure protocol can not return Failure, if this story was
    composed with substory defined with enum as failure protocol."""

    class T(f.ChildWithEnum, f.NormalMethod):
        pass

    class J(f.ParentWithNull, f.NullParentMethod):
        def __init__(self):
            self.x = T().x

    # Substory DI.

    expected = """
Failure() can not be used in a story composition.

Different types of failure protocol were used in parent and substory definitions.

Function returned value: J.before

Use 'failures' story method to define failure protocol.
    """.strip()

    assert isinstance(J().a.failures, enum.EnumMeta)
    assert set(J().a.failures.__members__.keys()) == {"foo", "bar", "baz"}

    with pytest.raises(FailureProtocolError) as exc_info:
        r(J().a)()
    assert str(exc_info.value) == expected

    with pytest.raises(FailureProtocolError) as exc_info:
        r(J().a.run)()
    assert str(exc_info.value) == expected 
开发者ID:proofit404,项目名称:stories,代码行数:35,代码来源:test_failure_reasons.py

示例15: test_expand_sequential_substory_protocol_enum_with_null

# 需要导入模块: import enum [as 别名]
# 或者: from enum import EnumMeta [as 别名]
def test_expand_sequential_substory_protocol_enum_with_null(r, f):
    """If parent story consist from sequential substories, we should merge their failure
    protocols together."""

    class T(f.ChildWithEnum, f.EnumMethod):
        pass

    class E(f.NextChildWithNull, f.NormalMethod):
        pass

    class J(f.SequenceParentWithNull, f.NormalParentMethod):
        def __init__(self):
            self.x = T().x
            self.y = E().y

    # Substory DI.

    assert isinstance(J().a.failures, enum.EnumMeta)
    assert set(J().a.failures.__members__.keys()) == {"foo", "bar", "baz"}

    with pytest.raises(FailureError) as exc_info:
        r(J().a)()
    assert repr(exc_info.value) == "FailureError(<Errors.foo: 1>)"

    result = r(J().a.run)()
    assert result.failed_because(J().a.failures.foo) 
开发者ID:proofit404,项目名称:stories,代码行数:28,代码来源:test_failure_reasons.py


注:本文中的enum.EnumMeta方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。