80
80
self.assertTrue(pattern.match('foo'))
81
81
self.assertTrue(pattern.match('Foo'))
83
def test_findall(self):
84
pattern = lazy_regex.lazy_compile('fo*')
85
self.assertEqual(['f', 'fo', 'foo', 'fooo'],
86
pattern.findall('f fo foo fooo'))
88
def test_finditer(self):
89
pattern = lazy_regex.lazy_compile('fo*')
90
matches = [(m.start(), m.end(), m.group())
91
for m in pattern.finditer('foo bar fop')]
92
self.assertEqual([(0, 3, 'foo'), (8, 10, 'fo')], matches)
95
pattern = lazy_regex.lazy_compile('fo*')
96
self.assertIs(None, pattern.match('baz foo'))
97
self.assertEqual('fooo', pattern.match('fooo').group())
99
def test_search(self):
100
pattern = lazy_regex.lazy_compile('fo*')
101
self.assertEqual('foo', pattern.search('baz foo').group())
102
self.assertEqual('fooo', pattern.search('fooo').group())
104
def test_split(self):
105
pattern = lazy_regex.lazy_compile('[,;]*')
106
self.assertEqual(['x', 'y', 'z'], pattern.split('x,y;z'))
109
class TestInstallLazyCompile(tests.TestCase):
112
super(TestInstallLazyCompile, self).setUp()
113
self.addCleanup(lazy_regex.reset_compile)
115
def test_install(self):
116
lazy_regex.install_lazy_compile()
117
pattern = re.compile('foo')
118
self.assertIsInstance(pattern, lazy_regex.LazyRegex)
120
def test_reset(self):
121
lazy_regex.install_lazy_compile()
122
lazy_regex.reset_compile()
123
pattern = re.compile('foo')
124
self.failIf(isinstance(pattern, lazy_regex.LazyRegex),
125
'lazy_regex.reset_compile() did not restore the original'
126
' compile() function %s' % (type(pattern),))
127
# but the returned object should still support regex operations
128
m = pattern.match('foo')
129
self.assertEqual('foo', m.group())