本文整理汇总了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))
示例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)
示例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):
示例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)