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


Python enum.IntEnum方法代码示例

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


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

示例1: test_programatic_function_type_from_subclass

# 需要导入模块: import enum [as 别名]
# 或者: from enum import IntEnum [as 别名]
def test_programatic_function_type_from_subclass(self):
        SummerMonth = IntEnum('SummerMonth', 'june july august')
        lst = list(SummerMonth)
        self.assertEqual(len(lst), len(SummerMonth))
        self.assertEqual(len(SummerMonth), 3, SummerMonth)
        self.assertEqual(
                [SummerMonth.june, SummerMonth.july, SummerMonth.august],
                lst,
                )
        for i, month in enumerate('june july august'.split()):
            i += 1
            e = SummerMonth(i)
            self.assertEqual(e, i)
            self.assertEqual(e.name, month)
            self.assertTrue(e in SummerMonth)
            self.assertTrue(type(e) is SummerMonth) 
开发者ID:typeintandem,项目名称:tandem,代码行数:18,代码来源:test.py

示例2: test_programatic_function_unicode_type_from_subclass

# 需要导入模块: import enum [as 别名]
# 或者: from enum import IntEnum [as 别名]
def test_programatic_function_unicode_type_from_subclass(self):
        SummerMonth = IntEnum('SummerMonth', unicode('june july august'))
        lst = list(SummerMonth)
        self.assertEqual(len(lst), len(SummerMonth))
        self.assertEqual(len(SummerMonth), 3, SummerMonth)
        self.assertEqual(
                [SummerMonth.june, SummerMonth.july, SummerMonth.august],
                lst,
                )
        for i, month in enumerate(unicode('june july august').split()):
            i += 1
            e = SummerMonth(i)
            self.assertEqual(e, i)
            self.assertEqual(e.name, month)
            self.assertTrue(e in SummerMonth)
            self.assertTrue(type(e) is SummerMonth) 
开发者ID:typeintandem,项目名称:tandem,代码行数:18,代码来源:test.py

示例3: test_introspection

# 需要导入模块: import enum [as 别名]
# 或者: from enum import IntEnum [as 别名]
def test_introspection(self):
        class Number(IntEnum):
            one = 100
            two = 200
        self.assertTrue(Number.one._member_type_ is int)
        self.assertTrue(Number._member_type_ is int)
        class String(str, Enum):
            yarn = 'soft'
            rope = 'rough'
            wire = 'hard'
        self.assertTrue(String.yarn._member_type_ is str)
        self.assertTrue(String._member_type_ is str)
        class Plain(Enum):
            vanilla = 'white'
            one = 1
        self.assertTrue(Plain.vanilla._member_type_ is object)
        self.assertTrue(Plain._member_type_ is object) 
开发者ID:typeintandem,项目名称:tandem,代码行数:19,代码来源:test.py

示例4: check_net_address

# 需要导入模块: import enum [as 别名]
# 或者: from enum import IntEnum [as 别名]
def check_net_address(addr, family):
    """Check a net address validity. Supported families are IPv4,
    IPv6 and MAC addresses.
    """
    import ipaddress  # python >= 3.3 / requires "pip install ipaddress"
    if enum and PY3:
        assert isinstance(family, enum.IntEnum), family
    if family == socket.AF_INET:
        octs = [int(x) for x in addr.split('.')]
        assert len(octs) == 4, addr
        for num in octs:
            assert 0 <= num <= 255, addr
        if not PY3:
            addr = unicode(addr)
        ipaddress.IPv4Address(addr)
    elif family == socket.AF_INET6:
        assert isinstance(addr, str), addr
        if not PY3:
            addr = unicode(addr)
        ipaddress.IPv6Address(addr)
    elif family == psutil.AF_LINK:
        assert re.match(r'([a-fA-F0-9]{2}[:|\-]?){6}', addr) is not None, addr
    else:
        raise ValueError("unknown family %r", family) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:26,代码来源:__init__.py

示例5: allValues

# 需要导入模块: import enum [as 别名]
# 或者: from enum import IntEnum [as 别名]
def allValues(ctype):
  if issubclass(ctype, IntEnum):
    return list(ctype)
  
  if issubclass(ctype, Structure):
    names, types = zip(*ctype._fields)
    values = [allValues(t) for t in types]
    
    def make(vals):
      obj = ctype()
      for name, val in zip(names, vals):
        setattr(obj, name, val)
      return obj
  
    return [make(vals) for vals in product(*values)]
  
  # TODO: handle bounded ints via _fields
  # TODO: handle arrays
  raise TypeError("Unsupported type %s" % ctype) 
