-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathtest_pickup.py
90 lines (78 loc) · 3.74 KB
/
test_pickup.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
89
90
#!/usr/bin/env python
#
# License: BSD
# https://raw.githubusercontent.com/splintered-reality/py_trees/devel/LICENSE
#
##############################################################################
# Imports
##############################################################################
import py_trees
import py_trees.console as console
##############################################################################
# Logging Level
##############################################################################
py_trees.logging.level = py_trees.logging.Level.DEBUG
logger = py_trees.logging.Logger("Nosetest")
##############################################################################
# Tests
##############################################################################
def test_high_priority_interrupt() -> None:
console.banner("High Priority Interrupt")
task_one = py_trees.behaviours.StatusQueue(
name="Task 1",
queue=[
py_trees.common.Status.RUNNING,
py_trees.common.Status.RUNNING,
],
eventually=py_trees.common.Status.SUCCESS,
)
task_two = py_trees.behaviours.StatusQueue(
name="Task 2",
queue=[
py_trees.common.Status.RUNNING,
py_trees.common.Status.RUNNING,
],
eventually=py_trees.common.Status.SUCCESS,
)
tasks = [task_one, task_two]
high_priority_interrupt = py_trees.decorators.RunningIsFailure(
name="High Priority", child=py_trees.behaviours.Periodic(name="Periodic", n=3)
)
piwylo = py_trees.idioms.pick_up_where_you_left_off(
name="Pick Up\nWhere You\nLeft Off", tasks=tasks
)
root = py_trees.composites.Selector(name="Root", memory=False)
root.add_children([high_priority_interrupt, piwylo])
print(py_trees.display.unicode_tree(root))
visitor = py_trees.visitors.DebugVisitor()
py_trees.tests.tick_tree(root, 1, 3, visitors=[visitor])
print()
print("\n--------- Assertions ---------\n")
print("high_priority_interrupt.status == py_trees.common.Status.FAILURE")
assert high_priority_interrupt.status == py_trees.common.Status.FAILURE
print("piwylo.status == py_trees.common.Status.RUNNING")
assert piwylo.status == py_trees.common.Status.RUNNING
print("task_one.status == py_trees.common.Status.SUCCESS")
assert task_one.status == py_trees.common.Status.SUCCESS
print("task_two.status == py_trees.common.Status.RUNNING")
assert task_two.status == py_trees.common.Status.RUNNING
py_trees.tests.tick_tree(root, 4, 5, visitors=[visitor])
print("\n--------- Assertions ---------\n")
print("high_priority_interrupt.status == py_trees.common.Status.SUCCESS")
assert high_priority_interrupt.status == py_trees.common.Status.SUCCESS
print("piwylo.status == py_trees.common.Status.INVALID") # type: ignore[unreachable]
assert piwylo.status == py_trees.common.Status.INVALID
print("task_one.status == py_trees.common.Status.INVALID")
assert task_one.status == py_trees.common.Status.INVALID
print("task_two.status == py_trees.common.Status.INVALID")
assert task_two.status == py_trees.common.Status.INVALID
py_trees.tests.tick_tree(root, 6, 8, visitors=[visitor])
print("\n--------- Assertions ---------\n")
print("high_priority_interrupt.status == py_trees.common.Status.FAILURE")
assert high_priority_interrupt.status == py_trees.common.Status.FAILURE
print("piwylo.status == py_trees.common.Status.RUNNING")
assert piwylo.status == py_trees.common.Status.RUNNING
print("task_one.status == py_trees.common.Status.INVALID")
assert task_one.status == py_trees.common.Status.INVALID
print("task_two.status == py_trees.common.Status.RUNNING")
assert task_two.status == py_trees.common.Status.RUNNING