當前位置: 首頁>>代碼示例>>Python>>正文


Python InputReader.add_regex_line方法代碼示例

本文整理匯總了Python中input_reader.InputReader.add_regex_line方法的典型用法代碼示例。如果您正苦於以下問題:Python InputReader.add_regex_line方法的具體用法?Python InputReader.add_regex_line怎麽用?Python InputReader.add_regex_line使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在input_reader.InputReader的用法示例。


在下文中一共展示了InputReader.add_regex_line方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_regex_case_definition

# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_regex_line [as 別名]
def test_regex_case_definition():
    r = InputReader()
    a = r.add_regex_line('red', r'funny\d+DOG')
    assert a.name == 'red'
    assert a._regex.pattern == r'funny\d+DOG'
    if sys.version_info.major == 3:
        assert a._regex.flags == (re.IGNORECASE | re.UNICODE)
    else:
        assert a._regex.flags == re.IGNORECASE
    regex = re.compile(r'funny\d+dog', re.IGNORECASE)
    b = r.add_regex_line('blue', regex)
    assert b.name == 'blue'
    assert b._regex == regex
    c = r.add_regex_line('green', r'funny\d+DOG', case=True)
    assert c.name == 'green'
    assert c._regex.pattern == r'funny\d+DOG'
    if sys.version_info.major == 3:
        assert c._regex.flags == re.UNICODE
    else:
        assert c._regex.flags == 0
    regex = re.compile(r'funny\d+dog', re.IGNORECASE)
    # Case is ignored if a regex flag is given
    d = r.add_regex_line('gray', regex, case=True)
    assert d.name == 'gray'
    assert d._regex == regex
開發者ID:SethMMorton,項目名稱:input_reader,代碼行數:27,代碼來源:test_regex.py

示例2: test_regex_repeat_in_definition

# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_regex_line [as 別名]
def test_regex_repeat_in_definition():
    # You cannot repeat keys
    r = InputReader()
    r.add_regex_line('red', r'test')
    with raises(ReaderError) as e:
        r.add_regex_line('red', r'tax')
    regex = r'The handle "\w+" has been defined twice'
    assert search(regex, str(e.value))
開發者ID:SethMMorton,項目名稱:input_reader,代碼行數:10,代碼來源:test_regex.py

示例3: test_regex_correct_call_Str

# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_regex_line [as 別名]
def test_regex_correct_call_Str():
    r = InputReader()
    a = r.add_regex_line(str('red'), str(r'funny\d+dog'))
    assert a.name == 'red'
    assert a._regex.pattern == r'funny\d+dog'
    regex = re.compile(str(r'funny\d+dog'))
    b = r.add_regex_line(str('blue'), regex)
    assert b.name == 'blue'
    assert b._regex == regex
開發者ID:SethMMorton,項目名稱:input_reader,代碼行數:11,代碼來源:test_regex.py

示例4: test_regex_correct_call

# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_regex_line [as 別名]
def test_regex_correct_call():
    r = InputReader()
    a = r.add_regex_line('red', r'funny\d+dog')
    assert a.name == 'red'
    assert a._regex.pattern == r'funny\d+dog'
    assert not a._case
    regex = re.compile(r'funny\d+dog')
    b = r.add_regex_line('blue', regex)
    assert b.name == 'blue'
    assert b._regex == regex
    assert not b._case
開發者ID:SethMMorton,項目名稱:input_reader,代碼行數:13,代碼來源:test_regex.py

示例5: test_regex_read

# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_regex_line [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

示例6: test_regex_handle_definition

# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_regex_line [as 別名]
def test_regex_handle_definition():
    r = InputReader()
    with raises(ValueError) as e:
        r.add_regex_line(23, r'test')
    assert 'handle must be str' in str(e.value)
    with raises(ValueError) as e:
        r.add_regex_line('hello goodbye', r'test')
    assert 'String cannot contain spaces' in str(e.value)
    with raises(ValueError) as e:
        r.add_regex_line('', r'test')
    assert 'String cannot be of zero length' in str(e.value)
開發者ID:SethMMorton,項目名稱:input_reader,代碼行數:13,代碼來源:test_regex.py

示例7: test_regex_missing_handle

# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_regex_line [as 別名]
def test_regex_missing_handle():
    r = InputReader()
    with raises(TypeError):
        r.add_regex_line()
    with raises(TypeError):
        r.add_regex_line('red')
開發者ID:SethMMorton,項目名稱:input_reader,代碼行數:8,代碼來源:test_regex.py

示例8: test_regex_bad_bool

# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_regex_line [as 別名]
def test_regex_bad_bool():
    r = InputReader()
    with raises(ValueError):
        r.add_regex_line('red', r'funny\d+dog', case=60)
開發者ID:SethMMorton,項目名稱:input_reader,代碼行數:6,代碼來源:test_regex.py


注:本文中的input_reader.InputReader.add_regex_line方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。