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