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


Python TypeBuilder.with_many方法代码示例

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


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

示例1: test_parse_with_many_and_unnamed_fields

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import with_many [as 别名]
    def test_parse_with_many_and_unnamed_fields(self):
        # -- ENSURE: Cardinality.one_or_more.group_count is correct
        # REQUIRES: ParserExt := parse_type.Parser with group_count support
        parse_many_numbers = TypeBuilder.with_many(parse_number)
        parse_many_numbers.name = "Number+"

        type_dict = build_type_dict([parse_many_numbers, parse_number])
        schema = "Numbers: {:Number+} {:Number}"
        parser = ParserExt(schema, type_dict)

        # -- CASE:
        result = parser.parse("Numbers: 1, 2, 3 42")
        expected = ([1, 2, 3], 42)
        self.assertIsNotNone(result)
        self.assertEqual(result.fixed, tuple(expected))

        result = parser.parse("Numbers: 3 43")
        expected = ([ 3 ], 43)
        self.assertIsNotNone(result)
        self.assertEqual(result.fixed, tuple(expected))
开发者ID:amigadave,项目名称:parse_type,代码行数:22,代码来源:test_cardinality.py

示例2: test_with_many

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import with_many [as 别名]
 def test_with_many(self):
     # -- ALIAS FOR: one_or_more
     parse_numbers = TypeBuilder.with_many(parse_number)
     self.check_parse_number_with_many(parse_numbers)
开发者ID:amigadave,项目名称:parse_type,代码行数:6,代码来源:test_cardinality.py

示例3: parse_number

# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import with_many [as 别名]
    find_largest_prime_factor, is_palindromic, find_largest_palindrome, find_factors, find_largest_multiple, \
    least_common_multiple, sum_of_squares_for_range, square_of_sums_for_range, difference_of_squares


@parse.with_pattern(r'\d+')
def parse_number(text):
    """
    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):
开发者ID:tipt,项目名称:euler,代码行数:33,代码来源:first_10_steps.py

示例4: step_when_I_meet_persons

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

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

company_persons = [ "Alice", "Bob", "Charly", "Dodo" ]
parse_person = TypeBuilder.make_choice(company_persons)
matchers.register_type(Person=parse_person)

# -- MANY-TYPE: Persons := list<Person> with list-separator = "and"
# parse_persons = TypeBuilder.with_one_or_more(parse_person, listsep="and")
parse_persons = TypeBuilder.with_many(parse_person, listsep="and")
matchers.register_type(PersonAndMore=parse_persons)


# @mark.steps
# ----------------------------------------------------------------------------
# STEPS:
# ----------------------------------------------------------------------------
from behave import given, when, then

# -- MANY-VARIANT 1: Use Cardinality field in parse expression (comma-separated)
@when('I meet {persons:Person+}')
def step_when_I_meet_persons(context, persons):
    for person in persons:
        context.meeting.persons.add(person)
开发者ID:ericxsun,项目名称:behave.example,代码行数:31,代码来源:step_cardinality_one_or_more.py


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