本文整理汇总了Python中parse_type.TypeBuilder.with_many0方法的典型用法代码示例。如果您正苦于以下问题:Python TypeBuilder.with_many0方法的具体用法?Python TypeBuilder.with_many0怎么用?Python TypeBuilder.with_many0使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类parse_type.TypeBuilder
的用法示例。
在下文中一共展示了TypeBuilder.with_many0方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parse_with_many0_and_unnamed_fields
# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import with_many0 [as 别名]
def test_parse_with_many0_and_unnamed_fields(self):
# -- ENSURE: Cardinality.zero_or_more.group_count is correct
# REQUIRES: ParserExt := parse_type.Parser with group_count support
parse_many0_numbers = TypeBuilder.with_many0(parse_number)
parse_many0_numbers.name = "Number*"
type_dict = build_type_dict([parse_many0_numbers, parse_number])
schema = "Numbers: {:Number*} {:Number}"
parser = ParserExt(schema, type_dict)
# -- CASE: Optional numbers are present
result = parser.parse("Numbers: 1, 2, 3 42")
expected = ([1, 2, 3], 42)
self.assertIsNotNone(result)
self.assertEqual(result.fixed, tuple(expected))
# -- CASE: Optional numbers are missing := EMPTY-LIST
result = parser.parse("Numbers: 43")
expected = ([ ], 43)
self.assertIsNotNone(result)
self.assertEqual(result.fixed, tuple(expected))
示例2: test_with_many0
# 需要导入模块: from parse_type import TypeBuilder [as 别名]
# 或者: from parse_type.TypeBuilder import with_many0 [as 别名]
def test_with_many0(self):
# -- ALIAS FOR: one_or_more
parse_numbers = TypeBuilder.with_many0(parse_number)
self.check_parse_number_with_many0(parse_numbers)