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