Skip to content

Commit 2beebdd

Browse files
committed
Fixed Pylint Errors, function docstrings
1 parent c17b367 commit 2beebdd

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

tests/unit/test_lidar_parser.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,30 @@
33
"""
44

55
import pytest
6+
67
from modules import lidar_detection
7-
from modules import lidar_oscillation
88
from modules.lidar_parser import lidar_parser
99

1010
ANGLE_UP = 15.0
1111
ANGLE_DOWN = -15.0
1212

13+
# pylint: disable=redefined-outer-name, duplicate-code
14+
1315

1416
@pytest.fixture()
1517
def lidar_parser_instance() -> lidar_parser.LidarParser: # type: ignore
18+
"""
19+
Fixture to initialize a LidarParser instance for testing.
20+
"""
1621
parser = lidar_parser.LidarParser()
1722
yield parser
1823

1924

2025
@pytest.fixture()
2126
def lidar_detection_up() -> lidar_detection.LidarDetection: # type: ignore
27+
"""
28+
Fixture to create an upward LidarDetection object.
29+
"""
2230
result, detection = lidar_detection.LidarDetection.create(5.0, ANGLE_UP)
2331
assert result
2432
assert detection is not None
@@ -27,6 +35,9 @@ def lidar_detection_up() -> lidar_detection.LidarDetection: # type: ignore
2735

2836
@pytest.fixture()
2937
def higher_angle_detection_up(lidar_detection_up: lidar_detection.LidarDetection) -> lidar_detection.LidarDetection: # type: ignore
38+
"""
39+
Fixture to create a LidarDetection object with a higher upward angle than the previous detection.
40+
"""
3041
result, higher_detection = lidar_detection.LidarDetection.create(
3142
5.0, lidar_detection_up.angle + 5.0
3243
)
@@ -37,6 +48,9 @@ def higher_angle_detection_up(lidar_detection_up: lidar_detection.LidarDetection
3748

3849
@pytest.fixture()
3950
def lidar_detection_down() -> lidar_detection.LidarDetection: # type: ignore
51+
"""
52+
Fixture to create a downward LidarDetection object.
53+
"""
4054
result, detection = lidar_detection.LidarDetection.create(5.0, ANGLE_DOWN)
4155
assert result
4256
assert detection is not None
@@ -45,6 +59,9 @@ def lidar_detection_down() -> lidar_detection.LidarDetection: # type: ignore
4559

4660
@pytest.fixture()
4761
def lower_angle_detection_down(lidar_detection_up: lidar_detection.LidarDetection) -> lidar_detection.LidarDetection: # type: ignore
62+
"""
63+
Fixture to create a LidarDetection object with a lower downward angle than the previous detection.
64+
"""
4865
result, lower_detection = lidar_detection.LidarDetection.create(
4966
5.0, lidar_detection_up.angle - 5.0
5067
)
@@ -63,6 +80,9 @@ def test_initial_run_no_oscillation(
6380
lidar_parser_instance: lidar_parser.LidarParser,
6481
lidar_detection_up: lidar_detection.LidarDetection,
6582
) -> None:
83+
"""
84+
Test that a single upward detection does not complete an oscillation.
85+
"""
6686
result, oscillation = lidar_parser_instance.run(lidar_detection_up)
6787
assert not result
6888
assert oscillation is None
@@ -74,7 +94,9 @@ def test_oscillation_detected_up_to_down(
7494
higher_angle_detection_up: lidar_detection.LidarDetection,
7595
lidar_detection_down: lidar_detection.LidarDetection,
7696
) -> None:
77-
97+
"""
98+
Test detection of an oscillation with a change in direction from up to down after multiple detections.
99+
"""
78100
lidar_parser_instance.run(lidar_detection_up)
79101
lidar_parser_instance.run(higher_angle_detection_up)
80102
result, oscillation = lidar_parser_instance.run(lidar_detection_down)
@@ -86,7 +108,9 @@ def test_no_oscillation_on_same_direction(
86108
lidar_parser_instance: lidar_parser.LidarParser,
87109
lidar_detection_up: lidar_detection.LidarDetection,
88110
) -> None:
89-
111+
"""
112+
Test that no oscillation is detected when multiple detections are in the same upward direction.
113+
"""
90114
for _ in range(5):
91115
result, oscillation = lidar_parser_instance.run(lidar_detection_up)
92116
assert not result
@@ -98,7 +122,9 @@ def test_direction_initialization_on_first_run(
98122
lidar_detection_up: lidar_detection.LidarDetection,
99123
lower_angle_detection_down: lidar_detection.LidarDetection,
100124
) -> None:
101-
125+
"""
126+
Test that the initial detection sets the direction to DOWN based on a second downward detection.
127+
"""
102128
lidar_parser_instance.run(lidar_detection_up)
103129
lidar_parser_instance.run(lower_angle_detection_down)
104130
assert lidar_parser_instance.direction == lidar_parser.Direction.DOWN
@@ -110,7 +136,9 @@ def test_oscillation_reset_after_detection(
110136
higher_angle_detection_up: lidar_detection.LidarDetection,
111137
lidar_detection_down: lidar_detection.LidarDetection,
112138
) -> None:
113-
139+
"""
140+
Test that the parser resets its readings after detecting an oscillation.
141+
"""
114142
lidar_parser_instance.run(lidar_detection_up)
115143
lidar_parser_instance.run(higher_angle_detection_up)
116144
result, oscillation = lidar_parser_instance.run(lidar_detection_down)
@@ -129,8 +157,6 @@ def test_alternating_up_down_oscillations(
129157
Test the parser with alternating up and down angles to simulate multiple oscillations.
130158
"""
131159
oscillation_count = 0
132-
133-
# Detect the first oscillation with three readings: two up, one down
134160
lidar_parser_instance.run(lidar_detection_up)
135161
lidar_parser_instance.run(higher_angle_detection_up)
136162
result, oscillation = lidar_parser_instance.run(lidar_detection_down)
@@ -139,25 +165,26 @@ def test_alternating_up_down_oscillations(
139165
oscillation_count += 1
140166
assert oscillation is not None
141167

142-
# Subsequent oscillations should alternate and be detected on every change of angle
143168
for i in range(4):
144-
if i % 2 == 0: # Every even index provides an upward reading
169+
if i % 2 == 0:
145170
result, oscillation = lidar_parser_instance.run(higher_angle_detection_up)
146-
else: # Every odd index provides a downward reading
171+
else:
147172
result, oscillation = lidar_parser_instance.run(lidar_detection_down)
148173

149174
if result:
150175
oscillation_count += 1
151176
assert oscillation is not None
152177

153-
# Verify that five oscillations were detected in total
154178
assert oscillation_count == 5
155179

156180
def test_no_oscillation_with_single_reading(
157181
self,
158182
lidar_parser_instance: lidar_parser.LidarParser,
159183
lidar_detection_up: lidar_detection.LidarDetection,
160184
) -> None:
185+
"""
186+
Test that a single detection does not produce an oscillation.
187+
"""
161188
result, oscillation = lidar_parser_instance.run(lidar_detection_up)
162189
assert not result
163190
assert oscillation is None
@@ -169,6 +196,9 @@ def test_oscillation_on_direction_change_after_none(
169196
higher_angle_detection_up: lidar_detection.LidarDetection,
170197
lidar_detection_down: lidar_detection.LidarDetection,
171198
) -> None:
199+
"""
200+
Test that direction changes after Direction.NONE trigger the first oscillation properly.
201+
"""
172202
lidar_parser_instance.run(lidar_detection_up)
173203
lidar_parser_instance.run(higher_angle_detection_up)
174204
assert lidar_parser_instance.direction == lidar_parser.Direction.UP

0 commit comments

Comments
 (0)