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


Python InputReader.read_input方法代码示例

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


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

示例1: test_unterminated_block

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import read_input [as 别名]
def test_unterminated_block():
    r = InputReader(ignoreunknown=True)
    a = r.add_block_key('red')
    a.add_boolean_key('rose')
    with raises(ReaderError) as e:
        r.read_input(['red', 'rose'])
    assert search('Unterminated block', str(e.value))
开发者ID:SethMMorton,项目名称:input_reader,代码行数:9,代码来源:test_block.py

示例2: test_block_read_end

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import read_input [as 别名]
def test_block_read_end():
    r = InputReader()
    a = r.add_block_key('red', end='subend')
    a.add_boolean_key('rose', default=False)
    inp = r.read_input(['red', 'rose', 'subend'])
    assert inp.red.rose
    inp = r.read_input(['red', 'subend'])
    assert not inp.red.rose
开发者ID:SethMMorton,项目名称:input_reader,代码行数:10,代码来源:test_block.py

示例3: test_line_read_case_sensitive

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import read_input [as 别名]
def test_line_read_case_sensitive():
    r = InputReader()
    r.add_line_key('blue', type=str)
    inp = r.read_input(['blue HeLLo'])
    assert inp.blue == 'hello'
    r.add_line_key('red', type=str, case=True)
    inp = r.read_input(['red HeLLo'])
    assert inp.red == 'HeLLo'
开发者ID:SethMMorton,项目名称:input_reader,代码行数:10,代码来源:test_line.py

示例4: test_unknown_keys_cause_failure

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import read_input [as 别名]
def test_unknown_keys_cause_failure(setup):
    # Don't ignore unknown keys
    parse_string = setup[-1]
    reader = InputReader(comment='//', ignoreunknown=False)
    reader.add_boolean_key('red')
    reader.add_line_key('path')
    with raises(ReaderError) as e:
        reader.read_input(parse_string)
    assert 'Unrecognized key' in str(e.value)
开发者ID:SethMMorton,项目名称:input_reader,代码行数:11,代码来源:test_read_file.py

示例5: test_comments_are_handled_correctly

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import read_input [as 别名]
def test_comments_are_handled_correctly(setup):
    parse_string = setup[-1]
    reader = InputReader(comment='#')
    reader.add_boolean_key('red')
    reader.add_boolean_key('blue')
    reader.add_line_key('path')
    with raises(ReaderError) as e:
        reader.read_input(parse_string)
    regex = r'expected \d+ arguments, got \d+'
    assert search(regex, str(e.value))
开发者ID:SethMMorton,项目名称:input_reader,代码行数:12,代码来源:test_read_file.py

示例6: test_line_read_using_defaults

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import read_input [as 别名]
def test_line_read_using_defaults():
    r = InputReader()
    r.add_line_key('blue')
    inp = r.read_input(['blue bird'])
    assert inp.blue == 'bird'
    with raises(ReaderError) as e:
        inp = r.read_input(['blue'])
    assert search(r'expected .*\d+ arguments, got \d+', str(e.value))
    with raises(ReaderError) as e:
        inp = r.read_input(['blue bird egg'])
    assert search(r'expected .*\d+ arguments, got \d+', str(e.value))
开发者ID:SethMMorton,项目名称:input_reader,代码行数:13,代码来源:test_line.py

示例7: test_block_read_case_sensitive

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import read_input [as 别名]
def test_block_read_case_sensitive():
    r = InputReader()
    a = r.add_block_key('red', case=True, end='END')
    a.add_boolean_key('ROSE')
    inp = r.read_input(['RED', 'ROSE', 'END'])
    assert 'rose' not in inp.red
    assert inp.red.ROSE
    b = r.add_block_key('pink', case=False)
    b.add_boolean_key('ROSE')
    inp = r.read_input(['PINK', 'ROSE', 'END'])
    assert 'ROSE' not in inp.pink
    assert inp.pink.rose
开发者ID:SethMMorton,项目名称:input_reader,代码行数:14,代码来源:test_block.py

示例8: test_block_read_ignoreunknown

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import read_input [as 别名]
def test_block_read_ignoreunknown():
    r = InputReader()
    a = r.add_block_key('red', ignoreunknown=False)
    a.add_boolean_key('rose')
    with raises(ReaderError) as e:
        inp = r.read_input(['red', 'rose', 'rider', 'end'])
    assert 'Unrecognized key' in str(e.value)
    b = r.add_block_key('blue', ignoreunknown=True)
    b.add_boolean_key('rose')
    inp = r.read_input(['blue', 'rose', 'rider', 'end'])
    assert inp.blue.rose
    assert 'rider' not in inp.blue
开发者ID:SethMMorton,项目名称:input_reader,代码行数:14,代码来源:test_block.py

示例9: test_block_read_subblocks

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import read_input [as 别名]
def test_block_read_subblocks():
    r = InputReader()
    a = r.add_block_key('red')
    b = a.add_block_key('blue')
    b.add_boolean_key('egg')
    inp = r.read_input(['red', 'blue', 'egg', 'end', 'end'])
    assert inp.red.blue.egg
    c = r.add_block_key('pink')
    d = c.add_block_key('blue', end='subend')
    d.add_boolean_key('egg')
    inp = r.read_input(['pink', 'blue', 'egg', 'subend', 'end'])
    assert inp.pink.blue.egg