开发者ID:vladfi1,项目名称:gym-dolphin,代码行数:21,代码来源:ctype_util.py

示例6: get_class

# 需要导入模块: import enum [as 别名]
# 或者: from enum import IntEnum [as 别名]
def get_class(self):
        """Return a Code class based on current ErrorType value.

        Returns:
            enum.IntEnum: class referenced by current error type.

        """
        classes = {'OFPET_HELLO_FAILED': HelloFailedCode,
                   'OFPET_BAD_REQUEST': BadRequestCode,
                   'OFPET_BAD_ACTION': BadActionCode,
                   'OFPET_BAD_INSTRUCTION': BadInstructionCode,
                   'OFPET_BAD_MATCH': BadMatchCode,
                   'OFPET_FLOW_MOD_FAILED': FlowModFailedCode,
                   'OFPET_GROUP_MOD_FAILED': GroupModFailedCode,
                   'OFPET_PORT_MOD_FAILED': PortModFailedCode,
                   'OFPET_QUEUE_OP_FAILED': QueueOpFailedCode,
                   'OFPET_SWITCH_CONFIG_FAILED': SwitchConfigFailedCode,
                   'OFPET_ROLE_REQUEST_FAILED': RoleRequestFailedCode,
                   'OFPET_METER_MOD_FAILED': MeterModFailedCode,
                   'OFPET_TABLE_MOD_FAILED': TableModFailedCode,
                   'OFPET_TABLE_FEATURES_FAILED': TableFeaturesFailedCode}
        return classes.get(self.name, GenericFailedCode) 
开发者ID:kytos,项目名称:python-openflow,代码行数:24,代码来源:error_msg.py

示例7: test_introspection

# 需要导入模块: import enum [as 别名]
# 或者: from enum import IntEnum [as 别名]
def test_introspection(self):
        class Number(IntEnum):
            one = 100
            two = 200
        self.assertIs(Number.one._member_type_, int)
        self.assertIs(Number._member_type_, int)
        class String(str, Enum):
            yarn = 'soft'
            rope = 'rough'
            wire = 'hard'
        self.assertIs(String.yarn._member_type_, str)
        self.assertIs(String._member_type_, str)
        class Plain(Enum):
            vanilla = 'white'
            one = 1
        self.assertIs(Plain.vanilla._member_type_, object)
        self.assertIs(Plain._member_type_, object) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_enum.py

示例8: payload_as_string

# 需要导入模块: import enum [as 别名]
# 或者: from enum import IntEnum [as 别名]
def payload_as_string(v):
    if isinstance(v, dict):
        return json.dumps(v)
    elif isinstance(v, IntEnum):
        return v.value
    elif not isinstance(v, list):
        return str(v)
    elif len(v) == 1:  # single-element array should be presented as single value
        return payload_as_string(v[0])
    else:
        return json.dumps(v) 
开发者ID:eschava,项目名称:psmqtt,代码行数:13,代码来源:psmqtt.py

示例9: setUp

# 需要导入模块: import enum [as 别名]
# 或者: from enum import IntEnum [as 别名]
def setUp(self):
        class Season(Enum):
            SPRING = 1
            SUMMER = 2
            AUTUMN = 3
            WINTER = 4
        self.Season = Season

        class Konstants(float, Enum):
            E = 2.7182818
            PI = 3.1415926
            TAU = 2 * PI
        self.Konstants = Konstants

        class Grades(IntEnum):
            A = 5
            B = 4
            C = 3
            D = 2
            F = 0
        self.Grades = Grades

        class Directional(str, Enum):
            EAST = 'east'
            WEST = 'west'
            NORTH = 'north'
            SOUTH = 'south'
        self.Directional = Directional

        from datetime import date
        class Holiday(date, Enum):
            NEW_YEAR = 2013, 1, 1
            IDES_OF_MARCH = 2013, 3, 15
        self.Holiday = Holiday 
开发者ID:typeintandem,项目名称:tandem,代码行数:36,代码来源:test.py

