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


Python TypeBuilder.make_choice2方法代码示例

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


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

示例1: test_make_choice2__with_transform

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_choice2 [as 别名]
    def test_make_choice2__with_transform(self):
        transform = lambda x: x.lower()
        parse_choice2 = TypeBuilder.make_choice2(["ZERO", "one", "Two"],
                                        transform=transform)
        self.assertSequenceEqual(parse_choice2.choices, ["zero", "one", "two"])
        schema = "Answer: {answer:NumberWordChoice}"
        parser = parse.Parser(schema, dict(NumberWordChoice=parse_choice2))

        # -- PERFORM TESTS:
        # NOTE: Parser uses re.IGNORECASE => Any case is accepted.
        self.assert_match(parser, "Answer: zERO", "answer", (0, "zero"))
        self.assert_match(parser, "Answer: ONE", "answer",  (1, "one"))
        self.assert_match(parser, "Answer: Two", "answer",  (2, "two"))
开发者ID:amigadave,项目名称:parse_type,代码行数:15,代码来源:test_builder.py

示例2: test_make_choice2__samecase_match_or_error

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_choice2 [as 别名]
    def test_make_choice2__samecase_match_or_error(self):
        # -- NOTE: strict=True => Enable errors due to case-mismatch.
        parse_choice2 = TypeBuilder.make_choice2(["Zero", "one", "TWO"],
                                                 strict=True)
        schema = "Answer: {answer:NumberWordChoice}"
        parser = parse.Parser(schema, dict(NumberWordChoice=parse_choice2))

        # -- PERFORM TESTS: Case matches.
        # NOTE: Parser uses re.IGNORECASE flag => Any case accepted.
        self.assert_match(parser, "Answer: Zero", "answer", (0, "Zero"))
        self.assert_match(parser, "Answer: one",  "answer", (1, "one"))
        self.assert_match(parser, "Answer: TWO",  "answer", (2, "TWO"))

        # -- PERFORM TESTS: EXACT-CASE MISMATCH
        case_mismatch_input_data = ["zero", "ZERO", "One", "ONE", "two" ]
        for input_value in case_mismatch_input_data:
            input_text = "Answer: %s" % input_value
            with self.assertRaises(ValueError):
                parser.parse(input_text)
开发者ID:amigadave,项目名称:parse_type,代码行数:21,代码来源:test_builder.py


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