当前位置: 首页>>代码示例>>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;未经允许,请勿转载。