Skip to content

Commit

Permalink
Fixed some ruff errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
senthurayyappan committed Nov 14, 2024
1 parent 46e9f21 commit 195da86
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 153 deletions.
19 changes: 13 additions & 6 deletions tests/test_logging/test_logging_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import pytest

from opensourceleg.logging.exceptions import *
from opensourceleg.logging.exceptions import (
ActuatorConnectionException,
ActuatorIsNoneException,
ActuatorKeyException,
ActuatorStreamException,
ControlModeException,
VoltageModeMissingException,
)


# Test ActuatorStreamException
Expand All @@ -24,9 +31,9 @@ def test_actuator_is_none_exception():
test_str = "test"
with pytest.raises(ActuatorIsNoneException) as e:
raise ActuatorIsNoneException(test_str)
assert (
str(e.value)
== f"Actuator is None in {test_str} mode, please pass the actuator instance to the mode during initialization or set the actuator instance using set_actuator method."
assert str(e.value) == (
f"Actuator is None in {test_str} mode, please pass the actuator instance to the mode during initialization "
"or set the actuator instance using set_actuator method."
)


Expand Down Expand Up @@ -58,6 +65,6 @@ def test_actuator_key_exception():
with pytest.raises(ActuatorKeyException) as e:
raise ActuatorKeyException(test_str, test_key)
assert (
str(e.value)
== f"{test_str} does not have {test_key} key in the actuators dictionary. Please check the actuators dictionary for the `{test_key}` key."
str(e.value) == f"{test_str} does not have {test_key} key in the actuators dictionary. "
f"Please check the actuators dictionary for the `{test_key}` key."
)
7 changes: 5 additions & 2 deletions tests/test_logging/test_logging_logger.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import csv
import logging
from collections import deque
from unittest.mock import Mock

import pytest

from opensourceleg.logging.logger import *
from opensourceleg.logging.logger import LOGGER, Logger, LogLevel


# Test LogLevel class
def test_log_level_default():
{"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"} <= {e.name for e in LogLevel}
assert {"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"} <= {e.name for e in LogLevel}


def test_log_level_value_logging():
Expand Down
7 changes: 4 additions & 3 deletions tests/test_math/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_saturating_ramp_update():
(test_model_default, "R_WC", 1.0702867186480716),
(test_model_default, "C_c", 512.249065845453),
(test_model_default, "R_CA", 1.9406620046327363),
(test_model_default, "α", 0.393 * 1 / 100),
(test_model_default, "α", 0.393 * 1 / 100), # noqa: RUF001
(test_model_default, "R_T_0", 65),
(test_model_default, "T_w", 21),
(test_model_default, "T_c", 21),
Expand All @@ -71,7 +71,7 @@ def test_saturating_ramp_update():
(test_model_specified, "R_WC", 1.0702867186480716),
(test_model_specified, "C_c", 512.249065845453),
(test_model_specified, "R_CA", 1.9406620046327363),
(test_model_specified, "α", 0.393 * 1 / 100),
(test_model_specified, "α", 0.393 * 1 / 100), # noqa: RUF001
(test_model_specified, "R_T_0", 65),
(test_model_specified, "T_w", 10),
(test_model_specified, "T_c", 10),
Expand All @@ -97,7 +97,8 @@ def test_update():
"""
Tests the ThermalModel update method\n
Calls the update method with no arguments and asserts the class variables are equal to the expected values.
Then calls the update method with a motor_current argument and asserts the class variables are equal to the expected values.
Then calls the update method with a motor_current argument and asserts the class variables
are equal to the expected values.
This is repeated once more to test the update method with a motor_current argument.
"""

Expand Down
12 changes: 7 additions & 5 deletions tests/test_robots/test_robots_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from opensourceleg.logging import LOGGER
from opensourceleg.robots.base import *
from opensourceleg.robots.base import RobotBase
from tests.test_actuators.test_actuators_base import MOTOR_CONSTANTS, MockActuator
from tests.test_sensors.test_sensors_base import MockSensor

Expand Down Expand Up @@ -64,8 +64,8 @@ def test_robot_base_init():
sample_robot.tag == tag_name,
sample_robot.actuators == test_actuators,
sample_robot.sensors == test_sensors,
type(sample_robot.actuators) == dict,
type(sample_robot.sensors) == dict,
type(sample_robot.actuators) is dict,
type(sample_robot.sensors) is dict,
])


