Skip to content

Commit

Permalink
Ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil21 committed Sep 16, 2024
1 parent ee762dc commit d3d4ecd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
7 changes: 5 additions & 2 deletions airbrakes/imu/imu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
try:
import mscl
except ImportError:
warnings.warn("Could not import MSCL, IMU will not work. Please see installation instructions"
"here: https://github.com/LORD-MicroStrain/MSCL/tree/master", stacklevel=2)
warnings.warn(
"Could not import MSCL, IMU will not work. Please see installation instructions"
"here: https://github.com/LORD-MicroStrain/MSCL/tree/master",
stacklevel=2,
)

from airbrakes.constants import ESTIMATED_DESCRIPTOR_SET, RAW_DESCRIPTOR_SET
from airbrakes.imu.imu_data_packet import EstimatedDataPacket, IMUDataPacket, RawDataPacket
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ select = ["E", "F", "I", "PL", "UP", "RUF", "PTH", "C4", "B", "PIE", "SIM", "RET
"D100", "D101", "D300", "D418", "D419", "S"]

[tool.ruff.lint.per-file-ignores]
"Scripts/run_*.py" = ["T20"]
"tests/*.py" = ["T20", "S101", "D100"]
"scripts/run_*.py" = ["T20"]
"tests/*.py" = ["T20", "S101", "D100", "ARG001"]
2 changes: 1 addition & 1 deletion scripts/run_imu.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
imu = IMU(PORT, FREQUENCY, UPSIDE_DOWN)

while True:
print(imu.get_imu_data_packet()) # noqa: T201
print(imu.get_imu_data_packet())
2 changes: 1 addition & 1 deletion scripts/run_servo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

servo = Servo(SERVO_PIN, MIN_EXTENSION, MAX_EXTENSION)

print("Type (1) to deploy and (0) to retract the airbrakes.") # noqa: T201
print("Type (1) to deploy and (0) to retract the airbrakes.")
while True:
servo.set_extension(float(input()))
15 changes: 9 additions & 6 deletions tests/test_imu.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import multiprocessing
import multiprocessing.sharedctypes
import time
from collections import deque

import pytest
import multiprocessing

from collections import deque
from airbrakes.constants import FREQUENCY, PORT, UPSIDE_DOWN
from airbrakes.imu.imu import IMU
from airbrakes.imu.imu_data_packet import EstimatedDataPacket, IMUDataPacket, RawDataPacket
from airbrakes.constants import PORT, FREQUENCY, UPSIDE_DOWN
import time


@pytest.fixture
def imu():
return IMU(port=PORT, frequency=FREQUENCY, upside_down=UPSIDE_DOWN)


RAW_DATA_PACKET_SAMPLING_RATE = 1/1000 # 1kHz
EST_DATA_PACKET_SAMPLING_RATE = 1/500 # 500Hz
RAW_DATA_PACKET_SAMPLING_RATE = 1 / 1000 # 1kHz
EST_DATA_PACKET_SAMPLING_RATE = 1 / 500 # 500Hz


class TestIMU:
"""Class to test the IMU class in imu.py"""

def test_init(self, imu):
assert isinstance(imu._data_queue, multiprocessing.queues.Queue)
# Test that _running is a shared boolean multiprocessing.Value:
Expand All @@ -46,6 +48,7 @@ def _fetch_data_loop(self, port: str, frequency: int, upside_down: bool):

def test_imu_stop(self, monkeypatch):
"""Tests whether the IMU process stops correctly."""

def _fetch_data_loop(self, port: str, frequency: int, upside_down: bool):
"""Monkeypatched method for testing."""

Expand Down
8 changes: 5 additions & 3 deletions tests/test_imu_data_packet.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import pytest

from airbrakes.imu.imu_data_packet import EstimatedDataPacket, RawDataPacket


class TestEstimatedDataPacket:
"""Tests the EstimatedDataPacket class"""

def test_estimated_data_packet_initialization(self):
packet = EstimatedDataPacket(
timestamp=123456789,
Expand All @@ -26,7 +28,7 @@ def test_estimated_data_packet_initialization(self):
estAngularRateZ=0.7,
estCompensatedAccelX=9.81,
estCompensatedAccelY=0.0,
estCompensatedAccelZ=-9.81
estCompensatedAccelZ=-9.81,
)

assert packet.timestamp == 123456789
Expand Down Expand Up @@ -80,13 +82,13 @@ def test_required_fields(self):
with pytest.raises(TypeError):
EstimatedDataPacket()


def test_wrong_type_does_not_raise_exception(self):
EstimatedDataPacket(timestamp="12345.6789", estFilterGpsTimeTow=object())


class TestRawDataPacket:
"""Tests the RawDataPacket class"""

def test_raw_data_packet_initialization(self):
packet = RawDataPacket(
timestamp=123456789,
Expand All @@ -98,7 +100,7 @@ def test_raw_data_packet_initialization(self):
scaledAccelZ=3.0,
scaledGyroX=4.0,
scaledGyroY=5.0,
scaledGyroZ=6.0
scaledGyroZ=6.0,
)

assert packet.timestamp == 123456789
Expand Down

0 comments on commit d3d4ecd

Please sign in to comment.