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


Python InputReader.add_block_key方法代码示例

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


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

示例1: test_block_case_definition

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_block_key [as 别名]
def test_block_case_definition():
    r = InputReader()
    a = r.add_block_key('red', case=True)
    assert a._case
    with raises(ValueError) as e:
        r.add_block_key('blue', case='True')
    assert 'case must be bool' in str(e.value)
开发者ID:SethMMorton,项目名称:input_reader,代码行数:9,代码来源:test_block.py

示例2: test_block_ignoreunknown_definition

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_block_key [as 别名]
def test_block_ignoreunknown_definition():
    r = InputReader()
    a = r.add_block_key('red', ignoreunknown=True)
    assert a._ignoreunknown
    with raises(ValueError) as e:
        b = r.add_block_key('blue', ignoreunknown='True')
    assert 'ignoreunknown must be bool' in str(e.value)
开发者ID:SethMMorton,项目名称:input_reader,代码行数:9,代码来源:test_block.py

示例3: test_block_repeat_in_definition

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_block_key [as 别名]
def test_block_repeat_in_definition():
    # You cannot repeat keys
    r = InputReader()
    r.add_block_key('red')
    with raises(ReaderError) as e:
        r.add_block_key('red')
    assert search(r'The keyname "\w+" has been defined twice', str(e.value))
开发者ID:SethMMorton,项目名称:input_reader,代码行数:9,代码来源:test_block.py

示例4: test_block_end_definition

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_block_key [as 别名]
def test_block_end_definition():
    r = InputReader()
    a = r.add_block_key('red', end='subend')
    assert a._end == 'subend'
    a = r.add_block_key('green', end=str('subending'))
    assert a._end == 'subending'
    with raises(ValueError) as e:
        r.add_block_key('blue', end=23)
    assert 'end must be str' in  str(e.value)
开发者ID:SethMMorton,项目名称:input_reader,代码行数:11,代码来源:test_block.py

示例5: test_block_read_subblocks

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_block_key [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

示例6: test_block_read_ignoreunknown

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_block_key [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

示例7: test_block_read_case_sensitive

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_block_key [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_correct_call

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_block_key [as 别名]
def test_block_correct_call():
    r = InputReader()
    a = r.add_block_key(str('red'))
    assert a.name == 'red'
    assert a._end == 'end'
    assert not a._case
    assert not a._ignoreunknown
开发者ID:SethMMorton,项目名称:input_reader,代码行数:9,代码来源:test_block.py

示例9: test_unterminated_block

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_block_key [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

示例10: test_block_read_end

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_block_key [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

示例11: test_block_missing_keyname

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_block_key [as 别名]
def test_block_missing_keyname():
    r = InputReader()
    with raises(TypeError):
        r.add_block_key()
    with raises(TypeError):
        r.add_block_key(end='subend')
    with raises(TypeError):
        r.add_block_key(ignoreunknown=True)
    with raises(TypeError):
        r.add_block_key(case=False)
开发者ID:SethMMorton,项目名称:input_reader,代码行数:12,代码来源:test_block.py

示例12: test_block_read_using_defaults

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_block_key [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

示例13: test_block_name_definition

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_block_key [as 别名]
def test_block_name_definition():
    r = InputReader()
    with raises(ValueError) as e:
        r.add_block_key(23)
    assert 'keyname must be str' in str(e.value)
    with raises(ValueError) as e:
        r.add_block_key('hello goodbye')
    assert 'String cannot contain spaces' in str(e.value)
    with raises(ValueError) as e:
        r.add_block_key('')
    assert 'String cannot be of zero length' in str(e.value)
开发者ID:SethMMorton,项目名称:input_reader,代码行数:13,代码来源:test_block.py

示例14: test_block_correct_call_str

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_block_key [as 别名]
def test_block_correct_call_str():
    r = InputReader()
    a = r.add_block_key(str('red'))
    assert a.name == 'red'
开发者ID:SethMMorton,项目名称:input_reader,代码行数:6,代码来源:test_block.py


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