def test_no_arguments(): matches = list(find_pattern_in_string()) assert len(matches) == 1 assert matches[0].re.pattern == '' if sys.version_info.major > 2: assert matches[0].re.flags == re.UNICODE else: assert matches[0].re.flags == 0 assert matches[0].string == '' assert matches[0].group() == ''
def test_flags_only(): matches = list(find_pattern_in_string(flags=re.I)) assert len(matches) == 1 assert matches[0].re.pattern == '' if sys.version_info.major > 2: assert matches[0].re.flags == re.I | re.UNICODE else: assert matches[0].re.flags == re.I assert matches[0].string == '' assert matches[0].group() == ''
def test_no_flags(): pattern = s = 'test' matches = list(find_pattern_in_string(pattern=s, s=s)) assert len(matches) == 1 assert matches[0].re.pattern == pattern if sys.version_info.major > 2: assert matches[0].re.flags == re.UNICODE else: assert matches[0].re.flags == 0 assert matches[0].string == s assert matches[0].group() == s
def test_no_pattern(): s = 'test' matches = list(find_pattern_in_string(flags=re.I, s=s)) assert len(matches) == len(s) + 1 for idx in range(len(s) + 1): assert matches[idx].re.pattern == '' if sys.version_info.major > 2: assert matches[idx].re.flags == re.I | re.UNICODE else: assert matches[0].re.flags == re.I assert matches[idx].string == s assert matches[idx].group() == ''
def test_complex_pattern(): pattern = r'(\d[.-])?\d{3,}[.-]\d{3,}[.-]\d{4,}' s = """ never call the number 1-800-666-1337. instead, you sould call the number 333-3737-13 but actually, that number sucks, so call "9-373-185-7242" or really just hit me up at777.777.7777 """ matches = list(find_pattern_in_string(pattern=pattern, s=s)) assert len(matches) == 3 for m in matches: assert m.re.pattern == pattern if sys.version_info.major > 2: assert m.re.flags == re.UNICODE else: assert m.re.flags == 0 assert m.string == s assert matches[0].group() == '1-800-666-1337' assert matches[1].group() == '9-373-185-7242' assert matches[2].group() == '777.777.7777'
def test_no_string(): assert list(find_pattern_in_string(pattern='test', flags=re.I)) == []
def test_pattern_only(): assert list(find_pattern_in_string(pattern='test')) == []