Skip to content

Commit

Permalink
Merge pull request #164 from sortafreel/fix_extract_regex_function
Browse files Browse the repository at this point in the history
Add tests for `extract_regex` function.
  • Loading branch information
eliasdorneles committed Oct 25, 2019
2 parents ce169cd + e3fe8c0 commit 15e4326
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from parsel.utils import shorten
from parsel.utils import shorten, extract_regex

from pytest import mark, raises
import six
Expand All @@ -24,3 +24,15 @@ def test_shorten(width, expected):
else:
with raises(expected):
shorten(u'foobar', width)


@mark.parametrize('regex, text, replace_entities, expected', (
[r'(?P<month>\w+)\s*(?P<day>\d+)\s*\,?\s*(?P<year>\d+)', 'October 25, 2019', True, ['October', '25', '2019']],
[r'(?P<month>\w+)\s*(?P<day>\d+)\s*\,?\s*(?P<year>\d+)', 'October 25 2019', True, ['October', '25', '2019']],
[r'(?P<extract>\w+)\s*(?P<day>\d+)\s*\,?\s*(?P<year>\d+)', 'October 25 2019', True, ['October']],
[r'\w+\s*\d+\s*\,?\s*\d+', 'October 25 2019', True, ['October 25 2019']],
[r'^.*$', '&quot;sometext&quot; &amp; &quot;moretext&quot;', True, ['"sometext" &amp; "moretext"']],
[r'^.*$', '&quot;sometext&quot; &amp; &quot;moretext&quot;', False, ['&quot;sometext&quot; &amp; &quot;moretext&quot;']],
))
def test_extract_regex(regex, text, replace_entities, expected):
assert extract_regex(regex, text, replace_entities) == expected

0 comments on commit 15e4326

Please sign in to comment.