开发者ID:SethMMorton,项目名称:input_reader,代码行数:14,代码来源:test_block.py

示例10: test_read_mutex_set_required

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import read_input [as 别名]
def test_read_mutex_set_required():
    r = InputReader()
    meg = r.add_mutually_exclusive_group(required=True)
    meg.add_boolean_key('red')
    meg.add_boolean_key('blue')
    meg.add_boolean_key('green')

    inp = r.read_input(['blue'])
    assert inp.blue
    assert not inp.red
    assert not inp.green

    with raises(ReaderError) as e:
        inp = r.read_input([])
    assert search(r'One and only one of .* must be included', str(e.value))
开发者ID:SethMMorton,项目名称:input_reader,代码行数:17,代码来源:test_mutually_excusive_group.py

示例11: test_regex_read

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import read_input [as 别名]
def test_regex_read():
    r = InputReader()
    # Remember it's case-insensitive
    r.add_regex_line('red', r'funny(\d+)DOG\s*(kitty)?')
    inp = r.read_input(['funny14dog'])
    assert inp.red.group(0) == 'funny14dog'
    assert inp.red.group(1) == '14'
    inp = r.read_input(['funny12DOG kitty'])
    # Regex won't lowercase for you
    assert inp.red.group(0) == 'funny12DOG kitty'
    assert inp.red.group(1) == '12'
    assert inp.red.group(2) == 'kitty'
    r.add_regex_line('blue', r'(SILLY|ODD)\s*(goose|duck)', case=True)
    inp = r.read_input(['SILLY goose'])
    assert inp.blue.group(0) == 'SILLY goose'
    inp = r.read_input(['ODD duck'])
    assert inp.blue.group(0) == 'ODD duck'
开发者ID:SethMMorton,项目名称:input_reader,代码行数:19,代码来源:test_regex.py

示例12: test_ignoreunknown_actually_ignores_unknown

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import read_input [as 别名]
def test_ignoreunknown_actually_ignores_unknown(setup):
    # Ignore unknown keys
    parse_string = setup[-1]
    reader = InputReader(comment='//', ignoreunknown=True)
    reader.add_boolean_key('red')
    reader.add_line_key('path')
    inp = reader.read_input(parse_string)
    with raises(AttributeError):
        inp.blue
开发者ID:SethMMorton,项目名称:input_reader,代码行数:11,代码来源:test_read_file.py

示例13: test_block_read_using_defaults

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import read_input [as 别名]
def test_block_read_using_defaults():
    r = InputReader()
    a = r.add_block_key('blue')
    inp = r.read_input(['blue', 'end'])
    assert inp.blue == Namespace()
    b = r.add_block_key('red')
    b.add_boolean_key('rose', default=False)
    b.add_boolean_key('rider', default=False)
    inp = r.read_input(['red', 'rose', 'end'])
    assert inp.red.rose
    assert not inp.red.rider
    inp = r.read_input(['red', 'end'])
    assert not inp.red.rose
    assert not inp.red.rider
    c = r.add_block_key('cyan')
    with raises(ReaderError) as e:
        inp = r.read_input(['cyan word', 'end'])
    assert search(r'The block "\w+" was given arguments, this is illegal',
                  str(e.value))
开发者ID:SethMMorton,项目名称:input_reader,代码行数:21,代码来源:test_block.py

示例14: test_read_mutex

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import read_input [as 别名]
def test_read_mutex():
    r = InputReader()
    meg = r.add_mutually_exclusive_group()
    meg.add_boolean_key('red')
    meg.add_boolean_key('blue')
    meg.add_boolean_key('green')

    inp = r.read_input(['red'])
    assert inp.red
    assert not inp.blue
    assert not inp.green

    with raises(ReaderError) as e:
        inp = r.read_input(['red', 'blue'])
    assert search(r'Only one of .* may be included', str(e.value))

    # Unfortunately we cannot detect duplicate groups in different meg's
    meg2 = r.add_mutually_exclusive_group()
    meg2.add_boolean_key('red')
开发者ID:SethMMorton,项目名称:input_reader,代码行数:21,代码来源:test_mutually_excusive_group.py

示例15: test_read_mutex_set_dest_set_required

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import read_input [as 别名]
def test_read_mutex_set_dest_set_required():
    r = InputReader()
    meg = r.add_mutually_exclusive_group(required=True, dest='color')
    meg.add_boolean_key('red')
    meg.add_boolean_key('blue')
    meg.add_boolean_key('green')
    r.add_boolean_key('cyan')

    with raises(ReaderError) as e:
        inp = r.read_input(['cyan'])
    assert search(r'One and only one of .* must be included', str(e.value))
开发者ID:SethMMorton,项目名称:input_reader,代码行数:13,代码来源:test_mutually_excusive_group.py


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