Expand All @@ -88,7 +88,8 @@ def test_robot_base_exit(mock_robot: MockRobot):

# Test start
def test_robot_base_start(mock_robot: MockRobot):
# "pass" is implementation for start function in both Actuator and Sensor base classes so just testing if called for that part of function
# "pass" is implementation for start function in both Actuator and Sensor base classes
# so just testing if called for that part of function
MockActuator.start = Mock()
MockSensor.start = Mock()

Expand All @@ -109,7 +110,8 @@ def test_robot_base_start(mock_robot: MockRobot):

# Test stop
def test_robot_base_stop(mock_robot: MockRobot):
# "pass" is implementation for stop function in both Actuator and Sensor base classes so just testing if called for that part of function
# "pass" is implementation for stop function in both Actuator and Sensor base classes
# so just testing if called for that part of function
MockActuator.stop = Mock()
MockSensor.stop = Mock()

Expand Down
20 changes: 13 additions & 7 deletions tests/test_robots/test_robots_osl.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_knee(sample_osl: OpenSourceLeg):

with pytest.raises(SystemExit) as e:
sample_osl.knee()
assert e.type == SystemExit
assert e.type is SystemExit

with open(LOGGER.file_path) as f:
output = f.read()
Expand Down Expand Up @@ -86,7 +86,7 @@ def test_ankle(sample_osl: OpenSourceLeg):

with pytest.raises(SystemExit) as e:
sample_osl.ankle()
assert e.type == SystemExit
assert e.type is SystemExit

with open(LOGGER.file_path) as f:
output = f.read()
Expand Down Expand Up @@ -122,7 +122,7 @@ def test_loadcell(sample_osl: OpenSourceLeg):

with pytest.raises(SystemExit) as e:
sample_osl.loadcell()
assert e.type == SystemExit
assert e.type is SystemExit

with open(LOGGER.file_path) as f:
output = f.read()
Expand All @@ -139,15 +139,18 @@ def test_loadcell(sample_osl: OpenSourceLeg):
# Test joint encoder knee
def test_joint_encoder_knee(sample_osl: OpenSourceLeg):
# Test error case
expected_error = "ERROR: Knee joint encoder sensor not found. Please check for `joint_encoder_knee` key in the sensors dictionary.\n"
expected_error = (
"ERROR: Knee joint encoder sensor not found. "
"Please check for `joint_encoder_knee` key in the sensors dictionary.\n"
)

with open(LOGGER.file_path) as f:
output = f.read()
assert expected_error not in output

with pytest.raises(SystemExit) as e:
sample_osl.joint_encoder_knee()
assert e.type == SystemExit
assert e.type is SystemExit

with open(LOGGER.file_path) as f:
output = f.read()
Expand All @@ -164,15 +167,18 @@ def test_joint_encoder_knee(sample_osl: OpenSourceLeg):
# Test joint encoder ankle
def test_joint_encoder_ankle(sample_osl: OpenSourceLeg):
# Test error case
expected_error = "ERROR: Ankle joint encoder sensor not found. Please check for `joint_encoder_ankle` key in the sensors dictionary.\n"
expected_error = (
"ERROR: Ankle joint encoder sensor not found. "
"Please check for `joint_encoder_ankle` key in the sensors dictionary.\n"
)

with open(LOGGER.file_path) as f:
output = f.read()
assert expected_error not in output

with pytest.raises(SystemExit) as e:
sample_osl.joint_encoder_ankle()
assert e.type == SystemExit
assert e.type is SystemExit

with open(LOGGER.file_path) as f:
output = f.read()
Expand Down
Loading

0 comments on commit 195da86

Please sign in to comment.