Skip to content

Commit e3fe8c0

Browse files
committed
Add tests for extract_regex function.
1 parent 3571df4 commit e3fe8c0

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tests/test_utils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from parsel.utils import shorten
1+
from parsel.utils import shorten, extract_regex
22

33
from pytest import mark, raises
44
import six
@@ -24,3 +24,15 @@ def test_shorten(width, expected):
2424
else:
2525
with raises(expected):
2626
shorten(u'foobar', width)
27+
28+
29+
@mark.parametrize('regex, text, replace_entities, expected', (
30+
[r'(?P<month>\w+)\s*(?P<day>\d+)\s*\,?\s*(?P<year>\d+)', 'October 25, 2019', True, ['October', '25', '2019']],
31+
[r'(?P<month>\w+)\s*(?P<day>\d+)\s*\,?\s*(?P<year>\d+)', 'October 25 2019', True, ['October', '25', '2019']],
32+
[r'(?P<extract>\w+)\s*(?P<day>\d+)\s*\,?\s*(?P<year>\d+)', 'October 25 2019', True, ['October']],
33+
[r'\w+\s*\d+\s*\,?\s*\d+', 'October 25 2019', True, ['October 25 2019']],
34+
[r'^.*$', '&quot;sometext&quot; &amp; &quot;moretext&quot;', True, ['"sometext" &amp; "moretext"']],
35+
[r'^.*$', '&quot;sometext&quot; &amp; &quot;moretext&quot;', False, ['&quot;sometext&quot; &amp; &quot;moretext&quot;']],
36+
))
37+
def test_extract_regex(regex, text, replace_entities, expected):
38+
assert extract_regex(regex, text, replace_entities) == expected

0 commit comments

Comments
 (0)