Skip to content

Commit 91ac567

Browse files
authored
BUG: fixes get_instance_attributes for Flight objects containing a Rocket object without rail buttons (#786)
* DOC: fixed a typo in funcify_method() description * TST: created test for get_instante_attributes() with flight without rail buttons * BUG: fixed __calculate_rail_button_forces() by assigning a Function(0) to null_force instead of an empty array * DEV: updates CHANGELOG
1 parent 9407470 commit 91ac567

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ Attention: The newest changes should be on top -->
4444

4545
- BUG: do not allow drawing rockets with no aerodynamic surface [#774](https://github.com/RocketPy-Team/RocketPy/pull/774)
4646
- BUG: update flight simulation logic to include burn start time [#778](https://github.com/RocketPy-Team/RocketPy/pull/778)
47+
- BUG: fixes get_instance_attributes for Flight objects containing a Rocket object without rail buttons [#786](https://github.com/RocketPy-Team/RocketPy/pull/786)
4748
- BUG: fixed AGL altitude print for parachutes with lag [#788](https://github.com/RocketPy-Team/RocketPy/pull/788)
4849

50+
4951
## [v1.8.0] - 2025-01-20
5052

5153
To install this version, run `pip install rocketpy==1.8.0`

rocketpy/mathutils/function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3492,7 +3492,7 @@ def funcify_method(*args, **kwargs): # pylint: disable=too-many-statements
34923492
>>> example.f
34933493
'Function from R1 to R1 : (x) → (f(x))'
34943494
3495-
In order to reset the cache, just delete de attribute from the instance:
3495+
In order to reset the cache, just delete the attribute from the instance:
34963496
34973497
>>> del example.f
34983498

rocketpy/simulation/flight.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2954,7 +2954,7 @@ def __calculate_rail_button_forces(self): # TODO: complex method.
29542954
Rail Button 2 force in the 2 direction
29552955
"""
29562956
# First check for no rail phase or rail buttons
2957-
null_force = []
2957+
null_force = Function(0)
29582958
if self.out_of_rail_time_index == 0: # No rail phase, no rail button forces
29592959
warnings.warn(
29602960
"Trying to calculate rail button forces without a rail phase defined."

tests/unit/test_utilities.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def test_flutter_plots(mock_show, flight_calisto_custom_wind): # pylint: disabl
165165
), "An error occurred while running the utilities._flutter_plots function."
166166

167167

168-
def test_get_instance_attributes(flight_calisto_robust):
168+
def test_get_instance_attributes_with_robust_flight(flight_calisto_robust):
169169
"""Tests if get_instance_attributes returns the expected results for a
170170
robust flight object."""
171171

@@ -178,6 +178,19 @@ def test_get_instance_attributes(flight_calisto_robust):
178178
assert attr == value
179179

180180

181+
def test_get_instance_attributes_with_flight_without_rail_buttons(flight_calisto):
182+
"""Tests if get_instance_attributes returns the expected results for a
183+
flight object that contains a rocket object without rail buttons."""
184+
185+
attributes = utilities.get_instance_attributes(flight_calisto)
186+
for key, value in attributes.items():
187+
attr = getattr(flight_calisto, key)
188+
if isinstance(attr, np.ndarray):
189+
assert np.allclose(attr, value)
190+
else:
191+
assert attr == value
192+
193+
181194
@pytest.mark.parametrize(
182195
"f, eps, expected",
183196
[

0 commit comments

Comments
 (0)