unit tests for regex utils
parent
221b0c30fd
commit
6259fc78be
|
@ -0,0 +1,38 @@
|
|||
from librefi.utils import regex_search_string
|
||||
|
||||
HTML_STRING = """
|
||||
<form method="POST" action="/?your=mother">
|
||||
<input type="hidden" value="tesco" />
|
||||
</form>
|
||||
"""
|
||||
|
||||
PATTERN = r'<form [^>]+action="([^"]+)'
|
||||
|
||||
EXPECTED_RESULT = "/?your=mother"
|
||||
|
||||
|
||||
def test_regex_search_single():
|
||||
result = regex_search_string(PATTERN, HTML_STRING)
|
||||
assert result is not None
|
||||
assert result == EXPECTED_RESULT
|
||||
|
||||
|
||||
def test_regex_search_multiple():
|
||||
result = regex_search_string(
|
||||
[r'dupsko', PATTERN, r'byle jakie'], HTML_STRING)
|
||||
assert result is not None
|
||||
assert result == EXPECTED_RESULT
|
||||
|
||||
|
||||
def test_regex_search_invalid():
|
||||
result = regex_search_string([r'dupsko', r'czorne'], HTML_STRING)
|
||||
assert result is None
|
||||
assert result != EXPECTED_RESULT
|
||||
|
||||
|
||||
def test_regex_search_default():
|
||||
default = "sth"
|
||||
result = regex_search_string(
|
||||
[r'dupsko', r'czorne'], HTML_STRING, default=default)
|
||||
assert result is not None
|
||||
assert result == default
|
Loading…
Reference in New Issue