tests: Update for IMU changes.

This commit is contained in:
Laurens Valk
2025-02-25 11:16:27 +01:00
parent 827eda031b
commit c5cfcd0ac8
9 changed files with 85 additions and 50 deletions
+1 -1
View File
@@ -196,7 +196,7 @@ Prime Hub / Inventor Hub
.. automethod:: pybricks.hubs::PrimeHub.system.shutdown
.. note::
The examples below use the ``PrimeHub`` class. The examples work fine
on both hubs because they are the identical. If you prefer, you can
change this to ``InventorHub``.
+2 -2
View File
@@ -76,8 +76,8 @@ def test_hub_dot_system_dot():
code = _create_snippet(line)
completions: list[CompletionItem] = json.loads(complete(code, 3, len(line) + 1))
assert [c["insertText"] for c in completions] == [
"name",
"reset_reason",
"info",
"reset_storage",
"set_stop_button",
"shutdown",
"storage",
+2 -2
View File
@@ -108,8 +108,8 @@ def test_hub_dot_system_dot():
code = _create_snippet(line)
completions: list[CompletionItem] = json.loads(complete(code, 3, len(line) + 1))
assert [c["insertText"] for c in completions] == [
"name",
"reset_reason",
"info",
"reset_storage",
"set_stop_button",
"shutdown",
"storage",
+2 -2
View File
@@ -88,8 +88,8 @@ def test_hub_dot_system_dot():
code = _create_snippet(line)
completions: list[CompletionItem] = json.loads(complete(code, 3, len(line) + 1))
assert [c["insertText"] for c in completions] == [
"name",
"reset_reason",
"info",
"reset_storage",
"set_stop_button",
"shutdown",
"storage",
+2 -2
View File
@@ -137,8 +137,8 @@ def test_hub_dot_system_dot():
code = _create_snippet(line)
completions: list[CompletionItem] = json.loads(complete(code, 3, len(line) + 1))
assert [c["insertText"] for c in completions] == [
"name",
"reset_reason",
"info",
"reset_storage",
"set_stop_button",
"shutdown",
"storage",
+2 -2
View File
@@ -96,8 +96,8 @@ def test_hub_dot_system_dot():
code = _create_snippet(line)
completions: list[CompletionItem] = json.loads(complete(code, 3, len(line) + 1))
assert [c["insertText"] for c in completions] == [
"name",
"reset_reason",
"info",
"reset_storage",
"set_stop_button",
"shutdown",
"storage",
+66 -31
View File
@@ -86,12 +86,12 @@ CONSTRUCTOR_PARAMS = [
pytest.param(
"pybricks.hubs",
"MoveHub",
[["broadcast_channel: int=0", "observe_channels: Sequence[int]=[]"]],
[["broadcast_channel: int=None", "observe_channels: Sequence[int]=[]"]],
),
pytest.param(
"pybricks.hubs",
"CityHub",
[["broadcast_channel: int=0", "observe_channels: Sequence[int]=[]"]],
[["broadcast_channel: int=None", "observe_channels: Sequence[int]=[]"]],
),
pytest.param(
"pybricks.hubs",
@@ -100,7 +100,7 @@ CONSTRUCTOR_PARAMS = [
[
"top_side: Axis=Axis.Z",
"front_side: Axis=Axis.X",
"broadcast_channel: int=0",
"broadcast_channel: int=None",
"observe_channels: Sequence[int]=[]",
]
],
@@ -112,7 +112,7 @@ CONSTRUCTOR_PARAMS = [
[
"top_side: Axis=Axis.Z",
"front_side: Axis=Axis.X",
"broadcast_channel: int=0",
"broadcast_channel: int=None",
"observe_channels: Sequence[int]=[]",
]
],
@@ -124,7 +124,7 @@ CONSTRUCTOR_PARAMS = [
[
"top_side: Axis=Axis.Z",
"front_side: Axis=Axis.X",
"broadcast_channel: int=0",
"broadcast_channel: int=None",
"observe_channels: Sequence[int]=[]",
]
],
@@ -264,7 +264,6 @@ METHOD_PARAMS = [
"system.set_stop_button",
[(["button: Optional[Union[Button, Iterable[Button]]]"], "None")],
),
pytest.param("pybricks.hubs", "MoveHub", "system.name", [([], "str")]),
pytest.param("pybricks.hubs", "MoveHub", "system.shutdown", [([], "None")]),
pytest.param(
"pybricks.hubs",
@@ -275,7 +274,6 @@ METHOD_PARAMS = [
(["offset: int", "*", "write: bytes"], "None"),
],
),
pytest.param("pybricks.hubs", "MoveHub", "system.reset_reason", [([], "int")]),
pytest.param("pybricks.hubs", "CityHub", "light.on", [(["color: Color"], "None")]),
pytest.param("pybricks.hubs", "CityHub", "light.off", [([], "None")]),
pytest.param(
@@ -299,7 +297,6 @@ METHOD_PARAMS = [
"system.set_stop_button",
[(["button: Optional[Union[Button, Iterable[Button]]]"], "None")],
),
pytest.param("pybricks.hubs", "CityHub", "system.name", [([], "str")]),
pytest.param("pybricks.hubs", "CityHub", "system.shutdown", [([], "None")]),
pytest.param(
"pybricks.hubs",
@@ -310,7 +307,6 @@ METHOD_PARAMS = [
(["offset: int", "*", "write: bytes"], "None"),
],
),
pytest.param("pybricks.hubs", "CityHub", "system.reset_reason", [([], "int")]),
pytest.param(
"pybricks.hubs", "TechnicHub", "light.on", [(["color: Color"], "None")]
),
@@ -327,19 +323,35 @@ METHOD_PARAMS = [
"light.animate",
[(["colors: Collection[Color]", "interval: Number"], "None")],
),
pytest.param("pybricks.hubs", "TechnicHub", "imu.up", [([], "Side")]),
pytest.param("pybricks.hubs", "TechnicHub", "imu.tilt", [([], "Tuple[int, int]")]),
pytest.param(
"pybricks.hubs",
"TechnicHub",
"imu.up",
[(["calibrated: bool=True"], "Side")],
),
pytest.param(
"pybricks.hubs",
"TechnicHub",
"imu.tilt",
[(["calibrated: bool=True"], "Tuple[int, int]")],
),
pytest.param(
"pybricks.hubs",
"TechnicHub",
"imu.acceleration",
[(["axis: Axis"], "float"), ([], "Matrix")],
[
(["axis: Axis=None", "calibrated: bool=True"], "float"),
(["calibrated: bool=True"], "Matrix"),
],
),
pytest.param(
"pybricks.hubs",
"TechnicHub",
"imu.angular_velocity",
[(["axis: Axis"], "float"), ([], "Matrix")],
[
(["axis: Axis=None", "calibrated: bool=True"], "float"),
(["calibrated: bool=True"], "Matrix"),
],
),
pytest.param("pybricks.hubs", "TechnicHub", "imu.heading", [([], "float")]),
pytest.param("pybricks.hubs", "TechnicHub", "imu.orientation", [([], "Matrix")]),
@@ -353,7 +365,7 @@ METHOD_PARAMS = [
"pybricks.hubs",
"TechnicHub",
"imu.rotation",
[(["axis: Axis"], "float")],
[(["axis: Axis", "calibrated: bool=True"], "float")],
),
pytest.param("pybricks.hubs", "TechnicHub", "battery.voltage", [([], "int")]),
pytest.param("pybricks.hubs", "TechnicHub", "battery.current", [([], "int")]),
@@ -366,7 +378,6 @@ METHOD_PARAMS = [
"system.set_stop_button",
[(["button: Optional[Union[Button, Iterable[Button]]]"], "None")],
),
pytest.param("pybricks.hubs", "TechnicHub", "system.name", [([], "str")]),
pytest.param("pybricks.hubs", "TechnicHub", "system.shutdown", [([], "None")]),
pytest.param(
"pybricks.hubs",
@@ -377,7 +388,6 @@ METHOD_PARAMS = [
(["offset: int", "*", "write: bytes"], "None"),
],
),
pytest.param("pybricks.hubs", "TechnicHub", "system.reset_reason", [([], "int")]),
pytest.param("pybricks.hubs", "PrimeHub", "light.on", [(["color: Color"], "None")]),
pytest.param("pybricks.hubs", "PrimeHub", "light.off", [([], "None")]),
pytest.param(
@@ -424,19 +434,32 @@ METHOD_PARAMS = [
[(["text: str", "on: Number=500", "off: Number=50"], "None")],
),
pytest.param("pybricks.hubs", "PrimeHub", "buttons.pressed", [([], "Set[Button]")]),
pytest.param("pybricks.hubs", "PrimeHub", "imu.up", [([], "Side")]),
pytest.param("pybricks.hubs", "PrimeHub", "imu.tilt", [([], "Tuple[int, int]")]),
pytest.param(
"pybricks.hubs", "PrimeHub", "imu.up", [(["calibrated: bool=True"], "Side")]
),
pytest.param(
"pybricks.hubs",
"PrimeHub",
"imu.tilt",
[(["calibrated: bool=True"], "Tuple[int, int]")],
),
pytest.param(
"pybricks.hubs",
"PrimeHub",
"imu.acceleration",
[(["axis: Axis"], "float"), ([], "Matrix")],
[
(["axis: Axis=None", "calibrated: bool=True"], "float"),
(["calibrated: bool=True"], "Matrix"),
],
),
pytest.param(
"pybricks.hubs",
"PrimeHub",
"imu.angular_velocity",
[(["axis: Axis"], "float"), ([], "Matrix")],
[
(["axis: Axis=None", "calibrated: bool=True"], "float"),
(["calibrated: bool=True"], "Matrix"),
],
),
pytest.param("pybricks.hubs", "PrimeHub", "imu.heading", [([], "float")]),
pytest.param("pybricks.hubs", "PrimeHub", "imu.orientation", [([], "Matrix")]),
@@ -450,7 +473,7 @@ METHOD_PARAMS = [
"pybricks.hubs",
"PrimeHub",
"imu.rotation",
[(["axis: Axis"], "float")],
[(["axis: Axis", "calibrated: bool=True"], "float")],
),
pytest.param(
"pybricks.hubs",
@@ -481,7 +504,6 @@ METHOD_PARAMS = [
"system.set_stop_button",
[(["button: Optional[Union[Button, Iterable[Button]]]"], "None")],
),
pytest.param("pybricks.hubs", "PrimeHub", "system.name", [([], "str")]),
pytest.param("pybricks.hubs", "PrimeHub", "system.shutdown", [([], "None")]),
pytest.param(
"pybricks.hubs",
@@ -492,7 +514,6 @@ METHOD_PARAMS = [
(["offset: int", "*", "write: bytes"], "None"),
],
),
pytest.param("pybricks.hubs", "PrimeHub", "system.reset_reason", [([], "int")]),
pytest.param(
"pybricks.hubs", "EssentialHub", "light.on", [(["color: Color"], "None")]
),
@@ -512,21 +533,32 @@ METHOD_PARAMS = [
pytest.param(
"pybricks.hubs", "EssentialHub", "buttons.pressed", [([], "Set[Button]")]
),
pytest.param("pybricks.hubs", "EssentialHub", "imu.up", [([], "Side")]),
pytest.param(
"pybricks.hubs", "EssentialHub", "imu.tilt", [([], "Tuple[int, int]")]
"pybricks.hubs", "EssentialHub", "imu.up", [(["calibrated: bool=True"], "Side")]
),
pytest.param(
"pybricks.hubs",
"EssentialHub",
"imu.tilt",
[(["calibrated: bool=True"], "Tuple[int, int]")],
),
pytest.param(
"pybricks.hubs",
"EssentialHub",
"imu.acceleration",
[(["axis: Axis"], "float"), ([], "Matrix")],
[
(["axis: Axis=None", "calibrated: bool=True"], "float"),
(["calibrated: bool=True"], "Matrix"),
],
),
pytest.param(
"pybricks.hubs",
"EssentialHub",
"imu.angular_velocity",
[(["axis: Axis"], "float"), ([], "Matrix")],
[
(["axis: Axis=None", "calibrated: bool=True"], "float"),
(["calibrated: bool=True"], "Matrix"),
],
),
pytest.param("pybricks.hubs", "EssentialHub", "imu.heading", [([], "float")]),
pytest.param("pybricks.hubs", "EssentialHub", "imu.orientation", [([], "Matrix")]),
@@ -540,7 +572,7 @@ METHOD_PARAMS = [
"pybricks.hubs",
"EssentialHub",
"imu.rotation",
[(["axis: Axis"], "float")],
[(["axis: Axis", "calibrated: bool=True"], "float")],
),
pytest.param("pybricks.hubs", "EssentialHub", "battery.voltage", [([], "int")]),
pytest.param("pybricks.hubs", "EssentialHub", "battery.current", [([], "int")]),
@@ -553,7 +585,6 @@ METHOD_PARAMS = [
"system.set_stop_button",
[(["button: Optional[Union[Button, Iterable[Button]]]"], "None")],
),
pytest.param("pybricks.hubs", "EssentialHub", "system.name", [([], "str")]),
pytest.param("pybricks.hubs", "EssentialHub", "system.shutdown", [([], "None")]),
pytest.param(
"pybricks.hubs",
@@ -564,7 +595,6 @@ METHOD_PARAMS = [
(["offset: int", "*", "write: bytes"], "None"),
],
),
pytest.param("pybricks.hubs", "EssentialHub", "system.reset_reason", [([], "int")]),
# TODO: iodevices module here
pytest.param("pybricks.pupdevices", "DCMotor", "dc", [(["duty: Number"], "None")]),
pytest.param("pybricks.pupdevices", "DCMotor", "stop", [([], "None")]),
@@ -994,7 +1024,12 @@ METHOD_PARAMS = [
pytest.param(
"pybricks.robotics", "DriveBase", "state", [([], "Tuple[int, int, int, int]")]
),
pytest.param("pybricks.robotics", "DriveBase", "reset", [([], "None")]),
pytest.param(
"pybricks.robotics",
"DriveBase",
"reset",
[(["distance: Number=0", "angle: Number=0"], "None")],
),
pytest.param("pybricks.robotics", "DriveBase", "done", [([], "bool")]),
pytest.param("pybricks.robotics", "DriveBase", "stalled", [([], "bool")]),
]
+7 -7
View File
@@ -1028,7 +1028,7 @@ class SimpleAccelerometer:
class IMU:
def up(self, calibrated=True) -> Side:
def up(self, calibrated: bool = True) -> Side:
"""up(calibrated=True) -> Side
Checks which side of the hub currently faces upward.
@@ -1043,7 +1043,7 @@ class IMU:
``Side.FRONT`` or ``Side.BACK``.
"""
def tilt(self, calibrated=True) -> Tuple[int, int]:
def tilt(self, calibrated: bool = True) -> Tuple[int, int]:
"""tilt(calibrated=True) -> Tuple[int, int]
Gets the pitch and roll angles. This is relative to the
@@ -1063,10 +1063,10 @@ class IMU:
"""
@overload
def acceleration(self, axis: Axis = None, calibrated=True) -> float: ...
def acceleration(self, axis: Axis = None, calibrated: bool = True) -> float: ...
@overload
def acceleration(self, calibrated=True) -> Matrix: ...
def acceleration(self, calibrated: bool = True) -> Matrix: ...
def acceleration(self, *args):
"""
@@ -1246,10 +1246,10 @@ class IMU:
"""
@overload
def angular_velocity(self, axis: Axis = None, calibrated=True) -> float: ...
def angular_velocity(self, axis: Axis = None, calibrated: bool = True) -> float: ...
@overload
def angular_velocity(self, calibrated=True) -> Matrix: ...
def angular_velocity(self, calibrated: bool = True) -> Matrix: ...
def angular_velocity(self, *args):
"""
@@ -1271,7 +1271,7 @@ class IMU:
this returns a vector of accelerations along all axes.
"""
def rotation(self, axis: Axis, calibrated=True) -> float:
def rotation(self, axis: Axis, calibrated: bool = True) -> float:
"""
rotation(axis, calibrated=True) -> float: deg
+1 -1
View File
@@ -119,7 +119,7 @@ class DriveBase:
Tuple of distance, drive speed, angle, and turn rate of the robot.
"""
def reset(self, distance=0, angle=0) -> None:
def reset(self, distance: Number = 0, angle: Number = 0) -> None:
"""reset(distance=0, angle=0)
Resets the estimated driven distance and heading angle.