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


Python TypeBuilder.make_enum方法代码示例

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


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

示例1: test_make_enum_with_enum_class

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_enum [as 别名]
    def test_make_enum_with_enum_class(self):
        """
        Use :meth:`parse_type.TypeBuilder.make_enum()` with enum34 classes.
        """
        class Color(Enum):
            red = 1
            green = 2
            blue = 3

        parse_color = TypeBuilder.make_enum(Color)
        parse_color.name = "Color"
        schema = "Answer: {color:Color}"
        parser = parse.Parser(schema, dict(Color=parse_color))

        # -- PERFORM TESTS:
        self.ensure_can_parse_all_enum_values(parser,
                parse_color, "Answer: %s", "color")

        # -- VALID:
        self.assert_match(parser, "Answer: red",   "color", Color.red)
        self.assert_match(parser, "Answer: green", "color", Color.green)
        self.assert_match(parser, "Answer: blue",  "color", Color.blue)

        # -- IGNORE-CASE: In parsing, calls type converter function !!!
        self.assert_match(parser, "Answer: RED", "color", Color.red)

        # -- PARSE MISMATCH:
        self.assert_mismatch(parser, "Answer: __RED__", "color")
        self.assert_mismatch(parser, "Answer: red ",    "color")
        self.assert_mismatch(parser, "Answer: redx",    "color")
        self.assert_mismatch(parser, "Answer: redx ZZZ", "color")
开发者ID:amigadave,项目名称:parse_type,代码行数:33,代码来源:test_builder.py

示例2: test_with_one_or_more_enum

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_enum [as 别名]
    def test_with_one_or_more_enum(self):
        parse_color  = TypeBuilder.make_enum({"red": 1, "green":2, "blue": 3})
        parse_colors = TypeBuilder.with_one_or_more(parse_color)
        parse_colors.name = "Colors"

        extra_types = build_type_dict([ parse_colors ])
        schema = "List: {colors:Colors}"
        parser = parse.Parser(schema, extra_types)

        # -- PERFORM TESTS:
        self.assert_match(parser, "List: green",      "colors", [ 2 ])
        self.assert_match(parser, "List: red, green", "colors", [ 1, 2 ])

        # -- PARSE MISMATCH:
        self.assert_mismatch(parser, "List: ",   "colors")  # Zero items.
        self.assert_mismatch(parser, "List: x",  "colors")  # Not a Color.
        self.assert_mismatch(parser, "List: black", "colors")  # Unknown
        self.assert_mismatch(parser, "List: red,",  "colors")  # Trailing sep.
        self.assert_mismatch(parser, "List: a, b",  "colors")  # List of ...
开发者ID:amigadave,项目名称:parse_type,代码行数:21,代码来源:test_cardinality.py

示例3: int

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_enum [as 别名]
    turns text into an int to help make feature files nicer to read

    :param text: str text to parse into an int
    :return: int parsed text
    """
    return int(text.strip())


parse_numbers = TypeBuilder.with_many(parse_number, listsep=',')
register_type(ListInts=parse_numbers)

true_false_mapper = {
    'True': True,
    'False': False
}
parse_bool = TypeBuilder.make_enum(true_false_mapper)

register_type(Boolean=parse_bool)

use_step_matcher('parse')


@when("I find the multiples of 3 and 5 under {limit:d}")
def i_find_multiples_of_3_and_5_under(context, limit):
    context.limit = limit
    context.sequence = find_multiples_of_3_and_5(limit)


@when("I find the fibonacci numbers under {limit:d}")
def i_find_the_fibonacci_numbers_under(context, limit):
    context.limit = limit
开发者ID:tipt,项目名称:euler,代码行数:33,代码来源:first_10_steps.py

示例4: parse_number

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_enum [as 别名]
    import unittest


# -----------------------------------------------------------------------------
# TEST SUPPORT FOR: TypeBuilder Tests
# -----------------------------------------------------------------------------
# -- PROOF-OF-CONCEPT DATATYPE:
def parse_number(text):
    return int(text)
parse_number.pattern = r"\d+"   # Provide better regexp pattern than default.
parse_number.name = "Number"    # For testing only.

# -- ENUM DATATYPE:
parse_yesno = TypeBuilder.make_enum({
    "yes":  True,   "no":  False,
    "on":   True,   "off": False,
    "true": True,   "false": False,
})
parse_yesno.name = "YesNo"      # For testing only.

# -- ENUM CLASS:
class Color(Enum):
    red = 1
    green = 2
    blue = 3

parse_color = TypeBuilder.make_enum(Color)
parse_color.name = "Color"

# -- CHOICE DATATYPE:
parse_person_choice = TypeBuilder.make_choice(["Alice", "Bob", "Charly"])
开发者ID:jenisys,项目名称:parse_type,代码行数:33,代码来源:parse_type_test.py

示例5: True

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_enum [as 别名]
# ------------------------------------------------------------------------
answer_oracle = {
    "Do you love me?": True,
    "Do you hate me?": False,
    "Do you kiss me?": True,
}

# @mark.user_defined_types
# ------------------------------------------------------------------------
# USER-DEFINED TYPES:
# ------------------------------------------------------------------------
from behave import register_type
from parse_type import TypeBuilder

# -- ENUM: Returns True (for "yes" and "jubilee"), False (for "no")
parse_yesno = TypeBuilder.make_enum({"yes": True, "no": False, "jubilee": True})
register_type(YesNo=parse_yesno)

# @mark.steps
# ----------------------------------------------------------------------------
# STEPS:
# ----------------------------------------------------------------------------
from behave import when, then
from hamcrest import assert_that, equal_to


@when(u'Romeo asks Julia: "{question}"')
def step_when_romeo_asks_julia(context, question):
    context.question = question

开发者ID:LorenaH,项目名称:TN-Automatizacion,代码行数:31,代码来源:step_enum.py

示例6: before_scenario

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_enum [as 别名]
import os
import tempfile
import shutil
import sys

from parse_type import TypeBuilder
from behave import register_type

parse_bool = TypeBuilder.make_enum({"False": False, "True": True})
register_type(Bool=parse_bool)


def before_scenario(context, scenario):
    context.tmpdir = tempfile.mkdtemp()
    sys.path.append(context.tmpdir + '/output')
    os.chdir(context.tmpdir)


def after_scenario(context, scenario):
    sys.path.remove(context.tmpdir + '/output')
    os.chdir('/')
    shutil.rmtree(context.tmpdir)

开发者ID:ursfassler,项目名称:rizzly,代码行数:24,代码来源:environment.py


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