Skip to content

Commit 6dc2947

Browse files
Refactor environment method access in controller test for clarity
1 parent df536da commit 6dc2947

File tree

2 files changed

+29
-34
lines changed

2 files changed

+29
-34
lines changed

tests/integration/simulation/test_flight.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,20 @@ def test_environment_methods_accessible_in_controller(
742742
"temperature": False,
743743
}
744744

745+
def _call_env_methods(environment, altitude_asl, methods_called):
746+
_ = environment.elevation
747+
methods_called["elevation"] = True
748+
_ = environment.wind_velocity_x(altitude_asl)
749+
methods_called["wind_velocity_x"] = True
750+
_ = environment.wind_velocity_y(altitude_asl)
751+
methods_called["wind_velocity_y"] = True
752+
_ = environment.speed_of_sound(altitude_asl)
753+
methods_called["speed_of_sound"] = True
754+
_ = environment.pressure(altitude_asl)
755+
methods_called["pressure"] = True
756+
_ = environment.temperature(altitude_asl)
757+
methods_called["temperature"] = True
758+
745759
def controller_test_environment_access( # pylint: disable=unused-argument
746760
time,
747761
sampling_rate,
@@ -758,29 +772,10 @@ def controller_test_environment_access( # pylint: disable=unused-argument
758772
if time < 3.9:
759773
return None
760774

761-
# Test accessing various environment methods
762775
try:
763-
_ = environment.elevation
764-
methods_called["elevation"] = True
765-
766-
_ = environment.wind_velocity_x(altitude_asl)
767-
methods_called["wind_velocity_x"] = True
768-
769-
_ = environment.wind_velocity_y(altitude_asl)
770-
methods_called["wind_velocity_y"] = True
771-
772-
_ = environment.speed_of_sound(altitude_asl)
773-
methods_called["speed_of_sound"] = True
774-
775-
_ = environment.pressure(altitude_asl)
776-
methods_called["pressure"] = True
777-
778-
_ = environment.temperature(altitude_asl)
779-
methods_called["temperature"] = True
780-
776+
_call_env_methods(environment, altitude_asl, methods_called)
781777
air_brakes.deployment_level = 0.3
782778
except AttributeError as e:
783-
# If any method is not accessible, the test should fail
784779
raise AssertionError(f"Environment method not accessible: {e}") from e
785780

786781
return (time, air_brakes.deployment_level)

tests/unit/rocket/test_parachute.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99

1010
def _make_parachute(**kwargs):
11-
defaults = dict(
12-
name="test",
13-
cd_s=10.0,
14-
trigger="apogee",
15-
sampling_rate=100,
16-
)
11+
defaults = {
12+
"name": "test",
13+
"cd_s": 10.0,
14+
"trigger": "apogee",
15+
"sampling_rate": 100,
16+
}
1717
defaults.update(kwargs)
1818
return Parachute(**defaults)
1919

@@ -98,14 +98,14 @@ def test_from_dict_round_trip_preserves_drag_coefficient(self):
9898
def test_from_dict_defaults_drag_coefficient_to_1_4_when_absent(self):
9999
"""Dicts serialized before drag_coefficient was added (no key) must
100100
fall back to 1.4 for backward compatibility."""
101-
data = dict(
102-
name="legacy",
103-
cd_s=10.0,
104-
trigger="apogee",
105-
sampling_rate=100,
106-
lag=0,
107-
noise=(0, 0, 0),
101+
data = {
102+
"name": "legacy",
103+
"cd_s": 10.0,
104+
"trigger": "apogee",
105+
"sampling_rate": 100,
106+
"lag": 0,
107+
"noise": (0, 0, 0),
108108
# no drag_coefficient key — simulates old serialized data
109-
)
109+
}
110110
parachute = Parachute.from_dict(data)
111111
assert parachute.drag_coefficient == pytest.approx(1.4)

0 commit comments

Comments
 (0)