-
Notifications
You must be signed in to change notification settings - Fork 0
/
testNode.py
88 lines (74 loc) · 2.01 KB
/
testNode.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from anytree import Node, RenderTree
import pytest
class TestSetup:
def __init__(self):
self.a = Node("a")
self.b = Node("b", parent=self.a)
self.c = Node("c", parent=self.b)
self.d = Node("d", parent=self.b)
self.e = Node("e", parent=self.a)
self.f = Node("f", parent=self.e)
@pytest.fixture()
def setup():
"""
Tree look like this:
a
|-- b
| |-- c
| +-- d
+-- e
+-- f
"""
return TestSetup()
def testGetStatus(setup):
"""
By default, every node should be ON since we didn't specify fail rate
"""
for pre, fill, node in RenderTree(setup.a):
assert node.getstatus() == 1
def testSetStatus(setup):
"""
Do changes propagate through tree
"""
setup.a.setstatus(0)
assert setup.a.getstatus() == 0
assert setup.b.getstatus() == 0
assert setup.c.getstatus() == 0
assert setup.d.getstatus() == 0
assert setup.e.getstatus() == 0
assert setup.f.getstatus() == 0
def testSetStatus(setup):
"""
Does setting b status affect b subtree and ONLY b subtree
"""
setup.b.setstatus(0)
for pre, fill, node in RenderTree(setup.b):
assert node.getstatus() == 0
# that should only have affected the b subtree
for pre, fill, node in RenderTree(setup.e):
assert node.getstatus() == 1
def testOnOff(setup):
"""
"""
setup.a.onoff()
assert setup.a.getstatus() == 1
def testReset(setup):
setup.c.status = 0
setup.e.status = 0
setup.a.reset()
assert setup.a.getstatus() == 1
assert setup.b.getstatus() == 1
assert setup.c.getstatus() == 1
assert setup.d.getstatus() == 1
assert setup.e.getstatus() == 1
assert setup.f.getstatus() == 1
def testOnOff2(setup):
setup.a.status = 0
setup.b.onoff()
assert setup.b.getstatus() == 0
def testRefresh(setup):
setup.b.status = 0
setup.a.refresh()
assert setup.c.getstatus() == 0
assert setup.a.getstatus() == 1
assert setup.b.getstatus() == 0