Working on the matches() function
This commit is contained in:
41
tests/tests_matches.py
Normal file
41
tests/tests_matches.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import pytest
|
||||
from fasthtml.components import *
|
||||
|
||||
from myfasthtml.core.matcher import matches, StartsWith, Contains, DoesNotContain
|
||||
|
||||
|
||||
@pytest.mark.parametrize('actual, expected', [
|
||||
(Div(), Div()),
|
||||
(None, None),
|
||||
([Div(), Span()], [Div(), Span()]),
|
||||
(Div(attr1="value"), Div(attr1="value")),
|
||||
(Div(attr1="value", attr2="value"), Div(attr1="value")),
|
||||
(Div(attr1="valueXXX", attr2="value"), Div(attr1=StartsWith("value"))),
|
||||
(Div(attr1="before value after", attr2="value"), Div(attr1=Contains("value"))),
|
||||
(Div(attr1="before after", attr2="value"), Div(attr1=DoesNotContain("value"))),
|
||||
])
|
||||
def test_i_can_match(actual, expected):
|
||||
assert matches(actual, expected)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('actual, expected, error_message', [
|
||||
(None, Div(), "Actual is None"),
|
||||
(Div(), None, "Actual is not None"),
|
||||
(123, Div(), "The types are different:"),
|
||||
([Div(), Span()], [], "Actual is bigger than expected:"),
|
||||
([], [Div(), Span()], "Actual is smaller than expected:"),
|
||||
("not a list", [Div(), Span()], "The types are different:"),
|
||||
([Div(), Span()], [Div(), 123], "The types are different:"),
|
||||
(Div(), Span(), "The elements are different:"),
|
||||
([Div(), Span()], [Div(), Div()], "The elements are different:"),
|
||||
(Div(), Div(attr1="value"), "'attr1' is not found in Actual:"),
|
||||
(Div(attr1="value1"), Div(attr1="value2"), "The values are different for 'attr1':"),
|
||||
(Div(attr1="value1"), Div(attr1=StartsWith("value2")), "The condition 'StartsWith(value2)' is not satisfied:"),
|
||||
(Div(attr1="value1"), Div(attr1=Contains("value2")), "The condition 'Contains(value2)' is not satisfied:"),
|
||||
(Div(attr1="value1 value2"), Div(attr1=DoesNotContain("value2")), "The condition 'DoesNotContain(value2)' is not satisfied:"),
|
||||
|
||||
])
|
||||
def test_i_can_detect_errors(actual, expected, error_message):
|
||||
with pytest.raises(AssertionError) as exc_info:
|
||||
matches(actual, expected)
|
||||
assert error_message in str(exc_info.value)
|
||||
Reference in New Issue
Block a user