unit tests for regex utils

netiawifi
selfisekai 2020-09-09 18:37:20 +02:00
parent 221b0c30fd
commit 6259fc78be
1 changed files with 38 additions and 0 deletions

38
tests/regex_utils.py Normal file
View File

@ -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