Skip to content

Commit 59ab007

Browse files
committed
TST:add tests for the methods animate_propellant_mass and animate_fluid_volume and solve linters issues
1 parent 2f87bef commit 59ab007

3 files changed

Lines changed: 38 additions & 6 deletions

File tree

rocketpy/plots/motor_plots.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def animate_propellant_mass(self, filename=None, fps=30):
528528
----------
529529
filename : str | None, optional
530530
The path the animation should be saved to. By default None, in which
531-
case the animation will be shown instead of saved.Supported file
531+
case the animation will be shown instead of saved.Supported file
532532
ending is: .gif
533533
fps : int, optional
534534
Frames per second for the animation. Default is 30.
@@ -567,7 +567,7 @@ def init():
567567

568568
# Update per frame
569569
def update(frame_index):
570-
line.set_data(times[:frame_index+1], values[:frame_index+1])
570+
line.set_data(times[: frame_index + 1], values[: frame_index + 1])
571571
point.set_data([times[frame_index]], [values[frame_index]])
572572
return line, point
573573

rocketpy/plots/tank_plots.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,14 @@ def init():
231231

232232
def update(frame_index):
233233
# Liquid part
234-
line_liquid.set_data(times[:frame_index+1], liquid_values[:frame_index+1])
235-
point_liquid.set_data(times[frame_index], liquid_values[frame_index])
234+
line_liquid.set_data(
235+
times[: frame_index + 1], liquid_values[: frame_index + 1]
236+
)
237+
point_liquid.set_data([times[frame_index]], [liquid_values[frame_index]])
236238

237239
# Gas part
238-
line_gas.set_data(times[:frame_index+1], gas_values[:frame_index+1])
239-
point_gas.set_data(times[frame_index], gas_values[frame_index])
240+
line_gas.set_data(times[: frame_index + 1], gas_values[: frame_index + 1])
241+
point_gas.set_data([times[frame_index]], [gas_values[frame_index]])
240242

241243
return line_liquid, line_gas, point_liquid, point_gas
242244

tests/unit/test_plots.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,33 @@ def update(frame):
141141

142142
with pytest.raises(ValueError, match="Unsupported file ending"):
143143
show_or_save_animation(animation, "test.mp4")
144+
145+
146+
def test_animate_propellant_mass(cesaroni_m1670):
147+
"""Test that animate_propellant_mass saves a .gif file correctly."""
148+
149+
motor = cesaroni_m1670
150+
animation = motor.plots.animate_propellant_mass(filename="cesaroni_m1670.gif")
151+
152+
# Check animation type
153+
assert isinstance(animation, FuncAnimation)
154+
155+
# check if file exists
156+
assert os.path.exists("cesaroni_m1670.gif")
157+
158+
os.remove("cesaroni_m1670.gif")
159+
160+
161+
def test_animate_fluid_volume(example_mass_flow_rate_based_tank_seblm):
162+
"""Test that animate_fluid_volume saves a .gif file correctly."""
163+
164+
tank = example_mass_flow_rate_based_tank_seblm
165+
animation = tank.plots.animate_fluid_volume(filename="test_fluid_volume.gif")
166+
167+
# Check animation type
168+
assert isinstance(animation, FuncAnimation)
169+
170+
# Check if file exists
171+
assert os.path.exists("test_fluid_volume.gif")
172+
173+
os.remove("test_fluid_volume.gif")

0 commit comments

Comments
 (0)