From c5cfcd0ac8ad5ef9932cc4e5ebae8b9e4b12da6d Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Tue, 25 Feb 2025 11:15:47 +0100 Subject: [PATCH] tests: Update for IMU changes. --- doc/main/hubs/primehub.rst | 2 +- jedi/tests/test_complete_city_hub.py | 4 +- jedi/tests/test_complete_essential_hub.py | 4 +- jedi/tests/test_complete_move_hub.py | 4 +- jedi/tests/test_complete_prime_hub.py | 4 +- jedi/tests/test_complete_technic_hub.py | 4 +- jedi/tests/test_get_signature.py | 97 +++++++++++++++-------- src/pybricks/_common.py | 14 ++-- src/pybricks/robotics.py | 2 +- 9 files changed, 85 insertions(+), 50 deletions(-) diff --git a/doc/main/hubs/primehub.rst b/doc/main/hubs/primehub.rst index 88717db..e01f54a 100644 --- a/doc/main/hubs/primehub.rst +++ b/doc/main/hubs/primehub.rst @@ -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``. diff --git a/jedi/tests/test_complete_city_hub.py b/jedi/tests/test_complete_city_hub.py index 7f7f0d2..d676a8b 100644 --- a/jedi/tests/test_complete_city_hub.py +++ b/jedi/tests/test_complete_city_hub.py @@ -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", diff --git a/jedi/tests/test_complete_essential_hub.py b/jedi/tests/test_complete_essential_hub.py index d66f9ee..d578b8e 100644 --- a/jedi/tests/test_complete_essential_hub.py +++ b/jedi/tests/test_complete_essential_hub.py @@ -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", diff --git a/jedi/tests/test_complete_move_hub.py b/jedi/tests/test_complete_move_hub.py index e295b58..09a2570 100644 --- a/jedi/tests/test_complete_move_hub.py +++ b/jedi/tests/test_complete_move_hub.py @@ -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", diff --git a/jedi/tests/test_complete_prime_hub.py b/jedi/tests/test_complete_prime_hub.py index 65080ad..acec03a 100644 --- a/jedi/tests/test_complete_prime_hub.py +++ b/jedi/tests/test_complete_prime_hub.py @@ -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", diff --git a/jedi/tests/test_complete_technic_hub.py b/jedi/tests/test_complete_technic_hub.py index 0188853..6525753 100644 --- a/jedi/tests/test_complete_technic_hub.py +++ b/jedi/tests/test_complete_technic_hub.py @@ -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", diff --git a/jedi/tests/test_get_signature.py b/jedi/tests/test_get_signature.py index b64ce15..426b30d 100644 --- a/jedi/tests/test_get_signature.py +++ b/jedi/tests/test_get_signature.py @@ -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")]), ] diff --git a/src/pybricks/_common.py b/src/pybricks/_common.py index 4165e4b..ef1f9b5 100644 --- a/src/pybricks/_common.py +++ b/src/pybricks/_common.py @@ -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 diff --git a/src/pybricks/robotics.py b/src/pybricks/robotics.py index 1380251..8dd36c7 100644 --- a/src/pybricks/robotics.py +++ b/src/pybricks/robotics.py @@ -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.