Skip to content

Commit 6eaf99d

Browse files
authored
TST: add branch coverage for fin_flutter_analysis and fix keyword argument bug (#904)
* TST: add branch coverage for fin_flutter_analysis and fix keyword bug This commit increases test coverage for utilities.py by adding three new tests that cover previously untested branches in the fin_flutter_analysis function. The tests cover the see_prints=True branch, see_graphs=True branch, and both flags enabled simultaneously. During testing, discovered and fixed a bug where the filename parameter was incorrectly passed as a positional argument to _flutter_plots, which requires it as a keyword-only argument. This would cause a TypeError at runtime when users attempted to save flutter plots to files. Changes: - Add test_fin_flutter_analysis_with_prints for print branch coverage - Add test_fin_flutter_analysis_with_graphs for plotting branch coverage - Add test_fin_flutter_analysis_complete_output for combined coverage - Fix filename argument bug in fin_flutter_analysis (line 286) - Fix test_flutter_plots to use keyword argument for filename - Increases utilities.py coverage from 68% to 69% (+2 statements) * DOC: updated CHANGELOG for test coverage and bug fix * DOC: revert CHANGELOG.md changes per reviewer feedback
1 parent 14b9984 commit 6eaf99d

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

rocketpy/utilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def fin_flutter_analysis(
283283
flight,
284284
)
285285
if see_graphs:
286-
_flutter_plots(flight, flutter_mach, safety_factor, filename)
286+
_flutter_plots(flight, flutter_mach, safety_factor, filename=filename)
287287
else:
288288
return flutter_mach, safety_factor
289289

tests/unit/test_utilities.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,76 @@ def test_fin_flutter_analysis(flight_calisto_custom_wind):
117117
assert np.isclose(safety_factor(np.inf), 61.669562809629035, atol=5e-3)
118118

119119

120+
def test_fin_flutter_analysis_with_prints(flight_calisto_custom_wind):
121+
"""Test fin_flutter_analysis with see_prints=True to cover print branch.
122+
123+
Parameters
124+
----------
125+
flight_calisto_custom_wind : Flight
126+
A Flight object with a rocket with fins.
127+
"""
128+
flutter_mach, safety_factor = utilities.fin_flutter_analysis(
129+
fin_thickness=2 / 1000,
130+
shear_modulus=10e9,
131+
flight=flight_calisto_custom_wind,
132+
see_prints=True,
133+
see_graphs=False, # False = returns tuple!
134+
filename=None,
135+
)
136+
137+
# Verify returns are valid
138+
assert flutter_mach is not None
139+
assert safety_factor is not None
140+
141+
142+
@patch("matplotlib.pyplot.show")
143+
def test_fin_flutter_analysis_with_graphs(mock_show, flight_calisto_custom_wind): # pylint: disable=unused-argument
144+
"""Test fin_flutter_analysis with see_graphs=True to cover plotting branch.
145+
146+
Parameters
147+
----------
148+
mock_show : mock
149+
Mock of matplotlib.pyplot.show function.
150+
flight_calisto_custom_wind : Flight
151+
A Flight object with a rocket with fins.
152+
"""
153+
result = utilities.fin_flutter_analysis(
154+
fin_thickness=2 / 1000,
155+
shear_modulus=10e9,
156+
flight=flight_calisto_custom_wind,
157+
see_prints=False,
158+
see_graphs=True, # True = returns None!
159+
filename=None,
160+
)
161+
162+
assert result is None
163+
mock_show.assert_called()
164+
165+
166+
@patch("matplotlib.pyplot.show")
167+
def test_fin_flutter_analysis_complete_output(mock_show, flight_calisto_custom_wind): # pylint: disable=unused-argument
168+
"""Test fin_flutter_analysis with both prints and graphs enabled.
169+
170+
Parameters
171+
----------
172+
mock_show : mock
173+
Mock of matplotlib.pyplot.show function.
174+
flight_calisto_custom_wind : Flight
175+
A Flight object with a rocket with fins.
176+
"""
177+
result = utilities.fin_flutter_analysis(
178+
fin_thickness=2 / 1000,
179+
shear_modulus=10e9,
180+
flight=flight_calisto_custom_wind,
181+
see_prints=True,
182+
see_graphs=True, # True = returns None!
183+
filename=None,
184+
)
185+
186+
assert result is None
187+
mock_show.assert_called()
188+
189+
120190
def test_flutter_prints(flight_calisto_custom_wind):
121191
"""Tests the _flutter_prints function.
122192

0 commit comments

Comments
 (0)