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


Python TypeBuilder.make_variant方法代码示例

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


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

示例1: test_make_variant__with_color_or_person

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_variant [as 别名]
    def test_make_variant__with_color_or_person(self):
        type_converters = [parse_color, parse_person_choice]
        parse_variant2 = TypeBuilder.make_variant(type_converters)
        schema = "Variant2: {variant:Color_or_Person}"
        parser = parse.Parser(schema, dict(Color_or_Person=parse_variant2))

        # -- TYPE 1: Color
        self.assert_match(parser, "Variant2: red",  "variant", Color.red)
        self.assert_match(parser, "Variant2: blue", "variant", Color.blue)

        # -- TYPE 2: Person
        self.assert_match(parser, "Variant2: Alice",  "variant", "Alice")
        self.assert_match(parser, "Variant2: Bob",    "variant", "Bob")
        self.assert_match(parser, "Variant2: Charly", "variant", "Charly")

        # -- PARSE MISMATCH:
        self.assert_mismatch(parser, "Variant2: __Alice__")
        self.assert_mismatch(parser, "Variant2: Alice ")
        self.assert_mismatch(parser, "Variant2: Alice2")
        self.assert_mismatch(parser, "Variant2: red2")

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

        self.ensure_can_parse_all_choices(parser,
                    parse_person_choice, "Variant2: %s", "variant")
开发者ID:amigadave,项目名称:parse_type,代码行数:29,代码来源:test_builder.py

示例2: test_make_variant__with_strict_raises_error_on_case_mismatch

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_variant [as 别名]
 def test_make_variant__with_strict_raises_error_on_case_mismatch(self):
     # -- NEEDS:
     #  * re_opts=0 (IGNORECASE disabled)
     #  * strict=True, allow that an error is raised
     type_converters = [parse_number, parse_yesno]
     parse_variant = TypeBuilder.make_variant(type_converters,
                                              strict=True, re_opts=0)
     schema = "Variant: {variant:YesNo_or_Number}"
     parser = parse.Parser(schema, dict(YesNo_or_Number=parse_variant))
     self.assertRaises(AssertionError,  parser.parse, "Variant: YES")
开发者ID:amigadave,项目名称:parse_type,代码行数:12,代码来源:test_builder.py

示例3: test_make_variant__without_strict_may_return_none_on_case_mismatch

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_variant [as 别名]
 def test_make_variant__without_strict_may_return_none_on_case_mismatch(self):
     # -- NEEDS:
     #  * re_opts=0 (IGNORECASE disabled)
     #  * strict=False, otherwise an error is raised
     type_converters = [parse_number, parse_yesno]
     parse_variant = TypeBuilder.make_variant(type_converters, re_opts=0,
                                              strict=False)
     schema = "Variant: {variant:YesNo_or_Number}"
     parser = parse.Parser(schema, dict(YesNo_or_Number=parse_variant))
     result = parser.parse("Variant: No")
     self.assertNotEqual(result, None)
     self.assertEqual(result["variant"], None)
开发者ID:amigadave,项目名称:parse_type,代码行数:14,代码来源:test_builder.py

示例4: test_make_variant__with_strict_and_compiled_raises_error_on_case_mismatch

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_variant [as 别名]
    def test_make_variant__with_strict_and_compiled_raises_error_on_case_mismatch(self):
        # XXX re_opts=0 seems to work differently.
        # -- NEEDS:
        #  * re_opts=0 (IGNORECASE disabled)
        #  * strict=True, allow that an error is raised
        type_converters = [parse_number, parse_yesno]
        # -- ENSURE: coverage for cornercase.
        parse_number.matcher = re.compile(parse_number.pattern)

        parse_variant = TypeBuilder.make_variant(type_converters,
                                        compiled=True, re_opts=0, strict=True)
        schema = "Variant: {variant:YesNo_or_Number}"
        parser = parse.Parser(schema, dict(YesNo_or_Number=parse_variant))
        # XXX self.assertRaises(AssertionError,  parser.parse, "Variant: YES")
        result = parser.parse("Variant: Yes")
        self.assertNotEqual(result, None)
        self.assertEqual(result["variant"], True)
开发者ID:amigadave,项目名称:parse_type,代码行数:19,代码来源:test_builder.py

示例5: test_make_variant__with_strict

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_variant [as 别名]
 def test_make_variant__with_strict(self):
     # -- SKIP: IGNORECASE checks which would raise an error in strict mode.
     type_converters = [parse_number, parse_yesno]
     parse_variant = TypeBuilder.make_variant(type_converters, strict=True)
     self.check_parse_variant_number_or_yesno(parse_variant,
                                              with_ignorecase=False)
开发者ID:amigadave,项目名称:parse_type,代码行数:8,代码来源:test_builder.py

示例6: test_make_variant__with_re_opts_IGNORECASE

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_variant [as 别名]
 def test_make_variant__with_re_opts_IGNORECASE(self):
     type_converters = [parse_number, parse_yesno]
     parse_variant3 = TypeBuilder.make_variant(type_converters,
                                               re_opts=re.IGNORECASE)
     self.check_parse_variant_number_or_yesno(parse_variant3)
开发者ID:amigadave,项目名称:parse_type,代码行数:7,代码来源:test_builder.py

示例7: test_make_variant__compiled

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_variant [as 别名]
 def test_make_variant__compiled(self):
     # -- REVERSED ORDER VARIANT:
     type_converters = [parse_number, parse_yesno]
     parse_variant2 = TypeBuilder.make_variant(type_converters,
                                               compiled=True)
     self.check_parse_variant_number_or_yesno(parse_variant2)
开发者ID:amigadave,项目名称:parse_type,代码行数:8,代码来源:test_builder.py

示例8: test_make_variant__uncompiled

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import make_variant [as 别名]
 def test_make_variant__uncompiled(self):
     type_converters = [parse_yesno, parse_number]
     parse_variant1 = TypeBuilder.make_variant(type_converters)
     self.check_parse_variant_number_or_yesno(parse_variant1)
开发者ID:amigadave,项目名称:parse_type,代码行数:6,代码来源:test_builder.py


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