示例10: test_intenum_inherited

# 需要导入模块: import enum [as 别名]
# 或者: from enum import IntEnum [as 别名]
def test_intenum_inherited(self):
        class IntEnum(int, Enum):
            pass
        class phy(IntEnum):
            pi = 3
            tau = 2 * pi
        self.assertTrue(phy.pi < phy.tau) 
开发者ID:typeintandem,项目名称:tandem,代码行数:9,代码来源:test.py

示例11: test_intenum

# 需要导入模块: import enum [as 别名]
# 或者: from enum import IntEnum [as 别名]
def test_intenum(self):
        class WeekDay(IntEnum):
            SUNDAY = 1
            MONDAY = 2
            TUESDAY = 3
            WEDNESDAY = 4
            THURSDAY = 5
            FRIDAY = 6
            SATURDAY = 7

        self.assertEqual(['a', 'b', 'c'][WeekDay.MONDAY], 'c')
        self.assertEqual([i for i in range(WeekDay.TUESDAY)], [0, 1, 2])

        lst = list(WeekDay)
        self.assertEqual(len(lst), len(WeekDay))
        self.assertEqual(len(WeekDay), 7)
        target = 'SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY'
        target = target.split()
        for i, weekday in enumerate(target):
            i += 1
            e = WeekDay(i)
            self.assertEqual(e, i)
            self.assertEqual(int(e), i)
            self.assertEqual(e.name, weekday)
            self.assertTrue(e in WeekDay)
            self.assertEqual(lst.index(e)+1, i)
            self.assertTrue(0 < e < 8)
            self.assertTrue(type(e) is WeekDay)
            self.assertTrue(isinstance(e, int))
            self.assertTrue(isinstance(e, Enum)) 
开发者ID:typeintandem,项目名称:tandem,代码行数:32,代码来源:test.py

示例12: test_intenum_duplicates

# 需要导入模块: import enum [as 别名]
# 或者: from enum import IntEnum [as 别名]
def test_intenum_duplicates(self):
        class WeekDay(IntEnum):
            __order__ = 'SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY'
            SUNDAY = 1
            MONDAY = 2
            TUESDAY = TEUSDAY = 3
            WEDNESDAY = 4
            THURSDAY = 5
            FRIDAY = 6
            SATURDAY = 7
        self.assertTrue(WeekDay.TEUSDAY is WeekDay.TUESDAY)
        self.assertEqual(WeekDay(3).name, 'TUESDAY')
        self.assertEqual([k for k,v in WeekDay.__members__.items()
                if v.name != k], ['TEUSDAY', ]) 
开发者ID:typeintandem,项目名称:tandem,代码行数:16,代码来源:test.py

示例13: test_intenum_transitivity

# 需要导入模块: import enum [as 别名]
# 或者: from enum import IntEnum [as 别名]
def test_intenum_transitivity(self):
        class number(IntEnum):
            one = 1
            two = 2
            three = 3
        class numero(IntEnum):
            uno = 1
            dos = 2
            tres = 3
        self.assertEqual(number.one, numero.uno)
        self.assertEqual(number.two, numero.dos)
        self.assertEqual(number.three, numero.tres) 
开发者ID:typeintandem,项目名称:tandem,代码行数:14,代码来源:test.py

示例14: test_wrong_enum_in_mixed_call

# 需要导入模块: import enum [as 别名]
# 或者: from enum import IntEnum [as 别名]
def test_wrong_enum_in_mixed_call(self):
        class Monochrome(IntEnum):
            black = 0
            white = 1
        class Gender(Enum):
            male = 0
            female = 1
        self.assertRaises(ValueError, Monochrome, Gender.male) 
开发者ID:typeintandem,项目名称:tandem,代码行数:10,代码来源:test.py

示例15: test_mixed_enum_in_call_1

# 需要导入模块: import enum [as 别名]
# 或者: from enum import IntEnum [as 别名]
def test_mixed_enum_in_call_1(self):
        class Monochrome(IntEnum):
            black = 0
            white = 1
        class Gender(IntEnum):
            male = 0
            female = 1
        self.assertTrue(Monochrome(Gender.female) is Monochrome.white) 
开发者ID:typeintandem,项目名称:tandem,代码行数:10,代码来源:test.py


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