當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。