-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: html: add tests for node comparisons
Signed-off-by: Florian Scherf <mail@florianscherf.de>
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
def test_node_comparisons(): | ||
from lona.html import Widget, Span, Node, Div | ||
from lona.html.text_node import TextNode | ||
|
||
class TestWidget(Widget): | ||
def __init__(self, *nodes, **widget_data): | ||
self.nodes = nodes | ||
self.data = widget_data | ||
|
||
# simple comparison | ||
assert Div() == Div() | ||
assert Div() is not Div() | ||
assert Div() != Widget() | ||
assert Div() != TextNode('') | ||
|
||
# text nodes | ||
assert TextNode('foo') == TextNode('foo') | ||
assert TextNode('foo') != TextNode('bar') | ||
assert TextNode('foo') is not TextNode('foo') | ||
|
||
# legacy widgets | ||
# TODO: remove in 2.0 | ||
assert TestWidget() == TestWidget() | ||
|
||
assert TestWidget(Div()) == TestWidget(Div()) | ||
assert TestWidget(Div()) != TestWidget(Span()) | ||
|
||
assert TestWidget(foo=1) == TestWidget(foo=1) | ||
assert TestWidget(foo=1) != TestWidget() | ||
assert TestWidget(foo=1) != TestWidget(foo=2) | ||
assert TestWidget(foo=1) != TestWidget(foo=1, bar=2) | ||
|
||
# non node comparisons | ||
assert Div() != 'Div' | ||
assert Div() != object() | ||
|
||
# namespace | ||
assert Div() != Div(namespace='foo') | ||
assert Div(namespace='foo') != Div(namespace='bar') | ||
|
||
# tag name | ||
assert Div() != Span() | ||
assert Node(tag_name='div') != Node(tag_name='span') | ||
|
||
# id list | ||
assert Div(_id='foo') == Div(_id='foo') | ||
assert Div(_id='foo') != Div() | ||
assert Div(_id='foo') != Div(_id='foo bar') | ||
|
||
# class list | ||
assert Div(_class='foo') == Div(_class='foo') | ||
assert Div(_class='foo') != Div() | ||
assert Div(_class='foo') != Div(_class='foo bar') | ||
|
||
# style | ||
assert Div(style={'color': 'red'}) == Div(style={'color': 'red'}) | ||
assert Div(style={'color': 'red'}) != Div(style={'color': 'blue'}) | ||
assert Div(style={'color': 'red'}) != Div(style={'color': 'red', 'a': 'b'}) | ||
|
||
# attributes | ||
assert Div(a=1) == Div(a=1) | ||
assert Div(a=1) != Div(a=2) | ||
assert Div(a=1) != Div(a=1, b=2) | ||
|
||
# sub nodes | ||
assert Div(Div()) == Div(Div()) | ||
assert Div(Div()) != Div(Div(a=1)) | ||
assert Div(Div()) != Div(Div(Span())) | ||
assert Div(Div()) != Div() | ||
|
||
# widget | ||
assert Div(widget='foo') == Div(widget='foo') | ||
assert Div(widget='foo') != Div() | ||
|
||
# widget data | ||
assert Div(widget_data=['foo']) == Div(widget_data=['foo']) | ||
assert Div(widget_data=['foo']) != Div(widget_data=['foo', 'bar']) | ||
assert Div(widget_data=['foo']) != Div() |