Skip to content

Commit cd2a9f5

Browse files
committed
magicbot: Test feedback
1 parent 8eaf5ff commit cd2a9f5

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

tests/test_magicbot_feedback.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
from typing import Sequence
2+
3+
import ntcore
4+
from wpimath import geometry
5+
6+
import magicbot
7+
8+
9+
class BasicComponent:
10+
@magicbot.feedback
11+
def get_number(self):
12+
return 0
13+
14+
@magicbot.feedback
15+
def get_ints(self):
16+
return (0,)
17+
18+
@magicbot.feedback
19+
def get_floats(self):
20+
return (0.0, 0)
21+
22+
def execute(self):
23+
pass
24+
25+
26+
class TypeHintedComponent:
27+
@magicbot.feedback
28+
def get_rotation(self) -> geometry.Rotation2d:
29+
return geometry.Rotation2d()
30+
31+
@magicbot.feedback
32+
def get_rotation_array(self) -> Sequence[geometry.Rotation2d]:
33+
return [geometry.Rotation2d()]
34+
35+
@magicbot.feedback
36+
def get_int(self) -> int:
37+
return 0
38+
39+
@magicbot.feedback
40+
def get_float(self) -> float:
41+
return 0.5
42+
43+
@magicbot.feedback
44+
def get_ints(self) -> Sequence[int]:
45+
return (0,)
46+
47+
def execute(self):
48+
pass
49+
50+
51+
class Robot(magicbot.MagicRobot):
52+
basic: BasicComponent
53+
type_hinted: TypeHintedComponent
54+
55+
def createObjects(self):
56+
pass
57+
58+
59+
def test_collect_feedbacks_with_type_hints():
60+
robot = Robot()
61+
robot.robotInit()
62+
nt = ntcore.NetworkTableInstance.getDefault().getTable("components")
63+
64+
robot._do_periodics()
65+
66+
for name, type_str, value in (
67+
("basic/number", "double", 0.0),
68+
("basic/ints", "int[]", [0]),
69+
("basic/floats", "double[]", [0.0, 0.0]),
70+
("type_hinted/int", "int", 0),
71+
("type_hinted/float", "double", 0.5),
72+
("type_hinted/ints", "int[]", [0]),
73+
):
74+
topic = nt.getTopic(name)
75+
assert topic.getTypeString() == type_str
76+
assert topic.genericSubscribe().get().value() == value

0 commit comments

Comments
 (0)