-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_element.py
More file actions
71 lines (50 loc) · 1.91 KB
/
test_element.py
File metadata and controls
71 lines (50 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Unit tests for Element descriptors."""
from pythonnative.element import Element
def test_element_creation() -> None:
el = Element("Text", {"text": "hello"}, [])
assert el.type == "Text"
assert el.props == {"text": "hello"}
assert el.children == []
assert el.key is None
def test_element_with_key() -> None:
el = Element("Text", {}, [], key="abc")
assert el.key == "abc"
def test_element_with_children() -> None:
child1 = Element("Text", {"text": "a"}, [])
child2 = Element("Text", {"text": "b"}, [])
parent = Element("Column", {}, [child1, child2])
assert len(parent.children) == 2
assert parent.children[0].props["text"] == "a"
assert parent.children[1].props["text"] == "b"
def test_element_equality() -> None:
a = Element("Text", {"text": "hi"}, [])
b = Element("Text", {"text": "hi"}, [])
assert a == b
def test_element_inequality_type() -> None:
a = Element("Text", {"text": "hi"}, [])
b = Element("Button", {"text": "hi"}, [])
assert a != b
def test_element_inequality_props() -> None:
a = Element("Text", {"text": "hi"}, [])
b = Element("Text", {"text": "bye"}, [])
assert a != b
def test_element_inequality_children() -> None:
child = Element("Text", {}, [])
a = Element("Column", {}, [child])
b = Element("Column", {}, [])
assert a != b
def test_element_not_equal_to_other_types() -> None:
el = Element("Text", {}, [])
assert el != "not an element"
assert el != 42
def test_element_repr() -> None:
el = Element("Button", {"title": "ok"}, [])
r = repr(el)
assert "Button" in r
assert "children=0" in r
def test_deeply_nested_equality() -> None:
leaf = Element("Text", {"text": "x"}, [])
mid = Element("Row", {}, [leaf])
root_a = Element("Column", {}, [mid])
root_b = Element("Column", {}, [Element("Row", {}, [Element("Text", {"text": "x"}, [])])])
assert root_a == root_b